wmsClient = new FineexWms($config['fineex']); break; default: throw new \Exception('仓库不存在'); } } 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']; if ($logistics['type'] == 'toC') { // 2C订单发货 $res = $this->deliveryOrderCreate($params); $type = 1; } else { // 2B订单发货 $params['out_warehouse_number'] = $params['order_no']; $params['address_name'] = $params['order_address']['receive_name']; $params['address_telephone'] = $params['order_address']['receive_mobile']; $params['address_province'] = $params['order_address']['receive_province']; $params['address_city'] = $params['order_address']['receive_city']; $params['address_area'] = $params['order_address']['receive_district']; $params['address_detail'] = $params['order_address']['receive_address']; $params['order_type'] = 'PTCK'; foreach ($params['order_goods'] as &$item) { $item['product_name'] = $item['goods_name']; $item['number'] = $item['sku_quantity']; } $res = $this->stockOutCreate($params); $type = 0; } $res['response']['type'] = $type; return $res; } public function deliveryOrderCreate($params) { return $this->wmsClient->deliveryOrderCreate($params); } public function inventoryQuerySingle($wmsCode, $inventoryType = 'ZP') { return $this->wmsClient->inventoryQuerySingle($wmsCode, $inventoryType); } public function inventoryQuery($params, $inventoryType = 'ZP') { return $this->wmsClient->inventoryQuery($params, $inventoryType); } public function goodsSkuSync($params) { return $this->wmsClient->goodsSkuSync($params); } public function orderCancel($params) { return $this->wmsClient->orderCancel($params); } public function returnOrderCreate($params) { return $this->wmsClient->returnOrderCreate($params); } public function stockInCreate($params) { return $this->wmsClient->stockInCreate($params); } public function stockOutCreate($params) { return $this->wmsClient->stockOutCreate($params); } /** * 获取sku总重量 * @param $orderGoods * @return float|int */ public function getSkuTotalWeight($orderGoods) { $skuTotalWeight = 0; foreach ($orderGoods as $item) { $item['product_name'] = $item['goods_name']; $item['number'] = $item['sku_quantity']; if ($item['sku_type'] == 0) { $skuTotalWeight += ($item['weight'] * $item['sku_quantity']) / 1000; } elseif ($item['sku_type'] == 1) { foreach ($item['sku_nexus_snapshot'] as $gv) { $skuTotalWeight += ($gv['weight'] * $gv['sku_quantity'] * $item['sku_quantity']) / 1000; } } } return $skuTotalWeight; } /** * 选择物流公司 * @param string $province * @param string $weight * @return array */ 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'; } } return [ 'type' => $type, 'code' => $expressChooseConf['logistics'][$type]['code'], 'name' => $expressChooseConf['logistics'][$type]['name'], ]; } }