ShoppingCart.php
9.4 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<?php
use Action\AbstractAction;
use Index\CartModel;
use Plugin\Helpers;
/**
* 购物车
*/
class ShoppingCartController extends AbstractAction
{
/*
* 购物车首页
*/
public function indexAction()
{
$this->setTitle('购物车');
$this->setNavHeader('购物车');
$shoppingKey = $this->getSession('shoppingKey');
$uid = $this->getUid(true);
$data = array(
'shoppingCartPage' => true,
'shoppingCart' => CartModel::getCartData($uid, $shoppingKey)
);
// 渲染模板
$this->_view->display('index', $data);
}
/**
* 移出购物车
*/
public function delAction()
{
$result = array();
if ($this->isAjax()) {
$productId = $this->post('id', 0);
$uid = $this->getUid(true);
$shoppingKey = $this->getSession('shoppingKey');
$result = CartModel::removeFromCart($uid, $productId, $shoppingKey);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
}
/**
* 移入收藏夹
*/
public function colAction()
{
$result = array();
if ($this->isAjax()) {
$productId = $this->post('id', 0);
$uid = $this->getUid(true);
$result = CartModel::addToFav($uid, $productId);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
}
/*
* 获取购物车商品数据
*/
public function goodinfoAction()
{
$result = array();
if ($this->isAjax()) {
$num = $this->get('buy_num', 1);
$skn = $this->get('id', 1);
$uid = $this->getUid(true);
$result = CartModel::cartProductData($uid, $skn, $num); // 测试skn的ID为51172055
$result['num'] = $num;
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
}
/*
* 获取购物车加价购商品数据
*/
public function giftinfoAction()
{
$result = array();
if ($this->isAjax()) {
$skn = $this->get('skn', null);
$promotionId = $this->get('promotionId', null);
$result = CartModel::giftProductData($skn, $promotionId);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
}
/**
* 修改购物车商品数据
*/
public function modifyAction()
{
$result = array();
if ($this->isAjax()) {
$shoppingKey = $this->getSession('shoppingKey');
$uid = $this->getUid(true);
$params = array();
$params['old_product_sku']= $this->post('old_product_sku', 0);
$params['new_product_sku']= $this->post('new_product_sku', 0);
$params['buy_number']= $this->post('buy_number', 0);
$params['selected']= $this->post('selected', null);
$result = CartModel::modifyCartProduct($uid, $params, $shoppingKey);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
}
/**
* 购物车结算请求
*/
public function payAction()
{
$this->setTitle('购物车');
$this->setNavHeader('购物车');
$cartType = $this->post('cartType', 'ordinary');
$uid = $this->getUid(true);
$data = array(
'orderEnsurePage' => true,
'orderEnsure' => CartModel::cartPay($uid, $cartType)
);
$this->_view->display('order-ensure', $data);
}
/**
* 购物车选择支付方式和配送方式接口
*/
public function payAndDeliveryAction()
{
$result = array();
if ($this->isAjax()) {
$cartType = $this->post('cartType', 'ordinary');
$deliveryWay = $this->post('deliveryWay', 1);
$paymentType = $this->post('paymentType', 1);
$uid = $this->getUid(true);
$result = CartModel::paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
}
/**
* 购物车输入优惠券码使用优惠券
*/
public function couponAction()
{
$result = array();
if ($this->isAjax()) {
$couponCode = $this->post('couponCode', '');
$uid = $this->getUid(true);
$result = CartModel::getCoupon($uid, $couponCode);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
}
/**
* 购物车使用YOHO币
*/
public function yohoCoinAction()
{
$result = array();
if ($this->isAjax()) {
$cartType = $this->post('cartType', 'ordinary');
$deliveryWay = $this->post('deliveryWay', 1);
$paymentType = $this->post('paymentType', 1);
$yohoCoin = $this->post('yohoCoin', 1);
$result = CartModel::paymentTypeAndDelivery($this->_uid, $cartType, $deliveryWay, $paymentType, $yohoCoin);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
}
public function giftAdvanceAction()
{
$data = array(
'advance' => array(
array(
'title' => '【izzue】加¥19购袜子',
'goods' => array(
'id' => 1,
'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/09/17/03/014cacfa5c458b9732c68adf1af15d7a45.jpg?imageMogr2/thumbnail/120x120/extent/120x120/background/d2hpdGU=/position/center/quality/90',
'name' => 'Life.After.Life纯棉短袜',
'salePrice' => 19,
'price' => 99,
'count' => 1
)
),
array(
'title' => '【银鳞堂】加¥9购手绳',
'goods' => array(
'id' => 1,
'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/10/03/10/01bc1878f9154e77ac4f7a6003c954f1b8.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
'name' => '银鳞堂民族风牛皮手绳',
'salePrice' => 9,
'price' => 19,
'count' => 1
)
)
)
);
$data = array(
'gift' => array(
'id' => 1,
'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/09/17/03/014cacfa5c458b9732c68adf1af15d7a45.jpg?imageMogr2/thumbnail/120x120/extent/120x120/background/d2hpdGU=/position/center/quality/90',
'name' => 'Life.After.Life纯棉短袜',
'color' => '黄色',
'size' => 'L',
'price' => 0,
'count' => 1
)
);
$this->_view->display('gift-advance', array('giftAdvancePage' => true, 'pageHeader' => array(
'navBack' => true, 'navTitle' => '加价购'), 'shoppingCart' => $data));
}
/*
* 确认订单
*/
public function orderEnsureAction() {
$data = array(
'orderEnsurePage' => true,
'orderEnsure' => array(
'name' => '申建军',
'phoneNum' => '12345678',
'address' => '江苏省南京市建邺区',
'dispatchMode' => array(
array(
'id' => 1,
'name' => '普通快递¥10'
),
array(
'id' => 2,
'name' => '顺丰速运¥15(仅支持顺丰克配送的地区)'
)
),
'dispatchTime' => array(
array(
'id' => 1,
'name' => '工作日、双休日、节假日均可送货'
),
array(
'id' => 2,
'name' => '只工作日送货'
),
array(
'id' => 3,
'name' => '只双休日、节假日送货'
)
),
'goods' => array(
array(
'id' => 1,
'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
'name' => 'Adidas Originals ZX FLUXM22508',
'color' => '黄',
'size' => '43',
'price' => '699.00',
'count' => '2'
),
array(
'id' => 1,
'thumb' => 'http://img10.static.yhbimg.com/goodsimg/2015/11/04/05/0188f1aca49ac478a565ec029b5d2d4a6c.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
'name' => 'B.Duck浴室玩伴mini浮水鸭',
'gift' => true,
'color' => '黄',
'size' => '43',
'price' => '0.00',
'count' => '1'
)
),
'coupon' => array(
'count' => 1,
'notUsed' => true
),
'yohoCoin' => '0',
'invoice' => true,
'sumPrice' => 900,
'salePrice' => 90,
'freight' => 0,
'price' => 810
)
);
$this->_view->display('order-ensure', $data);
}
/**
* 读取chose-panel内容
*/
public function tplAction()
{
if($this->isAjax()) {
$data = file_get_contents('../../../template/m.yohobuy.com/partials/shopping-cart/chose-panel.phtml');
echo($data);
}
}
}