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
+1 -1
View File
@@ -258,7 +258,7 @@ export default function WineryBillsPage() {
</Typography.Title>
<Typography.Text type="secondary">
8:00 × {ratePct}%绿
T+3 8:00 3 / × {ratePct}%绿
</Typography.Text>
</Space>
{canEditWineryBank ? (
+1 -1
View File
@@ -183,7 +183,7 @@ export const STORE_SETTLEMENT_DEFAULT_RATE = 0.6;
/** 酒厂账单结算比例(酒单实付 × 比例),暂定 30% */
export const WINERY_SETTLEMENT_RATE = 0.3;
/** 酒厂账单出账滞后自然日(T+3:支付日 + 3 天后纳入账单) */
/** 酒厂账单出账滞后自然日(T+3:订单完成日 + 3 天后纳入账单) */
export const WINERY_SETTLEMENT_LAG_DAYS = 3;
export type { LogisticsSettlementMethod } from './enums';
@@ -5,7 +5,7 @@ import { AlertService } from '../common/alert/alert.service';
/**
* 财务对账单定时任务(Asia/Shanghai
* - 每日 08:00:酒厂日账单 + 门店日账单(统计昨日 00:00~今日 00:00
* - 每日 08:00:酒厂日账单(T+3:3 天前已完成订单)+ 门店日账单(昨日核销
* - 每月 1 日 08:00:合伙人上一自然月账单 + 物流承运商上一自然月对账
* - 工作日 18:05:门店提现 T+0 审完预警(FIN-003
*/
@@ -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!,
})),
});
}