2020-03-19 09:05:29 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace PdWms;
|
|
|
|
|
|
|
|
|
|
class WmsStrategy
|
|
|
|
|
{
|
|
|
|
|
public $wmsClient;
|
|
|
|
|
|
|
|
|
|
public function __construct($warehouseId)
|
|
|
|
|
{
|
2020-03-25 06:16:20 +00:00
|
|
|
|
$config = require(dirname(dirname(__FILE__)) . '/config/wms.php');
|
2020-03-19 09:05:29 +00:00
|
|
|
|
switch ($warehouseId)
|
|
|
|
|
{
|
2020-07-13 02:44:15 +00:00
|
|
|
|
case $config['fineex']['warehouse_id']:
|
|
|
|
|
$this->wmsClient = new FineexWms($config['fineex']);
|
2020-03-19 09:05:29 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new \Exception('仓库不存在');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-13 10:57:14 +00:00
|
|
|
|
public function saleOrderCreate($params) {
|
2020-08-27 09:34:42 +00:00
|
|
|
|
$orderLogisticsType = '';
|
|
|
|
|
if ($params['delivery_type'] == 1) {
|
|
|
|
|
$orderLogisticsType = 'toC';
|
|
|
|
|
} else if ($params['delivery_type'] == 2) {
|
|
|
|
|
$orderLogisticsType = 'toB';
|
|
|
|
|
}
|
2020-07-13 10:57:14 +00:00
|
|
|
|
|
2020-08-27 09:34:42 +00:00
|
|
|
|
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'];
|
2020-08-27 09:44:21 +00:00
|
|
|
|
$orderLogisticsType = $logistics['type'];
|
2020-08-27 09:34:42 +00:00
|
|
|
|
} else {
|
|
|
|
|
$params['order_sender_info']['logistics_code'] = $params['express_code'];
|
|
|
|
|
$params['order_sender_info']['logistics_name'] = self::getExpressNameByExpressCode($params['express_code']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($orderLogisticsType == 'toC') {
|
2020-07-13 10:57:14 +00:00
|
|
|
|
// 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'];
|
2020-07-23 02:11:50 +00:00
|
|
|
|
$params['order_type'] = 'PTCK';
|
2020-07-13 10:57:14 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 02:51:11 +00:00
|
|
|
|
public function deliveryOrderCreate($params) {
|
|
|
|
|
return $this->wmsClient->deliveryOrderCreate($params);
|
2020-03-19 09:05:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 02:51:11 +00:00
|
|
|
|
public function inventoryQuerySingle($wmsCode, $inventoryType = 'ZP') {
|
|
|
|
|
return $this->wmsClient->inventoryQuerySingle($wmsCode, $inventoryType);
|
2020-03-19 09:05:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 02:51:11 +00:00
|
|
|
|
public function inventoryQuery($params, $inventoryType = 'ZP') {
|
|
|
|
|
return $this->wmsClient->inventoryQuery($params, $inventoryType);
|
2020-03-19 09:05:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 02:51:11 +00:00
|
|
|
|
public function goodsSkuSync($params) {
|
|
|
|
|
return $this->wmsClient->goodsSkuSync($params);
|
2020-03-19 09:05:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function orderCancel($params) {
|
|
|
|
|
return $this->wmsClient->orderCancel($params);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 02:51:11 +00:00
|
|
|
|
public function returnOrderCreate($params) {
|
|
|
|
|
return $this->wmsClient->returnOrderCreate($params);
|
2020-03-19 09:05:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-14 06:27:45 +00:00
|
|
|
|
public function stockInCreate($params) {
|
|
|
|
|
return $this->wmsClient->stockInCreate($params);
|
2020-03-19 09:05:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function stockOutCreate($params) {
|
|
|
|
|
return $this->wmsClient->stockOutCreate($params);
|
|
|
|
|
}
|
2020-07-13 10:57:14 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取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;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-27 06:48:15 +00:00
|
|
|
|
/**
|
2020-08-27 06:50:03 +00:00
|
|
|
|
* 选择物流公司
|
2020-08-27 06:48:15 +00:00
|
|
|
|
* @param string $province
|
|
|
|
|
* @param string $weight
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2020-08-27 06:50:03 +00:00
|
|
|
|
public function chooseLogisticsCompany($province, $weight)
|
2020-08-27 06:48:15 +00:00
|
|
|
|
{
|
|
|
|
|
$expressChooseConf = require(dirname(dirname(__FILE__)) . '/config/express_choose.php');
|
|
|
|
|
$type = self::getOrderType($province, $weight, $expressChooseConf);
|
2020-08-27 06:50:03 +00:00
|
|
|
|
return [
|
|
|
|
|
'type' => $type,
|
|
|
|
|
'code' => $expressChooseConf['logistics'][$type][0]['code'],
|
|
|
|
|
'name' => $expressChooseConf['logistics'][$type][0]['name'],
|
|
|
|
|
];
|
2020-08-27 06:48:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-13 10:57:14 +00:00
|
|
|
|
/**
|
2020-08-27 06:50:03 +00:00
|
|
|
|
* 根据商品重量区分bc单,返回可选择的物流快递
|
2020-07-13 10:57:14 +00:00
|
|
|
|
* @param string $province
|
|
|
|
|
* @param string $weight
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2020-08-27 06:50:03 +00:00
|
|
|
|
static public function getLogistics($province, $weight)
|
2020-07-13 10:57:14 +00:00
|
|
|
|
{
|
|
|
|
|
$expressChooseConf = require(dirname(dirname(__FILE__)) . '/config/express_choose.php');
|
2020-08-27 06:43:39 +00:00
|
|
|
|
$type = self::getOrderType($province, $weight, $expressChooseConf);
|
2020-09-04 03:53:17 +00:00
|
|
|
|
$expressChooseConf['logistics'][$type][0]['is_default'] = true;
|
|
|
|
|
return collect([$expressChooseConf['logistics']['toC'], $expressChooseConf['logistics']['toB']])->collapse()->all();
|
2020-08-27 06:43:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断订单BC类型
|
|
|
|
|
* @param $province
|
|
|
|
|
* @param $weight
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
static public function getOrderType($province, $weight, $expressChooseConf)
|
|
|
|
|
{
|
2020-07-13 10:57:14 +00:00
|
|
|
|
if (in_array($province, $expressChooseConf['address_list'])) {
|
|
|
|
|
if ($weight >= $expressChooseConf['jzh_express_weight']) {
|
2020-08-27 06:43:39 +00:00
|
|
|
|
return 'toB';
|
2020-07-13 10:57:14 +00:00
|
|
|
|
}
|
2020-08-27 06:43:39 +00:00
|
|
|
|
return 'toC';
|
2020-07-13 10:57:14 +00:00
|
|
|
|
} else {
|
|
|
|
|
if ($weight >= $expressChooseConf['other_express_weight']) {
|
2020-08-27 06:43:39 +00:00
|
|
|
|
return 'toB';
|
2020-07-13 10:57:14 +00:00
|
|
|
|
}
|
2020-08-27 06:43:39 +00:00
|
|
|
|
return 'toC';
|
2020-07-13 10:57:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-27 08:32:35 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据物流快递判断订单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 '';
|
|
|
|
|
}
|
2020-08-27 09:34:42 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据物流码获取物流名称
|
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
}
|
2020-03-19 09:05:29 +00:00
|
|
|
|
}
|