|
|
|
@ -761,14 +761,20 @@ class OrderService implements OrderServiceInterface |
|
|
|
|
|
|
|
if (empty($orderMain)) { |
|
|
|
Db::rollBack(); |
|
|
|
return '查询不到订单'; |
|
|
|
return [ |
|
|
|
'code' => 1, |
|
|
|
'msg' =>'查询不到订单' |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
$orderMain->state = OrderMain::ORDER_STATE_REFUNDED; |
|
|
|
|
|
|
|
if(!$orderMain->save()){ |
|
|
|
Db::rollBack(); |
|
|
|
return '更新主订单失败'; |
|
|
|
return [ |
|
|
|
'code' => 2, |
|
|
|
'msg' =>'更新主订单失败' |
|
|
|
]; |
|
|
|
}; |
|
|
|
|
|
|
|
// 子订单状态更新
|
|
|
|
@ -778,64 +784,68 @@ class OrderService implements OrderServiceInterface |
|
|
|
->update(['state' => OrderMain::ORDER_STATE_REFUNDED]); |
|
|
|
if(empty($upChild)){ |
|
|
|
Db::rollBack(); |
|
|
|
return '更新子订单失败'; |
|
|
|
return [ |
|
|
|
'code' => 3, |
|
|
|
'msg' =>'更新子订单失败' |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
if($orderMain->pay_type == OrderMain::ORDER_PAY_WX){ |
|
|
|
$data = [ |
|
|
|
'global_order_id' => $global_order_id, |
|
|
|
'money' => $orderMain->money |
|
|
|
]; |
|
|
|
|
|
|
|
// 微信支付 微信退款
|
|
|
|
$refundRes = $this->wxRefundService->wxPayRefund($data); |
|
|
|
$refundRes = $this->wxRefundService->wxPayRefund($orderMain->global_order_id); |
|
|
|
var_dump($refundRes); |
|
|
|
if( |
|
|
|
empty($refundRes) |
|
|
|
|| !$refundRes |
|
|
|
|| !isset($refundRes['result_code']) |
|
|
|
|| $refundRes['result_code'] != 'SUCCESS' |
|
|
|
){ |
|
|
|
Db::rollBack(); |
|
|
|
return $refundRes; |
|
|
|
}; |
|
|
|
|
|
|
|
/* --- 退款成功 --- */ |
|
|
|
$orderMain = $orderMain->fresh(); |
|
|
|
if(empty($orderMain->refund_time)){ |
|
|
|
// 添加退款时间
|
|
|
|
$orderMain->refund_time = time(); |
|
|
|
$orderMain->save(); |
|
|
|
|
|
|
|
// 退款返还优惠券
|
|
|
|
$this->couponService->orderRefundCoupons($orderMain->global_order_id); |
|
|
|
|
|
|
|
// 删除特价商品缓存
|
|
|
|
$this->purchaseLimitService->delSsdbPurchaseRecord($orderMain->id); |
|
|
|
|
|
|
|
// 添加用户的流水
|
|
|
|
$this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); |
|
|
|
} |
|
|
|
}else if($orderMain->pay_type == OrderMain::ORDER_PAY_BALANCE){ |
|
|
|
|
|
|
|
// 余额支付 退款到用户余额
|
|
|
|
// if($this->userService->userWallet($orderMain->user_id,$orderMain->money,Users::WALLET_TYPE_INC)){
|
|
|
|
// Db::rollBack();
|
|
|
|
// return false;
|
|
|
|
// };
|
|
|
|
if($this->userService->userWallet($orderMain->user_id,$orderMain->money,Users::WALLET_TYPE_INC)){ |
|
|
|
Db::rollBack(); |
|
|
|
return [ |
|
|
|
'code' => 4, |
|
|
|
'msg' =>'退款到用户余额失败' |
|
|
|
]; |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
// 返还优惠券
|
|
|
|
// $this->couponService->orderRefundCoupon($global_order_id);
|
|
|
|
/* --- 退款成功 --- */ |
|
|
|
$orderMain = $orderMain->fresh(); |
|
|
|
if(empty($orderMain->refund_time)){ |
|
|
|
// 添加退款时间
|
|
|
|
$orderMain->refund_time = time(); |
|
|
|
$orderMain->save(); |
|
|
|
|
|
|
|
// 退款返还优惠券
|
|
|
|
$this->couponService->orderRefundCoupons($orderMain->global_order_id); |
|
|
|
|
|
|
|
// 删除特价商品缓存
|
|
|
|
// $this->orderService->clearTodayGoodPurchase($orderMain->user_id,1);
|
|
|
|
// 添加用户流水
|
|
|
|
// $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money);
|
|
|
|
$this->purchaseLimitService->delSsdbPurchaseRecord($orderMain->global_order_id); |
|
|
|
|
|
|
|
// 添加用户的流水
|
|
|
|
$this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); |
|
|
|
} |
|
|
|
|
|
|
|
Db::commit(); |
|
|
|
return true; |
|
|
|
return [ |
|
|
|
'code' => 0, |
|
|
|
'msg' =>'退款成功' |
|
|
|
]; |
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
|
|
$this->log->event(LogLabel::ORDER_LOG, ['msg'=> '订单退款','exception' => $e->getMessage()]); |
|
|
|
Db::rollBack(); |
|
|
|
return false; |
|
|
|
return [ |
|
|
|
'code' => 5, |
|
|
|
'msg' => $e->getMessage() |
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|