ship增加了个别trigger

This commit is contained in:
Xu Chang 2025-03-03 19:11:44 +08:00
parent dad12657a3
commit 13bd23414d
9 changed files with 119 additions and 16 deletions

View File

@ -24,10 +24,10 @@ export default OakComponent({
},
isList: false,
properties: {
accountId: '',
accountAvailMax: 0,
accountId: '', // 是否可以使用帐户中的余额抵扣
accountAvailMax: 0, // 本次交易可以使用的帐户中的Avail max值调用者自己保证此数值的一致性不要扣成负数
onSetPays: (pays) => undefined,
accountTips: '',
accountTips: '', // 使用余额支付的提示说明
autoStartPay: false,
},
formData({ data }) {

View File

@ -60,8 +60,8 @@ export const entityDesc = {
},
v: {
iState: {
unshipped: '发货',
shipping: '发货中',
unshipped: '发货',
shipping: '运输中',
received: '已收货',
rejected: '已拒绝',
givenUp: '已放弃',

View File

@ -18,8 +18,8 @@
},
"v": {
"iState": {
"unshipped": "发货",
"shipping": "发货中",
"unshipped": "发货",
"shipping": "运输中",
"received": "已收货",
"rejected": "已拒绝",
"givenUp": "已放弃",

View File

@ -77,6 +77,40 @@ const triggers = [
}
return 1;
}
},
{
name: '当物流创建时将对应的order状态变为已发货',
entity: 'ship',
action: 'create',
when: 'after',
fn: async ({ operation }, context, option) => {
const { data } = operation;
const orders = await context.select('order', {
data: {
id: 1,
gState: 1,
},
filter: {
shipOrder$order: {
shipId: data.id,
}
}
}, { dontCollect: true });
const unshipped = orders.filter(ele => ele.gState === 'unshipped');
if (unshipped.length > 0) {
await context.operate('order', {
id: await generateNewIdAsync(),
action: 'ship',
data: {},
filter: {
id: {
$in: unshipped.map(ele => ele.id),
},
},
}, option);
}
return unshipped.length;
}
}
];
export default triggers;

View File

@ -63,8 +63,8 @@ exports.entityDesc = {
},
v: {
iState: {
unshipped: '发货',
shipping: '发货中',
unshipped: '发货',
shipping: '运输中',
received: '已收货',
rejected: '已拒绝',
givenUp: '已放弃',

View File

@ -18,8 +18,8 @@
},
"v": {
"iState": {
"unshipped": "发货",
"shipping": "发货中",
"unshipped": "发货",
"shipping": "运输中",
"received": "已收货",
"rejected": "已拒绝",
"givenUp": "已放弃",

View File

@ -79,6 +79,40 @@ const triggers = [
}
return 1;
}
},
{
name: '当物流创建时将对应的order状态变为已发货',
entity: 'ship',
action: 'create',
when: 'after',
fn: async ({ operation }, context, option) => {
const { data } = operation;
const orders = await context.select('order', {
data: {
id: 1,
gState: 1,
},
filter: {
shipOrder$order: {
shipId: data.id,
}
}
}, { dontCollect: true });
const unshipped = orders.filter(ele => ele.gState === 'unshipped');
if (unshipped.length > 0) {
await context.operate('order', {
id: await (0, uuid_1.generateNewIdAsync)(),
action: 'ship',
data: {},
filter: {
id: {
$in: unshipped.map(ele => ele.id),
},
},
}, option);
}
return unshipped.length;
}
}
];
exports.default = triggers;

View File

@ -100,8 +100,8 @@ export const entityDesc: EntityDesc<Schema, Action, '', {
},
v: {
iState: {
unshipped: '发货',
shipping: '发货中',
unshipped: '发货',
shipping: '运输中',
received: '已收货',
rejected: '已拒绝',
givenUp: '已放弃',

View File

@ -1,4 +1,4 @@
import { CreateTriggerInTxn, Trigger, UpdateTriggerInTxn } from 'oak-domain/lib/types/Trigger';
import { CreateTrigger, CreateTriggerCrossTxn, CreateTriggerInTxn, Trigger, UpdateTriggerInTxn } from 'oak-domain/lib/types/Trigger';
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
import { EntityDict } from '../oak-app-domain';
import { BRC } from '../types/RuntimeCxt';
@ -30,7 +30,7 @@ const triggers: Trigger<EntityDict, 'ship', BRC>[] = [
}
return;
},
},
} as CreateTriggerCrossTxn<EntityDict, 'ship', BRC>,
{
entity: 'ship',
name: '当虚拟的ship变为shipping状态时调用小程序发货信息录入接口',
@ -84,7 +84,42 @@ const triggers: Trigger<EntityDict, 'ship', BRC>[] = [
}
return 1;
}
} as UpdateTriggerInTxn<EntityDict, 'ship', BRC>
} as UpdateTriggerInTxn<EntityDict, 'ship', BRC>,
{
name: '当物流创建时将对应的order状态变为已发货',
entity: 'ship',
action: 'create',
when: 'after',
fn: async ({ operation }, context, option) => {
const { data } = operation as EntityDict['ship']['CreateSingle'];
const orders = await context.select('order', {
data: {
id: 1,
gState: 1,
},
filter: {
shipOrder$order: {
shipId: data.id,
}
}
}, { dontCollect: true });
const unshipped = orders.filter(ele => ele.gState === 'unshipped');
if (unshipped.length > 0) {
await context.operate('order', {
id: await generateNewIdAsync(),
action: 'ship',
data: {},
filter: {
id: {
$in: unshipped.map(ele => ele.id!),
},
},
}, option);
}
return unshipped.length;
}
} as CreateTrigger<EntityDict, 'ship', BRC>
];
export default triggers;