Cart.php
4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
namespace app\api\controller;
use addons\shopro\model\Cart as CartModel;
/**
* 购物车接口
*/
class Cart extends Base
{
protected $noNeedLogin = [];
protected $noNeedRight = ['*'];
/**
* @ApiWeigh (99)
* @ApiTitle (购物车首页)
* @ApiSummary (购物车首页)
* @ApiMethod (GET)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiReturn({
"code": 1,
"msg": "我的购物车",
"time": "1608087096",
"data": [{
"id": 1, //购物车ID
"user_id": 1, //用户ID
"goods_id": 4, //商品ID
"goods_num": 2, //加入数量
"sku_price_id": 6,
"goods": { //商品信息
"id": 4, //商品ID
"type": "normal",
"title": "测试", //商品标题
"subtitle": "2", //商品副标题
"weigh": 0,
"category_ids": "3",
"image": "http://www.ant.top/uploads/20201214/076abf7cf60e82783cfdd819746b4b19.png", //商品主图
"images": [ //商品轮播图
"http://www.ant.top/uploads/20201214/b655ea4dc4779222ab7a4e2b95feb3a4.png"
],
"params": [],
"content": "测试多规格",
"price": "20", //现价
"original_price": "200.00", //原价
"is_sku": 1, //是否多规格:0=否,1=是
"likes": 0,
"views": 1,
"sales": 0,
"show_sales": 0,
"service_ids": "4,3",
"dispatch_type": "express",
"dispatch_ids": "1",
"deletetime": null,
"dispatch_type_arr": [
"express"
]
},
"sku_price": {
"id": 6,
"goods_sku_ids": "2,6",
"goods_id": 4,
"weigh": 0,
"image": "",
"stock": 20,
"sales": 0,
"sn": "",
"weight": 1,
"price": "10.00",
"goods_sku_text": "黄色,小",
"status": "up",
"goods_sku_id_arr": [
"2",
"6"
]
}
}]
})
*/
public function index()
{
$data = CartModel::info();
$this->success('我的购物车', $data);
}
/**
* @ApiWeigh (97)
* @ApiTitle (加入购物车)
* @ApiSummary (加入购物车)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=goods_list, type=array, required=false, description="购买的商品:[{goods_id: 3, goods_num: 1, sku_price_id: 3, goods_price: 0.10}]")
*
* @ApiReturn({
"code": 1,
"msg": "已添加",
"time": "1608087096",
"data": null
})
*/
public function add()
{
$params = $this->request->post();
$params['goods_list'] = is_string($params['goods_list']) ? json_decode(htmlspecialchars_decode($params['goods_list']),true) : $params['goods_list'];
// 表单验证
$this->shoproValidate($params, get_class(), 'add');
$goodsList = $params['goods_list'];
$this->success('已添加', CartModel::add($goodsList));
}
/**
* @ApiWeigh (95)
* @ApiTitle (编辑购物车)
* @ApiSummary (编辑购物车)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=act, type=string, required=true, description="操作类型:delete=删除,change=修改")
* @ApiParams (name=cart_list, type=array, required=true, description="购物车ID数组:[1775, 1776]")
* @ApiParams (name=value, type=inter, required=false, description="act为change时必传")
*
* @ApiReturn()
*/
public function edit()
{
$params = $this->request->post();
// 表单验证
$this->shoproValidate($params, get_class(), 'edit');
$this->success('', CartModel::edit($params));
}
}