feat: gift card breakdown - migrations, fdw queries, finance recharge task, board-finance page updates
This commit is contained in:
@@ -1906,8 +1906,9 @@ def get_finance_recharge(
|
||||
actual_income → recharge_cash, first_charge → first_recharge_cash,
|
||||
renew_charge → renewal_cash, consumed → 不存在(暂返回 0),
|
||||
card_balance → cash_card_balance, all_card_balance → total_card_balance。
|
||||
赠送卡 3×4 矩阵细分列不存在(无酒水卡/台费卡/抵用券拆分),
|
||||
只有 gift_card_balance 总额,矩阵全部返回 0。
|
||||
CHANGE 2026-07-22 | Prompt: gift-card-breakdown Task 7.1 | 直接原因: SQL 新增 6 个赠送卡细分字段 SUM 聚合
|
||||
新增: gift_liquor_balance, gift_table_fee_balance, gift_voucher_balance,
|
||||
gift_liquor_recharge, gift_table_fee_recharge, gift_voucher_recharge
|
||||
"""
|
||||
with _fdw_context(conn, site_id) as cur:
|
||||
cur.execute(
|
||||
@@ -1917,7 +1918,13 @@ def get_finance_recharge(
|
||||
SUM(renewal_cash) AS renew_charge,
|
||||
SUM(cash_card_balance) AS card_balance,
|
||||
SUM(total_card_balance) AS all_card_balance,
|
||||
SUM(gift_card_balance) AS gift_balance_total
|
||||
SUM(gift_card_balance) AS gift_balance_total,
|
||||
SUM(gift_liquor_balance) AS gift_liquor_balance,
|
||||
SUM(gift_table_fee_balance) AS gift_table_fee_balance,
|
||||
SUM(gift_voucher_balance) AS gift_voucher_balance,
|
||||
SUM(gift_liquor_recharge) AS gift_liquor_recharge,
|
||||
SUM(gift_table_fee_recharge) AS gift_table_fee_recharge,
|
||||
SUM(gift_voucher_recharge) AS gift_voucher_recharge
|
||||
FROM app.v_dws_finance_recharge_summary
|
||||
WHERE stat_date >= %s::date AND stat_date <= %s::date
|
||||
""",
|
||||
@@ -1932,6 +1939,14 @@ def get_finance_recharge(
|
||||
return _empty_recharge_data()
|
||||
|
||||
gift_balance = _f(row[5])
|
||||
# CHANGE 2026-07-22 | Prompt: gift-card-breakdown Task 7.2 | 直接原因: gift_rows 填充真实细分数据
|
||||
gift_liquor_balance = _f(row[6])
|
||||
gift_table_fee_balance = _f(row[7])
|
||||
gift_voucher_balance = _f(row[8])
|
||||
gift_liquor_recharge = _f(row[9])
|
||||
gift_table_fee_recharge = _f(row[10])
|
||||
gift_voucher_recharge = _f(row[11])
|
||||
|
||||
# CHANGE 2026-03-20 | gift_rows 每个 cell 必须是 GiftCell dict({"value": float}),
|
||||
# 不能是裸 float,否则 Pydantic ResponseValidationError
|
||||
_gc = lambda v: {"value": v}
|
||||
@@ -1942,10 +1957,24 @@ def get_finance_recharge(
|
||||
"consumed": 0.0, # 视图无消耗列,暂返回 0
|
||||
"card_balance": _f(row[3]),
|
||||
"gift_rows": [
|
||||
# 赠送卡矩阵:视图无细分列(酒水卡/台费卡/抵用券),全部返回 0
|
||||
{"label": "新增", "total": _gc(0.0), "liquor": _gc(0.0), "table_fee": _gc(0.0), "voucher": _gc(0.0)},
|
||||
{"label": "消费", "total": _gc(0.0), "liquor": _gc(0.0), "table_fee": _gc(0.0), "voucher": _gc(0.0)},
|
||||
{"label": "余额", "total": _gc(gift_balance), "liquor": _gc(0.0), "table_fee": _gc(0.0), "voucher": _gc(0.0)},
|
||||
# 新增行:total = 三个细分之和(保证 total = liquor + table_fee + voucher 恒等)
|
||||
{"label": "新增",
|
||||
"total": _gc(gift_liquor_recharge + gift_table_fee_recharge + gift_voucher_recharge),
|
||||
"liquor": _gc(gift_liquor_recharge),
|
||||
"table_fee": _gc(gift_table_fee_recharge),
|
||||
"voucher": _gc(gift_voucher_recharge)},
|
||||
# 消费行:上游 API 仅提供消费总额,无法按卡类型拆分,细分列保持 0
|
||||
{"label": "消费",
|
||||
"total": _gc(0.0),
|
||||
"liquor": _gc(0.0),
|
||||
"table_fee": _gc(0.0),
|
||||
"voucher": _gc(0.0)},
|
||||
# 余额行:填充对应细分余额
|
||||
{"label": "余额",
|
||||
"total": _gc(gift_balance),
|
||||
"liquor": _gc(gift_liquor_balance),
|
||||
"table_fee": _gc(gift_table_fee_balance),
|
||||
"voucher": _gc(gift_voucher_balance)},
|
||||
],
|
||||
"all_card_balance": _f(row[4]),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user