Skip to content

前台商品展示及购物车

sfyr111 edited this page Feb 26, 2018 · 2 revisions

GET 搜索商品名

{{host}}/product/name/search?productName=产品&pageNum=1&pageSize=10

request

productName
pageNum
pageSize

response

{
    "status": 0,
    "msg": null,
    "data": {
        "pageNum": "1",
        "pageSize": "10",
        "list": [
            {
                "id": 1,
                "categoryId": 1,
                "name": "产品名称1",
                "subtitle": "副标题",
                "mainImage": "url1",
                "subImages": "url1,url2",
                "detail": "详情",
                "price": "12.13",
                "stock": 998,
                "status": 1,
                "createTime": "2018-02-14T17:39:36.000Z",
                "updateTime": "2018-02-26T09:04:41.000Z"
            }
        ],
        "total": 5,
        "host": "oss-cn-hangzhou.aliyuncs.com"
    }
}

GET 商品详情

{{host}}/product/detail/:productId

response

{
    "status": 0,
    "msg": null,
    "data": {
        "id": 1,
        "categoryId": 1,
        "name": "产品名称1",
        "subtitle": "副标题",
        "mainImage": "url1",
        "subImages": "url1,url2",
        "detail": "详情",
        "price": "12.13",
        "stock": 998,
        "status": 1,
        "createTime": "2018-02-14T17:39:36.000Z",
        "updateTime": "2018-02-26T09:04:41.000Z"
    }
}

GET 根据分类 id 或分类名称搜索商品

{{host}}/product/categoryId/search?categoryId=1&categoryName=分类&pageNum=1&pageSize=10

request

categoryId: 指定 id 优先级高于分类名称
categoryName
pageNum
pageSize

response

{
    "status": 0,
    "msg": null,
    "data": {
        "pageNum": "1",
        "pageSize": "10",
        "categoryName": "分类",
        "list": [
            {
                "id": 1,
                "categoryId": 1,
                "name": "产品名称1",
                "subtitle": "副标题",
                "mainImage": "url1",
                "subImages": "url1,url2",
                "detail": "详情",
                "price": "12.13",
                "stock": 998,
                "status": 1,
                "createTime": "2018-02-14T17:39:36.000Z",
                "updateTime": "2018-02-26T09:04:41.000Z"
            }
        ],
        "total": 5,
        "host": "oss-cn-hangzhou.aliyuncs.com"
    }
}

POST 添加或更新购物车

{{host}}/cart/update

request

count
productId: 已添加此商品则更新数量

response

{
    "status": 0,
    "msg": "添加购物车成功",
    "data": {
        "totalPrice": "36.45",
        "allChecked": false,
        "list": [
            {
                "id": 5,
                "userId": 12,
                "productId": 5,
                "quantity": 2,
                "checked": 0,
                "createTime": "2018-02-19T07:01:44.000Z",
                "updateTime": "2018-02-24T08:43:06.000Z",
                "product": {
                    "id": 5,
                    "categoryId": 1,
                    "name": "产品名称2",
                    "subtitle": "副标题",
                    "mainImage": "url1",
                    "subImages": "url1,url2",
                    "detail": "详情",
                    "price": "12.14",
                    "stock": 1000,
                    "status": 1,
                    "createTime": "2018-02-16T13:04:40.000Z",
                    "updateTime": "2018-02-16T13:04:40.000Z"
                }
            },
            {
                "id": 12,
                "userId": 12,
                "productId": 6,
                "quantity": 3,
                "checked": 1,
                "createTime": "2018-02-26T08:23:03.000Z",
                "updateTime": "2018-02-26T08:23:03.000Z",
                "product": {
                    "id": 6,
                    "categoryId": 1,
                    "name": "产品名称3",
                    "subtitle": "副标题",
                    "mainImage": "url1",
                    "subImages": "url1,url2",
                    "detail": "详情",
                    "price": "12.15",
                    "stock": 954,
                    "status": 1,
                    "createTime": "2018-02-24T08:27:48.000Z",
                    "updateTime": "2018-02-24T08:27:48.000Z"
                }
            }
        ],
        "host": "oss-cn-hangzhou.aliyuncs.com"
    }
}

GET 获取购物车列表

{{host}}/cart/list

response

{
    "status": 0,
    "data": {
        "totalPrice": "36.45",
        "allChecked": false,
        "list": [
            {
                "id": 5,
                "userId": 12,
                "productId": 5,
                "quantity": 2,
                "checked": 0,
                "createTime": "2018-02-19T07:01:44.000Z",
                "updateTime": "2018-02-24T08:43:06.000Z",
                "product": {
                    "id": 5,
                    "categoryId": 1,
                    "name": "产品名称2",
                    "subtitle": "副标题",
                    "mainImage": "url1",
                    "subImages": "url1,url2",
                    "detail": "详情",
                    "price": "12.14",
                    "stock": 1000,
                    "status": 1,
                    "createTime": "2018-02-16T13:04:40.000Z",
                    "updateTime": "2018-02-16T13:04:40.000Z"
                }
            },
            {
                "id": 12,
                "userId": 12,
                "productId": 6,
                "quantity": 3,
                "checked": 1,
                "createTime": "2018-02-26T08:23:03.000Z",
                "updateTime": "2018-02-26T08:23:03.000Z",
                "product": {
                    "id": 6,
                    "categoryId": 1,
                    "name": "产品名称3",
                    "subtitle": "副标题",
                    "mainImage": "url1",
                    "subImages": "url1,url2",
                    "detail": "详情",
                    "price": "12.15",
                    "stock": 954,
                    "status": 1,
                    "createTime": "2018-02-24T08:27:48.000Z",
                    "updateTime": "2018-02-24T08:27:48.000Z"
                }
            }
        ],
        "host": "oss-cn-hangzhou.aliyuncs.com"
    }
}

