From 911fd7661f221b743c6c4658a42049a8a745bf8a Mon Sep 17 00:00:00 2001 From: spudding <1115683088@qq.com> Date: Fri, 6 Nov 2026 15:52:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(xq0041):=20=E7=BB=8F=E8=90=A5=E5=AE=9D?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=94=B9=E4=BA=BA=E5=B7=A5=E7=82=B9=E7=A1=AE?= =?UTF-8?q?=E8=AE=A4=20+=20=E5=8F=8C=E5=85=AC=E5=8F=B8=E7=8B=AC=E7=AB=8B?= =?UTF-8?q?=E6=A1=A3=E6=A1=88=E4=B8=8E=E6=89=A7=E8=A1=8C=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E6=8B=86=E5=88=86=EF=BC=881.3.9=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 登录改为自动填账号密码并勾选用户协议,页面右上角浮层提示人工点「登录」(按钮、滑块/短信、选门店仍人工),登录一次长期复用 - 金色印象 / 金色湖畔各自独立浏览器档案与调试端口(xq0041 / xq0041_b,9222 / 9333),避免同浏览器反复切号触发风控 - 执行模式拆 full(只导金色印象 + 并台账 + 更新核对统计)/ export_only(按范围勾选各导一份,不写表),湖畔报表文件名带「金色湖畔_」前缀;UI 同步重建 --- .../XQ0041 新美大平台核对/__init__.py | 144 +++++--- .../XQ0041 新美大平台核对/config/__init__.py | 108 +++++- .../XQ0041 新美大平台核对/data/browser.py | 34 +- .../data/meituan_login.py | 338 ++++++++++++++---- .../data/payment_download.py | 36 +- .../data/profit_download.py | 4 +- .../logic/merge_ledger.py | 6 +- .../XQ0041 新美大平台核对/plugin.json | 47 ++- .../XQ0041 新美大平台核对/ui-src/src/App.vue | 309 +++++++++++----- ...{index-Du0XtKs7.css => index-BVdn0lhW.css} | 2 +- .../{index-CBLp7rYV.js => index-BcCXU4Vw.js} | 42 +-- .../XQ0041 新美大平台核对/ui/index.html | 4 +- 12 files changed, 827 insertions(+), 247 deletions(-) rename plugins/XQ0001-0100/XQ0041 新美大平台核对/ui/assets/{index-Du0XtKs7.css => index-BVdn0lhW.css} (99%) rename plugins/XQ0001-0100/XQ0041 新美大平台核对/ui/assets/{index-CBLp7rYV.js => index-BcCXU4Vw.js} (53%) diff --git a/plugins/XQ0001-0100/XQ0041 新美大平台核对/__init__.py b/plugins/XQ0001-0100/XQ0041 新美大平台核对/__init__.py index 47ee68e..bf3396d 100644 --- a/plugins/XQ0001-0100/XQ0041 新美大平台核对/__init__.py +++ b/plugins/XQ0001-0100/XQ0041 新美大平台核对/__init__.py @@ -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: diff --git a/plugins/XQ0001-0100/XQ0041 新美大平台核对/config/__init__.py b/plugins/XQ0001-0100/XQ0041 新美大平台核对/config/__init__.py index 7bfaedb..0c8167a 100644 --- a/plugins/XQ0001-0100/XQ0041 新美大平台核对/config/__init__.py +++ b/plugins/XQ0001-0100/XQ0041 新美大平台核对/config/__init__.py @@ -51,6 +51,7 @@ LEDGER_SHEET = '金色印象--新美大导出(收)' STAT_SHEET = '新美大核对统计' TIME_COL = '验券/退款/调整时间' DETAIL_GLOB = '团购收益明细_*.xlsx' +# 金色湖畔的明细带「金色湖畔_」前缀,天然匹配不到上面的 glob → 并入台账只认金色印象那份 HEADER_ROW = 2 DATA_START_ROW = 3 @@ -71,10 +72,11 @@ def set_work_dir(path=None): WORK_DIR = p or DEFAULT_WORK_DIR return WORK_DIR -# ==================== 账号密码自动登录(可选,界面配置) ==================== +# ==================== 账号密码预填(可选,界面配置) ==================== +# 只预填账号密码 + 勾「用户协议」,**不点登录**:登录按钮、滑块/图形验证码、 +# 短信验证码、选商家全部由用户在浏览器里自己完成(脚本只等结果)。 AUTOFILL_WAIT = 45 # 等登录页账号密码输入框出现的最长时间(登录页异步渲染/多次重定向) AUTOFILL_POLL = 1.5 -AUTOFILL_SUBMIT_DELAY = 1.2 # 填完账号密码后等前端校验再点「登录」 # 登录表单不一定在主文档里:实测 ecom.meituan.com 的登录页是内嵌 iframe # (