当物流取消时修改相应的order状态trigger修正

This commit is contained in:
lxy 2025-03-13 14:56:55 +08:00
parent 463f58e6f7
commit bb3fe6cd49
1 changed files with 18 additions and 36 deletions

View File

@ -39,10 +39,10 @@ const triggers: Trigger<EntityDict, 'ship', BRC>[] = [
strict: 'makeSure', strict: 'makeSure',
asRoot: true, asRoot: true,
check: (operation: EntityDict['ship']['CreateSingle']) => ['express'].includes(operation.data.type!), check: (operation: EntityDict['ship']['CreateSingle']) => ['express'].includes(operation.data.type!),
fn: async({ ids }, context, option) => { fn: async ({ ids }, context, option) => {
assert (ids.length === 1); assert(ids.length === 1);
const id = ids[0]; const id = ids[0];
const [ ship ] = await context.select('ship', { const [ship] = await context.select('ship', {
data: { data: {
id: 1, id: 1,
entity: 1, entity: 1,
@ -174,7 +174,7 @@ const triggers: Trigger<EntityDict, 'ship', BRC>[] = [
if (result) { if (result) {
d.entity = result[0]; d.entity = result[0];
d.entityId = result[1]; d.entityId = result[1];
count ++; count++;
} }
} }
} }
@ -185,7 +185,7 @@ const triggers: Trigger<EntityDict, 'ship', BRC>[] = [
if (result) { if (result) {
data.entity = result[0]; data.entity = result[0];
data.entityId = result[1]; data.entityId = result[1];
count ++; count++;
} }
} }
return count; return count;
@ -215,7 +215,7 @@ const triggers: Trigger<EntityDict, 'ship', BRC>[] = [
if (packaged.length > 0) { if (packaged.length > 0) {
await context.operate('order', { await context.operate('order', {
id: await generateNewIdAsync(), id: await generateNewIdAsync(),
action: 'ship', action: 'send',
data: {}, data: {},
filter: { filter: {
id: { id: {
@ -261,34 +261,16 @@ const triggers: Trigger<EntityDict, 'ship', BRC>[] = [
} }
} }
}, { dontCollect: true }); }, { dontCollect: true });
await context.operate('order', {
const packaged = orders.filter(ele => ele.receivingMethod === 'express'); id: await generateNewIdAsync(),
if (packaged.length > 0) { action: 'unship',
await context.operate('order', { data: {},
id: await generateNewIdAsync(), filter: {
action: 'turnBack', id: {
data: {}, $in: orders.map(ele => ele.id!),
filter: {
id: {
$in: packaged.map(ele => ele.id!),
},
}, },
}, option); },
} }, option);
const staged = orders.filter(ele => ele.receivingMethod === 'pickup');
if (staged.length > 0) {
await context.operate('order', {
id: await generateNewIdAsync(),
action: 'cancelTaking',
data: {},
filter: {
id: {
$in: staged.map(ele => ele.id!),
},
},
}, option);
}
assert(staged.length + packaged.length === orders.length);
return orders.length; return orders.length;
} }
} as UpdateTriggerInTxn<EntityDict, 'ship', BRC>, } as UpdateTriggerInTxn<EntityDict, 'ship', BRC>,
@ -308,10 +290,10 @@ const triggers: Trigger<EntityDict, 'ship', BRC>[] = [
$exists: true, $exists: true,
}, },
}, },
fn: async({ ids }, context, option) => { fn: async ({ ids }, context, option) => {
assert (ids.length === 1); assert(ids.length === 1);
const id = ids[0]; const id = ids[0];
const [ ship ] = await context.select('ship', { const [ship] = await context.select('ship', {
data: { data: {
id: 1, id: 1,
entity: 1, entity: 1,