feat: 新增交通银行数据导出插件及测试通道机制

This commit is contained in:
2026-11-05 15:20:34 +08:00
parent b976b80d9d
commit 4e8b3e7d43
230 changed files with 19827 additions and 1440 deletions
@@ -27,6 +27,54 @@ PASSPORT_HINTS = ( # 统一登录/账号域
# 登录票据 Cookie:名字带分区后缀 `_ls`(老版本/无分区时是裸名),按前缀匹配
SESSION_COOKIE_PREFIXES = ('sessionid', 'sid_tt', 'sid_guard', 'sid_ucp')
# ==================== 多公司(同一来客账号下可切换的「公司/门店账号」) ====================
# 实测(2026-11-05):切换公司 = 打开带 `groupid=<公司account_id>` 的页面,
# 之后同页发出的业务接口就按该公司返回(导出接口自身只带 root_life_account_id,靠页面上下文定公司)。
# 平台导出的文件名**不含公司名**,两家同名会互相覆盖,所以除台账那家外用 file_prefix 区分。
# ledger=True 的那家:文件名保持平台原名(台账合并按 `核销明细*.xlsx` 找明细,加前缀就找不到);
# ledger=False 的那家:文件名加简称前缀,既避免覆盖,也天然被台账 glob 排除。
COMPANIES = (
{'id': '1732612560882691', 'short': '金色印象',
'name': '重庆金色印象营销策划有限公司', 'file_prefix': '', 'ledger': True},
{'id': '1738783659418632', 'short': '金色湖畔',
'name': '重庆金色湖畔酒店管理有限公司', 'file_prefix': '金色湖畔_', 'ledger': False},
)
def get_company(company_id):
"""按 account_id 取公司配置;未知 id 返回 None。"""
cid = str(company_id or '').strip()
return next((dict(c) for c in COMPANIES if c['id'] == cid), None)
def default_company_ids():
return [c['id'] for c in COMPANIES]
# ==================== 执行模式 ====================
# export_only:仅导出(COMPANIES 全部,含湖畔),不并台账、不补核对表;
# full:含写表(只导 ledger=True 的金色印象),导出后并台账 + 补核对表取数。
RUN_MODE_EXPORT_ONLY = 'export_only'
RUN_MODE_FULL = 'full'
RUN_MODE_EXPORT_ONLY_ALIASES = ('export_only', 'export', '仅导出', '只导出')
RUN_MODE_FULL_ALIASES = ('full', 'write', '含写表', '写表', '完整')
def normalize_run_mode(raw):
"""执行模式归一:未配置/未知 → 含写表(保持历史行为)。"""
text = str(raw or '').strip().lower()
if text in RUN_MODE_EXPORT_ONLY_ALIASES:
return RUN_MODE_EXPORT_ONLY
return RUN_MODE_FULL
def companies_for_mode(mode):
"""模式 → 要导出的公司列表:仅导出=全部公司;含写表=只导台账那家。"""
if normalize_run_mode(mode) == RUN_MODE_EXPORT_ONLY:
return [dict(c) for c in COMPANIES]
picked = [dict(c) for c in COMPANIES if c.get('ledger')]
return picked or [dict(COMPANIES[0])]
# 票据候选(子串匹配,仅用于日志摘要)与埋点排除项
TICKET_KEY_HINTS = ('session', 'sid', 'token', 'ticket', 'userid', 'user_id')
IGNORE_KEY_HINTS = (
@@ -98,6 +146,36 @@ DATA_START_ROW = 2
FORMULA_SKIP_COLS = ('CC',) # 不随行下拉的公式列(业务口径:CC 不管)
NUM_TYPE_SAMPLE = 30 # 判断某列写数值还是文本时参考的末行样本数
# ==================== 导出字段(默认 / 自定义) ====================
# 实测(2026-11-05):导出字段不是随导出请求传的,而是**账号级设置**:
# 1) POST download/get_field_config → data.download_field_list(分组字段目录)
# 2) POST download/sve_field_config → 保存 select_keys / un_select_keys(写该账号的场景配置)
# 3) 导出时只传 download_field_option:1=平台默认字段,2=用上面保存的自定义字段
# 字段目录见 config/export_fields.py(option_type 1=系统默认必选 / 2=默认勾选 / 3=可选)。
FIELD_CONFIG_API = ('https://life.douyin.com/life/trade_view/v1/download/get_field_config')
FIELD_SAVE_API = ('https://life.douyin.com/life/trade_view/v1/download/sve_field_config')
FIELD_SCENE = {'version': 'management',
'view_type': VERIFY_VIEW_TYPE,
'view_function': 'download'}
FIELD_MODE_PRESET = 'preset' # 推荐字段:平台默认 72 列 + 台账需要的 4 列(走 option=2)
FIELD_MODE_DEFAULT = 'default' # 平台默认字段(option=1,实测缺核销门店省份/核销人昵称/核销人ID/保险费用)
FIELD_MODE_CUSTOM = 'custom' # 用户勾选(会写入该账号的导出字段设置)
FIELD_MODE_CUSTOM_ALIASES = ('custom', '自定义', '自定义字段', '自定义勾选', 'self')
FIELD_MODE_DEFAULT_ALIASES = ('default', '平台默认', '平台默认字段')
FIELD_MODE_PRESET_ALIASES = ('preset', '推荐', '推荐字段', '预置')
def normalize_field_mode(raw):
"""字段方案归一:空/未知 → 推荐字段(避免默认导出漏台账列);其余按别名匹配。"""
text = str(raw or '').strip().lower()
if text in FIELD_MODE_CUSTOM_ALIASES:
return FIELD_MODE_CUSTOM
if text in FIELD_MODE_DEFAULT_ALIASES:
return FIELD_MODE_DEFAULT
return FIELD_MODE_PRESET
# 台账合并必需列:明细表头名 → 平台 field_key;自定义时缺了会自动补回,否则并入台账会静默丢数据
LEDGER_REQUIRED_FIELDS = ((TIME_COL, 'verify_time_str'), ('订单编号', 'shop_order_id'))
# ==================== 核对表取数链接(抖音到账核对) ====================
# 「抖音到账核对」整行都是外部工作簿取数(与 xq0041 新美大核对统计同源,同一份共享总表):
# O = [n]资金组取数!$B$24 应收岗-团购统计表-昨日遗留 (E)
@@ -109,6 +187,7 @@ NUM_TYPE_SAMPLE = 30 # 判断某列写数值还是文本时参
# 其余行仍是 [1](9.1 的文件),所以要按日期重写(已是目标链接的行原样保留,含缓存值)。
# 列不写死:stat_links 扫整行所有 `[n]资金组取数!` 公式,把 [n] 换成该行日期的编号。
STAT_SHEET = '抖音到账核对'
SHARE_ROOT = r'\\caiwu01\共享文件夹\1111\TG'
LINK_BOOK = '马敏团购总表'
LINK_SHEET = '资金组取数'
@@ -0,0 +1,169 @@
# -*- coding: utf-8 -*-
"""核销明细导出字段目录(平台 get_field_config 实测,2026-11-05)。
option_type:1=系统默认(必选、不可改);2=默认勾选(可取消);3=可选(多数默认不勾)。
is_default:平台当前默认是否勾选(用户切到「自定义字段」时的预勾选)。
导出用 field_key;field_name 仅用于界面展示与日志。
平台增删字段后重新跑一次抓取脚本再生成本文件(未知 key 后端会告警但照传)。
"""
FIELD_GROUPS = (
{
"value": "order_info",
"label": "订单基础信息",
"fields": (
{"key": "shop_order_id", "name": "订单编号", "option_type": 1, "is_default": True},
{"key": "order_tags", "name": "订单标签", "option_type": 1, "is_default": True},
{"key": "create_time", "name": "下单时间", "option_type": 1, "is_default": True},
{"key": "pay_time", "name": "支付时间", "option_type": 1, "is_default": True},
{"key": "deposit_pay_time", "name": "订金支付时间", "option_type": 3, "is_default": False},
{"key": "balance_pay_time", "name": "尾款支付时间", "option_type": 3, "is_default": False},
),
},
{
"value": "verify_info",
"label": "核销信息",
"fields": (
{"key": "verify_id", "name": "核销记录ID", "option_type": 3, "is_default": False},
{"key": "code", "name": "券码(已撤销核销加密)", "option_type": 1, "is_default": True},
{"key": "poi_province", "name": "核销门店省份", "option_type": 3, "is_default": True},
{"key": "poi_city", "name": "核销门店城市", "option_type": 3, "is_default": False},
{"key": "poi_id", "name": "核销门店ID", "option_type": 1, "is_default": True},
{"key": "poi_name", "name": "核销门店", "option_type": 1, "is_default": True},
{"key": "poi_name_remark", "name": "核销门店名称备注", "option_type": 3, "is_default": False},
{"key": "poi_id_remark", "name": "核销门店编号备注", "option_type": 3, "is_default": False},
{"key": "verify_status", "name": "核销状态", "option_type": 1, "is_default": True},
{"key": "verifier_account", "name": "核销人账号", "option_type": 3, "is_default": False},
{"key": "verifier_name", "name": "核销人昵称", "option_type": 3, "is_default": True},
{"key": "verifier_id", "name": "核销人ID", "option_type": 3, "is_default": True},
{"key": "fulfil_type_str", "name": "核销方式", "option_type": 3, "is_default": False},
{"key": "verify_time_str", "name": "核销时间", "option_type": 1, "is_default": True},
{"key": "use_complete_time_str", "name": "使用完成时间", "option_type": 1, "is_default": True},
{"key": "cancel_time_str", "name": "撤销核销时间", "option_type": 2, "is_default": True},
{"key": "external_good_id", "name": "外部货号", "option_type": 3, "is_default": False},
{"key": "merchant_remark", "name": "商家备注", "option_type": 3, "is_default": False},
{"key": "write_off_gift", "name": "赠品信息", "option_type": 2, "is_default": True},
),
},
{
"value": "product_info",
"label": "商品信息",
"fields": (
{"key": "product_name", "name": "商品名称", "option_type": 1, "is_default": True},
{"key": "product_type_name", "name": "商品类型", "option_type": 1, "is_default": True},
{"key": "product_id", "name": "商品ID", "option_type": 1, "is_default": True},
{"key": "category_name", "name": "商品类目", "option_type": 2, "is_default": True},
{"key": "product_owner_type", "name": "商品归属", "option_type": 3, "is_default": False},
{"key": "product_owner_account_name", "name": "商品归属商户", "option_type": 1, "is_default": True},
{"key": "product_owner_account_id", "name": "商品归属商户ID", "option_type": 1, "is_default": True},
{"key": "item_num", "name": "购买数量", "option_type": 1, "is_default": True},
{"key": "product_sale_currency", "name": "商品售价币种", "option_type": 3, "is_default": False},
{"key": "product_actual_amount", "name": "商品售价(单价)", "option_type": 1, "is_default": True},
{"key": "product_origin_amount", "name": "用户侧划线价", "option_type": 2, "is_default": True},
{"key": "once_origin_amount", "name": "单次划线价", "option_type": 3, "is_default": False},
{"key": "voucher_verify_info", "name": "代金券面额", "option_type": 3, "is_default": False},
{"key": "combo_product_name", "name": "组合商品名称", "option_type": 3, "is_default": False},
{"key": "combo_product_amount", "name": "组合商品价格", "option_type": 3, "is_default": False},
{"key": "sale_specs", "name": "商品规格", "option_type": 1, "is_default": True},
),
},
{
"value": "amount_info",
"label": "券金额信息",
"fields": (
{"key": "pay_amount_currency", "name": "用户实付币种", "option_type": 2, "is_default": True},
{"key": "pay_amount_str", "name": "用户实付", "option_type": 1, "is_default": True},
{"key": "payment_amount_currency", "name": "订单实收币种", "option_type": 2, "is_default": True},
{"key": "payment_amount", "name": "订单实收", "option_type": 1, "is_default": True},
{"key": "deposit_pay_amount", "name": "订金实付金额", "option_type": 3, "is_default": False},
{"key": "balance_pay_amount", "name": "尾款实付金额", "option_type": 3, "is_default": False},
{"key": "merchant_amount_currency", "name": "预计收入币种", "option_type": 2, "is_default": True},
{"key": "merchant_amount", "name": "预计收入", "option_type": 2, "is_default": True},
{"key": "purchase_fee", "name": "采购价", "option_type": 3, "is_default": False},
{"key": "benefit_verify_amount", "name": "惠享卡核销金额", "option_type": 3, "is_default": False},
{"key": "benefit_left_principal_amount", "name": "惠享卡本金核销余额", "option_type": 3, "is_default": False},
{"key": "benefit_left_benefit_amount", "name": "惠享卡赠送金核销余额", "option_type": 3, "is_default": False},
{"key": "merchant_funder_discount", "name": "代商家出资补贴", "option_type": 2, "is_default": True},
{"key": "merchant_discount_detail", "name": "商家补贴优惠明细", "option_type": 1, "is_default": True},
{"key": "merchant_discount_amount2", "name": "商家货款补贴", "option_type": 2, "is_default": True},
{"key": "pay_discount", "name": "抖音支付优惠", "option_type": 2, "is_default": True},
{"key": "platform_discount_amount", "name": "平台补贴", "option_type": 2, "is_default": True},
{"key": "platform_discount_detail", "name": "平台补贴优惠明细", "option_type": 2, "is_default": True},
{"key": "brand_discount_amount", "name": "品牌商补贴", "option_type": 2, "is_default": True},
{"key": "brand_discount_detail", "name": "品牌商补贴优惠明细", "option_type": 2, "is_default": True},
{"key": "provider_discount_amount", "name": "服务商补贴", "option_type": 2, "is_default": True},
{"key": "provider_discount_detail", "name": "服务商补贴优惠明细", "option_type": 2, "is_default": True},
{"key": "government_voucher_discount_amount", "name": "政府补贴", "option_type": 2, "is_default": True},
{"key": "government_voucher_discount_detail", "name": "政府补贴优惠明细", "option_type": 2, "is_default": True},
{"key": "combined_hote_sale_price", "name": "酒店房价", "option_type": 3, "is_default": False},
{"key": "combined_scenic_sale_price", "name": "景区分销金额", "option_type": 3, "is_default": False},
{"key": "commission_base", "name": "各类服务费率基数", "option_type": 2, "is_default": True},
{"key": "platform_service_amount", "name": "软件服务费", "option_type": 2, "is_default": True},
{"key": "platform_service_rate", "name": "软件服务费率", "option_type": 2, "is_default": True},
{"key": "ybq_fee", "name": "出单宝托管服务费", "option_type": 2, "is_default": False},
{"key": "ybq_fee_rate", "name": "出单宝托管服务费率", "option_type": 2, "is_default": False},
{"key": "ybq_platform_fee", "name": "平台费用抵扣", "option_type": 2, "is_default": False},
{"key": "handling_fee_amount", "name": "支付手续费(已含在软件服务费中)", "option_type": 2, "is_default": True},
{"key": "handling_fee_rate", "name": "支付手续费费率", "option_type": 2, "is_default": True},
{"key": "talent_commission_amount", "name": "达人服务费", "option_type": 2, "is_default": True},
{"key": "talent_commission_rate", "name": "达人服务费比例", "option_type": 2, "is_default": True},
{"key": "craftsman_commission_amount", "name": "职人激励金", "option_type": 2, "is_default": True},
{"key": "craftsman_commission_rate", "name": "职人激励金比例", "option_type": 2, "is_default": True},
{"key": "broker_commission_amount", "name": "团长服务费", "option_type": 2, "is_default": True},
{"key": "agent_commission_amount", "name": "服务商服务费", "option_type": 2, "is_default": True},
{"key": "agent_commission_rate", "name": "服务商服务费比例", "option_type": 2, "is_default": True},
{"key": "agent_account_name", "name": "服务商名称", "option_type": 2, "is_default": True},
{"key": "insurance_commission_amount", "name": "保险费用", "option_type": 3, "is_default": True},
{"key": "welfare_donation", "name": "公益捐赠", "option_type": 3, "is_default": False},
{"key": "clerk_commission_amount", "name": "店员激励金", "option_type": 2, "is_default": True},
{"key": "clerk_commission_rate", "name": "店员激励金比例", "option_type": 2, "is_default": True},
{"key": "month_pay_interest", "name": "月付贴息", "option_type": 2, "is_default": True},
{"key": "zlb_promotion_fee", "name": "增量宝", "option_type": 2, "is_default": True},
{"key": "content_production_fee", "name": "AIGC 服务费", "option_type": 2, "is_default": False},
),
},
{
"value": "channel_info",
"label": "渠道信息",
"fields": (
{"key": "sale_channel", "name": "成交渠道", "option_type": 2, "is_default": True},
{"key": "app_source", "name": "下单来源", "option_type": 2, "is_default": True},
{"key": "media_url", "name": "内容地址", "option_type": 3, "is_default": False},
{"key": "sale_role", "name": "带货角色", "option_type": 2, "is_default": True},
{"key": "sale_user_nickname", "name": "带货人", "option_type": 2, "is_default": True},
{"key": "transform_nickname", "name": "订单归属人昵称(字段如果获取不到就默认展示商家,如对账以账单为主)", "option_type": 2, "is_default": True},
{"key": "transform_uid", "name": "订单归属人uid", "option_type": 2, "is_default": True},
{"key": "talent_aweme_nickname", "name": "达人昵称", "option_type": 2, "is_default": True},
{"key": "talent_aweme_unique_id", "name": "达人抖音号", "option_type": 2, "is_default": True},
{"key": "talent_aweme_uid", "name": "达人uid", "option_type": 2, "is_default": True},
{"key": "craftsman_aweme_nickname", "name": "职人昵称", "option_type": 3, "is_default": False},
{"key": "craftsman_aweme_unique_id", "name": "职人抖音号", "option_type": 3, "is_default": False},
{"key": "craftsman_aweme_uid", "name": "职人uid", "option_type": 3, "is_default": False},
{"key": "clerk_aweme_nickname", "name": "店员昵称", "option_type": 3, "is_default": False},
{"key": "clerk__aweme_unique_id", "name": "店员抖音号", "option_type": 3, "is_default": False},
{"key": "clerk_aweme_uid", "name": "店员uid", "option_type": 3, "is_default": False},
),
},
{
"value": "pick_up_info",
"label": "提货信息",
"fields": (
{"key": "pick_up_spec", "name": "提货规格", "option_type": 2, "is_default": True},
{"key": "pick_up_validate_end_time", "name": "提货截止时间", "option_type": 2, "is_default": True},
),
},
)
def _all():
for group in FIELD_GROUPS:
for item in group["fields"]:
yield item
LOCKED_KEYS = tuple(i["key"] for i in _all() if i["option_type"] == 1)
DEFAULT_KEYS = tuple(i["key"] for i in _all()
if i["option_type"] in (1, 2) or i["is_default"])
ALL_KEYS = tuple(i["key"] for i in _all())
NAME_BY_KEY = {i["key"]: i["name"] for i in _all()}
TYPE_BY_KEY = {i["key"]: i["option_type"] for i in _all()}