文件位置:app/services/erp/OrderServices.php
需要调整的方法:upload、getItems
替换下面对应方法:
/**
* 订单上传
* @param int $oid
* @return bool
* @throws \Exception
*/
public function upload(int $oid): bool
{
/** @var StoreOrderServices $orderServices */
$orderServices = app()->make(StoreOrderServices::class);
$order = $orderServices->get($oid, ['*'], ['store']);
if ($order['id'] < 1) {
throw new AdminException('订单信息不能为空!');
}
// 过滤已退款订单和虚拟商品
if ($order['refund_status'] == 2 || $order['product_type'] > 0) {
return true;
}
$biz = [
'shop_id' => $this->getShopId($order->store->erp_shop_id ?? 0), // 店铺编号
'so_id' => $this->getErpOrderId($order['order_id'], $order['erp_order_id']), // 线上订单号, 长度 <= 50
'shop_status' => 'WAIT_SELLER_SEND_GOODS', // 订单状态 待发货
'buyer_message' => $order['mark'], // 买家留言
'shop_buyer_id' => (string)$order['uid'], // 买家帐号
'receiver_name' => $order['real_name'], // 收件人
'receiver_mobile' => $order['user_phone'], // 联系手机
'pay_amount' => (float)$order['pay_price'], // 应付金额,保留两位小数,单位元)
'freight' => (float)$order['freight_price'], // 运费
'order_date' => date('Y-m-d H:i:s', $order['add_time']), // 订单日期
'shop_modified' => date('Y-m-d H:i:s', $order['add_time']), // 订单修改日期
'items' => $this->getItems($oid, (int)$order['uid'], $order['unique']),
'pay' => [
'outer_pay_id' => 'xxx', // 外部支付单号,最大50
'pay_date' => date('Y-m-d H:i:s', $order['pay_time']), // 支付日期
'payment' => $order['pay_type'], // 支付方式,最大20
'seller_account' => 'seller', // 卖家支付账号,最大 50
'buyer_account' => 'buyer', // 买家支付账号,最大 200
'amount' => (float)$order['pay_price'] // 支付总额
]
];
$biz = array_merge($biz, $this->getAddress($order['user_address']));
$num = 3;
for ($i = $num; $i >= 0; $i--) {
if ($i <= 0) {
Log::error(['msg' => 'ERP订单上传失败,调用均为异常', 'oid' => $oid]);
return false;
}
try {
$result = $this->services->serviceDriver('order')->ordersUpload([$biz]);
if ($result['datas'][0]['issuccess'] && $order['erp_order_id'] != $biz['so_id']) {
$order->save(['erp_id' => $result['datas'][0]['o_id'], 'erp_order_id' => $biz['so_id']]);
}
break;
} catch (\Exception $e) {
usleep(1000 * 50);
Log::error('ERP订单上传失败,原因:' . $e->getMessage());
}
}
return true;
}
/**
* 获取erp指定订单商品详情
* @param int $oid
* @param int $uid
* @param string $unique
* @return array
*/
public function getItems(int $oid, int $uid, string $unique): array
{
/** @var StoreOrderCartInfoServices $storeOrderCartInfoServices */
$storeOrderCartInfoServices = app()->make(StoreOrderCartInfoServices::class);
$cartInfo = $storeOrderCartInfoServices->getOrderCartInfo($oid);
if (empty($cartInfo)) {
/** @var StoreOrderServices $orderServices */
$orderServices = app()->make(StoreOrderServices::class);
//同步查询订单商品为查询到 查询缓存信息
$orderInfo = $orderServices->getCacheOrderInfo($uid, $unique);
$cartInfo = $orderInfo['cartInfo'] ?? [];
}
$items = [];
foreach ($cartInfo as $cart) {
$cart = $cart['cart_info'] ?? $cart;
$attrInfo = $cart['productInfo']['attrInfo'];
$items[] = [
'sku_id' => $attrInfo['code'],
'shop_sku_id' => $attrInfo['code'],
'base_price' => (float)bcdiv((string)$cart['truePrice'], (string)$cart['cart_num'], 2),
'amount' => (float)$cart['truePrice'],
'qty' => $cart['cart_num'],
'pic' => $cart['productInfo']['image'],
'name' => $cart['productInfo']['store_name'],
'properties_value' => $attrInfo['suk'],
'outer_oi_id' => $cart['product_attr_unique'],
];
}
return $items;
}
然后重启Swoole!!!
{{item.user_info.nickname ? item.user_info.nickname : item.user_name}}
作者 管理员 企业
{{itemf.name}}
{{itemc.user_info.nickname}}
{{itemc.user_name}}
回复 {{itemc.comment_user_info.nickname}}
{{itemf.name}}