feat(xq0042): 新增默认区间开关(金色印象3天/金色湖畔2天)并重建前端(0.9.8)

This commit is contained in:
2026-11-10 09:38:34 +08:00
parent 2ade0efb35
commit fd338e70c4
12 changed files with 252 additions and 144 deletions
@@ -3,6 +3,7 @@
打开抖音来客 → 人工登录(含验证码/滑块,浏览器里一次性完成,之后复用登录态)
→ 按日期区间导出「核销明细」(履约管理订单列表)与「提现记录」(财务导出记录)
区间留空时按公司默认天数:金色印象 3 天(前日 ~ 今日)、金色湖畔 2 天(昨日 ~ 今日)
→ 轮询生成状态 → 下载到本机目录(默认 D:\\资料\\财务\\抖音平台核对)
→ 核销明细增量并入台账「抖音到账统计YYYY.M月.xlsx」的「金色印象--抖音」sheet。
→ 再按日期给「抖音到账核对」O/P 列补共享总表(资金组取数)外部取数公式。
@@ -29,12 +30,22 @@ def _parse_day(s):
return None
def _resolve_pair(raw_from, raw_to):
"""解析日期区间:都空=昨天~今天;只给一端=单日;起止颠倒自动换序。"""
def _default_days(raw):
"""默认导出天数(含今天):非法/小于 1 则回退 config.DEFAULT_EXPORT_DAYS。"""
try:
days = int(raw)
except (TypeError, ValueError):
return config.DEFAULT_EXPORT_DAYS
return days if days >= 1 else config.DEFAULT_EXPORT_DAYS
def _resolve_pair(raw_from, raw_to, default_days=None):
"""解析日期区间:都空=按公司默认天数(today-(N-1) ~ today);只给一端=单日;起止颠倒自动换序。"""
d1 = _parse_day(raw_from) if raw_from else None
d2 = _parse_day(raw_to) if raw_to else None
if d1 is None and d2 is None:
return ((date.today() - timedelta(days=1)).isoformat(), date.today().isoformat())
days = _default_days(default_days)
return ((date.today() - timedelta(days=days - 1)).isoformat(), date.today().isoformat())
if d1 is None:
d1 = d2
if d2 is None:
@@ -44,6 +55,13 @@ def _resolve_pair(raw_from, raw_to):
return d1.isoformat(), d2.isoformat()
def _company_ranges(company, raws):
"""按公司默认天数解析(核销区间, 提现区间);显式填了日期则各公司一致。"""
days = _default_days((company or {}).get('default_days'))
v_from, v_to, w_from, w_to = raws
return (_resolve_pair(v_from, v_to, days), _resolve_pair(w_from, w_to, days))
def _limit(raw, default):
"""导出记录保留阈值:非法/过小则回退默认值。"""
try:
@@ -79,8 +97,9 @@ def _companies(run_mode):
class Xq0042Plugin(ScenePlugin):
id = 'xq0042'
name = '抖音平台核对'
version = '0.9.4'
description = ('抖音来客数据自动导出:登录后按日期区间导出核销明细(字段可选平台默认或自定义勾选)、'
version = '0.9.8'
description = ('抖音来客数据自动导出:登录后按日期区间导出核销明细(字段可选平台默认或自定义勾选,'
'区间留空按公司默认天数:金色印象前日~今日、金色湖畔昨日~今日)、'
'提现记录,轮询生成完成后下载到本机目录,核销明细增量并入台账「金色印象--抖音」'
'(公式列自动下拉),并按日期把「抖音到账核对」整行同源取数公式'
'(资金组取数)换成当天共享总表的链接;导出记录超阈值自动删最早的')
@@ -89,6 +108,7 @@ class Xq0042Plugin(ScenePlugin):
capabilities = ['xq0042']
permissions = {'platforms': []}
fields = {
'auto_range': {'type': 'boolean', 'title': '默认区间', 'default': True},
'date_from': {'type': 'string', 'title': '核销时间-开始日期', 'default': ''},
'date_to': {'type': 'string', 'title': '核销时间-结束日期', 'default': ''},
'withdraw_from': {'type': 'string', 'title': '提现时间-开始日期', 'default': ''},
@@ -118,8 +138,13 @@ class Xq0042Plugin(ScenePlugin):
config.set_progress(ctx.progress)
config.set_debug(fields.get('debug_mode'))
v_from, v_to = _resolve_pair(fields.get('date_from'), fields.get('date_to'))
w_from, w_to = _resolve_pair(fields.get('withdraw_from'), fields.get('withdraw_to'))
# 日期区间原样保留:留空时按各公司默认天数解析(印象 3 天 / 湖畔 2 天)
raws = (fields.get('date_from'), fields.get('date_to'),
fields.get('withdraw_from'), fields.get('withdraw_to'))
# auto_range=True(界面「默认区间」):忽略手填日期,一律按各公司天数推算;
# 未传该键(老定时任务/老配置)时保持原语义,用手填日期
if fields.get('auto_range'):
raws = ('', '', '', '')
save_dir = (str(fields.get('save_dir') or '').strip().strip('"')
or config.WORK_DIR)
force = bool(fields.get('force_login'))
@@ -144,17 +169,31 @@ class Xq0042Plugin(ScenePlugin):
config.log('自定义字段未勾选,本次按「系统默认字段 + 台账必需列」执行', 'WARN')
companies = _companies(run_mode)
ranges_by_company = [] # [(公司简称, 核销区间, 提现区间)]
for comp in companies:
v_pair, w_pair = _company_ranges(comp, raws)
ranges_by_company.append((comp.get('short') or comp['id'], v_pair, w_pair))
v_from, v_to = ranges_by_company[0][1]
w_from, w_to = ranges_by_company[0][2]
range_map = {name: (v_pair, w_pair) for name, v_pair, w_pair in ranges_by_company}
def _range_text(show_company=True):
items = []
for name, v_pair, w_pair in ranges_by_company:
segs = []
if do_verify:
segs.append(f'核销 {v_pair[0]} ~ {v_pair[1]}')
if do_withdraw:
segs.append(f'提现 {w_pair[0]} ~ {w_pair[1]}')
seg = ';'.join(segs)
items.append(f'{name}:{seg}' if show_company else seg)
return '|'.join(items)
kinds = [k for k, on in (('核销明细', do_verify), ('提现记录', do_withdraw)) if on]
ranges = []
if do_verify:
ranges.append(f'核销 {v_from} ~ {v_to}')
if do_withdraw:
ranges.append(f'提现 {w_from} ~ {w_to}')
ranges = [_range_text(len(ranges_by_company) > 1)]
plan = []
if do_download:
plan.append(f'导出{"、".join(kinds)}({";".join(ranges)})'
f'公司:{"、".join(c.get("short") or c["id"] for c in companies)}'
f' → {save_dir}')
plan.append(f'导出{"、".join(kinds)}({";".join(ranges)})→ {save_dir}')
if do_verify:
if field_mode == config.FIELD_MODE_DEFAULT:
plan.append('核销明细字段=平台默认字段')
@@ -193,15 +232,16 @@ class Xq0042Plugin(ScenePlugin):
done = 0
for comp in companies:
short = comp.get('short') or comp['id']
c_v, c_w = range_map.get(short, ((v_from, v_to), (w_from, w_to)))
if do_verify:
results[f'{short}·核销明细'] = douyin_export.run(
page, v_from, v_to, save_dir, limit_verify,
page, c_v[0], c_v[1], 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)
page, c_w[0], c_w[1], save_dir, limit_withdraw, comp)
done += 1
config.progress(30 + int(60 * done / max(steps, 1)))
finally:
@@ -248,6 +288,8 @@ 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,
'date_ranges': {name: {'verify': list(v_pair), 'withdraw': list(w_pair)}
for name, v_pair, w_pair in ranges_by_company},
'run_mode': run_mode,
'export_field_mode': field_mode,
'companies': [c.get('short') or c['id'] for c in companies],