php-wms-client/src/WmsStrategy.php

137 lines
4.6 KiB
PHP
Raw Normal View History

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'];
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');
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'],
];
}
2020-03-19 09:05:29 +00:00
}