From a115068bbc5b561395b91ef5dd4358ccf697181d Mon Sep 17 00:00:00 2001 From: ctexthuang Date: Tue, 18 Mar 2025 15:15:25 +0800 Subject: [PATCH] feat : wechatPay callback --- app/Model/RefundOrder.php | 2 +- app/Service/Amqp/Refund/RefundService.php | 2 +- app/Service/Api/Order/RefundOrderService.php | 12 +++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/Model/RefundOrder.php b/app/Model/RefundOrder.php index f9252fa..9299d0a 100644 --- a/app/Model/RefundOrder.php +++ b/app/Model/RefundOrder.php @@ -73,7 +73,7 @@ class RefundOrder extends Model ->where('order_id', $orderId) ->where('order_type', $type) ->whereIn('refund_status',[ - RefundCode::WAIT_REFUND, + RefundCode::WAIT_BY_PAY_TOOL, RefundCode::REFUND_SUCCESS ])->sum('refund_money') ?? 0; } diff --git a/app/Service/Amqp/Refund/RefundService.php b/app/Service/Amqp/Refund/RefundService.php index 1121d3e..d7802c4 100644 --- a/app/Service/Amqp/Refund/RefundService.php +++ b/app/Service/Amqp/Refund/RefundService.php @@ -199,7 +199,7 @@ class RefundService protected function checkRefundAmount(): void { // 等于支付金额 减去 已退款金额 减去 本次退款金额 小于 0 就是错误的 大于等于 0 就是正确的 - if ($this->payInfo->pay_money - $this->isRefundMoney - $this->refundAmount < 0) throw new Exception('退款金额不能大于订单金额'); + if (($this->payInfo->pay_money - $this->isRefundMoney - $this->refundAmount) < 0) throw new Exception('退款金额不能大于订单金额'); $this->refundAmount = min($this->payInfo->pay_money - $this->isRefundMoney, $this->refundAmount); } diff --git a/app/Service/Api/Order/RefundOrderService.php b/app/Service/Api/Order/RefundOrderService.php index 9d14348..33f493e 100644 --- a/app/Service/Api/Order/RefundOrderService.php +++ b/app/Service/Api/Order/RefundOrderService.php @@ -13,6 +13,7 @@ namespace App\Service\Api\Order; use App\Constants\Common\OrderCode; use App\Exception\ErrException; use App\Model\Order; +use App\Model\PayOrder; use App\Service\Api\BaseService; use App\Service\ServiceTrait\Common\OrderChangeStatusTrait; use Hyperf\Di\Annotation\Inject; @@ -29,6 +30,12 @@ class RefundOrderService extends BaseService #[Inject] protected Order $orderModel; + /** + * @var PayOrder + */ + #[Inject] + protected PayOrder $payOrderModel; + /** * @return array * @throws ContainerExceptionInterface @@ -44,8 +51,11 @@ class RefundOrderService extends BaseService if ($orderInfo->status != OrderCode::PAYED) throw new ErrException('该订单状态已变更,请勿重复操作,刷新后无法退款请联系客服'); + $payInfo = $this->payOrderModel->getInfoByOrderIdAndType($orderInfo->id,OrderCode::ORDER_TYPE_GOOD); + if (empty($payInfo)) throw new ErrException('订单支付信息不存在'); + //立即取消 - $this->joinRefundQueue($orderId, $type, (float)$orderInfo->actual_price, '用户主动取消订单'); + $this->joinRefundQueue($orderId, $type, (float)$payInfo->pay_money, '用户主动取消订单'); return $this->return->success(); }