fix(orders): 订单项替换统一分摊收入

This commit is contained in:
yml2213
2026-11-06 17:27:19 +08:00
parent df7f651542
commit 91e0bc8c9a
2 changed files with 33 additions and 3 deletions
@@ -42,9 +42,22 @@ export async function replaceOrderItems(
orderId: number | string,
items: OrderItemReplaceInput[],
): Promise<OrderItemRow[]> {
return withTransaction((client: PoolClient) =>
replaceOrderItemsWithExecutor(client.query.bind(client), orderId, items),
)
return withTransaction(async (client: PoolClient) => {
const executor = client.query.bind(client)
await replaceOrderItemsWithExecutor(executor, orderId, items)
const order = await client.query<{ total_amount: string | number }>(
`SELECT total_amount FROM orders WHERE id = $1`,
[orderId],
)
if (order.rows[0]) {
await applyOrderItemRevenueAllocationWithExecutor(
executor,
orderId,
Number(order.rows[0].total_amount) || 0,
)
}
return listOrderItemsByOrderIdWithExecutor(executor, orderId)
})
}
export async function applyOrderItemRevenueAllocationWithExecutor(