添加定时器 同步快递类型的ship的状态
This commit is contained in:
parent
24b5e28531
commit
6b8f123e63
|
|
@ -1,4 +1,4 @@
|
|||
import { getShipState } from '../utils/ship';
|
||||
import { getOrderShipState } from '../utils/ship';
|
||||
/**
|
||||
* 获取小程序订单发货状态
|
||||
* @param params
|
||||
|
|
@ -9,7 +9,7 @@ export async function getMpShipState(params, context) {
|
|||
const { type, } = application;
|
||||
if (type === 'wechatMp') {
|
||||
const { shipId } = params;
|
||||
const shipState = await getShipState(context, shipId);
|
||||
const shipState = await getOrderShipState(context, shipId);
|
||||
return shipState;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Timer } from 'oak-domain/lib/types/Timer';
|
||||
import { EntityDict } from '../oak-app-domain/index';
|
||||
import { BRC } from '../types/RuntimeCxt';
|
||||
declare const timers: Array<Timer<EntityDict, keyof EntityDict, BRC>>;
|
||||
export default timers;
|
||||
declare const _default: Timer<EntityDict, keyof EntityDict, BRC>[];
|
||||
export default _default;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
import ShipTimers from './ship';
|
||||
export default [
|
||||
...ShipTimers,
|
||||
];
|
||||
const timers = [
|
||||
// {
|
||||
// name: '示例timer',
|
||||
|
|
@ -22,4 +26,4 @@ const timers = [
|
|||
// },
|
||||
// },
|
||||
];
|
||||
export default timers;
|
||||
// export default timers;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
import { Timer } from 'oak-domain/lib/types/Timer';
|
||||
import { EntityDict } from '../oak-app-domain/index';
|
||||
import { BRC } from '../types/RuntimeCxt';
|
||||
declare const timers: Array<Timer<EntityDict, 'ship', BRC>>;
|
||||
export default timers;
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
import { refreshtShipState } from '../utils/ship';
|
||||
import { mergeOperationResult } from 'oak-domain/lib/utils/operationResult';
|
||||
const timers = [
|
||||
{
|
||||
name: '同步快递ship状态',
|
||||
cron: '0 0 0 * * ?',
|
||||
entity: 'ship',
|
||||
filter: {
|
||||
type: 'express',
|
||||
iState: {
|
||||
$nin: ['received', 'cancelled', 'rejected'],
|
||||
},
|
||||
entity: {
|
||||
$exists: true
|
||||
},
|
||||
entityId: {
|
||||
$exists: true
|
||||
},
|
||||
extraShipId: {
|
||||
$exists: true,
|
||||
}
|
||||
},
|
||||
projection: {
|
||||
id: 1,
|
||||
entity: 1,
|
||||
entityId: 1,
|
||||
},
|
||||
fn: async (context, data) => {
|
||||
const results = [];
|
||||
for (const ship of data) {
|
||||
const result = await refreshtShipState(ship, context);
|
||||
if (result) {
|
||||
results.push(result);
|
||||
}
|
||||
}
|
||||
if (results.length === 0) {
|
||||
return {};
|
||||
}
|
||||
return results.reduce((prev, cur) => mergeOperationResult(prev, cur));
|
||||
},
|
||||
},
|
||||
];
|
||||
export default timers;
|
||||
|
|
@ -2,7 +2,7 @@ import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
|
|||
import { DATA_SUBSCRIBER_KEYS } from '../config/constants';
|
||||
import assert from 'assert';
|
||||
import { getShipClazz, getShipEntity } from '../utils/shipClazz';
|
||||
import { getShipState, uploadShippingInfo } from '../utils/ship';
|
||||
import { uploadShippingInfo } from '../utils/ship';
|
||||
const triggers = [
|
||||
{
|
||||
name: '当虚拟或自提类型的ship创建后自动发货',
|
||||
|
|
@ -98,12 +98,8 @@ const triggers = [
|
|||
const { id: shipId, type, deposit$ship: deposits, shipOrder$ship, shipServiceId, entity, entityId, wechatMpShip } = ship || {};
|
||||
if (deposits && deposits.length > 0) {
|
||||
//充值 (此时该充值必定为受发货限制的小程序上的充值)
|
||||
//发货前先查询,检查是否为未同步微信端发货状态
|
||||
const shipState = await getShipState(context, shipId);
|
||||
if (shipState === 'unshipped') {
|
||||
await uploadShippingInfo(shipId, context);
|
||||
return 1;
|
||||
}
|
||||
await uploadShippingInfo(shipId, context);
|
||||
return 1;
|
||||
}
|
||||
if (shipOrder$ship && shipOrder$ship.length > 0) {
|
||||
//订单
|
||||
|
|
@ -111,13 +107,8 @@ const triggers = [
|
|||
const { openId } = await clazz.getReceiverInfo(shipOrder$ship.map((ele) => ele.orderId), wechatMpShip?.applicationId, context);
|
||||
if (openId) {
|
||||
//当存在openId时调用小程序发货信息录入
|
||||
const shipState = await getShipState(context, shipId);
|
||||
//当已发货的订单再次调用小程序发货信息录入接口视为重新发货(仅可重新发货一次)
|
||||
if (shipState && ['unshipped', 'shipping'].includes(shipState)) {
|
||||
// 发货/更换发货
|
||||
await uploadShippingInfo(shipId, context);
|
||||
return 1;
|
||||
}
|
||||
await uploadShippingInfo(shipId, context);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@ import { BRC } from '../types/RuntimeCxt';
|
|||
* @param context
|
||||
* @param refunds
|
||||
*/
|
||||
export declare function updateWithdrawState(context: BRC, id: string): Promise<1 | 0>;
|
||||
export declare function updateWithdrawState(context: BRC, id: string): Promise<0 | 1>;
|
||||
declare const triggers: Trigger<EntityDict, 'withdraw', BRC>[];
|
||||
export default triggers;
|
||||
|
|
|
|||
|
|
@ -20,8 +20,9 @@ export declare function uploadShippingInfo(shipId: string, context: BRC): Promis
|
|||
* @param order
|
||||
* @returns
|
||||
*/
|
||||
export declare function getShipState(context: BRC, shipId: string): Promise<string | undefined>;
|
||||
/**刷新shipping的ship的小程序物流状态
|
||||
export declare function getOrderShipState(context: BRC, shipId: string): Promise<string | undefined>;
|
||||
/**
|
||||
* 刷新ship的物流状态
|
||||
* @param ship
|
||||
* @param context
|
||||
* @returns
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
|
|||
import { UploadShipException } from '../types/Exception';
|
||||
import dayjs from 'dayjs';
|
||||
import { isMobile } from 'oak-domain/lib/utils/validator';
|
||||
import { getShipClazz } from './shipClazz';
|
||||
export const shipProjection = {
|
||||
id: 1,
|
||||
type: 1,
|
||||
|
|
@ -143,7 +144,7 @@ export async function uploadShippingInfo(shipId, context) {
|
|||
const { deposit$ship: deposits, shipOrder$ship, type: shipType, extraShipId, shipService, from, to } = ship;
|
||||
// assert(iState === 'unshipped'); //可更改一次发货信息
|
||||
//发货信息录入前检查小程序订单发货状态
|
||||
const shipState = await getShipState(context, shipId);
|
||||
const shipState = await getOrderShipState(context, shipId);
|
||||
const now = dayjs().format();
|
||||
const application = context.getApplication();
|
||||
const { type, config } = application;
|
||||
|
|
@ -182,6 +183,7 @@ export async function uploadShippingInfo(shipId, context) {
|
|||
}
|
||||
else if (shipOrder$ship && shipOrder$ship.length > 0 && shipState && ['unshipped', 'shipping'].includes(shipState)) {
|
||||
//订单 每笔微信支付调用一次接口
|
||||
//当已发货的订单再次调用小程序发货信息录入接口视为重新发货(仅可重新发货一次)
|
||||
const orders = shipOrder$ship.map((ele) => ele.order);
|
||||
const fromPhoneStr = maskPhone(from.phone);
|
||||
const toPhoneStr = maskPhone(to.phone);
|
||||
|
|
@ -236,7 +238,7 @@ export async function uploadShippingInfo(shipId, context) {
|
|||
* @param order
|
||||
* @returns
|
||||
*/
|
||||
export async function getShipState(context, shipId) {
|
||||
export async function getOrderShipState(context, shipId) {
|
||||
const [ship] = await context.select('ship', {
|
||||
data: shipProjection,
|
||||
filter: {
|
||||
|
|
@ -299,14 +301,15 @@ export async function getShipState(context, shipId) {
|
|||
}
|
||||
}
|
||||
}
|
||||
/**刷新shipping的ship的小程序物流状态
|
||||
/**
|
||||
* 刷新ship的物流状态
|
||||
* @param ship
|
||||
* @param context
|
||||
* @returns
|
||||
*/
|
||||
export async function refreshtShipState(ship, context) {
|
||||
let ship2 = ship;
|
||||
if (!ship2.iState) {
|
||||
if (!ship2.iState || !ship2.entity || !ship2.entityId) {
|
||||
const ships = await context.select('ship', {
|
||||
data: shipProjection,
|
||||
filter: {
|
||||
|
|
@ -318,15 +321,20 @@ export async function refreshtShipState(ship, context) {
|
|||
});
|
||||
ship2 = ships[0];
|
||||
}
|
||||
const state = await getShipState(context, ship2.id);
|
||||
const { entity, entityId } = ship2;
|
||||
const clazz = await getShipClazz(entity, entityId, context);
|
||||
const state = await clazz.syncState(ship2.id, context);
|
||||
let action = undefined;
|
||||
switch (state) {
|
||||
case 'shipping': //已发货
|
||||
action = 'ship';
|
||||
break;
|
||||
case 'received': //确认收货
|
||||
case 'received': //已收货
|
||||
action = 'receive';
|
||||
break;
|
||||
case 'unknow': //不明
|
||||
action = 'unknow';
|
||||
break;
|
||||
default:
|
||||
action = undefined;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,20 +27,6 @@ export default class WechatMpShipDebug<ED extends EntityDict & BaseEntityDict, C
|
|||
waybill_id: NonNullable<ED["ship"]["Schema"]["extraShipId"]>;
|
||||
order_id: string;
|
||||
}>;
|
||||
protected prepareGetWaybillToken(shipId: string, context: Context): Promise<{
|
||||
openid: string | undefined;
|
||||
sender_phone: string;
|
||||
receiver_phone: string;
|
||||
delivery_id: string;
|
||||
waybill_id: NonNullable<ED["ship"]["Schema"]["extraShipId"]>;
|
||||
goods_info: {
|
||||
detail_list: {
|
||||
goods_name: string;
|
||||
goods_img_url: string;
|
||||
goods_desc?: string | undefined;
|
||||
}[];
|
||||
};
|
||||
}>;
|
||||
protected prepareGetPath(shipId: string, context: Context): Promise<{
|
||||
openid: string | undefined;
|
||||
delivery_id: string;
|
||||
|
|
|
|||
|
|
@ -205,57 +205,6 @@ export default class WechatMpShipDebug {
|
|||
order_id: shipId,
|
||||
};
|
||||
}
|
||||
async prepareGetWaybillToken(shipId, context) {
|
||||
const [ship] = await context.select('ship', {
|
||||
data: {
|
||||
id: 1,
|
||||
from: {
|
||||
id: 1,
|
||||
phone: 1,
|
||||
},
|
||||
to: {
|
||||
id: 1,
|
||||
phone: 1,
|
||||
},
|
||||
shipService: {
|
||||
shipCompanyId: 1,
|
||||
},
|
||||
extraShipId: 1,
|
||||
wechatMpShip: {
|
||||
applicationId: 1,
|
||||
},
|
||||
shipOrder$ship: {
|
||||
$entity: 'shipOrder',
|
||||
data: {
|
||||
id: 1,
|
||||
orderId: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
filter: {
|
||||
id: shipId,
|
||||
}
|
||||
}, { dontCollect: true });
|
||||
assert(ship);
|
||||
const { extraShipId, from, to, shipService, shipOrder$ship: shipOrders, wechatMpShip } = ship;
|
||||
const orderIds = shipOrders.map(ele => ele.orderId);
|
||||
const { openId } = await this.getReceiverInfo(orderIds, wechatMpShip.applicationId, context);
|
||||
const extraData = await this.getExtraData(shipId, context);
|
||||
const detailList = extraData.shop.detail_list;
|
||||
//todo order_detail_path
|
||||
return {
|
||||
openid: openId,
|
||||
sender_phone: from.phone,
|
||||
receiver_phone: from.phone,
|
||||
delivery_id: shipService.shipCompanyId,
|
||||
waybill_id: extraShipId,
|
||||
goods_info: {
|
||||
detail_list: detailList,
|
||||
},
|
||||
// trans_id: '',
|
||||
// order_detail_path: '',
|
||||
};
|
||||
}
|
||||
async prepareGetPath(shipId, context) {
|
||||
const [ship] = await context.select('ship', {
|
||||
data: {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ async function getMpShipState(params, context) {
|
|||
const { type, } = application;
|
||||
if (type === 'wechatMp') {
|
||||
const { shipId } = params;
|
||||
const shipState = await (0, ship_1.getShipState)(context, shipId);
|
||||
const shipState = await (0, ship_1.getOrderShipState)(context, shipId);
|
||||
return shipState;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Timer } from 'oak-domain/lib/types/Timer';
|
||||
import { EntityDict } from '../oak-app-domain/index';
|
||||
import { BRC } from '../types/RuntimeCxt';
|
||||
declare const timers: Array<Timer<EntityDict, keyof EntityDict, BRC>>;
|
||||
export default timers;
|
||||
declare const _default: Timer<EntityDict, keyof EntityDict, BRC>[];
|
||||
export default _default;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
const ship_1 = tslib_1.__importDefault(require("./ship"));
|
||||
exports.default = [
|
||||
...ship_1.default,
|
||||
];
|
||||
const timers = [
|
||||
// {
|
||||
// name: '示例timer',
|
||||
|
|
@ -24,4 +29,4 @@ const timers = [
|
|||
// },
|
||||
// },
|
||||
];
|
||||
exports.default = timers;
|
||||
// export default timers;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
import { Timer } from 'oak-domain/lib/types/Timer';
|
||||
import { EntityDict } from '../oak-app-domain/index';
|
||||
import { BRC } from '../types/RuntimeCxt';
|
||||
declare const timers: Array<Timer<EntityDict, 'ship', BRC>>;
|
||||
export default timers;
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const ship_1 = require("../utils/ship");
|
||||
const operationResult_1 = require("oak-domain/lib/utils/operationResult");
|
||||
const timers = [
|
||||
{
|
||||
name: '同步快递ship状态',
|
||||
cron: '0 0 0 * * ?',
|
||||
entity: 'ship',
|
||||
filter: {
|
||||
type: 'express',
|
||||
iState: {
|
||||
$nin: ['received', 'cancelled', 'rejected'],
|
||||
},
|
||||
entity: {
|
||||
$exists: true
|
||||
},
|
||||
entityId: {
|
||||
$exists: true
|
||||
},
|
||||
extraShipId: {
|
||||
$exists: true,
|
||||
}
|
||||
},
|
||||
projection: {
|
||||
id: 1,
|
||||
entity: 1,
|
||||
entityId: 1,
|
||||
},
|
||||
fn: async (context, data) => {
|
||||
const results = [];
|
||||
for (const ship of data) {
|
||||
const result = await (0, ship_1.refreshtShipState)(ship, context);
|
||||
if (result) {
|
||||
results.push(result);
|
||||
}
|
||||
}
|
||||
if (results.length === 0) {
|
||||
return {};
|
||||
}
|
||||
return results.reduce((prev, cur) => (0, operationResult_1.mergeOperationResult)(prev, cur));
|
||||
},
|
||||
},
|
||||
];
|
||||
exports.default = timers;
|
||||
|
|
@ -101,12 +101,8 @@ const triggers = [
|
|||
const { id: shipId, type, deposit$ship: deposits, shipOrder$ship, shipServiceId, entity, entityId, wechatMpShip } = ship || {};
|
||||
if (deposits && deposits.length > 0) {
|
||||
//充值 (此时该充值必定为受发货限制的小程序上的充值)
|
||||
//发货前先查询,检查是否为未同步微信端发货状态
|
||||
const shipState = await (0, ship_1.getShipState)(context, shipId);
|
||||
if (shipState === 'unshipped') {
|
||||
await (0, ship_1.uploadShippingInfo)(shipId, context);
|
||||
return 1;
|
||||
}
|
||||
await (0, ship_1.uploadShippingInfo)(shipId, context);
|
||||
return 1;
|
||||
}
|
||||
if (shipOrder$ship && shipOrder$ship.length > 0) {
|
||||
//订单
|
||||
|
|
@ -114,13 +110,8 @@ const triggers = [
|
|||
const { openId } = await clazz.getReceiverInfo(shipOrder$ship.map((ele) => ele.orderId), wechatMpShip?.applicationId, context);
|
||||
if (openId) {
|
||||
//当存在openId时调用小程序发货信息录入
|
||||
const shipState = await (0, ship_1.getShipState)(context, shipId);
|
||||
//当已发货的订单再次调用小程序发货信息录入接口视为重新发货(仅可重新发货一次)
|
||||
if (shipState && ['unshipped', 'shipping'].includes(shipState)) {
|
||||
// 发货/更换发货
|
||||
await (0, ship_1.uploadShippingInfo)(shipId, context);
|
||||
return 1;
|
||||
}
|
||||
await (0, ship_1.uploadShippingInfo)(shipId, context);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@ import { BRC } from '../types/RuntimeCxt';
|
|||
* @param context
|
||||
* @param refunds
|
||||
*/
|
||||
export declare function updateWithdrawState(context: BRC, id: string): Promise<1 | 0>;
|
||||
export declare function updateWithdrawState(context: BRC, id: string): Promise<0 | 1>;
|
||||
declare const triggers: Trigger<EntityDict, 'withdraw', BRC>[];
|
||||
export default triggers;
|
||||
|
|
|
|||
|
|
@ -20,8 +20,9 @@ export declare function uploadShippingInfo(shipId: string, context: BRC): Promis
|
|||
* @param order
|
||||
* @returns
|
||||
*/
|
||||
export declare function getShipState(context: BRC, shipId: string): Promise<string | undefined>;
|
||||
/**刷新shipping的ship的小程序物流状态
|
||||
export declare function getOrderShipState(context: BRC, shipId: string): Promise<string | undefined>;
|
||||
/**
|
||||
* 刷新ship的物流状态
|
||||
* @param ship
|
||||
* @param context
|
||||
* @returns
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.refreshtShipState = exports.getShipState = exports.uploadShippingInfo = exports.maskPhone = exports.shipProjection = void 0;
|
||||
exports.refreshtShipState = exports.getOrderShipState = exports.uploadShippingInfo = exports.maskPhone = exports.shipProjection = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const oak_external_sdk_1 = require("oak-external-sdk");
|
||||
const assert_1 = require("oak-domain/lib/utils/assert");
|
||||
|
|
@ -8,6 +8,7 @@ const uuid_1 = require("oak-domain/lib/utils/uuid");
|
|||
const Exception_1 = require("../types/Exception");
|
||||
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
||||
const validator_1 = require("oak-domain/lib/utils/validator");
|
||||
const shipClazz_1 = require("./shipClazz");
|
||||
exports.shipProjection = {
|
||||
id: 1,
|
||||
type: 1,
|
||||
|
|
@ -148,7 +149,7 @@ async function uploadShippingInfo(shipId, context) {
|
|||
const { deposit$ship: deposits, shipOrder$ship, type: shipType, extraShipId, shipService, from, to } = ship;
|
||||
// assert(iState === 'unshipped'); //可更改一次发货信息
|
||||
//发货信息录入前检查小程序订单发货状态
|
||||
const shipState = await getShipState(context, shipId);
|
||||
const shipState = await getOrderShipState(context, shipId);
|
||||
const now = (0, dayjs_1.default)().format();
|
||||
const application = context.getApplication();
|
||||
const { type, config } = application;
|
||||
|
|
@ -187,6 +188,7 @@ async function uploadShippingInfo(shipId, context) {
|
|||
}
|
||||
else if (shipOrder$ship && shipOrder$ship.length > 0 && shipState && ['unshipped', 'shipping'].includes(shipState)) {
|
||||
//订单 每笔微信支付调用一次接口
|
||||
//当已发货的订单再次调用小程序发货信息录入接口视为重新发货(仅可重新发货一次)
|
||||
const orders = shipOrder$ship.map((ele) => ele.order);
|
||||
const fromPhoneStr = maskPhone(from.phone);
|
||||
const toPhoneStr = maskPhone(to.phone);
|
||||
|
|
@ -242,7 +244,7 @@ exports.uploadShippingInfo = uploadShippingInfo;
|
|||
* @param order
|
||||
* @returns
|
||||
*/
|
||||
async function getShipState(context, shipId) {
|
||||
async function getOrderShipState(context, shipId) {
|
||||
const [ship] = await context.select('ship', {
|
||||
data: exports.shipProjection,
|
||||
filter: {
|
||||
|
|
@ -305,15 +307,16 @@ async function getShipState(context, shipId) {
|
|||
}
|
||||
}
|
||||
}
|
||||
exports.getShipState = getShipState;
|
||||
/**刷新shipping的ship的小程序物流状态
|
||||
exports.getOrderShipState = getOrderShipState;
|
||||
/**
|
||||
* 刷新ship的物流状态
|
||||
* @param ship
|
||||
* @param context
|
||||
* @returns
|
||||
*/
|
||||
async function refreshtShipState(ship, context) {
|
||||
let ship2 = ship;
|
||||
if (!ship2.iState) {
|
||||
if (!ship2.iState || !ship2.entity || !ship2.entityId) {
|
||||
const ships = await context.select('ship', {
|
||||
data: exports.shipProjection,
|
||||
filter: {
|
||||
|
|
@ -325,15 +328,20 @@ async function refreshtShipState(ship, context) {
|
|||
});
|
||||
ship2 = ships[0];
|
||||
}
|
||||
const state = await getShipState(context, ship2.id);
|
||||
const { entity, entityId } = ship2;
|
||||
const clazz = await (0, shipClazz_1.getShipClazz)(entity, entityId, context);
|
||||
const state = await clazz.syncState(ship2.id, context);
|
||||
let action = undefined;
|
||||
switch (state) {
|
||||
case 'shipping': //已发货
|
||||
action = 'ship';
|
||||
break;
|
||||
case 'received': //确认收货
|
||||
case 'received': //已收货
|
||||
action = 'receive';
|
||||
break;
|
||||
case 'unknow': //不明
|
||||
action = 'unknow';
|
||||
break;
|
||||
default:
|
||||
action = undefined;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,20 +27,6 @@ export default class WechatMpShipDebug<ED extends EntityDict & BaseEntityDict, C
|
|||
waybill_id: NonNullable<ED["ship"]["Schema"]["extraShipId"]>;
|
||||
order_id: string;
|
||||
}>;
|
||||
protected prepareGetWaybillToken(shipId: string, context: Context): Promise<{
|
||||
openid: string | undefined;
|
||||
sender_phone: string;
|
||||
receiver_phone: string;
|
||||
delivery_id: string;
|
||||
waybill_id: NonNullable<ED["ship"]["Schema"]["extraShipId"]>;
|
||||
goods_info: {
|
||||
detail_list: {
|
||||
goods_name: string;
|
||||
goods_img_url: string;
|
||||
goods_desc?: string | undefined;
|
||||
}[];
|
||||
};
|
||||
}>;
|
||||
protected prepareGetPath(shipId: string, context: Context): Promise<{
|
||||
openid: string | undefined;
|
||||
delivery_id: string;
|
||||
|
|
|
|||
|
|
@ -208,57 +208,6 @@ class WechatMpShipDebug {
|
|||
order_id: shipId,
|
||||
};
|
||||
}
|
||||
async prepareGetWaybillToken(shipId, context) {
|
||||
const [ship] = await context.select('ship', {
|
||||
data: {
|
||||
id: 1,
|
||||
from: {
|
||||
id: 1,
|
||||
phone: 1,
|
||||
},
|
||||
to: {
|
||||
id: 1,
|
||||
phone: 1,
|
||||
},
|
||||
shipService: {
|
||||
shipCompanyId: 1,
|
||||
},
|
||||
extraShipId: 1,
|
||||
wechatMpShip: {
|
||||
applicationId: 1,
|
||||
},
|
||||
shipOrder$ship: {
|
||||
$entity: 'shipOrder',
|
||||
data: {
|
||||
id: 1,
|
||||
orderId: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
filter: {
|
||||
id: shipId,
|
||||
}
|
||||
}, { dontCollect: true });
|
||||
(0, assert_1.default)(ship);
|
||||
const { extraShipId, from, to, shipService, shipOrder$ship: shipOrders, wechatMpShip } = ship;
|
||||
const orderIds = shipOrders.map(ele => ele.orderId);
|
||||
const { openId } = await this.getReceiverInfo(orderIds, wechatMpShip.applicationId, context);
|
||||
const extraData = await this.getExtraData(shipId, context);
|
||||
const detailList = extraData.shop.detail_list;
|
||||
//todo order_detail_path
|
||||
return {
|
||||
openid: openId,
|
||||
sender_phone: from.phone,
|
||||
receiver_phone: from.phone,
|
||||
delivery_id: shipService.shipCompanyId,
|
||||
waybill_id: extraShipId,
|
||||
goods_info: {
|
||||
detail_list: detailList,
|
||||
},
|
||||
// trans_id: '',
|
||||
// order_detail_path: '',
|
||||
};
|
||||
}
|
||||
async prepareGetPath(shipId, context) {
|
||||
const [ship] = await context.select('ship', {
|
||||
data: {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { OakException, OakInputIllegalException } from 'oak-domain/lib/types';
|
|||
import { EntityDict } from '../oak-app-domain';
|
||||
import { BRC } from '../types/RuntimeCxt';
|
||||
import assert from 'assert';
|
||||
import { getShipState } from '../utils/ship';
|
||||
import { getOrderShipState } from '../utils/ship';
|
||||
|
||||
/**
|
||||
* 获取小程序订单发货状态
|
||||
|
|
@ -19,7 +19,7 @@ export async function getMpShipState(
|
|||
const { type, } = application!;
|
||||
if (type === 'wechatMp') {
|
||||
const { shipId } = params;
|
||||
const shipState = await getShipState(
|
||||
const shipState = await getOrderShipState(
|
||||
context,
|
||||
shipId,
|
||||
) as EntityDict['ship']['Schema']['iState'];
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
import { Timer } from 'oak-domain/lib/types/Timer';
|
||||
import { EntityDict } from '@oak-app-domain';
|
||||
import { BRC } from '../types/RuntimeCxt';
|
||||
import ShipTimers from './ship';
|
||||
|
||||
export default [
|
||||
...ShipTimers,
|
||||
|
||||
] as Array<Timer<EntityDict, keyof EntityDict, BRC>>;
|
||||
|
||||
const timers: Array<Timer<EntityDict, keyof EntityDict, BRC>> = [
|
||||
// {
|
||||
|
|
@ -27,4 +33,4 @@ const timers: Array<Timer<EntityDict, keyof EntityDict, BRC>> = [
|
|||
// },
|
||||
];
|
||||
|
||||
export default timers;
|
||||
// export default timers;
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
import { Timer } from 'oak-domain/lib/types/Timer';
|
||||
import { EntityDict } from '@oak-app-domain';
|
||||
import { BRC } from '../types/RuntimeCxt';
|
||||
import { getShipClazz } from '@project/utils/shipClazz';
|
||||
import { OperationResult } from 'oak-domain/lib/types';
|
||||
import { refreshtShipState } from '@project/utils/ship';
|
||||
import { mergeOperationResult } from 'oak-domain/lib/utils/operationResult';
|
||||
|
||||
const timers: Array<Timer<EntityDict, 'ship', BRC>> = [
|
||||
{
|
||||
name: '同步快递ship状态',
|
||||
cron: '0 0 0 * * ?',
|
||||
entity: 'ship',
|
||||
filter: {
|
||||
type: 'express',
|
||||
iState: {
|
||||
$nin: ['received', 'cancelled', 'rejected'],
|
||||
},
|
||||
entity: {
|
||||
$exists: true
|
||||
},
|
||||
entityId: {
|
||||
$exists: true
|
||||
},
|
||||
extraShipId: {
|
||||
$exists: true,
|
||||
}
|
||||
},
|
||||
projection: {
|
||||
id: 1,
|
||||
entity: 1,
|
||||
entityId: 1,
|
||||
},
|
||||
fn: async (context, data) => {
|
||||
const results = [] as OperationResult<EntityDict>[];
|
||||
for (const ship of data) {
|
||||
const result = await refreshtShipState(ship as EntityDict['ship']['OpSchema'], context);
|
||||
if (result) {
|
||||
results.push(result);
|
||||
}
|
||||
}
|
||||
if (results.length === 0) {
|
||||
return {};
|
||||
}
|
||||
return results.reduce(
|
||||
(prev, cur) => mergeOperationResult(prev, cur)
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export default timers;
|
||||
|
|
@ -5,7 +5,7 @@ import { BRC } from '../types/RuntimeCxt';
|
|||
import { DATA_SUBSCRIBER_KEYS } from '../config/constants';
|
||||
import assert from 'assert';
|
||||
import { getShipClazz, getShipEntity } from '../utils/shipClazz';
|
||||
import { getShipState, uploadShippingInfo } from '../utils/ship';
|
||||
import { uploadShippingInfo } from '../utils/ship';
|
||||
|
||||
const triggers: Trigger<EntityDict, 'ship', BRC>[] = [
|
||||
{
|
||||
|
|
@ -107,13 +107,8 @@ const triggers: Trigger<EntityDict, 'ship', BRC>[] = [
|
|||
const { id: shipId, type, deposit$ship: deposits, shipOrder$ship, shipServiceId, entity, entityId, wechatMpShip } = ship || {};
|
||||
if (deposits && deposits.length > 0) {
|
||||
//充值 (此时该充值必定为受发货限制的小程序上的充值)
|
||||
|
||||
//发货前先查询,检查是否为未同步微信端发货状态
|
||||
const shipState = await getShipState(context, shipId!);
|
||||
if (shipState === 'unshipped') {
|
||||
await uploadShippingInfo(shipId!, context);
|
||||
return 1;
|
||||
}
|
||||
await uploadShippingInfo(shipId!, context);
|
||||
return 1;
|
||||
}
|
||||
if (shipOrder$ship && shipOrder$ship.length > 0) {
|
||||
//订单
|
||||
|
|
@ -121,13 +116,8 @@ const triggers: Trigger<EntityDict, 'ship', BRC>[] = [
|
|||
const { openId } = await clazz.getReceiverInfo(shipOrder$ship.map((ele) => ele.orderId!), wechatMpShip?.applicationId!, context);
|
||||
if (openId) {
|
||||
//当存在openId时调用小程序发货信息录入
|
||||
const shipState = await getShipState(context, shipId!);
|
||||
//当已发货的订单再次调用小程序发货信息录入接口视为重新发货(仅可重新发货一次)
|
||||
if (shipState && ['unshipped', 'shipping'].includes(shipState)) {
|
||||
// 发货/更换发货
|
||||
await uploadShippingInfo(shipId!, context);
|
||||
return 1;
|
||||
}
|
||||
await uploadShippingInfo(shipId!, context);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -7,9 +7,7 @@ import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
|
|||
import { UploadShipException } from '../types/Exception';
|
||||
import dayjs from 'dayjs';
|
||||
import { isMobile } from 'oak-domain/lib/utils/validator';
|
||||
import { OakInputIllegalException } from 'oak-domain/lib/types';
|
||||
import { unionBy } from 'oak-domain/lib/utils/lodash';
|
||||
|
||||
import { getShipClazz } from './shipClazz';
|
||||
|
||||
export const shipProjection: EntityDict['ship']['Projection'] = {
|
||||
id: 1,
|
||||
|
|
@ -156,7 +154,7 @@ export async function uploadShippingInfo(
|
|||
// assert(iState === 'unshipped'); //可更改一次发货信息
|
||||
|
||||
//发货信息录入前检查小程序订单发货状态
|
||||
const shipState = await getShipState(context, shipId);
|
||||
const shipState = await getOrderShipState(context, shipId);
|
||||
const now = dayjs().format();
|
||||
|
||||
const application = context.getApplication();
|
||||
|
|
@ -205,6 +203,7 @@ export async function uploadShippingInfo(
|
|||
}
|
||||
} else if (shipOrder$ship && shipOrder$ship.length > 0 && shipState && ['unshipped', 'shipping'].includes(shipState)) {
|
||||
//订单 每笔微信支付调用一次接口
|
||||
//当已发货的订单再次调用小程序发货信息录入接口视为重新发货(仅可重新发货一次)
|
||||
const orders = shipOrder$ship.map((ele) => ele.order);
|
||||
const fromPhoneStr = maskPhone(from!.phone!);
|
||||
const toPhoneStr = maskPhone(to!.phone!);
|
||||
|
|
@ -265,7 +264,7 @@ export async function uploadShippingInfo(
|
|||
* @param order
|
||||
* @returns
|
||||
*/
|
||||
export async function getShipState(
|
||||
export async function getOrderShipState(
|
||||
context: BRC,
|
||||
shipId: string,
|
||||
) {
|
||||
|
|
@ -339,7 +338,8 @@ export async function getShipState(
|
|||
}
|
||||
|
||||
|
||||
/**刷新shipping的ship的小程序物流状态
|
||||
/**
|
||||
* 刷新ship的物流状态
|
||||
* @param ship
|
||||
* @param context
|
||||
* @returns
|
||||
|
|
@ -350,7 +350,7 @@ export async function refreshtShipState(
|
|||
context: BRC,
|
||||
) {
|
||||
let ship2 = ship;
|
||||
if (!ship2.iState) {
|
||||
if (!ship2.iState || !ship2.entity || !ship2.entityId) {
|
||||
const ships = await context.select('ship', {
|
||||
data: shipProjection,
|
||||
filter: {
|
||||
|
|
@ -362,15 +362,20 @@ export async function refreshtShipState(
|
|||
});
|
||||
ship2 = ships[0] as typeof ship;
|
||||
}
|
||||
const state = await getShipState(context, ship2.id!);
|
||||
const { entity, entityId } = ship2;
|
||||
const clazz = await getShipClazz(entity!, entityId!, context);
|
||||
const state = await clazz.syncState(ship2.id!, context);
|
||||
let action = undefined;
|
||||
switch (state) {
|
||||
case 'shipping': //已发货
|
||||
action = 'ship';
|
||||
break;
|
||||
case 'received': //确认收货
|
||||
case 'received': //已收货
|
||||
action = 'receive';
|
||||
break;
|
||||
case 'unknow': //不明
|
||||
action = 'unknow';
|
||||
break;
|
||||
default:
|
||||
action = undefined;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -245,66 +245,6 @@ export default class WechatMpShipDebug<ED extends EntityDict & BaseEntityDict, C
|
|||
};
|
||||
}
|
||||
|
||||
protected async prepareGetWaybillToken(shipId: string, context: Context) {
|
||||
const [ship] = await context.select('ship', {
|
||||
data: {
|
||||
id: 1,
|
||||
from: {
|
||||
id: 1,
|
||||
phone: 1,
|
||||
},
|
||||
to: {
|
||||
id: 1,
|
||||
phone: 1,
|
||||
},
|
||||
shipService: {
|
||||
shipCompanyId: 1,
|
||||
},
|
||||
extraShipId: 1,
|
||||
wechatMpShip: {
|
||||
applicationId: 1,
|
||||
},
|
||||
shipOrder$ship: {
|
||||
$entity: 'shipOrder',
|
||||
data: {
|
||||
id: 1,
|
||||
orderId: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
filter: {
|
||||
id: shipId,
|
||||
}
|
||||
}, { dontCollect: true });
|
||||
|
||||
assert(ship);
|
||||
const { extraShipId, from, to, shipService, shipOrder$ship: shipOrders, wechatMpShip } = ship;
|
||||
const orderIds = shipOrders!.map(ele => ele.orderId);
|
||||
const { openId } = await this.getReceiverInfo(orderIds, wechatMpShip!.applicationId!, context);
|
||||
|
||||
|
||||
const extraData = await this.getExtraData(shipId, context);
|
||||
const detailList = extraData.shop.detail_list! as Array<{
|
||||
goods_name: string;
|
||||
goods_img_url: string;
|
||||
goods_desc?: string;
|
||||
}>;
|
||||
|
||||
//todo order_detail_path
|
||||
return {
|
||||
openid: openId,
|
||||
sender_phone: from!.phone!,
|
||||
receiver_phone: from!.phone!,
|
||||
delivery_id: shipService!.shipCompanyId!,
|
||||
waybill_id: extraShipId!,
|
||||
goods_info: {
|
||||
detail_list: detailList,
|
||||
},
|
||||
// trans_id: '',
|
||||
// order_detail_path: '',
|
||||
};
|
||||
}
|
||||
|
||||
protected async prepareGetPath(shipId: string, context: Context) {
|
||||
const [ship] = await context.select('ship', {
|
||||
data: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue