|
@@ -104,7 +104,7 @@ class Order extends Api |
|
@@ -104,7 +104,7 @@ class Order extends Api |
104
|
if ($v['stock_num'] == 0) $this->error($v['ch_name'] . '商品库存不足');
|
104
|
if ($v['stock_num'] == 0) $this->error($v['ch_name'] . '商品库存不足');
|
105
|
//判断用户收货区域是否有库存
|
105
|
//判断用户收货区域是否有库存
|
106
|
$areaStock = $goodsModel->getAreaStockNum(['g.id' => $v['id'], 'd.area_id' => $provinceId]);
|
106
|
$areaStock = $goodsModel->getAreaStockNum(['g.id' => $v['id'], 'd.area_id' => $provinceId]);
|
107
|
- if (!$areaStock) $data['is_lack_stock'] = 1;
|
107
|
+ if (!empty($areaStock) && $areaStock['stock_num'] == 0) $data['is_lack_stock'] = 1;
|
108
|
}
|
108
|
}
|
109
|
}
|
109
|
}
|
110
|
|
110
|
|
|
@@ -118,12 +118,12 @@ class Order extends Api |
|
@@ -118,12 +118,12 @@ class Order extends Api |
118
|
if ($v['stock_num'] == 0) $this->error($v['ch_name'] . '商品库存不足');
|
118
|
if ($v['stock_num'] == 0) $this->error($v['ch_name'] . '商品库存不足');
|
119
|
//判断用户收货区域是否有库存
|
119
|
//判断用户收货区域是否有库存
|
120
|
$areaStock = $this->integralGoodsModel->getAreaStockNum(['g.id' => $v['id'], 'd.area_id' => $provinceId]);
|
120
|
$areaStock = $this->integralGoodsModel->getAreaStockNum(['g.id' => $v['id'], 'd.area_id' => $provinceId]);
|
121
|
- if (!$areaStock) $data['is_lack_stock'] = 1;
|
121
|
+ if (!empty($areaStock) && $areaStock['stock_num'] == 0) $data['is_lack_stock'] = 1;
|
122
|
}
|
122
|
}
|
123
|
}
|
123
|
}
|
124
|
//判断优惠码是否可用
|
124
|
//判断优惠码是否可用
|
125
|
if (!empty($ticketCode)) {
|
125
|
if (!empty($ticketCode)) {
|
126
|
- $ticketCodeInfo = $ticketCodeModel->where('code', $ticketCode)->field('user_id,validtime')->find();
|
126
|
+ $ticketCodeInfo = $ticketCodeModel->where('code', $ticketCode)->find();
|
127
|
if (!$ticketCodeInfo) $this->error('优惠码不存在!');
|
127
|
if (!$ticketCodeInfo) $this->error('优惠码不存在!');
|
128
|
if ($ticketCodeInfo['validtime'] < time()) $this->error('优惠码已过期!');
|
128
|
if ($ticketCodeInfo['validtime'] < time()) $this->error('优惠码已过期!');
|
129
|
if ($ticketCodeInfo['user_id']) $this->error('优惠码已使用!');
|
129
|
if ($ticketCodeInfo['user_id']) $this->error('优惠码已使用!');
|
|
@@ -268,7 +268,7 @@ class Order extends Api |
|
@@ -268,7 +268,7 @@ class Order extends Api |
268
|
if (!$validate->check($param)) {
|
268
|
if (!$validate->check($param)) {
|
269
|
$this->error($validate->getError());
|
269
|
$this->error($validate->getError());
|
270
|
}
|
270
|
}
|
271
|
- if ($param['pay_type'] == 3 || $param['pay_type'] == 4) $this->error('员工或代理不能使用余额支付!');
|
271
|
+ if (($param['pay_type'] == 2 && $this->user['type'] == 3) || ($param['pay_type'] == 2 && $this->user['type'] == 4)) $this->error('员工或代理不能使用余额支付!');
|
272
|
//判断优惠券和优惠码不能同时使用
|
272
|
//判断优惠券和优惠码不能同时使用
|
273
|
if (!empty($param['ticket_code']) && !empty($param['ticket_user_id'])) $this->error('优惠券与优惠码不能同时使用!');
|
273
|
if (!empty($param['ticket_code']) && !empty($param['ticket_user_id'])) $this->error('优惠券与优惠码不能同时使用!');
|
274
|
//获取普通商品id
|
274
|
//获取普通商品id
|
|
@@ -383,11 +383,11 @@ class Order extends Api |
|
@@ -383,11 +383,11 @@ class Order extends Api |
383
|
'pay_total' => $data['price'],
|
383
|
'pay_total' => $data['price'],
|
384
|
'discount_price' => $data['discount_price'],
|
384
|
'discount_price' => $data['discount_price'],
|
385
|
'score' => $data['integral'],
|
385
|
'score' => $data['integral'],
|
386
|
- 'present_id' => !empty($data['present_id']) ? $data['present_id'] : '',
|
386
|
+ 'present_id' => !empty($param['present_id']) ? $param['present_id'] : '',
|
387
|
'postage_total' => $postage,
|
387
|
'postage_total' => $postage,
|
388
|
'postage_type' => $param['postage_type'],
|
388
|
'postage_type' => $param['postage_type'],
|
389
|
- 'postage_date' => $param['postage_date'],
|
|
|
390
|
- 'postage_time' => $param['postage_time'],
|
389
|
+ 'postage_date' => !empty($data['postage_date']) ? $data['postage_date'] : '',
|
|
|
390
|
+ 'postage_time' => !empty($data['postage_time']) ? $data['postage_time'] : '',
|
391
|
'user_ticket_id' => !empty($data['user_ticket_id']) ? $data['user_ticket_id'] : '',
|
391
|
'user_ticket_id' => !empty($data['user_ticket_id']) ? $data['user_ticket_id'] : '',
|
392
|
'ticket_price' => !empty($data['ticket_discount_price']) ? $data['ticket_discount_price'] : '',
|
392
|
'ticket_price' => !empty($data['ticket_discount_price']) ? $data['ticket_discount_price'] : '',
|
393
|
'ticketcode_id' => !empty($data['ticketcode_id']) ? $data['ticketcode_id'] : '',
|
393
|
'ticketcode_id' => !empty($data['ticketcode_id']) ? $data['ticketcode_id'] : '',
|
|
@@ -472,6 +472,384 @@ class Order extends Api |
|
@@ -472,6 +472,384 @@ class Order extends Api |
472
|
}
|
472
|
}
|
473
|
}
|
473
|
}
|
474
|
|
474
|
|
|
|
475
|
+ /**
|
|
|
476
|
+ * @ApiTitle (确认订单(积分商品))
|
|
|
477
|
+ * @ApiSummary (确认订单(积分商品))
|
|
|
478
|
+ * @ApiMethod (POST)
|
|
|
479
|
+ * @ApiHeaders (name=token, type=string, required=true description="请求的Token")
|
|
|
480
|
+ * @ApiParams (name=goods_id, type=string, required=true, description="商品id")
|
|
|
481
|
+ * @ApiParams (name=ticket_user_id, type=string, required=false, description="用户优惠券id")
|
|
|
482
|
+ * @ApiParams (name=ticket_code, type=string, required=false, description="优惠码")
|
|
|
483
|
+ * @ApiParams (name=province_id, type=string, required=true, description="省id")
|
|
|
484
|
+ * @ApiParams (name=city_id, type=string, required=true, description="市")
|
|
|
485
|
+ * @ApiParams (name=county_id, type=string, required=true, description="县")
|
|
|
486
|
+ * @ApiParams (name=postage_type, type=string, required=true, description="配送类型:1=普通配送,2=闪送")
|
|
|
487
|
+ * @ApiRoute (/api/order/orderIntegral)
|
|
|
488
|
+ * @ApiReturn({
|
|
|
489
|
+ "code": 1,
|
|
|
490
|
+ "msg": "success",
|
|
|
491
|
+ "time": "1587691008",
|
|
|
492
|
+ "data": {
|
|
|
493
|
+ "price": 263.7, 总价
|
|
|
494
|
+ "discount_price": 12.3, 折扣价
|
|
|
495
|
+ "original_price": 246, 原价
|
|
|
496
|
+ "ticketcode_discount_price": 5, 优惠码优惠价
|
|
|
497
|
+ "ticket_discount_price": 10, 优惠券优惠价
|
|
|
498
|
+ "integral": 0, 积分
|
|
|
499
|
+ "postage": "30.00" 运费
|
|
|
500
|
+ }
|
|
|
501
|
+ },
|
|
|
502
|
+ })
|
|
|
503
|
+ */
|
|
|
504
|
+ public function orderIntegral()
|
|
|
505
|
+ {
|
|
|
506
|
+ $carModel = new \app\api\model\Car();
|
|
|
507
|
+ $goodsModel = new \app\api\model\Goods();
|
|
|
508
|
+ $ticketCodeModel = new \app\api\model\Ticketcode();
|
|
|
509
|
+ $userTicketModel = new \app\api\model\UserTicket();
|
|
|
510
|
+ $userId = $this->getUserId();
|
|
|
511
|
+ $goodsId = $this->request->param('goods_id');
|
|
|
512
|
+ $ticketId = $this->request->param('ticket_user_id');
|
|
|
513
|
+ $ticketCode = $this->request->param('ticket_code');
|
|
|
514
|
+ $provinceId = $this->request->param('province_id');
|
|
|
515
|
+ $cityId = $this->request->param('city_id');
|
|
|
516
|
+ $countyId = $this->request->param('county_id');
|
|
|
517
|
+ $postageType = $this->request->param('postage_type');
|
|
|
518
|
+ if (empty($goodsId)) $this->error('缺少参数 goods_id!');
|
|
|
519
|
+ if (empty($provinceId)) $this->error('缺少参数 province_id!');
|
|
|
520
|
+ if (empty($cityId)) $this->error('缺少参数 city_id!');
|
|
|
521
|
+ if (empty($countyId)) $this->error('缺少参数 county_id!');
|
|
|
522
|
+ if (empty($postageType)) $this->error('缺少参数 postage_type!');
|
|
|
523
|
+ //判断优惠券和优惠码不能同时使用
|
|
|
524
|
+ if (!empty($ticketCode) && !empty($ticketId)) $this->error('优惠券与优惠码不能同时使用!');
|
|
|
525
|
+
|
|
|
526
|
+
|
|
|
527
|
+ //获取积分商品状态
|
|
|
528
|
+ $goodsInfo = $this->integralGoodsModel->where(['id' => $goodsId])->field('id,status,stock_num,goods_price,integral')->find();
|
|
|
529
|
+
|
|
|
530
|
+ //判断商品是否有库存和状态
|
|
|
531
|
+ if ($goodsInfo['status'] == 2) $this->error($goodsInfo['ch_name'] . '商品已下架');
|
|
|
532
|
+ if ($goodsInfo['stock_num'] == 0) $this->error($goodsInfo['ch_name'] . '商品库存不足');
|
|
|
533
|
+ //判断用户收货区域是否有库存
|
|
|
534
|
+ $areaStock = $this->integralGoodsModel->getAreaStockNum(['g.id' => $goodsInfo['id'], 'd.area_id' => $provinceId]);
|
|
|
535
|
+ if (!empty($areaStock) && $areaStock['stock_num'] == 0) $data['is_lack_stock'] = 1;
|
|
|
536
|
+
|
|
|
537
|
+ //判断优惠码是否可用
|
|
|
538
|
+ if (!empty($ticketCode)) {
|
|
|
539
|
+ $ticketCodeInfo = $ticketCodeModel->where('code', $ticketCode)->find();
|
|
|
540
|
+ if (!$ticketCodeInfo) $this->error('优惠码不存在!');
|
|
|
541
|
+ if ($ticketCodeInfo['validtime'] < time()) $this->error('优惠码已过期!');
|
|
|
542
|
+ if ($ticketCodeInfo['user_id']) $this->error('优惠码已使用!');
|
|
|
543
|
+ }
|
|
|
544
|
+
|
|
|
545
|
+ //判断优惠券是否可用
|
|
|
546
|
+ if (!empty($ticketId)) {
|
|
|
547
|
+ $ticketInfo = $userTicketModel->where(['user_id' => $userId, 'id' => $ticketId, 'status' => 1])->find();
|
|
|
548
|
+ if (!$ticketInfo) $this->error('优惠码不存在!');
|
|
|
549
|
+ }
|
|
|
550
|
+
|
|
|
551
|
+ //获取原价,现价,折扣
|
|
|
552
|
+ $goodsInfo['user_type'] = $this->user['type'];
|
|
|
553
|
+ $data['price'] = round(get_price($goodsInfo), 2); //折扣后价格
|
|
|
554
|
+ $data['discount_price'] = round(get_discount_price($goodsInfo), 2);//折扣金额
|
|
|
555
|
+ $data['original_price'] = $goodsInfo['goods_price'];//原价
|
|
|
556
|
+ $data['integral'] = $goodsInfo['integral']; //积分
|
|
|
557
|
+
|
|
|
558
|
+
|
|
|
559
|
+ //判断积分
|
|
|
560
|
+ if ($data['integral'] > $this->user['score']) $this->error('积分不足');
|
|
|
561
|
+ //获取运费
|
|
|
562
|
+ $is_special = $this->areaExtendModel->where(['province_id' => $provinceId])->value('is_special');
|
|
|
563
|
+ //特殊地区满200免运费
|
|
|
564
|
+ if ($is_special == 1 && $data['price'] >= 200) {
|
|
|
565
|
+ $postage = 0;
|
|
|
566
|
+ //其他地区满300免运费
|
|
|
567
|
+ } elseif ($data['price'] >= 300) {
|
|
|
568
|
+ $postage = 0;
|
|
|
569
|
+ } else {
|
|
|
570
|
+ //都不满足获取对应的运费
|
|
|
571
|
+ $postageWhere = ['province_id' => $provinceId, 'city_id' => $cityId, 'county_id' => $countyId];
|
|
|
572
|
+ if ($postageType == 2) {
|
|
|
573
|
+ //配送为闪送
|
|
|
574
|
+ $postage = $this->areaExtendModel->where($postageWhere)->value('postage2');
|
|
|
575
|
+ if (!$postage) {
|
|
|
576
|
+ $postage = $this->areaExtendModel->where(['province_id' => $provinceId])->value('postage2');
|
|
|
577
|
+ }
|
|
|
578
|
+ } else {
|
|
|
579
|
+ //配送为普通配送
|
|
|
580
|
+ $postage = $this->areaExtendModel->where($postageWhere)->value('postage1');
|
|
|
581
|
+ if (!$postage) {
|
|
|
582
|
+ $postage = $this->areaExtendModel->where(['province_id' => $provinceId])->value('postage1');
|
|
|
583
|
+ }
|
|
|
584
|
+ }
|
|
|
585
|
+ }
|
|
|
586
|
+ $data['postage'] = $postage;
|
|
|
587
|
+ $data['price'] += $postage;
|
|
|
588
|
+
|
|
|
589
|
+ //使用优惠码
|
|
|
590
|
+ if (!empty($ticketCodeInfo)) {
|
|
|
591
|
+ $data['price'] = $data['price'] - $ticketCodeInfo['price'];
|
|
|
592
|
+ $data['ticketcode_discount_price'] = $ticketCodeInfo['price'];
|
|
|
593
|
+ }
|
|
|
594
|
+
|
|
|
595
|
+ //使用优惠券
|
|
|
596
|
+ if (!empty($ticketInfo)) {
|
|
|
597
|
+ $data['price'] = $data['price'] - $ticketInfo['price'];
|
|
|
598
|
+ $data['ticket_discount_price'] = $ticketInfo['price'];
|
|
|
599
|
+ }
|
|
|
600
|
+
|
|
|
601
|
+ $this->success('success', $data);
|
|
|
602
|
+
|
|
|
603
|
+ }
|
|
|
604
|
+
|
|
|
605
|
+
|
|
|
606
|
+ /**
|
|
|
607
|
+ * @ApiTitle (创建订单(积分商品))
|
|
|
608
|
+ * @ApiSummary (创建订单(积分商品))
|
|
|
609
|
+ * @ApiMethod (POST)
|
|
|
610
|
+ * @ApiHeaders (name=token, type=string, required=true description="请求的Token")
|
|
|
611
|
+ * @ApiParams (name=goods_id, type=string, required=true, description="商品id")
|
|
|
612
|
+ * @ApiParams (name=pay_type, type=string, required=false, description="支付类型:1=微信支付,2=余额支付")
|
|
|
613
|
+ * @ApiParams (name=ticket_user_id, type=string, required=false, description="用户优惠券id")
|
|
|
614
|
+ * @ApiParams (name=ticket_code, type=string, required=false, description="优惠码")
|
|
|
615
|
+ * @ApiParams (name=province_id, type=string, required=true, description="商品收货地址省id")
|
|
|
616
|
+ * @ApiParams (name=city_id, type=string, required=true, description="商品收货地址市id")
|
|
|
617
|
+ * @ApiParams (name=county_id, type=string, required=true, description="商品收货地址县id")
|
|
|
618
|
+ * @ApiParams (name=address, type=string, required=true, description="商品收货地址")
|
|
|
619
|
+ * @ApiParams (name=name, type=string, required=true, description="商品收货人")
|
|
|
620
|
+ * @ApiParams (name=mobile, type=string, required=true, description="商品收货电话")
|
|
|
621
|
+ * @ApiParams (name=present_id, type=string, required=false, description="赠品id")
|
|
|
622
|
+ * @ApiParams (name=postage_type, type=string, required=true, description="配送类型:1=普通配送,2=闪送")
|
|
|
623
|
+ * @ApiParams (name=postage_date, type=string, required=false, description="配送日期")
|
|
|
624
|
+ * @ApiParams (name=postage_time, type=string, required=false, description="配送时间")
|
|
|
625
|
+ * @ApiParams (name=invoice_status, type=string, required=true, description="发票状态:1=个人或事业单位,2=企业,3=不需要开发票")
|
|
|
626
|
+ * @ApiParams (name=invoice_type, type=string, required=false, description="发票类型:1=纸质发票,2=电子发票")
|
|
|
627
|
+ * @ApiParams (name=invoice_email, type=string, required=false, description="电子发票邮箱")
|
|
|
628
|
+ * @ApiParams (name=taitou, type=string, required=false, description="发票抬头")
|
|
|
629
|
+ * @ApiParams (name=duty_num, type=string, required=false, description="发票税号")
|
|
|
630
|
+ * @ApiParams (name=invoice_province_id, type=string, required=false, description="发票收货地址省id")
|
|
|
631
|
+ * @ApiParams (name=invoice_city_id, type=string, required=false, description="发票收货地址市id")
|
|
|
632
|
+ * @ApiParams (name=invoice_county_id, type=string, required=false, description="发票收货地址县id")
|
|
|
633
|
+ * @ApiParams (name=invoice_address, type=string, required=false, description="发票收货地址")
|
|
|
634
|
+ * @ApiParams (name=invoice_name, type=string, required=false, description="发票收货人")
|
|
|
635
|
+ * @ApiParams (name=invoice_mobile, type=string, required=false, description="发票收货电话")
|
|
|
636
|
+ * @ApiParams (name=order_note, type=string, required=false, description="订单备注")
|
|
|
637
|
+ * @ApiRoute (/api/order/createOrderIntegral)
|
|
|
638
|
+ * @ApiReturn({
|
|
|
639
|
+
|
|
|
640
|
+ },
|
|
|
641
|
+ })
|
|
|
642
|
+ */
|
|
|
643
|
+ public function createOrderIntegral()
|
|
|
644
|
+ {
|
|
|
645
|
+ $ticketCodeModel = new \app\api\model\Ticketcode();
|
|
|
646
|
+ $userTicketModel = new \app\api\model\UserTicket();
|
|
|
647
|
+ $userId = $this->getUserId();
|
|
|
648
|
+ $param = $this->request->param();
|
|
|
649
|
+ $param['user_id'] = $userId;
|
|
|
650
|
+ $validate = new Validate([
|
|
|
651
|
+ 'goods_id' => 'require',
|
|
|
652
|
+ 'pay_type' => 'require',
|
|
|
653
|
+ 'name' => 'require',
|
|
|
654
|
+ 'mobile' => 'require',
|
|
|
655
|
+ 'address' => 'require',
|
|
|
656
|
+ 'province_id' => 'require',
|
|
|
657
|
+ 'city_id' => 'require',
|
|
|
658
|
+ 'county_id' => 'require',
|
|
|
659
|
+ 'postage_type' => 'require',
|
|
|
660
|
+ 'invoice_status' => 'require',
|
|
|
661
|
+
|
|
|
662
|
+ ]);
|
|
|
663
|
+
|
|
|
664
|
+ $validate->message([
|
|
|
665
|
+ 'goods_id' => '缺少参数 goods_id!',
|
|
|
666
|
+ 'pay_type' => '缺少参数 pay_type!',
|
|
|
667
|
+ 'name' => '缺少参数 name!',
|
|
|
668
|
+ 'mobile' => '缺少参数 mobile!',
|
|
|
669
|
+ 'address' => '缺少参数 address!',
|
|
|
670
|
+ 'province_id' => '缺少参数 province_id!',
|
|
|
671
|
+ 'city_id' => '缺少参数 city_id!',
|
|
|
672
|
+ 'county_id' => '缺少参数 county_id!',
|
|
|
673
|
+ 'postage_type' => '缺少参数 postage_type!',
|
|
|
674
|
+ 'invoice_status' => '缺少参数 invoice_status!',
|
|
|
675
|
+ ]);
|
|
|
676
|
+
|
|
|
677
|
+ if (!$validate->check($param)) {
|
|
|
678
|
+ $this->error($validate->getError());
|
|
|
679
|
+ }
|
|
|
680
|
+ if (($param['pay_type'] == 2 && $this->user['type'] == 3) || ($param['pay_type'] == 2 && $this->user['type'] == 4)) $this->error('员工或代理不能使用余额支付!');
|
|
|
681
|
+ //判断优惠券和优惠码不能同时使用
|
|
|
682
|
+ if (!empty($param['ticket_code']) && !empty($param['ticket_user_id'])) $this->error('优惠券与优惠码不能同时使用!');
|
|
|
683
|
+ //获取积分商品状态
|
|
|
684
|
+ $goodsInfo = $this->integralGoodsModel->where(['id' => $param['goods_id']])->field('id,ch_name,en_name,image,status,stock_num,goods_price,integral')->find();
|
|
|
685
|
+
|
|
|
686
|
+ //判断商品是否有库存和状态
|
|
|
687
|
+ if ($goodsInfo['status'] == 2) $this->error($goodsInfo['ch_name'] . '商品已下架');
|
|
|
688
|
+ if ($goodsInfo['stock_num'] == 0) $this->error($goodsInfo['ch_name'] . '商品库存不足');
|
|
|
689
|
+ //判断用户收货区域是否有库存
|
|
|
690
|
+ $areaStock = $this->integralGoodsModel->getAreaStockNum(['g.id' => $goodsInfo['id'], 'd.area_id' => $param['province_id']]);
|
|
|
691
|
+ if (!empty($areaStock) && $areaStock['stock_num'] == 0) $data['is_lack_stock'] = 1;
|
|
|
692
|
+
|
|
|
693
|
+ //判断优惠码是否可用
|
|
|
694
|
+ if (!empty($param['ticket_code'])) {
|
|
|
695
|
+ $ticketCodeInfo = $ticketCodeModel->where('code', $param['ticket_code'])->find();
|
|
|
696
|
+ if (!$ticketCodeInfo) $this->error('优惠码不存在!');
|
|
|
697
|
+ if ($ticketCodeInfo['validtime'] < time()) $this->error('优惠码已过期!');
|
|
|
698
|
+ if ($ticketCodeInfo['user_id']) $this->error('优惠码已使用!');
|
|
|
699
|
+ }
|
|
|
700
|
+
|
|
|
701
|
+ //判断优惠券是否可用
|
|
|
702
|
+ if (!empty($param['ticket_user_id'])) {
|
|
|
703
|
+ $ticketInfo = $userTicketModel->where(['user_id' => $userId, 'id' => $param['ticket_user_id'], 'status' => 1])->find();
|
|
|
704
|
+ if (!$ticketInfo) $this->error('优惠码不存在!');
|
|
|
705
|
+ }
|
|
|
706
|
+
|
|
|
707
|
+ //获取原价,现价,折扣
|
|
|
708
|
+ $goodsInfo['user_type'] = $this->user['type'];
|
|
|
709
|
+ $data['price'] = round(get_price($goodsInfo), 2); //折扣后价格
|
|
|
710
|
+ $data['discount_price'] = round(get_discount_price($goodsInfo), 2);//折扣金额
|
|
|
711
|
+ $data['original_price'] = $goodsInfo['goods_price'];//原价
|
|
|
712
|
+ $data['integral'] = $goodsInfo['integral']; //积分
|
|
|
713
|
+
|
|
|
714
|
+ //判断积分
|
|
|
715
|
+ if ($data['integral'] > $this->user['score']) $this->error('积分不足');
|
|
|
716
|
+ //获取运费
|
|
|
717
|
+ $is_special = $this->areaExtendModel->where(['province_id' => $param['province_id']])->value('is_special');
|
|
|
718
|
+ //特殊地区满200免运费
|
|
|
719
|
+ if ($is_special == 1 && $data['price'] >= 200) {
|
|
|
720
|
+ $postage = 0;
|
|
|
721
|
+ //其他地区满300免运费
|
|
|
722
|
+ } elseif ($data['price'] >= 300) {
|
|
|
723
|
+ $postage = 0;
|
|
|
724
|
+ } else {
|
|
|
725
|
+ //都不满足获取对应的运费
|
|
|
726
|
+ $postageWhere = ['province_id' => $param['province_id'], 'city_id' => $param['city_id'], 'county_id' => $param['county_id']];
|
|
|
727
|
+ if ($param['postage_type'] == 2) {
|
|
|
728
|
+ //配送为闪送
|
|
|
729
|
+ $postage = $this->areaExtendModel->where($postageWhere)->value('postage2');
|
|
|
730
|
+ if (!$postage) {
|
|
|
731
|
+ $postage = $this->areaExtendModel->where(['province_id' => $param['province_id']])->value('postage2');
|
|
|
732
|
+ }
|
|
|
733
|
+ } else {
|
|
|
734
|
+ //配送为普通配送
|
|
|
735
|
+ $postage = $this->areaExtendModel->where($postageWhere)->value('postage1');
|
|
|
736
|
+ if (!$postage) {
|
|
|
737
|
+ $postage = $this->areaExtendModel->where(['province_id' => $param['province_id']])->value('postage1');
|
|
|
738
|
+ }
|
|
|
739
|
+ }
|
|
|
740
|
+ }
|
|
|
741
|
+ $data['postage'] = $postage;
|
|
|
742
|
+ $data['price'] += $postage;
|
|
|
743
|
+
|
|
|
744
|
+ Db::startTrans();
|
|
|
745
|
+ try {
|
|
|
746
|
+ //使用优惠码
|
|
|
747
|
+ if (!empty($ticketCodeInfo)) {
|
|
|
748
|
+ $data['price'] = $data['price'] - $ticketCodeInfo['price'];
|
|
|
749
|
+ $data['ticketcode_discount_price'] = $ticketCodeInfo['price'];
|
|
|
750
|
+ $data['ticketcode_id'] = $ticketCodeInfo['id'];
|
|
|
751
|
+ $this->ticketCodeModel->where('id', $ticketCodeInfo['id'])->update(['user_id' => $userId]);
|
|
|
752
|
+ }
|
|
|
753
|
+
|
|
|
754
|
+ //使用优惠券
|
|
|
755
|
+ if (!empty($ticketInfo)) {
|
|
|
756
|
+ $data['price'] = $data['price'] - $ticketInfo['price'];
|
|
|
757
|
+ $data['ticket_discount_price'] = $ticketInfo['price'];
|
|
|
758
|
+ $data['user_ticket_id'] = $ticketInfo['id'];
|
|
|
759
|
+ $this->userTicketModel->where('id', $ticketInfo['id'])->update(['status' => 2]);
|
|
|
760
|
+
|
|
|
761
|
+ }
|
|
|
762
|
+
|
|
|
763
|
+ //order表数据
|
|
|
764
|
+ $orderData = [
|
|
|
765
|
+ 'order_num' => get_order_num(),
|
|
|
766
|
+ 'user_id' => $userId,
|
|
|
767
|
+ 'pay_type' => $param['pay_type'],
|
|
|
768
|
+ 'goods_total' => $data['original_price'],
|
|
|
769
|
+ 'pay_total' => $data['price'],
|
|
|
770
|
+ 'discount_price' => $data['discount_price'],
|
|
|
771
|
+ 'score' => $data['integral'],
|
|
|
772
|
+ 'present_id' => !empty($param['present_id']) ? $param['present_id'] : '',
|
|
|
773
|
+ 'postage_total' => $postage,
|
|
|
774
|
+ 'postage_type' => $param['postage_type'],
|
|
|
775
|
+ 'postage_date' => !empty($data['postage_date']) ? $data['postage_date'] : '',
|
|
|
776
|
+ 'postage_time' => !empty($data['postage_time']) ? $data['postage_time'] : '',
|
|
|
777
|
+ 'user_ticket_id' => !empty($data['user_ticket_id']) ? $data['user_ticket_id'] : '',
|
|
|
778
|
+ 'ticket_price' => !empty($data['ticket_discount_price']) ? $data['ticket_discount_price'] : '',
|
|
|
779
|
+ 'ticketcode_id' => !empty($data['ticketcode_id']) ? $data['ticketcode_id'] : '',
|
|
|
780
|
+ 'ticketcode_price' => !empty($data['ticketcode_discount_price']) ? $data['ticketcode_discount_price'] : '',
|
|
|
781
|
+ 'invoice_status' => $param['invoice_status'],
|
|
|
782
|
+ 'invoice_type' => !empty($param['invoice_type']) ? $param['invoice_type'] : '',
|
|
|
783
|
+ 'invoice_email' => !empty($param['invoice_email']) ? $param['invoice_email'] : '',
|
|
|
784
|
+ 'taitou' => !empty($param['taitou']) ? $param['taitou'] : '',
|
|
|
785
|
+ 'duty_num' => !empty($param['duty_num']) ? $param['duty_num'] : '',
|
|
|
786
|
+ 'order_note' => !empty($param['order_note']) ? $param['order_note'] : '',
|
|
|
787
|
+ 'type' => 2,
|
|
|
788
|
+ 'status' => 1,
|
|
|
789
|
+ 'createtime' => time(),
|
|
|
790
|
+ 'updatetime' => time(),
|
|
|
791
|
+ ];
|
|
|
792
|
+ $res1 = $this->orderModel->insertGetId($orderData);
|
|
|
793
|
+
|
|
|
794
|
+ //收货地址数据
|
|
|
795
|
+ $orderAddress = [
|
|
|
796
|
+ 'order_id' => $res1,
|
|
|
797
|
+ 'name' => $param['name'],
|
|
|
798
|
+ 'mobile' => $param['mobile'],
|
|
|
799
|
+ 'address' => $param['address'],
|
|
|
800
|
+ 'province_id' => $param['province_id'],
|
|
|
801
|
+ 'city_id' => $param['city_id'],
|
|
|
802
|
+ 'county_id' => $param['county_id'],
|
|
|
803
|
+ 'createtime' => time(),
|
|
|
804
|
+ 'updatetime' => time(),
|
|
|
805
|
+ ];
|
|
|
806
|
+ $res2 = $this->orderAddressModel->insertData($orderAddress);
|
|
|
807
|
+ if ($param['invoice_status'] != 3) {
|
|
|
808
|
+ //收货地址数据
|
|
|
809
|
+ $orderAddressInvoice = [
|
|
|
810
|
+ 'order_id' => $res1,
|
|
|
811
|
+ 'name' => $param['invoice_name'],
|
|
|
812
|
+ 'mobile' => $param['invoice_mobile'],
|
|
|
813
|
+ 'address' => $param['invoice_address'],
|
|
|
814
|
+ 'province_id' => $param['invoice_province_id'],
|
|
|
815
|
+ 'city_id' => $param['invoice_city_id'],
|
|
|
816
|
+ 'county_id' => $param['invoice_county_id'],
|
|
|
817
|
+ 'createtime' => time(),
|
|
|
818
|
+ 'updatetime' => time(),
|
|
|
819
|
+ ];
|
|
|
820
|
+ $res3 = $this->orderAddressInvoiceModel->insertData($orderAddressInvoice);
|
|
|
821
|
+ }
|
|
|
822
|
+
|
|
|
823
|
+ //获取商品详情列表
|
|
|
824
|
+ $orderInfoData = [
|
|
|
825
|
+ 'order_id' => $res1,
|
|
|
826
|
+ 'pay_type' => $param['pay_type'],
|
|
|
827
|
+ 'user_id' => $userId,
|
|
|
828
|
+ 'goods_id' => $goodsInfo['id'],
|
|
|
829
|
+ 'ch_goods_name' => $goodsInfo['ch_name'],
|
|
|
830
|
+ 'en_goods_name' => $goodsInfo['en_name'],
|
|
|
831
|
+ 'goods_image' => $goodsInfo['image'],
|
|
|
832
|
+ 'number' => 1,
|
|
|
833
|
+ 'type' => 2, //积分商品
|
|
|
834
|
+ 'score' => !empty($data['integral']) ? $data['integral'] : 0,
|
|
|
835
|
+ 'goods_total' => get_price($goodsInfo),
|
|
|
836
|
+ 'pay_total' => $data['price'],
|
|
|
837
|
+ 'postage_total' => $postage,
|
|
|
838
|
+ ];
|
|
|
839
|
+
|
|
|
840
|
+ $res4 = $this->orderInfoModel->save($orderInfoData);
|
|
|
841
|
+
|
|
|
842
|
+ if ($res1 && $res2 && $res4 && (empty($res3) || $res3)) {
|
|
|
843
|
+ Db::commit();
|
|
|
844
|
+ return true;
|
|
|
845
|
+ } else {
|
|
|
846
|
+ return false;
|
|
|
847
|
+ }
|
|
|
848
|
+ } catch (Exception $e) {
|
|
|
849
|
+ Db::rollback();
|
|
|
850
|
+ return false;
|
|
|
851
|
+ }
|
|
|
852
|
+ }
|
475
|
|
853
|
|
476
|
/**
|
854
|
/**
|
477
|
* @ApiTitle (确认订单(团购商品))
|
855
|
* @ApiTitle (确认订单(团购商品))
|
|
@@ -479,7 +857,6 @@ class Order extends Api |
|
@@ -479,7 +857,6 @@ class Order extends Api |
479
|
* @ApiMethod (POST)
|
857
|
* @ApiMethod (POST)
|
480
|
* @ApiHeaders (name=token, type=string, required=true description="请求的Token")
|
858
|
* @ApiHeaders (name=token, type=string, required=true description="请求的Token")
|
481
|
* @ApiParams (name=goods_id, type=string, required=true, description="商品id")
|
859
|
* @ApiParams (name=goods_id, type=string, required=true, description="商品id")
|
482
|
- * @ApiParams (name=number, type=string, required=true, description="商品数量")
|
|
|
483
|
* @ApiParams (name=province_id, type=string, required=true, description="省id")
|
860
|
* @ApiParams (name=province_id, type=string, required=true, description="省id")
|
484
|
* @ApiParams (name=city_id, type=string, required=true, description="市")
|
861
|
* @ApiParams (name=city_id, type=string, required=true, description="市")
|
485
|
* @ApiParams (name=county_id, type=string, required=true, description="县")
|
862
|
* @ApiParams (name=county_id, type=string, required=true, description="县")
|
|
@@ -502,43 +879,36 @@ class Order extends Api |
|
@@ -502,43 +879,36 @@ class Order extends Api |
502
|
*/
|
879
|
*/
|
503
|
public function orderTeam()
|
880
|
public function orderTeam()
|
504
|
{
|
881
|
{
|
505
|
- $goodsModel = new \app\api\model\Goods();
|
|
|
506
|
$userId = $this->getUserId();
|
882
|
$userId = $this->getUserId();
|
507
|
- $number = $this->request->param('number');
|
|
|
508
|
$goodsId = $this->request->param('goods_id');
|
883
|
$goodsId = $this->request->param('goods_id');
|
509
|
$provinceId = $this->request->param('province_id');
|
884
|
$provinceId = $this->request->param('province_id');
|
510
|
$cityId = $this->request->param('city_id');
|
885
|
$cityId = $this->request->param('city_id');
|
511
|
$countyId = $this->request->param('county_id');
|
886
|
$countyId = $this->request->param('county_id');
|
512
|
$postageType = $this->request->param('postage_type');
|
887
|
$postageType = $this->request->param('postage_type');
|
513
|
if (empty($goodsId)) $this->error('缺少参数 goods_id!');
|
888
|
if (empty($goodsId)) $this->error('缺少参数 goods_id!');
|
514
|
- if (empty($number)) $this->error('缺少参数 number!');
|
|
|
515
|
if (empty($provinceId)) $this->error('缺少参数 province_id!');
|
889
|
if (empty($provinceId)) $this->error('缺少参数 province_id!');
|
516
|
if (empty($cityId)) $this->error('缺少参数 city_id!');
|
890
|
if (empty($cityId)) $this->error('缺少参数 city_id!');
|
517
|
if (empty($countyId)) $this->error('缺少参数 county_id!');
|
891
|
if (empty($countyId)) $this->error('缺少参数 county_id!');
|
518
|
if (empty($postageType)) $this->error('缺少参数 postage_type!');
|
892
|
if (empty($postageType)) $this->error('缺少参数 postage_type!');
|
519
|
|
893
|
|
520
|
- $goodsInfo = $goodsModel->where(['id' => $goodsId])->field('id,status,stock_num')->find();
|
894
|
+ $goodsInfo = $this->goodsModel->where(['id' => $goodsId])->field('id,status,stock_num,is_group,group_num,group_price,grouptime,goods_price')->find();
|
521
|
//判断商品是否有库存和状态
|
895
|
//判断商品是否有库存和状态
|
522
|
if ($goodsInfo['status'] == 2) $this->error('商品已下架');
|
896
|
if ($goodsInfo['status'] == 2) $this->error('商品已下架');
|
523
|
if ($goodsInfo['stock_num'] == 0) $this->error('商品库存不足');
|
897
|
if ($goodsInfo['stock_num'] == 0) $this->error('商品库存不足');
|
|
|
898
|
+ if ($goodsInfo['is_group'] != 1) $this->error('该商品不是团购商品');
|
524
|
//判断用户收货区域是否有库存
|
899
|
//判断用户收货区域是否有库存
|
525
|
- $areaStock = $goodsModel->getAreaStockNum(['g.id' => $goodsId, 'd.area_id' => $provinceId]);
|
|
|
526
|
- if (!$areaStock) $data['is_lack_stock'] = 1;
|
900
|
+ $areaStock = $this->goodsModel->getAreaStockNum(['g.id' => $goodsId, 'd.area_id' => $provinceId]);
|
|
|
901
|
+ if (!empty($areaStock) && $areaStock['stock_num'] == 0) $data['is_lack_stock'] = 1;
|
527
|
|
902
|
|
528
|
//获取原价,现价,折扣
|
903
|
//获取原价,现价,折扣
|
529
|
- $priceArr = $this->carModel->getCarMoney(['id' => ['in', $carId]]);
|
|
|
530
|
$data['price'] = 0; //折扣后价格
|
904
|
$data['price'] = 0; //折扣后价格
|
531
|
$data['discount_price'] = 0; //折扣金额
|
905
|
$data['discount_price'] = 0; //折扣金额
|
532
|
$data['original_price'] = 0; //原价
|
906
|
$data['original_price'] = 0; //原价
|
533
|
- $data['integral'] = 0; //积分
|
|
|
534
|
- foreach ($priceArr as $k => $v) {
|
|
|
535
|
- $priceArr[$k]['user_type'] = $this->user['type'];
|
|
|
536
|
- $data['price'] += round(get_price($v), 2);
|
|
|
537
|
- $data['discount_price'] += round(get_discount_price($v), 2);
|
|
|
538
|
- $data['original_price'] += $v['goods_price'];
|
|
|
539
|
- if (!empty($v['integral'])) $data['integral'] += $v['integral'];
|
907
|
+ $goodsInfo['user_type'] = $this->user['type'];
|
|
|
908
|
+ $data['price'] += round(get_price($goodsInfo), 2);
|
|
|
909
|
+ $data['discount_price'] += round(get_discount_price($goodsInfo), 2);
|
|
|
910
|
+ $data['original_price'] += $goodsInfo['group_price'];
|
540
|
|
911
|
|
541
|
- }
|
|
|
542
|
//获取运费
|
912
|
//获取运费
|
543
|
$is_special = $this->areaExtendModel->where(['province_id' => $provinceId])->value('is_special');
|
913
|
$is_special = $this->areaExtendModel->where(['province_id' => $provinceId])->value('is_special');
|
544
|
//特殊地区满200免运费
|
914
|
//特殊地区满200免运费
|
|
@@ -572,6 +942,229 @@ class Order extends Api |
|
@@ -572,6 +942,229 @@ class Order extends Api |
572
|
|
942
|
|
573
|
}
|
943
|
}
|
574
|
|
944
|
|
|
|
945
|
+ /**
|
|
|
946
|
+ * @ApiTitle (创建订单(团购商品))
|
|
|
947
|
+ * @ApiSummary (创建订单(团购商品))
|
|
|
948
|
+ * @ApiMethod (POST)
|
|
|
949
|
+ * @ApiHeaders (name=token, type=string, required=true description="请求的Token")
|
|
|
950
|
+ * @ApiParams (name=goods_id, type=string, required=false, description="商品id")
|
|
|
951
|
+ * @ApiParams (name=team_group_id, type=string, required=false, description="拼团id")
|
|
|
952
|
+ * @ApiParams (name=pay_type, type=string, required=false, description="支付类型:1=微信支付,2=余额支付")
|
|
|
953
|
+ * @ApiParams (name=province_id, type=string, required=true, description="商品收货地址省id")
|
|
|
954
|
+ * @ApiParams (name=city_id, type=string, required=true, description="商品收货地址市id")
|
|
|
955
|
+ * @ApiParams (name=county_id, type=string, required=true, description="商品收货地址县id")
|
|
|
956
|
+ * @ApiParams (name=address, type=string, required=true, description="商品收货地址")
|
|
|
957
|
+ * @ApiParams (name=name, type=string, required=true, description="商品收货人")
|
|
|
958
|
+ * @ApiParams (name=mobile, type=string, required=true, description="商品收货电话")
|
|
|
959
|
+ * @ApiParams (name=present_id, type=string, required=false, description="赠品id")
|
|
|
960
|
+ * @ApiParams (name=postage_type, type=string, required=true, description="配送类型:1=普通配送,2=闪送")
|
|
|
961
|
+ * @ApiParams (name=postage_date, type=string, required=false, description="配送日期")
|
|
|
962
|
+ * @ApiParams (name=postage_time, type=string, required=false, description="配送时间")
|
|
|
963
|
+ * @ApiParams (name=invoice_status, type=string, required=true, description="发票状态:1=个人或事业单位,2=企业,3=不需要开发票")
|
|
|
964
|
+ * @ApiParams (name=invoice_type, type=string, required=false, description="发票类型:1=纸质发票,2=电子发票")
|
|
|
965
|
+ * @ApiParams (name=invoice_email, type=string, required=false, description="电子发票邮箱")
|
|
|
966
|
+ * @ApiParams (name=taitou, type=string, required=false, description="发票抬头")
|
|
|
967
|
+ * @ApiParams (name=duty_num, type=string, required=false, description="发票税号")
|
|
|
968
|
+ * @ApiParams (name=invoice_province_id, type=string, required=false, description="发票收货地址省id")
|
|
|
969
|
+ * @ApiParams (name=invoice_city_id, type=string, required=false, description="发票收货地址市id")
|
|
|
970
|
+ * @ApiParams (name=invoice_county_id, type=string, required=false, description="发票收货地址县id")
|
|
|
971
|
+ * @ApiParams (name=invoice_address, type=string, required=false, description="发票收货地址")
|
|
|
972
|
+ * @ApiParams (name=invoice_name, type=string, required=false, description="发票收货人")
|
|
|
973
|
+ * @ApiParams (name=invoice_mobile, type=string, required=false, description="发票收货电话")
|
|
|
974
|
+ * @ApiParams (name=order_note, type=string, required=false, description="订单备注")
|
|
|
975
|
+ * @ApiRoute (/api/order/createOrderTeam)
|
|
|
976
|
+ * @ApiReturn({
|
|
|
977
|
+
|
|
|
978
|
+ },
|
|
|
979
|
+ })
|
|
|
980
|
+ */
|
|
|
981
|
+ public function createOrderTeam()
|
|
|
982
|
+ {
|
|
|
983
|
+ $userId = $this->getUserId();
|
|
|
984
|
+ $param = $this->request->param();
|
|
|
985
|
+ $param['user_id'] = $userId;
|
|
|
986
|
+ $validate = new Validate([
|
|
|
987
|
+ 'goods_id' => 'require',
|
|
|
988
|
+ 'pay_type' => 'require',
|
|
|
989
|
+ 'name' => 'require',
|
|
|
990
|
+ 'mobile' => 'require',
|
|
|
991
|
+ 'address' => 'require',
|
|
|
992
|
+ 'province_id' => 'require',
|
|
|
993
|
+ 'city_id' => 'require',
|
|
|
994
|
+ 'county_id' => 'require',
|
|
|
995
|
+ 'postage_type' => 'require',
|
|
|
996
|
+ 'invoice_status' => 'require',
|
|
|
997
|
+
|
|
|
998
|
+ ]);
|
|
|
999
|
+
|
|
|
1000
|
+ $validate->message([
|
|
|
1001
|
+ 'goods_id' => '缺少参数 goods_id!',
|
|
|
1002
|
+ 'pay_type' => '缺少参数 pay_type!',
|
|
|
1003
|
+ 'name' => '缺少参数 name!',
|
|
|
1004
|
+ 'mobile' => '缺少参数 mobile!',
|
|
|
1005
|
+ 'address' => '缺少参数 address!',
|
|
|
1006
|
+ 'province_id' => '缺少参数 province_id!',
|
|
|
1007
|
+ 'city_id' => '缺少参数 city_id!',
|
|
|
1008
|
+ 'county_id' => '缺少参数 county_id!',
|
|
|
1009
|
+ 'postage_type' => '缺少参数 postage_type!',
|
|
|
1010
|
+ 'invoice_status' => '缺少参数 invoice_status!',
|
|
|
1011
|
+ ]);
|
|
|
1012
|
+
|
|
|
1013
|
+ if (!$validate->check($param)) {
|
|
|
1014
|
+ $this->error($validate->getError());
|
|
|
1015
|
+ }
|
|
|
1016
|
+ if (($param['pay_type'] == 2 && $this->user['type'] == 3) || ($param['pay_type'] == 2 && $this->user['type'] == 4)) $this->error('员工或代理不能使用余额支付!');
|
|
|
1017
|
+
|
|
|
1018
|
+ $goodsInfo = $this->goodsModel->where(['id' => $param['goods_id']])->field('id,status,stock_num,is_group,group_num,group_price,grouptime,goods_price,ch_name,en_name,image')->find();
|
|
|
1019
|
+ //判断商品是否有库存和状态
|
|
|
1020
|
+ if ($goodsInfo['status'] == 2) $this->error('商品已下架');
|
|
|
1021
|
+ if ($goodsInfo['stock_num'] == 0) $this->error('商品库存不足');
|
|
|
1022
|
+ if ($goodsInfo['is_group'] != 1) $this->error('该商品不是团购商品');
|
|
|
1023
|
+ //判断用户收货区域是否有库存
|
|
|
1024
|
+ $areaStock = $this->goodsModel->getAreaStockNum(['g.id' => $param['goods_id'], 'd.area_id' => $param['province_id']]);
|
|
|
1025
|
+ if (!empty($areaStock) && $areaStock['stock_num'] == 0) $data['is_lack_stock'] = 1;
|
|
|
1026
|
+
|
|
|
1027
|
+ //判断团购是否满人
|
|
|
1028
|
+ if (!empty($param['team_group_id'])) {
|
|
|
1029
|
+ $teamInfo = Db::name('team_group')->where('id', $param['team_group_id'])->field('group_num,grouptime')->find();
|
|
|
1030
|
+ $count = Db::name('team_group_info')->where('team_group_id', $param['team_group_id'])->count();
|
|
|
1031
|
+ $is_join_team = Db::name('team_group_info')->where(['team_group_id' => $param['team_group_id'], 'user_id' => $userId])->count();
|
|
|
1032
|
+ if (!$teamInfo) $this->error('没有此拼团信息');
|
|
|
1033
|
+ if ($teamInfo['grouptime'] <= time()) $this->error('拼团已失效');
|
|
|
1034
|
+ if ($teamInfo['group_num'] <= $count) $this->error('参团人数已满');
|
|
|
1035
|
+ if ($is_join_team) $this->error('您已参团了');
|
|
|
1036
|
+ }
|
|
|
1037
|
+
|
|
|
1038
|
+ //获取原价,现价,折扣
|
|
|
1039
|
+ $data['price'] = 0; //折扣后价格
|
|
|
1040
|
+ $data['discount_price'] = 0; //折扣金额
|
|
|
1041
|
+ $data['original_price'] = 0; //原价
|
|
|
1042
|
+ $goodsInfo['user_type'] = $this->user['type'];
|
|
|
1043
|
+ $data['price'] += round(get_price($goodsInfo), 2);
|
|
|
1044
|
+ $data['discount_price'] += round(get_discount_price($goodsInfo), 2);
|
|
|
1045
|
+ $data['original_price'] += $goodsInfo['group_price'];
|
|
|
1046
|
+
|
|
|
1047
|
+ //获取运费
|
|
|
1048
|
+ $is_special = $this->areaExtendModel->where(['province_id' => $param['province_id']])->value('is_special');
|
|
|
1049
|
+ //特殊地区满200免运费
|
|
|
1050
|
+ if ($is_special == 1 && $data['price'] >= 200) {
|
|
|
1051
|
+ $postage = 0;
|
|
|
1052
|
+ //其他地区满300免运费
|
|
|
1053
|
+ } elseif ($data['price'] >= 300) {
|
|
|
1054
|
+ $postage = 0;
|
|
|
1055
|
+ } else {
|
|
|
1056
|
+ //都不满足获取对应的运费
|
|
|
1057
|
+ $postageWhere = ['province_id' => $param['province_id'], 'city_id' => $param['city_id'], 'county_id' => $param['county_id']];
|
|
|
1058
|
+ if ($param['postage_type'] == 2) {
|
|
|
1059
|
+ //配送为闪送
|
|
|
1060
|
+ $postage = $this->areaExtendModel->where($postageWhere)->value('postage2');
|
|
|
1061
|
+ if (!$postage) {
|
|
|
1062
|
+ $postage = $this->areaExtendModel->where(['province_id' => $param['province_id']])->value('postage2');
|
|
|
1063
|
+ }
|
|
|
1064
|
+ } else {
|
|
|
1065
|
+ //配送为普通配送
|
|
|
1066
|
+ $postage = $this->areaExtendModel->where($postageWhere)->value('postage1');
|
|
|
1067
|
+ if (!$postage) {
|
|
|
1068
|
+ $postage = $this->areaExtendModel->where(['province_id' => $param['province_id']])->value('postage1');
|
|
|
1069
|
+ }
|
|
|
1070
|
+ }
|
|
|
1071
|
+ }
|
|
|
1072
|
+ $data['postage'] = $postage;
|
|
|
1073
|
+ $data['price'] += $postage;
|
|
|
1074
|
+
|
|
|
1075
|
+
|
|
|
1076
|
+ Db::startTrans();
|
|
|
1077
|
+ try {
|
|
|
1078
|
+ //order表数据
|
|
|
1079
|
+ $orderData = [
|
|
|
1080
|
+ 'order_num' => get_order_num(),
|
|
|
1081
|
+ 'user_id' => $userId,
|
|
|
1082
|
+ 'pay_type' => $param['pay_type'],
|
|
|
1083
|
+ 'goods_total' => $data['original_price'],
|
|
|
1084
|
+ 'pay_total' => $data['price'],
|
|
|
1085
|
+ 'discount_price' => $data['discount_price'],
|
|
|
1086
|
+ 'present_id' => !empty($param['present_id']) ? $param['present_id'] : '',
|
|
|
1087
|
+ 'team_group_id' => !empty($param['team_group_id']) ? $param['team_group_id'] : '',
|
|
|
1088
|
+ 'team_group_status' => 1,
|
|
|
1089
|
+ 'postage_total' => $postage,
|
|
|
1090
|
+ 'postage_type' => $param['postage_type'],
|
|
|
1091
|
+ 'postage_date' => !empty($data['postage_date']) ? $data['postage_date'] : '',
|
|
|
1092
|
+ 'postage_time' => !empty($data['postage_time']) ? $data['postage_time'] : '',
|
|
|
1093
|
+ 'user_ticket_id' => !empty($data['user_ticket_id']) ? $data['user_ticket_id'] : '',
|
|
|
1094
|
+ 'ticket_price' => !empty($data['ticket_discount_price']) ? $data['ticket_discount_price'] : '',
|
|
|
1095
|
+ 'ticketcode_id' => !empty($data['ticketcode_id']) ? $data['ticketcode_id'] : '',
|
|
|
1096
|
+ 'ticketcode_price' => !empty($data['ticketcode_discount_price']) ? $data['ticketcode_discount_price'] : '',
|
|
|
1097
|
+ 'invoice_status' => $param['invoice_status'],
|
|
|
1098
|
+ 'invoice_type' => !empty($param['invoice_type']) ? $param['invoice_type'] : '',
|
|
|
1099
|
+ 'invoice_email' => !empty($param['invoice_email']) ? $param['invoice_email'] : '',
|
|
|
1100
|
+ 'taitou' => !empty($param['taitou']) ? $param['taitou'] : '',
|
|
|
1101
|
+ 'duty_num' => !empty($param['duty_num']) ? $param['duty_num'] : '',
|
|
|
1102
|
+ 'order_note' => !empty($param['order_note']) ? $param['order_note'] : '',
|
|
|
1103
|
+ 'type' => 3,
|
|
|
1104
|
+ 'status' => 1,
|
|
|
1105
|
+ 'createtime' => time(),
|
|
|
1106
|
+ 'updatetime' => time(),
|
|
|
1107
|
+ ];
|
|
|
1108
|
+ $res1 = $this->orderModel->insertGetId($orderData);
|
|
|
1109
|
+
|
|
|
1110
|
+ //收货地址数据
|
|
|
1111
|
+ $orderAddress = [
|
|
|
1112
|
+ 'order_id' => $res1,
|
|
|
1113
|
+ 'name' => $param['name'],
|
|
|
1114
|
+ 'mobile' => $param['mobile'],
|
|
|
1115
|
+ 'address' => $param['address'],
|
|
|
1116
|
+ 'province_id' => $param['province_id'],
|
|
|
1117
|
+ 'city_id' => $param['city_id'],
|
|
|
1118
|
+ 'county_id' => $param['county_id'],
|
|
|
1119
|
+ 'createtime' => time(),
|
|
|
1120
|
+ 'updatetime' => time(),
|
|
|
1121
|
+ ];
|
|
|
1122
|
+ $res2 = $this->orderAddressModel->insertData($orderAddress);
|
|
|
1123
|
+ if ($param['invoice_status'] != 3) {
|
|
|
1124
|
+ //收货地址数据
|
|
|
1125
|
+ $orderAddressInvoice = [
|
|
|
1126
|
+ 'order_id' => $res1,
|
|
|
1127
|
+ 'name' => $param['invoice_name'],
|
|
|
1128
|
+ 'mobile' => $param['invoice_mobile'],
|
|
|
1129
|
+ 'address' => $param['invoice_address'],
|
|
|
1130
|
+ 'province_id' => $param['invoice_province_id'],
|
|
|
1131
|
+ 'city_id' => $param['invoice_city_id'],
|
|
|
1132
|
+ 'county_id' => $param['invoice_county_id'],
|
|
|
1133
|
+ 'createtime' => time(),
|
|
|
1134
|
+ 'updatetime' => time(),
|
|
|
1135
|
+ ];
|
|
|
1136
|
+ $res3 = $this->orderAddressInvoiceModel->insertData($orderAddressInvoice);
|
|
|
1137
|
+ }
|
|
|
1138
|
+
|
|
|
1139
|
+ //获取商品详情
|
|
|
1140
|
+ $orderInfoData = [
|
|
|
1141
|
+ 'order_id' => $res1,
|
|
|
1142
|
+ 'pay_type' => $param['pay_type'],
|
|
|
1143
|
+ 'user_id' => $userId,
|
|
|
1144
|
+ 'goods_id' => $param['goods_id'],
|
|
|
1145
|
+ 'ch_goods_name' => $goodsInfo['ch_name'],
|
|
|
1146
|
+ 'en_goods_name' => $goodsInfo['en_name'],
|
|
|
1147
|
+ 'goods_image' => $goodsInfo['image'],
|
|
|
1148
|
+ 'number' => 1, //团购商品购买数量只能是1
|
|
|
1149
|
+ 'type' => 3,
|
|
|
1150
|
+ 'goods_total' => $data['original_price'],
|
|
|
1151
|
+ 'pay_total' => $data['price'],
|
|
|
1152
|
+ 'postage_total' => $postage,
|
|
|
1153
|
+ ];
|
|
|
1154
|
+
|
|
|
1155
|
+ $res4 = $this->orderInfoModel->save($orderInfoData);
|
|
|
1156
|
+
|
|
|
1157
|
+ if ($res1 && $res2 && $res4 && (empty($res3) || $res3)) {
|
|
|
1158
|
+ Db::commit();
|
|
|
1159
|
+ return true;
|
|
|
1160
|
+ } else {
|
|
|
1161
|
+ return false;
|
|
|
1162
|
+ }
|
|
|
1163
|
+ } catch (Exception $e) {
|
|
|
1164
|
+ Db::rollback();
|
|
|
1165
|
+ return false;
|
|
|
1166
|
+ }
|
|
|
1167
|
+ }
|
575
|
|
1168
|
|
576
|
/**
|
1169
|
/**
|
577
|
* @ApiTitle (订单付款)
|
1170
|
* @ApiTitle (订单付款)
|
|
@@ -601,6 +1194,7 @@ class Order extends Api |
|
@@ -601,6 +1194,7 @@ class Order extends Api |
601
|
$this->error(__($validate->getError()));
|
1194
|
$this->error(__($validate->getError()));
|
602
|
}
|
1195
|
}
|
603
|
$order = $this->orderModel->where(['id' => $param['order_id']])->find();
|
1196
|
$order = $this->orderModel->where(['id' => $param['order_id']])->find();
|
|
|
1197
|
+ if (!$order) $this->error('订单不存在');
|
604
|
if ($order['status'] == 2) $this->error('订单已支付');
|
1198
|
if ($order['status'] == 2) $this->error('订单已支付');
|
605
|
if ($order['status'] == -1) $this->error('订单已取消');
|
1199
|
if ($order['status'] == -1) $this->error('订单已取消');
|
606
|
//判断积分
|
1200
|
//判断积分
|
|
@@ -618,6 +1212,13 @@ class Order extends Api |
|
@@ -618,6 +1212,13 @@ class Order extends Api |
618
|
if (!$is_stock) $this->error($v['ch_goods_name'] . ' 库存不足');
|
1212
|
if (!$is_stock) $this->error($v['ch_goods_name'] . ' 库存不足');
|
619
|
}
|
1213
|
}
|
620
|
}
|
1214
|
}
|
|
|
1215
|
+ //判断团购是否满人
|
|
|
1216
|
+ if (!empty($order['team_group_id'])) {
|
|
|
1217
|
+ $teamInfo = Db::name('team_group')->where('id', $order['team_group_id'])->field('group_num,grouptime')->find();
|
|
|
1218
|
+ $count = Db::name('team_group_info')->where('team_group_id', $order['team_group_id'])->count();
|
|
|
1219
|
+ if ($teamInfo['group_num'] <= $count) $this->error('参团人数已满');
|
|
|
1220
|
+ if ($teamInfo['grouptime'] <= time()) $this->error('拼团已失效');
|
|
|
1221
|
+ }
|
621
|
$amount = $order['pay_total'];
|
1222
|
$amount = $order['pay_total'];
|
622
|
$payType = $order['pay_type'];
|
1223
|
$payType = $order['pay_type'];
|
623
|
if ($payType == 2) {
|
1224
|
if ($payType == 2) {
|
|
@@ -634,4 +1235,41 @@ class Order extends Api |
|
@@ -634,4 +1235,41 @@ class Order extends Api |
634
|
//微信支付
|
1235
|
//微信支付
|
635
|
}
|
1236
|
}
|
636
|
}
|
1237
|
}
|
|
|
1238
|
+
|
|
|
1239
|
+ /**
|
|
|
1240
|
+ * @ApiTitle (取消订单)
|
|
|
1241
|
+ * @ApiSummary (取消订单)
|
|
|
1242
|
+ * @ApiMethod (POST)
|
|
|
1243
|
+ * @ApiRoute (/api/order/orderCancel)
|
|
|
1244
|
+ * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
1245
|
+ * @ApiParams (name=order_id, type=string, required=true, description="订单id")
|
|
|
1246
|
+ * @ApiReturn ({
|
|
|
1247
|
+ })
|
|
|
1248
|
+ */
|
|
|
1249
|
+ public function orderCancel()
|
|
|
1250
|
+ {
|
|
|
1251
|
+ $userId = $this->getUserId();
|
|
|
1252
|
+ $param = $this->request->param();
|
|
|
1253
|
+ $rule = [
|
|
|
1254
|
+ 'order_id' => 'require',
|
|
|
1255
|
+ ];
|
|
|
1256
|
+
|
|
|
1257
|
+ $msg = [
|
|
|
1258
|
+ 'order_id' => '缺少参数 order_id!',
|
|
|
1259
|
+ ];
|
|
|
1260
|
+
|
|
|
1261
|
+ $validate = new Validate($rule, $msg);
|
|
|
1262
|
+ $result = $validate->check($param);
|
|
|
1263
|
+ if (!$result) {
|
|
|
1264
|
+ $this->error(__($validate->getError()));
|
|
|
1265
|
+ }
|
|
|
1266
|
+ $order = $this->orderModel->where(['id' => $param['order_id']])->find();
|
|
|
1267
|
+ if (!$order) $this->error('订单不存在');
|
|
|
1268
|
+ if ($order['status'] == 2) $this->error('订单已支付');
|
|
|
1269
|
+ if ($order['status'] == -1) $this->error('订单已取消');
|
|
|
1270
|
+
|
|
|
1271
|
+ $res = $this->orderModel->orderCancel($order);
|
|
|
1272
|
+ if ($res) $this->success('取消订单成功');
|
|
|
1273
|
+ else $this->error('取消订单失败');
|
|
|
1274
|
+ }
|
637
|
} |
1275
|
} |