Browse Source

Merge branch 'sh/28' into test01

sunhao 5 years ago
parent
commit
8ac1a395a1

+ 353 - 6
app/Http/Controllers/Admin/OrderController.php

@@ -485,7 +485,29 @@ class OrderController extends Controller
485 485
         $self_role = session('role_name');
486 486
         $createTime = date('Y-m-d H:i:s');
487 487
 
488
-        return view('order/ordercreate', ['categorylist' => $catelist, 'adminlist'=>$adminList, 'teamlist'=>$teamList, 'self_role'=>$self_role, 'createTime'=>$createTime, 'last_url' => $_SERVER['HTTP_REFERER']]);
488
+        //当月礼品
489
+        $mtime = date('Y-m-01');
490
+        $gift_info = DB::table('customer_month_gift')->where('mtime', $mtime)->get();
491
+        $gift_info = json_decode(json_encode($gift_info), true);
492
+        $m_gift=array();
493
+        $b_gift=array();
494
+        foreach($gift_info as $k=>$v){
495
+            //获取礼品信息
496
+            $goods_name = Goods::where('id', $v['goods_id'])->pluck('name');
497
+            $sku = GoodsSkus::where('id', $v['sku_id'])->first();
498
+            $data = array();
499
+            $data['id'] = $v['id'];
500
+            $data['goods_name'] = $goods_name;
501
+            $data['propsName'] = $sku['propsName'];
502
+            $data['price'] = $sku['price'];
503
+            if($v['type'] == 0){
504
+                $m_gift[] = $data;
505
+            }else{
506
+                $b_gift[] = $data;
507
+            }
508
+        }
509
+
510
+        return view('order/ordercreate', ['categorylist' => $catelist, 'adminlist'=>$adminList, 'teamlist'=>$teamList, 'self_role'=>$self_role, 'createTime'=>$createTime, 'last_url' => $_SERVER['HTTP_REFERER'], 'm_gift'=>$m_gift, 'b_gift'=>$b_gift]);
489 511
     }
490 512
     /**
491 513
      * 分组管理-进行添加操作
@@ -498,6 +520,7 @@ class OrderController extends Controller
498 520
             'customerName'           => 'required|between:1,6', 
499 521
             'receiverName'           => 'required|between:1,6', 
500 522
             'receiverMobile'           => 'required|regex:/^1[3456789]\d{9}$/',  
523
+            'buyer_phone'           => 'required|regex:/^1[3456789]\d{9}$/',  
501 524
             'fanTime'           => 'required|date', 
502 525
             'receiverState'           => 'required|between:1,5', 
503 526
             'receiverCity'           => 'required|between:1,10', 
@@ -514,6 +537,7 @@ class OrderController extends Controller
514 537
             'receiverName.required'           => '收货人不能为空', 
515 538
             'receiverName.between'           => '收货人不能超过6个字符',                  
516 539
             'receiverMobile.required'           => '收货人手机号不能为空',                   
540
+            'buyer_phone.required'           => '买家手机号不能为空',                   
517 541
             'receiverMobile.regex'           => '收货人手机号格式有误',                   
518 542
             'fanTime.required'           => '加粉时间不能为空',              
519 543
             'receiverState.required'           => '省不能为空',   
@@ -532,7 +556,7 @@ class OrderController extends Controller
532 556
 
533 557
         //redis防重复数据
534 558
         $phone = $request->input('receiverMobile');
535
-        
559
+        /*
536 560
         $redisKey = 'seafood.order_phone_add.'.$phone;
537 561
         $res = RedisModel::setnx($redisKey, 1);
538 562
         if( $res == 0 ){
@@ -540,7 +564,7 @@ class OrderController extends Controller
540 564
             return redirect('/admin/order/index')->with('info', $msg);
541 565
         }
542 566
         $res = RedisModel::expire( $redisKey, 60 );
543
-        
567
+        */
544 568
         $skus = $request->input('skus');
545 569
         $warehouse = (int)$request->input('warehouse');
