73 lines
2.1 KiB
JavaScript
73 lines
2.1 KiB
JavaScript
"use strict";
|
||
Object.defineProperty(exports, "__esModule", { value: true });
|
||
const pay_1 = require("../utils/pay");
|
||
const operationResult_1 = require("oak-domain/lib/utils/operationResult");
|
||
const QUERY_PAYING_STATE_GAP = process.env.NODE_ENV === 'production' ? 600 * 1000 : 60 * 1000;
|
||
const watchers = [
|
||
{
|
||
name: '对paying状态的订单,同步其真实支付状态',
|
||
entity: 'pay',
|
||
filter: async () => {
|
||
const now = Date.now();
|
||
return {
|
||
iState: 'paying',
|
||
$$updateAt$$: {
|
||
$lte: now - QUERY_PAYING_STATE_GAP,
|
||
},
|
||
externalId: {
|
||
$exists: true,
|
||
}
|
||
};
|
||
},
|
||
projection: pay_1.fullPayProjection,
|
||
fn: async (context, data) => {
|
||
const results = [];
|
||
for (const pay of data) {
|
||
const result = await (0, pay_1.refreshPayState)(pay, context);
|
||
if (result) {
|
||
results.push(result);
|
||
}
|
||
}
|
||
if (results.length === 0) {
|
||
return {};
|
||
}
|
||
return results.reduce((prev, cur) => (0, operationResult_1.mergeOperationResult)(prev, cur));
|
||
}
|
||
},
|
||
{
|
||
name: '当pay达到禁止退款期限时,关闭退款允许',
|
||
entity: 'pay',
|
||
filter: () => {
|
||
const now = Date.now();
|
||
return {
|
||
refundable: true,
|
||
forbidRefundAt: {
|
||
$lte: now,
|
||
},
|
||
};
|
||
},
|
||
action: 'closeRefund',
|
||
actionData: {
|
||
refundable: false,
|
||
}
|
||
},
|
||
{
|
||
name: '当pay达到过期期限时,关闭pay',
|
||
entity: 'pay',
|
||
filter: () => {
|
||
const now = Date.now();
|
||
return {
|
||
iState: {
|
||
$in: ['unpaid', 'paying'],
|
||
},
|
||
timeoutAt: {
|
||
$lt: now,
|
||
},
|
||
};
|
||
},
|
||
action: 'close',
|
||
actionData: {},
|
||
}
|
||
];
|
||
exports.default = watchers;
|