90 lines
2.5 KiB
JavaScript
90 lines
2.5 KiB
JavaScript
import { refreshShipState, refreshMpOrderShipState } from '../utils/ship';
|
|
import { mergeOperationResult } from 'oak-domain/lib/utils/operationResult';
|
|
const timers = [
|
|
{
|
|
name: '同步快递ship状态',
|
|
cron: '0 0 3,15 * * ?',
|
|
entity: 'ship',
|
|
filter: {
|
|
type: 'express',
|
|
iState: {
|
|
$nin: ['received', 'cancelled', 'rejected', 'receiving', 'unshipped'],
|
|
},
|
|
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 refreshShipState(ship.id, context);
|
|
if (result) {
|
|
results.push(result);
|
|
}
|
|
}
|
|
if (results.length === 0) {
|
|
return {};
|
|
}
|
|
return results.reduce((prev, cur) => mergeOperationResult(prev, cur));
|
|
},
|
|
},
|
|
{
|
|
name: '同步微信小程序虚拟、自提ship状态',
|
|
cron: '0 * * * * ?',
|
|
entity: 'ship',
|
|
filter: {
|
|
type: {
|
|
$in: ['virtual', 'pickup'],
|
|
},
|
|
iState: {
|
|
$nin: ['received', 'cancelled', 'rejected'],
|
|
},
|
|
},
|
|
projection: {
|
|
id: 1,
|
|
iState: 1,
|
|
},
|
|
fn: async (context, data) => {
|
|
const results = [];
|
|
for (const ship of data) {
|
|
const result = await refreshMpOrderShipState(ship.id, context);
|
|
if (result) {
|
|
results.push(result);
|
|
}
|
|
}
|
|
if (results.length === 0) {
|
|
return {};
|
|
}
|
|
return results.reduce((prev, cur) => mergeOperationResult(prev, cur));
|
|
},
|
|
},
|
|
// {
|
|
// name: '对虚拟或自提类型的ship自动发货',
|
|
// cron: '0 * * * * ?',
|
|
// entity: 'ship',
|
|
// filter: {
|
|
// type: {
|
|
// $in: ['virtual', 'pickup'],
|
|
// },
|
|
// iState: 'unshipped',
|
|
// },
|
|
// projection: {
|
|
// id: 1,
|
|
// },
|
|
// action: 'ship',
|
|
// actionData: {},
|
|
// },
|
|
];
|
|
export default timers;
|