feat: 新增交通银行数据导出插件及测试通道机制
This commit is contained in:
@@ -53,12 +53,35 @@ def _limit(raw, default):
|
||||
return val if val >= config.RECORD_LIMIT_MIN else default
|
||||
|
||||
|
||||
def _field_keys(raw):
|
||||
"""自定义字段入参:兼容 list / 逗号分隔字符串 / 空。去空去重、保序。"""
|
||||
items = [str(x) for x in raw] if isinstance(raw, (list, tuple, set)) else [str(raw or '')]
|
||||
out, seen = [], set()
|
||||
for item in items:
|
||||
for key in item.replace(',', ',').replace(';', ',').split(','):
|
||||
key = key.strip()
|
||||
if key and key not in seen:
|
||||
seen.add(key)
|
||||
out.append(key)
|
||||
return out
|
||||
|
||||
|
||||
def _field_mode(raw):
|
||||
"""字段方案:preset(推荐,默认)/ default(平台默认)/ custom(自己勾)。"""
|
||||
return config.normalize_field_mode(raw)
|
||||
|
||||
|
||||
def _companies(run_mode):
|
||||
"""执行模式 → 公司列表:仅导出=两家都导;含写表=只导台账那家。"""
|
||||
return config.companies_for_mode(run_mode)
|
||||
|
||||
|
||||
class Xq0042Plugin(ScenePlugin):
|
||||
id = 'xq0042'
|
||||
name = '抖音平台核对'
|
||||
version = '0.7.7'
|
||||
description = ('抖音来客数据自动导出:登录后按日期区间导出核销明细、提现记录,'
|
||||
'轮询生成完成后下载到本机目录,核销明细增量并入台账「金色印象--抖音」'
|
||||
version = '0.9.1'
|
||||
description = ('抖音来客数据自动导出:登录后按日期区间导出核销明细(字段可选平台默认或自定义勾选)、'
|
||||
'提现记录,轮询生成完成后下载到本机目录,核销明细增量并入台账「金色印象--抖音」'
|
||||
'(公式列自动下拉),并按日期把「抖音到账核对」整行同源取数公式'
|
||||
'(资金组取数)换成当天共享总表的链接;导出记录超阈值自动删最早的')
|
||||
platform = '' # 插件自带登录(抖音来客 SSO),不用底座共享登录态
|
||||
@@ -72,6 +95,11 @@ class Xq0042Plugin(ScenePlugin):
|
||||
'withdraw_to': {'type': 'string', 'title': '提现时间-结束日期', 'default': ''},
|
||||
'export_verify': {'type': 'boolean', 'title': '导出核销明细', 'default': True},
|
||||
'export_withdraw': {'type': 'boolean', 'title': '导出提现记录', 'default': True},
|
||||
'export_field_mode': {'type': 'string', 'title': '核销明细-导出字段',
|
||||
'default': config.FIELD_MODE_PRESET},
|
||||
'export_fields': {'type': 'array', 'title': '自定义导出字段(field_key)', 'default': []},
|
||||
'run_mode': {'type': 'string', 'title': '执行模式',
|
||||
'default': config.RUN_MODE_FULL},
|
||||
'record_limit_verify': {'type': 'integer', 'title': '核销明细-导出记录保留条数',
|
||||
'default': config.RECORD_LIMIT_VERIFY},
|
||||
'record_limit_withdraw': {'type': 'integer', 'title': '提现记录-导出记录保留条数',
|
||||
@@ -97,8 +125,12 @@ class Xq0042Plugin(ScenePlugin):
|
||||
force = bool(fields.get('force_login'))
|
||||
do_verify = fields.get('export_verify', True) is not False
|
||||
do_withdraw = fields.get('export_withdraw', True) is not False
|
||||
run_merge = fields.get('run_merge', True) is not False
|
||||
run_stat = fields.get('run_stat_links', True) is not False
|
||||
run_mode = config.normalize_run_mode(fields.get('run_mode'))
|
||||
# 仅导出模式:不写表(忽略并入台账/补核对表的勾选)
|
||||
run_merge = (fields.get('run_merge', True) is not False
|
||||
and run_mode != config.RUN_MODE_EXPORT_ONLY)
|
||||
run_stat = (fields.get('run_stat_links', True) is not False
|
||||
and run_mode != config.RUN_MODE_EXPORT_ONLY)
|
||||
dry_run = bool(fields.get('dry_run'))
|
||||
do_download = do_verify or do_withdraw
|
||||
if not do_download and not run_merge and not run_stat:
|
||||
@@ -106,7 +138,12 @@ class Xq0042Plugin(ScenePlugin):
|
||||
'(导出核销明细 / 导出提现记录 / 并入台账 / 补核对表取数)')
|
||||
limit_verify = _limit(fields.get('record_limit_verify'), config.RECORD_LIMIT_VERIFY)
|
||||
limit_withdraw = _limit(fields.get('record_limit_withdraw'), config.RECORD_LIMIT_WITHDRAW)
|
||||
field_mode = _field_mode(fields.get('export_field_mode'))
|
||||
field_keys = _field_keys(fields.get('export_fields'))
|
||||
if field_mode == config.FIELD_MODE_CUSTOM and not field_keys:
|
||||
config.log('自定义字段未勾选,本次按「系统默认字段 + 台账必需列」执行', 'WARN')
|
||||
|
||||
companies = _companies(run_mode)
|
||||
kinds = [k for k, on in (('核销明细', do_verify), ('提现记录', do_withdraw)) if on]
|
||||
ranges = []
|
||||
if do_verify:
|
||||
@@ -115,7 +152,16 @@ class Xq0042Plugin(ScenePlugin):
|
||||
ranges.append(f'提现 {w_from} ~ {w_to}')
|
||||
plan = []
|
||||
if do_download:
|
||||
plan.append(f'导出{"、".join(kinds)}({";".join(ranges)})→ {save_dir}')
|
||||
plan.append(f'导出{"、".join(kinds)}({";".join(ranges)})'
|
||||
f'公司:{"、".join(c.get("short") or c["id"] for c in companies)}'
|
||||
f' → {save_dir}')
|
||||
if do_verify:
|
||||
if field_mode == config.FIELD_MODE_DEFAULT:
|
||||
plan.append('核销明细字段=平台默认字段')
|
||||
elif field_mode == config.FIELD_MODE_PRESET:
|
||||
plan.append('核销明细字段=推荐字段(平台默认+台账列)')
|
||||
else:
|
||||
plan.append(f'核销明细字段=自定义 {len(field_keys)} 项')
|
||||
if run_merge:
|
||||
plan.append(f'并入台账「{config.LEDGER_SHEET}」'
|
||||
+ ('(演练,不写文件)' if dry_run else ''))
|
||||
@@ -123,6 +169,9 @@ class Xq0042Plugin(ScenePlugin):
|
||||
plan.append(f'补核对表「{config.STAT_SHEET}」同源取数公式'
|
||||
+ ('(演练,不写文件)' if dry_run else ''))
|
||||
config.log('本次执行:' + ' + '.join(plan) + ('(强制重新登录)' if force else ''))
|
||||
config.log('执行模式:' + ('仅导出(金色印象 + 金色湖畔,不写表)'
|
||||
if run_mode == config.RUN_MODE_EXPORT_ONLY
|
||||
else '含写表(只导金色印象 + 并台账 + 补核对表)'))
|
||||
if do_download:
|
||||
config.log(f'导出记录保留条数:核销明细 {limit_verify}、提现记录 {limit_withdraw}')
|
||||
config.progress(5)
|
||||
@@ -139,14 +188,22 @@ class Xq0042Plugin(ScenePlugin):
|
||||
login_msg = msg
|
||||
config.progress(30)
|
||||
|
||||
if do_verify:
|
||||
results['核销明细'] = douyin_export.run(page, v_from, v_to, save_dir,
|
||||
limit_verify)
|
||||
config.progress(65)
|
||||
if do_withdraw:
|
||||
results['提现记录'] = douyin_export.run_withdraw(page, w_from, w_to,
|
||||
save_dir, limit_withdraw)
|
||||
config.progress(95)
|
||||
# 逐家公司导:切到该公司 groupid 后再导出(导出接口按页面上下文定公司)
|
||||
steps = len(companies) * ((1 if do_verify else 0) + (1 if do_withdraw else 0))
|
||||
done = 0
|
||||
for comp in companies:
|
||||
short = comp.get('short') or comp['id']
|
||||
if do_verify:
|
||||
results[f'{short}·核销明细'] = douyin_export.run(
|
||||
page, v_from, v_to, save_dir, limit_verify,
|
||||
field_mode, field_keys, comp)
|
||||
done += 1
|
||||
config.progress(30 + int(60 * done / max(steps, 1)))
|
||||
if do_withdraw:
|
||||
results[f'{short}·提现记录'] = douyin_export.run_withdraw(
|
||||
page, w_from, w_to, save_dir, limit_withdraw, comp)
|
||||
done += 1
|
||||
config.progress(30 + int(60 * done / max(steps, 1)))
|
||||
finally:
|
||||
browser.close_page(page)
|
||||
|
||||
@@ -191,6 +248,11 @@ class Xq0042Plugin(ScenePlugin):
|
||||
'summary': ';'.join(p for p in parts if p) or '执行完成',
|
||||
'detail': {'date_from': v_from, 'date_to': v_to,
|
||||
'withdraw_from': w_from, 'withdraw_to': w_to,
|
||||
'run_mode': run_mode,
|
||||
'export_field_mode': field_mode,
|
||||
'companies': [c.get('short') or c['id'] for c in companies],
|
||||
'export_fields': (results.get('核销明细') or {}).get('field_keys')
|
||||
or field_keys,
|
||||
'login': login_msg, 'results': results,
|
||||
'merge': merge, 'stat_links': links, 'dry_run': dry_run},
|
||||
'path': path,
|
||||
|
||||
@@ -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()}
|
||||
@@ -2,7 +2,8 @@
|
||||
"""浏览器:一次运行共用一个可见浏览器(登录 + 后续取数都复用它,避免反复开关)。
|
||||
|
||||
独立固定用户目录 %LOCALAPPDATA%\\37duAutomation\\browser_sessions\\xq0042,
|
||||
登录态跨次保留,不占用用户日常 Chrome 配置。
|
||||
不占用用户日常 Chrome 配置。注意:来客票据是会话级 Cookie,Chromium 退出后不保证保留,
|
||||
所以登录态以 douyin_login 落盘的快照为准,启动后由 douyin_login.restore_cookies 注入。
|
||||
"""
|
||||
import os
|
||||
|
||||
|
||||
@@ -103,11 +103,17 @@ def _group_id(page):
|
||||
return config.ORDER_GROUP_ID
|
||||
|
||||
|
||||
def _ensure_page(page, url, hint, label):
|
||||
"""切到导出所在页面(同域上下文,SDK 才会给请求签名)。"""
|
||||
target = url.replace(config.ORDER_GROUP_ID, _group_id(page))
|
||||
if hint not in (page.url or ''):
|
||||
config.log(f'打开{label}页面')
|
||||
def _ensure_page(page, url, hint, label, group_id=None):
|
||||
"""切到导出所在页面(同域上下文,SDK 才会给请求签名)。
|
||||
|
||||
group_id:目标公司 account_id;页面已是该公司的目标页才跳过导航(否则公司会串)。
|
||||
"""
|
||||
gid = str(group_id or '').strip() or _group_id(page)
|
||||
target = url.replace(config.ORDER_GROUP_ID, gid)
|
||||
cur_url = page.url or ''
|
||||
same = hint in cur_url and f'groupid={gid}' in cur_url
|
||||
if not same:
|
||||
config.log(f'打开{label}页面(groupid={gid})')
|
||||
page.get(target)
|
||||
try:
|
||||
page.wait.doc_loaded(timeout=20)
|
||||
@@ -118,14 +124,14 @@ def _ensure_page(page, url, hint, label):
|
||||
return target
|
||||
|
||||
|
||||
def _ensure_order_page(page):
|
||||
def _ensure_order_page(page, group_id=None):
|
||||
return _ensure_page(page, config.ORDER_URL,
|
||||
'fulfillment-admin/order-list', '履约管理订单列表')
|
||||
'fulfillment-admin/order-list', '履约管理订单列表', group_id)
|
||||
|
||||
|
||||
def _ensure_withdraw_page(page):
|
||||
def _ensure_withdraw_page(page, group_id=None):
|
||||
return _ensure_page(page, config.WITHDRAW_URL,
|
||||
'fulfillsettle/export_records', '提现记录')
|
||||
'fulfillsettle/export_records', '提现记录', group_id)
|
||||
|
||||
|
||||
def _list_records(page, download_type):
|
||||
@@ -192,7 +198,106 @@ def _ensure_capacity(page, download_type, limit):
|
||||
return _delete_oldest(page, download_type, total - limit, infos)
|
||||
|
||||
|
||||
def _create_export(page, start_ts, end_ts):
|
||||
def _field_catalog(page):
|
||||
"""拉平台字段目录(分组)。返回 download_field_list 或 None。"""
|
||||
aid = _account_id(page)
|
||||
url = config.FIELD_CONFIG_API + (f'?root_life_account_id={aid}' if aid else '')
|
||||
data = _api_json(page, 'POST', url, {
|
||||
'scene': dict(config.FIELD_SCENE), 'source': 1, 'need_merchant_custom': True})
|
||||
if data is None:
|
||||
return None
|
||||
groups = (data.get('data') or {}).get('download_field_list') or []
|
||||
return groups or None
|
||||
|
||||
|
||||
def _save_field_config(page, select_keys, un_select_keys):
|
||||
"""保存该账号的导出字段设置(自定义字段走这条路,导出时只需 option=2)。"""
|
||||
aid = _account_id(page)
|
||||
url = config.FIELD_SAVE_API + (f'?root_life_account_id={aid}' if aid else '')
|
||||
data = _api_json(page, 'POST', url, {
|
||||
'scene': dict(config.FIELD_SCENE),
|
||||
'select_keys': list(select_keys),
|
||||
'un_select_keys': list(un_select_keys),
|
||||
})
|
||||
if data is None:
|
||||
return False
|
||||
base = (data.get('BaseResp') or {})
|
||||
if base.get('StatusCode') not in (0, None) or data.get('status_code') not in (0, None):
|
||||
config.log(f'保存字段设置返回异常:{base.get("StatusMessage") or data}', 'WARN')
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def _prepare_fields(page, field_mode, field_keys):
|
||||
"""按字段方案准备导出:返回 (download_field_option, 实际字段 key 列表)。
|
||||
|
||||
default → 1(平台默认字段,不写账号设置);preset → 推荐字段(option=2,含台账 4 列);
|
||||
custom → 用户勾选(option=2)。后两者会写账号字段设置(已是同一套则跳过写入)。
|
||||
非 default 时系统默认字段(option_type=1)与台账必需列会被强制补回,避免导出缺列。
|
||||
"""
|
||||
mode = config.normalize_field_mode(field_mode)
|
||||
if mode == config.FIELD_MODE_DEFAULT:
|
||||
config.log('导出字段:平台默认字段(注意平台默认不含核销门店省份/核销人昵称/核销人ID/保险费用)')
|
||||
return 1, []
|
||||
|
||||
if mode == config.FIELD_MODE_PRESET:
|
||||
from ..config.export_fields import DEFAULT_KEYS
|
||||
field_keys = list(DEFAULT_KEYS)
|
||||
config.log(f'导出字段:推荐字段 {len(field_keys)} 个(平台默认 72 列 + 台账列)')
|
||||
|
||||
catalog = _field_catalog(page)
|
||||
if not catalog:
|
||||
config.log('读取平台字段清单失败,本次退回「平台默认字段」导出', 'WARN')
|
||||
return 1, []
|
||||
|
||||
known = {}
|
||||
for group in catalog:
|
||||
for item in group.get('field_list') or []:
|
||||
key = item.get('field_key')
|
||||
if key:
|
||||
known[key] = item
|
||||
locked = [k for k, it in known.items() if it.get('option_type') == 1]
|
||||
current = {k for k, it in known.items() if it.get('is_select')}
|
||||
|
||||
want, seen = [], set()
|
||||
|
||||
def _add(key):
|
||||
if key and key not in seen:
|
||||
seen.add(key)
|
||||
want.append(key)
|
||||
|
||||
for key in field_keys or []:
|
||||
_add(str(key).strip())
|
||||
|
||||
added_locked = [k for k in locked if k not in seen]
|
||||
for key in locked:
|
||||
_add(key)
|
||||
if added_locked:
|
||||
config.log(f'系统默认字段自动补回 {len(added_locked)} 个(平台不可取消)', 'DEBUG')
|
||||
|
||||
for label, key in config.LEDGER_REQUIRED_FIELDS:
|
||||
if key not in seen:
|
||||
_add(key)
|
||||
config.log(f'自定义字段缺少台账必需列「{label}」,已自动补上', 'WARN')
|
||||
|
||||
unknown = [k for k in want if k not in known]
|
||||
if unknown:
|
||||
config.log(f'字段清单里没有这些 key(照传,平台不认识会忽略):{unknown}', 'WARN')
|
||||
|
||||
# 账号当前字段设置已经一致就不重复写(减少对该账号共享设置的扰动)
|
||||
if not unknown and current == seen:
|
||||
config.log(f'账号导出字段已是这套({len(want)} 个),跳过写入')
|
||||
return 2, want
|
||||
|
||||
unselect = [k for k in known if k not in seen]
|
||||
if not _save_field_config(page, want, unselect):
|
||||
config.log('保存自定义字段设置失败,本次退回「平台默认字段」导出', 'WARN')
|
||||
return 1, []
|
||||
config.log(f'已写入账号导出字段:{len(want)} 个(平台清单共 {len(known)} 个)')
|
||||
return 2, want
|
||||
|
||||
|
||||
def _create_export(page, start_ts, end_ts, field_option=1):
|
||||
"""发起核销明细导出,返回 downloadStruct(含 download_id / file_name)。"""
|
||||
aid = _account_id(page)
|
||||
url = config.VERIFY_EXPORT_API + (f'?root_life_account_id={aid}' if aid else '')
|
||||
@@ -209,7 +314,7 @@ def _create_export(page, start_ts, end_ts):
|
||||
'is_app': False,
|
||||
'show_reason': config.VERIFY_SHOW_REASON,
|
||||
'view_type': config.VERIFY_VIEW_TYPE,
|
||||
'download_field_option': 1,
|
||||
'download_field_option': int(field_option or 1),
|
||||
'permission_common_param': {},
|
||||
}
|
||||
for attempt in range(1, config.RETRY_MAX + 1):
|
||||
@@ -329,11 +434,16 @@ def _day_bounds(date_from, date_to):
|
||||
return start_ts, end_ts
|
||||
|
||||
|
||||
def _save_record(record, save_dir, default_name, label):
|
||||
"""把生成好的记录下载落盘,返回统一结果 dict。"""
|
||||
def _save_record(record, save_dir, default_name, label, name_prefix=''):
|
||||
"""把生成好的记录下载落盘,返回统一结果 dict。
|
||||
|
||||
name_prefix:多公司时给文件名加公司简称(平台文件名不含公司名,两家同名会互相覆盖)。
|
||||
"""
|
||||
download_id = str(record.get('download_id') or '')
|
||||
file_name = record.get('file_name') or default_name
|
||||
safe_name = str(file_name).replace('/', '_').replace('\\', '_')
|
||||
file_name = str(record.get('file_name') or default_name)
|
||||
if name_prefix and not file_name.startswith(name_prefix):
|
||||
file_name = name_prefix + file_name
|
||||
safe_name = file_name.replace('/', '_').replace('\\', '_')
|
||||
save_path = os.path.join(save_dir, safe_name)
|
||||
size = _download(record.get('file_url'), save_path)
|
||||
if not size:
|
||||
@@ -344,24 +454,34 @@ def _save_record(record, save_dir, default_name, label):
|
||||
'download_id': download_id, 'file_name': safe_name, 'size': size}
|
||||
|
||||
|
||||
def run(page, date_from, date_to, save_dir=None, record_limit=None):
|
||||
def run(page, date_from, date_to, save_dir=None, record_limit=None,
|
||||
field_mode=None, field_keys=None, company=None):
|
||||
"""导出指定「核销时间」区间的核销明细并下载。
|
||||
|
||||
date_from/date_to:YYYY-MM-DD;核销时间按自然日取整(00:00:00 ~ 23:59:59)。
|
||||
record_limit:导出记录保留条数(超出则先删最早的),默认 config.RECORD_LIMIT_VERIFY。
|
||||
返回 {ok, message, path, download_id, file_name}
|
||||
field_mode:preset=推荐字段;default=平台默认字段;custom=按 field_keys 自定义。
|
||||
field_keys:自定义字段的 field_key 列表(仅 custom 生效)。
|
||||
company:公司配置 dict(id/short/file_prefix);缺省用 config 里的台账那家。
|
||||
返回 {ok, message, path, download_id, file_name, field_option, field_keys, company}
|
||||
"""
|
||||
company = company or config.get_company(config.ORDER_GROUP_ID) or {}
|
||||
gid = str(company.get('id') or config.ORDER_GROUP_ID)
|
||||
prefix = str(company.get('file_prefix') or '')
|
||||
save_dir = save_dir or config.WORK_DIR
|
||||
limit = int(record_limit or config.RECORD_LIMIT_VERIFY)
|
||||
os.makedirs(save_dir, exist_ok=True)
|
||||
start_ts, end_ts = _day_bounds(date_from, date_to)
|
||||
|
||||
_ensure_order_page(page)
|
||||
config.log(f'发起核销明细导出:核销时间 {date_from} ~ {date_to}')
|
||||
_ensure_order_page(page, gid)
|
||||
config.log(f'发起核销明细导出[{company.get("short") or gid}]:核销时间 {date_from} ~ {date_to}')
|
||||
_ensure_capacity(page, config.DOWNLOAD_TYPE, limit)
|
||||
struct = _create_export(page, start_ts, end_ts)
|
||||
field_option, used_keys = _prepare_fields(page, field_mode, field_keys)
|
||||
struct = _create_export(page, start_ts, end_ts, field_option)
|
||||
if not struct:
|
||||
return {'ok': False, 'message': '发起导出失败(接口未返回 download_id)', 'path': ''}
|
||||
return {'ok': False, 'message': f'{company.get("short") or ""}发起导出失败(接口未返回 download_id)',
|
||||
'path': '', 'field_option': field_option, 'field_keys': used_keys,
|
||||
'company': company}
|
||||
download_id = str(struct.get('download_id'))
|
||||
file_name = struct.get('file_name') or f'核销明细_{date_from}_{date_to}.xlsx'
|
||||
config.log(f'导出任务已创建:download_id={download_id},文件名={file_name}')
|
||||
@@ -370,34 +490,47 @@ def run(page, date_from, date_to, save_dir=None, record_limit=None):
|
||||
lambda x: str(x.get('download_id')) == download_id)
|
||||
if not record:
|
||||
return {'ok': False, 'message': '导出任务未生成完成', 'path': '',
|
||||
'download_id': download_id, 'file_name': file_name}
|
||||
return _save_record(record, save_dir, file_name, '核销明细')
|
||||
'download_id': download_id, 'file_name': file_name,
|
||||
'field_option': field_option, 'field_keys': used_keys, 'company': company}
|
||||
result = _save_record(record, save_dir, file_name, '核销明细', prefix)
|
||||
result['field_option'] = field_option
|
||||
result['field_keys'] = used_keys
|
||||
result['company'] = company
|
||||
return result
|
||||
|
||||
|
||||
def run_withdraw(page, date_from, date_to, save_dir=None, record_limit=None):
|
||||
def run_withdraw(page, date_from, date_to, save_dir=None, record_limit=None, company=None):
|
||||
"""导出指定区间的「提现记录」(资金账户交易提现记录)并下载。
|
||||
|
||||
该接口不回 download_id,创建后按 generate_start_time 找最新那条记录。
|
||||
record_limit:导出记录保留条数,默认 config.RECORD_LIMIT_WITHDRAW。
|
||||
company:公司配置 dict(id/short/file_prefix),提现按公司分别导。
|
||||
"""
|
||||
company = company or config.get_company(config.ORDER_GROUP_ID) or {}
|
||||
gid = str(company.get('id') or config.ORDER_GROUP_ID)
|
||||
prefix = str(company.get('file_prefix') or '')
|
||||
save_dir = save_dir or config.WORK_DIR
|
||||
limit = int(record_limit or config.RECORD_LIMIT_WITHDRAW)
|
||||
os.makedirs(save_dir, exist_ok=True)
|
||||
start_ts, end_ts = _day_bounds(date_from, date_to)
|
||||
|
||||
_ensure_withdraw_page(page)
|
||||
config.log(f'发起提现记录导出:{date_from} ~ {date_to}')
|
||||
_ensure_withdraw_page(page, gid)
|
||||
config.log(f'发起提现记录导出[{company.get("short") or gid}]:{date_from} ~ {date_to}')
|
||||
_ensure_capacity(page, config.WITHDRAW_DOWNLOAD_TYPE, limit)
|
||||
before = int(time.time()) - 5
|
||||
ok, msg = _create_withdraw(page, start_ts, end_ts)
|
||||
if not ok:
|
||||
return {'ok': False, 'message': f'发起提现记录导出失败:{msg}', 'path': ''}
|
||||
return {'ok': False, 'message': f'发起提现记录导出失败:{msg}', 'path': '',
|
||||
'company': company}
|
||||
|
||||
record = _wait_record(page, config.WITHDRAW_DOWNLOAD_TYPE,
|
||||
lambda x: int(x.get('generate_start_time') or 0) >= before)
|
||||
if not record:
|
||||
return {'ok': False, 'message': '提现记录导出任务未生成完成', 'path': ''}
|
||||
return {'ok': False, 'message': '提现记录导出任务未生成完成', 'path': '',
|
||||
'company': company}
|
||||
config.log(f'导出任务已创建:download_id={record.get("download_id")},'
|
||||
f'文件名={record.get("file_name")}')
|
||||
return _save_record(record, save_dir,
|
||||
f'资金账户交易提现记录_{date_from}_{date_to}.xlsx', '提现记录')
|
||||
result = _save_record(record, save_dir,
|
||||
f'资金账户交易提现记录_{date_from}_{date_to}.xlsx', '提现记录', prefix)
|
||||
result['company'] = company
|
||||
return result
|
||||
|
||||
@@ -11,6 +11,11 @@
|
||||
2) douyin 域下存在会话票据 Cookie(sessionid* / sid_tt* / sid_guard*);
|
||||
3) 连续稳定 BACKEND_STABLE 秒,期间没有被踢回登录页。
|
||||
|
||||
登录态缓存(跨次复用):
|
||||
来客票据 sessionid_ls / sid_tt_ls / sid_guard_ls 都是**会话级 Cookie**,Chromium 退出后
|
||||
并不保证落盘保留(只靠 profile 目录不可靠),所以每次运行前把快照 douyin_cookies.json
|
||||
重新注入新启动的浏览器(page.set.cookies),profile 只当兜底;注入后仍进不了后台才转人工登录。
|
||||
|
||||
落盘(%LOCALAPPDATA%\\37duAutomation\\.sessions\\douyin_*):
|
||||
douyin_cookies.json / douyin_cookies_header.txt / douyin_tokens.json / douyin_session_meta.json
|
||||
"""
|
||||
@@ -167,6 +172,127 @@ def _save_login_state(page):
|
||||
return summary
|
||||
|
||||
|
||||
# ==================== 登录态缓存:快照 → 浏览器注入 ====================
|
||||
# 只注入 douyin 相关域;埋点/上报域(report/monitor/lx/dreport)丢掉,减少无关 Cookie 干扰。
|
||||
_INJECT_SKIP_DOMAINS = ('report', 'monitor', 'lx', 'dreport', 'open.douyin')
|
||||
|
||||
|
||||
def _load_cookies():
|
||||
"""读取落盘 Cookies 快照:去掉空值与已过期的,返回列表;无可用项返回 None。"""
|
||||
path = config.COOKIE_FILE
|
||||
if not os.path.exists(path):
|
||||
return None
|
||||
try:
|
||||
with open(path, encoding='utf-8') as f:
|
||||
cookies = json.load(f)
|
||||
except Exception as e:
|
||||
config.log(f'读取 Cookies 快照失败(忽略缓存):{e}', 'WARN')
|
||||
return None
|
||||
|
||||
now = time.time()
|
||||
alive = []
|
||||
for c in cookies or []:
|
||||
if not c.get('name') or not c.get('value'):
|
||||
continue
|
||||
try:
|
||||
exp = float(c.get('expires'))
|
||||
except (TypeError, ValueError):
|
||||
exp = -1.0
|
||||
if exp > 0 and exp <= now: # 已过期:注入了也只会被服务端判无效
|
||||
continue
|
||||
alive.append(c)
|
||||
return alive or None
|
||||
|
||||
|
||||
def _inject_item(c):
|
||||
"""快照里的 Cookie → page.set.cookies 需要的结构(只带有效字段)。"""
|
||||
item = {
|
||||
'name': c.get('name'),
|
||||
'value': c.get('value'),
|
||||
'domain': c.get('domain') or config.BACKEND_HOST,
|
||||
'path': c.get('path') or '/',
|
||||
}
|
||||
try:
|
||||
exp = float(c.get('expires'))
|
||||
except (TypeError, ValueError):
|
||||
exp = -1.0
|
||||
if exp > 0:
|
||||
item['expires'] = exp # 会话级 Cookie(-1)不传 expires,交给浏览器当会话 Cookie
|
||||
if c.get('secure'):
|
||||
item['secure'] = True
|
||||
if c.get('httpOnly'):
|
||||
item['httpOnly'] = True
|
||||
same_site = str(c.get('sameSite') or '').strip()
|
||||
if same_site in ('Strict', 'Lax', 'None'):
|
||||
item['sameSite'] = same_site
|
||||
return item
|
||||
|
||||
|
||||
def restore_cookies(page):
|
||||
"""把上次落盘的登录态注入刚启动的浏览器,返回注入条数(0=无可用缓存)。"""
|
||||
cookies = _load_cookies()
|
||||
if not cookies:
|
||||
config.log('无可用登录态快照(首次运行或已过期)', 'DEBUG')
|
||||
return 0
|
||||
|
||||
items = [_inject_item(c) for c in cookies
|
||||
if 'douyin.com' in (c.get('domain') or '')
|
||||
and not any(s in (c.get('domain') or '') for s in _INJECT_SKIP_DOMAINS)]
|
||||
if not items:
|
||||
return 0
|
||||
injected = False
|
||||
try:
|
||||
# 浏览器级注入(Storage.setCookies):此时页面还是 about:blank,不依赖加载完成
|
||||
page.browser.set.cookies(items)
|
||||
injected = True
|
||||
except Exception as e:
|
||||
config.log(f'浏览器级注入失败,改走标签页注入:{e}', 'DEBUG')
|
||||
if not injected:
|
||||
try:
|
||||
page.set.cookies(items)
|
||||
injected = True
|
||||
except Exception as e:
|
||||
config.log(f'注入缓存 Cookies 失败(改走 profile / 人工登录):{e}', 'WARN')
|
||||
return 0
|
||||
|
||||
saved_at = ''
|
||||
try:
|
||||
with open(config.META_FILE, encoding='utf-8') as f:
|
||||
saved_at = str((json.load(f) or {}).get('saved_at') or '')
|
||||
except Exception:
|
||||
pass
|
||||
config.log(f'已注入缓存登录态:{len(items)} 个 douyin Cookie'
|
||||
+ (f'(快照时间 {saved_at})' if saved_at else '')
|
||||
+ f',含会话票据={"是" if _has_session_cookie(items) else "否"}')
|
||||
return len(items)
|
||||
|
||||
|
||||
def clear_snapshot():
|
||||
"""删除登录态快照文件(强制重新登录时用,避免下次又被旧账号缓存带进去)。"""
|
||||
for path in (config.COOKIE_FILE, config.COOKIE_HEADER_FILE,
|
||||
config.TOKEN_FILE, config.META_FILE):
|
||||
try:
|
||||
if os.path.exists(path):
|
||||
os.remove(path)
|
||||
except Exception as e:
|
||||
config.log(f'删除登录态快照失败(忽略):{path} {e}', 'WARN')
|
||||
|
||||
|
||||
def clear_browser_cookies(page):
|
||||
"""清掉浏览器里的 Cookies(localStorage 保留,不影响页面偏好配置)。"""
|
||||
if page is None:
|
||||
return
|
||||
try:
|
||||
page.clear_cache(session_storage=False, local_storage=False, cache=False, cookies=True)
|
||||
return
|
||||
except Exception as e:
|
||||
config.log(f'清除浏览器 Cookies 失败(改走 CDP):{e}', 'DEBUG')
|
||||
try:
|
||||
page.set.cookies.clear() # Network.clearBrowserCookies
|
||||
except Exception as e:
|
||||
config.log(f'清除浏览器 Cookies 失败:{e}', 'WARN')
|
||||
|
||||
|
||||
def _wait_backend(page):
|
||||
"""等人工完成「登录 + 验证码」,返回 True/False。"""
|
||||
deadline = time.time() + config.LOGIN_WAIT
|
||||
@@ -211,26 +337,34 @@ def _wait_backend(page):
|
||||
def ensure_login(page, force=False):
|
||||
"""确保 page 已进入来客后台;必要时停在前台等人工登录。
|
||||
|
||||
force=True 跳过 profile 残留会话试探,直接等人工登录(换账号/排查问题用)。
|
||||
复用顺序:落盘快照注入(restore_cookies)→ profile 残留会话 → 人工登录。
|
||||
force=True 先清空浏览器 Cookies 与本地快照,再等人工重新登录(换账号/排查问题用)。
|
||||
"""
|
||||
if force:
|
||||
config.log('强制重新登录:清除浏览器 Cookies 与本地登录态快照', 'WARN')
|
||||
clear_browser_cookies(page)
|
||||
clear_snapshot()
|
||||
else:
|
||||
restore_cookies(page)
|
||||
|
||||
config.log(f'打开抖音来客:{config.HOME_URL}')
|
||||
page.get(config.HOME_URL)
|
||||
time.sleep(config.POLL_SECONDS)
|
||||
|
||||
# 复用 profile 残留会话:能直接进后台就不用打扰用户
|
||||
# 复用缓存(注入的 Cookie + profile 残留):能直接进后台就不用打扰用户
|
||||
if not force:
|
||||
reuse_end = time.time() + config.BACKEND_STABLE + 10
|
||||
while time.time() < reuse_end:
|
||||
state = classify(page.url)
|
||||
if state == 'backend' and _has_session_cookie(_cookies(page)):
|
||||
config.log(f'profile 残留会话有效,直接复用(URL={page.url})')
|
||||
config.log(f'缓存登录态有效,直接复用(URL={page.url})')
|
||||
time.sleep(config.SETTLE_WAIT)
|
||||
_save_login_state(page)
|
||||
return True, '复用缓存登录态'
|
||||
if state == 'login':
|
||||
break
|
||||
time.sleep(config.POLL_SECONDS)
|
||||
config.log('profile 无有效会话,转人工登录', 'WARN')
|
||||
config.log('缓存登录态已失效,转人工登录', 'WARN')
|
||||
|
||||
config.log(f'需要人工登录(含验证码/滑块),最多等待 {config.LOGIN_WAIT} 秒…')
|
||||
if not _wait_backend(page):
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
"schema_version": 1,
|
||||
"id": "xq0042",
|
||||
"name": "抖音平台核对",
|
||||
"version": "0.7.7",
|
||||
"description": "抖音来客(life.douyin.com)数据自动导出:打开官方页面人工登录(含验证码/滑块),按日期区间导出核销明细与提现记录,轮询生成完成后下载到本机目录;导出记录超过保留阈值自动删最早的(阈值可在界面改);核销明细按「核销时间」增量并入台账「抖音到账统计YYYY.M月.xlsx」的「金色印象--抖音」sheet,A 与 BT~CA 公式列自动下拉;并按 A 列日期把「抖音到账核对」整行同源取数公式([n]资金组取数!$B$xx,实测 O/P/R/S)的链接换成当天那份共享总表。",
|
||||
"version": "0.9.1",
|
||||
"description": "抖音来客(life.douyin.com)数据自动导出:打开官方页面人工登录(含验证码/滑块),按日期区间导出核销明细(字段可选平台默认字段或自定义勾选,自定义会写入该账号的导出字段设置)与提现记录,轮询生成完成后下载到本机目录;导出记录超过保留阈值自动删最早的(阈值可在界面改);核销明细按「核销时间」增量并入台账「抖音到账统计YYYY.M月.xlsx」的「金色印象--抖音」sheet,A 与 BT~CA 公式列自动下拉;并按 A 列日期把「抖音到账核对」整行同源取数公式([n]资金组取数!$B$xx,实测 O/P/R/S)的链接换成当天那份共享总表。",
|
||||
"category": "财务",
|
||||
"icon": "",
|
||||
"platform": "",
|
||||
@@ -55,6 +55,36 @@
|
||||
"default": true,
|
||||
"description": "财务 → 导出记录 → 余额提现记录(资金账户交易提现记录)"
|
||||
},
|
||||
"export_field_mode": {
|
||||
"type": "string",
|
||||
"title": "核销明细-导出字段",
|
||||
"default": "preset",
|
||||
"enum": [
|
||||
"preset",
|
||||
"default",
|
||||
"custom"
|
||||
],
|
||||
"description": "preset=推荐字段(平台默认 72 列 + 台账列:核销门店省份/核销人昵称/核销人ID/保险费用);default=平台默认字段(会缺上述 4 列);custom=按 export_fields 自定义勾选。preset/custom 会写入该账号的导出字段设置"
|
||||
},
|
||||
"export_fields": {
|
||||
"type": "array",
|
||||
"title": "自定义导出字段(field_key)",
|
||||
"default": [],
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "仅 export_field_mode=custom 生效;系统默认字段与台账必需列(核销时间、订单编号)会自动补上"
|
||||
},
|
||||
"run_mode": {
|
||||
"type": "string",
|
||||
"title": "执行模式",
|
||||
"default": "full",
|
||||
"enum": [
|
||||
"full",
|
||||
"export_only"
|
||||
],
|
||||
"description": "full=含写表(只导金色印象,导出后并台账 + 补核对表取数);export_only=仅导出(金色印象 + 金色湖畔各导一份,不写表,湖畔文件名带「金色湖畔_」前缀)"
|
||||
},
|
||||
"record_limit_verify": {
|
||||
"type": "integer",
|
||||
"title": "核销明细-导出记录保留条数",
|
||||
|
||||
@@ -58,13 +58,88 @@
|
||||
:disabled="running || !form.export_withdraw" />
|
||||
</el-form-item>
|
||||
</div>
|
||||
|
||||
<el-form-item label="执行模式">
|
||||
<el-radio-group v-model="form.run_mode" :disabled="running">
|
||||
<el-radio-button value="export_only">仅导出(金色印象 + 金色湖畔)</el-radio-button>
|
||||
<el-radio-button value="full">含写表(只导金色印象 + 并台账 + 补核对表)</el-radio-button>
|
||||
</el-radio-group>
|
||||
<div class="field-hint mode-hint">
|
||||
{{ form.run_mode === 'export_only'
|
||||
? '两家公司各导一份(湖畔文件名带「金色湖畔_」前缀),不并台账、不补核对表'
|
||||
: '只导金色印象,导出后并入台账「金色印象--抖音」并补「抖音到账核对」取数公式' }}
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="核销明细 导出字段">
|
||||
<div class="field-ctrl">
|
||||
<el-radio-group v-model="form.export_field_mode"
|
||||
:disabled="running || !form.export_verify">
|
||||
<el-radio-button value="preset">推荐字段</el-radio-button>
|
||||
<el-radio-button value="default">平台默认字段</el-radio-button>
|
||||
<el-radio-button value="custom">自定义勾选</el-radio-button>
|
||||
</el-radio-group>
|
||||
<el-button v-if="form.export_field_mode === 'custom'" class="field-btn"
|
||||
:disabled="running || !form.export_verify" @click="openFieldDialog">
|
||||
选择字段(已选 {{ form.export_fields.length }} / {{ FIELD_TOTAL }})
|
||||
</el-button>
|
||||
<span v-if="form.export_field_mode === 'custom'" class="field-hint">
|
||||
系统默认字段固定导出,其余按勾选
|
||||
</span>
|
||||
<span v-else-if="form.export_field_mode === 'preset'" class="field-hint">
|
||||
{{ DEFAULT_KEYS.length }} 列 = 平台默认 72 列 + 台账列(核销门店省份 / 核销人昵称 / 核销人ID / 保险费用)
|
||||
</span>
|
||||
<span v-else class="field-hint is-warn">
|
||||
平台默认不含核销门店省份 / 核销人昵称 / 核销人ID / 保险费用,台账合并会留空
|
||||
</span>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<div class="tip">
|
||||
默认昨天到今天;今天的核销数据当天可导,要完整日结数据建议选到昨天。
|
||||
自定义字段会写入该账号在平台的「导出字段」设置(同账号后续导出沿用),
|
||||
系统默认字段与台账必需列(核销时间、订单编号)会自动补上。
|
||||
</div>
|
||||
</el-form>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 字段选择弹窗:分组勾选(系统默认字段灰显不可取消) -->
|
||||
<el-dialog v-model="fieldDialog" title="选择核销明细导出字段" width="780px"
|
||||
append-to-body :close-on-click-modal="false" class="field-dialog">
|
||||
<div class="fd-head">
|
||||
<el-input v-model="fieldQuery" class="fd-search" clearable
|
||||
placeholder="搜索字段名 / field_key" />
|
||||
<el-button @click="applyPreset">恢复默认勾选</el-button>
|
||||
<el-button @click="toggleAll(true)">全选</el-button>
|
||||
<el-button @click="toggleAll(false)">清空可选</el-button>
|
||||
</div>
|
||||
<div class="fd-body">
|
||||
<div v-for="g in visibleGroups" :key="g.label" class="fd-group">
|
||||
<div class="fd-group-head">
|
||||
<el-checkbox :model-value="groupChecked(g)" :indeterminate="groupIndeterminate(g)"
|
||||
@change="(v) => toggleGroup(g, v)">
|
||||
<b>{{ g.label }}</b>
|
||||
</el-checkbox>
|
||||
<span class="fd-count">{{ groupSelected(g) }} / {{ g.fields.length }}</span>
|
||||
</div>
|
||||
<div class="fd-items">
|
||||
<el-checkbox v-for="f in g.fields" :key="f.key" class="fd-item"
|
||||
:model-value="fieldDraft.includes(f.key)" :disabled="f.locked"
|
||||
@change="(v) => toggleField(f, v)">
|
||||
{{ f.name }}<span v-if="f.locked" class="fd-tag">默认</span>
|
||||
</el-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!visibleGroups.length" class="fd-empty">没有匹配的字段</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<span class="fd-total">已选 {{ fieldDraft.length }} / {{ FIELD_TOTAL }}
|
||||
(系统默认 {{ LOCKED_KEYS.length }} 个必选)</span>
|
||||
<el-button @click="fieldDialog = false">取消</el-button>
|
||||
<el-button type="primary" @click="confirmFields">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 02 执行设置 -->
|
||||
<section class="sec">
|
||||
<div class="sec-head">
|
||||
@@ -74,7 +149,7 @@
|
||||
</div>
|
||||
<div class="sec-body">
|
||||
<el-form label-position="top">
|
||||
<div class="rows">
|
||||
<div class="rows rows-grid">
|
||||
<div class="row">
|
||||
<div class="r-main">
|
||||
<div class="r-title">强制重新登录</div>
|
||||
@@ -117,20 +192,26 @@
|
||||
</div>
|
||||
<div class="sec-body">
|
||||
<el-form label-position="top">
|
||||
<div class="rows">
|
||||
<div class="rows rows-grid">
|
||||
<div class="row">
|
||||
<div class="r-main">
|
||||
<div class="r-title">并入台账(金色印象--抖音)</div>
|
||||
<div class="r-desc">核销明细按「核销时间」增量追加,A 与 BT~CA 公式列自动下拉</div>
|
||||
</div>
|
||||
<div class="r-ctrl"><el-switch v-model="form.run_merge" :disabled="running" /></div>
|
||||
<div class="r-ctrl">
|
||||
<el-switch v-model="form.run_merge"
|
||||
:disabled="running || form.run_mode === 'export_only'" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="r-main">
|
||||
<div class="r-title">补核对表同源取数公式</div>
|
||||
<div class="r-desc">按 A 列日期把「抖音到账核对」整行的 [n] 换成当天那份共享总表</div>
|
||||
</div>
|
||||
<div class="r-ctrl"><el-switch v-model="form.run_stat_links" :disabled="running" /></div>
|
||||
<div class="r-ctrl">
|
||||
<el-switch v-model="form.run_stat_links"
|
||||
:disabled="running || form.run_mode === 'export_only'" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="r-main">
|
||||
@@ -139,13 +220,18 @@
|
||||
</div>
|
||||
<div class="r-ctrl">
|
||||
<el-switch v-model="form.dry_run"
|
||||
:disabled="running || (!form.run_merge && !form.run_stat_links)" />
|
||||
:disabled="running || form.run_mode === 'export_only'
|
||||
|| (!form.run_merge && !form.run_stat_links)" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tip">
|
||||
只勾这两项、不勾导出时可单独补账(不开浏览器);写入前自动备份(_备份 / _核对备份 + 时间戳),
|
||||
写入期间请关闭该台账。
|
||||
<b v-if="form.run_mode === 'export_only'">当前是「仅导出」模式:这三项不生效(不写任何表)。
|
||||
需要并台账时把执行模式切成「含写表」。</b>
|
||||
<template v-else>
|
||||
只勾这两项、不勾导出时可单独补账(不开浏览器);写入前自动备份(_备份 / _核对备份 + 时间戳),
|
||||
写入期间请关闭该台账。
|
||||
</template>
|
||||
</div>
|
||||
</el-form>
|
||||
</div>
|
||||
@@ -158,6 +244,18 @@
|
||||
<div class="hb-line"><b>① 导出内容</b>:<b>核销明细</b>走履约管理订单列表,按核销时间导出;
|
||||
<b>提现记录</b>走财务 → 导出记录里的「余额提现记录」(资金账户交易提现记录),按提现时间导出。
|
||||
两类文件分别落到保存目录,文件名由平台生成。</div>
|
||||
<div class="hb-line"><b>①-0 两种模式</b>:<b>仅导出</b>=金色印象 + 金色湖畔各导一份,不写任何表;
|
||||
<b>含写表</b>=只导金色印象,导出后并台账 + 补核对表。切换公司 = 打开带
|
||||
<b>groupid=公司account_id</b> 的页面,导出接口即按该公司返回。两家文件名在平台完全同名,
|
||||
所以湖畔的导出会自动加前缀(<b>金色湖畔_核销明细-…xlsx</b>),既不覆盖台账那家的文件,
|
||||
也天然不被台账合并扫到。</div>
|
||||
<div class="hb-line"><b>①-1 核销明细字段</b>:三选一 ——
|
||||
<b>推荐字段</b>(默认,76 列 = 平台默认 72 列 + 台账需要的核销门店省份 / 核销人昵称 / 核销人ID / 保险费用)、
|
||||
<b>平台默认字段</b>(平台自己那 72 列,缺上面 4 列,并入台账会留空)、
|
||||
<b>自定义勾选</b>(弹窗里按分组勾,想加什么自己点)。
|
||||
平台的字段设置是<b>账号级</b>的:推荐/自定义会把结果写到该账号的「导出字段」设置再发起导出
|
||||
(账号已是同一套就跳过写入),所以同账号后续在网页上导出也会沿用这套字段;
|
||||
系统默认字段(21 个)与台账必需列(核销时间、订单编号)不可取消,脚本会自动补上。</div>
|
||||
<div class="hb-line"><b>② 登录态</b>:打开 life.douyin.com 人工登录(账密 / 短信 / 扫码 / 滑块均可,脚本不碰表单),
|
||||
成功后 Cookies 落盘到 <b>%LOCALAPPDATA%\37duAutomation\.sessions\douyin_*</b>,
|
||||
后续直接复用浏览器档案;只有过期才会再次要求登录。</div>
|
||||
@@ -200,6 +298,9 @@
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { usePluginUI } from './usePluginUI'
|
||||
import { DEFAULT_KEYS, FIELD_GROUPS, LOCKED_KEYS } from './exportFields'
|
||||
|
||||
const FIELD_TOTAL = FIELD_GROUPS.reduce((n, g) => n + g.fields.length, 0)
|
||||
|
||||
// 默认日期区间:昨天 ~ 今天
|
||||
function defaultRange() {
|
||||
@@ -219,6 +320,9 @@ const DEFAULTS = () => {
|
||||
withdraw_to: to,
|
||||
export_verify: true,
|
||||
export_withdraw: true,
|
||||
export_field_mode: 'preset',
|
||||
export_fields: [],
|
||||
run_mode: 'full',
|
||||
record_limit_verify: 60,
|
||||
record_limit_withdraw: 25,
|
||||
run_merge: true,
|
||||
@@ -238,11 +342,17 @@ const {
|
||||
} = usePluginUI({
|
||||
defaults: DEFAULTS,
|
||||
validate() {
|
||||
if (!form.export_verify && !form.export_withdraw && !form.run_merge
|
||||
&& !form.run_stat_links) {
|
||||
const exportOnly = form.run_mode === 'export_only'
|
||||
if (!form.export_verify && !form.export_withdraw
|
||||
&& (exportOnly || (!form.run_merge && !form.run_stat_links))) {
|
||||
ElMessage.warning('请至少选择一项执行内容(核销明细 / 提现记录 / 并入台账 / 补核对表取数)')
|
||||
return false
|
||||
}
|
||||
if (form.export_verify && form.export_field_mode === 'custom'
|
||||
&& !(form.export_fields || []).length) {
|
||||
ElMessage.warning('自定义字段至少要勾一个(系统默认字段会自动带上),或切回「平台默认字段」')
|
||||
return false
|
||||
}
|
||||
const pairs = []
|
||||
if (form.export_verify) pairs.push(['核销时间', form.date_from, form.date_to])
|
||||
if (form.export_withdraw) pairs.push(['提现时间', form.withdraw_from, form.withdraw_to])
|
||||
@@ -262,6 +372,7 @@ const {
|
||||
const x = Number(v)
|
||||
return Number.isFinite(x) && x >= 5 ? Math.floor(x) : d
|
||||
}
|
||||
const exportOnly = f.run_mode === 'export_only'
|
||||
return {
|
||||
date_from: t(f.date_from),
|
||||
date_to: t(f.date_to),
|
||||
@@ -269,11 +380,17 @@ const {
|
||||
withdraw_to: t(f.withdraw_to),
|
||||
export_verify: !!f.export_verify,
|
||||
export_withdraw: !!f.export_withdraw,
|
||||
export_field_mode: ['preset', 'default', 'custom'].includes(f.export_field_mode)
|
||||
? f.export_field_mode : 'preset',
|
||||
export_fields: f.export_field_mode === 'custom'
|
||||
? fieldKeysFor(f.export_fields)
|
||||
: [],
|
||||
run_mode: f.run_mode === 'export_only' ? 'export_only' : 'full',
|
||||
record_limit_verify: n(f.record_limit_verify, 60),
|
||||
record_limit_withdraw: n(f.record_limit_withdraw, 25),
|
||||
run_merge: !!f.run_merge,
|
||||
run_stat_links: !!f.run_stat_links,
|
||||
dry_run: !!((f.run_merge || f.run_stat_links) && f.dry_run),
|
||||
run_merge: !exportOnly && !!f.run_merge,
|
||||
run_stat_links: !exportOnly && !!f.run_stat_links,
|
||||
dry_run: !exportOnly && !!((f.run_merge || f.run_stat_links) && f.dry_run),
|
||||
save_dir: t(f.save_dir),
|
||||
force_login: !!f.force_login,
|
||||
debug_mode: !!f.debug_mode,
|
||||
@@ -285,6 +402,109 @@ function start() {
|
||||
run()
|
||||
}
|
||||
|
||||
// 自定义字段:系统默认字段必须带上(平台不可取消),去空去重保序
|
||||
function fieldKeysFor(raw) {
|
||||
const out = []
|
||||
const seen = new Set()
|
||||
for (const k of [...(raw || []), ...LOCKED_KEYS]) {
|
||||
const key = String(k || '').trim()
|
||||
if (key && !seen.has(key)) {
|
||||
seen.add(key)
|
||||
out.push(key)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
function resetFieldKeys() {
|
||||
form.export_fields = fieldKeysFor(DEFAULT_KEYS)
|
||||
}
|
||||
|
||||
// 首次切到「自定义勾选」且还没选过:带出平台默认勾选的那套,用户只做加减
|
||||
watch(() => form.export_field_mode, (mode) => {
|
||||
if (mode === 'custom' && !(form.export_fields || []).length) resetFieldKeys()
|
||||
})
|
||||
|
||||
// ---------- 字段选择弹窗 ----------
|
||||
const fieldDialog = ref(false)
|
||||
const fieldDraft = ref([]) // 弹窗内的临时勾选,点「确定」才写回 form
|
||||
const fieldQuery = ref('')
|
||||
|
||||
const editableKeys = (g) => g.fields.filter((f) => !f.locked).map((f) => f.key)
|
||||
|
||||
// 搜索命中:组内按字段名/key 过滤,空组不显示
|
||||
const visibleGroups = computed(() => {
|
||||
const q = fieldQuery.value.trim().toLowerCase()
|
||||
if (!q) return FIELD_GROUPS
|
||||
return FIELD_GROUPS
|
||||
.map((g) => ({
|
||||
label: g.label,
|
||||
fields: g.fields.filter((f) => f.name.toLowerCase().includes(q)
|
||||
|| f.key.toLowerCase().includes(q)),
|
||||
}))
|
||||
.filter((g) => g.fields.length)
|
||||
})
|
||||
|
||||
function groupSelected(g) {
|
||||
return g.fields.filter((f) => fieldDraft.value.includes(f.key)).length
|
||||
}
|
||||
|
||||
function groupChecked(g) {
|
||||
const keys = editableKeys(g)
|
||||
return keys.length > 0 && keys.every((k) => fieldDraft.value.includes(k))
|
||||
}
|
||||
|
||||
function groupIndeterminate(g) {
|
||||
const keys = editableKeys(g)
|
||||
const hit = keys.filter((k) => fieldDraft.value.includes(k)).length
|
||||
return hit > 0 && hit < keys.length
|
||||
}
|
||||
|
||||
function openFieldDialog() {
|
||||
fieldDraft.value = fieldKeysFor(form.export_fields)
|
||||
fieldQuery.value = ''
|
||||
fieldDialog.value = true
|
||||
}
|
||||
|
||||
function toggleField(f, checked) {
|
||||
const set = new Set(fieldDraft.value)
|
||||
if (checked) set.add(f.key)
|
||||
else set.delete(f.key)
|
||||
fieldDraft.value = fieldKeysFor([...set])
|
||||
}
|
||||
|
||||
function toggleGroup(g, checked) {
|
||||
const set = new Set(fieldDraft.value)
|
||||
for (const k of editableKeys(g)) {
|
||||
if (checked) set.add(k)
|
||||
else set.delete(k)
|
||||
}
|
||||
fieldDraft.value = fieldKeysFor([...set])
|
||||
}
|
||||
|
||||
function toggleAll(checked) {
|
||||
const scope = checked ? visibleGroups.value : FIELD_GROUPS
|
||||
const set = new Set(fieldDraft.value)
|
||||
for (const g of scope) {
|
||||
for (const k of editableKeys(g)) {
|
||||
if (checked) set.add(k)
|
||||
else set.delete(k)
|
||||
}
|
||||
}
|
||||
fieldDraft.value = fieldKeysFor([...set])
|
||||
}
|
||||
|
||||
function applyPreset() {
|
||||
fieldDraft.value = fieldKeysFor(DEFAULT_KEYS)
|
||||
ElMessage.success(`已恢复平台默认勾选的 ${fieldDraft.value.length} 个字段`)
|
||||
}
|
||||
|
||||
function confirmFields() {
|
||||
form.export_fields = fieldKeysFor(fieldDraft.value)
|
||||
fieldDialog.value = false
|
||||
ElMessage.success(`已选 ${form.export_fields.length} 个字段`)
|
||||
}
|
||||
|
||||
// 调用壳子本机接口打开原生「选择文件夹」对话框(壳子 /api/dialog/directory,仅返回路径)
|
||||
const picking = ref(false)
|
||||
async function pickDir() {
|
||||
@@ -352,4 +572,31 @@ watch(loaded, (v) => {
|
||||
.dir-ctrl { display: flex; align-items: center; gap: var(--space-2); width: 100%; }
|
||||
.dir-ctrl .dir-input { flex: 1 1 auto; min-width: 0; }
|
||||
.dir-ctrl .dir-btn { flex: 0 0 auto; }
|
||||
/* 开关类设置并排:宽屏一行 2~3 个,窄屏自动换行(不再一个开关一行) */
|
||||
.rows-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
align-items: stretch;
|
||||
}
|
||||
.rows-grid .row { height: 100%; }
|
||||
|
||||
/* 自定义字段:方案单选 + 入口按钮 + 说明,同一行 */
|
||||
.field-ctrl { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); width: 100%; }
|
||||
.field-ctrl .field-btn { flex: 0 0 auto; }
|
||||
.field-hint { font-size: 12px; opacity: .65; }
|
||||
.field-hint.is-warn { opacity: 1; color: var(--el-color-warning); }
|
||||
.co-note { margin-left: 4px; font-size: 11.5px; opacity: .6; }
|
||||
|
||||
/* 字段选择弹窗 */
|
||||
.fd-head { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-3); }
|
||||
.fd-head .fd-search { flex: 1 1 auto; min-width: 0; }
|
||||
.fd-body { max-height: 56vh; overflow: auto; padding-right: 4px; }
|
||||
.fd-group { border: 1px solid var(--el-border-color-lighter); border-radius: 6px; padding: 8px 12px 4px; margin-bottom: 10px; }
|
||||
.fd-group-head { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px dashed var(--el-border-color-lighter); padding-bottom: 4px; margin-bottom: 6px; }
|
||||
.fd-count { font-size: 12px; opacity: .6; }
|
||||
.fd-items { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px 8px; }
|
||||
.fd-item { margin-right: 0; }
|
||||
.fd-tag { margin-left: 4px; font-size: 11px; opacity: .55; border: 1px solid currentColor; border-radius: 3px; padding: 0 3px; }
|
||||
.fd-empty { padding: 24px 0; text-align: center; opacity: .6; }
|
||||
.fd-total { float: left; font-size: 12px; opacity: .7; line-height: 32px; }
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
// 核销明细导出字段目录(平台 get_field_config 实测,2026-11-05 生成;平台改字段后重新生成)
|
||||
// locked = 系统默认字段(必选且不可取消)
|
||||
export const FIELD_GROUPS = [
|
||||
{
|
||||
label: "订单基础信息",
|
||||
fields: [
|
||||
{ key: "shop_order_id", name: "订单编号", locked: true, preset: true },
|
||||
{ key: "order_tags", name: "订单标签", locked: true, preset: true },
|
||||
{ key: "create_time", name: "下单时间", locked: true, preset: true },
|
||||
{ key: "pay_time", name: "支付时间", locked: true, preset: true },
|
||||
{ key: "deposit_pay_time", name: "订金支付时间", locked: false, preset: false },
|
||||
{ key: "balance_pay_time", name: "尾款支付时间", locked: false, preset: false },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "核销信息",
|
||||
fields: [
|
||||
{ key: "verify_id", name: "核销记录ID", locked: false, preset: false },
|
||||
{ key: "code", name: "券码(已撤销核销加密)", locked: true, preset: true },
|
||||
{ key: "poi_province", name: "核销门店省份", locked: false, preset: true },
|
||||
{ key: "poi_city", name: "核销门店城市", locked: false, preset: false },
|
||||
{ key: "poi_id", name: "核销门店ID", locked: true, preset: true },
|
||||
{ key: "poi_name", name: "核销门店", locked: true, preset: true },
|
||||
{ key: "poi_name_remark", name: "核销门店名称备注", locked: false, preset: false },
|
||||
{ key: "poi_id_remark", name: "核销门店编号备注", locked: false, preset: false },
|
||||
{ key: "verify_status", name: "核销状态", locked: true, preset: true },
|
||||
{ key: "verifier_account", name: "核销人账号", locked: false, preset: false },
|
||||
{ key: "verifier_name", name: "核销人昵称", locked: false, preset: true },
|
||||
{ key: "verifier_id", name: "核销人ID", locked: false, preset: true },
|
||||
{ key: "fulfil_type_str", name: "核销方式", locked: false, preset: false },
|
||||
{ key: "verify_time_str", name: "核销时间", locked: true, preset: true },
|
||||
{ key: "use_complete_time_str", name: "使用完成时间", locked: true, preset: true },
|
||||
{ key: "cancel_time_str", name: "撤销核销时间", locked: false, preset: true },
|
||||
{ key: "external_good_id", name: "外部货号", locked: false, preset: false },
|
||||
{ key: "merchant_remark", name: "商家备注", locked: false, preset: false },
|
||||
{ key: "write_off_gift", name: "赠品信息", locked: false, preset: true },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "商品信息",
|
||||
fields: [
|
||||
{ key: "product_name", name: "商品名称", locked: true, preset: true },
|
||||
{ key: "product_type_name", name: "商品类型", locked: true, preset: true },
|
||||
{ key: "product_id", name: "商品ID", locked: true, preset: true },
|
||||
{ key: "category_name", name: "商品类目", locked: false, preset: true },
|
||||
{ key: "product_owner_type", name: "商品归属", locked: false, preset: false },
|
||||
{ key: "product_owner_account_name", name: "商品归属商户", locked: true, preset: true },
|
||||
{ key: "product_owner_account_id", name: "商品归属商户ID", locked: true, preset: true },
|
||||
{ key: "item_num", name: "购买数量", locked: true, preset: true },
|
||||
{ key: "product_sale_currency", name: "商品售价币种", locked: false, preset: false },
|
||||
{ key: "product_actual_amount", name: "商品售价(单价)", locked: true, preset: true },
|
||||
{ key: "product_origin_amount", name: "用户侧划线价", locked: false, preset: true },
|
||||
{ key: "once_origin_amount", name: "单次划线价", locked: false, preset: false },
|
||||
{ key: "voucher_verify_info", name: "代金券面额", locked: false, preset: false },
|
||||
{ key: "combo_product_name", name: "组合商品名称", locked: false, preset: false },
|
||||
{ key: "combo_product_amount", name: "组合商品价格", locked: false, preset: false },
|
||||
{ key: "sale_specs", name: "商品规格", locked: true, preset: true },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "券金额信息",
|
||||
fields: [
|
||||
{ key: "pay_amount_currency", name: "用户实付币种", locked: false, preset: true },
|
||||
{ key: "pay_amount_str", name: "用户实付", locked: true, preset: true },
|
||||
{ key: "payment_amount_currency", name: "订单实收币种", locked: false, preset: true },
|
||||
{ key: "payment_amount", name: "订单实收", locked: true, preset: true },
|
||||
{ key: "deposit_pay_amount", name: "订金实付金额", locked: false, preset: false },
|
||||
{ key: "balance_pay_amount", name: "尾款实付金额", locked: false, preset: false },
|
||||
{ key: "merchant_amount_currency", name: "预计收入币种", locked: false, preset: true },
|
||||
{ key: "merchant_amount", name: "预计收入", locked: false, preset: true },
|
||||
{ key: "purchase_fee", name: "采购价", locked: false, preset: false },
|
||||
{ key: "benefit_verify_amount", name: "惠享卡核销金额", locked: false, preset: false },
|
||||
{ key: "benefit_left_principal_amount", name: "惠享卡本金核销余额", locked: false, preset: false },
|
||||
{ key: "benefit_left_benefit_amount", name: "惠享卡赠送金核销余额", locked: false, preset: false },
|
||||
{ key: "merchant_funder_discount", name: "代商家出资补贴", locked: false, preset: true },
|
||||
{ key: "merchant_discount_detail", name: "商家补贴优惠明细", locked: true, preset: true },
|
||||
{ key: "merchant_discount_amount2", name: "商家货款补贴", locked: false, preset: true },
|
||||
{ key: "pay_discount", name: "抖音支付优惠", locked: false, preset: true },
|
||||
{ key: "platform_discount_amount", name: "平台补贴", locked: false, preset: true },
|
||||
{ key: "platform_discount_detail", name: "平台补贴优惠明细", locked: false, preset: true },
|
||||
{ key: "brand_discount_amount", name: "品牌商补贴", locked: false, preset: true },
|
||||
{ key: "brand_discount_detail", name: "品牌商补贴优惠明细", locked: false, preset: true },
|
||||
{ key: "provider_discount_amount", name: "服务商补贴", locked: false, preset: true },
|
||||
{ key: "provider_discount_detail", name: "服务商补贴优惠明细", locked: false, preset: true },
|
||||
{ key: "government_voucher_discount_amount", name: "政府补贴", locked: false, preset: true },
|
||||
{ key: "government_voucher_discount_detail", name: "政府补贴优惠明细", locked: false, preset: true },
|
||||
{ key: "combined_hote_sale_price", name: "酒店房价", locked: false, preset: false },
|
||||
{ key: "combined_scenic_sale_price", name: "景区分销金额", locked: false, preset: false },
|
||||
{ key: "commission_base", name: "各类服务费率基数", locked: false, preset: true },
|
||||
{ key: "platform_service_amount", name: "软件服务费", locked: false, preset: true },
|
||||
{ key: "platform_service_rate", name: "软件服务费率", locked: false, preset: true },
|
||||
{ key: "ybq_fee", name: "出单宝托管服务费", locked: false, preset: true },
|
||||
{ key: "ybq_fee_rate", name: "出单宝托管服务费率", locked: false, preset: true },
|
||||
{ key: "ybq_platform_fee", name: "平台费用抵扣", locked: false, preset: true },
|
||||
{ key: "handling_fee_amount", name: "支付手续费(已含在软件服务费中)", locked: false, preset: true },
|
||||
{ key: "handling_fee_rate", name: "支付手续费费率", locked: false, preset: true },
|
||||
{ key: "talent_commission_amount", name: "达人服务费", locked: false, preset: true },
|
||||
{ key: "talent_commission_rate", name: "达人服务费比例", locked: false, preset: true },
|
||||
{ key: "craftsman_commission_amount", name: "职人激励金", locked: false, preset: true },
|
||||
{ key: "craftsman_commission_rate", name: "职人激励金比例", locked: false, preset: true },
|
||||
{ key: "broker_commission_amount", name: "团长服务费", locked: false, preset: true },
|
||||
{ key: "agent_commission_amount", name: "服务商服务费", locked: false, preset: true },
|
||||
{ key: "agent_commission_rate", name: "服务商服务费比例", locked: false, preset: true },
|
||||
{ key: "agent_account_name", name: "服务商名称", locked: false, preset: true },
|
||||
{ key: "insurance_commission_amount", name: "保险费用", locked: false, preset: true },
|
||||
{ key: "welfare_donation", name: "公益捐赠", locked: false, preset: false },
|
||||
{ key: "clerk_commission_amount", name: "店员激励金", locked: false, preset: true },
|
||||
{ key: "clerk_commission_rate", name: "店员激励金比例", locked: false, preset: true },
|
||||
{ key: "month_pay_interest", name: "月付贴息", locked: false, preset: true },
|
||||
{ key: "zlb_promotion_fee", name: "增量宝", locked: false, preset: true },
|
||||
{ key: "content_production_fee", name: "AIGC 服务费", locked: false, preset: true },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "渠道信息",
|
||||
fields: [
|
||||
{ key: "sale_channel", name: "成交渠道", locked: false, preset: true },
|
||||
{ key: "app_source", name: "下单来源", locked: false, preset: true },
|
||||
{ key: "media_url", name: "内容地址", locked: false, preset: false },
|
||||
{ key: "sale_role", name: "带货角色", locked: false, preset: true },
|
||||
{ key: "sale_user_nickname", name: "带货人", locked: false, preset: true },
|
||||
{ key: "transform_nickname", name: "订单归属人昵称(字段如果获取不到就默认展示商家,如对账以账单为主)", locked: false, preset: true },
|
||||
{ key: "transform_uid", name: "订单归属人uid", locked: false, preset: true },
|
||||
{ key: "talent_aweme_nickname", name: "达人昵称", locked: false, preset: true },
|
||||
{ key: "talent_aweme_unique_id", name: "达人抖音号", locked: false, preset: true },
|
||||
{ key: "talent_aweme_uid", name: "达人uid", locked: false, preset: true },
|
||||
{ key: "craftsman_aweme_nickname", name: "职人昵称", locked: false, preset: false },
|
||||
{ key: "craftsman_aweme_unique_id", name: "职人抖音号", locked: false, preset: false },
|
||||
{ key: "craftsman_aweme_uid", name: "职人uid", locked: false, preset: false },
|
||||
{ key: "clerk_aweme_nickname", name: "店员昵称", locked: false, preset: false },
|
||||
{ key: "clerk__aweme_unique_id", name: "店员抖音号", locked: false, preset: false },
|
||||
{ key: "clerk_aweme_uid", name: "店员uid", locked: false, preset: false },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "提货信息",
|
||||
fields: [
|
||||
{ key: "pick_up_spec", name: "提货规格", locked: false, preset: true },
|
||||
{ key: "pick_up_validate_end_time", name: "提货截止时间", locked: false, preset: true },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
export const LOCKED_KEYS = FIELD_GROUPS.flatMap((g) => g.fields.filter((f) => f.locked).map((f) => f.key))
|
||||
|
||||
// 预勾选 = 系统默认 + 平台默认勾选(用户首次切到自定义字段时用)
|
||||
export const DEFAULT_KEYS = FIELD_GROUPS.flatMap((g) => g.fields.filter((f) => f.preset).map((f) => f.key))
|
||||
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -4,8 +4,8 @@
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>抖音平台核对</title>
|
||||
<script type="module" crossorigin src="/pui/xq0042/assets/index-n9vLqOmI.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/pui/xq0042/assets/index-C6qgsB3L.css">
|
||||
<script type="module" crossorigin src="/pui/xq0042/assets/index-DIiggrI1.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/pui/xq0042/assets/index-mhuQMXFK.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
||||
Reference in New Issue
Block a user