feat(xq0041): 经营宝登录改人工点确认 + 双公司独立档案与执行模式拆分(1.3.9)

- 登录改为自动填账号密码并勾选用户协议,页面右上角浮层提示人工点「登录」(按钮、滑块/短信、选门店仍人工),登录一次长期复用

- 金色印象 / 金色湖畔各自独立浏览器档案与调试端口(xq0041 / xq0041_b,9222 / 9333),避免同浏览器反复切号触发风控

- 执行模式拆 full(只导金色印象 + 并台账 + 更新核对统计)/ export_only(按范围勾选各导一份,不写表),湖畔报表文件名带「金色湖畔_」前缀;UI 同步重建
This commit is contained in:
2026-11-06 15:52:10 +08:00
parent 8cf38ba3b6
commit 911fd7661f
12 changed files with 827 additions and 247 deletions
@@ -8,6 +8,14 @@
更新核对统计(适合数据已下载、只想重算的场景);
action='all' → 下载后再核对(默认)。
多公司(对齐 xq0042 抖音平台核对):金色印象(台账那家)与金色湖畔在平台上是两套登录,
各自用独立的浏览器档案与调试端口(browser_sessions/xq0041 与 xq0041_b,端口 9222 / 9333),
登录态互不干扰,避免同浏览器反复切号触发风控。
run_mode='full' → 只导金色印象 + 并入台账 + 更新核对统计(默认,历史行为)
run_mode='export_only' → 按 export_companies 勾选的公司各导一份(可只导一家),不写任何表
(湖畔文件名带「金色湖畔_」前缀)
并入台账 / 更新核对统计只认金色印象那份明细(湖畔文件天然落在台账 glob 之外)。
签名说明:平台接口的签名参数由页面自身的前端组件生成,插件只在页面上下文发起请求,
不涉及任何签名算法。
"""
@@ -69,20 +77,31 @@ def _resolve_action(fields):
class Xq0041Plugin(ScenePlugin):
id = 'xq0041'
name = '新美大平台核对'
version = '1.1.14'
version = '1.3.8'
description = ('美团经营宝账单自动下载与台账核对:按需下载打款记录、团购收益明细、'
'预订收益明细,把新产生的收益按验券时间并入月份台账,'
'并按日期把核对统计表整行同源取数公式(资金组取数)换成当天共享总表的链接;'
'界面可配账号密码自动登录并自动选「非餐饮商家版」(验证码/具体门店仍需人工)')
'界面可配账号密码自动填好并勾选用户协议、浏览器内浮层提示你点登录'
'(登录按钮/验证码/选门店仍人工),并自动选「非餐饮商家版」;'
'执行模式分「含写表」(只导金色印象 + 并台账 + 更新核对统计)与'
'「仅导出」(金色印象 / 金色湖畔按需勾选,可只导一家,不写表),'
'两家各自独立浏览器档案与调试端口,登录态互不干扰')
platform = '' # 插件自带登录(经营宝 SSO + 选商家),不用底座共享登录态
uses_month = False
capabilities = ['xq0041']
permissions = {'platforms': []}
# 与 plugin.json.fields 一致(ui=true,前端按此渲染表单)
fields = {
'mt_username': {'type': 'string', 'title': '经营宝账号', 'default': ''},
'mt_password': {'type': 'string', 'title': '经营宝登录密码', 'default': '',
'mt_username': {'type': 'string', 'title': '金色印象-经营宝账号', 'default': ''},
'mt_password': {'type': 'string', 'title': '金色印象-登录密码', 'default': '',
'format': 'password'},
'mt2_username': {'type': 'string', 'title': '金色湖畔-经营宝账号', 'default': ''},
'mt2_password': {'type': 'string', 'title': '金色湖畔-登录密码', 'default': '',
'format': 'password'},
'run_mode': {'type': 'string', 'title': '执行模式', 'default': config.RUN_MODE_FULL,
'enum': [config.RUN_MODE_FULL, config.RUN_MODE_EXPORT_ONLY]},
'export_companies': {'type': 'array', 'title': '导出范围(仅导出模式生效)',
'default': ['a', 'b'], 'items': {'type': 'string'}},
'action': {'type': 'string', 'title': '执行过程', 'default': 'all',
'enum': ['all', 'download', 'reconcile']},
'do_download': {'type': 'boolean', 'title': '下载数据', 'default': True},
@@ -110,10 +129,17 @@ class Xq0041Plugin(ScenePlugin):
# ---------- 参数 ----------
action = _resolve_action(fields)
run_mode = config.normalize_run_mode(fields.get('run_mode'))
if run_mode == config.RUN_MODE_EXPORT_ONLY:
# 仅导出:两家公司各导一份,不写任何表(对齐 xq0042 的语义)
if action == 'reconcile':
raise RuntimeError('「仅导出」模式不做核对;要并台账请把执行模式切成「含写表」')
action = 'download'
if not action:
raise RuntimeError('请至少选择一个执行过程(下载数据 / 更新核对)')
do_download = action in ('all', 'download')
do_reconcile = action in ('all', 'reconcile')
export_only = run_mode == config.RUN_MODE_EXPORT_ONLY
codes = []
if fields.get('profit_group', True):
@@ -129,9 +155,14 @@ class Xq0041Plugin(ScenePlugin):
# 保存目录同时是台账目录:并入台账 / 更新核对统计都读它
save_dir = config.set_work_dir(fields.get('save_dir'))
# 登录账号密码(界面配置;留空 = 完全手工登录)
mt_user = str(fields.get('mt_username') or '').strip()
mt_pwd = str(fields.get('mt_password') or '').strip()
# 登录账号密码(界面配置;留空 = 该家手工登录)
# 金色印象 / 金色湖畔 是平台上的两个主体,各自一套账号,导谁用谁的
creds = {
'a': (str(fields.get('mt_username') or '').strip(),
str(fields.get('mt_password') or '').strip()),
'b': (str(fields.get('mt2_username') or '').strip(),
str(fields.get('mt2_password') or '').strip()),
}
if do_download and not pay_on and not codes:
raise RuntimeError('请至少勾选一项要下载的内容(打款记录 / 团购 / 预订)')
@@ -146,8 +177,10 @@ class Xq0041Plugin(ScenePlugin):
fields.get('profit_date_to'))
os.makedirs(save_dir, exist_ok=True)
companies = config.companies_for_mode(run_mode, fields.get('export_companies'))
plan = []
if do_download:
plan.append('公司 ' + ' + '.join(c['short'] for c in companies))
if pay_on:
plan.append(f'打款记录 {pay_from}~{pay_to}')
if codes:
@@ -160,47 +193,78 @@ class Xq0041Plugin(ScenePlugin):
config.log(('本次执行:' + ';'.join(plan) if plan else '本次没有可执行的动作')
+ f';目录 {save_dir}'
+ ('(只核对不写入)' if dry_run else ''))
config.log('执行模式:' + ('仅导出(金色印象 + 金色湖畔,不写表)' if export_only
else '含写表(只导金色印象 + 并台账 + 更新核对统计)'))
detail = {'action': action, 'pay': None, 'profit': None, 'merge': None, 'links': None}
detail = {'action': action, 'run_mode': run_mode, 'pay': None, 'profit': None,
'merge': None, 'links': None, 'results': {},
'companies': [c['short'] for c in companies]}
files = []
# ---------- 1~3:登录 + 下载 ----------
# ---------- 1~3:登录 + 下载(逐家公司:各自独立浏览器档案 + 端口) ----------
if do_download:
ctx.progress(2)
page = browser.open_page(force_login=force_login)
jobs = [(comp, *creds.get(comp['id'], ('', ''))) for comp in companies]
dl_end = 60 if do_reconcile else 95
span = (dl_end - 2) / len(jobs)
errors = []
try:
config.log('登录方式:' + ('界面配置的账号密码自动登录'
if (mt_user and mt_pwd) else '手工登录'))
ok, msg = meituan_login.ensure_login(page, mt_user, mt_pwd)
config.log(msg)
if not ok:
raise RuntimeError(f'登录失败:{msg}')
ctx.progress(20 if do_reconcile else 30)
for i, (comp, user, pwd) in enumerate(jobs):
config.set_company(comp['id'])
label = comp['short']
base = 2 + span * i
ctx.progress(int(base))
if len(jobs) > 1:
config.log(f'—— {label}:档案 {comp["profile"]} / 端口 {comp["port"]} ——')
page = browser.open_page(force_login=force_login)
try:
config.log(f'{label} 登录方式:' + ('界面配置的账号密码自动登录'
if (user and pwd) else '手工登录'))
ok, msg = meituan_login.ensure_login(page, user, pwd)
config.log(msg)
if not ok:
raise RuntimeError(f'{label} 登录失败:{msg}')
ctx.progress(int(base + span * 0.4))
if pay_on:
r1 = payment_download.download(page, pay_from, pay_to, save_dir, dry_run)
if not r1.get('ok'):
raise RuntimeError(f'打款记录下载失败:{r1.get("message")}')
config.log(r1.get('message') or '')
if r1.get('empty'):
# 区间内没有打款记录:正常跳过,不影响收益明细下载与核对
config.log('打款记录区间内无数据,已跳过本项', 'WARN')
elif r1.get('path'):
files.append(r1['path'])
detail['pay'] = r1
ctx.progress(45 if do_reconcile else 65)
if pay_on:
r1 = payment_download.download(page, pay_from, pay_to, save_dir,
dry_run)
if not r1.get('ok'):
raise RuntimeError(f'{label} 打款记录下载失败:{r1.get("message")}')
config.log(r1.get('message') or '')
if r1.get('empty'):
# 区间内没有打款记录:正常跳过,不影响收益明细下载与核对
config.log('打款记录区间内无数据,已跳过本项', 'WARN')
elif r1.get('path'):
files.append(r1['path'])
if comp.get('ledger'):
detail['pay'] = r1
ctx.progress(int(base + span * 0.7))
if codes:
r2 = profit_download.download(page, profit_from, profit_to, save_dir,
codes, dry_run)
if not r2.get('ok'):
raise RuntimeError(f'收益明细下载失败:{r2.get("message")}')
config.log(r2.get('message') or '')
files.extend(r2.get('paths') or [])
detail['profit'] = r2
ctx.progress(60 if do_reconcile else 95)
if codes:
r2 = profit_download.download(page, profit_from, profit_to, save_dir,
codes, dry_run)
if not r2.get('ok'):
raise RuntimeError(f'{label} 收益明细下载失败:{r2.get("message")}')
config.log(r2.get('message') or '')
files.extend(r2.get('paths') or [])
if comp.get('ledger'):
detail['profit'] = r2
ctx.progress(int(base + span))
detail['results'] = detail.get('results') or {}
detail['results'][label] = {'ok': True}
except Exception as e:
if len(jobs) == 1:
raise
config.log(f'{label} 导出失败:{e}', 'ERROR')
errors.append(str(e))
detail['results'] = detail.get('results') or {}
detail['results'][label] = {'ok': False, 'message': str(e)}
finally:
browser.close_page(page)
finally:
browser.close_page(page)
config.set_company('a')
if errors:
raise RuntimeError(';'.join(errors))
# ---------- 4~5:并入台账 + 更新核对(不依赖浏览器) ----------
if do_reconcile: