From 471edb975d1d60e2812ea8a8f0ca19d9922a5b5a Mon Sep 17 00:00:00 2001 From: ZweiCD <416931358@qq.com> Date: Thu, 27 Aug 2020 14:43:39 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=89=A9=E6=B5=81=E5=BF=AB=E9=80=92=E9=9D=99=E6=80=81=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/express_choose.php | 17 +++++++++++++---- src/WmsStrategy.php | 39 ++++++++++++++++++++++++--------------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/config/express_choose.php b/config/express_choose.php index 605b450..933f3e3 100644 --- a/config/express_choose.php +++ b/config/express_choose.php @@ -6,12 +6,21 @@ return [ 'other_express_weight' => 45, 'logistics' => [ 'toB' => [ - 'code' => 'CN7000001003751', - 'name' => '跨越', + [ + 'code' => 'CN7000001003751', + 'name' => '跨越', + ], + [ + 'code' => 'CN7000001000869', + 'name' => '安能快运', + ], + ], 'toC' => [ - 'code' => 'STO', - 'name' => '申通', + [ + 'code' => 'STO', + 'name' => '申通', + ], ] ], ]; \ No newline at end of file diff --git a/src/WmsStrategy.php b/src/WmsStrategy.php index bcb2811..a770890 100644 --- a/src/WmsStrategy.php +++ b/src/WmsStrategy.php @@ -115,23 +115,32 @@ class WmsStrategy public function chooseLogisticsCompany($province, $weight) { $expressChooseConf = require(dirname(dirname(__FILE__)) . '/config/express_choose.php'); - if (in_array($province, $expressChooseConf['address_list'])) { - if ($weight >= $expressChooseConf['jzh_express_weight']) { - $type = 'toB'; - } else { - $type = 'toC'; - } - } else { - if ($weight >= $expressChooseConf['other_express_weight']) { - $type = 'toB'; - } else { - $type = 'toC'; - } - } + $type = self::getOrderType($province, $weight, $expressChooseConf); return [ 'type' => $type, - 'code' => $expressChooseConf['logistics'][$type]['code'], - 'name' => $expressChooseConf['logistics'][$type]['name'], + 'code' => $expressChooseConf['logistics'][$type][0]['code'], + 'name' => $expressChooseConf['logistics'][$type][0]['name'], ]; } + + /** + * 判断订单BC类型 + * @param $province + * @param $weight + * @return string + */ + static public function getOrderType($province, $weight, $expressChooseConf) + { + if (in_array($province, $expressChooseConf['address_list'])) { + if ($weight >= $expressChooseConf['jzh_express_weight']) { + return 'toB'; + } + return 'toC'; + } else { + if ($weight >= $expressChooseConf['other_express_weight']) { + return 'toB'; + } + return 'toC'; + } + } } From 466442976106121ce1133c73091631ad42731dc7 Mon Sep 17 00:00:00 2001 From: ZweiCD <416931358@qq.com> Date: Thu, 27 Aug 2020 14:48:15 +0800 Subject: [PATCH 2/6] update --- src/WmsStrategy.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/WmsStrategy.php b/src/WmsStrategy.php index a770890..76e6208 100644 --- a/src/WmsStrategy.php +++ b/src/WmsStrategy.php @@ -106,6 +106,19 @@ class WmsStrategy return $skuTotalWeight; } + /** + * 根据商品重量区分bc单,返回可选择的物流快递 + * @param string $province + * @param string $weight + * @return array + */ + public function getLogistics($province, $weight) + { + $expressChooseConf = require(dirname(dirname(__FILE__)) . '/config/express_choose.php'); + $type = self::getOrderType($province, $weight, $expressChooseConf); + return $expressChooseConf['logistics'][$type]; + } + /** * 选择物流公司 * @param string $province From ee866468de1b0cfa800dad12ed971d64b5c5e5dd Mon Sep 17 00:00:00 2001 From: ZweiCD <416931358@qq.com> Date: Thu, 27 Aug 2020 14:50:03 +0800 Subject: [PATCH 3/6] update --- src/WmsStrategy.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/WmsStrategy.php b/src/WmsStrategy.php index 76e6208..184f60d 100644 --- a/src/WmsStrategy.php +++ b/src/WmsStrategy.php @@ -106,19 +106,6 @@ class WmsStrategy return $skuTotalWeight; } - /** - * 根据商品重量区分bc单,返回可选择的物流快递 - * @param string $province - * @param string $weight - * @return array - */ - public function getLogistics($province, $weight) - { - $expressChooseConf = require(dirname(dirname(__FILE__)) . '/config/express_choose.php'); - $type = self::getOrderType($province, $weight, $expressChooseConf); - return $expressChooseConf['logistics'][$type]; - } - /** * 选择物流公司 * @param string $province @@ -136,6 +123,19 @@ class WmsStrategy ]; } + /** + * 根据商品重量区分bc单,返回可选择的物流快递 + * @param string $province + * @param string $weight + * @return array + */ + static public function getLogistics($province, $weight) + { + $expressChooseConf = require(dirname(dirname(__FILE__)) . '/config/express_choose.php'); + $type = self::getOrderType($province, $weight, $expressChooseConf); + return $expressChooseConf['logistics'][$type]; + } + /** * 判断订单BC类型 * @param $province From 5ec16680577188b4fc93d68a47cc93988e2f4cd4 Mon Sep 17 00:00:00 2001 From: ZweiCD <416931358@qq.com> Date: Thu, 27 Aug 2020 16:32:35 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=BF=AB=E9=80=92code?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E8=AE=A2=E5=8D=95bc=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/WmsStrategy.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/WmsStrategy.php b/src/WmsStrategy.php index 184f60d..dfe21a8 100644 --- a/src/WmsStrategy.php +++ b/src/WmsStrategy.php @@ -156,4 +156,23 @@ class WmsStrategy return 'toC'; } } + + /** + * 根据物流快递判断订单bc类型 + * @param $expressCode + * @return string + */ + static public function getOrderTypeByExpressCode($expressCode) + { + $expressChooseConf = require(dirname(dirname(__FILE__)) . '/config/express_choose.php'); + $logisticsToC = collect($expressChooseConf['logistics']['toC'])->pluck('code')->toArray(); + if (in_array($expressCode, $logisticsToC)) { + return 'toC'; + } + $logisticsToB = collect($expressChooseConf['logistics']['toB'])->pluck('code')->toArray(); + if (in_array($expressCode, $logisticsToB)) { + return 'toB'; + } + return ''; + } } 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 5/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=80=E5=94=AE?= =?UTF-8?q?=E5=8D=95=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; + } } From 4503cca8bd53f6c4a6cef928c343509c737f3702 Mon Sep 17 00:00:00 2001 From: ZweiCD <416931358@qq.com> Date: Thu, 27 Aug 2020 17:44:21 +0800 Subject: [PATCH 6/6] update --- src/WmsStrategy.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/WmsStrategy.php b/src/WmsStrategy.php index 994efe1..591a4d1 100644 --- a/src/WmsStrategy.php +++ b/src/WmsStrategy.php @@ -33,6 +33,7 @@ class WmsStrategy $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 = $logistics['type']; } else { $params['order_sender_info']['logistics_code'] = $params['express_code']; $params['order_sender_info']['logistics_name'] = self::getExpressNameByExpressCode($params['express_code']);