Browse Source

充值卡退补

sunhao 5 years ago
parent
commit
922b178f57

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

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

+ 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>