[Note 5 - shopping cart and address module] independently completed the development of enterprise Java e-commerce website (server side) from 0

Shopping Cart module

Database table design

Shopping cart Watch

CREATE TABLE mmall_ cart (
'id' int(11) NOT NULL AUTO_ INCREMENT,
'user_ id' int(11) NOT NULL,
'product_ id' int(11) DEFAULT NULL COMMENT ' commodity id',
'quantity' int(11) DEFAULT NULL COMMENT  'Number',
'checked' int(11) DEFAULT NULL COMMENT ' Select or not, 1=Selected,0=Unchecked' ,
'create_ time' datetime DEFAULT NULL COMMENT ' Creation time'
'update_ _time' datetime DEFAULT NULL COMMENT ' Update time' ,
PRIMARY KEY (' id'),
KEY 'user_ id_ index' (user_ id') USING BTREE
) ENGINE=InnoDB AUTO_ INCREMENT=121 DEFAULT CHARSET=utf8

function

Add merchandise
Number of updated products
Number of items queried
Remove merchandise
Radio / cancel
Select all / cancel
Shopping cart list

Knowledge points involved

Design idea of shopping cart module

How to encapsulate a high reuse shopping cart core method

Solving the problem of losing precision in floating-point commercial operation

interface design

[portal]

1. Shopping cart List

/cart/list.do

http://localhost:8080/cart/list.do

Note:

  1. Need to log in first, all passwords are 123
  2. Need "login (10," need "login"), / / error code to log in
  3. The unit of price is yuan, 2 decimal places are reserved

request

No parameters, login status required

response

success

{
    "status": 0,
    "data": {
        "cartProductVoList": [
            {
                "id": 1,
                "userId": 13,
                "productId": 1,
                "quantity": 1,
                "productName": "iphone7",
                "productSubtitle": "Double eleven promotion",
                "productMainImage": "mainimage.jpg",
                "productPrice": 7199.22,
                "productStatus": 1,
                "productTotalPrice": 7199.22,
                "productStock": 86,
                "productChecked": 1,
                "limitQuantity": "LIMIT_NUM_SUCCESS"
            },
            {
                "id": 2,
                "userId": 13,
                "productId": 2,
                "quantity": 1,
                "productName": "oppo R8",
                "productSubtitle": "oppo Promotion in progress",
                "productMainImage": "mainimage.jpg",
                "productPrice": 2999.11,
                "productStatus": 1,
                "productTotalPrice": 2999.11,
                "productStock": 86,
                "productChecked": 1,
                "limitQuantity": "LIMIT_NUM_SUCCESS"
            }
        ],
        "allChecked": true,
        "cartTotalPrice": 10198.33
    }
}

2. Add items to shopping cart

/cart/add.do

http://localhost:8080/cart/add.do?productId=1&count=10

Please pay attention to this field. If the quantity is exceeded, the ID "limitQuantity" will be returned

Failed: limit num fail
Successful: limit num success

request

productId,count

response

success

{
    "status": 0,
    "data": {
        "cartProductVoList": [
            {
                "id": 1,
                "userId": 13,
                "productId": 1,
                "quantity": 12,
                "productName": "iphone7",
                "productSubtitle": "Double eleven promotion",
                "productMainImage": "mainimage.jpg",
                "productPrice": 7199.22,
                "productStatus": 1,
                "productTotalPrice": 86390.64,
                "productStock": 86,
                "productChecked": 1,
                "limitQuantity": "LIMIT_NUM_SUCCESS"
            },
            {
                "id": 2,
                "userId": 13,
                "productId": 2,
                "quantity": 1,
                "productName": "oppo R8",
                "productSubtitle": "oppo Promotion in progress",
                "productMainImage": "mainimage.jpg",
                "productPrice": 2999.11,
                "productStatus": 1,
                "productTotalPrice": 2999.11,
                "productStock": 86,
                "productChecked": 1,
                "limitQuantity": "LIMIT_NUM_SUCCESS"
            }
        ],
        "allChecked": true,
        "cartTotalPrice": 89389.75
    }
}

3. Update product quantity of shopping cart

/cart/update.do

http://localhost:8080/cart/update.do?productId=1&count=2

request

productId,count

response

Responding to the same 2

success

{
    "status": 0,
    "data": {
        "cartProductVoList": [
            {
                "id": 1,
                "userId": 13,
                "productId": 1,
                "quantity": 12,
                "productName": "iphone7",
                "productSubtitle": "Double eleven promotion",
                "productMainImage": "mainimage.jpg",
                "productPrice": 7199.22,
                "productStatus": 1,
                "productTotalPrice": 86390.64,
                "productStock": 86,
                "productChecked": 1,
                "limitQuantity": "LIMIT_NUM_SUCCESS"
            },
            {
                "id": 2,
                "userId": 13,
                "productId": 2,
                "quantity": 1,
                "productName": "oppo R8",
                "productSubtitle": "oppo Promotion in progress",
                "productMainImage": "mainimage.jpg",
                "productPrice": 2999.11,
                "productStatus": 1,
                "productTotalPrice": 2999.11,
                "productStock": 86,
                "productChecked": 1,
                "limitQuantity": "LIMIT_NUM_SUCCESS"
            }
        ],
        "allChecked": true,
        "cartTotalPrice": 89389.75
    }
}

