112 lines
3.8 KiB
JavaScript
112 lines
3.8 KiB
JavaScript
"use strict";
|
||
Object.defineProperty(exports, "__esModule", { value: true });
|
||
const uuid_1 = require("oak-domain/lib/utils/uuid");
|
||
const constants_1 = require("../config/constants");
|
||
const ship_1 = require("../utils/ship");
|
||
const triggers = [
|
||
{
|
||
name: '当虚拟发货创建后自动发货',
|
||
entity: 'ship',
|
||
action: 'create',
|
||
when: 'commit',
|
||
asRoot: true,
|
||
fn: async ({ ids }, context, option) => {
|
||
for (const id of ids) {
|
||
const [ship] = await context.select('ship', {
|
||
data: {
|
||
id: 1,
|
||
type: 1,
|
||
deposit$ship: {
|
||
$entity: 'deposit',
|
||
data: {
|
||
id: 1,
|
||
iState: 1,
|
||
}
|
||
}
|
||
},
|
||
filter: {
|
||
id,
|
||
}
|
||
}, {});
|
||
const { type } = ship;
|
||
if (type === 'virtual') {
|
||
await context.operate('ship', {
|
||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||
action: 'ship',
|
||
data: {},
|
||
filter: {
|
||
id,
|
||
}
|
||
}, option);
|
||
}
|
||
}
|
||
return;
|
||
},
|
||
},
|
||
{
|
||
entity: 'ship',
|
||
name: '当虚拟的ship变为shipping状态时,调用小程序发货信息录入接口',
|
||
action: 'ship',
|
||
when: 'before',
|
||
asRoot: true,
|
||
priority: 99,
|
||
fn: async ({ operation }, context) => {
|
||
const { data, filter } = operation;
|
||
const [ship] = await context.select('ship', {
|
||
data: {
|
||
id: 1,
|
||
type: 1,
|
||
deposit$ship: {
|
||
$entity: 'deposit',
|
||
data: {
|
||
id: 1,
|
||
pay$deposit: {
|
||
$entity: 'pay',
|
||
data: {
|
||
id: 1,
|
||
entity: 1,
|
||
entityId: 1,
|
||
meta: 1,
|
||
applicationId: 1,
|
||
},
|
||
filter: {
|
||
iState: 'paid',
|
||
},
|
||
indexFrom: 0,
|
||
count: 1,
|
||
}
|
||
},
|
||
indexFrom: 0,
|
||
count: 1,
|
||
}
|
||
},
|
||
filter,
|
||
}, {});
|
||
const { type, deposit$ship: deposits } = ship || {};
|
||
if (type === 'virtual') {
|
||
const deposit = deposits?.[0];
|
||
const result = await (0, ship_1.uploadShippingInfo)({ depositId: deposit?.id, }, context);
|
||
if (result) {
|
||
return 1;
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
},
|
||
{
|
||
entity: 'ship',
|
||
name: '当ship状态发生变化时,尝试向订阅者推送',
|
||
action: ['ship', 'receive', 'giveUp', 'reject'],
|
||
when: 'after',
|
||
fn: async ({ operation }, context, option) => {
|
||
const { filter, id } = operation;
|
||
const { id: shipId } = filter;
|
||
if (shipId) {
|
||
context.saveOperationToEvent(id, `${constants_1.DATA_SUBSCRIBER_KEYS.shipStateChanged}-${shipId}`);
|
||
}
|
||
return 1;
|
||
}
|
||
}
|
||
];
|
||
exports.default = triggers;
|