546 570
         if($warehouse == 3 && empty($skus)){
@@ -625,6 +649,8 @@ class OrderController extends Controller
625 649
         $order['delivery_date'] = !empty($request->input('delivery_date')) ? $request->input('delivery_date') : date('Y-m-d'); //发货日期
626 650
         $order['order_status'] = (int)$request->input('order_status');
627 651
         $order['payment_type'] = (int)$request->input('payment_type'); //支付方式
652
+        $order['buyer_phone'] = $request->input('buyer_phone'); 
653
+        $order['use_coupon'] = (int)$request->input('use_coupon'); 
628 654
        
629 655
         //充值卡验证余额
630 656
         if($order['payment_type'] == 4){
@@ -698,6 +724,61 @@ class OrderController extends Controller
698 724
                     $order_skus_insert = DB::table('order_goods_skus')->insert($order_skus);
699 725
                 }
700 726
 
727
+                #加赠品逻辑
728
+                $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');
731
+                if($use_coupon == 1){
732
+                    $coupon = DB::table('customer_coupons')->where('phone', $order['buyer_phone'])->where('is_use',0)->orderBy('id', 'desc')->first();
733
+                    if(!empty($coupon)){
734
+                        $cup = array();
735
+                        $cup['is_use'] = 1;
736
+                        $cup['use_time'] = date('Y-m-d H:i:s');
737
+                        $cup['order_id'] = $res;
738
+                        DB::table('customer_coupons')->where('id', $coupon->id)->update($cup);
739
+                    }
740
+                }
741
+                if($m_gift_id>0){
742
+                    $m_gift = DB::table('customer_month_gift')->where('id', $m_gift_id)->where('type', 0)->first();
743
+                    $order_m_gift = array();
744
+                    $m_sku = GoodsSkus::where('id', $m_gift->sku_id)->first();
745
+                    $order_m_gift['sku_id'] = $m_gift->sku_id;
746
+                    $order_m_gift['order_id'] = $res;
747
+                    $order_m_gift['goods_id'] = $m_sku->goodsCode;
748
+                    $order_m_gift['num'] = $m_gift->num;
749
+                    $order_m_gift['price'] = $m_sku->price;
750
+                    $order_m_gift['gift_id'] = $m_gift_id;
751
+                    $order_gift_insert = DB::table('order_goods_skus')->insert($order_m_gift);
752
+                    #记录领取
753
+                    $receive_gift = array();
754
+                    $receive_gift['phone'] = $order['buyer_phone'];
755
+                    $receive_gift['dtime'] = date('Y-m-d');
756
+                    $receive_gift['order_id'] = $res;
757
+                    $receive_gift['gift_id'] = $m_gift_id;
758
+                    $receive_gift['gift_type'] = 0;
759
+                    DB::table('customer_gift_receives')->insert($receive_gift);
760
+                }
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);
772
+                    #记录领取
773
+                    $receive_gift = array();
774
+                    $receive_gift['phone'] = $order['buyer_phone'];
775
+                    $receive_gift['dtime'] = date('Y-m-d');
776
+                    $receive_gift['order_id'] = $res;
777
+                    $receive_gift['gift_id'] = $b_gift_id;
778
+                    $receive_gift['gift_type'] = 1;
779
+                    DB::table('customer_gift_receives')->insert($receive_gift);
780
+                }
781
+
701 782
                 #新加逻辑,若付款方式为充值卡/消费记录
