feat : wechatPay callback

This commit is contained in:
2025-03-18 16:20:32 +08:00
parent bdffc3311d
commit 63b6cce2bd
5 changed files with 25 additions and 20 deletions

View File

@@ -72,10 +72,12 @@ class RefundOrder extends Model
return $this return $this
->where('order_id', $orderId) ->where('order_id', $orderId)
->where('order_type', $type) ->where('order_type', $type)
->whereIn('refund_status',[ ->where('refund_status',RefundCode::REFUND_SUCCESS)
RefundCode::WAIT_BY_PAY_TOOL, // ->whereIn('refund_status',[
RefundCode::REFUND_SUCCESS // RefundCode::WAIT_BY_PAY_TOOL,
])->sum('refund_money') ?? 0; // RefundCode::REFUND_SUCCESS
// ])
->sum('refund_money') ?? 0;
} }
/** /**
@@ -95,6 +97,6 @@ class RefundOrder extends Model
*/ */
public function getInfoByOrderSnoAndType(string $orderSno, int $type): \Hyperf\Database\Model\Model|null public function getInfoByOrderSnoAndType(string $orderSno, int $type): \Hyperf\Database\Model\Model|null
{ {
return $this->where('order_sno',$orderSno)->where('order_type',$type)->first(); return $this->where('refund_order_sno',$orderSno)->where('refund_type',$type)->first();
} }
} }

View File

@@ -184,7 +184,7 @@ class RefundService
*/ */
protected function getAllRefundMoneyByOrderId(): void protected function getAllRefundMoneyByOrderId(): void
{ {
$this->isRefundMoney = $this->refundOrderModel->getSuccessMoneyByOrderId($this->orderId,$this->type); $this->isRefundMoney = $this->refundOrderModel->getAllMoneyByOrderId($this->orderId,$this->type);
} }
// protected function getUser() // protected function getUser()

View File

@@ -97,13 +97,13 @@ abstract class WxJsRechargeBaseService implements ThirdPayInterface
{ {
$this->setConfig(); $this->setConfig();
// $this->callbackData = $this->request->all(); $this->callbackData = $this->request->all();
try { // try {
$this->callbackData = $this->ysdPay->wechat($this->config)->callback($this->request)->toArray()['resource']['ciphertext']; // $this->callbackData = $this->ysdPay->wechat($this->config)->callback($this->request)->toArray()['resource']['ciphertext'];
}catch (Exception $e) { // }catch (Exception $e) {
$this->log->debug(__CLASS__.'wxPay回调解密失败'.json_encode($e->getMessage())); // $this->log->debug(__CLASS__.'wxPay回调解密失败'.json_encode($e->getMessage()));
throw new ErrException('wxPay回调解密失败'); // throw new ErrException('wxPay回调解密失败');
} // }
if (empty($this->callbackData)) { if (empty($this->callbackData)) {
$this->log->debug(__CLASS__.'wxPay获取回调失败'.json_encode($this->request)); $this->log->debug(__CLASS__.'wxPay获取回调失败'.json_encode($this->request));

View File

@@ -34,16 +34,18 @@ trait CheckOrderCallBackTrait
public function checkWxRefundCallBackOrder(): void public function checkWxRefundCallBackOrder(): void
{ {
if ( if (
!isset($this->callbackData['return_code']) || !isset($this->callbackData['refund_status']) ||
$this->callbackData['return_code']!= 'SUCCESS' || $this->callbackData['refund_status']!= 'SUCCESS' ||
!isset($this->callbackData['out_trade_no']) || !isset($this->callbackData['out_trade_no']) ||
empty($this->callbackData['out_trade_no']) || empty($this->callbackData['out_trade_no']) ||
!isset($this->callbackData['mch_id']) || !isset($this->callbackData['out_refund_no']) ||
empty($this->callbackData['mch_id']) empty($this->callbackData['out_refund_no']) ||
!isset($this->callbackData['amount']['total']) ||
$this->callbackData['amount']['total'] <= 0
) { ) {
throw new ErrException('此订单回调异常'); throw new ErrException('此订单回调异常');
} }
$this->orderNo = $this->callbackData['out_trade_no']; $this->orderNo = $this->callbackData['out_refund_no'];
} }
} }

View File

@@ -19,7 +19,7 @@ trait RefundOrderTrait
*/ */
protected function checkRefundOrder(): void protected function checkRefundOrder(): void
{ {
$this->refundInfo = $this->refundOrderModel->getInfoByOrderSnoAndType($this->orderNo,self::OrderType); $this->refundInfo = $this->refundOrderModel->getInfoByOrderSnoAndType($this->orderNo,self::PayType);
$this->orderInfo = $this->orderModel->getInfoById($this->refundInfo->order_id); $this->orderInfo = $this->orderModel->getInfoById($this->refundInfo->order_id);
$this->payInfo = $this->payOrderModel->getInfoByOrderIdAndTypeAndRType($this->orderInfo->id,self::OrderType,self::PayType); $this->payInfo = $this->payOrderModel->getInfoByOrderIdAndTypeAndRType($this->orderInfo->id,self::OrderType,self::PayType);
@@ -51,6 +51,7 @@ trait RefundOrderTrait
$this->refundInfo->refund_time = date('Y-m-d H:i:s'); $this->refundInfo->refund_time = date('Y-m-d H:i:s');
$this->refundInfo->wx_transaction_id = $this->callbackData['transaction_id']; $this->refundInfo->wx_transaction_id = $this->callbackData['transaction_id'];
$this->refundInfo->notify_json = json_encode($this->callbackData); $this->refundInfo->notify_json = json_encode($this->callbackData);
$this->refundInfo->remark = '退款成功';
if (!$this->refundInfo->save()) throw new Exception('更新退款订单失败'); if (!$this->refundInfo->save()) throw new Exception('更新退款订单失败');
@@ -72,7 +73,7 @@ trait RefundOrderTrait
if ($isRefundMoney <= 0) throw new Exception('订单退款金额错误'); if ($isRefundMoney <= 0) throw new Exception('订单退款金额错误');
if ($isRefundMoney == $this->orderInfo->actual_price) { if ($isRefundMoney == $this->payInfo->pay_money) {
$this->orderInfo->status = OrderCode::FINISH_REFUND; $this->orderInfo->status = OrderCode::FINISH_REFUND;
$this->orderInfo->is_refund_all = 1;//todo 感觉可以删除这个值 $this->orderInfo->is_refund_all = 1;//todo 感觉可以删除这个值
} else { } else {