Browse Source

Merge branch 'sh/31'

sunhao 5 years ago
parent
commit
d569e92be1

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

@@ -164,6 +164,8 @@ class OrderController extends Controller
164 164
                 $v['refund_type'] = '付款码支付';
165 165
             }elseif($v['refund_type'] == 3){
166 166
                 $v['refund_type'] = '个体户支付';
167
+            }elseif($v['refund_type'] == 4){
168
+                $v['refund_type'] = '充值卡支付';
167 169
             }else{
168 170
                 $v['refund_type'] = '';
169 171
             }  
@@ -869,7 +871,7 @@ class OrderController extends Controller
869 871
         $order = Order::findOrFail($id);
870 872
         $order = json_decode(json_encode($order), true);
871 873
         // 临时处理,只能用自己充值卡
872
-        //$order['deposit_phone'] = $order['receiverMobile'];
874
+        $order['deposit_phone'] = $order['receiverMobile'];
873 875
         $order['receiverMobile'] = substr($order['receiverMobile'], 0, 3).'****'.substr($order['receiverMobile'], 7);
874 876
         $order['goods'] = '';
875 877
         $order_skus = DB::table('order_goods_skus')->where('is_del', 0)->where('order_id', $id)->whereNull('gift_id')->lists('num','sku_id');
@@ -891,10 +893,10 @@ class OrderController extends Controller
891 893
             $order['goods'] = $goods;
892 894
         }
893 895
 
894
-        $deposit_phone = '';
896
+        $deposit_phone = $order['deposit_phone'];
895 897
         if($order['payment_type'] == 4){
896 898
             $consum = CustomerConsum::select('phone')->where('order_id', $id)->first();
897
-            $deposit_phone = isset($consum->phone) ? $consum->phone : '';
899
+            $deposit_phone = isset($consum->phone) ? $consum->phone : $order['deposit_phone'];
898 900
         }
899 901
 
900 902
         //下单当月礼品
@@ -1255,7 +1257,7 @@ class OrderController extends Controller
1255 1257
                         $customerInfo->balance = $customerInfo->balance - $order['receivedAmount'];
1256 1258
                         $customerInfo->save();
1257 1259
                     }elseif($old_order->receivedAmount != $order['receivedAmount']){
1258
-                        $consum = CustomerConsum::where('order_id', $id)->first();                       
1260
+                        $consum = CustomerConsum::where('order_id', $id)->where('type', 0)->first();                       
1259 1261
                         $consum->money = $order['receivedAmount'];
1260 1262
                         $consum->save();
1261 1263
                         //更新余额
@@ -1410,11 +1412,13 @@ class OrderController extends Controller
1410 1412
                 if($order->payment_type == 4){
1411 1413
                     //查询消费记录/卡号
1412 1414
                     $consum = CustomerConsum::where('order_id', $id)->where('is_del', 0)->first();
1415
+                    //查询需要返还消费钱数
1416
+                    $fan_money = CustomerConsum::where('order_id', $id)->where('is_del', 0)->sum('money');
1413 1417
                     //消费记录设为删除
1414 1418
                     CustomerConsum::where('order_id', $id)->update(['is_del'=>1]);
1415 1419
                     //余额返还
1416 1420
                     $cust = CustomerInfo::select('balance')->where('phone', $consum->phone)->first();
1417
-                    $balance = $cust->balance + $order->receivedAmount;
1421
+                    $balance = $cust->balance + $fan_money;
1418 1422
                     CustomerInfo::where('phone', $consum->phone)->update(['balance'=>$balance]);
1419 1423
                 }
1420 1424
 
@@ -1502,11 +1506,13 @@ class OrderController extends Controller
1502 1506
                 if($order->payment_type == 4){
1503 1507
                     //查询消费记录/卡号
1504 1508
                     $consum = CustomerConsum::where('order_id', $id)->where('is_del', 0)->first();
1509
+                    //查询需要返还消费钱数
1510
+                    $fan_money = CustomerConsum::where('order_id', $id)->where('is_del', 0)->sum('money');
1505 1511
                     //消费记录设为删除
1506 1512
                     CustomerConsum::where('order_id', $id)->update(['is_del'=>1]);
1507 1513
                     //余额返还
1508 1514
                     $cust = CustomerInfo::select('balance')->where('phone', $consum->phone)->first();
1509
-                    $balance = $cust->balance + $order->receivedAmount;
1515
+                    $balance = $cust->balance + $fan_money;
1510 1516
                     CustomerInfo::where('phone', $consum->phone)->update(['balance'=>$balance]);
1511 1517
                 }
1512 1518
 
@@ -1878,14 +1884,36 @@ class OrderController extends Controller
1878 1884
             }else{
1879 1885
                 $data['is_refund'] = 1;
1880 1886
                 if(!$order->refund_type) $data['refund_type'] = 1;
1887
+                if(!$order->refund_time) $data['refund_time'] = date('Y-m-d');
1888
+                if($order->refund_type == 4 && $refund_price != $order->refund_price){
1889
+                    // 充值退补
1890
+                    $res = $this->depositRefund($id, $refund_price);
1891
+                    if(!$res){
1892
+                        return 0;
1893
+                    }
1894
+                }
1881 1895
             }
