From 0ed540ccd8a5bd4123ab80ea7be3768d7f4d416a Mon Sep 17 00:00:00 2001 From: Hankin Date: Thu, 2 Apr 2026 12:01:42 +0800 Subject: [PATCH] refund --- .../Server/Admin/OrderController.php | 68 +++++++++---------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/app/Http/Controllers/Server/Admin/OrderController.php b/app/Http/Controllers/Server/Admin/OrderController.php index 2d9829f..44c29cb 100644 --- a/app/Http/Controllers/Server/Admin/OrderController.php +++ b/app/Http/Controllers/Server/Admin/OrderController.php @@ -1543,45 +1543,43 @@ class OrderController extends Controller $result = Http::post($url, $data); Log::info("退款:" . $result); $result = json_decode($result, true); - if (isset($result["code"]) && $result["code"] == 0) {//退款成功 - $refund->update(['is_hook' => 1]); - DB::commit(); - $admin_id = $request->merchant_admin_id; - $user_id = $this->matchFulinkUser($order->account_id); - $result_type = $this->getOrderType($order); - if ($user_id) { - $maker_user_id = 0;//福恋操作人id - $admin = !empty($admin_id) ? MerchantAdmins::find($admin_id) : MerchantAccount::find($merchant_id); - $maker_user_id = User::where('mobile', $admin->mobile)->value('id'); - $maker_user_id = $maker_user_id ?? 0; - $text = '订单类型:' . $result_type . ' 订单号:' . $order->trade_no . ' 发起退款' . $refund_price . '元 理由:' . $request->remark; - if ($maker_user_id) { - $nickname = User::where('id', $maker_user_id)->value('nickname'); - $text = $text . ' 操作人【' . $nickname . '】'; - } - //同步一条该订单用户的用户备注 - ClientComment::create([ - 'user_id' => $user_id, - 'maker_user_id' => $maker_user_id, - 'type' => 'mobile', - 'comment' => $text, - ]); - } - \CommonUtilsService::refundNotice($order, $refund_price, $result_type); - //未结算订单重新计算收益 - if ($order->pay_status == 1) {//重新计算预分成 - SendEarningMessageV2::dispatch($order->id)->onQueue('order'); - } elseif ($order->pay_status == 3) {//删除预分成记录 - MAdvanceEarning::where('m_order_id', $order->id)->delete(); - } - return $this->success('退款成功'); - } elseif (isset($result["code"]) && $result['code'] == 1) { + if (isset($result["code"]) && $result["code"] == 1) {//退款失败 $refund->update(['err_msg' => $result['message']]); DB::commit(); return $this->failure('退款失败,', $result['message']); - } else { - return $this->failure('退款失败'); } + $refund->update(['is_hook' => 1]); + DB::commit(); + $admin_id = $request->merchant_admin_id; + $user_id = $this->matchFulinkUser($order->account_id); + $result_type = $this->getOrderType($order); + if ($user_id) { + $maker_user_id = 0;//福恋操作人id + $admin = !empty($admin_id) ? MerchantAdmins::find($admin_id) : MerchantAccount::find($merchant_id); + $maker_user_id = User::where('mobile', $admin->mobile)->value('id'); + $maker_user_id = $maker_user_id ?? 0; + $text = '订单类型:' . $result_type . ' 订单号:' . $order->trade_no . ' 发起退款' . $refund_price . '元 理由:' . $request->remark; + if ($maker_user_id) { + $nickname = User::where('id', $maker_user_id)->value('nickname'); + $text = $text . ' 操作人【' . $nickname . '】'; + } + //同步一条该订单用户的用户备注 + ClientComment::create([ + 'user_id' => $user_id, + 'maker_user_id' => $maker_user_id, + 'type' => 'mobile', + 'comment' => $text, + ]); + } + \CommonUtilsService::refundNotice($order, $refund_price, $result_type); + //未结算订单重新计算收益 + if ($order->pay_status == 1) {//重新计算预分成 + SendEarningMessageV2::dispatch($order->id)->onQueue('order'); + } elseif ($order->pay_status == 3) {//删除预分成记录 + MAdvanceEarning::where('m_order_id', $order->id)->delete(); + } + DB::commit(); + return $this->success('退款成功'); } catch (\Exception $e) { DB::rollBack(); $this->getError($e);