sunhao 5 years ago
parent
commit
f2349ccfa1

+ 44 - 5
app/Http/Controllers/Admin/OrderController.php

@@ -520,6 +520,7 @@ class OrderController extends Controller
520 520
             'customerName'           => 'required|between:1,6', 
521 521
             'receiverName'           => 'required|between:1,6', 
522 522
             'receiverMobile'           => 'required|regex:/^1[3456789]\d{9}$/',  
523
+            'buyer_phone'           => 'required|regex:/^1[3456789]\d{9}$/',  
523 524
             'fanTime'           => 'required|date', 
524 525
             'receiverState'           => 'required|between:1,5', 
525 526
             'receiverCity'           => 'required|between:1,10', 
@@ -536,6 +537,7 @@ class OrderController extends Controller
536 537
             'receiverName.required'           => '收货人不能为空', 
537 538
             'receiverName.between'           => '收货人不能超过6个字符',                  
538 539
             'receiverMobile.required'           => '收货人手机号不能为空',                   
540
+            'buyer_phone.required'           => '买家手机号不能为空',                   
539 541
             'receiverMobile.regex'           => '收货人手机号格式有误',                   
540 542
             'fanTime.required'           => '加粉时间不能为空',              
541 543
             'receiverState.required'           => '省不能为空',   
@@ -647,6 +649,7 @@ class OrderController extends Controller
647 649
         $order['delivery_date'] = !empty($request->input('delivery_date')) ? $request->input('delivery_date') : date('Y-m-d'); //发货日期
648 650
         $order['order_status'] = (int)$request->input('order_status');
649 651
         $order['payment_type'] = (int)$request->input('payment_type'); //支付方式
652
+        $order['buyer_phone'] = $request->input('buyer_phone'); 
650 653
        
651 654
         //充值卡验证余额
652 655
         if($order['payment_type'] == 4){
@@ -720,6 +723,43 @@ class OrderController extends Controller
720 723
                     $order_skus_insert = DB::table('order_goods_skus')->insert($order_skus);
721 724
                 }
722 725
 
726
+                #加赠品逻辑
727
+                $use_coupon = (int)$request->input('use_coupon');
728
+                $m_gift_id = (int)$request->input('m_gift_id');
729
+                $b_gift_id = (int)$request->input('b_gift_id');
730
+                if($use_coupon == 1){
731
+                    $coupon = DB::table('customer_coupons')->where('phone', $order['buyer_phone'])->where('is_use',0)->orderBy('id', 'desc')->first();
732
+                    if(!empty($coupon)){
733
+                        $cup = array();
734
+                        $cup['is_use'] = 1;
735
+                        $cup['use_time'] = date('Y-m-d H:i:s');
736
+                        $cup['order_id'] = $res;
737
+                        DB::table('customer_coupons')->where('id', $coupon->id)->update($cup);
738
+                    }
739
+                }
740
+                if($m_gift_id>0){
741
+                    $m_gift = DB::table('customer_month_gift')->where('id', $m_gift_id)->where('type', 0)->first();
742
+                    $order_m_gift = array();
743
+                    $m_sku = GoodsSkus::where('id', $m_gift->sku_id)->first();
744
+                    $order_m_gift['sku_id'] = $m_gift->sku_id;
745
+                    $order_m_gift['order_id'] = $res;
746
+                    $order_m_gift['goods_id'] = $m_sku->goodsCode;
747
+                    $order_m_gift['num'] = $m_gift->num;
748
+                    $order_m_gift['price'] = $m_sku->price;
749
+                    $order_gift_insert = DB::table('order_goods_skus')->insert($order_m_gift);
750
+                }
751
+                if($b_gift_id>0){
752
+                    $b_gift = DB::table('customer_month_gift')->where('id', $b_gift_id)->where('type', 1)->first();
753
+                    $order_b_gift = array();
754
+                    $b_sku = GoodsSkus::where('id', $b_gift->sku_id)->first();
755
+                    $order_b_gift['sku_id'] = $b_gift->sku_id;
756
+                    $order_b_gift['order_id'] = $res;
757
+                    $order_b_gift['goods_id'] = $b_sku->goodsCode;
758
+                    $order_b_gift['num'] = $b_gift->num;
759
+                    $order_b_gift['price'] = $b_sku->price;
760
+                    $order_gift_insert = DB::table('order_goods_skus')->insert($order_b_gift);
761
+                }
762
+
723 763
                 #新加逻辑,若付款方式为充值卡/消费记录
