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) {
|
|
|
|
//计算商品重量
|
|
|
|
$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'];
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 选择物流公司
|
|
|
|
* @param string $province
|
|
|
|
* @param string $weight
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function chooseLogisticsCompany($province, $weight)
|
|
|
|
{
|
|
|
|
$expressChooseConf = require(dirname(dirname(__FILE__)) . '/config/express_choose.php');
|
2020-08-27 06:43:39 +00:00
|
|
|
$type = self::getOrderType($province, $weight, $expressChooseConf);
|
|
|
|
return [
|
|
|
|
'type' => $type,
|
|
|
|
'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)
|
|
|
|
{
|
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-03-19 09:05:29 +00:00
|
|
|
}
|