WMS_MAIN/app/service/systems/polo_api.js

193 lines
5.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
const Service = require('egg').Service;
const PoloApiClient = require('../../lib/polo_api_client');
class PoloApiService extends Service {
/**
* @param {object} ctx - Egg 上下文对象。
*/
constructor(ctx) {
super(ctx);
this.client = new PoloApiClient(ctx);
}
/**
* 发起 Polo API POST 请求。
*
* @param {string} method 接口方法名。
* @param {object|string} [bizcontent={}] 业务参数。
* @param {object} [config={}] 平台配置。
* @param {string} [token] 可选 token。
* @return {Promise<any>} 接口响应数据。
*/
async request(method, bizcontent = {}, config = {}, token) {
console.log('查询菠萝派平台数据,入参bizcontent:', JSON.stringify(bizcontent));
return this.client.request({
method,
bizcontent,
config,
token,
});
}
/**
* 发起 Polo API GET 请求。
*
* @param {string} method 接口方法名。
* @param {object|string} [bizcontent={}] 业务参数。
* @param {object} [config={}] 平台配置。
* @param {string} [token] 可选 token。
* @return {Promise<any>} 接口响应数据。
*/
async get(method, bizcontent = {}, config = {}, token) {
console.log('查询菠萝派平台数据,入参bizcontent:', JSON.stringify(bizcontent));
return this.client.get({
method,
bizcontent,
config,
token,
});
}
/**
* 快手取号。
*
* @param {object} [options={}] - 快手取号入参。
* @param {string} [options.express_id=''] - 快手平台对应的承运商编码。
* @param {object} [options.wmsOrder={}] - WMS 订单信息。
* @param {object} [options.expressConfig={}] - 发件方与店铺配置。
* @return {Promise<any>} 接口响应 data。
*/
async kuaishou(options = {}) {
const {
express_id = '',
wmsOrder = {},
expressConfig = {},
} = options;
const {
sourceId = '',
sourceOrderCode = '',
postcode = '',
wareHouseId = 0,
storeId = 0,
items = '',
goodsCount = 0,
orderWeight = 0,
address = '',
name = '',
expAreaName = '',
cityName = '',
province = '',
tempMobile = '',
tel = '',
} = wmsOrder;
const {
storeName = '',
address: senderAddress = '',
senderName = '',
districtName = '',
cityName: senderCityName = '',
senderTel = '',
provinceName = '',
siteCode = '',
clientId = '',
} = expressConfig;
const platid = 556;
const method = 'Differ.JH.Logistics.PostOrder';
const shoptype = 'JH_001';
const sourceIdText = String(sourceId || '');
const sourceOrderCodeText = String(sourceOrderCode || '');
const [ senderArea = '', senderTown = '' ] = String(districtName || '').split(';');
const mobile = tempMobile || tel || '';
const cpcode = express_id || '';
const txLogisticID = sourceIdText.replace(/_/g, '');
let cnname = '';
if (!(wareHouseId === 5400 || storeId === 58303)) {
const firstItem = String(items || '').split('|')[0] || '';
const itemFields = firstItem.split(',');
if (itemFields.length > 2) {
cnname = itemFields[2];
}
} else {
cnname = 'sp';
}
const order = {
businessplat: 'OTHERS',
ismultiplepieces: '0',
businesstype: 'JH_Normal',
cpcode,
customercode: '',
customername: storeName || '测试',
goods: [{
cnname,
count: String(goodsCount),
unit: '属性',
currencytype: 'CNY',
Unit: '',
weight: String(orderWeight),
price: '0.0',
}],
logisticsproductname: 'JH_02',
logistictype: cpcode,
mainsubpaymode: '1',
needencrypt: '1',
numpackage: '1',
orderno: sourceOrderCodeText || (sourceIdText.length > 13 ? sourceIdText.substring(0, 14) : sourceIdText),
ordersource: 'KUAI_SHOU',
ordertype: 'JH_Normal',
plattradeno: sourceOrderCodeText || txLogisticID,
ProviderID: postcode === 'p03' ? 1327 : (postcode === 'p04' ? 1499 : ''),
providercode: cpcode,
receiver: {
address,
name,
area: expAreaName,
city: cityName,
mobile,
province,
},
sender: {
country: 'CN',
Company: storeName,
address: senderAddress,
name: senderName,
area: senderArea,
town: senderTown,
city: senderCityName,
phone: senderTel,
mobile: senderTel,
tel: senderTel,
province: provinceName,
},
shipperno: [ 'p22', 'p35', 'p10' ].includes(postcode) ? siteCode : clientId,
sitecode: siteCode || '',
Inputsite: siteCode || '',
transtype: '0',
};
if (postcode === 'p10') {
const pickupDate = new Date();
pickupDate.setDate(pickupDate.getDate() + 3);
const pickupEndDate = new Date();
pickupEndDate.setDate(pickupEndDate.getDate() + 4);
const pad = value => (value < 10 ? `0${value}` : String(value));
order.pickUpDate = `${pickupDate.getFullYear()}-${pad(pickupDate.getMonth() + 1)}-${pad(pickupDate.getDate())} 18:00:00`;
order.pickUpEndDate = `${pickupEndDate.getFullYear()}-${pad(pickupEndDate.getMonth() + 1)}-${pad(pickupEndDate.getDate())} 18:00:00`;
}
return this.client.request({
method,
platid,
bizcontent: {
orders: [ order ],
shoptype,
},
});
}
}
module.exports = PoloApiService;