oak-pay-business/lib/timers/ship.js

92 lines
2.6 KiB
JavaScript

"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 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 (0, ship_1.refreshShipState)(ship.id, context);
if (result) {
results.push(result);
}
}
if (results.length === 0) {
return {};
}
return results.reduce((prev, cur) => (0, operationResult_1.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 (0, ship_1.refreshMpOrderShipState)(ship.id, context);
if (result) {
results.push(result);
}
}
if (results.length === 0) {
return {};
}
return results.reduce((prev, cur) => (0, operationResult_1.mergeOperationResult)(prev, cur));
},
},
// {
// name: '对虚拟或自提类型的ship自动发货',
// cron: '0 * * * * ?',
// entity: 'ship',
// filter: {
// type: {
// $in: ['virtual', 'pickup'],
// },
// iState: 'unshipped',
// },
// projection: {
// id: 1,
// },
// action: 'ship',
// actionData: {},
// },
];
exports.default = timers;