Index.php
30.2 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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
<?php
use Action\AbstractAction;
use Hood\Core\Security\AuthCode;
use Index\CartModel;
use Index\UserModel;
use LibModels\Wap\Home\CartData;
use LibModels\Wap\Home\UserData;
use Plugin\Encryption;
use Plugin\Helpers;
use Plugin\UdpLog;
/**
* 购物车相关的控制器
*
* @name IndexController
* @package Cart
* @copyright yoho.inc
* @version 1.0 (2015-12-16 11:47:20)
* @author gtskk <iamgtskk@gmail.com>
*/
class IndexController extends AbstractAction
{
/**
* 通过当前用户审判是否跳到登录
*
* @param boolean $useSession (true:从服务端session中检查, false:从客户端cookie中检查)
* @return void
*/
protected function auditJumpLogin($useSession = true)
{
$uid = $this->getUid($useSession);
if (!$uid) {
$isWeixin = stripos($this->server('HTTP_USER_AGENT', ''), 'MicroMessenger') !== false;
if ($isWeixin) {
$this->go(Helpers::url('/passport/login/wechat', array('refer' => $this->server('HTTP_REFERER', SITE_MAIN))));
} else {
$this->go(Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER', SITE_MAIN))));
}
}
}
/*
* 购物车首页
*/
public function indexAction()
{
$this->setTitle('购物车');
//$this->setNavHeader('购物车', true, '');
// 显示底部TAB
$this->setNavFooterTab();
$shoppingKey = Helpers::getShoppingKeyByCookie();
$uid = $this->getUid(true);
$cartType = $this->get('cartType', 'all');
$data = array(
'shoppingCartPage' => true,
'shoppingCart' => CartModel::getCartData($uid, $shoppingKey, $cartType)
);
// 根据COOKIE记录的频道进行导航定位
$channel = Helpers::getChannelByCookie();
switch ($channel) {
default:
case 1:
$data['channelboys'] = true;
break;
case 2:
$data['channelgirls'] = true;
break;
case 3:
$data['channelkids'] = true;
break;
case 4:
$data['channellifeStyle'] = true;
break;
}
// 渲染模板
$this->_view->display('index', $data);
}
/*
* 异步获取购物车数据
*/
public function getCartDataAction()
{
$result = array();
if ($this->isAjax()) {
$shoppingKey = Helpers::getShoppingKeyByCookie();
$uid = $this->getUid(true);
$result = CartModel::getCartData($uid, $shoppingKey);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
}
/**
* 异步获取购物车商品数目
*/
public function countAction()
{
$result = array();
if ($this->isAjax()) {
$uid = $this->getUid(true);
$shoppingKey = Helpers::getShoppingKeyByCookie();
$result = CartModel::getCartCount($uid, $shoppingKey);
}
$this->echoJson($result);
}
/**
* 购物车商品选择与取消
*/
public function selectAction()
{
$result = array();
if ($this->isAjax()) {
$productId = $this->post('skuList', 0);
$uid = $this->getUid(true);
$shoppingKey = Helpers::getShoppingKeyByCookie();
$result = CartModel::selectGoods($uid, $productId, $shoppingKey);
}
$this->echoJson($result);
}
/**
* 移出购物车
*/
public function delAction()
{
$result = array();
if ($this->isAjax()) {
$sku = $this->post('sku', 0);
$count = $this->post('count', 0);
$uid = $this->getUid(true);
$shoppingKey = Helpers::getShoppingKeyByCookie();
$promotionId = $this->post('promotionId', 0);
$result = CartModel::removeFromCart($uid, $sku, $count, $shoppingKey, $promotionId);
}
$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);
}
$this->echoJson($result);
}
/*
* 赠品页面
*/
public function giftAction()
{
$this->setTitle('赠品');
$this->setNavHeader('赠品', true, false);
$shoppingKey = Helpers::getShoppingKeyByCookie();
$uid = $this->getUid(true);
$cartType = $this->get('cartType', 'ordinary');
$data = array('giftPage' => true, 'cartType' => $cartType);
$data += CartModel::getCartData($uid, $shoppingKey, $cartType, true);
// 渲染模板
$this->_view->display('gift-advance', $data);
}
/*
* 加价购页面
*/
public function advanceBuyAction()
{
$this->setTitle('加价购');
$this->setNavHeader('加价购', true, false);
$shoppingKey = Helpers::getShoppingKeyByCookie();
$uid = $this->getUid(true);
$cartType = $this->get('cartType', 'ordinary');
$data = array('advanceBuyPage' => true, 'cartType' => $cartType);
$data += CartModel::getCartData($uid, $shoppingKey, $cartType, false, true);
// 渲染模板
$this->_view->display('gift-advance', $data);
}
/*
* 获取购物车商品数据
*/
public function goodinfoAction()
{
$result = array();
if ($this->isAjax()) {
$num = $this->get('buy_num', 1);
$mnum = $this->get('mnum', null);
$skn = $this->get('skn', 1);
$uid = $this->getUid(true);
$result = CartModel::cartProductData($uid, $skn, $num); // 测试skn的ID为51172055
$result['num'] = $num;
/* 量贩数据处理 */
if (!empty($mnum)) {
$bundleInfo = CartModel::handleBundleInfo($skn);
$result['discountBuy'] = $bundleInfo;
}
}
if (!isset($result['code'])) {
$this->_view->display('gift-info', array(
'cartInfo' => $result
));
} else {
echo ' ';
}
}
// /*
// * 获取购物车加价购商品数据模板
// */
// public function giftinfoTplAction()
// {
// if ($this->isAjax()) {
// echo file_get_contents($this->_view->getScriptPath() . '/../partials/cart/chose-panel.phtml');
// }
// }
/*
* 获取购物车加价购商品数据
*/
public function giftinfoAction()
{
$result = array();
if ($this->isAjax()) {
$skn = $this->get('skn', null);
$promotionId = $this->get('promotionId', null);
$result = CartModel::giftProductData($skn, $promotionId);
}
$this->_view->display('gift-info', array(
'promotionId' => $promotionId,
'cartInfo' => $result
));
}
/**
* 修改购物车商品数量
*/
public function modifyNumAction()
{
$result = array();
if ($this->isAjax()) {
$shoppingKey = $this->getSession('shoppingKey');
$uid = $this->getUid(true);
$sku = $this->post('sku', 0);
$increaseNum = $this->post('increaseNum', null);
$decreaseNum = $this->post('decreaseNum', null);
$result = CartModel::modifyProductNum($uid, $sku, $increaseNum, $decreaseNum, $shoppingKey);
}
$this->echoJson($result);
}
/**
* 修改购物车商品数据
*/
public function modifyAction()
{
$result = array();
if ($this->isAjax()) {
$shoppingKey = Helpers::getShoppingKeyByCookie();
$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);
}
$this->echoJson($result);
}
/**
* 购物车结算请求
*/
public function orderEnsureAction()
{
// 审判跳转登录页
$this->auditJumpLogin();
// 返回地址
$returnUrl = Helpers::url('/cart/index/index');
// $returnUrl = 'javascript:history.go(-1);';
$cartType = $this->get('cartType', 'ordinary');
$cookieData = $this->getCookie('order-info', null);
$orderInfo = array();
if (!empty($cookieData)) {
$orderInfo = json_decode($cookieData, true);
//如果为空,获取默认
$cartType = empty($orderInfo['cartType']) ? $cartType : $orderInfo['cartType'];
}
// 如果传递了code, sku,skn,buy_number就代表是限购商品
$limitProductCode = $this->get('limitproductcode', '');
$sku = $this->get('sku', '');
$skn = $this->get('skn', '');
$buyNumber = $this->get('buy_number', 1);
if ($limitProductCode) {
$returnUrl = $this->server('HTTP_REFERER', $returnUrl);
}
// 购物车商品为空跳转到购物车页面
$uid = $this->getUid(true);
$isAjax = $this->isAjax();
if ($this->get('activityType', null) === 'bundle') {
$activityInfo = json_decode($this->getCookie('activity-info', null), true);
$order = CartModel::cartPay($uid, 'bundle', $orderInfo, null, null, null, null,
false, $activityInfo);
} else {
$order = CartModel::cartPay($uid, $cartType, $orderInfo, $limitProductCode, $sku, $skn, $buyNumber, $isAjax);
}
if (isset($order['cartUrl'])) { // 普通或者预售商品为空时
$this->go($order['cartUrl']);
}
// 限购商品支付接口返回为空或错误时(异步请求)
if ($isAjax) {
$this->echoJson($order);
return;
}
$userData = UserData::userData($uid);
$mobile = empty($userData['data']) || empty($userData['data']['mobile']) ? '' : $userData['data']['mobile']; //用户手机
$addresslist = UserData::addressTextData($uid); //获取地址列表
//获取所选地址的手机号码
if (isset($orderInfo['address']) && !empty($orderInfo['address'])) {
foreach ($addresslist['data'] as $addresskey) {
if ($addresskey['address_id'] == $orderInfo['address']['address_id'])
$mobile = $addresskey['mobile'];
}
}
$data = array(
'orderEnsurePage' => true,
'isOrdinaryCart' => ($cartType !== 'advance'),
'orderEnsure' => $order,
'userMobile' => $mobile
);
$this->setTitle('确认订单');
$this->setNavHeader('确认订单', $returnUrl, false); // 不显示右上角home按钮
$this->_view->display('order-ensure', $data);
}
/**
* 发票信息
*/
public function invoiceInfoAction()
{
$uid = $this->getUid();
if (!$uid) {
$this->go(Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER', SITE_MAIN))));
}
$cookieData = $this->getCookie('order-info', null); //从缓存中获取电子发票信息
$orderInfo = json_decode($cookieData, true);
//当没有地址时显示用户号码
$userData = UserData::userData($uid);
$userMobile = empty($userData['data']) || empty($userData['data']['mobile']) ? '' : $userData['data']['mobile']; //用户手机
$mobile = $userMobile;
$addresslist = UserData::addressTextData($uid); //获取地址列表
do {
if (empty($orderInfo['receiverMobile']) && !isset($orderInfo['addressId']) && empty($orderInfo['addressId'])) {
break;
}
//用户手动修改号码后直接去修改后号码
if (!empty($orderInfo['receiverMobile']) && $orderInfo['isModifyTel'] == true) {
$mobile = $orderInfo['receiverMobile']; //用户号码
} else {
//未手动修改获取用户所选地址的手机号码
foreach ($addresslist['data'] as $addresskey) {
if ($addresskey['address_id'] == Encryption::decrypt($orderInfo['addressId'])) {
$mobile = $addresskey['mobile'];
}
}
}
} while (false);
if (!empty($orderInfo['invoiceType']) && !empty($orderInfo['invoiceTitle'])) {
$invoiceType = $orderInfo['invoiceType']; //发票类型ID
$invoices_type = $orderInfo['invoicesType'] * 1; //发票类型 /**纸质 1 ,电子 2 */
$invoices_title = $orderInfo['invoiceText']; //发票抬头
$invoice_Top = $orderInfo['invoiceTitle']; //单位 个人
} else {
$invoices_title = '';
$invoiceType = '7'; //发票类型ID
// $invoices_type = '1'; //发票类型 /**纸质 1 ,电子 2 */
$invoices_type = '2'; //发票类型 /**纸质 1 ,电子 2 */
$invoice_Top = '个人';
}
$data = array(
'invoiceInfoPage' => true,
'invoiceNotice' => '发票须知',
'phone' => $mobile ? substr_replace($mobile, '****', 3, 4) : '',
'completeTel' => $mobile,
'isCompany' => $invoice_Top == '单位' ? false : true,
'companyName' => $invoices_title,
'isPaper' => $invoices_type == 1 ? true : false,
'invoicesType' => array(
array(
'id' => '2',
'type' => '电子发票',
'choosed' => empty($invoices_type) || $invoices_type == 2 ? true : false,
),
array(
'id' => '1',
'type' => '纸质发票',
'choosed' => $invoices_type == 1 ? true : false,
)
),
'invoiceTitle' => array(
array(
'type' => '个人',
'choosed' => $invoice_Top == '个人' ? true : false,
),
array(
'type' => '单位',
'choosed' => $invoice_Top == '单位' ? true : false,
)
),
'content' => array(
array(
'choosed' => empty($invoiceType) || $invoiceType == 7 ? true : false,
'id' => 7,
'text' => '服装'
),
array(
'choosed' => $invoiceType == 1 ? true : false,
'id' => 1,
'text' => '图书'
),
array(
'choosed' => $invoiceType == 9 ? true : false,
'id' => 9,
'text' => '配件'
),
array(
'choosed' => $invoiceType == 11 ? true : false,
'id' => 11,
'text' => '日用品'
),
/* tar modified 161118 要求去除办公用品开票类目 */
/*array(
'choosed' => $invoiceType == 3 ? true : false,
'id' => 3,
'text' => '办公用品'
),*/
array(
'choosed' => $invoiceType == 6 ? true : false,
'id' => 6,
'text' => '体育用品'
),
array(
'choosed' => $invoiceType == 10 ? true : false,
'id' => 10,
'text' => '数码产品'
)
)
);
$this->setTitle('发票信息');
$this->setNavHeader('发票信息', true, false); // 不显示右上角home按钮
$moreUrl = $this->server('HTTP_REFERER', '/cart/index/orderEnsure');//取跳过来的url
//购物车订单进来,秒杀进来
if (strrpos($moreUrl, '/cart/index/orderEnsure') !== false || strrpos($moreUrl, '/cart/index/seckill') !== false) {
$this->setSession('addressMore', $moreUrl);
}
$data['addressMore'] = $this->getSession('addressMore');
$this->_view->display('invoice-info', $data);
}
/**
* 购物车选择改变字段,重新运算订单数据
*/
public function orderComputeAction()
{
$result = array();
if ($this->isAjax()) {
$cartType = $this->post('cartType', 'ordinary');
$deliveryWay = $this->post('deliveryId', 1);
$paymentType = $this->post('paymentTypeId', 1);
$couponCode = $this->post('couponCode', null);
$yohoCoin = $this->post('yohoCoin', null);
$productSku = $this->post('productSku', null);
$buyNumber = $this->post('buyNumber', null);
$uid = $this->getUid(true);
$skuList = $this->post('skuList', '');
$type = $this->post('type', null);
//type : tickets 门票
if ($type !== 'tickets' ) {
if ($this->post('activityType', null) === 'bundle') {
$activityInfo = json_decode($this->getCookie('activity-info', null), true);
$result = CartModel::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin, null, $activityInfo);
} else {
$result = CartModel::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin, $skuList, null);
}
} else {
// 门票
$result = CartModel::ticketsOrderCompute($uid, $productSku, $buyNumber, $yohoCoin);
}
}
$this->echoJson($result);
}
/**
* 购物车输入优惠券码使用优惠券
*/
public function couponSearchAction()
{
$result = array();
if ($this->isAjax()) {
$couponCode = $this->post('couponCode', '');
$uid = $this->getUid(true);
$result = CartModel::searchCoupon($uid, $couponCode);
}
$this->echoJson($result);
}
/**
* 购物车结算--获取优惠券列表
*/
public function couponListAction()
{
$result = array();
if ($this->isAjax()) {
$uid = $this->getUid(true);
$result = CartModel::getCouponList($uid);
}
if (empty($result)) {
// 这儿需要返回空数组,勿改!!!
echo '[]';
} else {
$this->echoJson($result);
}
}
/**
* 下单流程 选择地址
*/
public function selectAddressAction()
{
// 审判跳转登录页
$this->auditJumpLogin();
// 设置网站标题
$this->setTitle('选择地址');
$uid = $this->getUid(true);
$address = UserModel::getAddressData($uid);
$moreUrl = $this->server('HTTP_REFERER', '/cart/index/orderEnsure');//取跳过来的url
//购物车订单进来,秒杀进来
if (strrpos($moreUrl, '/cart/index/orderEnsure') !== false || strrpos($moreUrl, '/cart/index/seckill') !== false) {
$this->setSession('addressMore', $moreUrl);
}
$moreUrl = $this->getSession('addressMore');
$this->setNavHeader('选择地址', $moreUrl, false);
$this->_view->display('select-address', array(
'selectAddressPage' => true,
'pageFooter' => true,
'address' => $address,
'moreUrl' => $moreUrl
));
}
/**
* 下单流程 选择优惠券
*/
public function selectCouponAction()
{
// 审判跳转登录页
$this->auditJumpLogin();
// 设置网站标题
$this->setTitle('选择优惠券');
$this->setNavHeader('选择优惠券', Helpers::url('/cart/index/orderEnsure'), false);
$this->_view->display('select-coupon', array(
'selectCouponPage' => true,
'pageFooter' => true
));
}
/**
* 确认结算订单
*/
public function orderSubAction()
{
if ($this->isAjax()) {
$uid = $this->getUid(true);
$addressId = $this->post('addressId', null);
$addressId = Encryption::decrypt($addressId);
$cartType = $this->post('cartType', 'ordinary'); // 默认普通购物车
$deliveryTime = $this->post('deliveryTimeId', 1); // 默认只工作日配送
$deliveryWay = $this->post('deliveryId', 1); // 默认普通快递
$paymentId = $this->post('paymentTypeId', 15);
$paymentType = $this->post('paymentType', 1); // 默认在线支付
$remark = $this->post('msg', null);
$couponCode = $this->post('couponCode', null);
$yohoCoin = $this->post('yohoCoin', 1);
$skuList = $this->post('skuList', '');
$cookieData = $this->getCookie('order-info', null); //获取电子发票信息
$times = $this->post('times', 1);
//电子发票信息数组
$invoices = array();
if (!empty($cookieData)) {
$orderInfo = json_decode($cookieData, true);
$invoices['invoices_type_id'] = $orderInfo['invoiceType']; //发票类型ID
$invoices['invoices_type'] = $orderInfo['invoicesType']; //发票类型 /**纸质 1 ,电子 2 */
$invoices['receiverMobile'] = $orderInfo['receiverMobile']; //发票人手机
$invoices['invoices_title'] = empty($orderInfo['invoiceText']) ? '个人' : $orderInfo['invoiceText']; //发票抬头
}
/* 判断是否是友盟过来的用户 */
$userAgent = null;
$unionKey = '';
$unionInfo = array();
if (!empty($_COOKIE['mkt_code']) || !empty($_COOKIE['_QYH_UNION'])) {
/* tar modified 161108 添加新的联盟数据处理逻辑,兼容原有联盟数据处理,
区别是旧的北京写 cookie 加密过来,新的 node 写 cookie,没有加密 */
if (!empty($_COOKIE['_QYH_UNION'])) {
$encryData = trim(Encryption::decrypt(rawurldecode($_COOKIE['_QYH_UNION'])));
$extraIndex = strrpos($encryData, '}') + 1;
$encryObject = substr($encryData, 0, $extraIndex);
$testQyhUnion = json_decode($encryObject, true);
if (isset($testQyhUnion['client_id'])) {
$unionKey = $encryObject;
} else {
$unionKey = AuthCode::decode($_COOKIE['_QYH_UNION'], 'q_union_yohobuy');
}
} else {
$unionKey = '{"client_id":' . $_COOKIE['mkt_code'] . '}';
}
/* 检查联盟参数是否有效 */
$unionInfo = empty($unionKey) ? array() : json_decode($unionKey, true);
/* 模拟APP的User-Agent */
$userAgent = isset($unionInfo['client_id']) ? 'YOHO!Buy/3.8.2.259(Model/PC;Channel/' . $unionInfo['client_id'] . ';uid/' . $uid . ')' : null;
}
/* tar modified 161206 套餐 */
if ($this->post('activityType', null) === 'bundle') {
$activityInfo = json_decode($this->getCookie('activity-info', null), true);
$result = CartModel::orderSub($uid, $addressId, 'bundle', $deliveryTime, $deliveryWay, $invoices, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, null, $unionKey, $userAgent, $times, $activityInfo);
} else {
$result = CartModel::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoices, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList, $unionKey, $userAgent);
}
if (!empty($unionInfo)) {
$before = array(" "," ","\t","\n","\r");
$after = array("","","","","");
$result['data']['unionCookie'] = str_replace($before, $after, json_encode($unionInfo));
}
// 记录下单异常的数据
if (empty($result)) {
$message = 'uid:' . $uid . ',addressId:' . $addressId . ',cartType:' . $cartType . ',deliveryTime:' . $deliveryTime
. ',deliveryWay:' . $deliveryWay . ',yohoCoin:' . $yohoCoin
. ',paymentId:' . $paymentId . ',paymentType:' . $paymentType . ',remark:' . $remark . ',couponCode:' . $couponCode . "\n";
UdpLog::info('【下单】下单异常数据', 'message:' . $message, '返回:' . json_encode($result));
} else {
// 返回数据
// 提交成功清除Cookie
$this->setCookie('order-info', null);
if ($result['code'] === 409) {
headers_sent() || header('Content-Type: application/json; charset=utf-8;');
$result = json_encode($result);
echo urldecode($result);
exit;
} else {
$this->echoJson($result);
}
}
} else {
echo ' ';
}
}
/**
* 加入购物车
*
* @param string productSku 商品的SKU
* @param int buyNumber 购买数量
* @param int promotionId 促销ID, 加价购有关
* @param int goodsType 商品类型,0表示普通商品,1表示加价购商品
* @param int isEdit 是否是编辑商品SKU,0表示不是编辑
* @return json
*/
public function addAction()
{
$result = array();
if ($this->isAjax()) {
$shoppingKey = Helpers::getShoppingKeyByCookie();
$productSku = $this->post('productSku');
$buyNumber = $this->post('buyNumber', 1);
$goodsType = $this->post('goodsType', 0);
$promotionId = $this->post('promotionId', 0);
$isEdit = $this->post('isEdit', 0);
$uid = $this->getUid(true);
// 执行加入购物车操作
$result = CartModel::addToCart($productSku, $buyNumber, $goodsType, $isEdit, $promotionId, $uid, $shoppingKey);
// 设置加入购物车凭证到客户端浏览器
if (empty($shoppingKey) && isset($result['data']['shopping_key'])) {
$this->setCookie('_SPK', $result['data']['shopping_key'], time() + 86400 * 360);
}
}
$this->echoJson($result);
}
/**
* jit拆单/配送信息
*
*
*/
public function jitDetailAction()
{
$data = array();
$uid = $this->getUid(true);
$cartType = $this->get('cartType', ''); //购物车类型
$skuList = $this->get('skuList', ''); //cookie中记录的一些订单有关数据
$orderCode = $this->get('orderCode', ''); //订单号
$sessionKey = $this->get('sessionKey', ''); //用户会话
$deliveryId = $this->get('deliveryId', ''); //配送方式,1表示普通快递,2表示顺丰速运
$paymentType = $this->get('paymentType', ''); //支付方式,1表示在线支付,2表示货到付款
$couponCode = $this->get('couponCode', ''); //优惠券码
$yohoCoin = $this->get('yohoCoin', ''); //使用的有货币数量
$data = CartModel::getPackageInfo($uid, $cartType, $skuList, $orderCode, $sessionKey, $deliveryId, $paymentType, $couponCode, $yohoCoin);
$this->setTitle('配送信息');
if ($cartType) {
$this->setNavHeader('配送信息', $data['returnUrl']); //购物车
} else {
$this->setNavHeader('配送信息'); //订单详情页
}
$this->_view->display('jit-detail', $data);
}
/**
* 校验电子票
*
*/
public function checkTicketsAction()
{
if (!$this->isAjax()) {
exit;
}
$data = array();
$uid = $this->getUid();
do {
//判断用户登陆
if (!$uid) {
$data = array(
'code' => 401,
);
break;
}
$productSku = $this->post('productSku');
$buyNumber = $this->post('buyNumber');
$useYohoCoin = $this->post('useYohoCoin', 0);
$data = CartData::checkTickets($uid, $productSku, $buyNumber, $useYohoCoin);
} while (false);
$this->echoJson($data);
}
//电子票确认
public function ticketsConfirmAction()
{
// 审判跳转登录页
$this->auditJumpLogin();
$uid = $this->getUid();
$productSku = $this->post('productSku');
$buyNumber = $this->post('buyNumber');
if (empty($productSku) || empty($buyNumber)) {
$this->error();
}
$tickets = CartModel::getTickets($uid, $productSku, $buyNumber);
$this->setTitle('确认订单');
$this->setNavHeader('确认订单', true, false); // 不显示右上角home按钮
$tickets['orderEnsurePage'] = true;
$tickets['productSku'] = $productSku;
$tickets['buyNumber'] = $buyNumber;
$this->_view->display('tickets-confirm', $tickets);
}
//电子票下单
public function submitTicketAction()
{
$result = array();
do {
$uid = $this->getUid();
$productSku = $this->post('productSku');
$buyNumber = $this->post('buyNumber');
$mobile = $this->post('mobile');
$useYohoCoin = $this->post('useYohoCoin');
if (empty($uid) || empty($productSku) || empty($buyNumber) || empty($mobile)) {
break;
}
//联盟参数
$data = CartData::submitTicket($uid, $productSku, $buyNumber, $mobile, $useYohoCoin);
if (isset($data['code'])) {
$result = $data;
}
} while (false);
$this->echoJson($result);
}
}