修改syncState方法

This commit is contained in:
lxy 2025-03-11 17:24:47 +08:00
parent 5e87132d27
commit 12fa14c711
3 changed files with 121 additions and 113 deletions

View File

@ -13,46 +13,48 @@ export default class WechatMpShip extends DebugClazz {
}
async syncState(shipId, context) {
const instance = await this.getInstance(context);
const data = await this.prepareGetWaybillToken(shipId, context);
const waybillToken = await instance.getWaybillToken(data);
const result = await instance.getExpressState(waybillToken);
const { errcode, errmsg, waybill_info } = result;
if (errcode !== 0) {
throw new Error(errmsg);
}
else {
/**
* 0 运单不存在或未揽收
* 1 已揽件
* 2 运输中
* 3 派件中
* 4 已签收
* 5 异常
* 6 代签收
*/
const status = waybill_info.status;
let state = undefined;
switch (status) {
case 1:
case 2:
case 3: {
state = 'shipping';
break;
}
case 4:
case 6: {
state = 'received';
break;
}
case 5: {
state = 'unknow';
}
default: {
state = undefined;
}
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;
}
return state;
}
async syncPaths(shipId, context) {
const instance = await this.getInstance(context);

View File

@ -16,46 +16,48 @@ class WechatMpShip extends WechatMpShip_debug_1.default {
}
async syncState(shipId, context) {
const instance = await this.getInstance(context);
const data = await this.prepareGetWaybillToken(shipId, context);
const waybillToken = await instance.getWaybillToken(data);
const result = await instance.getExpressState(waybillToken);
const { errcode, errmsg, waybill_info } = result;
if (errcode !== 0) {
throw new Error(errmsg);
}
else {
/**
* 0 运单不存在或未揽收
* 1 已揽件
* 2 运输中
* 3 派件中
* 4 已签收
* 5 异常
* 6 代签收
*/
const status = waybill_info.status;
let state = undefined;
switch (status) {
case 1:
case 2:
case 3: {
state = 'shipping';
break;
}
case 4:
case 6: {
state = 'received';
break;
}
case 5: {
state = 'unknow';
}
default: {
state = undefined;
}
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;
}
return state;
}
async syncPaths(shipId, context) {
const instance = await this.getInstance(context);

View File

@ -21,45 +21,49 @@ export default class WechatMpShip<ED extends EntityDict & BaseEntityDict, Contex
async syncState(shipId: string, context: Context): Promise<EntityDict['ship']['OpSchema']['iState']> {
const instance = await this.getInstance(context);
const data = await this.prepareGetWaybillToken(shipId, context);
const waybillToken = await instance.getWaybillToken(data);
const result = await instance.getExpressState(waybillToken);
const { errcode, errmsg, waybill_info } = result;
if (errcode !== 0) {
throw new Error(errmsg);
} else {
/**
* 0
* 1
* 2
* 3
* 4
* 5
* 6
*/
const status = waybill_info!.status!;
let state: EntityDict['ship']['OpSchema']['iState'] = undefined;
switch (status) {
case 1:
case 2:
case 3: {
state = 'shipping';
break;
}
case 4:
case 6: {
state = 'received';
break;
}
case 5: {
state = 'unknow';
}
default: {
state = undefined;
}
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: EntityDict['ship']['OpSchema']['iState'] = 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;
}
return state;
}
async syncPaths(shipId: string, context: Context): Promise<EntityDict['ship']['OpSchema']['extraPaths']> {