702 783
                 if($order['payment_type'] == 4){
703 784
                     $consum = new CustomerConsum();
@@ -763,7 +844,7 @@ class OrderController extends Controller
763 844
         $order['deposit_phone'] = $order['receiverMobile'];
764 845
         $order['receiverMobile'] = substr($order['receiverMobile'], 0, 3).'****'.substr($order['receiverMobile'], 7);
765 846
         $order['goods'] = '';
766
-        $order_skus = DB::table('order_goods_skus')->where('is_del', 0)->where('order_id', $id)->lists('num','sku_id');
847
+        $order_skus = DB::table('order_goods_skus')->where('is_del', 0)->where('order_id', $id)->whereNull('gift_id')->lists('num','sku_id');
767 848
 
768 849
         $skus = array_keys($order_skus);
769 850
         if(!empty($skus)){
@@ -780,6 +861,71 @@ class OrderController extends Controller
780 861
             $consum = CustomerConsum::select('phone')->where('order_id', $id)->first();
781 862
             $deposit_phone = isset($consum->phone) ? $consum->phone : '';
782 863
         }
864
+
865
+        //下单当月礼品
866
+        $mtime = date('Y-m-01', strtotime($order['create_time']));
867
+        $gift_info = DB::table('customer_month_gift')->where('mtime', $mtime)->get();
868
+        $gift_info = json_decode(json_encode($gift_info), true);
869
+        $m_gift=array();
870
+        $b_gift=array();
871
+        foreach($gift_info as $k=>$val){
872
+            //获取礼品信息
873
+            $goods_name = Goods::where('id', $val['goods_id'])->pluck('name');
874
+            $sku = GoodsSkus::where('id', $val['sku_id'])->first();
875
+            $data = array();
876
+            $data['id'] = $val['id'];
877
+            $data['goods_name'] = $goods_name;
878
+            $data['propsName'] = $sku['propsName'];
879
+            $data['price'] = $sku['price'];
880
+            if($val['type'] == 0){
881
+                $m_gift[] = $data;
882
+            }else{
883
+                $b_gift[] = $data;
884
+            }
885
+        }
886
+
887
+        #获取赠品信息
888
+        $order_gifts = DB::table('order_goods_skus')->where('is_del', 0)->where('order_id', $id)->where('gift_id','>',0)->lists('gift_id');
889
+        $order_m_gifts = DB::table('customer_month_gift')->whereIn('id', $order_gifts)->where('type', 0)->lists('id');
890
+        $order_b_gifts = DB::table('customer_month_gift')->whereIn('id', $order_gifts)->where('type', 1)->lists('id');
891
+
892
+        #查询用户会员信息
893
+        $cust_info = array();
894
+        $cust_info['coupons'] = 0;
895
+        $cust_info['if_m_gift'] = 0;
896
+        $cust_info['if_b_gift'] = 0;
897
+
898
+        $phone = $order['buyer_phone'];
899
+        $time = date('Y-m-d H:i:s');
900
+        $customer_info = DB::table('customer_vip')->where('phone', $phone)->where('is_del', 0)->first();
901
+        if(!empty($customer_info) && $order['create_time']>'2019-11-28'){
902
+            //判断是否过期
903
+            if($customer_info->vip_end_time > $time){
904
+                //未过期,1.获取优惠券,获取当月礼,获取生日礼,判断领取
905
+                $coupons = DB::table('customer_coupons')->where('phone', $phone)->where('is_use', 0)->where('end_time', '>', $time)->first();
906
+                $cust_info['coupons'] = !empty($coupons) ? 1:0;
907
+                //判断是否领取当月礼
908
+                $if_m_gift = DB::table('customer_gift_receives')->where('phone', $phone)->where('is_del',0)->where('gift_type', 0)->where('dtime', '>=', $mtime)->first();
909
+                if(empty($if_m_gift)){
910
+                    $cust_info['if_m_gift'] = 1;
911
+                }
912
+                          
913
+                //判断生日礼
914
+                $birth_stime = date('m-d', strtotime($customer_info->birthday.' -3 day'));               
915
+                $birth_etime = date('m-d', strtotime($customer_info->birthday.' +3 day'));      
916
+                $today = date('m-d'); 
917
+                if($today>=$birth_stime && $today<=$birth_etime){
918
+                    //生日期内,判断是否已领
919
+                    $if_b_gift = DB::table('customer_gift_receives')->where('phone', $phone)->where('is_del',0)->where('gift_type', 1)->where('dtime', '>=', $mtime)->first();
920
+                    if(empty($if_b_gift)){
921
+                        $cust_info['if_b_gift'] = 1;
922
+                    }
923
+                }
924
+
925
+            }
926
+
927
+        }
928
+
783 929
         return view('order/orderedit', [       
784 930
             'order' => $order,
785 931
             //'categorylist' => $catelist,
@@ -789,6 +935,11 @@ class OrderController extends Controller
789 935
             'str_query'=> 'page='.$page.'&admin_id='.$admin_id.'&stime='.$stime.'&etime='.$etime.'&receiverName='.$receiverName.'&receiverMobile='.$receiverMobile,
790 936
             'last_url' => $last_url,
791 937
             'deposit_phone' => $deposit_phone,
938
+            'm_gift' => $m_gift,
939
+            'b_gift' => $b_gift,
940
+            'order_m_gifts' => $order_m_gifts,
941
+            'order_b_gifts' => $order_b_gifts,
942
+            'cust_info' => $cust_info,
792 943
         ]);
793 944
 
794 945
     }
@@ -866,6 +1017,8 @@ class OrderController extends Controller
866 1017
         //if(!empty($request->input('createTime'))) $order['createTime'] = $request->input('createTime'); // 订单创建时间
867 1018
         $order['order_status'] = (int)$request->input('order_status');
868 1019
         $order['payment_type'] = (int)$request->input('payment_type'); //支付方式
1020
+        $order['use_coupon'] = (int)$request->input('use_coupon');
1021
+        $order['buyer_phone'] = $request->input('buyer_phone');
869 1022
 
870 1023
         //$order['status'] = (int)$request->input('status');
871 1024
         $order['should_amount'] = $request->input('should_amount');
@@ -968,7 +1121,7 @@ class OrderController extends Controller
968 1121
             $gnum = $request->input('gnum');
969 1122
             if(empty($skus)) $skus = [];
970 1123
             //先删除
971
-            $del_re = DB::table('order_goods_skus')->where('order_id', $id)->whereNotIn('sku_id', $skus)->update(['is_del'=>1]);
1124
+            $del_re = DB::table('order_goods_skus')->where('order_id', $id)->whereNull('gift_id')->whereNotIn('sku_id', $skus)->update(['is_del'=>1]);
972 1125
             if(!empty($skus)){            
973 1126
                 //再同步
974 1127
                 foreach($skus as $k=>$sku_id){
@@ -1073,11 +1226,125 @@ class OrderController extends Controller
1073 1226
                 Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
1074 1227
             }  
1075 1228
 
1229
+            #新加逻辑,使用优惠券,赠礼
1230
+            $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');
1233
+            if($use_coupon == 1 && $old_order->use_coupon != 1){
1234
+                $coupon = DB::table('customer_coupons')->where('phone', $order['buyer_phone'])->where('is_use',0)->orderBy('id', 'desc')->first();
1235
+                if(!empty($coupon)){
1236
+                    $cup = array();
1237
+                    $cup['is_use'] = 1;
1238
+                    $cup['use_time'] = date('Y-m-d H:i:s');
1239
+                    $cup['order_id'] = $id;
1240
+                    DB::table('customer_coupons')->where('id', $coupon->id)->update($cup);
1241
+                }
1242
+            }elseif($use_coupon == 0 && $old_order->use_coupon == 1){
1243
+                DB::table('customer_coupons')->where('order_id', $id)->update(['is_use'=>0]);
1244
+            }
1245
+             #查询本单使用赠礼
1246
+            $order_gifts = DB::table('order_goods_skus')->where('is_del', 0)->where('order_id', $id)->where('gift_id','>',0)->lists('gift_id');
1247
+            $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');
1249
+
1250
+            if($m_gift_id>0 && empty($order_m_gift_id) ){
1251
+                $m_gift = DB::table('customer_month_gift')->where('id', $m_gift_id)->where('type', 0)->first();
1252
+                $order_m_gift = array();
1253
+                $m_sku = GoodsSkus::where('id', $m_gift->sku_id)->first();
1254
+                $order_m_gift['sku_id'] = $m_gift->sku_id;
1255
+                $order_m_gift['order_id'] = $id;
1256
+                $order_m_gift['goods_id'] = $m_sku->goodsCode;
1257
+                $order_m_gift['num'] = $m_gift->num;
1258
+                $order_m_gift['price'] = $m_sku->price;
1259
+                $order_m_gift['gift_id'] = $m_gift_id;
1260
+                $order_gift_insert = DB::table('order_goods_skus')->insert($order_m_gift);
1261
+                #记录领取
1262
+                $receive_gift = array();
1263
+                $receive_gift['phone'] = $order['buyer_phone'];
1264
+                $receive_gift['dtime'] = date('Y-m-d');
1265
+                $receive_gift['order_id'] = $id;
1266
+                $receive_gift['gift_id'] = $m_gift_id;
1267
+                $receive_gift['gift_type'] = 0;
1268
+                DB::table('customer_gift_receives')->insert($receive_gift);
1269
+            }elseif($m_gift_id>0 && $m_gift_id != $order_m_gift_id){
1270
+                DB::table('order_goods_skus')->where('gift_id', $order_m_gift_id)->where('order_id', $id)->update(['is_del'=>1]);
1271
+                DB::table('customer_gift_receives')->where('order_id', $id)->where('gift_id', $order_m_gift_id)->update(['is_del'=>1]);
1272
+
1273
+                $m_gift = DB::table('customer_month_gift')->where('id', $m_gift_id)->where('type', 0)->first();
1274
+                $order_m_gift = array();
1275
+                $m_sku = GoodsSkus::where('id', $m_gift->sku_id)->first();
1276
+                $order_m_gift['sku_id'] = $m_gift->sku_id;
1277
+                $order_m_gift['order_id'] = $id;
1278
+                $order_m_gift['goods_id'] = $m_sku->goodsCode;
1279
+                $order_m_gift['num'] = $m_gift->num;
1280
+                $order_m_gift['price'] = $m_sku->price;
1281
+                $order_m_gift['gift_id'] = $m_gift_id;
1282
+                $order_gift_insert = DB::table('order_goods_skus')->insert($order_m_gift);
1283
+                #记录领取
1284
+                $receive_gift = array();
1285
+                $receive_gift['phone'] = $order['buyer_phone'];
1286
+                $receive_gift['dtime'] = date('Y-m-d');
1287
+                $receive_gift['order_id'] = $id;
1288
+                $receive_gift['gift_id'] = $m_gift_id;
1289
+                $receive_gift['gift_type'] = 0;
1290
+                DB::table('customer_gift_receives')->insert($receive_gift);
1291
+            }elseif($m_gift_id==0 && $order_m_gift_id>0){
1292
+                DB::table('order_goods_skus')->where('gift_id', $order_m_gift_id)->where('order_id', $id)->update(['is_del'=>1]);
1293
+                DB::table('customer_gift_receives')->where('order_id', $id)->where('gift_id', $order_m_gift_id)->update(['is_del'=>1]);
1294
+            }
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);
1328
+                #记录领取
1329
+                $receive_gift = array();
1330
+                $receive_gift['phone'] = $order['buyer_phone'];
1331
+                $receive_gift['dtime'] = date('Y-m-d');
1332
+                $receive_gift['order_id'] = $id;
1333
+                $receive_gift['gift_id'] = $b_gift_id;
1334
+                $receive_gift['gift_type'] = 1;
1335
+                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]);
1340
+            }
1341
+
1076 1342
             DB::commit();
1077 1343
         }catch (Exception $e){
1078 1344
             DB::rollback();
1079 1345
             Log::errorLog($request,['error'=>$e->getMessage()],"order/update",0,'');
1080
-            return redirect('/admin/order/index?'.$str_query)->with('info', $e->getMessage()); 
1346
+            var_dump($e->getMessage());
1347
+            //return redirect('/admin/order/index?'.$str_query)->with('info', $e->getMessage()); 
1081 1348
         }     
1082 1349
 
1083 1350
         if(!empty($last_url)){
@@ -1122,6 +1389,25 @@ class OrderController extends Controller
1122 1389
                     CustomerInfo::where('phone', $consum->phone)->update(['balance'=>$balance]);
1123 1390
                 }
1124 1391
 
1392
+                //假如删除订单使用了优惠券,礼品
1393
+                if($order->use_coupon == 1){
1394
+                    DB::table('customer_coupons')->where('order_id', $id)->update(['is_use'=>0]);
1395
+                }
1396
+                 #查询本单使用赠礼
1397
+                $order_gifts = DB::table('order_goods_skus')->where('is_del', 0)->where('order_id', $id)->where('gift_id','>',0)->lists('gift_id');
1398
+                if(!empty($order_gifts)){
1399
+                    $order_m_gift_id = DB::table('customer_month_gift')->whereIn('id', $order_gifts)->where('type', 0)->pluck('id');
1400
+                    $order_b_gift_id = DB::table('customer_month_gift')->whereIn('id', $order_gifts)->where('type', 1)->pluck('id');
1401
+                    if($order_m_gift_id>0){
1402
+                        DB::table('order_goods_skus')->where('gift_id', $order_m_gift_id)->where('order_id', $id)->update(['is_del'=>1]);
1403
+                        DB::table('customer_gift_receives')->where('order_id', $id)->where('gift_id', $order_m_gift_id)->update(['is_del'=>1]);
1404
+                    }
1405
+                    if($order_b_gift_id>0){
1406
+                        DB::table('order_goods_skus')->where('gift_id', $order_b_gift_id)->where('order_id', $id)->update(['is_del'=>1]);
1407
+                        DB::table('customer_gift_receives')->where('order_id', $id)->where('gift_id', $order_b_gift_id)->update(['is_del'=>1]);
1408
+                    }
1409
+                }
1410
+
1125 1411
                 #记录操作日志
1126 1412
                 $self_id = session('admin_id');
1127 1413
                 $self_name = session('real_name');            
@@ -1188,6 +1474,25 @@ class OrderController extends Controller
1188 1474
                     $balance = $cust->balance + $order->receivedAmount;
1189 1475
                     CustomerInfo::where('phone', $consum->phone)->update(['balance'=>$balance]);
1190 1476
                 }
1477
+
1478
+                //假如删除订单使用了优惠券,礼品
1479
+                if($order->use_coupon == 1){
1480
+                    DB::table('customer_coupons')->where('order_id', $id)->update(['is_use'=>0]);
1481
+                }
1482
+                 #查询本单使用赠礼
1483
+                $order_gifts = DB::table('order_goods_skus')->where('is_del', 0)->where('order_id', $id)->where('gift_id','>',0)->lists('gift_id');
1484
+                if(!empty($order_gifts)){
1485
+                    $order_m_gift_id = DB::table('customer_month_gift')->whereIn('id', $order_gifts)->where('type', 0)->pluck('id');
1486
+                    $order_b_gift_id = DB::table('customer_month_gift')->whereIn('id', $order_gifts)->where('type', 1)->pluck('id');
1487
+                    if($order_m_gift_id>0){
1488
+                        DB::table('order_goods_skus')->where('gift_id', $order_m_gift_id)->where('order_id', $id)->update(['is_del'=>1]);
1489
+                        DB::table('customer_gift_receives')->where('order_id', $id)->where('gift_id', $order_m_gift_id)->update(['is_del'=>1]);
1490
+                    }
1491
+                    if($order_b_gift_id>0){
1492
+                        DB::table('order_goods_skus')->where('gift_id', $order_b_gift_id)->where('order_id', $id)->update(['is_del'=>1]);
1493
+                        DB::table('customer_gift_receives')->where('order_id', $id)->where('gift_id', $order_b_gift_id)->update(['is_del'=>1]);
1494
+                    }
1495
+                }
1191 1496
                 
