|
|
@@ -11,12 +11,17 @@ use SixShop\Payment\Contracts\PaymentNotifyResult;
|
|
|
use SixShop\Payment\Contracts\PaymentProviderInterface;
|
|
|
use SixShop\Payment\Contracts\PaymentQueryResult;
|
|
|
use SixShop\Payment\Contracts\PaymentRefundQueryResult;
|
|
|
+use SixShop\Payment\Contracts\PaymentRefundRequest;
|
|
|
use SixShop\Payment\Contracts\PaymentRefundResult;
|
|
|
use SixShop\Payment\Contracts\PaymentResponse;
|
|
|
use SixShop\Payment\Entity\ExtensionPaymentEntity;
|
|
|
+use SixShop\Payment\Entity\ExtensionRefundEntity;
|
|
|
use SixShop\Payment\Enum\PaymentBizEnum;
|
|
|
use SixShop\Payment\Enum\PaymentStatusEnum;
|
|
|
+use SixShop\Payment\Enum\RefundStatusEnum;
|
|
|
use SixShop\Payment\Event\PaymentSuccessEvent;
|
|
|
+use SixShop\Payment\Event\RefundSuccessEvent;
|
|
|
+use think\facade\Db;
|
|
|
use think\facade\Event;
|
|
|
|
|
|
class PaymentProvider implements PaymentProviderInterface
|
|
|
@@ -26,6 +31,7 @@ class PaymentProvider implements PaymentProviderInterface
|
|
|
public function __construct(
|
|
|
private readonly ExtensionBalpayLogEntity $logEntity,
|
|
|
private readonly ExtensionPaymentEntity $extensionPaymentEntity,
|
|
|
+ private readonly ExtensionRefundEntity $extensionRefundEntity,
|
|
|
)
|
|
|
{
|
|
|
}
|
|
|
@@ -51,7 +57,7 @@ class PaymentProvider implements PaymentProviderInterface
|
|
|
'amount' => $order['pay_amount'],
|
|
|
'status' => PaymentStatusEnum::SUCCESS,
|
|
|
]);
|
|
|
- $this->logEntity->add(
|
|
|
+ $this->logEntity->change(
|
|
|
$order['user_id'],
|
|
|
(float)$order['pay_amount'],
|
|
|
BalpayLogTypeEnum::CONSUMTION,
|
|
|
@@ -77,9 +83,31 @@ class PaymentProvider implements PaymentProviderInterface
|
|
|
|
|
|
}
|
|
|
|
|
|
- public function refund(array $refund): PaymentRefundResult
|
|
|
+ public function refund(int $recordID, PaymentRefundRequest $param): PaymentRefundResult
|
|
|
{
|
|
|
- throw new \Exception('未实现refund方法');
|
|
|
+ $payment = $this->extensionPaymentEntity->find($recordID);
|
|
|
+ $reund = Db::transaction(function () use ($payment, $param) {
|
|
|
+ $reund = $this->extensionRefundEntity->create([
|
|
|
+ 'payment_id' => $payment->id,
|
|
|
+ 'order_sn' => $payment->out_trade_no,
|
|
|
+ 'reason' => $param->getReason(),
|
|
|
+ 'amount' => $param->getAmount(),
|
|
|
+ 'status' => RefundStatusEnum::SUCCESS,
|
|
|
+ 'status_desc' => '已经退款到用户余额',
|
|
|
+ ]);
|
|
|
+ $this->logEntity->change(
|
|
|
+ $payment->user_id,
|
|
|
+ $param->getAmount(),
|
|
|
+ BalpayLogTypeEnum::REFUND,
|
|
|
+ sprintf('订单退款成功,订单编号:%s', $payment->order_sn),
|
|
|
+ $payment->order_id
|
|
|
+ );
|
|
|
+ // 余额退款直接成功
|
|
|
+ Event::trigger(new RefundSuccessEvent($reund));
|
|
|
+ return $reund;
|
|
|
+ });
|
|
|
+
|
|
|
+ return new PaymentRefundResult($reund);
|
|
|
}
|
|
|
|
|
|
public function refundQuery(string $refundNo): PaymentRefundQueryResult
|