From ce1efee9b1e16230208417f1ccfc6d7d68e78723 Mon Sep 17 00:00:00 2001 From: ZweiCD <416931358@qq.com> Date: Thu, 27 Aug 2020 17:34:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=80=E5=94=AE=E5=8D=95?= =?UTF-8?q?=E5=8F=91=E8=B4=A7=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/WmsStrategy.php | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/WmsStrategy.php b/src/WmsStrategy.php index dfe21a8..994efe1 100644 --- a/src/WmsStrategy.php +++ b/src/WmsStrategy.php @@ -20,13 +20,25 @@ class WmsStrategy } public function saleOrderCreate($params) { - //计算商品重量 - $skuTotalWeight = $this->getSkuTotalWeight($params['order_goods']); - $logistics = $this->chooseLogisticsCompany($params['order_address']['receive_province'], $skuTotalWeight); - $params['order_sender_info']['logistics_code'] = $logistics['code']; - $params['order_sender_info']['logistics_name'] = $logistics['name']; + $orderLogisticsType = ''; + if ($params['delivery_type'] == 1) { + $orderLogisticsType = 'toC'; + } else if ($params['delivery_type'] == 2) { + $orderLogisticsType = 'toB'; + } - if ($logistics['type'] == 'toC') { + if (!$orderLogisticsType || !$params['express_code']) { + //计算商品重量 + $skuTotalWeight = $this->getSkuTotalWeight($params['order_goods']); + $logistics = $this->chooseLogisticsCompany($params['order_address']['receive_province'], $skuTotalWeight); + $params['order_sender_info']['logistics_code'] = $logistics['code']; + $params['order_sender_info']['logistics_name'] = $logistics['name']; + } else { + $params['order_sender_info']['logistics_code'] = $params['express_code']; + $params['order_sender_info']['logistics_name'] = self::getExpressNameByExpressCode($params['express_code']); + } + + if ($orderLogisticsType == 'toC') { // 2C订单发货 $res = $this->deliveryOrderCreate($params); $type = 1; @@ -175,4 +187,18 @@ class WmsStrategy } return ''; } + + /** + * 根据物流码获取物流名称 + */ + static public function getExpressNameByExpressCode($expressCode) + { + $expressChooseConf = require(dirname(dirname(__FILE__)) . '/config/express_choose.php'); + $logistics = collect([$expressChooseConf['logistics']['toC'], $expressChooseConf['logistics']['toB']]) + ->collapse() + ->keyBy('code') + ->all(); + $expressName = $logistics[$expressCode] ? $logistics[$expressCode]['name'] : ''; + return $expressName; + } }