feat : wechatPay callback

This commit is contained in:
2025-03-18 15:15:25 +08:00
parent c8a36f4af8
commit a115068bbc
3 changed files with 13 additions and 3 deletions

View File

@@ -73,7 +73,7 @@ class RefundOrder extends Model
->where('order_id', $orderId) ->where('order_id', $orderId)
->where('order_type', $type) ->where('order_type', $type)
->whereIn('refund_status',[ ->whereIn('refund_status',[
RefundCode::WAIT_REFUND, RefundCode::WAIT_BY_PAY_TOOL,
RefundCode::REFUND_SUCCESS RefundCode::REFUND_SUCCESS
])->sum('refund_money') ?? 0; ])->sum('refund_money') ?? 0;
} }

View File

@@ -199,7 +199,7 @@ class RefundService
protected function checkRefundAmount(): void protected function checkRefundAmount(): void
{ {
// 等于支付金额 减去 已退款金额 减去 本次退款金额 小于 0 就是错误的 大于等于 0 就是正确的 // 等于支付金额 减去 已退款金额 减去 本次退款金额 小于 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); $this->refundAmount = min($this->payInfo->pay_money - $this->isRefundMoney, $this->refundAmount);
} }

View File

@@ -13,6 +13,7 @@ namespace App\Service\Api\Order;
use App\Constants\Common\OrderCode; use App\Constants\Common\OrderCode;
use App\Exception\ErrException; use App\Exception\ErrException;
use App\Model\Order; use App\Model\Order;
use App\Model\PayOrder;
use App\Service\Api\BaseService; use App\Service\Api\BaseService;
use App\Service\ServiceTrait\Common\OrderChangeStatusTrait; use App\Service\ServiceTrait\Common\OrderChangeStatusTrait;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
@@ -29,6 +30,12 @@ class RefundOrderService extends BaseService
#[Inject] #[Inject]
protected Order $orderModel; protected Order $orderModel;
/**
* @var PayOrder
*/
#[Inject]
protected PayOrder $payOrderModel;
/** /**
* @return array * @return array
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
@@ -44,8 +51,11 @@ class RefundOrderService extends BaseService
if ($orderInfo->status != OrderCode::PAYED) throw new ErrException('该订单状态已变更,请勿重复操作,刷新后无法退款请联系客服'); 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(); return $this->return->success();
} }