feat(finance): 完成财务控制、L1 钱包硬化与迁移收敛
- P0/P1:影子总账追加调整、关账/退款/资金/积分幂等、成本版本追溯、对账订单项维度 - 迁移收敛:原 103–114 合并为 103_finance_foundation、104_finance_controls、105_work_order_consignment - 数据:L1 钱包 BIGINT/CHECK/奖励幂等;重复奖励审计口径修正与人工核对清单 - 报表:销售毛利缺失成本收入提示,旧收支页明确现金流口径 - 文档:同步迁移基线、合并评估、代码复核与上线说明
This commit is contained in:
@@ -178,6 +178,7 @@ export async function grantPlatformCredit(payload: JsonObject, session: AdminSes
|
||||
const quantity = normalizePositiveQuantity(payload.quantity)
|
||||
const platformRef = optionalText(payload.platformRef ?? payload.platform_ref, 100)
|
||||
const note = optionalText(payload.note, 300)
|
||||
const requestId = optionalText(payload.requestId ?? payload.request_id, 80)
|
||||
|
||||
const unitPrices = await loadUnitPrices()
|
||||
const unitPriceFen = unitPrices[platformKey]
|
||||
@@ -194,16 +195,36 @@ export async function grantPlatformCredit(payload: JsonObject, session: AdminSes
|
||||
WHERE id = $1`,
|
||||
[account.id, nextBalance, now],
|
||||
)
|
||||
const entryResult = await client.query<CreditEntryRow>(
|
||||
`
|
||||
INSERT INTO platform_credit_entries (
|
||||
account_id, entry_type, quantity_delta, balance_after, amount_fen,
|
||||
platform_ref, note, created_at
|
||||
) VALUES ($1, 'grant', $2, $3, $4, $5, $6, $7)
|
||||
RETURNING *
|
||||
`,
|
||||
[account.id, quantity, nextBalance, quantity * unitPriceFen, platformRef, note, now],
|
||||
)
|
||||
let entryResult
|
||||
try {
|
||||
entryResult = await client.query<CreditEntryRow>(
|
||||
`
|
||||
INSERT INTO platform_credit_entries (
|
||||
account_id, entry_type, quantity_delta, balance_after, amount_fen,
|
||||
platform_ref, note, request_id, created_at
|
||||
) VALUES ($1, 'grant', $2, $3, $4, $5, $6, $7, $8)
|
||||
RETURNING *
|
||||
`,
|
||||
[
|
||||
account.id,
|
||||
quantity,
|
||||
nextBalance,
|
||||
quantity * unitPriceFen,
|
||||
platformRef,
|
||||
note,
|
||||
requestId,
|
||||
now,
|
||||
],
|
||||
)
|
||||
} catch (error) {
|
||||
if ((error as { code?: string }).code === '23505') {
|
||||
throw createHttpError('该请求已处理,请勿重复提交', {
|
||||
statusCode: 409,
|
||||
errorCode: 'platform_credit_request_duplicate',
|
||||
})
|
||||
}
|
||||
throw error
|
||||
}
|
||||
return {
|
||||
accountId: Number(account.id),
|
||||
platformKey,
|
||||
@@ -236,6 +257,7 @@ export async function adjustPlatformCredit(payload: JsonObject, session: AdminSe
|
||||
errorCode: 'platform_credit_adjust_note_required',
|
||||
})
|
||||
}
|
||||
const requestId = optionalText(payload.requestId ?? payload.request_id, 80)
|
||||
const unitPrices = await loadUnitPrices()
|
||||
const unitPriceFen = unitPrices[platformKey]
|
||||
const now = nowIso()
|
||||
@@ -256,16 +278,27 @@ export async function adjustPlatformCredit(payload: JsonObject, session: AdminSe
|
||||
WHERE id = $1`,
|
||||
[account.id, nextBalance, now],
|
||||
)
|
||||
const entryResult = await client.query<CreditEntryRow>(
|
||||
`
|
||||
INSERT INTO platform_credit_entries (
|
||||
account_id, entry_type, quantity_delta, balance_after, amount_fen,
|
||||
note, created_at
|
||||
) VALUES ($1, 'adjust', $2, $3, $4, $5, $6)
|
||||
RETURNING *
|
||||
`,
|
||||
[account.id, quantity, nextBalance, quantity * unitPriceFen, note, now],
|
||||
)
|
||||
let entryResult
|
||||
try {
|
||||
entryResult = await client.query<CreditEntryRow>(
|
||||
`
|
||||
INSERT INTO platform_credit_entries (
|
||||
account_id, entry_type, quantity_delta, balance_after, amount_fen,
|
||||
note, request_id, created_at
|
||||
) VALUES ($1, 'adjust', $2, $3, $4, $5, $6, $7)
|
||||
RETURNING *
|
||||
`,
|
||||
[account.id, quantity, nextBalance, quantity * unitPriceFen, note, requestId, now],
|
||||
)
|
||||
} catch (error) {
|
||||
if ((error as { code?: string }).code === '23505') {
|
||||
throw createHttpError('该请求已处理,请勿重复提交', {
|
||||
statusCode: 409,
|
||||
errorCode: 'platform_credit_request_duplicate',
|
||||
})
|
||||
}
|
||||
throw error
|
||||
}
|
||||
return {
|
||||
accountId: Number(account.id),
|
||||
platformKey,
|
||||
|
||||
Reference in New Issue
Block a user