4. Remove a product from the shopping cart

/cart/delete_product.do

http://localhost:8080/cart/delete_product.do?productIds=1,3

request

productIds

response

success

{
    "status": 0,
    "data": {
        "cartProductVoList": [
            {
                "id": 2,
                "userId": 13,
                "productId": 2,
                "quantity": 1,
                "productName": "oppo R8",
                "productSubtitle": "oppo Promotion in progress",
                "productMainImage": "mainimage.jpg",
                "productPrice": 2999.11,
                "productStatus": 1,
                "productTotalPrice": 2999.11,
                "productStock": 86,
                "productChecked": 1,
                "limitQuantity": "LIMIT_NUM_SUCCESS"
            }
        ],
        "allChecked": true,
        "cartTotalPrice": 2999.11
    }
}

5. Select a product in the shopping cart

/cart/select.do

http://localhost:8080/cart/select.do?productId=1

request

productId

response

success

{
    "status": 0,
    "data": {
        "cartProductVoList": [
            {
                "id": 2,
                "userId": 13,
                "productId": 2,
                "quantity": 1,
                "productName": "oppo R8",
                "productSubtitle": "oppo Promotion in progress",
                "productMainImage": "mainimage.jpg",
                "productPrice": 2999.11,
                "productStatus": 1,
                "productTotalPrice": 2999.11,
                "productStock": 86,
                "productChecked": 1,
                "limitQuantity": "LIMIT_NUM_SUCCESS"
            }
        ],
        "allChecked": true,
        "cartTotalPrice": 2999.11
    }
}

6. Deselect a product in the shopping cart

/cart/un_select.do

http://localhost:8080/cart/un_select.do?productId=2

Note the cartTotalPrice in the return value. If the total price changes after reverse selection

request

productId

response

success

{
    "status": 0,
    "data": {
        "cartProductVoList": [
            {
                "id": 2,
                "userId": 13,
                "productId": 2,
                "quantity": 1,
                "productName": "oppo R8",
                "productSubtitle": "oppo Promotion in progress",
                "productMainImage": "mainimage.jpg",
                "productPrice": 2999.11,
                "productStatus": 1,
                "productTotalPrice": 2999.11,
                "productStock": 86,
                "productChecked": 0,
                "limitQuantity": "LIMIT_NUM_SUCCESS"
            }
        ],
        "allChecked": true,
        "cartTotalPrice": 0
    }
}

7. Query the product quantity in the shopping cart

/cart/get_cart_product_count.do

http://localhost:8080/cart/get_cart_product_count.do

Not logged in returned 0

request

nothing

response

success

{
    "status": 0,
    "data": 0
    
}

8. Shopping cart selection

/cart/select_all.do

http://localhost:8080/cart/select_all.do

Notice the change of cartTotalPrice in the return value

request

nothing

response

success

{
    "status": 0,
    "data": {
        "cartProductVoList": [
            {
                "id": 2,
                "userId": 13,
                "productId": 2,
                "quantity": 1,
                "productName": "oppo R8",
                "productSubtitle": "oppo Promotion in progress",
                "productMainImage": "mainimage.jpg",
                "productPrice": 2999.11,
                "productStatus": 1,
                "productTotalPrice": 2999.11,
                "productStock": 86,
                "productChecked": 0,
                "limitQuantity": "LIMIT_NUM_SUCCESS"
            }
        ],
        "allChecked": true,
        "cartTotalPrice": 2999.11
    }
}

9. Shopping cart deselect all

/cart/un_select_all.do

http://localhost:8080/cart/un_select_all.do

Note the change in the total price of cartTotalPrice in the return value

request

nothing

response

success

{
    "status": 0,
    "data": {
        "cartProductVoList": [
            {
                "id": 2,
                "userId": 13,
                "productId": 2,
                "quantity": 1,
                "productName": "oppo R8",
                "productSubtitle": "oppo Promotion in progress",
                "productMainImage": "mainimage.jpg",
                "productPrice": 2999.11,
                "productStatus": 1,
                "productTotalPrice": 2999.11,
                "productStock": 86,
                "productChecked": 0,
                "limitQuantity": "LIMIT_NUM_SUCCESS"
            }
        ],
        "allChecked": true,
        "cartTotalPrice": 0
    }
}

Receiving address module

Database table design

Receiving address table