724 764
                 if($order['payment_type'] == 4){
725 765
                     $consum = new CustomerConsum();
@@ -1972,7 +2012,7 @@ class OrderController extends Controller
1972 2012
             if($customer_info->vip_end_time > $time){
1973 2013
                 //未过期,1.获取优惠券,获取当月礼,获取生日礼,判断领取
1974 2014
                 $coupons = DB::table('customer_coupons')->where('phone', $phone)->where('is_use', 0)->where('end_time', '>', $time)->first();
1975
-                $customer_info->coupons = $coupons;
2015
+                $customer_info->coupons = !empty($coupons) ? 1:0;
1976 2016
                 //判断是否领取当月礼
1977 2017
                 $mtime = date('Y-m-01');
1978 2018
                 $if_m_gift = DB::table('customer_gift_receives')->where('phone', $phone)->where('is_del',0)->where('gift_type', 0)->where('dtime', '>=', $mtime)->first();
@@ -1994,13 +2034,12 @@ class OrderController extends Controller
1994 2034
                     }
1995 2035
                 }
1996 2036
 
1997
-                $customer_info = json_encode($customer_info);
1998
-                exit(['code'=>0, 'data'=>$customer_info]);
2037
+                exit(json_encode(['code'=>0, 'data'=>$customer_info]));
1999 2038
             }
2000
-            exit(['code'=>1,'msg'=>'会员过期']);
2039
+            exit(json_encode(['code'=>1,'msg'=>'会员过期']));
2001 2040
         }
2002 2041
 
2003
-        exit(['code'=>1,'msg'=>'不是会员']);
2042
+        exit(json_encode(['code'=>1,'msg'=>'不是会员']));
2004 2043
     }
2005 2044
 
2006 2045
 }

+ 25 - 15
resources/views/order/ordercreate.blade.php

@@ -48,7 +48,7 @@
48 48
                 </div>
49 49
             </div>
50 50
 
51
-             <div class="row cl" style="display: none">
51
+             <div id='use_coupon_div' class="row cl" style="display: none">
52 52
                 <label class="form-label col-xs-4 col-sm-2">
53 53
                     <font color='red'>* </font>是否使用优惠券:</label>
54 54
                 <div class="formControls col-xs-6 col-sm-6">
@@ -196,7 +196,7 @@
196 196
                
197 197
             </div><br>   
198 198
 
199
-            <div class="row cl">
199
+            <div id='m_gift_div' class="row cl" style="display: none">
200 200
                 <label class="form-label col-xs-4 col-sm-2">
201 201
                     <font color='red'> </font>选择会员每月赠品</label>
202 202
                 <div class="formControls col-xs-6 col-sm-6">
@@ -211,7 +211,7 @@
211 211
                 </div>
212 212
             </div> 
213 213
 
214
-            <div class="row cl">
214
+            <div id='b_gift_div' class="row cl" style="display: none">
215 215
                 <label class="form-label col-xs-4 col-sm-2">
216 216
                     <font color='red'> </font>选择生日赠品</label>
217 217
                 <div class="formControls col-xs-6 col-sm-6">
@@ -865,19 +865,29 @@
865 865
                     'type': 'get',
866 866
                     'dateType': 'json',
867 867
                     success:function(data){
868
-                        if(data != '0'){
869
-                            data = eval("("+data+")");
870
-                            $("input[name=receiverState]").val(data.receiverState);
871
-                            $("input[name=receiverCity]").val(data.receiverCity);
872
-                            //$("input[name=receiverDistrict]").val(data.receiverDistrict);
873
-                            //$("input[name=receiverStreet]").val(data.receiverStreet);
874
-                            $("input[name=receiverAddress]").val(data.receiverAddress);
875
-                            $("input[name=fanTime]").val(data.fanTime);
876
-                            $("#fanTime_div").hide();
877
-                        }
878
-                        else{
879
-                            $("#fanTime_div").show();
868
+                        data = eval("("+data+")");
869
+                        if(data.code==0){
870
+                            if(data.data.coupons == 1){
871
+                                $("input[name=use_coupon]").removeAttr('disabled');
872
+                                $("#use_coupon_div").show();                              
873
+                            }
874
+                            if(data.data.if_m_gift == 1){
875
+                                $("#m_gift").removeAttr('disabled');
876
+                                $("#m_gift_div").show();
877
+                            }
878
+                            if(data.data.if_b_gift == 1){
879
+                                $("#b_gift").removeAttr('disabled');
880
+                                $("#b_gift_div").show();
881
+                            }
882
+                        }else{
883
+                            $("input[name=use_coupon]").attr('disabled','disabled');
884
+                            $("#m_gift").attr('disabled','disabled');
885
+                            $("#b_gift").attr('disabled','disabled');
886
+                            $("#use_coupon_div").hide();
887
+                            $("#m_gift_div").hide();
888
+                            $("#b_gift_div").hide();
880 889
                         }
890
+                       
881 891
                     }
882 892
                 })
883 893
             }