|
@@ -21,6 +21,7 @@ use SixShop\Payment\Enum\RefundStatusEnum;
|
|
|
use SixShop\Payment\Event\PaymentSuccessEvent;
|
|
use SixShop\Payment\Event\PaymentSuccessEvent;
|
|
|
use SixShop\Payment\Event\RefundSuccessEvent;
|
|
use SixShop\Payment\Event\RefundSuccessEvent;
|
|
|
use SixShop\Wechat\Facade\WechatUser;
|
|
use SixShop\Wechat\Facade\WechatUser;
|
|
|
|
|
+use SixShop\WechatPay\Job\QueryRefundJob;
|
|
|
use SixShop\WechatPay\Trait\ApiTrait;
|
|
use SixShop\WechatPay\Trait\ApiTrait;
|
|
|
use SixShop\WechatPay\Trait\PaymentParamsTrait;
|
|
use SixShop\WechatPay\Trait\PaymentParamsTrait;
|
|
|
use think\facade\Db;
|
|
use think\facade\Db;
|
|
@@ -73,7 +74,7 @@ class PaymentProvider implements PaymentProviderInterface
|
|
|
$payment->expire_time = $expireTime;
|
|
$payment->expire_time = $expireTime;
|
|
|
$openid = WechatUser::openid($order['user_id']);
|
|
$openid = WechatUser::openid($order['user_id']);
|
|
|
if ($openid === null) {
|
|
if ($openid === null) {
|
|
|
- Helper::throw_logic_exception('用户需要先使用微信登录绑定微信身份');
|
|
|
|
|
|
|
+ throw_logic_exception('用户需要先使用微信登录绑定微信身份');
|
|
|
}
|
|
}
|
|
|
$payment->payment_param = $this->wechatPay(
|
|
$payment->payment_param = $this->wechatPay(
|
|
|
openid: $openid,
|
|
openid: $openid,
|
|
@@ -127,8 +128,8 @@ class PaymentProvider implements PaymentProviderInterface
|
|
|
public function refund(int $recordID, PaymentRefundRequest $param): PaymentRefundResult
|
|
public function refund(int $recordID, PaymentRefundRequest $param): PaymentRefundResult
|
|
|
{
|
|
{
|
|
|
$payment = $this->extensionPaymentEntity->find($recordID);
|
|
$payment = $this->extensionPaymentEntity->find($recordID);
|
|
|
- $reund = Db::transaction(function () use ($param, $payment) {
|
|
|
|
|
- $reund = $this->extensionRefundEntity->create([
|
|
|
|
|
|
|
+ $refund = Db::transaction(function () use ($param, $payment) {
|
|
|
|
|
+ $refund = $this->extensionRefundEntity->create([
|
|
|
'payment_id' => $payment->id,
|
|
'payment_id' => $payment->id,
|
|
|
'order_sn' => $payment->out_trade_no,
|
|
'order_sn' => $payment->out_trade_no,
|
|
|
'reason' => $param->getReason(),
|
|
'reason' => $param->getReason(),
|
|
@@ -137,16 +138,28 @@ class PaymentProvider implements PaymentProviderInterface
|
|
|
'refund_param' => $param->getRaw(),
|
|
'refund_param' => $param->getRaw(),
|
|
|
'status_desc' => '正在申请微信接口退款',
|
|
'status_desc' => '正在申请微信接口退款',
|
|
|
]);
|
|
]);
|
|
|
- $this->domesticRefunds(
|
|
|
|
|
- $reund->out_refund_no,
|
|
|
|
|
|
|
+ $result = $this->domesticRefunds(
|
|
|
|
|
+ $refund->out_refund_no,
|
|
|
$payment->out_trade_no,
|
|
$payment->out_trade_no,
|
|
|
$param->getAmount(),
|
|
$param->getAmount(),
|
|
|
$payment->amount,
|
|
$payment->amount,
|
|
|
$param->getReason()
|
|
$param->getReason()
|
|
|
);
|
|
);
|
|
|
- return $reund;
|
|
|
|
|
|
|
+ $refund->refund_id = $result->refund_id;
|
|
|
|
|
+ $refund->refund_result = $result;
|
|
|
|
|
+ $refund->save();
|
|
|
|
|
+ if ($result->status === 'SUCCESS' || $result->status === 'PROCESSING') {
|
|
|
|
|
+ QueryRefundJob::dispatch($refund->id)->delay(10);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new \RuntimeException(match ($result->status) {
|
|
|
|
|
+ 'CLOSED' => '退款关闭',
|
|
|
|
|
+ 'ABNORMAL' => '退款异常',
|
|
|
|
|
+ default => '未知错误',
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ return $refund;
|
|
|
});
|
|
});
|
|
|
- return new PaymentRefundResult($reund);
|
|
|
|
|
|
|
+ return new PaymentRefundResult($refund);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function refundQuery(int $refundID): PaymentRefundResult
|
|
public function refundQuery(int $refundID): PaymentRefundResult
|
|
@@ -154,10 +167,9 @@ class PaymentProvider implements PaymentProviderInterface
|
|
|
$refund = $this->extensionRefundEntity->with('payment')->find($refundID);
|
|
$refund = $this->extensionRefundEntity->with('payment')->find($refundID);
|
|
|
if ($refund->status === RefundStatusEnum::REFUNDING) {
|
|
if ($refund->status === RefundStatusEnum::REFUNDING) {
|
|
|
$result = $this->queryRefund($refund->out_refund_no);
|
|
$result = $this->queryRefund($refund->out_refund_no);
|
|
|
- $refund->refund_id = $result->refund_id;
|
|
|
|
|
$refund->refund_result = $result;
|
|
$refund->refund_result = $result;
|
|
|
if ($result->status === 'SUCCESS') {
|
|
if ($result->status === 'SUCCESS') {
|
|
|
- $refund->status = RefunddStatusEnum::SUCCESS;
|
|
|
|
|
|
|
+ $refund->status = RefundStatusEnum::SUCCESS;
|
|
|
$refund->success_time = strtotime($result->success_time);
|
|
$refund->success_time = strtotime($result->success_time);
|
|
|
Event::trigger(new RefundSuccessEvent(
|
|
Event::trigger(new RefundSuccessEvent(
|
|
|
$refund->model(),
|
|
$refund->model(),
|