fengketrade/addons/shopro/library/ccblife/CcbOrderService.php

611 lines
22 KiB
PHP
Raw Normal View History

2025-10-17 16:32:16 +08:00
<?php
namespace addons\shopro\library\ccblife;
2025-10-17 17:18:15 +08:00
use think\Db;
use think\Log;
2025-10-17 16:32:16 +08:00
/**
2025-10-17 17:18:15 +08:00
* 建行生活订单服务类
* 处理订单同步、状态更新、查询等业务逻辑
2025-10-17 16:32:16 +08:00
*/
class CcbOrderService
{
/**
2025-10-17 17:18:15 +08:00
* HTTP客户端实例
2025-10-17 16:32:16 +08:00
*/
private $httpClient;
/**
* 配置信息
*/
private $config;
/**
* 构造函数
*/
2025-10-17 17:18:15 +08:00
public function __construct()
2025-10-17 16:32:16 +08:00
{
2025-10-18 15:47:25 +08:00
// 加载插件配置文件
$configFile = __DIR__ . '/../../config/ccblife.php';
if (file_exists($configFile)) {
$this->config = include $configFile;
} else {
throw new \Exception('建行生活配置文件不存在');
}
2025-10-21 10:17:40 +08:00
// ✅ 修复: 删除processPemKeys()调用
// 密钥格式化统一由CcbRSA类处理避免重复格式化导致OpenSSL ASN1解析错误
// CcbRSA::formatPublicKey/formatPrivateKey 会在加密/解密时自动处理密钥格式
2025-10-18 15:47:25 +08:00
2025-10-17 17:18:15 +08:00
$this->httpClient = new CcbHttpClient($this->config);
2025-10-17 16:32:16 +08:00
}
/**
2025-10-17 17:18:15 +08:00
* 推送订单到建行生活平台
* 当用户下单后调用此方法同步订单信息
2025-10-17 16:32:16 +08:00
*
2025-10-17 17:18:15 +08:00
* @param int $orderId Shopro订单ID
2025-10-21 14:33:20 +08:00
* @param string $payFlowId 支付流水号(由控制器统一生成)
2025-10-17 17:18:15 +08:00
* @return array ['status' => bool, 'message' => string, 'data' => array]
* @throws \Exception
2025-10-17 16:32:16 +08:00
*/
2025-10-21 14:33:20 +08:00
public function pushOrder($orderId, $payFlowId)
2025-10-17 16:32:16 +08:00
{
2025-10-17 17:18:15 +08:00
$startTime = microtime(true);
2025-10-17 16:32:16 +08:00
try {
2025-10-21 14:33:20 +08:00
// ✅ 验证支付流水号
if (empty($payFlowId)) {
throw new \Exception('支付流水号不能为空');
}
2025-10-17 17:18:15 +08:00
// 获取订单信息
$order = Db::name('shopro_order')
->alias('o')
->join('user u', 'o.user_id = u.id', 'LEFT')
->where('o.id', $orderId)
->field('o.*, u.ccb_user_id')
->find();
if (!$order) {
throw new \Exception('订单不存在');
}
// 获取建行用户ID
$ccbUserId = $order['ccb_user_id'];
if (!$ccbUserId) {
throw new \Exception('用户未绑定建行生活账号');
}
// 获取订单商品列表
$orderItems = Db::name('shopro_order_item')
->where('order_id', $orderId)
2025-10-21 10:17:40 +08:00
->select();
2025-10-17 17:18:15 +08:00
// 构建订单数据符合A3341TP01接口规范
2025-10-21 14:33:20 +08:00
// ✅ 传入统一的支付流水号
$orderData = $this->buildOrderData($order, $orderItems, $ccbUserId, $payFlowId);
2025-10-17 17:18:15 +08:00
// 记录请求数据(同步日志)
$txSeq = CcbMD5::generateTransactionSeq();
$this->recordSyncLog($orderId, 'A3341TP01', $txSeq, $orderData, 'request');
// 调用建行API推送订单
$response = $this->httpClient->pushOrder($orderData);
// 记录响应数据和耗时
$costTime = round((microtime(true) - $startTime) * 1000, 2);
$this->recordSyncLog($orderId, 'A3341TP01', $txSeq, $response, 'response', true, $costTime);
2025-10-17 16:32:16 +08:00
2025-10-17 17:18:15 +08:00
// 更新订单同步状态
$this->updateOrderSyncStatus($orderId, 1);
2025-10-17 16:32:16 +08:00
return [
2025-10-17 17:18:15 +08:00
'status' => true,
'message' => '订单推送成功',
'data' => $response
2025-10-17 16:32:16 +08:00
];
2025-10-17 17:18:15 +08:00
} catch (\Exception $e) {
// 记录错误
$costTime = round((microtime(true) - $startTime) * 1000, 2);
$this->recordSyncLog($orderId, 'A3341TP01', '', null, 'error', false, $costTime, $e->getMessage());
// 更新同步状态为失败
$this->updateOrderSyncStatus($orderId, 2);
Log::error('建行订单推送失败: ' . $e->getMessage());
2025-10-17 16:32:16 +08:00
return [
2025-10-17 17:18:15 +08:00
'status' => false,
'message' => $e->getMessage(),
'data' => null
2025-10-17 16:32:16 +08:00
];
}
}
/**
2025-10-17 17:18:15 +08:00
* 更新订单状态到建行生活
2025-10-17 16:32:16 +08:00
*
2025-10-17 17:18:15 +08:00
* @param int $orderId 订单ID
* @param string $status 订单状态
* @param string $refundStatus 退款状态
* @return array
2025-10-17 16:32:16 +08:00
*/
2025-10-17 17:18:15 +08:00
public function updateOrderStatus($orderId, $status = null, $refundStatus = null)
2025-10-17 16:32:16 +08:00
{
2025-10-17 17:18:15 +08:00
$startTime = microtime(true);
$txSeq = CcbMD5::generateTransactionSeq();
2025-10-17 16:32:16 +08:00
try {
2025-10-17 17:18:15 +08:00
// 获取订单信息
$order = Db::name('shopro_order')
->alias('o')
->join('user u', 'o.user_id = u.id', 'LEFT')
->where('o.id', $orderId)
->field('o.*, u.ccb_user_id')
->find();
if (!$order) {
throw new \Exception('订单不存在');
}
// 获取建行用户ID
$ccbUserId = $order['ccb_user_id'];
if (!$ccbUserId) {
throw new \Exception('用户未绑定建行生活账号');
}
// 映射订单状态
$orderStatus = $status ?: $this->mapOrderStatus($order['status']);
$refundStatus = $refundStatus ?: $this->mapRefundStatus($order['refund_status'] ?? 0);
// 记录请求
$requestData = [
'ccb_user_id' => $ccbUserId,
'order_sn' => $order['order_sn'],
'order_status' => $orderStatus,
'refund_status' => $refundStatus
];
$this->recordSyncLog($orderId, 'A3341TP02', $txSeq, $requestData, 'request');
// 调用建行API更新状态
$response = $this->httpClient->updateOrderStatus(
$ccbUserId,
$order['order_sn'],
$orderStatus,
$refundStatus
);
2025-10-17 16:32:16 +08:00
2025-10-17 17:18:15 +08:00
// 记录响应
$costTime = round((microtime(true) - $startTime) * 1000, 2);
$this->recordSyncLog($orderId, 'A3341TP02', $txSeq, $response, 'response', true, $costTime);
2025-10-17 16:32:16 +08:00
return [
2025-10-17 17:18:15 +08:00
'status' => true,
'message' => '订单状态更新成功',
'data' => $response
2025-10-17 16:32:16 +08:00
];
2025-10-17 17:18:15 +08:00
} catch (\Exception $e) {
$costTime = round((microtime(true) - $startTime) * 1000, 2);
$this->recordSyncLog($orderId, 'A3341TP02', $txSeq, null, 'error', false, $costTime, $e->getMessage());
Log::error('建行订单状态更新失败: ' . $e->getMessage());
2025-10-17 16:32:16 +08:00
return [
2025-10-17 17:18:15 +08:00
'status' => false,
'message' => $e->getMessage(),
'data' => null
2025-10-17 16:32:16 +08:00
];
}
}
/**
2025-10-17 17:18:15 +08:00
* 查询建行订单信息
2025-10-17 16:32:16 +08:00
*
2025-10-17 17:18:15 +08:00
* @param string $orderSn 订单号
* @return array
2025-10-17 16:32:16 +08:00
*/
2025-10-17 17:18:15 +08:00
public function queryOrder($orderSn)
2025-10-17 16:32:16 +08:00
{
try {
2025-10-17 17:18:15 +08:00
// 调用建行API查询订单
$response = $this->httpClient->queryOrder($orderSn);
2025-10-17 16:32:16 +08:00
return [
2025-10-17 17:18:15 +08:00
'status' => true,
'message' => '订单查询成功',
'data' => $response
2025-10-17 16:32:16 +08:00
];
2025-10-17 17:18:15 +08:00
} catch (\Exception $e) {
Log::error('建行订单查询失败: ' . $e->getMessage());
2025-10-17 16:32:16 +08:00
return [
2025-10-17 17:18:15 +08:00
'status' => false,
'message' => $e->getMessage(),
'data' => null
2025-10-17 16:32:16 +08:00
];
}
}
/**
2025-10-17 17:18:15 +08:00
* 处理订单退款
2025-10-17 16:32:16 +08:00
*
2025-10-17 17:18:15 +08:00
* @param int $orderId 订单ID
2025-10-17 16:32:16 +08:00
* @param float $refundAmount 退款金额
* @param string $refundReason 退款原因
2025-10-17 17:18:15 +08:00
* @return array
2025-10-17 16:32:16 +08:00
*/
public function refundOrder($orderId, $refundAmount, $refundReason = '')
{
try {
2025-10-17 17:18:15 +08:00
// 获取订单信息
2025-10-21 09:51:19 +08:00
$order = Db::name('shopro_order')->where('id', $orderId)->find();
2025-10-17 17:18:15 +08:00
if (!$order) {
throw new \Exception('订单不存在');
}
// 验证退款金额
2025-10-21 09:51:19 +08:00
if ($refundAmount > $order['order_amount']) {
2025-10-17 17:18:15 +08:00
throw new \Exception('退款金额不能超过订单总额');
}
// 调用建行API发起退款
$response = $this->httpClient->refund(
$order['order_sn'],
number_format($refundAmount, 2, '.', ''),
$refundReason
);
2025-10-17 16:32:16 +08:00
2025-10-17 17:18:15 +08:00
// 更新订单退款状态
$this->updateOrderStatus($orderId, null, '2');
2025-10-17 16:32:16 +08:00
return [
2025-10-17 17:18:15 +08:00
'status' => true,
'message' => '退款申请成功',
'data' => $response
2025-10-17 16:32:16 +08:00
];
2025-10-17 17:18:15 +08:00
} catch (\Exception $e) {
Log::error('建行订单退款失败: ' . $e->getMessage());
2025-10-17 16:32:16 +08:00
return [
2025-10-17 17:18:15 +08:00
'status' => false,
'message' => $e->getMessage(),
'data' => null
2025-10-17 16:32:16 +08:00
];
}
}
/**
2025-10-21 09:51:19 +08:00
* 构建符合建行 A3341TP01 接口规范的订单数据
*
2025-10-21 11:11:59 +08:00
* 📋 建行生活订单推送接口规范说明v1.1.6
2025-10-17 16:32:16 +08:00
*
2025-10-21 09:51:19 +08:00
* 必填字段11个
* - USER_ID: 客户编号建行用户ID
* - ORDER_ID: 订单号
* - ORDER_DT: 订单日期yyyyMMddHHmmss格式
* - TOTAL_AMT: 订单原金额
* - ORDER_STATUS: 订单状态
2025-10-21 11:11:59 +08:00
* - REFUND_STATUS: 退款状态
2025-10-21 09:51:19 +08:00
* - MCT_NM: 商户名称
* - CUS_ORDER_URL: 订单详情链接
2025-10-21 11:11:59 +08:00
* - PAY_FLOW_ID: 支付流水号
* - PAY_MRCH_ID: 支付商户号
2025-10-21 09:51:19 +08:00
* - SKU_LIST: 商品信息JSON字符串
*
2025-10-21 11:11:59 +08:00
* 重要可选字段(建议必填):
* - PAY_AMT: 订单实际支付金额(文档要求:如为空必须在状态变更时推送)
* - DISCOUNT_AMT: 第三方平台优惠金额(文档要求:如为空必须在状态变更时推送)
2025-10-21 09:51:19 +08:00
* - DISCOUNT_AMT_DESC: 第三方平台优惠说明
2025-10-21 11:11:59 +08:00
* - INV_DT: 订单过期日期
* - GOODS_NM: 商品名称
* - PREFTL_MRCH_ID: 门店商户号
* - PLAT_MCT_ID: 服务商门店编号
2025-10-21 09:51:19 +08:00
* - PLAT_ORDER_TYPE: 服务方订单类型
2025-10-21 11:11:59 +08:00
* - PLATFORM: 下单场景
2025-10-21 09:51:19 +08:00
*
* ⚠️ 注意Shopro字段映射
* - pay_fee PAY_AMT实际支付金额
* - order_amount TOTAL_AMT订单总金额
* - total_discount_fee DISCOUNT_AMT优惠总金额
* - createtime ORDER_DT毫秒时间戳需除以1000
2025-10-21 11:11:59 +08:00
* - expiry_time INV_DT过期时间
2025-10-18 01:16:25 +08:00
*
2025-10-17 17:18:15 +08:00
* @param array $order 订单数组
* @param array $orderItems 订单商品列表
* @param string $ccbUserId 建行用户ID
* @return array
2025-10-17 16:32:16 +08:00
*/
2025-10-21 14:33:20 +08:00
private function buildOrderData($order, $orderItems, $ccbUserId, $payFlowId)
2025-10-17 16:32:16 +08:00
{
2025-10-21 14:33:20 +08:00
// ✅ 使用控制器传入的统一支付流水号(确保与支付串生成使用同一流水号)
if (empty($payFlowId)) {
throw new \Exception('支付流水号不能为空');
2025-10-21 11:11:59 +08:00
}
2025-10-21 09:51:19 +08:00
// 构建SKU商品列表JSON字符串格式
$skuList = $this->buildSkuList($orderItems);
2025-10-21 11:11:59 +08:00
2025-10-21 09:51:19 +08:00
// 计算各项金额保留2位小数
2025-10-18 15:47:25 +08:00
$totalAmount = number_format($order['order_amount'] ?? 0, 2, '.', '');
2025-10-21 11:11:59 +08:00
$payAmount = number_format($order['pay_fee'] ?? $order['order_amount'] ?? 0, 2, '.', '');
$discountAmount = number_format($order['total_discount_fee'] ?? 0, 2, '.', '');
$totalRefundAmount = number_format($order['refund_fee'] ?? 0, 2, '.', '');
2025-10-21 09:51:19 +08:00
// 处理订单时间Shopro的createtime是毫秒时间戳需要除以1000
2025-10-18 15:47:25 +08:00
$createTimeValue = $order['createtime'] ?? null;
if (empty($createTimeValue) || !is_numeric($createTimeValue)) {
2025-10-21 09:51:19 +08:00
$createTimeValue = time() * 1000;
2025-10-18 15:47:25 +08:00
}
2025-10-21 09:51:19 +08:00
$orderDt = date('YmdHis', intval($createTimeValue / 1000));
2025-10-18 15:47:25 +08:00
2025-10-21 11:11:59 +08:00
// 处理订单过期时间
$invDt = '';
if (!empty($order['expiry_time'])) {
// Shopro 的 expiry_time 可能是时间戳或日期字符串
if (is_numeric($order['expiry_time'])) {
// 如果是毫秒时间戳需要除以1000
$timestamp = intval($order['expiry_time']);
if ($timestamp > 9999999999) {
$timestamp = intval($timestamp / 1000);
}
$invDt = date('YmdHis', $timestamp);
} else {
$invDt = date('YmdHis', strtotime($order['expiry_time']));
}
}
// 获取商品名称(取第一个商品)
$goodsName = '';
if (!empty($orderItems)) {
$goodsName = $orderItems[0]['goods_title'] ?? '';
// 如果有多个商品,可以拼接
if (count($orderItems) > 1) {
$goodsName .= ' 等' . count($orderItems) . '件商品';
}
}
// 构建优惠说明(如果有优惠金额)
$discountAmtDesc = '';
if ($discountAmount > 0) {
// 格式:名称=金额|@|名称=金额
// 这里简化处理,实际应该根据具体优惠券信息构建
$discountAmtDesc = '平台优惠=' . $discountAmount;
}
2025-10-21 09:51:19 +08:00
// 构建符合A3341TP01接口规范的订单数据
2025-10-21 11:11:59 +08:00
$orderData = [
2025-10-21 09:51:19 +08:00
// ========== 必填字段 ==========
'USER_ID' => $ccbUserId, // 客户编号
2025-10-17 17:18:15 +08:00
'ORDER_ID' => $order['order_sn'], // 订单号
2025-10-21 09:51:19 +08:00
'ORDER_DT' => $orderDt, // 订单日期yyyyMMddHHmmss
2025-10-18 01:16:25 +08:00
'TOTAL_AMT' => $totalAmount, // 订单原金额
2025-10-17 17:18:15 +08:00
'ORDER_STATUS' => $this->mapOrderStatus($order['status']), // 订单状态
2025-10-21 09:51:19 +08:00
'REFUND_STATUS' => $this->mapRefundStatus($order['refund_status'] ?? 0), // 退款状态
2025-10-17 17:18:15 +08:00
'MCT_NM' => $this->config['merchant']['name'] ?? '商户名称', // 商户名称
2025-10-21 14:33:20 +08:00
'PAY_FLOW_ID' => $payFlowId, // ✅ 支付流水号(使用控制器传入的统一流水号)
2025-10-21 11:11:59 +08:00
'PAY_MRCH_ID' => $this->config['merchant_id'], // 支付商户号(必填!)
2025-10-21 09:51:19 +08:00
'SKU_LIST' => $skuList, // 商品信息JSON字符串必填
2025-10-21 11:11:59 +08:00
// ========== 重要可选字段(强烈建议填写) ==========
'PAY_AMT' => $payAmount, // 订单实际支付金额
'DISCOUNT_AMT' => $discountAmount, // 第三方平台优惠金额
'PLAT_ORDER_TYPE' => 'T0000', // 服务方订单类型T0000-普通类型)
'PLATFORM' => '99', // 下单场景99-建行生活APP
2025-10-17 16:32:16 +08:00
];
2025-10-21 11:11:59 +08:00
// ========== 条件可选字段(有值才添加) ==========
// 优惠说明
if (!empty($discountAmtDesc)) {
$orderData['DISCOUNT_AMT_DESC'] = $discountAmtDesc;
}
// 订单过期时间
if (!empty($invDt)) {
$orderData['INV_DT'] = $invDt;
}
// 商品名称
if (!empty($goodsName)) {
$orderData['GOODS_NM'] = mb_substr($goodsName, 0, 200); // 限制长度200字符
}
// 累计退款金额(如果有退款)
if ($totalRefundAmount > 0) {
$orderData['TOTAL_REFUND_AMT'] = $totalRefundAmount;
}
return $orderData;
2025-10-17 16:32:16 +08:00
}
/**
2025-10-21 09:51:19 +08:00
* 构建符合建行规范的SKU商品列表JSON字符串格式
2025-10-17 17:18:15 +08:00
*
2025-10-21 09:51:19 +08:00
* 📋 建行 SKU_LIST 字段规范:
2025-10-17 17:18:15 +08:00
*
2025-10-21 09:51:19 +08:00
* 必填字段4个
* - SKU_NAME: 商品名称(必填)
* - SKU_REF_PRICE: 商品参考价必填支持小数最多2位
* - SKU_NUM: 商品数量必填支持小数最多1位
* - SKU_SELL_PRICE: 商品售价必填支持小数最多2位
2025-10-18 15:47:25 +08:00
*
2025-10-21 09:51:19 +08:00
* ⚠️ 注意Shopro字段映射
* - goods_title SKU_NAME商品名称
* - goods_original_price SKU_REF_PRICE商品原价作为参考价
* - goods_num SKU_NUM购买数量
* - goods_price SKU_SELL_PRICE商品实际售价
*
* @param array $items 订单商品项数组
* @return string JSON字符串格式的SKU列表
2025-10-17 17:18:15 +08:00
*/
2025-10-21 09:51:19 +08:00
private function buildSkuList($items)
2025-10-17 17:18:15 +08:00
{
2025-10-21 09:51:19 +08:00
$skuList = [];
foreach ($items as $item) {
$skuList[] = [
'SKU_NAME' => $item['goods_title'], // 商品名称(必填)
'SKU_REF_PRICE' => number_format($item['goods_original_price'] ?? $item['goods_price'], 2, '.', ''), // 商品参考价(必填)
'SKU_NUM' => $item['goods_num'], // 商品数量(必填)
'SKU_SELL_PRICE' => number_format($item['goods_price'], 2, '.', ''), // 商品售价(必填)
];
2025-10-18 15:47:25 +08:00
}
2025-10-21 09:51:19 +08:00
// 返回JSON字符串不转义Unicode保持中文可读
return json_encode($skuList, JSON_UNESCAPED_UNICODE);
2025-10-17 17:18:15 +08:00
}
2025-10-21 10:17:40 +08:00
2025-10-17 17:18:15 +08:00
/**
* 记录同步日志
*
* @param int $orderId 订单ID
* @param string $txCode 交易代码
* @param string $txSeq 交易流水号
* @param mixed $data 数据
* @param string $type 类型request/response/error
* @param bool $success 是否成功
* @param float $costTime 耗时(毫秒)
* @param string $errorMsg 错误信息
*/
private function recordSyncLog($orderId, $txCode, $txSeq, $data, $type = 'request', $success = true, $costTime = 0, $errorMsg = '')
{
try {
// 获取订单号
$orderSn = Db::name('shopro_order')->where('id', $orderId)->value('order_sn');
$logData = [
'order_id' => $orderId,
'order_sn' => $orderSn ?: '',
'tx_code' => $txCode,
'tx_seq' => $txSeq,
'sync_status' => $success ? 1 : 0,
'sync_time' => time(),
'cost_time' => intval($costTime),
'retry_times' => 0
];
if ($type == 'request') {
$logData['request_data'] = is_array($data) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
} elseif ($type == 'response') {
$logData['response_data'] = is_array($data) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data;
} elseif ($type == 'error') {
$logData['error_msg'] = $errorMsg;
}
Db::name('ccb_sync_log')->insert($logData);
} catch (\Exception $e) {
Log::error('记录同步日志失败: ' . $e->getMessage());
}
}
/**
* 更新订单同步状态
2025-10-17 16:32:16 +08:00
*
2025-10-17 17:18:15 +08:00
* @param int $orderId 订单ID
* @param int $status 同步状态0-未同步 1-已同步 2-同步失败
*/
private function updateOrderSyncStatus($orderId, $status)
{
Db::name('shopro_order')->where('id', $orderId)->update([
'ccb_sync_status' => $status,
'ccb_sync_time' => time(),
'updatetime' => time()
]);
}
/**
* 映射订单状态
2025-10-17 16:32:16 +08:00
*
* @param string $status Shopro订单状态
* @return string 建行订单状态
*/
private function mapOrderStatus($status)
{
2025-10-17 17:18:15 +08:00
$statusMap = [
'unpaid' => '0', // 待支付
'paid' => '1', // 已支付
'shipped' => '2', // 已发货
'received' => '3', // 已收货
'completed' => '4', // 已完成
'cancelled' => '5', // 已取消
'refunded' => '6' // 已退款
2025-10-17 16:32:16 +08:00
];
2025-10-17 17:18:15 +08:00
return $statusMap[$status] ?? '0';
2025-10-17 16:32:16 +08:00
}
/**
* 映射退款状态
*
2025-10-17 17:18:15 +08:00
* @param int $refundStatus 退款状态
* @return string
*/
private function mapRefundStatus($refundStatus)
{
if ($refundStatus == 0) return '0'; // 无退款
if ($refundStatus == 1) return '1'; // 退款中
if ($refundStatus == 2) return '2'; // 已退款
return '0';
}
/**
* 批量同步订单
* 用于初始化或定时同步
*
* @param array $conditions 查询条件
* @param int $limit 批量数量
* @return array
*/
public function batchSync($conditions = [], $limit = 100)
{
$successCount = 0;
$failCount = 0;
$errors = [];
try {
// 构建查询
$query = Db::name('shopro_order');
if (!empty($conditions)) {
$query->where($conditions);
}
// 查询需要同步的订单
$orders = $query->where('status', '<>', 'cancelled')
->where('ccb_sync_status', 'in', [0, 2]) // 未同步或同步失败的
->limit($limit)
->select();
foreach ($orders as $order) {
$result = $this->pushOrder($order['id']);
if ($result['status']) {
$successCount++;
} else {
$failCount++;
$errors[] = "订单{$order['order_sn']}: {$result['message']}";
}
}
return [
'status' => true,
'message' => "批量同步完成",
'data' => [
'total' => count($orders),
'success' => $successCount,
'fail' => $failCount,
'errors' => $errors
]
];
} catch (\Exception $e) {
return [
'status' => false,
'message' => '批量同步失败: ' . $e->getMessage(),
'data' => null
];
}
2025-10-17 16:32:16 +08:00
}
}