"""客户权益目录种子:把《高净值客户服务规范》的权益转成表数据。 数据源:`knowledge/product/高净值客户服务规范.md` 第二章「各层级专属权益」。 **逐条照抄文档**,不改写、不新增文档里没有的权益。 执行: python -X utf8 -m tools.seed_customer_benefits 幂等:按 `benefit_code` 先查后插;已存在的**不覆盖**(避免把人工调整冲掉)。 ## 两处刻意的处理 1. **私行那条"7×24 小时私人银行专线:400-XXX-XXXX 转 8" 不写号码**。 文档里是占位符,而项目已有明确口径:对客号码的唯一来源是 `app/core/customer_service_rules.py` 的 `CONTACT_PHONE` (本线此前修过"同一客服给客户两个不同号码"的缺陷,见 `docs/37` §6.3 的 A1)。 把占位符抄进库,等于又造了第二份假号码。故只保留权益名称与说明。 2. **权益按层级累积分组**:文档每层都写"含全部下级权益,新增以下"。 表里**只存该层新增的条目**,累积展开由 `CustomerBenefitService.tier_chain()` 完成 —— 否则同一条权益要在多个层级重复存,改一处漏三处。 """ from __future__ import annotations import asyncio import sys from datetime import UTC, datetime from sqlalchemy import select from app.infrastructure.db import SessionFactory from app.model.benefit import CustomerBenefit #: (层级, 类别, 名称, 说明);display_order 按此列表顺序自动编号。 #: 层级顺序 gold → platinum → diamond → private = 累积顺序。 BENEFITS: tuple[tuple[str, str, str, str], ...] = ( # ---- 金卡(50 万+)---- ("gold", "financial", "专属理财经理服务", "由理财经理提供专属服务(1:N,N≤300)"), ("gold", "financial", "基金申购费率 5 折优惠", "高于普通客户的 1 折优惠"), ("gold", "financial", "银行理财专属高收益产品", "较公开产品收益高 10-20BP"), ("gold", "financial", "每月 1 次免费资产配置报告", "每月可获取一次资产配置报告"), ("gold", "financial", "优先认购热门基金产品", "热门基金产品优先认购"), ("gold", "non_financial", "生日祝福礼遇", "精美礼品一份"), ("gold", "non_financial", "节日关怀", "春节、中秋礼品卡"), ("gold", "non_financial", "APP 金卡专属标识", "客户端展示金卡专属标识"), ("gold", "non_financial", "财富中心 VIP 区域使用", "可使用财富中心 VIP 区域"), # ---- 白金(200 万+,含全部金卡权益)---- ("platinum", "financial", "1 对 1 高级理财经理服务", "由高级理财经理提供 1 对 1 服务(N≤150)"), ("platinum", "financial", "基金申购费率 3 折优惠", "较金卡的 5 折进一步优惠"), ("platinum", "financial", "每季度 1 次投资策略会/市场研判会", "每季度参与资格一次"), ("platinum", "financial", "专属理财产品", "白金客户专享,年化收益较普通产品高 20-30BP"), ("platinum", "financial", "私募产品优先认购权", "私募产品优先认购"), ("platinum", "financial", "基金投顾服务费 8 折优惠", "投顾服务费 8 折"), ("platinum", "non_financial", "每年 2 次高端客户沙龙", "品酒、艺术品鉴赏等"), ("platinum", "non_financial", "三甲医院专家门诊预约", "每年 2 次"), ("platinum", "non_financial", "机场贵宾厅服务", "每年 6 次"), ("platinum", "non_financial", "高尔夫球场预约优惠", "合作球场 8 折"), ("platinum", "non_financial", "子女留学规划咨询", "合作机构免费 1 次"), # ---- 钻石(600 万+,含全部白金权益)---- ("diamond", "financial", "资深客户经理 1 对 1 专属服务", "由资深客户经理提供(N≤80)"), ("diamond", "financial", "基金申购费率 2 折优惠", "较白金的 3 折进一步优惠"), ("diamond", "financial", "家族办公室初步服务对接", "家族办公室服务初步对接"), ("diamond", "financial", "全球资产配置咨询", "全球范围资产配置咨询"), ("diamond", "financial", "私募产品优先配置权", "含稀缺额度"), ("diamond", "financial", "定制化投资报告", "月度/季度定制报告"), ("diamond", "financial", "税务筹划初步咨询", "每年 1 次"), ("diamond", "non_financial", "高端健康管理", "年度全面体检套餐"), ("diamond", "non_financial", "每年 4 次高端客户活动", "米其林晚宴、私人音乐会等"), ("diamond", "non_financial", "全球紧急救援服务", "全球范围紧急救援"), ("diamond", "non_financial", "机场专车接送服务", "每年 8 次"), ("diamond", "non_financial", "高端酒店会员权益", "合作五星级酒店 VIP 待遇"), ("diamond", "non_financial", "子女实习/就业推荐", "合作企业资源对接"), # ---- 私行(1000 万+,含全部钻石权益)---- ("private", "financial", "私人银行家 1 对 1 专属服务", "由私人银行家提供(N≤40)"), ("private", "financial", "基金申购费率 1 折优惠", "最低费率档"), ("private", "financial", "家族信托设立与管理服务", "家族信托全流程服务"), ("private", "financial", "家族办公室全方位服务", "家族办公室全方位服务"), ("private", "financial", "全球资产配置方案", "含海外置业、移民咨询"), ("private", "financial", "专属投委会成员定期沟通", "与投委会成员定期沟通"), ("private", "financial", "私募股权/创投基金认购权", "私募股权与创投基金认购"), ("private", "financial", "企业融资顾问服务", "免费提供"), ("private", "financial", "定制化资产配置白皮书", "年度"), ("private", "financial", "税务筹划与遗产规划", "CFA/CTA 专家服务"), ("private", "financial", "艺术品投资咨询", "艺术品投资咨询"), ("private", "financial", "专属理财产品定制", "单户可定制产品方案"), # ⚠️ 文档原文为「7×24 小时私人银行专线:400-XXX-XXXX 转 8」—— # 号码是占位符,此处**只保留权益名**,号码一律走 customer_service_rules.CONTACT_PHONE。 ("private", "non_financial", "7×24 小时私人银行专线", "全天候私人银行专线(号码统一由客服热线配置提供)"), ("private", "non_financial", "私人银行家上门服务", "每月至少 1 次"), ("private", "non_financial", "全球顶尖医疗资源对接", "全球医疗资源对接"), ("private", "non_financial", "机场贵宾厅及专车接送不限次", "每年不限次"), ("private", "non_financial", "私人飞机/游艇租赁服务", "合作供应商优惠价"), ("private", "non_financial", "高端社交圈层活动", "南方私行俱乐部年会、海外游学"), ("private", "non_financial", "家族传承规划", "法律、税务、治理综合方案"), ("private", "non_financial", "公益慈善顾问服务", "慈善顾问服务"), ("private", "non_financial", "奢侈品鉴赏", "珠宝、名表、红酒私人顾问"), ) def _code(tier: str, index: int) -> str: return f"tier:{tier}:{index:02d}" async def seed() -> int: now = datetime.now(UTC).replace(tzinfo=None) inserted = 0 async with SessionFactory() as session: existing = set(await session.scalars(select(CustomerBenefit.benefit_code))) order_by_tier: dict[str, int] = {} for tier, category, name, description in BENEFITS: order_by_tier[tier] = order_by_tier.get(tier, 0) + 1 code = _code(tier, order_by_tier[tier]) if code in existing: continue session.add(CustomerBenefit( benefit_code=code, customer_tier=tier, category=category, name=name, description=description, display_order=order_by_tier[tier], status="active", created_at=now, updated_at=now, )) inserted += 1 await session.commit() return inserted async def main() -> None: inserted = await seed() async with SessionFactory() as session: rows = (await session.execute( select(CustomerBenefit.customer_tier, CustomerBenefit.category) )).all() per_tier: dict[str, int] = {} for tier, _category in rows: per_tier[tier] = per_tier.get(tier, 0) + 1 print(f"新增 {inserted} 条;库中现有 {len(rows)} 条:") for tier, _label in (("gold", "金卡"), ("platinum", "白金"), ("diamond", "钻石"), ("private", "私行")): print(f" {tier:9} {_label} {per_tier.get(tier, 0)} 条") if __name__ == "__main__": sys.stdout.reconfigure(encoding="utf-8") asyncio.run(main())