sunhao 5 anos atrás
pai
commit
02f70ab81b

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

@@ -556,7 +556,7 @@ class OrderController extends Controller
556 556
 
557 557
         //redis防重复数据
558 558
         $phone = $request->input('receiverMobile');
559
-        
559
+        /*
560 560
         $redisKey = 'seafood.order_phone_add.'.$phone;
561 561
         $res = RedisModel::setnx($redisKey, 1);
562 562
         if( $res == 0 ){
@@ -564,7 +564,7 @@ class OrderController extends Controller
564 564
             return redirect('/admin/order/index')->with('info', $msg);
565 565
         }
566 566
         $res = RedisModel::expire( $redisKey, 60 );
567
-        
567
+        */
568 568
         $skus = $request->input('skus');
569 569
         $warehouse = (int)$request->input('warehouse');
570 570
         if($warehouse == 3 && empty($skus)){
@@ -650,6 +650,7 @@ class OrderController extends Controller
650 650
         $order['order_status'] = (int)$request->input('order_status');
651 651
         $order['payment_type'] = (int)$request->input('payment_type'); //支付方式
652 652
         $order['buyer_phone'] = $request->input('buyer_phone'); 
653
+        $order['use_coupon'] = (int)$request->input('use_coupon'); 
653 654
        
654 655
         //充值卡验证余额
655 656
         if($order['payment_type'] == 4){
@@ -746,7 +747,16 @@ class OrderController extends Controller
746 747
                     $order_m_gift['goods_id'] = $m_sku->goodsCode;
747 748
                     $order_m_gift['num'] = $m_gift->num;
748 749
                     $order_m_gift['price'] = $m_sku->price;
750
+                    $order_m_gift['gift_id'] = $m_gift_id;
749 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);
750 760
                 }
751 761
                 if($b_gift_id>0){
752 762
                     $b_gift = DB::table('customer_month_gift')->where('id', $b_gift_id)->where('type', 1)->first();
@@ -757,7 +767,16 @@ class OrderController extends Controller
757 767
                     $order_b_gift['goods_id'] = $b_sku->goodsCode;
758 768
                     $order_b_gift['num'] = $b_gift->num;
759 769
                     $order_b_gift['price'] = $b_sku->price;
770
+                    $order_b_gift['gift_id'] = $b_gift_id;
760 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);
761 780
                 }
762 781
 
763 782
                 #新加逻辑,若付款方式为充值卡/消费记录
@@ -825,7 +844,7 @@ class OrderController extends Controller
825 844
         $order['deposit_phone'] = $order['receiverMobile'];
826 845
         $order['receiverMobile'] = substr($order['receiverMobile'], 0, 3).'****'.substr($order['receiverMobile'], 7);
827 846
         $order['goods'] = '';
828
-        $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');
829 848
 
830 849
         $skus = array_keys($order_skus);
831 850
         if(!empty($skus)){
@@ -842,6 +861,71 @@ class OrderController extends Controller
842 861
             $consum = CustomerConsum::select('phone')->where('order_id', $id)->first();
843 862
             $deposit_phone = isset($consum->phone) ? $consum->phone : '';
844 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
+
845 929
         return view('order/orderedit', [       
846 930
             'order' => $order,
847 931
             //'categorylist' => $catelist,
@@ -851,6 +935,11 @@ class OrderController extends Controller
851 935
             'str_query'=> 'page='.$page.'&admin_id='.$admin_id.'&stime='.$stime.'&etime='.$etime.'&receiverName='.$receiverName.'&receiverMobile='.$receiverMobile,
852 936
             'last_url' => $last_url,
853 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,
854 943
         ]);
855 944
 
856 945
     }
@@ -928,6 +1017,8 @@ class OrderController extends Controller
928 1017
         //if(!empty($request->input('createTime'))) $order['createTime'] = $request->input('createTime'); // 订单创建时间
929 1018
         $order['order_status'] = (int)$request->input('order_status');
930 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');
931 1022
 
932 1023
         //$order['status'] = (int)$request->input('status');
933 1024
         $order['should_amount'] = $request->input('should_amount');
@@ -1030,7 +1121,7 @@ class OrderController extends Controller
1030 1121
             $gnum = $request->input('gnum');
1031 1122
             if(empty($skus)) $skus = [];
1032 1123
             //先删除
1033
-            $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]);
1034 1125
             if(!empty($skus)){            
1035 1126
                 //再同步
1036 1127
                 foreach($skus as $k=>$sku_id){
@@ -1135,11 +1226,125 @@ class OrderController extends Controller
1135 1226
                 Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
1136 1227
             }  
1137 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
+
1138 1342
             DB::commit();
1139 1343
         }catch (Exception $e){
1140 1344
             DB::rollback();
1141 1345
             Log::errorLog($request,['error'=>$e->getMessage()],"order/update",0,'');
1142
-            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()); 
1143 1348
         }     
1144 1349
 
1145 1350
         if(!empty($last_url)){

+ 49 - 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" >
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">
@@ -201,6 +220,36 @@
201 220
                 
202 221
             </div><br>
203 222
 
223
+            <div id='m_gift_div' class="row cl" @if(empty($order_m_gifts) && $cust_info['if_m_gift'] != '1') style="display: none" @endif>
224
+                <label class="form-label col-xs-4 col-sm-2">
225
+                    <font color='red'> </font>选择会员每月赠品</label>
226
+                <div class="formControls col-xs-6 col-sm-6">
227
+                    <span class="select-box">
228
+                        <select  size="1" name="m_gift_id" id='m_gift'>                           
229
+                            <option value="0" @if(old('m_gift_id')=='0') selected @endif>- 请选择 -</option>
230
+                            @foreach($m_gift as $item)
231
+                                <option value="{{$item['id']}}" @if( in_array($item['id'], $order_m_gifts) ) selected @endif>{{$item['goods_name']}}【{{$item['propsName']}} ¥{{$item['price']}}】</option>
232
+                            @endforeach                                        
233
+                        </select>
234
+                    </span>
235
+                </div>
236
+            </div> 
237
+
238
+            <div id='b_gift_div' class="row cl"   @if(empty($order_b_gifts) && $cust_info['if_b_gift'] != '1') style="display: none" @endif>
239
+                <label class="form-label col-xs-4 col-sm-2">
240
+                    <font color='red'> </font>选择生日赠品</label>
241
+                <div class="formControls col-xs-6 col-sm-6">
242
+                    <span class="select-box">
243
+                        <select  size="1" name="b_gift_id" id='b_gift'>                           
244
+                            <option value="0" @if(old('b_gift_id')=='0') selected @endif>- 请选择 -</option>
245
+                            @foreach($b_gift as $item)
246
+                                <option value="{{$item['id']}}" @if( in_array($item['id'], $order_b_gifts) ) selected @endif>{{$item['goods_name']}}【{{$item['propsName']}} ¥{{$item['price']}}】</option>
247
+                            @endforeach                                        
248
+                        </select>
249
+                    </span>
250
+                </div>
251
+            </div> 
252
+
204 253
             <div class="row cl">
205 254
                 <label class="form-label col-xs-4 col-sm-2">
206 255
                    应收金额:</label>