oak-pay-business/lib/utils/shipClazz/WechatMpShip/WechatMpShip.js

74 lines
2.6 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const WechatMpShip_debug_1 = tslib_1.__importDefault(require("./WechatMpShip.debug"));
class WechatMpShip extends WechatMpShip_debug_1.default {
async eOrder(shipId, context) {
const data = await this.prepareOrder(shipId, context);
const instance = await this.getInstance(context);
const result = await instance.addExpressOrder(data);
return result.waybill_id;
}
async cancelOrder(shipId, context) {
const instance = await this.getInstance(context);
const data = await this.prepareCancelOrder(shipId, context);
await instance.cancelExpressOrder(data);
}
async syncState(shipId, context) {
const instance = await this.getInstance(context);
const data = await this.prepareGetPath(shipId, context);
const result = await instance.getExpressPath(data);
const { path_item_num, path_item_list } = result;
const latestPath = path_item_list[path_item_num - 1] || undefined;
const latestType = latestPath?.action_type;
/**
* action_type:
* 100001 揽件阶段-揽件成功
* 100002 揽件阶段-揽件失败
* 100003 揽件阶段-分配业务员
* 200001 运输阶段-更新运输轨迹
* 300002 派送阶段-开始派送
* 300003 派送阶段-签收成功
* 300004 派送阶段-签收失败
* 400001 异常阶段-订单取消
* 400002 异常阶段-订单滞留
*/
let state = undefined;
switch (latestType) {
case 100001:
case 100003:
case 200001:
case 300002: {
state = 'shipping';
break;
}
case 300003: {
state = 'received';
break;
}
// case 400001: {
// state = 'reject';
// break;
// }
case 100002:
case 300004:
case 400002: {
state = 'unknow';
break;
}
}
return state;
}
async syncPaths(shipId, context) {
const instance = await this.getInstance(context);
const data = await this.prepareGetPath(shipId, context);
const result = await instance.getExpressPath(data);
const paths = result.path_item_list?.map((path) => ({
time: path.action_time,
action: path.action_msg,
}));
return paths;
}
}
exports.default = WechatMpShip;