feat : wechatPay callback

This commit is contained in:
2025-03-18 11:14:07 +08:00
parent b50a0738fb
commit 4f4a4a6dd4
10 changed files with 42 additions and 30 deletions

View File

@@ -12,14 +12,14 @@ trait CheckOrderCallBackTrait
public function checkWxCallBackOrder(): void
{
if (
!isset($this->callbackData['return_code']) ||
$this->callbackData['return_code'] != 'SUCCESS' ||
!isset($this->callbackData['total_fee']) ||
$this->callbackData['total_fee'] <= 0 ||
!isset($this->callbackData['trade_state']) ||
$this->callbackData['trade_state'] != 'SUCCESS' ||
!isset($this->callbackData['amount']['total']) ||
$this->callbackData['amount']['total'] <= 0 ||
!isset($this->callbackData['out_trade_no']) ||
empty($this->callbackData['out_trade_no']) ||
!isset($this->callbackData['mch_id']) ||
empty($this->callbackData['mch_id']) ||
// !isset($this->callbackData['mch_id']) ||
// empty($this->callbackData['mch_id']) ||
!in_array($this->callbackData['trade_type'],['APP','JSAPI'])
){
throw new ErrException('此订单回调异常');

View File

@@ -50,10 +50,10 @@ trait GoodOrderTrait
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
protected function checkOrder(): void
protected function checkCallBackOrder(): void
{
$this->orderInfo = $this->orderModel->getInfoByOrderSno($this->orderNo);
$this->payInfo = $this->payOrderModel->getInfoByOrderIdAndType($this->orderInfo->id,self::OrderType);
$this->payInfo = $this->payOrderModel->getInfoByOrderIdAndTypeAndRType($this->orderInfo->id,self::OrderType,self::PayType);
if (empty($this->orderInfo) || empty($this->payInfo)) {
$this->log->debug(__CLASS__.':订单不存在,订单号:'.$this->orderNo);
@@ -65,7 +65,7 @@ trait GoodOrderTrait
throw new ErrException('订单已充值成功');
}
if ($this->orderInfo->action != PayCode::WECHAT_PAY) {
if ($this->payInfo->recharge_type != PayCode::WECHAT_PAY) {
$this->log->debug(__CLASS__.':订单充值渠道错误,订单信息:'.json_encode($this->orderInfo->toArray()));
throw new ErrException('订单充值渠道错误');
}
@@ -78,13 +78,12 @@ trait GoodOrderTrait
*/
protected function manageOrder(): void
{
try {
$this->orderInfo->status = OrderCode::PAYED;
$this->orderInfo->pay_time = date('Y-m-d H:i:s');
$this->orderInfo->status = OrderCode::PAYED;
$this->orderInfo->pay_time = date('Y-m-d H:i:s');
}catch (Exception $e) {
$this->log->error(__CLASS__.':Function:manageGoodOrder:'.$e->getMessage().':orderId:'.$this->orderInfo->id);
throw new ErrException($e->getMessage());
if (!$this->orderInfo->save()) {
$this->log->debug(__CLASS__.':Function:manageOrder:更新充值订单的状态失败:'.$this->orderInfo->id);
throw new ErrException('更新充值订单的状态失败');
}
}
}

View File

@@ -22,7 +22,7 @@ trait PayFinishTrait
$this->payInfo->wx_transaction_id = $this->callbackData['transaction_id'];
$this->payInfo->notify_json = json_encode($this->callbackData);
if (!$this->orderInfo->save()) {
if (!$this->payInfo->save()) {
$this->log->debug(__CLASS__.':Function:manageWxOrder:更新充值订单的状态失败:'.$this->payInfo->id);
throw new ErrException('更新充值订单的状态失败');
}

View File

@@ -21,7 +21,7 @@ trait RefundOrderTrait
{
$this->refundInfo = $this->refundOrderModel->getInfoByOrderSnoAndType($this->orderNo,self::OrderType);
$this->orderInfo = $this->orderModel->getInfoById($this->refundInfo->order_id);
$this->payInfo = $this->payOrderModel->getInfoByOrderIdAndType($this->orderInfo->id,self::OrderType);
$this->payInfo = $this->payOrderModel->getInfoByOrderIdAndTypeAndRType($this->orderInfo->id,self::OrderType,self::PayType);
if (empty($this->orderInfo) || empty($this->payInfo) || empty($this->refundInfo)) {
$this->log->debug(__CLASS__.':订单不存在,订单号:'.$this->orderNo);