fix(settlement): align winery bill T+3 window to order completedAt

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-05 22:36:51 +08:00
parent 1c4b986924
commit bd1930f6b1
4 changed files with 9 additions and 6 deletions
@@ -1581,13 +1581,15 @@ export class SettlementService {
return { billDate: billDate.toISOString().slice(0, 10), skipped: true, reason: '已打款' };
}
// T+3:纳入「账单日」当天完成的同城/跨城订单(完成日 = 今天 − lagDays)
const orders = await this.prisma.order.findMany({
where: {
status: 'COMPLETED',
payStatus: 'PAID',
deliveryType: { in: ['LOCAL', 'CROSS_CITY'] },
paidAt: { gte: start, lt: end },
completedAt: { gte: start, lt: end },
},
orderBy: { paidAt: 'asc' },
orderBy: { completedAt: 'asc' },
});
if (orders.length === 0 && !existing) {
@@ -1633,7 +1635,8 @@ export class SettlementService {
deliveryType: o.deliveryType,
payAmount: o.payAmount,
wineryAmount: round2(Number(o.payAmount) * rate),
paidAt: o.paidAt!,
// 明细仍保留支付时间;账期窗口按 completedAt 归属
paidAt: o.paidAt ?? o.completedAt!,
})),
});
}