DELETE 根据产品 id 删除购物车

{{host}}/cart/delete?productIdList=1,5

request

productIdList: 1, 5 逗号分隔多个商品 id 

response

{
    "status": 0,
    "msg": "删除购物车成功",
    "data": {
        "totalPrice": "36.45",
        "allChecked": true,
        "list": [
            {
                "id": 12,
                "userId": 12,
                "productId": 6,
                "quantity": 3,
                "checked": 1,
                "createTime": "2018-02-26T08:23:03.000Z",
                "updateTime": "2018-02-26T08:23:03.000Z",
                "product": {
                    "id": 6,
                    "categoryId": 1,
                    "name": "产品名称3",
                    "subtitle": "副标题",
                    "mainImage": "url1",
                    "subImages": "url1,url2",
                    "detail": "详情",
                    "price": "12.15",
                    "stock": 954,
                    "status": 1,
                    "createTime": "2018-02-24T08:27:48.000Z",
                    "updateTime": "2018-02-24T08:27:48.000Z"
                }
            }
        ],
        "host": "oss-cn-hangzhou.aliyuncs.com"
    }
}

PUT 全选购物车

{{host}}/cart/selectAll

response

{
    "status": 0,
    "msg": "选择",
    "data": {
        "totalPrice": "36.45",
        "allChecked": true,
        "list": [
            {
                "id": 12,
                "userId": 12,
                "productId": 6,
                "quantity": 3,
                "checked": 1,
                "createTime": "2018-02-26T08:23:03.000Z",
                "updateTime": "2018-02-26T09:29:19.000Z",
                "product": {
                    "id": 6,
                    "categoryId": 1,
                    "name": "产品名称3",
                    "subtitle": "副标题",
                    "mainImage": "url1",
                    "subImages": "url1,url2",
                    "detail": "详情",
                    "price": "12.15",
                    "stock": 954,
                    "status": 1,
                    "createTime": "2018-02-24T08:27:48.000Z",
                    "updateTime": "2018-02-24T08:27:48.000Z"
                }
            }
        ],
        "host": "oss-cn-hangzhou.aliyuncs.com"
    }
}

PUT 全反选购物车

{{host}}/cart/unSelectAll

response

{
    "status": 0,
    "msg": "选择",
    "data": {
        "totalPrice": 0,
        "allChecked": false,
        "list": [
            {
                "id": 12,
                "userId": 12,
                "productId": 6,
                "quantity": 3,
                "checked": 0,
                "createTime": "2018-02-26T08:23:03.000Z",
                "updateTime": "2018-02-26T09:29:47.000Z",
                "product": {
                    "id": 6,
                    "categoryId": 1,
                    "name": "产品名称3",
                    "subtitle": "副标题",
                    "mainImage": "url1",
                    "subImages": "url1,url2",
                    "detail": "详情",
                    "price": "12.15",
                    "stock": 954,
                    "status": 1,
                    "createTime": "2018-02-24T08:27:48.000Z",
                    "updateTime": "2018-02-24T08:27:48.000Z"
                }
            }
        ],
        "host": "oss-cn-hangzhou.aliyuncs.com"
    }
}

PUT 选中购物车商品

{{host}}/cart/select/:productId

response

{
    "status": 0,
    "msg": "",
    "data": {
        "totalPrice": "36.45",
        "allChecked": true,
        "list": [
            {
                "id": 12,
                "userId": 12,
                "productId": 6,
                "quantity": 3,
                "checked": 1,
                "createTime": "2018-02-26T08:23:03.000Z",
                "updateTime": "2018-02-26T09:30:46.000Z",
                "product": {
                    "id": 6,
                    "categoryId": 1,
                    "name": "产品名称3",
                    "subtitle": "副标题",
                    "mainImage": "url1",
                    "subImages": "url1,url2",
                    "detail": "详情",
                    "price": "12.15",
                    "stock": 954,
                    "status": 1,
                    "createTime": "2018-02-24T08:27:48.000Z",
                    "updateTime": "2018-02-24T08:27:48.000Z"
                }
            }
        ],
        "host": "oss-cn-hangzhou.aliyuncs.com"
    }
}

PUT 反选购物车

{{host}}/cart/unSelect/5

response

{
    "status": 0,
    "msg": "",
    "data": {
        "totalPrice": 0,
        "allChecked": false,
        "list": [
            {
                "id": 12,
                "userId": 12,
                "productId": 6,
                "quantity": 3,
                "checked": 0,
                "createTime": "2018-02-26T08:23:03.000Z",
                "updateTime": "2018-02-26T09:30:59.000Z",
                "product": {
                    "id": 6,
                    "categoryId": 1,
                    "name": "产品名称3",
                    "subtitle": "副标题",
                    "mainImage": "url1",
                    "subImages": "url1,url2",
                    "detail": "详情",
                    "price": "12.15",
                    "stock": 954,
                    "status": 1,
                    "createTime": "2018-02-24T08:27:48.000Z",
                    "updateTime": "2018-02-24T08:27:48.000Z"
                }
            }
        ],
        "host": "oss-cn-hangzhou.aliyuncs.com"
    }
}

GET 获取用户购物车产品总数

{{host}}/cart/count

response

{
    "status": 0,
    "msg": null,
    "data": {
        "count": "3"
    }
}