|
@@ -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');
|