|
@@ -277,7 +277,6 @@ class OrderController extends Controller
|
|
|
$user_id = $order->user_id;
|
|
|
$area_id = $order->area_id;
|
|
|
|
|
|
-
|
|
|
if ($order->status == Order::STATUS_CLOSE_BIKE) {
|
|
|
$pay_money = bcadd($dispatch_money, $ridding_money, 2) < 0 ? 0 : bcadd($dispatch_money, $ridding_money, 2);
|
|
|
//1.判断用户钱包余额是否大于支付金额
|
|
@@ -287,7 +286,6 @@ class OrderController extends Controller
|
|
|
$result = bcsub($wallet_money, $pay_money, 2);
|
|
|
$order->pay_type = Order::PAY_TYPE_ACCOUNT;
|
|
|
|
|
|
-
|
|
|
try {
|
|
|
DB::beginTransaction();
|
|
|
// 修改调度费 各种费用
|
|
@@ -317,12 +315,7 @@ class OrderController extends Controller
|
|
|
$orderBikeOperate->is_admin = OrderBikeOperate::IS_ADMIN_YES;
|
|
|
$orderBikeOperate->admin_id = Admin::user()->id;
|
|
|
$orderBikeOperate->save();
|
|
|
- $user = User::find($order->user_id);
|
|
|
- if (!empty($order)) {
|
|
|
- Notification::send($user, new OrderNoPayNotification($user, $order));
|
|
|
- }
|
|
|
DB::commit();
|
|
|
- return $this->ok('费用已调整');
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
DB::rollBack();
|
|
@@ -330,11 +323,17 @@ class OrderController extends Controller
|
|
|
return $this->error('操作失败请联系管理员');
|
|
|
}
|
|
|
|
|
|
+ $user = User::find($order->user_id);
|
|
|
+ if (!empty($order)) {
|
|
|
+ Notification::send($user, new OrderNoPayNotification($user, $order));
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->ok('费用已调整');
|
|
|
+
|
|
|
} else {
|
|
|
return $this->error('车辆未关锁,请刷新后重试');
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -388,166 +387,162 @@ class OrderController extends Controller
|
|
|
DB::beginTransaction();
|
|
|
try {
|
|
|
|
|
|
- $old_pay_money = $order->pay_money;
|
|
|
- //1.更新订单
|
|
|
- $order->dispatch_money = bcsub($dispatch_money, $return_dispatch_money, 2);
|
|
|
- $order->time_money = bcsub($time_money, $return_ridding_money, 2);
|
|
|
- $order->pay_money = bcsub($pay_money, $return_money, 2);
|
|
|
- $order->total_money = bcadd($order->time_money, $order->dispatch_money, 2);
|
|
|
- $order->is_refund_money = Order::REFUND_MONEY_OK;
|
|
|
- $res1 = $order->save();
|
|
|
- OrderBikeOperate::logs(
|
|
|
- OrderBikeOperate::$typeMaps[OrderBikeOperate::TYPE_ADMIN_ORDER_REFUND] . '(' . Admin::user()->name . ')',
|
|
|
- OrderBikeOperate::TYPE_ADMIN_ORDER_REFUND,
|
|
|
- $order->bike_id,
|
|
|
- $order->id,
|
|
|
- $order->user_id,
|
|
|
- OrderBikeOperate::IS_ADMIN_YES,
|
|
|
- Admin::user()->id
|
|
|
- );
|
|
|
-
|
|
|
-
|
|
|
- if (!$res1) {
|
|
|
- DB::rollBack();
|
|
|
- Log::error('更新订单失败');
|
|
|
- return $this->error('操作失败请联系管理员');
|
|
|
- }
|
|
|
- //2.判断返还类别 更新用户余额 或微信退款
|
|
|
- if ($return_type === 'wallet') {
|
|
|
- $return_type_name = '退平台钱包';
|
|
|
- //3.插入钱包记录
|
|
|
- $wallet_log = new WalletLog();
|
|
|
- $wallet_log->name = WalletLog::$typeMaps[WalletLog::TYPE_ADMIN_ADD_TO_WALLET];
|
|
|
- $wallet_log->type = WalletLog::TYPE_ADMIN_ADD_TO_WALLET;
|
|
|
- $wallet_log->operate_type = WalletLog::OPERATE_TYPE_ADD;
|
|
|
- $wallet_log->money = (float)$return_money;
|
|
|
- $wallet_log->user_id = $user_id;
|
|
|
- $wallet_log->area_id = $area_id;
|
|
|
- $wallet_log->log_id = $order_id;
|
|
|
- $wallet_log->log_type = Order::class;
|
|
|
- $wallet_log->merchant_id = $order->merchant_id;
|
|
|
- $res2 = $wallet_log->save();
|
|
|
- if (!$res2) {
|
|
|
- DB::rollBack();
|
|
|
- Log::error('插入钱包记录失败');
|
|
|
- return $this->error('操作失败请联系管理员');
|
|
|
- }
|
|
|
- // 4.退余额
|
|
|
- $user = User::query()->find($user_id);
|
|
|
- $wallet_money = $user->wallet_money;
|
|
|
- $user->wallet_money = (float)$wallet_money + (float)$return_money;
|
|
|
- $res3 = $user->save();
|
|
|
- if (!$res3) {
|
|
|
+ $old_pay_money = $order->pay_money;
|
|
|
+ //1.更新订单
|
|
|
+ $order->dispatch_money = bcsub($dispatch_money, $return_dispatch_money, 2);
|
|
|
+ $order->time_money = bcsub($time_money, $return_ridding_money, 2);
|
|
|
+ $order->pay_money = bcsub($pay_money, $return_money, 2);
|
|
|
+ $order->total_money = bcadd($order->time_money, $order->dispatch_money, 2);
|
|
|
+ $order->is_refund_money = Order::REFUND_MONEY_OK;
|
|
|
+ $res1 = $order->save();
|
|
|
+ OrderBikeOperate::logs(
|
|
|
+ OrderBikeOperate::$typeMaps[OrderBikeOperate::TYPE_ADMIN_ORDER_REFUND] . '(' . Admin::user()->name . ')',
|
|
|
+ OrderBikeOperate::TYPE_ADMIN_ORDER_REFUND,
|
|
|
+ $order->bike_id,
|
|
|
+ $order->id,
|
|
|
+ $order->user_id,
|
|
|
+ OrderBikeOperate::IS_ADMIN_YES,
|
|
|
+ Admin::user()->id
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ if (!$res1) {
|
|
|
DB::rollBack();
|
|
|
- Log::error('更新用户余额失败');
|
|
|
+ Log::error('更新订单失败');
|
|
|
return $this->error('操作失败请联系管理员');
|
|
|
}
|
|
|
- } else if ($return_type === 'wechatANDalipay') {
|
|
|
- $return_type_name = '原路退回';
|
|
|
- //退微信
|
|
|
- if ($order->pay_type == Order::PAY_TYPE_ACCOUNT) {
|
|
|
- DB::rollBack();
|
|
|
- return $this->error('此订单为余额支付 ');
|
|
|
- }
|
|
|
- //插入钱包记录 增加
|
|
|
- $wallet_log_add = new WalletLog();
|
|
|
- $wallet_log_add->name = WalletLog::$typeMaps[WalletLog::TYPE_ADD_WECHAT_PAY_ORDER_MONEY];
|
|
|
- $wallet_log_add->type = WalletLog::TYPE_ADD_WECHAT_PAY_ORDER_MONEY;
|
|
|
- $wallet_log_add->operate_type = WalletLog::OPERATE_TYPE_ADD;
|
|
|
- $wallet_log_add->money = (float)$return_money;
|
|
|
- $wallet_log_add->user_id = $user_id;
|
|
|
- $wallet_log_add->area_id = $area_id;
|
|
|
- $wallet_log_add->log_id = $order_id;
|
|
|
- $wallet_log_add->log_type = Order::class;
|
|
|
- $wallet_log_add->merchant_id = $order->merchant_id;
|
|
|
- $wallet_log_add->save();
|
|
|
-
|
|
|
- //3.插入钱包记录 减少
|
|
|
- $wallet_log = new WalletLog();
|
|
|
- $wallet_log->name = WalletLog::$typeMaps[WalletLog::TYPE_SUB_ORDER_MONEY_PAY_WECHAT];
|
|
|
- $wallet_log->type = WalletLog::TYPE_SUB_ORDER_MONEY_PAY_WECHAT;
|
|
|
- $wallet_log->operate_type = WalletLog::OPERATE_TYPE_SUB;
|
|
|
- $wallet_log->money = -(float)$return_money;
|
|
|
- $wallet_log->user_id = $user_id;
|
|
|
- $wallet_log->area_id = $area_id;
|
|
|
- $wallet_log->log_id = $order_id;
|
|
|
- $wallet_log->status = WalletLog::STATUS_PAUSE;
|
|
|
- $wallet_log->log_type = Order::class;
|
|
|
- $wallet_log->merchant_id = $order->merchant_id;
|
|
|
- $res2 = $wallet_log->save();
|
|
|
- if (!$res2) {
|
|
|
- DB::rollBack();
|
|
|
- Log::error('插入钱包记录失败');
|
|
|
- return $this->error('操作失败请联系管理员');
|
|
|
- }
|
|
|
-
|
|
|
- switch ($order->pay_type) {
|
|
|
- case Order::PAY_TYPE_WECHAT:
|
|
|
-
|
|
|
- //微信退部分钱
|
|
|
- $payment = Factory::payment(wechat_pay_config(AdminMerchant::byId($order->merchant_id)));
|
|
|
- $refund_no = $order->no;
|
|
|
- $result = $payment->refund->byOutTradeNumber($order->no, $refund_no, wechat_fee($old_pay_money), wechat_fee($return_money), [
|
|
|
- // 可在此处传入其他参数,详细参数见微信支付文档
|
|
|
- 'refund_desc' => '退订单支付费用',
|
|
|
- 'notify_url' => config('bike.app_api_url') . '/api/payments/wechat-refund-notify/' . $order->merchant_id,
|
|
|
- ]);
|
|
|
+ //2.判断返还类别 更新用户余额 或微信退款
|
|
|
+ if ($return_type === 'wallet') {
|
|
|
+ $return_type_name = '退平台钱包';
|
|
|
+ //3.插入钱包记录
|
|
|
+ $wallet_log = new WalletLog();
|
|
|
+ $wallet_log->name = WalletLog::$typeMaps[WalletLog::TYPE_ADMIN_ADD_TO_WALLET];
|
|
|
+ $wallet_log->type = WalletLog::TYPE_ADMIN_ADD_TO_WALLET;
|
|
|
+ $wallet_log->operate_type = WalletLog::OPERATE_TYPE_ADD;
|
|
|
+ $wallet_log->money = (float)$return_money;
|
|
|
+ $wallet_log->user_id = $user_id;
|
|
|
+ $wallet_log->area_id = $area_id;
|
|
|
+ $wallet_log->log_id = $order_id;
|
|
|
+ $wallet_log->log_type = Order::class;
|
|
|
+ $wallet_log->merchant_id = $order->merchant_id;
|
|
|
+ $res2 = $wallet_log->save();
|
|
|
+ if (!$res2) {
|
|
|
+ DB::rollBack();
|
|
|
+ Log::error('插入钱包记录失败');
|
|
|
+ return $this->error('操作失败请联系管理员');
|
|
|
+ }
|
|
|
+ // 4.退余额
|
|
|
+ $user = User::query()->find($user_id);
|
|
|
+ $wallet_money = $user->wallet_money;
|
|
|
+ $user->wallet_money = (float)$wallet_money + (float)$return_money;
|
|
|
+ $res3 = $user->save();
|
|
|
+ if (!$res3) {
|
|
|
+ DB::rollBack();
|
|
|
+ Log::error('更新用户余额失败');
|
|
|
+ return $this->error('操作失败请联系管理员');
|
|
|
+ }
|
|
|
+ } else if ($return_type === 'wechatANDalipay') {
|
|
|
+ $return_type_name = '原路退回';
|
|
|
+ //退微信
|
|
|
+ if ($order->pay_type == Order::PAY_TYPE_ACCOUNT) {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->error('此订单为余额支付 ');
|
|
|
+ }
|
|
|
+ //插入钱包记录 增加
|
|
|
+ $wallet_log_add = new WalletLog();
|
|
|
+ $wallet_log_add->name = WalletLog::$typeMaps[WalletLog::TYPE_ADD_WECHAT_PAY_ORDER_MONEY];
|
|
|
+ $wallet_log_add->type = WalletLog::TYPE_ADD_WECHAT_PAY_ORDER_MONEY;
|
|
|
+ $wallet_log_add->operate_type = WalletLog::OPERATE_TYPE_ADD;
|
|
|
+ $wallet_log_add->money = (float)$return_money;
|
|
|
+ $wallet_log_add->user_id = $user_id;
|
|
|
+ $wallet_log_add->area_id = $area_id;
|
|
|
+ $wallet_log_add->log_id = $order_id;
|
|
|
+ $wallet_log_add->log_type = Order::class;
|
|
|
+ $wallet_log_add->merchant_id = $order->merchant_id;
|
|
|
+ $wallet_log_add->save();
|
|
|
+
|
|
|
+ //3.插入钱包记录 减少
|
|
|
+ $wallet_log = new WalletLog();
|
|
|
+ $wallet_log->name = WalletLog::$typeMaps[WalletLog::TYPE_SUB_ORDER_MONEY_PAY_WECHAT];
|
|
|
+ $wallet_log->type = WalletLog::TYPE_SUB_ORDER_MONEY_PAY_WECHAT;
|
|
|
+ $wallet_log->operate_type = WalletLog::OPERATE_TYPE_SUB;
|
|
|
+ $wallet_log->money = -(float)$return_money;
|
|
|
+ $wallet_log->user_id = $user_id;
|
|
|
+ $wallet_log->area_id = $area_id;
|
|
|
+ $wallet_log->log_id = $order_id;
|
|
|
+ $wallet_log->status = WalletLog::STATUS_PAUSE;
|
|
|
+ $wallet_log->log_type = Order::class;
|
|
|
+ $wallet_log->merchant_id = $order->merchant_id;
|
|
|
+ $res2 = $wallet_log->save();
|
|
|
+ if (!$res2) {
|
|
|
+ DB::rollBack();
|
|
|
+ Log::error('插入钱包记录失败');
|
|
|
+ return $this->error('操作失败请联系管理员');
|
|
|
+ }
|
|
|
|
|
|
- if ($result['return_code'] === 'SUCCESS') {
|
|
|
+ switch ($order->pay_type) {
|
|
|
+ case Order::PAY_TYPE_WECHAT:
|
|
|
+
|
|
|
+ //微信退部分钱
|
|
|
+ $payment = Factory::payment(wechat_pay_config(AdminMerchant::byId($order->merchant_id)));
|
|
|
+ $refund_no = $order->no;
|
|
|
+ $result = $payment->refund->byOutTradeNumber($order->no, $refund_no, wechat_fee($old_pay_money), wechat_fee($return_money), [
|
|
|
+ // 可在此处传入其他参数,详细参数见微信支付文档
|
|
|
+ 'refund_desc' => '退订单支付费用',
|
|
|
+ 'notify_url' => config('bike.app_api_url') . '/api/payments/wechat-refund-notify/' . $order->merchant_id,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if ($result['return_code'] === 'SUCCESS') {
|
|
|
+ DB::commit();
|
|
|
+ return $this->ok('退还成功');
|
|
|
+ } else {
|
|
|
+ Log::error($result);
|
|
|
+ Log::error('微信退款接口失败');
|
|
|
+ DB::commit();
|
|
|
+ return $this->error('退还失败,请联系管理员');
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case Order::PAY_TYPE_ALIPAYMINI:
|
|
|
+ //支付宝退部分钱
|
|
|
$user = User::find($order->user_id);
|
|
|
- // 返还通知
|
|
|
- Notification::send($user, new OrderRefundNotification($user, $order, $return_money, $return_type_name));
|
|
|
- DB::commit();
|
|
|
- return $this->ok('退还成功');
|
|
|
- } else {
|
|
|
- Log::error('微信退款接口失败');
|
|
|
- DB::commit();
|
|
|
- return $this->error('退还失败,请联系管理员');
|
|
|
- }
|
|
|
- break;
|
|
|
- case Order::PAY_TYPE_ALIPAYMINI:
|
|
|
- //支付宝退部分钱
|
|
|
- $user = User::find($order->user_id);
|
|
|
- $refund_no = $order->no;
|
|
|
- $url = config('systemConfig.api_url') . '/api/common/alipay-refund-little?merchant_id=' . $user->merchant_id . '&no=' . $order->no . '&money=' . $return_money . '&out_request_no=' . $refund_no;
|
|
|
- $data = [
|
|
|
- 'merchant_id' => $user->merchant_id,
|
|
|
- 'no' => $order->no,
|
|
|
- 'money' => $return_money,
|
|
|
- 'out_request_no' => $refund_no
|
|
|
- ];
|
|
|
-
|
|
|
- $res = curl_request($url, 'get', $data);
|
|
|
-
|
|
|
- $res = json_decode($res, true);
|
|
|
-
|
|
|
- if ($res['is_refund_status']) {
|
|
|
- //返还成功
|
|
|
- // 返还通知
|
|
|
- Notification::send($user, new OrderRefundNotification($user, $order, $return_money, $return_type_name));
|
|
|
- DB::commit();
|
|
|
- $order->refund_order_callback();
|
|
|
- return $this->ok('退还成功');
|
|
|
- } else {
|
|
|
- Log::error('支付宝退款接口失败');
|
|
|
- DB::commit();
|
|
|
- return $this->error('退还失败,请联系管理员');
|
|
|
- }
|
|
|
+ $refund_no = $order->no;
|
|
|
+ $url = config('systemConfig.api_url') . '/api/common/alipay-refund-little?merchant_id=' . $user->merchant_id . '&no=' . $order->no . '&money=' . $return_money . '&out_request_no=' . $refund_no;
|
|
|
+ $data = [
|
|
|
+ 'merchant_id' => $user->merchant_id,
|
|
|
+ 'no' => $order->no,
|
|
|
+ 'money' => $return_money,
|
|
|
+ 'out_request_no' => $refund_no
|
|
|
+ ];
|
|
|
+
|
|
|
+ $res = curl_request($url, 'get', $data);
|
|
|
+
|
|
|
+ $res = json_decode($res, true);
|
|
|
+
|
|
|
+ if ($res['is_refund_status']) {
|
|
|
+ //返还成功
|
|
|
+ DB::commit();
|
|
|
+ $order->refund_order_callback();
|
|
|
+ return $this->ok('退还成功');
|
|
|
+ } else {
|
|
|
+ Log::error('支付宝退款接口失败');
|
|
|
+ DB::commit();
|
|
|
+ return $this->error('退还失败,请联系管理员');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->error('返还类型不存在');
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- break;
|
|
|
- default:
|
|
|
- DB::rollBack();
|
|
|
- return $this->error('返还类型不存在');
|
|
|
+ } else {
|
|
|
+ DB::rollBack();
|
|
|
+ return $this->error('返还类型错误');
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- } else {
|
|
|
- DB::rollBack();
|
|
|
- return $this->error('返还类型错误');
|
|
|
- }
|
|
|
-
|
|
|
- DB::commit();
|
|
|
+ DB::commit();
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
DB::rollBack();
|