|
@@ -651,6 +651,11 @@ class OrderController extends Controller
|
651
|
651
|
$order['payment_type'] = (int)$request->input('payment_type'); //支付方式
|
652
|
652
|
$order['buyer_phone'] = $request->input('buyer_phone');
|
653
|
653
|
$order['use_coupon'] = (int)$request->input('use_coupon');
|
|
654
|
+ $order['use_b_gift'] = (int)$request->input('use_b_gift');
|
|
655
|
+ $m_gift_id = (int)$request->input('m_gift_id');
|
|
656
|
+ if($m_gift_id>0){
|
|
657
|
+ $order['use_m_gift'] = 1;
|
|
658
|
+ }
|
654
|
659
|
|
655
|
660
|
//充值卡验证余额
|
656
|
661
|
if($order['payment_type'] == 4){
|
|
@@ -726,8 +731,7 @@ class OrderController extends Controller
|
726
|
731
|
|
727
|
732
|
#加赠品逻辑
|
728
|
733
|
$use_coupon = (int)$request->input('use_coupon');
|
729
|
|
- $m_gift_id = (int)$request->input('m_gift_id');
|
730
|
|
- $b_gift_id = (int)$request->input('b_gift_id');
|
|
734
|
+ $use_b_gift = (int)$request->input('use_b_gift');
|
731
|
735
|
if($use_coupon == 1){
|
732
|
736
|
$coupon = DB::table('customer_coupons')->where('phone', $order['buyer_phone'])->where('is_use',0)->orderBy('id', 'desc')->first();
|
733
|
737
|
if(!empty($coupon)){
|
|
@@ -758,23 +762,26 @@ class OrderController extends Controller
|
758
|
762
|
$receive_gift['gift_type'] = 0;
|
759
|
763
|
DB::table('customer_gift_receives')->insert($receive_gift);
|
760
|
764
|
}
|
761
|
|
- if($b_gift_id>0){
|
762
|
|
- $b_gift = DB::table('customer_month_gift')->where('id', $b_gift_id)->where('type', 1)->first();
|
763
|
|
- $order_b_gift = array();
|
764
|
|
- $b_sku = GoodsSkus::where('id', $b_gift->sku_id)->first();
|
765
|
|
- $order_b_gift['sku_id'] = $b_gift->sku_id;
|
766
|
|
- $order_b_gift['order_id'] = $res;
|
767
|
|
- $order_b_gift['goods_id'] = $b_sku->goodsCode;
|
768
|
|
- $order_b_gift['num'] = $b_gift->num;
|
769
|
|
- $order_b_gift['price'] = $b_sku->price;
|
770
|
|
- $order_b_gift['gift_id'] = $b_gift_id;
|
771
|
|
- $order_gift_insert = DB::table('order_goods_skus')->insert($order_b_gift);
|
|
765
|
+ $mdate = date('Y-m-01');
|
|
766
|
+ if($use_b_gift>0){
|
|
767
|
+ $b_gifts = DB::table('customer_month_gift')->where('mtime', $mdate)->where('type', 1)->get();
|
|
768
|
+ $b_gifts = json_decode(json_encode($b_gifts),true);
|
|
769
|
+ foreach($b_gifts as $b_gift){
|
|
770
|
+ $order_b_gift = array();
|
|
771
|
+ $b_sku = GoodsSkus::where('id', $b_gift['sku_id'])->first();
|
|
772
|
+ $order_b_gift['sku_id'] = $b_gift['sku_id'];
|
|
773
|
+ $order_b_gift['order_id'] = $res;
|
|
774
|
+ $order_b_gift['goods_id'] = $b_sku->goodsCode;
|
|
775
|
+ $order_b_gift['num'] = $b_gift['num'];
|
|
776
|
+ $order_b_gift['price'] = $b_sku->price;
|
|
777
|
+ $order_b_gift['gift_id'] = $b_gift['id'];
|
|
778
|
+ $order_gift_insert = DB::table('order_goods_skus')->insert($order_b_gift);
|
|
779
|
+ }
|
772
|
780
|
#记录领取
|
773
|
781
|
$receive_gift = array();
|
774
|
782
|
$receive_gift['phone'] = $order['buyer_phone'];
|
775
|
783
|
$receive_gift['dtime'] = date('Y-m-d');
|
776
|
784
|
$receive_gift['order_id'] = $res;
|
777
|
|
- $receive_gift['gift_id'] = $b_gift_id;
|
778
|
785
|
$receive_gift['gift_type'] = 1;
|
779
|
786
|
DB::table('customer_gift_receives')->insert($receive_gift);
|
780
|
787
|
}
|
|
@@ -1019,6 +1026,12 @@ class OrderController extends Controller
|
1019
|
1026
|
$order['payment_type'] = (int)$request->input('payment_type'); //支付方式
|
1020
|
1027
|
$order['use_coupon'] = (int)$request->input('use_coupon');
|
1021
|
1028
|
$order['buyer_phone'] = $request->input('buyer_phone');
|
|
1029
|
+ $order['use_b_gift'] = (int)$request->input('use_b_gift');
|
|
1030
|
+
|
|
1031
|
+ $m_gift_id = (int)$request->input('m_gift_id');
|
|
1032
|
+ if($m_gift_id>0){
|
|
1033
|
+ $order['use_m_gift'] = 1;
|
|
1034
|
+ }
|
1022
|
1035
|
|
1023
|
1036
|
//$order['status'] = (int)$request->input('status');
|
1024
|
1037
|
$order['should_amount'] = $request->input('should_amount');
|
|
@@ -1228,8 +1241,8 @@ class OrderController extends Controller
|
1228
|
1241
|
|
1229
|
1242
|
#新加逻辑,使用优惠券,赠礼
|
1230
|
1243
|
$use_coupon = (int)$request->input('use_coupon');
|
1231
|
|
- $m_gift_id = (int)$request->input('m_gift_id');
|
1232
|
|
- $b_gift_id = (int)$request->input('b_gift_id');
|
|
1244
|
+ $use_b_gift = (int)$request->input('use_b_gift');
|
|
1245
|
+
|
1233
|
1246
|
if($use_coupon == 1 && $old_order->use_coupon != 1){
|
1234
|
1247
|
$coupon = DB::table('customer_coupons')->where('phone', $order['buyer_phone'])->where('is_use',0)->orderBy('id', 'desc')->first();
|
1235
|
1248
|
if(!empty($coupon)){
|
|
@@ -1245,7 +1258,7 @@ class OrderController extends Controller
|
1245
|
1258
|
#查询本单使用赠礼
|
1246
|
1259
|
$order_gifts = DB::table('order_goods_skus')->where('is_del', 0)->where('order_id', $id)->where('gift_id','>',0)->lists('gift_id');
|
1247
|
1260
|
$order_m_gift_id = DB::table('customer_month_gift')->whereIn('id', $order_gifts)->where('type', 0)->pluck('id');
|
1248
|
|
- $order_b_gift_id = DB::table('customer_month_gift')->whereIn('id', $order_gifts)->where('type', 1)->pluck('id');
|
|
1261
|
+ $order_b_gift_ids = DB::table('customer_month_gift')->whereIn('id', $order_gifts)->where('type', 1)->lists('id');
|
1249
|
1262
|
|
1250
|
1263
|
if($m_gift_id>0 && empty($order_m_gift_id) ){
|
1251
|
1264
|
$m_gift = DB::table('customer_month_gift')->where('id', $m_gift_id)->where('type', 0)->first();
|
|
@@ -1292,51 +1305,32 @@ class OrderController extends Controller
|
1292
|
1305
|
DB::table('order_goods_skus')->where('gift_id', $order_m_gift_id)->where('order_id', $id)->update(['is_del'=>1]);
|
1293
|
1306
|
DB::table('customer_gift_receives')->where('order_id', $id)->where('gift_id', $order_m_gift_id)->update(['is_del'=>1]);
|
1294
|
1307
|
}
|
1295
|
|
- if($b_gift_id>0 && empty($order_b_gift_id) ){
|
1296
|
|
- $b_gift = DB::table('customer_month_gift')->where('id', $b_gift_id)->where('type', 1)->first();
|
1297
|
|
- $order_b_gift = array();
|
1298
|
|
- $b_sku = GoodsSkus::where('id', $b_gift->sku_id)->first();
|
1299
|
|
- $order_b_gift['sku_id'] = $b_gift->sku_id;
|
1300
|
|
- $order_b_gift['order_id'] = $id;
|
1301
|
|
- $order_b_gift['goods_id'] = $b_sku->goodsCode;
|
1302
|
|
- $order_b_gift['num'] = $b_gift->num;
|
1303
|
|
- $order_b_gift['price'] = $b_sku->price;
|
1304
|
|
- $order_b_gift['gift_id'] = $b_gift_id;
|
1305
|
|
- $order_gift_insert = DB::table('order_goods_skus')->insert($order_b_gift);
|
1306
|
|
- #记录领取
|
1307
|
|
- $receive_gift = array();
|
1308
|
|
- $receive_gift['phone'] = $order['buyer_phone'];
|
1309
|
|
- $receive_gift['dtime'] = date('Y-m-d');
|
1310
|
|
- $receive_gift['order_id'] = $id;
|
1311
|
|
- $receive_gift['gift_id'] = $b_gift_id;
|
1312
|
|
- $receive_gift['gift_type'] = 1;
|
1313
|
|
- DB::table('customer_gift_receives')->insert($receive_gift);
|
1314
|
|
- }elseif($b_gift_id>0 && $b_gift_id != $order_b_gift_id){
|
1315
|
|
- DB::table('order_goods_skus')->where('gift_id', $order_b_gift_id)->where('order_id', $id)->update(['is_del'=>1]);
|
1316
|
|
- DB::table('customer_gift_receives')->where('order_id', $id)->where('gift_id', $order_b_gift_id)->update(['is_del'=>1]);
|
1317
|
|
-
|
1318
|
|
- $b_gift = DB::table('customer_month_gift')->where('id', $b_gift_id)->where('type', 1)->first();
|
1319
|
|
- $order_b_gift = array();
|
1320
|
|
- $b_sku = GoodsSkus::where('id', $b_gift->sku_id)->first();
|
1321
|
|
- $order_b_gift['sku_id'] = $b_gift->sku_id;
|
1322
|
|
- $order_b_gift['order_id'] = $id;
|
1323
|
|
- $order_b_gift['goods_id'] = $b_sku->goodsCode;
|
1324
|
|
- $order_b_gift['num'] = $b_gift->num;
|
1325
|
|
- $order_b_gift['price'] = $b_sku->price;
|
1326
|
|
- $order_b_gift['gift_id'] = $b_gift_id;
|
1327
|
|
- $order_gift_insert = DB::table('order_goods_skus')->insert($order_b_gift);
|
|
1308
|
+
|
|
1309
|
+ $mdate = date('Y-m-01', strtotime($old_order['create_time']));
|
|
1310
|
+ if($use_b_gift>0 && empty($order_b_gift_ids) ){
|
|
1311
|
+ $b_gifts = DB::table('customer_month_gift')->where('mtime', $mdate)->where('type', 1)->get();
|
|
1312
|
+ $b_gifts = json_decode(json_encode($b_gifts),true);
|
|
1313
|
+ foreach($b_gifts as $b_gift){
|
|
1314
|
+ $order_b_gift = array();
|
|
1315
|
+ $b_sku = GoodsSkus::where('id', $b_gift['sku_id'])->first();
|
|
1316
|
+ $order_b_gift['sku_id'] = $b_gift['sku_id'];
|
|
1317
|
+ $order_b_gift['order_id'] = $id;
|
|
1318
|
+ $order_b_gift['goods_id'] = $b_sku->goodsCode;
|
|
1319
|
+ $order_b_gift['num'] = $b_gift['num'];
|
|
1320
|
+ $order_b_gift['price'] = $b_sku->price;
|
|
1321
|
+ $order_b_gift['gift_id'] = $b_gift['id'];
|
|
1322
|
+ $order_gift_insert = DB::table('order_goods_skus')->insert($order_b_gift);
|
|
1323
|
+ }
|
1328
|
1324
|
#记录领取
|
1329
|
1325
|
$receive_gift = array();
|
1330
|
1326
|
$receive_gift['phone'] = $order['buyer_phone'];
|
1331
|
1327
|
$receive_gift['dtime'] = date('Y-m-d');
|
1332
|
1328
|
$receive_gift['order_id'] = $id;
|
1333
|
|
- $receive_gift['gift_id'] = $b_gift_id;
|
1334
|
1329
|
$receive_gift['gift_type'] = 1;
|
1335
|
1330
|
DB::table('customer_gift_receives')->insert($receive_gift);
|
1336
|
|
-
|
1337
|
|
- }elseif($b_gift_id==0 && $order_b_gift_id>0){
|
1338
|
|
- DB::table('order_goods_skus')->where('gift_id', $order_b_gift_id)->where('order_id', $id)->update(['is_del'=>1]);
|
1339
|
|
- DB::table('customer_gift_receives')->where('order_id', $id)->where('gift_id', $order_b_gift_id)->update(['is_del'=>1]);
|
|
1331
|
+ }elseif($use_b_gift==0 && !empty($order_b_gift_ids)){
|
|
1332
|
+ DB::table('order_goods_skus')->whereIn('gift_id', $order_b_gift_ids)->where('order_id', $id)->update(['is_del'=>1]);
|
|
1333
|
+ DB::table('customer_gift_receives')->where('order_id', $id)->where('gift_type', 1)->update(['is_del'=>1]);
|
1340
|
1334
|
}
|
1341
|
1335
|
|
1342
|
1336
|
DB::commit();
|