1192 1497
                 #记录操作日志
1193 1498
                 $self_id = session('admin_id');
@@ -1938,5 +2243,47 @@ class OrderController extends Controller
1938 2243
         return $mjOrder['order'];
1939 2244
     }
1940 2245
 
2246
+    /**
2247
+     * 获取手机号会员信息
2248
+     */
2249
+    public function getVip(Request $request){
2250
+        $phone = $request->input('phone');
2251
+        $time = date('Y-m-d H:i:s');
2252
+        $customer_info = DB::table('customer_vip')->where('phone', $phone)->where('is_del', 0)->first();
2253
+        if(!empty($customer_info)){
2254
+            //判断是否过期
2255
+            if($customer_info->vip_end_time > $time){
2256
+                //未过期,1.获取优惠券,获取当月礼,获取生日礼,判断领取
2257
+                $coupons = DB::table('customer_coupons')->where('phone', $phone)->where('is_use', 0)->where('end_time', '>', $time)->first();
2258
+                $customer_info->coupons = !empty($coupons) ? 1:0;
2259
+                //判断是否领取当月礼
2260
+                $mtime = date('Y-m-01');
2261
+                $if_m_gift = DB::table('customer_gift_receives')->where('phone', $phone)->where('is_del',0)->where('gift_type', 0)->where('dtime', '>=', $mtime)->first();
2262
+                $customer_info->if_m_gift = 0;
2263
+                if(empty($if_m_gift)){
2264
+                    $customer_info->if_m_gift = 1;
2265
+                }
2266
+                          
2267
+                //判断生日礼
2268
+                $birth_stime = date('m-d', strtotime($customer_info->birthday.' -3 day'));               
2269
+                $birth_etime = date('m-d', strtotime($customer_info->birthday.' +3 day'));      
2270
+                $today = date('m-d'); 
2271
+                $customer_info->if_b_gift = 0;
2272
+                if($today>=$birth_stime && $today<=$birth_etime){
2273
+                    //生日期内,判断是否已领
2274
+                    $if_b_gift = DB::table('customer_gift_receives')->where('phone', $phone)->where('is_del',0)->where('gift_type', 1)->where('dtime', '>=', $mtime)->first();
2275
+                    if(empty($if_b_gift)){
2276
+                        $customer_info->if_b_gift = 1;
2277
+                    }
2278
+                }
2279
+
2280
+                exit(json_encode(['code'=>0, 'data'=>$customer_info]));
2281
+            }
2282
+            exit(json_encode(['code'=>1,'msg'=>'会员过期']));
2283
+        }
2284
+
2285
+        exit(json_encode(['code'=>1,'msg'=>'不是会员']));
2286
+    }
2287
+
1941 2288
 }
1942 2289
 

+ 1 - 0
app/Http/routes.php