1882 1896
             $data['refund_price'] = $refund_price;
1883 1897
         }
1884 1898
         if(isset($refund_type)){
1885 1899
             if(empty($refund_type)){
1886 1900
                 $refund_type = null;                
1901
+            }elseif($refund_type == 4){
1902
+                //判断是否是充值卡支付方式
1903
+                if($order->payment_type != 4){
1904
+                    return 0;
1905
+                }
1906
+                if($order->refund_price != 0 && $order->refund_type != 4){
1907
+                    $res = $this->depositRefund($id, $order->refund_price);
1908
+                    if(!$res){
1909
+                        return 0;
1910
+                    }
1911
+                }
1912
+            }elseif($refund_type != 4 && $order->refund_type == 4){
1913
+                return 0;
1887 1914
             }
1888 1915
             $data['refund_type'] = (int)$refund_type;
1916
+            if(!$order->refund_time) $data['refund_time'] = date('Y-m-d');
1889 1917
         }
1890 1918
         if($id>0 && !empty($data)){
1891 1919
             $res = Order::where('id', $id)->update($data);
@@ -1894,6 +1922,45 @@ class OrderController extends Controller
1894 1922
         return 1;
1895 1923
     }
1896 1924
 
1925
+    /**
1926
+     * 充值卡退补
1927
+     */
1928
+    public function depositRefund($order_id, $refund_price){
1929
+        //查消费记录
1930
+        $order_consum = DB::table('customer_consum')->where('is_del', 0)->where('order_id', $order_id)->where('type', 0)->first();
1931
+        if(empty($order_consum)){
1932
+            return false;
1933
+        }
1934
+        //查看是否已有退补记录
1935
+        $order_refund = DB::table('customer_consum')->where('is_del', 0)->where('order_id', $order_id)->where('type', 1)->first();
1936
+        $balance = CustomerInfo::where('phone', $order_consum->phone)->pluck('balance');
1937
+        if(empty($order_refund)){
1938
+            if($refund_price>0){
1939
+                //补钱,判断充值卡余额           
1940
+                if($balance - $refund_price < 0){
1941
+                    return false;
1942
+                }
1943
+            }
1944
+            $consum = array();
1945
+            $consum['phone'] = $order_consum->phone;
1946
+            $consum['order_id'] = $order_id;
1947
+            $consum['money'] = $refund_price;
1948
+            $consum['type'] = 1;
1949
+            DB::table('customer_consum')->insert($consum);
1950
+            $balance = $balance - $refund_price;
1951
+        }elseif($order_refund->money != $refund_price){
1952
+            //已有退款,更变le 退款钱数
1953
+            if($balance - $refund_price + $order_refund->money <0 ){
1954
+                return false;
1955
+            }
1956
+            DB::table('customer_consum')->where('id', $order_refund->id)->update(['money'=>$refund_price]);
1957
+            $balance = $balance - $refund_price + $order_refund->money;
1958
+        }
1959
+   
1960
+        CustomerInfo::where('phone', $order_consum->phone)->update(['balance' => $balance]);
1961
+        return true;
1962
+    }
1963
+
1897 1964
     public function warehouse_export(Request $request){
1898 1965
         
1899 1966
         $self_role = session('role_name');        

File diff suppressed because it is too large
+ 26 - 6
app/Http/Controllers/Admin/StatisticsController.php


+ 3 - 1
resources/views/deposit/consumList.blade.php

@@ -14,8 +14,9 @@
14 14
                 <tr class="text-c">
15 15
                     {{--<th width="25"><input type="checkbox" name="" value=""></th>--}}
16 16
                     <th width="10%">账号</th>                   
17
-                    <th width="10%">消费金额</th>
17
+                    <th width="10%">消费(或退补)金额</th>
18 18
                     <th width="10%">订单ID</th>
19
+                    <th width="10%">类型</th>
19 20
                     <th width="10%">时间</th>
20 21
                 </tr>
21 22
                 </thead>
@@ -27,6 +28,7 @@
27 28
                         <td class="text-c">{{$a['phone']}}</td>
28 29
                         <td class="text-c">{{$a['money']}}</td>
29 30
                         <td class="text-c">{{$a['order_id']}}</td>
31
+                        <td class="text-c">@if($a['type'] == 1) 退补 @else 消费 @endif</td>
30 32
                         <td class="text-c">{{$a['create_time']}}</td>
31 33
                         
32 34
                     </tr>

+ 2 - 3
resources/views/order/orderedit.blade.php

@@ -311,9 +311,8 @@
311 311
             <div class="row cl"  style="display: none" id='deposit_div'>
312 312
                 <label class="form-label col-xs-4 col-sm-2">
313 313
                     <font color='red'> </font>充值卡号:</label>
314
-                <div class="formControls col-xs-6 col-sm-6">
315
-                    <input id='deposit_phone_i' type="text" class="input-text" value="{{old('deposit_phone')}}" placeholder="*默认收货人手机号" disabled name="deposit_phone_i">
316
-                    <input id='deposit_phone' type="hidden" class="input-text" value="{{old('deposit_phone')}}" placeholder="" name="deposit_phone">
314
+                <div class="formControls col-xs-6 col-sm-6">                  
315
+                    <input id='deposit_phone' type="text" class="input-text" value="{{old('deposit_phone')}}" onkeyup="getBalance()" placeholder="" name="deposit_phone">
317 316
                     <font color='red' id='vip_pay'></font>
318 317
                 </div>
319 318
             </div>

+ 12 - 2
resources/views/order/orderlist.blade.php

@@ -179,6 +179,7 @@
179 179
                                     <option value='1'>微信支付</option>
180 180
                                     <!--option value='2'>付款码支付</option-->
181 181
                                     <option value='3'>个体户支付</option>
182
+                                    <option value='4'>充值卡支付</option>
182 183
                                 </select>
183 184
                                 <span class="sort_icon" hidden  onClick='change_refund_type_click("{{$a['id']}}","{{$a['cost']}}")' style="cursor:pointer"><i class="Hui-iconfont">&#xe647;</i></span>
184 185
                             </td>
@@ -718,8 +719,11 @@
718 719
             $.ajax({
719 720
                 url: '/admin/order/editLogisticsId?id='+id+'&refund_price='+refund_price,
720 721
                 type: 'get',
721
-                dateType: 'json',
722 722
                 success:function(msg){
723
+                    if(msg == 0){
724
+                        alert('操作有误');
725
+                        return false;
726
+                    }
723 727
                     $("#refund_price_1"+id).html(refund_price);
724 728
                     if(!refund_type){
725 729
                         $("#refund_type_1"+id).html('微信支付');
@@ -741,8 +745,11 @@
741 745
             $.ajax({
742 746
                 url: '/admin/order/editLogisticsId?id='+id+'&refund_type='+refund_type,
743 747
                 type: 'get',
744
-                dateType: 'json',
745 748
                 success:function(msg){
749
+                    if(msg == 0){
750
+                        alert('操作有误');
751
+                        return false;
752
+                    }
746 753
                     if(refund_type==1){
747 754
                         refund_type = '微信支付';
748 755
                     }
@@ -752,6 +759,9 @@
752 759
                     if(refund_type==3){
753 760
                         refund_type = '个体户支付';
754 761
                     }
762
+                    if(refund_type==4){
763
+                        refund_type = '充值卡支付';
764
+                    }
755 765
                     if(refund_type==0){
756 766
                         refund_type = '';
757 767
                     }

+ 1 - 0
resources/views/order/predictorderlist.blade.php

@@ -160,6 +160,7 @@
160 160
                                     <option value='1'>微信支付</option>
161 161
                                     <!--option value='2'>付款码支付</option-->
162 162
                                     <option value='3'>个体户支付</option>
163
+                                    <option value='4'>充值卡支付</option>
163 164
                                 </select>
164 165
                                 <span class="sort_icon" hidden  onClick='change_refund_type_click("{{$a['id']}}","{{$a['cost']}}")' style="cursor:pointer"><i class="Hui-iconfont">&#xe647;</i></span>
165 166
                             </td>

+ 6 - 0
resources/views/statistics/teamFinanceTotal.blade.php

@@ -45,6 +45,9 @@
45 45
                     <th width="4%">个体户退补单数</th>
46 46
                     <th width="4%">个体户退补差价</th>
47 47
                     <th width="5%">个体户实际金额</th>
48
+                    <th width="4%">充值卡退补单数</th>
49
+                    <th width="4%">充值卡退补差价</th>
50
+                    <th width="5%">充值卡实际金额</th>
48 51
                     <th width="4%">发货单数</th>
49 52
                     <th width="5%">货品成本</th>
50 53
                     <th width="5%">物流成本</th>
@@ -75,6 +78,9 @@
75 78
                             <td>{{$a['gth_refund_count']}}</td>
76 79
                             <td>{{$a['gth_refund_price']}}</td>
77 80
                             <td>{{$a['gth_true_amount']}}</td>
81
+                            <td>{{$a['czk_refund_count']}}</td>
82
+                            <td>{{$a['czk_refund_price']}}</td>
83
+                            <td>{{$a['czk_true_amount']}}</td>
78 84
                             <td>{{$a['send_count']}}</td>
79 85
                             <td>{{$a['cost']}}</td>
80 86
                             <td>{{$a['freight_cost']}}</td>