175 lines
4.8 KiB
JavaScript
175 lines
4.8 KiB
JavaScript
'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 请求并返回请求结果。
|
|
*
|
|
* @returns {Promise<any>} request() 的返回结果。
|
|
*/
|
|
async test() {
|
|
return this.client.request({
|
|
method: 'Differ.JH.LogisticsPlatFeatures',
|
|
platid: 556,
|
|
bizcontent: {},
|
|
});
|
|
}
|
|
async test2() {
|
|
return this.client.request({
|
|
method: 'Differ.JH.LogisticsPlatFeatures',
|
|
platid: 556,
|
|
bizcontent: {},
|
|
});
|
|
}
|
|
/**
|
|
* 快手取号。
|
|
*
|
|
* @param {object} [options={}] - 快手取号入参。
|
|
* @param {string} [options.express_id=''] - 快手平台对应的承运商编码。
|
|
* @param {object} [options.wmsOrder={}] - WMS 订单信息。
|
|
* @param {object} [options.expressConfig={}] - 发件方与店铺配置。
|
|
* @returns {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;
|