@@ -88,6 +88,7 @@ Route::group(['prefix' => 'admin'], function(){
88 88
         Route::post('/order/setrefundinfo', 'Admin\OrderController@set_refund');  //设为退货 用于c仓同步到卖家取消订单,不删除单子
89 89
         Route::get('/order/setverify/{id}', 'Admin\OrderController@setverify');  //设为已审核
90 90
         Route::get('/order/setverifymore', 'Admin\OrderController@setverifymore');  //设为已审核
91
+        Route::get('/order/getVip', 'Admin\OrderController@getVip');  //获取会员信息
91 92
 
92 93
         //分销订单管理
93 94
         Route::get('/fxorder/index', 'Admin\FxOrderController@orderindex');

+ 100 - 1
resources/views/order/ordercreate.blade.php

@@ -40,6 +40,24 @@
40 40
                 </div>
41 41
             </div>
42 42
             
43
+            <div class="row cl">
44
+                <label class="form-label col-xs-4 col-sm-2">
45
+                    <font color='red'>* </font>买家手机号:</label>
46
+                <div class="formControls col-xs-6 col-sm-6">
47
+                    <input type="text" class="input-text" value="{{old('buyer_phone')}}" placeholder="" onkeyup="getVip()" name="buyer_phone">
48
+                </div>
49
+            </div>
50
+
51
+             <div id='use_coupon_div' class="row cl" style="display: none">
52
+                <label class="form-label col-xs-4 col-sm-2">
53
+                    <font color='red'>* </font>是否使用优惠券:</label>
54
+                <div class="formControls col-xs-6 col-sm-6">
55
+                    <input type="radio" name="use_coupon"  value="0"  checked>
56
+                    <label for="status-0" style="margin-right: 27px;">否</label>
57
+                    <input type="radio" name="use_coupon" value="1" @if(old('use_coupon')==='1') checked @endif>
58
+                    <label for="status-1">是</label>
59
+                </div>
60
+            </div>
43 61
             
44 62
             <div class="row cl">
45 63
                 <label class="form-label col-xs-4 col-sm-2">
@@ -177,7 +195,37 @@
177 195
                     
178 196
                 </div>
179 197
                
180
-            </div><br>       
198
+            </div><br>   
199
+
200
+            <div id='m_gift_div' class="row cl" style="display: none">
201
+                <label class="form-label col-xs-4 col-sm-2">
202
+                    <font color='red'> </font>选择会员当月赠品</label>
203
+                <div class="formControls col-xs-6 col-sm-6">
204
+                    <span class="select-box">
205
+                        <select  size="1" name="m_gift_id" id='m_gift'>                           
206
+                            <option value="0" @if(old('m_gift_id')=='0') selected @endif>- 请选择 -</option>
207
+                            @foreach($m_gift as $item)
208
+                                <option value="{{$item['id']}}" @if(old('m_gift_id')==$item['id']) selected @endif>{{$item['goods_name']}}【{{$item['propsName']}} ¥{{$item['price']}}】</option>
209
+                            @endforeach                                        
210
+                        </select>
211
+                    </span>
212
+                </div>
213
+            </div> 
214
+
215
+            <div id='b_gift_div' class="row cl" style="display: none">
216
+                <label class="form-label col-xs-4 col-sm-2">
217
+                    <font color='red'> </font>选择生日赠品</label>
218
+                <div class="formControls col-xs-6 col-sm-6">
219
+                    <span class="select-box">
220
+                        <select  size="1" name="b_gift_id" id='b_gift'>                           
221
+                            <option value="0" @if(old('b_gift_id')=='0') selected @endif>- 请选择 -</option>
222
+                            @foreach($b_gift as $item)
223
+                                <option value="{{$item['id']}}" @if(old('b_gift_id')==$item['id']) selected @endif>{{$item['goods_name']}}【{{$item['propsName']}} ¥{{$item['price']}}】</option>
224
+                            @endforeach                                        
225
+                        </select>
226
+                    </span>
227
+                </div>
228
+            </div>    
181 229
 
182 230
             <div class="row cl">
183 231
                 <label class="form-label col-xs-4 col-sm-2">
@@ -779,6 +827,12 @@
779 827
         var is_ok = 1;
780 828
         var payment_type = $("input[type='radio'][name='payment_type']:checked").val();
781 829
         if(payment_type==4){
830
+            //使用充值卡不能使用优惠券验证
831
+            use_coupon = $("input[type='radio'][name='use_coupon']:checked").val();
832
+            if(use_coupon == 1){
833
+                layer.msg('充值卡不能和优惠券同时使用!',{icon:2,time:1500});
834
+                return false;
835
+            }
782 836
             var phone = $("input[name=deposit_phone]").val();
783 837
             if(!phone){
784 838
                 is_ok = 0;
@@ -809,6 +863,51 @@
809 863
 
810 864
      }
811 865
 
866
+     function getVip(){
867
+            var phone = $('input[name=buyer_phone]').val();
868
+            var reg = /^1\d{10}$/
869
+            if(reg.test(phone)){
870
+                $.ajax({
871
+                    'url': '/admin/order/getVip?phone='+phone,
872
+                    'type': 'get',
873
+                    'dateType': 'json',
874
+                    success:function(data){
875
+                        data = eval("("+data+")");
876
+                        if(data.code==0){
877
+                            if(data.data.coupons == 1){
878
+                                $("input[name=use_coupon]").removeAttr('disabled');
879
+                                $("#use_coupon_div").show();                              
880
+                            }
881
+                            if(data.data.if_m_gift == 1){
882
+                                $("#m_gift").removeAttr('disabled');
883
+                                $("#m_gift_div").show();
884
+                            }
885
+                            if(data.data.if_b_gift == 1){
886
+                                $("#b_gift").removeAttr('disabled');
887
+                                $("#b_gift_div").show();
888
+                            }
889
+                        }else{
890
+                            $("input[name=use_coupon]").attr('disabled','disabled');
891
+                            $("#m_gift").attr('disabled','disabled');
892
+                            $("#b_gift").attr('disabled','disabled');
893
+                            $("#use_coupon_div").hide();
894
+                            $("#m_gift_div").hide();
895
+                            $("#b_gift_div").hide();
896
+                        }
897
+                       
898
+                    }
899
+                })
900
+            }
901
+            else{
902
+                $("input[name=use_coupon]").attr('disabled','disabled');
903
+                $("#m_gift").attr('disabled','disabled');
904
+                $("#b_gift").attr('disabled','disabled');
905
+                $("#use_coupon_div").hide();
906
+                $("#m_gift_div").hide();
907
+                $("#b_gift_div").hide();
908
+            }
909
+        }
910
+
812 911
     </script>
813 912
     </body>
814 913
 @endsection

+ 56 - 0
resources/views/order/orderedit.blade.php

@@ -41,6 +41,25 @@
41 41
                 </div>
42 42
             </div>
43 43
             
44
+            <div class="row cl">
45
+                <label class="form-label col-xs-4 col-sm-2">
46
+                    <font color='red'>* </font>买家手机号:</label>
47
+                <div class="formControls col-xs-6 col-sm-6">
48
+                    {{$order['buyer_phone']}}
49
+                    <input type="hidden" class="input-text" value="{{$order['buyer_phone']}}" placeholder="" name="buyer_phone">
50
+                </div>
51
+            </div>
52
+
53
+             <div id='use_coupon_div' class="row cl" @if($order['use_coupon'] !='1' && $cust_info['coupons'] != '1') style="display: none" @endif>
54
+                <label class="form-label col-xs-4 col-sm-2">
55
+                    <font color='red'>* </font>是否使用优惠券:</label>
56
+                <div class="formControls col-xs-6 col-sm-6">
57
+                    <input type="radio" name="use_coupon"  value="0"  @if($order['use_coupon']=='0') checked @endif>
58
+                    <label for="status-0" style="margin-right: 27px;">否</label>
59
+                    <input type="radio" name="use_coupon" value="1" @if($order['use_coupon']=='1') checked @endif>
60
+                    <label for="status-1">是</label>
61
+                </div>
62
+            </div>
44 63
             
45 64
             <div class="row cl">
46 65
                 <label class="form-label col-xs-4 col-sm-2">
@@ -203,6 +222,36 @@
203 222
                 
204 223
             </div><br>
205 224
 
225
+            <div id='m_gift_div' class="row cl" @if(empty($order_m_gifts) && $cust_info['if_m_gift'] != '1') style="display: none" @endif>
226
+                <label class="form-label col-xs-4 col-sm-2">
227
+                    <font color='red'> </font>选择会员当月赠品</label>
228
+                <div class="formControls col-xs-6 col-sm-6">
229
+                    <span class="select-box">
230
+                        <select  size="1" name="m_gift_id" id='m_gift'>                           
231
+                            <option value="0" @if(old('m_gift_id')=='0') selected @endif>- 请选择 -</option>
232
+                            @foreach($m_gift as $item)
233
+                                <option value="{{$item['id']}}" @if( in_array($item['id'], $order_m_gifts) ) selected @endif>{{$item['goods_name']}}【{{$item['propsName']}} ¥{{$item['price']}}】</option>
234
+                            @endforeach                                        
235
+                        </select>
236
+                    </span>
237
+                </div>
238
+            </div> 
239
+
240
+            <div id='b_gift_div' class="row cl"   @if(empty($order_b_gifts) && $cust_info['if_b_gift'] != '1') style="display: none" @endif>
241
+                <label class="form-label col-xs-4 col-sm-2">
242
+                    <font color='red'> </font>选择生日赠品</label>
243
+                <div class="formControls col-xs-6 col-sm-6">
244
+                    <span class="select-box">
245
+                        <select  size="1" name="b_gift_id" id='b_gift'>                           
246
+                            <option value="0" @if(old('b_gift_id')=='0') selected @endif>- 请选择 -</option>
247
+                            @foreach($b_gift as $item)
248
+                                <option value="{{$item['id']}}" @if( in_array($item['id'], $order_b_gifts) ) selected @endif>{{$item['goods_name']}}【{{$item['propsName']}} ¥{{$item['price']}}】</option>
249
+                            @endforeach                                        
250
+                        </select>
251
+                    </span>
252
+                </div>
253
+            </div> 
254
+
206 255
             <div class="row cl">
207 256
                 <label class="form-label col-xs-4 col-sm-2">
208 257
                    应收金额:</label>
@@ -674,6 +723,13 @@
674 723
         var receivedAmount = $("input[name=receivedAmount]").val();
675 724
         var payment_type = $("input[type='radio'][name='payment_type']:checked").val();
676 725
 
726
+        if( payment_type==4 ){
727
+            use_coupon = $("input[type='radio'][name='use_coupon']:checked").val();
728
+            if(use_coupon == 1){
729
+                layer.msg('充值卡不能和优惠券同时使用!',{icon:2,time:1500});
730
+                return false;
731
+            }
732
+        } 
677 733
 
678 734
         if( payment_type==4 && old_payment_type != 4 ){
679 735
             var phone = $("input[name=deposit_phone]").val();