CREATE TABLE'mmall_ shipping (
'id' int(11) NOT NULL AUTO_INCREMENT,
'user_ id'  int(11) DEFAULT NULL COMMENT 'user id'',
'receiver_ name' varchar(20) DEFAULT NULL COMMENT 'Receipt name',
'receiver_ phone' varchar(20) DEFAULT NULL COMMENT 'Receiving fixed line',
'receiver_ _mobile' varchar(20) DEFAULT NULL COMMENT ' Receiving mobile phone'',
'receiver_ province' varchar(20) DEFAULT NULL COMMENT 'Province',
'receiver_ _city' varchar(20) DEFAULT NULL COMMENT ' City'',
'receiver_ _district' varchar (20) DEFAULT NULL COMMENT 'area/county'',
'receiver_ address'  varchar(200) DEFAULT NULL COMMENT ' Detailed address',
'receiver_ zip'  varchar(6) DEFAULT NULL COMMENT ' Zip code' ,
'create_ _time' datetime DEFAULT NULL,
'update_ time' datetime DEFAULT NULL,
PRIMARY KEY ('id')
) ENGINE=InnoDB AUTO_ INCREMENT=32 DEFAULT CHARSET=utf8

function

Add address
Delete address
Update address
Address list
Address paging
Address Details

Knowledge points involved

Object binding in spring MVC data binding
mybatis automatically generates primary key, configures and uses
How to avoid consolidating the loopholes of horizontal ultra vires

interface design

[foreground]

1. Add address

/shipping/add.do

http://localhost:8080/shipping/add.do?userId=1&receiverName=geely&receiverPhone=010&receiverMobile=18688888888&receiverProvince=%E5%8C%97%E4%BA%AC&receiverCity=%E5%8C%97%E4%BA%AC%E5%B8%82&receiverAddress=%E4%B8%AD%E5%85%B3%E6%9D%91&receiverZip=100000

request

userId=1
receiverName=geely
receiverPhone=010
receiverMobile=18688888888
receiverProvince=Beijing
receiverCity=Beijing City
receiverAddress=Zhongguancun
receiverZip=100000

response

success

{
    "status": 0,
    "msg": "New address created successfully",
    "data": {
        "shippingId": 28
    }
}

2. Delete address

/shipping/del.do

request

shippingId

response

success

{
    "status": 0,
    "msg": "Address deleted successfully"
}

3. Login status update address

/shipping/update.do

http://localhost:8080/shipping/update.do?id=5&receiverName=AAA&receiverPhone=010&receiverMobile=18688888888&receiverProvince=%E5%8C%97%E4%BA%AC&receiverCity=%E5%8C%97%E4%BA%AC%E5%B8%82&receiverDistrict=%E6%B5%B7%E6%B7%80%E5%8C%BA&receiverAddress=%E4%B8%AD%E5%85%B3%E6%9D%91&receiverZip=100000

request

id=1
receiverName=geely
receiverPhone=010
receiverMobile=18688888888
receiverProvince=Beijing
receiverCity=Beijing City
receiverAddress=Zhongguancun
receiverZip=100000

response

success

{
    "status": 0,
    "msg": "Update address succeeded"
}

4. Select to view the specific address

/shipping/select.do

request

shippingId

response

success

{
    "status": 0,
    "data": {
        "id": 4,
        "userId": 13,
        "receiverName": "geely",
        "receiverPhone": "010",
        "receiverMobile": "18688888888",
        "receiverProvince": "Beijing",
        "receiverCity": "Beijing City",
        "receiverAddress": "Zhongguancun",
        "receiverZip": "100000",
        "createTime": 1485066385000,
        "updateTime": 1485066385000
    }
}

5. Address list

/shipping/list.do

http://localhost:8080/shipping/list.do

request

Pagenum (default 1), PageSize (default 10)

response

success

{
    "status": 0,
    "data": {
        "pageNum": 1,
        "pageSize": 10,
        "size": 2,
        "orderBy": null,
        "startRow": 1,
        "endRow": 2,
        "total": 2,
        "pages": 1,
        "list": [
            {
                "id": 4,
                "userId": 13,
                "receiverName": "geely",
                "receiverPhone": "010",
                "receiverMobile": "18688888888",
                "receiverProvince": "Beijing",
                "receiverCity": "Beijing City",
                "receiverAddress": "Zhongguancun",
                "receiverZip": "100000",
                "createTime": 1485066385000,
                "updateTime": 1485066385000
            },
            {
                "id": 5,
                "userId": 13,
                "receiverName": "AAA",
                "receiverPhone": "010",
                "receiverMobile": "18688888888",
                "receiverProvince": "Beijing",
                "receiverCity": "Beijing City",
                "receiverAddress": "Zhongguancun",
                "receiverZip": "100000",
                "createTime": 1485066392000,
                "updateTime": 1485075875000
            }
        ],
        "firstPage": 1,
        "prePage": 0,
        "nextPage": 0,
        "lastPage": 1,
        "isFirstPage": true,
        "isLastPage": true,
        "hasPreviousPage": false,
        "hasNextPage": false,
        "navigatePages": 8,
        "navigatepageNums": [
            1
        ]
    }
}

Tags: Java Database Mobile Spring Mybatis

Posted on Tue, 11 Feb 2020 03:38:01 -0500 by chixsilog