Browse Source

充值卡退补

sunhao 5 years ago
parent
commit
922b178f57

+ 16 - 8
app/Http/Controllers/Admin/OrderController.php

1257
                         $customerInfo->balance = $customerInfo->balance - $order['receivedAmount'];
1257
                         $customerInfo->balance = $customerInfo->balance - $order['receivedAmount'];
1258
                         $customerInfo->save();
1258
                         $customerInfo->save();
1259
                     }elseif($old_order->receivedAmount != $order['receivedAmount']){
1259
                     }elseif($old_order->receivedAmount != $order['receivedAmount']){
1260
-                        $consum = CustomerConsum::where('order_id', $id)->first();                       
1260
+                        $consum = CustomerConsum::where('order_id', $id)->where('type', 0)->first();                       
1261
                         $consum->money = $order['receivedAmount'];
1261
                         $consum->money = $order['receivedAmount'];
1262
                         $consum->save();
1262
                         $consum->save();
1263
                         //更新余额
1263
                         //更新余额
1412
                 if($order->payment_type == 4){
1412
                 if($order->payment_type == 4){
1413
                     //查询消费记录/卡号
1413
                     //查询消费记录/卡号
1414
                     $consum = CustomerConsum::where('order_id', $id)->where('is_del', 0)->first();
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');
1415
                     //消费记录设为删除
1417
                     //消费记录设为删除
1416
                     CustomerConsum::where('order_id', $id)->update(['is_del'=>1]);
1418
                     CustomerConsum::where('order_id', $id)->update(['is_del'=>1]);
1417
                     //余额返还
1419
                     //余额返还
1418
                     $cust = CustomerInfo::select('balance')->where('phone', $consum->phone)->first();
1420
                     $cust = CustomerInfo::select('balance')->where('phone', $consum->phone)->first();
1419
-                    $balance = $cust->balance + $order->receivedAmount;
1421
+                    $balance = $cust->balance + $fan_money;
1420
                     CustomerInfo::where('phone', $consum->phone)->update(['balance'=>$balance]);
1422
                     CustomerInfo::where('phone', $consum->phone)->update(['balance'=>$balance]);
1421
                 }
1423
                 }
1422
 
1424
 
1504
                 if($order->payment_type == 4){
1506
                 if($order->payment_type == 4){
1505
                     //查询消费记录/卡号
1507
                     //查询消费记录/卡号
1506
                     $consum = CustomerConsum::where('order_id', $id)->where('is_del', 0)->first();
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');
1507
                     //消费记录设为删除
1511
                     //消费记录设为删除
1508
                     CustomerConsum::where('order_id', $id)->update(['is_del'=>1]);
1512
                     CustomerConsum::where('order_id', $id)->update(['is_del'=>1]);
1509
                     //余额返还
1513
                     //余额返还
1510
                     $cust = CustomerInfo::select('balance')->where('phone', $consum->phone)->first();
1514
                     $cust = CustomerInfo::select('balance')->where('phone', $consum->phone)->first();
1511
-                    $balance = $cust->balance + $order->receivedAmount;
1515
+                    $balance = $cust->balance + $fan_money;
1512
                     CustomerInfo::where('phone', $consum->phone)->update(['balance'=>$balance]);
1516
                     CustomerInfo::where('phone', $consum->phone)->update(['balance'=>$balance]);
1513
                 }
1517
                 }
1514
 
1518
 
1880
             }else{
1884
             }else{
1881
                 $data['is_refund'] = 1;
1885
                 $data['is_refund'] = 1;
1882
                 if(!$order->refund_type) $data['refund_type'] = 1;
1886
                 if(!$order->refund_type) $data['refund_type'] = 1;
1887
+                if(!$order->refund_time) $data['refund_time'] = date('Y-m-d');
1883
                 if($order->refund_type == 4 && $refund_price != $order->refund_price){
1888
                 if($order->refund_type == 4 && $refund_price != $order->refund_price){
1884
                     // 充值退补
1889
                     // 充值退补
1885
                     $res = $this->depositRefund($id, $refund_price);
1890
                     $res = $this->depositRefund($id, $refund_price);
1904
                         return 0;
1909
                         return 0;
1905
                     }
1910
                     }
1906
                 }
1911
                 }
1912
+            }elseif($refund_type != 4 && $order->refund_type == 4){
1913
+                return 0;
1907
             }
1914
             }
1908
             $data['refund_type'] = (int)$refund_type;
1915
             $data['refund_type'] = (int)$refund_type;
1916
+            if(!$order->refund_time) $data['refund_time'] = date('Y-m-d');
1909
         }
1917
         }
1910
         if($id>0 && !empty($data)){
1918
         if($id>0 && !empty($data)){
1911
             $res = Order::where('id', $id)->update($data);
1919
             $res = Order::where('id', $id)->update($data);
1927
         $order_refund = DB::table('customer_consum')->where('is_del', 0)->where('order_id', $order_id)->where('type', 1)->first();
1935
         $order_refund = DB::table('customer_consum')->where('is_del', 0)->where('order_id', $order_id)->where('type', 1)->first();
1928
         $balance = CustomerInfo::where('phone', $order_consum->phone)->pluck('balance');
1936
         $balance = CustomerInfo::where('phone', $order_consum->phone)->pluck('balance');
1929
         if(empty($order_refund)){
1937
         if(empty($order_refund)){
1930
-            if($refund_price<0){
1938
+            if($refund_price>0){
1931
                 //补钱,判断充值卡余额           
1939
                 //补钱,判断充值卡余额           
1932
-                if($balance + $refund_price < 0){
1940
+                if($balance - $refund_price < 0){
1933
                     return false;
1941
                     return false;
1934
                 }
1942
                 }
1935
             }
1943
             }
1939
             $consum['money'] = $refund_price;
1947
             $consum['money'] = $refund_price;
1940
             $consum['type'] = 1;
1948
             $consum['type'] = 1;
1941
             DB::table('customer_consum')->insert($consum);
1949
             DB::table('customer_consum')->insert($consum);
1942
-            $balance = $balance + $refund_price;
1950
+            $balance = $balance - $refund_price;
1943
         }elseif($order_refund->money != $refund_price){
1951
         }elseif($order_refund->money != $refund_price){
1944
             //已有退款,更变le 退款钱数
1952
             //已有退款,更变le 退款钱数
1945
-            if($balance + $refund_price - $order_refund->money <0 ){
1953
+            if($balance - $refund_price + $order_refund->money <0 ){
1946
                 return false;
1954
                 return false;
1947
             }
1955
             }
1948
             DB::table('customer_consum')->where('id', $order_refund->id)->update(['money'=>$refund_price]);
1956
             DB::table('customer_consum')->where('id', $order_refund->id)->update(['money'=>$refund_price]);
1949
-            $balance = $balance + $refund_price - $order_refund->money;
1957
+            $balance = $balance - $refund_price + $order_refund->money;
1950
         }
1958
         }
1951
    
1959
    
1952
         CustomerInfo::where('phone', $order_consum->phone)->update(['balance' => $balance]);
1960
         CustomerInfo::where('phone', $order_consum->phone)->update(['balance' => $balance]);

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

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

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