修复订单状态

This commit is contained in:
Billy 2025-10-27 20:28:01 +08:00
parent b23d2f171d
commit d0243bde66
2 changed files with 24 additions and 13 deletions

View File

@ -239,7 +239,8 @@ class Ccbpayment extends Common
// 7. 解析建行返回数据 // 7. 解析建行返回数据
$ccbData = $queryResult['data']['CLD_BODY'] ?? []; $ccbData = $queryResult['data']['CLD_BODY'] ?? [];
$txnList = $ccbData['TXN_LST'] ?? []; // ✅ 修复:建行实际返回字段名是 LIST不是 TXN_LST
$txnList = $ccbData['LIST'] ?? [];
// 8. 检查是否有支付成功记录 // 8. 检查是否有支付成功记录
$isPaidInCcb = false; $isPaidInCcb = false;
@ -251,8 +252,11 @@ class Ccbpayment extends Common
// TXN_STATUS=00 表示交易成功 // TXN_STATUS=00 表示交易成功
if (isset($txn['TXN_STATUS']) && $txn['TXN_STATUS'] == '00') { if (isset($txn['TXN_STATUS']) && $txn['TXN_STATUS'] == '00') {
$isPaidInCcb = true; $isPaidInCcb = true;
$ccbPayTime = $txn['TXN_TIME'] ?? null; // 交易时间 YYYYMMDDHHmmss // ✅ 修复:建行实际返回的交易时间字段是 CLRG_STM_DT_TM清算时间
$ccbTransId = $txn['TXN_SEQ'] ?? null; // 交易流水号 $ccbPayTime = $txn['CLRG_STM_DT_TM'] ?? null; // 交易时间 YYYYMMDDHHmmss
// ✅ 修复:建行实际返回的交易流水号是 EBNK_VCHR_NO电子银行凭证号
// 备选字段ATM_TXN_SNATM交易流水号
$ccbTransId = $txn['EBNK_VCHR_NO'] ?? $txn['ATM_TXN_SN'] ?? null;
break; break;
} }
} }
@ -309,9 +313,7 @@ class Ccbpayment extends Common
OrderModel::where('id', $orderId)->update([ OrderModel::where('id', $orderId)->update([
'status' => 'paid', 'status' => 'paid',
'pay_type' => 'offline', // 建行支付归类为线下银行支付
'paid_time' => $paidTime, 'paid_time' => $paidTime,
'transaction_id' => $ccbTransId ?: $order->ccb_pay_flow_id, // 建行交易流水号
'updatetime' => time() 'updatetime' => time()
]); ]);

View File

@ -151,7 +151,8 @@ class CcbOrderService
} }
// 获取支付流水号 // 获取支付流水号
$payFlowId = $order['pay_flow_id'] ?? null; // ✅ 修复:订单表字段名是 ccb_pay_flow_id不是 pay_flow_id
$payFlowId = $order['ccb_pay_flow_id'] ?? null;
if (empty($payFlowId)) { if (empty($payFlowId)) {
throw new \Exception('订单缺少支付流水号,无法更新状态到建行'); throw new \Exception('订单缺少支付流水号,无法更新状态到建行');
} }
@ -243,13 +244,10 @@ class CcbOrderService
public function queryOrder($orderSn, $startTime = null, $endTime = null, $page = 1, $txType = '0', $txnStatus = '00') public function queryOrder($orderSn, $startTime = null, $endTime = null, $page = 1, $txType = '0', $txnStatus = '00')
{ {
try { try {
// 构建商户信息参数根据建行文档A3341TP03要求
$additionalParams = [ $additionalParams = [
'MERCHANTID' => $this->config['merchant_id'], 'CUSTOMERID' => $this->config['merchant_id'], // ✅ 改为 CUSTOMERID
'POSID' => $this->config['pos_id'], 'BRANCHID' => $this->config['branch_id'] // ✅ 保持 BRANCHID
'BRANCHID' => $this->config['branch_id']
]; ];
// 调用建行API查询订单使用新接口 // 调用建行API查询订单使用新接口
$response = $this->httpClient->queryOrder( $response = $this->httpClient->queryOrder(
$orderSn, $orderSn,
@ -300,7 +298,8 @@ class CcbOrderService
} }
// 获取支付流水号(必须) // 获取支付流水号(必须)
$payFlowId = $order['pay_flow_id'] ?? null; // ✅ 修复:订单表字段名是 ccb_pay_flow_id不是 pay_flow_id
$payFlowId = $order['ccb_pay_flow_id'] ?? null;
if (empty($payFlowId)) { if (empty($payFlowId)) {
throw new \Exception('订单缺少支付流水号,无法执行退款'); throw new \Exception('订单缺少支付流水号,无法执行退款');
} }
@ -311,12 +310,22 @@ class CcbOrderService
throw new \Exception('订单缺少支付时间,无法执行退款'); throw new \Exception('订单缺少支付时间,无法执行退款');
} }
// ✅ 修复:添加商户信息参数(与查询接口保持一致)
// 根据建行文档 A3341TP04 退款接口规范:
// - CUSTOMERID: 建行商户编号(必填)
// - BRANCHID: 商户一级分行号(必填,与 CUSTOMERID 配合使用)
$additionalParams = [
'CUSTOMERID' => $this->config['merchant_id'],
'BRANCHID' => $this->config['branch_id']
];
// 调用建行API发起退款使用新接口 // 调用建行API发起退款使用新接口
$response = $this->httpClient->refund( $response = $this->httpClient->refund(
$payFlowId, // 支付流水号对应收银台ORDERID $payFlowId, // 支付流水号对应收银台ORDERID
$refundAmount, // 退款金额 $refundAmount, // 退款金额
$payTime, // 支付时间(用于计算查询时间范围) $payTime, // 支付时间(用于计算查询时间范围)
$refundCode // 退款流水号(可选) $refundCode, // 退款流水号(可选)
$additionalParams // ✅ 添加商户信息
); );
// 更新订单退款状态 // 更新订单退款状态