feat(xq0041): 经营宝登录改人工点确认 + 双公司独立档案与执行模式拆分(1.3.9)
- 登录改为自动填账号密码并勾选用户协议,页面右上角浮层提示人工点「登录」(按钮、滑块/短信、选门店仍人工),登录一次长期复用 - 金色印象 / 金色湖畔各自独立浏览器档案与调试端口(xq0041 / xq0041_b,9222 / 9333),避免同浏览器反复切号触发风控 - 执行模式拆 full(只导金色印象 + 并台账 + 更新核对统计)/ export_only(按范围勾选各导一份,不写表),湖畔报表文件名带「金色湖畔_」前缀;UI 同步重建
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
# (<div class="loginBox"><iframe class="loginFormContent"
|
||||
@@ -97,6 +99,7 @@ LOGIN_WAIT = 600 # 等待人工登录(含验证码/选商家)超时
|
||||
BACKEND_STABLE = 20 # 后台页连续稳定秒数(/meishi 未登录也会停留约 20s 再跳)
|
||||
SETTLE_WAIT = 8 # 登录成功后等首屏请求结束再抓 cookie
|
||||
POLL_SECONDS = 2
|
||||
POLL_LOG_EVERY = 10 # 轮询等待日志节流(秒),避免 2s 一条刷屏
|
||||
RECORD_SECONDS = 120 # 账单生成后轮询记录的最长时间
|
||||
REUSE_MAX_AGE_MIN = 10 # 账单复用时效:记录生成时间距今 ≤ N 分钟才复用
|
||||
RETRY_MAX = 3
|
||||
@@ -110,15 +113,102 @@ def _app_data_dir():
|
||||
|
||||
|
||||
SESSIONS_DIR = os.path.join(_app_data_dir(), '.sessions')
|
||||
COOKIE_FILE = os.path.join(SESSIONS_DIR, 'meituan_cookies.json')
|
||||
COOKIE_HEADER_FILE = os.path.join(SESSIONS_DIR, 'meituan_cookies_header.txt')
|
||||
TOKEN_FILE = os.path.join(SESSIONS_DIR, 'meituan_tokens.json')
|
||||
META_FILE = os.path.join(SESSIONS_DIR, 'meituan_session_meta.json')
|
||||
|
||||
|
||||
def get_browser_profile_dir():
|
||||
"""独立固定浏览器用户目录:登录态跨次保留,不占用日常 Chrome 配置。"""
|
||||
return os.path.join(_app_data_dir(), 'browser_sessions', 'xq0041')
|
||||
# ==================== 公司与账号档案(对齐 xq0042 的多公司模式) ====================
|
||||
# 美团经营宝按主体分账号:金色印象(台账那家)与金色湖畔(只导出、不写表)。
|
||||
# 两个主体在平台上是两套登录,实测必须各自独立浏览器档案 + 独立端口,
|
||||
# 否则在同一档案里反复切号(清 Cookie 重新登录)最容易触发风控/验证码。
|
||||
# ledger=True 的那家:报表文件名保持原名(台账 glob 只认它,不会串);
|
||||
# ledger=False 的那家:文件名加「金色湖畔_」前缀,既避免同日互相覆盖,也天然被台账 glob 排除。
|
||||
COMPANIES = (
|
||||
{'id': 'a', 'short': '金色印象',
|
||||
'profile': 'xq0041', 'port': 9222, 'file_prefix': '', 'ledger': True},
|
||||
{'id': 'b', 'short': '金色湖畔',
|
||||
'profile': 'xq0041_b', 'port': 9333, 'file_prefix': '金色湖畔_', 'ledger': False},
|
||||
)
|
||||
|
||||
_cur_company = 'a'
|
||||
COOKIE_FILE = ''
|
||||
COOKIE_HEADER_FILE = ''
|
||||
TOKEN_FILE = ''
|
||||
META_FILE = ''
|
||||
|
||||
|
||||
# ==================== 执行模式 ====================
|
||||
# export_only:仅导出(两家都导,不并台账、不更新核对统计);
|
||||
# full:含写表(只导 ledger=True 的金色印象,导出后并台账 + 更新核对统计)。
|
||||
RUN_MODE_EXPORT_ONLY = 'export_only'
|
||||
RUN_MODE_FULL = 'full'
|
||||
_RUN_MODE_EXPORT_ONLY_ALIASES = ('export_only', 'export', '仅导出', '只导出')
|
||||
|
||||
|
||||
def normalize_run_mode(raw):
|
||||
"""执行模式归一:未配置/未知 → 含写表(保持历史行为)。"""
|
||||
text = str(raw or '').strip().lower()
|
||||
return RUN_MODE_EXPORT_ONLY if text in _RUN_MODE_EXPORT_ONLY_ALIASES else RUN_MODE_FULL
|
||||
|
||||
|
||||
def get_company(cid=None):
|
||||
"""取公司配置(默认当前档案);未知 id 回退第一家。"""
|
||||
key = str(cid if cid is not None else _cur_company).strip().lower()
|
||||
return next((dict(c) for c in COMPANIES if c['id'] == key), dict(COMPANIES[0]))
|
||||
|
||||
|
||||
def companies_for_mode(mode, picks=None):
|
||||
"""模式 + 勾选 → 要导出的公司列表。
|
||||
|
||||
仅导出:按 picks(公司 id 列表)挑,没勾或全是非法值 → 退回全部公司;
|
||||
含写表:只导 ledger=True 的金色印象(台账只有这一家的 sheet)。
|
||||
"""
|
||||
if normalize_run_mode(mode) == RUN_MODE_EXPORT_ONLY:
|
||||
want = [str(x).strip().lower() for x in (picks or []) if str(x).strip()]
|
||||
picked = [dict(c) for c in COMPANIES if c['id'] in want] if want else []
|
||||
return picked or [dict(c) for c in COMPANIES]
|
||||
picked = [dict(c) for c in COMPANIES if c.get('ledger')]
|
||||
return picked or [dict(COMPANIES[0])]
|
||||
|
||||
|
||||
def set_company(cid='a'):
|
||||
"""切换当前档案(连带切换 cookie 落盘文件),返回生效的公司配置。
|
||||
|
||||
meituan_login 直接读 config.COOKIE_FILE 等模块属性,这里改全局即全局生效。
|
||||
"""
|
||||
global _cur_company, COOKIE_FILE, COOKIE_HEADER_FILE, TOKEN_FILE, META_FILE
|
||||
comp = get_company(cid)
|
||||
_cur_company = comp['id']
|
||||
suffix = '' if comp['id'] == 'a' else f"_{comp['id']}"
|
||||
COOKIE_FILE = os.path.join(SESSIONS_DIR, f'meituan_cookies{suffix}.json')
|
||||
COOKIE_HEADER_FILE = os.path.join(SESSIONS_DIR, f'meituan_cookies_header{suffix}.txt')
|
||||
TOKEN_FILE = os.path.join(SESSIONS_DIR, f'meituan_tokens{suffix}.json')
|
||||
META_FILE = os.path.join(SESSIONS_DIR, f'meituan_session_meta{suffix}.json')
|
||||
return comp
|
||||
|
||||
|
||||
def current_company():
|
||||
return get_company(_cur_company)
|
||||
|
||||
|
||||
def company_label(cid=None):
|
||||
return get_company(cid)['short']
|
||||
|
||||
|
||||
def get_browser_profile_dir(cid=None):
|
||||
"""公司专属浏览器用户目录:各自独立,登录态跨次保留,不占用日常 Chrome。"""
|
||||
return os.path.join(_app_data_dir(), 'browser_sessions', get_company(cid)['profile'])
|
||||
|
||||
|
||||
def get_browser_port(cid=None):
|
||||
"""公司专属 CDP 调试端口(默认 9222,金色湖畔 9333,避免抢端口)。"""
|
||||
return int(get_company(cid)['port'])
|
||||
|
||||
|
||||
def file_prefix(cid=None):
|
||||
"""报表文件名前缀:金色印象为空(与历史文件一致),金色湖畔为「金色湖畔_」。"""
|
||||
return get_company(cid)['file_prefix']
|
||||
|
||||
|
||||
set_company('a')
|
||||
|
||||
|
||||
# ==================== 浏览器窗口(全屏 + 置顶) ====================
|
||||
|
||||
@@ -1,32 +1,54 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""浏览器:一次运行共用一个可见浏览器(登录 + 三张表下载都复用它,避免反复开关)。
|
||||
|
||||
独立固定用户目录 %LOCALAPPDATA%\\37duAutomation\\browser_sessions\\xq0041,
|
||||
登录态跨次保留,不占用用户日常 Chrome 配置。
|
||||
账号档案隔离(见 config.set_company):
|
||||
金色印象 用户目录 browser_sessions\\xq0041 调试端口 9222
|
||||
金色湖畔 用户目录 browser_sessions\\xq0041_b 调试端口 9333
|
||||
两套档案互不共享 Cookie / localStorage,等于两个独立浏览器身份,
|
||||
不会出现「同一浏览器里反复切号」那种高风控特征。
|
||||
"""
|
||||
import os
|
||||
import socket
|
||||
|
||||
from DrissionPage import ChromiumPage, ChromiumOptions
|
||||
|
||||
from .. import config
|
||||
|
||||
|
||||
def _free_port(base):
|
||||
"""从 base 起找一个没被占用的本地端口(避免和别的插件默认 9222 撞上)。"""
|
||||
for port in range(base, base + 20):
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
s.settimeout(0.2)
|
||||
if s.connect_ex(('127.0.0.1', port)) != 0:
|
||||
return port
|
||||
return base
|
||||
|
||||
|
||||
def open_page(force_login=False):
|
||||
co = ChromiumOptions()
|
||||
if config.HEADLESS:
|
||||
co.headless()
|
||||
base_port = config.get_browser_port()
|
||||
port = _free_port(base_port)
|
||||
try:
|
||||
co.set_local_port(port)
|
||||
except Exception as e:
|
||||
config.log(f'设置调试端口失败(忽略):{e}', 'WARN')
|
||||
co.set_argument('--start-maximized')
|
||||
co.set_pref('credentials_enable_service', False)
|
||||
co.set_pref('profile.password_manager_enabled', False)
|
||||
profile = config.get_browser_profile_dir()
|
||||
import os
|
||||
os.makedirs(profile, exist_ok=True)
|
||||
co.set_user_data_path(profile)
|
||||
config.log(f'浏览器用户目录:{profile}', 'DEBUG')
|
||||
config.log(f'{config.company_label()}:浏览器用户目录 {profile},调试端口 {port}'
|
||||
+ ('' if port == base_port else f'({base_port} 被占用,已顺延)'), 'DEBUG')
|
||||
page = ChromiumPage(co)
|
||||
if force_login:
|
||||
# 「强制重新登录」:清掉档案里的 Cookie,等于换账号 / 排查登录问题
|
||||
# 「强制重新登录」:清掉本档案里的 Cookie(不会影响另一家公司)
|
||||
try:
|
||||
page.set.cookies.clear()
|
||||
config.log('已清空浏览器 Cookie(强制重新登录)')
|
||||
config.log(f'已清空[{config.company_label()}]浏览器 Cookie(强制重新登录)')
|
||||
except Exception as e:
|
||||
config.log(f'清空 Cookie 失败(继续按残留登录态走):{e}', 'WARN')
|
||||
if not config.HEADLESS:
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""美团经营宝登录态:打开官方页面 → 自动/人工登录(含选商家)→ 检测完成 → 落盘 cookies/票据。
|
||||
|
||||
自动登录(可选):插件界面配置了账号 + 密码时,用页面上下文 JS 填写登录表单并点「登录」;
|
||||
滑块/短信验证码、选商家无法自动完成,脚本保持等待,由人工在浏览器窗口处理。
|
||||
未配置账号密码或自动填写失败 → 退回原手工登录流程,不影响业务。
|
||||
账号密码预填(可选):插件界面配置了账号 + 密码时,用页面上下文 JS 填好账号密码、
|
||||
勾上「用户协议」,**不点登录**;并在浏览器页面右上角挂一条醒目浮层,提示用户
|
||||
到浏览器里点「登录」(滑块 / 图形验证码 / 短信验证码 / 选商家同样交人工)。
|
||||
未配置账号密码或填不上 → 退回手工登录,不影响业务。
|
||||
|
||||
为什么通知走页面浮层而不是日志:任务跑在用户自己机器的可见浏览器里,登录期间
|
||||
用户眼前只有浏览器,日志在壳子面板里基本不会去看。
|
||||
|
||||
为什么不用 requests 校验:经营宝所有业务接口带 mtgsig 动态签名(页面 H5guard 秒级生成),
|
||||
requests 复刻必然 403。登录态有效性只由浏览器判定,取数也一律在页面上下文发请求。
|
||||
@@ -156,6 +160,9 @@ _FILL_JS = r'''
|
||||
return r.width > 2 && r.height > 2;
|
||||
};
|
||||
function setValue(el, v) {
|
||||
// 已是目标值就不再动:轮询会反复进来,重复 setValue 会打断用户手动输入、
|
||||
// 也会让页面反复校验闪红字
|
||||
if ((el.value || '') === (v || '')) return;
|
||||
try {
|
||||
var proto = el.tagName === 'TEXTAREA' ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
|
||||
var d = Object.getOwnPropertyDescriptor(proto, 'value');
|
||||
@@ -200,18 +207,18 @@ _FILL_JS = r'''
|
||||
setValue(acc, USER);
|
||||
setValue(pwd, PWD);
|
||||
|
||||
var out = { ok: true, filled_account: !!acc.value, filled_pwd: !!pwd.value,
|
||||
checked_agreement: false, submitted: false };
|
||||
var out = { ok: true, filled: !!(acc.value && pwd.value), filled_account: !!acc.value,
|
||||
filled_pwd: !!pwd.value, agreement_found: false, checked_agreement: false,
|
||||
reason: '' };
|
||||
|
||||
// 协议复选框(实测 epassport: <input id="checkbox"> + <span class="ep-authorize">我已阅读并同意…>,
|
||||
// 页面上同一份协议渲染了两遍、id 重复):只点「够得着同意/协议/隐私文案」且未勾选的第一项,
|
||||
// 避免点到「记住密码/自动登录」这类反向开关,也避免重复点击把同一状态点回去
|
||||
var boxes = [].slice.call(document.querySelectorAll('input[type="checkbox"]')).filter(function (el) {
|
||||
return visible(el) && !el.checked && !el.disabled;
|
||||
});
|
||||
var agree = boxes.filter(function (el) {
|
||||
// ---------- 用户协议(不勾上就绝不点「登录」) ----------
|
||||
// 实测 epassport: <input id="checkbox"> + <span class="ep-authorize">我已阅读并同意…>,
|
||||
// 同一份协议在页面上渲染两遍、id 重复;勾选框也可能被自定义样式盖住,光标点不动。
|
||||
function tipOf(el) {
|
||||
var tip = el.getAttribute('aria-label') || '';
|
||||
var scope = el.closest ? el.closest('.ep-protocol, .protocol, .agreement, .agree') : null;
|
||||
var scope = el.closest ? el.closest(
|
||||
'.ep-protocol, .protocol, .agreement, .agree, [class*="protocol"], [class*="agreement"], [class*="agree"]'
|
||||
) : null;
|
||||
if (scope) tip += scope.textContent || '';
|
||||
else if (el.parentElement && el.parentElement.parentElement) {
|
||||
tip += el.parentElement.parentElement.textContent || '';
|
||||
@@ -220,34 +227,53 @@ _FILL_JS = r'''
|
||||
var lab = document.querySelector('label[for="' + el.id + '"]');
|
||||
if (lab) tip += lab.textContent || '';
|
||||
}
|
||||
return tip;
|
||||
}
|
||||
function tryCheck(el) {
|
||||
if (el.checked) return true;
|
||||
// 真实页面结构:<input type="checkbox" id="checkbox"> 配 <label for="checkbox">
|
||||
// 里放自定义方块 .checkbox_icon,input 本身常被样式盖住 —— 所以先走 label(用户真实点击路径),
|
||||
// 再退到 input 自身、外层容器,最后强置 checked。
|
||||
var fns = [
|
||||
function () { var l = el.id && document.querySelector('label[for="' + el.id + '"]'); if (l) l.click(); },
|
||||
function () { el.click(); },
|
||||
function () {
|
||||
var p = (el.closest && el.closest('.ep-checkbox-container, label, .checkbox')) || el.parentElement;
|
||||
if (p) p.click();
|
||||
},
|
||||
function () { el.checked = true; el.dispatchEvent(new Event('change', { bubbles: true })); }
|
||||
];
|
||||
for (var i = 0; i < fns.length; i++) {
|
||||
try { fns[i](); } catch (e) {}
|
||||
if (el.checked) return true;
|
||||
}
|
||||
return !!el.checked;
|
||||
}
|
||||
var allBoxes = [].slice.call(document.querySelectorAll('input[type="checkbox"]')).filter(function (el) {
|
||||
return !el.disabled;
|
||||
});
|
||||
var boxes = allBoxes.filter(visible);
|
||||
// 协议框常被自定义样式盖住(opacity:0 / 尺寸 0),但它本身仍可点 —— 全被藏起来时退回全部
|
||||
if (!boxes.length) boxes = allBoxes;
|
||||
var agree = boxes.filter(function (el) {
|
||||
var tip = tipOf(el);
|
||||
if (/记住|自动登录|下次|保持登录/.test(tip)) return false;
|
||||
return /同意|协议|隐私/.test(tip);
|
||||
});
|
||||
if (agree.length) {
|
||||
try { agree[0].click(); out.checked_agreement = true; } catch (e) {}
|
||||
} else if (boxes.length === 1) {
|
||||
try { boxes[0].click(); out.checked_agreement = true; } catch (e) {}
|
||||
// 实测结构直接命中(.ep-protocol 容器 / id=checkbox),比文案猜测稳
|
||||
var directAgree = allBoxes.filter(function (el) {
|
||||
if (el.id === 'checkbox') return true;
|
||||
return !!(el.closest && el.closest('.ep-protocol, .ep-protocol_container, [class*="protocol"]'));
|
||||
})[0];
|
||||
var agreeBox = directAgree || agree[0] || (boxes.length === 1 ? boxes[0] : null);
|
||||
if (agreeBox) {
|
||||
out.agreement_found = true;
|
||||
out.checked_agreement = tryCheck(agreeBox);
|
||||
if (!out.checked_agreement) out.reason = 'agreement-not-checked';
|
||||
}
|
||||
|
||||
// 登录按钮:先试实测结构(form.ep-password-login_container button[type=submit] / button.ep-login_btn),
|
||||
// 找不到再退化为「文本恰为 登录/立即登录 的最内层元素」
|
||||
var texts = /^(登录|立即登录|账号登录|登入)$/;
|
||||
var btn = document.querySelector(
|
||||
'form.ep-password-login_container button[type="submit"], button.ep-login_btn'
|
||||
);
|
||||
if (btn && !visible(btn)) btn = null;
|
||||
if (!btn) {
|
||||
var nodes = [].slice.call(document.querySelectorAll('button,a,span,div,input[type="submit"]'));
|
||||
var hit = nodes.filter(function (el) {
|
||||
if (!visible(el)) return false;
|
||||
if (el.tagName === 'INPUT') return /^登\s*录$/.test((el.value || '').trim());
|
||||
if (!texts.test((el.textContent || '').replace(/\s+/g, ''))) return false;
|
||||
var inner = [].slice.call(el.querySelectorAll('button,a,span,div'));
|
||||
return !inner.some(function (c) { return texts.test((c.textContent || '').replace(/\s+/g, '')); });
|
||||
});
|
||||
btn = hit[0] || null;
|
||||
}
|
||||
if (btn) { btn.click(); out.submitted = true; }
|
||||
// 到此为止:只负责填账号密码 + 勾用户协议。
|
||||
// 「登录」按钮、滑块 / 图形验证码、短信验证码一律不碰,全部留给用户自己操作。
|
||||
return JSON.stringify(out);
|
||||
})()
|
||||
'''
|
||||
@@ -274,6 +300,130 @@ _TAB_JS = r'''
|
||||
'''
|
||||
|
||||
|
||||
# ==================== 浏览器内提示(用户只看浏览器,不看运行日志) ====================
|
||||
# 任务跑在用户本机的可见浏览器里,登录期间用户眼前只有浏览器窗口,日志在壳子面板里
|
||||
# 根本想不起来看。所以在登录页右上角挂一条醒目浮层,明确告诉用户"现在该你动手",
|
||||
# 进入商家后台后自动移除。
|
||||
_NOTICE_ID = '__xq41_login_notice'
|
||||
|
||||
_NOTICE_JS = r'''(function () {
|
||||
var ID = %(id)s, OPT = %(opt)s;
|
||||
var old = document.getElementById(ID);
|
||||
if (old && old.parentNode) old.parentNode.removeChild(old);
|
||||
if (!OPT || !OPT.text) return '0';
|
||||
var box = document.createElement('div');
|
||||
box.id = ID;
|
||||
box.style.cssText = 'position:fixed;top:18px;right:18px;z-index:2147483647;'
|
||||
+ 'max-width:360px;padding:14px 18px;border-radius:10px;background:#FF6A00;color:#fff;'
|
||||
+ 'font:600 15px/1.6 "Microsoft YaHei",sans-serif;box-shadow:0 8px 28px rgba(0,0,0,.35);'
|
||||
+ 'pointer-events:none;white-space:normal;text-align:left';
|
||||
var t = document.createElement('div');
|
||||
t.textContent = OPT.text;
|
||||
box.appendChild(t);
|
||||
if (OPT.sub) {
|
||||
var s = document.createElement('div');
|
||||
s.textContent = OPT.sub;
|
||||
s.style.cssText = 'margin-top:6px;font-weight:400;font-size:12.5px;opacity:.92';
|
||||
box.appendChild(s);
|
||||
}
|
||||
(document.body || document.documentElement).appendChild(box);
|
||||
return '1';
|
||||
})()
|
||||
'''
|
||||
|
||||
|
||||
# 最近一次提示内容:登录页刷新会把 DOM 整块换掉,靠它自动补挂
|
||||
_LAST_NOTICE = {'text': '', 'sub': ''}
|
||||
|
||||
|
||||
def _try_inject(target, js):
|
||||
try:
|
||||
return str(target.run_js(js) or '') == '1'
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def _doc_url(t):
|
||||
try:
|
||||
return (getattr(t, 'url', '') or '').split('?')[0] or '主页面'
|
||||
except Exception:
|
||||
return '?'
|
||||
|
||||
|
||||
def show_login_notice(page, text, sub='', frame=None, quiet=False):
|
||||
"""在浏览器页面里挂提示,全局**只保留一条**。
|
||||
|
||||
顺序:主文档 → 填表所在文档 → 其它 iframe,第一处成功就停。
|
||||
每次挂之前会先把所有文档里的旧浮层清掉 —— 否则「填表时挂在 iframe、后面更新文案
|
||||
时挂在主文档」会变成 iframe 一条 + 外层一条同时显示。
|
||||
"""
|
||||
_LAST_NOTICE['text'], _LAST_NOTICE['sub'] = text, sub
|
||||
opt = json.dumps({'text': text, 'sub': sub}, ensure_ascii=False)
|
||||
js = _NOTICE_JS % {'id': json.dumps(_NOTICE_ID), 'opt': opt}
|
||||
remove_js = _NOTICE_JS % {'id': json.dumps(_NOTICE_ID), 'opt': 'null'}
|
||||
|
||||
order = [page]
|
||||
if frame is not None and frame is not page:
|
||||
order.append(frame)
|
||||
try:
|
||||
order.extend([t for t in _targets(page) if t is not page and t is not frame])
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 先清干净,保证屏幕上只有一条(所有文档都清,别留历史遗留)
|
||||
for t in order:
|
||||
_try_inject(t, remove_js)
|
||||
|
||||
hit, tried, ok_doc = 0, [], ''
|
||||
for t in order[:3]: # 别在一个页面的十几个 iframe 上耗时间
|
||||
tried.append(_doc_url(t))
|
||||
for _attempt in range(2):
|
||||
if _try_inject(t, js):
|
||||
hit = 1
|
||||
ok_doc = _doc_url(t)
|
||||
break
|
||||
time.sleep(0.3)
|
||||
if hit:
|
||||
break
|
||||
|
||||
if hit:
|
||||
config.log(f'已在浏览器页面挂出提示({ok_doc}):{text}')
|
||||
else:
|
||||
config.log(f'登录提示没能挂到页面上(不影响下载流程):{text};已尝试文档:{tried}',
|
||||
'DEBUG' if quiet else 'WARN')
|
||||
return hit > 0
|
||||
|
||||
|
||||
def _notice_alive_any(page):
|
||||
"""任意文档里还留着提示元素?(页面重渲染会冲掉它)"""
|
||||
for t in [page] + [f for f in _targets(page) if f is not page]:
|
||||
try:
|
||||
if t.run_js('return !!document.getElementById(%s);' % json.dumps(_NOTICE_ID)):
|
||||
return True
|
||||
except Exception:
|
||||
continue
|
||||
return False
|
||||
|
||||
|
||||
def refresh_login_notice(page):
|
||||
"""登录页 DOM 被整块重渲染时把提示补回来(每 15 秒查一次,见 _wait_backend)。"""
|
||||
text = _LAST_NOTICE['text']
|
||||
if not text:
|
||||
return
|
||||
if _notice_alive_any(page):
|
||||
return
|
||||
show_login_notice(page, text, _LAST_NOTICE['sub'], quiet=True)
|
||||
|
||||
|
||||
def hide_login_notice(page):
|
||||
_LAST_NOTICE['text'] = ''
|
||||
js = _NOTICE_JS % {'id': json.dumps(_NOTICE_ID), 'opt': 'null'}
|
||||
_try_inject(page, js)
|
||||
for t in _targets(page):
|
||||
if t is not page:
|
||||
_try_inject(t, js)
|
||||
|
||||
|
||||
def _targets(page):
|
||||
"""登录表单可能不在主文档:实测 ecom 的登录页把表单放在
|
||||
<iframe class="loginFormContent" src="https://epassport.meituan.com/portal/login?..."> 里。
|
||||
@@ -303,14 +453,43 @@ def _targets(page):
|
||||
def _fill_once(frame, username, password):
|
||||
try:
|
||||
frame.run_js(_TARGET_SELECTOR_JS)
|
||||
raw = frame.run_js(_FILL_JS % {'user': json.dumps(username, ensure_ascii=False),
|
||||
'pwd': json.dumps(password, ensure_ascii=False)})
|
||||
return json.loads(raw) if raw else None
|
||||
raw = frame.run_js(_FILL_JS % {
|
||||
'user': json.dumps(username, ensure_ascii=False),
|
||||
'pwd': json.dumps(password, ensure_ascii=False),
|
||||
})
|
||||
# run_js 的返回值有两种可能:原始 JSON 字符串,或 DrissionPage 已自动解析成 dict。
|
||||
# 以前只按字符串 json.loads,遇到 dict 会抛 TypeError → 明明填好了却判定"没填上"。
|
||||
if isinstance(raw, dict):
|
||||
return raw
|
||||
if isinstance(raw, str) and raw.strip():
|
||||
try:
|
||||
return json.loads(raw)
|
||||
except ValueError:
|
||||
config.log(f'填写结果不是 JSON:{raw[:120]}', 'DEBUG')
|
||||
return None
|
||||
return None
|
||||
except Exception as e:
|
||||
config.log(f'自动填写尝试异常:{e}', 'DEBUG')
|
||||
return None
|
||||
|
||||
|
||||
def _verify_filled(frame, password):
|
||||
"""用原生 DOM 查询复核"到底填上没有"(run_js 拿不到返回值时的兜底)。"""
|
||||
try:
|
||||
el = frame.ele('#password', timeout=0.3)
|
||||
except Exception:
|
||||
return False
|
||||
if not el:
|
||||
return False
|
||||
for getter in (lambda e: e.value, lambda e: e.attr('value')):
|
||||
try:
|
||||
if str(getter(el) or '') == str(password):
|
||||
return True
|
||||
except Exception:
|
||||
continue
|
||||
return False
|
||||
|
||||
|
||||
def _switch_account_tab(frame):
|
||||
try:
|
||||
return str(frame.run_js(_TAB_JS) or '') == '1'
|
||||
@@ -319,34 +498,56 @@ def _switch_account_tab(frame):
|
||||
|
||||
|
||||
def autofill_login(page, username, password):
|
||||
"""用配置的账号密码自动填写并提交登录表单。
|
||||
"""用配置的账号密码预填登录表单(**不点登录**)。
|
||||
|
||||
返回 True=已填写并点过登录;False=没找到表单(由调用方继续等人工登录)。
|
||||
滑块/短信验证码、选商家仍需人工,这里不做任何绕过。
|
||||
只做两件事:填账号密码、勾「用户协议」,并在页面右上角挂醒目提示。
|
||||
「登录」按钮、滑块 / 图形验证码、短信验证码、选商家全部交人工 —— 不点、不猜、不绕过。
|
||||
账号密码已是目标值就不再重填,避免打断人工输入。
|
||||
|
||||
返回 True=已填好(已挂页面提示);False=没找到表单。
|
||||
"""
|
||||
deadline = time.time() + config.AUTOFILL_WAIT
|
||||
tab_clicked = False
|
||||
while time.time() < deadline:
|
||||
for frame in _targets(page):
|
||||
info = _fill_once(frame, username, password)
|
||||
if info and info.get('ok'):
|
||||
try:
|
||||
where = (getattr(frame, 'url', '') or '').split('?')[0] or '主页面'
|
||||
except Exception:
|
||||
where = '主页面'
|
||||
if not info.get('submitted'):
|
||||
config.log(f'已在 {where} 填写账号密码,但没找到「登录」按钮,请手动点一下', 'WARN')
|
||||
else:
|
||||
config.log(f'已在 {where} 自动填写账号密码并提交登录'
|
||||
'(若弹出滑块/短信验证码,请在浏览器窗口手动完成)')
|
||||
return True
|
||||
if info and info.get('reason') == 'no-password' and not tab_clicked:
|
||||
if _switch_account_tab(frame):
|
||||
try:
|
||||
where = (getattr(frame, 'url', '') or '').split('?')[0] or '主页面'
|
||||
except Exception:
|
||||
where = '主页面'
|
||||
|
||||
fill = _fill_once(frame, username, password)
|
||||
if fill is None and _verify_filled(frame, password):
|
||||
# 页面上已经填进去了,只是没读到 run_js 的返回值(跨域 iframe / 页面重渲染都会这样)
|
||||
fill = {'filled': True, 'agreement_found': False, 'checked_agreement': False}
|
||||
config.log(f'{where} 账号密码已填入(按原生 DOM 复核确认)', 'DEBUG')
|
||||
if not fill:
|
||||
continue
|
||||
if fill.get('reason') == 'no-password':
|
||||
if not tab_clicked and _switch_account_tab(frame):
|
||||
tab_clicked = True
|
||||
config.log('登录页默认非账密方式,已切换到「账号登录」', 'DEBUG')
|
||||
time.sleep(config.AUTOFILL_POLL)
|
||||
continue
|
||||
if not fill.get('filled') and not _verify_filled(frame, password):
|
||||
continue
|
||||
|
||||
agree_ok = bool(fill.get('checked_agreement'))
|
||||
agree_note = ',并已勾选用户协议' if agree_ok else ''
|
||||
if fill.get('agreement_found') and not agree_ok:
|
||||
config.log(f'已在 {where} 填好账号密码,但用户协议没能自动勾上:'
|
||||
'请在浏览器里手动勾选协议后点「登录」', 'WARN')
|
||||
show_login_notice(page, '请在浏览器里勾选「我已阅读并同意」后点「登录」',
|
||||
'需要先勾选协议', frame=frame)
|
||||
else:
|
||||
config.log(f'已在 {where} 填好账号密码{agree_note},'
|
||||
'请到浏览器窗口点「登录」(滑块 / 短信验证码也由你完成)')
|
||||
show_login_notice(page, '请在浏览器窗口点「登录」',
|
||||
'滑块 / 短信验证码按页面提示完成', frame=frame)
|
||||
return True
|
||||
time.sleep(config.AUTOFILL_POLL)
|
||||
config.log(f'未找到账号密码输入框(等 {config.AUTOFILL_WAIT}s),请在浏览器窗口手动登录', 'WARN')
|
||||
show_login_notice(page, '请在浏览器窗口手动登录经营宝',
|
||||
'请手动输入账号密码')
|
||||
return False
|
||||
|
||||
|
||||
@@ -471,6 +672,7 @@ def _wait_backend(page):
|
||||
login_hint_at = biz_hint_at = 0.0
|
||||
captcha_hint_at = captcha_checked_at = 0.0
|
||||
biz_at, biz_tries, biz_gave_up = 0.0, 0, False
|
||||
notice_at = 0.0
|
||||
|
||||
while time.time() < deadline:
|
||||
try:
|
||||
@@ -507,17 +709,26 @@ def _wait_backend(page):
|
||||
if state == 'login' and time.time() - login_hint_at > 30:
|
||||
login_hint_at = time.time()
|
||||
config.log('请在浏览器窗口内完成登录(账号密码 / 短信验证码 / 扫码均可)')
|
||||
show_login_notice(page, '请在浏览器窗口点「登录」',
|
||||
'滑块 / 短信验证码按页面提示完成即可')
|
||||
elif state == 'biz_choice' and time.time() - biz_hint_at > 30:
|
||||
biz_hint_at = time.time()
|
||||
config.log('账号已登录,请在页面上选择要进入的商家(脚本不自动选,避免进错店)')
|
||||
config.log('账号已登录,请在页面上选择要进入的商家(不自动选,避免进错店)')
|
||||
show_login_notice(page, '请选择要进入的商家',
|
||||
'点选要进入的门店即可')
|
||||
|
||||
if state == 'backend':
|
||||
if backend_since is None:
|
||||
backend_since = time.time()
|
||||
config.log(f'已进入商家后台,等待 {config.BACKEND_STABLE}s 确认不会再被踢回登录页…')
|
||||
elif time.time() - backend_since >= config.BACKEND_STABLE:
|
||||
hide_login_notice(page)
|
||||
return True
|
||||
else:
|
||||
# 登录页是 SPA,重渲染会把浮层冲掉;每 15 秒查一次,没了就补挂
|
||||
if time.time() - notice_at > 15:
|
||||
notice_at = time.time()
|
||||
refresh_login_notice(page)
|
||||
if backend_since is not None:
|
||||
config.log('又回到登录/选商家页,重新计时', 'WARN')
|
||||
backend_since = None
|
||||
@@ -526,8 +737,9 @@ def _wait_backend(page):
|
||||
captcha_checked_at = time.time()
|
||||
if _has_captcha(page) and time.time() - captcha_hint_at > 60:
|
||||
captcha_hint_at = time.time()
|
||||
config.log('检测到滑块/图形验证码,请在浏览器窗口手动完成'
|
||||
'(完成后脚本自动继续)')
|
||||
config.log('检测到滑块/图形验证码,请在浏览器窗口手动完成(完成后自动继续)')
|
||||
show_login_notice(page, '请完成滑块 / 图形验证码',
|
||||
'拖动滑块或点选完成验证')
|
||||
|
||||
time.sleep(config.POLL_SECONDS)
|
||||
return False
|
||||
@@ -546,6 +758,7 @@ def ensure_login(page, username='', password=''):
|
||||
if state == 'backend':
|
||||
time.sleep(config.SETTLE_WAIT)
|
||||
_save_login_state(page)
|
||||
hide_login_notice(page)
|
||||
return True, '复用缓存登录态'
|
||||
if state in ('login', 'biz_choice'):
|
||||
break
|
||||
@@ -555,11 +768,11 @@ def ensure_login(page, username='', password=''):
|
||||
password = (password or '').strip()
|
||||
if username and password:
|
||||
if classify(page.url) == 'biz_choice':
|
||||
config.log('账号已登录,仅需选择商家(自动登录不需要再填账号密码)')
|
||||
config.log('账号已登录,仅需选择商家(不需要再填账号密码)')
|
||||
else:
|
||||
config.log('检测到未登录,尝试用界面配置的账号密码自动登录…')
|
||||
config.log('检测到未登录:自动填好账号密码 + 勾选用户协议,'
|
||||
'「登录」按钮与验证码留给你在浏览器里操作…')
|
||||
autofill_login(page, username, password)
|
||||
time.sleep(config.AUTOFILL_SUBMIT_DELAY)
|
||||
elif username or password:
|
||||
config.log('账号 / 密码只填了一项,本次跳过自动登录,请手工登录', 'WARN')
|
||||
|
||||
@@ -575,4 +788,5 @@ def ensure_login(page, username='', password=''):
|
||||
if classify(page.url) != 'backend':
|
||||
return False, '登录态未稳定(落盘前离开后台)'
|
||||
_save_login_state(page)
|
||||
hide_login_notice(page)
|
||||
return True, '登录成功'
|
||||
|
||||
@@ -100,7 +100,7 @@ def download(page, d_from, d_to, save_dir, dry_run=False):
|
||||
if match_key in (it.get('timeInterval') or '') and it.get('downloadLink')]
|
||||
fresh = [it for it in cands if _age_minutes(it.get('addTime')) <= config.REUSE_MAX_AGE_MIN]
|
||||
if fresh and not dry_run:
|
||||
target = fresh[0]
|
||||
target = max(fresh, key=lambda x: str(x.get('addTime') or ''))
|
||||
config.log(f'复用 {_age_minutes(target.get("addTime")):.0f} 分钟前的同区间记录'
|
||||
f'(阈值 {config.REUSE_MAX_AGE_MIN} 分钟),不重复生成')
|
||||
elif cands:
|
||||
@@ -127,32 +127,44 @@ def download(page, d_from, d_to, save_dir, dry_run=False):
|
||||
continue
|
||||
return {'ok': False, 'message': f'生成任务提交失败:{msg}'}
|
||||
|
||||
# 平台是「先登记一条记录(此时 downloadLink 为空)→ 文件生成完再回填链接」,
|
||||
# 所以必须等 downloadLink 出现才算就绪,否则一命中空记录就退出等待(3 秒即失败)。
|
||||
deadline = time.time() + config.RECORD_SECONDS
|
||||
waited = 0
|
||||
last_log = -config.POLL_LOG_EVERY
|
||||
while time.time() < deadline:
|
||||
time.sleep(config.POLL_SECONDS)
|
||||
waited += config.POLL_SECONDS
|
||||
items = _history_items(frame)
|
||||
for it in items:
|
||||
if it.get('id') in before_ids:
|
||||
continue
|
||||
if match_key not in (it.get('timeInterval') or ''):
|
||||
continue
|
||||
target = it
|
||||
hits = [it for it in items
|
||||
if it.get('id') not in before_ids
|
||||
and match_key in (it.get('timeInterval') or '')]
|
||||
ready = [it for it in hits if it.get('downloadLink')]
|
||||
if ready:
|
||||
# 同区间可能登记多条(重试/多业务),取最新一条
|
||||
target = max(ready, key=lambda x: str(x.get('addTime') or ''))
|
||||
break
|
||||
if target:
|
||||
break
|
||||
config.log(' 等待账单生成…')
|
||||
if waited - last_log >= config.POLL_LOG_EVERY:
|
||||
last_log = waited
|
||||
if hits:
|
||||
config.log(f' 账单生成中({len(hits)} 条记录暂无 downloadLink,'
|
||||
f'已等 {waited}s / 上限 {config.RECORD_SECONDS}s)…')
|
||||
else:
|
||||
config.log(f' 等待账单生成…(已等 {waited}s)')
|
||||
|
||||
if dry_run:
|
||||
return {'ok': True, 'message': f'[演练] 将生成并下载打款记录 {d_from}~{d_to}', 'rows': total}
|
||||
|
||||
if not target:
|
||||
return {'ok': False, 'message': f'{config.RECORD_SECONDS}s 内未拿到可下载记录'}
|
||||
return {'ok': False,
|
||||
'message': f'{config.RECORD_SECONDS}s 内记录仍未生成完成(无 downloadLink)'}
|
||||
|
||||
link = target.get('downloadLink')
|
||||
if not link:
|
||||
return {'ok': False, 'message': '记录里没有 downloadLink(可能仍在生成)'}
|
||||
|
||||
path = os.path.join(save_dir, f'{config.PAYMENT_NAME_KEY}_{tag}.xlsx')
|
||||
# 公司前缀:金色湖畔落到「金色湖畔_打款记录_20261105.xlsx」,不与金色印象同日文件互相覆盖
|
||||
path = os.path.join(save_dir, f'{config.file_prefix()}{config.PAYMENT_NAME_KEY}_{tag}.xlsx')
|
||||
config.log(f'下载 → {path}')
|
||||
size = browser.download_file(link, path)
|
||||
if not size:
|
||||
|
||||
@@ -174,7 +174,9 @@ def download(page, d_from, d_to, save_dir, codes=None, dry_run=False):
|
||||
if not link:
|
||||
config.log(f'{name} 未取到 downloadLink,跳过', 'WARN')
|
||||
continue
|
||||
path = os.path.join(save_dir, f'{name}_{tag}.xlsx')
|
||||
# 公司前缀:金色湖畔落到「金色湖畔_团购收益明细_20261105.xlsx」,
|
||||
# 既不与金色印象同日文件互相覆盖,也天然落在台账 glob(团购收益明细_*.xlsx)之外
|
||||
path = os.path.join(save_dir, f'{config.file_prefix()}{name}_{tag}.xlsx')
|
||||
config.log(f'下载 {name} → {path}')
|
||||
size = browser.download_file(link, path)
|
||||
if not size:
|
||||
|
||||
@@ -60,7 +60,11 @@ def _month_key(path):
|
||||
|
||||
|
||||
def _pick_latest(pattern, by_month=True):
|
||||
"""排除备份文件(`_备份20261027_155650.xlsx` 同样匹配 glob,曾误当成台账)。"""
|
||||
"""排除备份文件(`_备份20261027_155650.xlsx` 同样匹配 glob,曾误当成台账)。
|
||||
|
||||
金色湖畔的明细带「金色湖畔_」前缀,不在 `团购收益明细_*.xlsx` 里,天然被排除
|
||||
—— 台账按单份明细增量合并,固定只认金色印象那份。
|
||||
"""
|
||||
files = [p for p in glob.glob(os.path.join(config.WORK_DIR, pattern))
|
||||
if '备份' not in os.path.basename(p) and not p.endswith('.rebuild.tmp')]
|
||||
if not files:
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
"schema_version": 1,
|
||||
"id": "xq0041",
|
||||
"name": "新美大平台核对",
|
||||
"version": "1.1.14",
|
||||
"description": "美团经营宝账单自动下载与台账核对:按需下载打款记录、团购收益明细、预订收益明细,把新产生的收益按验券时间并入月份台账,并按日期把核对统计表整行同源取数公式([n]资金组取数!$B$xx,实测 V/W/Y/Z)换成当天共享总表的链接。界面可配经营宝账号密码自动登录,并自动选「非餐饮商家版」(验证码/具体门店仍需人工),登录一次后可长期复用。",
|
||||
"version": "1.3.9",
|
||||
"description": "美团经营宝账单自动下载与台账核对:按需下载打款记录、团购收益明细、预订收益明细,把新产生的收益按验券时间并入月份台账,并按日期把核对统计表整行同源取数公式([n]资金组取数!$B$xx,实测 V/W/Y/Z)换成当天共享总表的链接。界面可配经营宝账号密码自动填好并勾选用户协议,登录页右上角浮层提示你去点「登录」(登录按钮、滑块/短信验证码、选门店仍由人工完成),登录一次后可长期复用。执行模式分「含写表」(只导金色印象 + 并台账 + 更新核对统计)与「仅导出」(金色印象 / 金色湖畔按需勾选,可只导一家,不写表);两家各自独立浏览器档案与调试端口(xq0041 / xq0041_b、9222 / 9333),登录态互不干扰,避免同浏览器反复切号触发风控,金色湖畔报表文件名带「金色湖畔_」前缀。",
|
||||
"category": "财务",
|
||||
"icon": "",
|
||||
"platform": "",
|
||||
@@ -21,16 +21,51 @@
|
||||
"properties": {
|
||||
"mt_username": {
|
||||
"type": "string",
|
||||
"title": "经营宝账号",
|
||||
"title": "金色印象-经营宝账号",
|
||||
"default": "",
|
||||
"description": "美团经营宝登录账号(手机号/账号)。与密码一起填写后自动登录;留空=手工登录"
|
||||
"description": "金色印象的美团经营宝账号(手机号/账号)。与密码一起填写后自动登录;留空=手工登录"
|
||||
},
|
||||
"mt_password": {
|
||||
"type": "string",
|
||||
"title": "经营宝登录密码",
|
||||
"title": "金色印象-登录密码",
|
||||
"default": "",
|
||||
"format": "password",
|
||||
"description": "仅保存在本机(%LOCALAPPDATA%\\37duAutomation\\plugin_configs),下次免填;滑块/短信验证码仍需人工完成"
|
||||
"description": "仅保存在本机(%LOCALAPPDATA%\\37duAutomation\\plugin_configs),下次免填;登录按钮与滑块/短信验证码仍由人工完成"
|
||||
},
|
||||
"mt2_username": {
|
||||
"type": "string",
|
||||
"title": "金色湖畔-经营宝账号",
|
||||
"default": "",
|
||||
"description": "金色湖畔的美团经营宝账号。仅在「仅导出」模式下使用;留空=该家手工登录"
|
||||
},
|
||||
"mt2_password": {
|
||||
"type": "string",
|
||||
"title": "金色湖畔-登录密码",
|
||||
"default": "",
|
||||
"format": "password",
|
||||
"description": "仅保存在本机(%LOCALAPPDATA%\\37duAutomation\\plugin_configs),下次免填"
|
||||
},
|
||||
"run_mode": {
|
||||
"type": "string",
|
||||
"title": "执行模式",
|
||||
"default": "full",
|
||||
"enum": [
|
||||
"full",
|
||||
"export_only"
|
||||
],
|
||||
"description": "full=只导金色印象 + 并台账 + 更新核对统计;export_only=按「导出范围」勾选的公司各导一份,不写任何表"
|
||||
},
|
||||
"export_companies": {
|
||||
"type": "array",
|
||||
"title": "导出范围(仅导出模式生效)",
|
||||
"default": [
|
||||
"a",
|
||||
"b"
|
||||
],
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "a=金色印象,b=金色湖畔;只勾一家就只导那一家"
|
||||
},
|
||||
"action": {
|
||||
"type": "string",
|
||||
|
||||
@@ -21,38 +21,87 @@
|
||||
<span>{{ notice.text }}</span>
|
||||
</div>
|
||||
|
||||
<!-- 01 登录账号 -->
|
||||
<section v-show="form.do_download" class="sec">
|
||||
<!-- 01 执行模式:决定导哪几家、写不写表,放最前面,下面的区块随它变 -->
|
||||
<section class="sec">
|
||||
<div class="sec-head">
|
||||
<span class="sec-badge">01</span>
|
||||
<span class="sec-name">登录账号</span>
|
||||
<span class="sec-name">执行模式</span>
|
||||
<span class="sec-line" />
|
||||
</div>
|
||||
<div class="sec-body">
|
||||
<el-form label-position="top">
|
||||
<div class="grid">
|
||||
<el-form-item label="经营宝账号">
|
||||
<el-input v-model="form.mt_username" placeholder="手机号 / 账号"
|
||||
:disabled="running" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="登录密码">
|
||||
<el-input v-model="form.mt_password" type="password" show-password
|
||||
placeholder="仅保存在本机,下次免填" :disabled="running" />
|
||||
</el-form-item>
|
||||
</div>
|
||||
<el-radio-group v-model="form.run_mode" class="mode-group" :disabled="running">
|
||||
<el-radio value="full" border class="mode-card">
|
||||
<span class="m-title">含写表</span>
|
||||
<span class="m-desc">只导「金色印象」→ 并入台账 + 更新核对统计</span>
|
||||
</el-radio>
|
||||
<el-radio value="export_only" border class="mode-card">
|
||||
<span class="m-title">仅导出</span>
|
||||
<span class="m-desc">按勾选的公司导出(可只导一家)→ 不写任何表</span>
|
||||
</el-radio>
|
||||
</el-radio-group>
|
||||
<el-form-item v-if="form.run_mode === 'export_only'" label="导出范围" class="range-item">
|
||||
<el-checkbox-group v-model="form.export_companies" :disabled="running">
|
||||
<el-checkbox value="a">金色印象</el-checkbox>
|
||||
<el-checkbox value="b">金色湖畔</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</el-form-item>
|
||||
<div class="tip">
|
||||
两项都填:登录时自动填写并提交(<b>失败自动降级为手工登录</b>);滑块 / 短信验证码、选商家
|
||||
无法自动完成,脚本会停在浏览器窗口等你处理。<br>
|
||||
都不填:完全手工登录(密码不会出现在「恢复上次参数」里)。
|
||||
{{ form.run_mode === 'export_only'
|
||||
? '只导勾选的公司,可只勾一家;湖畔文件名带「金色湖畔_」前缀。全程不并台账、不更新核对统计。'
|
||||
: '本次只登录金色印象导账单,导完自动并入台账并更新核对统计(历史行为)。' }}
|
||||
</div>
|
||||
</el-form>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 02 下载内容 -->
|
||||
<!-- 02 登录账号 -->
|
||||
<section v-show="form.do_download" class="sec">
|
||||
<div class="sec-head">
|
||||
<span class="sec-badge">02</span>
|
||||
<span class="sec-name">登录账号</span>
|
||||
<span class="sec-line" />
|
||||
<span class="sec-tag">本次导出:{{ exportTargets }}</span>
|
||||
</div>
|
||||
<div class="sec-body">
|
||||
<el-form label-position="top">
|
||||
<div v-if="exportA" class="grid">
|
||||
<el-form-item label="金色印象-经营宝账号">
|
||||
<el-input v-model="form.mt_username" placeholder="手机号 / 账号"
|
||||
:disabled="running" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="金色印象-登录密码">
|
||||
<el-input v-model="form.mt_password" type="password" show-password
|
||||
placeholder="仅保存在本机,下次免填" :disabled="running" />
|
||||
</el-form-item>
|
||||
</div>
|
||||
<div v-if="form.run_mode === 'export_only' && exportB" class="grid">
|
||||
<el-form-item label="金色湖畔-经营宝账号">
|
||||
<el-input v-model="form.mt2_username" placeholder="手机号 / 账号"
|
||||
:disabled="running" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="金色湖畔-登录密码">
|
||||
<el-input v-model="form.mt2_password" type="password" show-password
|
||||
placeholder="仅保存在本机,下次免填" :disabled="running" />
|
||||
</el-form-item>
|
||||
</div>
|
||||
<div class="tip">
|
||||
<template v-if="form.run_mode === 'export_only'">
|
||||
两家是平台上的两个主体,各用一套登录:金色印象档案 <b>xq0041</b> / 端口 9222,
|
||||
金色湖畔档案 <b>xq0041_b</b> / 端口 9333,Cookie 分开落盘,不会出现同一浏览器反复切号。<br>
|
||||
</template>
|
||||
账号密码都填:脚本自动填好账号密码并勾选用户协议,然后在浏览器右上角弹一条橙色提示。
|
||||
<b>「登录」按钮、滑块 / 短信验证码、选门店都由你在浏览器里点</b>,脚本只等结果。
|
||||
都留空:完全手工登录(密码不会出现在「恢复上次参数」里)。
|
||||
</div>
|
||||
</el-form>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 03 下载内容 -->
|
||||
<section v-show="form.do_download" class="sec">
|
||||
<div class="sec-head">
|
||||
<span class="sec-badge">03</span>
|
||||
<span class="sec-name">下载内容</span>
|
||||
<span class="sec-line" />
|
||||
</div>
|
||||
@@ -98,88 +147,101 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 03 执行过程 -->
|
||||
<!-- 04 执行过程 -->
|
||||
<section class="sec">
|
||||
<div class="sec-head">
|
||||
<span class="sec-badge">03</span>
|
||||
<span class="sec-badge">04</span>
|
||||
<span class="sec-name">执行过程</span>
|
||||
<span class="sec-line" />
|
||||
</div>
|
||||
<div class="sec-body">
|
||||
<el-form label-position="top">
|
||||
<div class="rows">
|
||||
<div class="row">
|
||||
<div class="r-main">
|
||||
<div class="r-title">下载数据</div>
|
||||
<div class="r-desc">登录经营宝,把勾选的账单下载到保存目录</div>
|
||||
</div>
|
||||
<div class="r-ctrl"><el-switch v-model="form.do_download" :disabled="running" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="r-main">
|
||||
<div class="r-title">更新核对</div>
|
||||
<div class="r-desc">读本机最新的台账与收益明细,并入台账并更新核对统计,不重新下载</div>
|
||||
</div>
|
||||
<div class="r-ctrl"><el-switch v-model="form.do_reconcile" :disabled="running" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="r-main">
|
||||
<div class="r-title">强制重新登录</div>
|
||||
<div class="r-desc">忽略残留登录态直接等人工登录,换账号 / 排查登录问题时用</div>
|
||||
</div>
|
||||
<div class="r-ctrl">
|
||||
<el-switch v-model="form.force_login" :disabled="running || !form.do_download" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="r-main">
|
||||
<div class="r-title">调试日志</div>
|
||||
<div class="r-desc">输出页面跳转轨迹与接口返回,日常保持关闭</div>
|
||||
</div>
|
||||
<div class="r-ctrl"><el-switch v-model="form.debug_mode" :disabled="running" /></div>
|
||||
</div>
|
||||
<div class="switch-row">
|
||||
<el-form-item>
|
||||
<template #label>
|
||||
<el-tooltip placement="top" :content="form.run_mode === 'export_only'
|
||||
? '仅导出模式固定要导(关掉就没有任何动作)'
|
||||
: '登录经营宝,把勾选的账单下载到保存目录'">
|
||||
<span class="lbl">下载数据</span>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<el-switch v-model="form.do_download"
|
||||
:disabled="running || form.run_mode === 'export_only'" />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="form.run_mode !== 'export_only'">
|
||||
<template #label>
|
||||
<el-tooltip placement="top"
|
||||
content="读本机最新的台账与收益明细,并入台账并更新核对统计,不重新下载">
|
||||
<span class="lbl">更新核对</span>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<el-switch v-model="form.do_reconcile" :disabled="running" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<template #label>
|
||||
<el-tooltip placement="top"
|
||||
content="清掉当前账号档案的 Cookie,忽略残留登录态直接等人工登录(另一家不受影响)">
|
||||
<span class="lbl">强制重新登录</span>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<el-switch v-model="form.force_login" :disabled="running || !form.do_download" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<template #label>
|
||||
<el-tooltip placement="top" content="输出页面跳转轨迹与接口返回,日常保持关闭">
|
||||
<span class="lbl">调试日志</span>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<el-switch v-model="form.debug_mode" :disabled="running" />
|
||||
</el-form-item>
|
||||
</div>
|
||||
<div class="tip">
|
||||
只勾「更新核对」可单独补账(不开浏览器);下载与核对都勾则先下载再核对。
|
||||
{{ form.run_mode === 'export_only'
|
||||
? '仅导出模式:只登录勾选的公司下载账单,不打开任何表格。'
|
||||
: '只勾「更新核对」可单独补账(不开浏览器);下载与核对都勾则先下载再核对。' }}
|
||||
</div>
|
||||
</el-form>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 04 台账合并与核对表 -->
|
||||
<section v-show="form.do_reconcile" class="sec">
|
||||
<!-- 05 台账合并与核对表(仅导出模式整块不出现) -->
|
||||
<section v-show="form.do_reconcile && form.run_mode !== 'export_only'" class="sec">
|
||||
<div class="sec-head">
|
||||
<span class="sec-badge">04</span>
|
||||
<span class="sec-badge">05</span>
|
||||
<span class="sec-name">台账合并与核对表</span>
|
||||
<span class="sec-line" />
|
||||
</div>
|
||||
<div class="sec-body">
|
||||
<el-form label-position="top">
|
||||
<div class="rows">
|
||||
<div class="row">
|
||||
<div class="r-main">
|
||||
<div class="r-title">并入台账</div>
|
||||
<div class="r-desc">收益明细按「验券/退款/调整时间」增量追加,AF~AP 公式列自动下拉</div>
|
||||
</div>
|
||||
<div class="r-ctrl"><el-switch v-model="form.run_merge" :disabled="running" /></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_links" :disabled="running" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="r-main">
|
||||
<div class="r-title">只核对不写入(演练)</div>
|
||||
<div class="r-desc">只输出将追加的行数与起止行号,不修改台账文件</div>
|
||||
</div>
|
||||
<div class="r-ctrl">
|
||||
<el-switch v-model="form.dry_run"
|
||||
:disabled="running || (!form.run_merge && !form.run_links)" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="switch-row">
|
||||
<el-form-item>
|
||||
<template #label>
|
||||
<el-tooltip placement="top"
|
||||
content="收益明细按「验券/退款/调整时间」增量追加,AF~AP 公式列自动下拉">
|
||||
<span class="lbl">并入台账</span>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<el-switch v-model="form.run_merge" :disabled="running" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<template #label>
|
||||
<el-tooltip placement="top"
|
||||
content="按 A 列日期把「新美大核对统计」整行的 [n] 换成当天那份共享总表">
|
||||
<span class="lbl">更新核对统计</span>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<el-switch v-model="form.run_links" :disabled="running" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<template #label>
|
||||
<el-tooltip placement="top"
|
||||
content="只输出将追加的行数与起止行号,不修改台账文件">
|
||||
<span class="lbl">只核对不写入(演练)</span>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<el-switch v-model="form.dry_run"
|
||||
:disabled="running || (!form.run_merge && !form.run_links)" />
|
||||
</el-form-item>
|
||||
</div>
|
||||
<div class="tip">
|
||||
只勾这两项、不勾下载时可单独补账(不开浏览器);写入前自动备份(_备份 + 时间戳),
|
||||
@@ -193,10 +255,15 @@
|
||||
<details class="help">
|
||||
<summary><span>流程说明与口径</span><span class="h-arrow">▾</span></summary>
|
||||
<div class="help-body">
|
||||
<div class="hb-line"><b>① 登录</b>:打开经营宝(ecom.meituan.com),配了账号密码就先自动填写提交,
|
||||
滑块 / 短信验证码与「选商家」交人工;进后台后 Cookies 落盘到
|
||||
<div class="hb-line"><b>① 登录</b>:打开经营宝(ecom.meituan.com),配了账号密码就先自动填好
|
||||
<b>并勾选用户协议</b>,浏览器右上角浮层会提示你点「登录」;登录按钮、滑块 / 短信验证码与
|
||||
「选商家」全部交人工。进后台后浮层自动消失,Cookies 落盘到
|
||||
<b>%LOCALAPPDATA%\37duAutomation\.sessions\meituan_*</b>,浏览器档案在
|
||||
<b>browser_sessions\xq0041</b>,下次直接复用,过期才会再要求登录。</div>
|
||||
<b>browser_sessions\xq0041</b>,下次直接复用,过期才会再要求登录。<br>
|
||||
<b>两家公司</b>:金色印象档案 <b>xq0041</b> / 端口 <b>9222</b>,金色湖畔档案 <b>xq0041_b</b> /
|
||||
端口 <b>9333</b>,Cookie 分开落盘,登录态互不覆盖,不会出现「同一浏览器反复切号」的高风控特征。<br>
|
||||
<b>执行模式</b>:「仅导出」两家都导(湖畔文件名带「金色湖畔_」前缀,不写表);
|
||||
「含写表」只导金色印象,导出后并入台账并更新核对统计。</div>
|
||||
<div class="hb-line"><b>② 打款记录</b>:走 h5 账单页 iframe 里的 smartBill 三接口(查询 → 生成 → 导出记录 → 预签名直下),
|
||||
10 分钟内同区间记录直接复用不重复生成;<b>区间内没有打款记录按「跳过」处理</b>,不影响后续核对。</div>
|
||||
<div class="hb-line"><b>③ 收益明细</b>:走 PC 商户中心 downloadManagement,一次生成团购 + 预订两个文件;
|
||||
@@ -254,6 +321,10 @@ const DEFAULTS = () => {
|
||||
return {
|
||||
mt_username: '',
|
||||
mt_password: '',
|
||||
mt2_username: '',
|
||||
mt2_password: '',
|
||||
run_mode: 'full',
|
||||
export_companies: ['a', 'b'],
|
||||
do_download: true,
|
||||
do_reconcile: true,
|
||||
pay_enabled: true,
|
||||
@@ -298,6 +369,22 @@ const {
|
||||
ElMessage.warning('账号和密码要么都填(自动登录),要么都留空(手工登录)')
|
||||
return false
|
||||
}
|
||||
if (form.run_mode === 'export_only') {
|
||||
if (!form.do_download) {
|
||||
ElMessage.warning('「仅导出」模式必须勾选「下载数据」(它只负责导出,不写表)')
|
||||
return false
|
||||
}
|
||||
if (!(form.export_companies || []).length) {
|
||||
ElMessage.warning('请至少勾选一家要导出的公司(金色印象 / 金色湖畔)')
|
||||
return false
|
||||
}
|
||||
const u2 = (form.mt2_username || '').trim()
|
||||
const p2 = (form.mt2_password || '').trim()
|
||||
if (exportB.value && (u2 || p2) && !(u2 && p2)) {
|
||||
ElMessage.warning('金色湖畔的账号和密码要么都填(自动登录),要么都留空(手工登录)')
|
||||
return false
|
||||
}
|
||||
}
|
||||
const pairs = []
|
||||
if (form.pay_enabled) pairs.push(['打款记录', form.pay_date_from, form.pay_date_to])
|
||||
if (form.profit_group || form.profit_booking) {
|
||||
@@ -315,10 +402,16 @@ const {
|
||||
},
|
||||
buildPayload(f) {
|
||||
const t = (v) => (v || '').trim()
|
||||
const action = f.do_download && f.do_reconcile ? 'all' : (f.do_download ? 'download' : 'reconcile')
|
||||
const exportOnly = f.run_mode === 'export_only'
|
||||
const action = exportOnly ? 'download'
|
||||
: (f.do_download && f.do_reconcile ? 'all' : (f.do_download ? 'download' : 'reconcile'))
|
||||
return {
|
||||
mt_username: t(f.mt_username),
|
||||
mt_password: t(f.mt_password),
|
||||
mt2_username: t(f.mt2_username),
|
||||
mt2_password: t(f.mt2_password),
|
||||
run_mode: exportOnly ? 'export_only' : 'full',
|
||||
export_companies: exportOnly ? (f.export_companies || []) : [],
|
||||
action,
|
||||
pay_enabled: !!f.pay_enabled,
|
||||
pay_date_from: t(f.pay_date_from),
|
||||
@@ -329,9 +422,9 @@ const {
|
||||
profit_date_to: t(f.profit_date_to),
|
||||
save_dir: t(f.save_dir),
|
||||
force_login: !!f.force_login,
|
||||
run_merge: !!f.run_merge,
|
||||
run_links: !!f.run_links,
|
||||
dry_run: !!((f.run_merge || f.run_links) && f.dry_run),
|
||||
run_merge: !exportOnly && !!f.run_merge,
|
||||
run_links: !exportOnly && !!f.run_links,
|
||||
dry_run: !exportOnly && !!((f.run_merge || f.run_links) && f.dry_run),
|
||||
debug_mode: !!f.debug_mode,
|
||||
}
|
||||
},
|
||||
@@ -363,6 +456,28 @@ async function pickDir() {
|
||||
|
||||
const profitOn = computed(() => form.profit_group || form.profit_booking)
|
||||
|
||||
// 仅导出模式勾了哪几家:账号区据此显示,标题右侧同步摘要
|
||||
// (含写表模式固定只导金色印象,所以 exportA 恒为 true)
|
||||
const exportA = computed(() => form.run_mode !== 'export_only'
|
||||
|| (form.export_companies || []).includes('a'))
|
||||
const exportB = computed(() => (form.run_mode === 'export_only'
|
||||
&& (form.export_companies || []).includes('b')))
|
||||
const exportTargets = computed(() => {
|
||||
if (form.run_mode !== 'export_only') return '金色印象'
|
||||
const names = []
|
||||
if (exportA.value) names.push('金色印象')
|
||||
if (exportB.value) names.push('金色湖畔')
|
||||
return names.join(' + ') || '未选择'
|
||||
})
|
||||
|
||||
// 仅导出必须开下载(该模式下开关本身被禁用,这里保证切过去时它一定是开的)
|
||||
watch(() => form.run_mode, (m) => {
|
||||
if (m === 'export_only') {
|
||||
form.do_download = true
|
||||
if (!(form.export_companies || []).length) form.export_companies = ['a', 'b']
|
||||
}
|
||||
})
|
||||
|
||||
// 日期区间选择器 ↔ 两个字段(plugin.json 仍以 *_date_from/to 为契约,定时任务兼容)
|
||||
function makeRange(getFrom, getTo, setFrom, setTo) {
|
||||
return computed({
|
||||
@@ -409,4 +524,26 @@ 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; }
|
||||
/* 执行模式:两张大卡片,一眼看清"导哪家 / 写不写表" */
|
||||
.mode-group { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); width: 100%; }
|
||||
.mode-group :deep(.el-radio) {
|
||||
height: auto;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
padding: 10px 14px;
|
||||
align-items: flex-start;
|
||||
white-space: normal; /* element-plus 默认 nowrap,会把卡片撑出容器 */
|
||||
}
|
||||
.mode-group :deep(.el-radio__input) { margin-top: 2px; }
|
||||
.mode-group :deep(.el-radio__label) { display: block; line-height: 1.5; white-space: normal; }
|
||||
/* 导出范围:跟在模式卡片下面,别贴着 */
|
||||
.range-item { margin-top: var(--space-3); }
|
||||
/* 执行过程:几个开关排一行,原始说明收进 hover 提示 */
|
||||
.switch-row { display: flex; flex-wrap: wrap; gap: 0 var(--space-5); }
|
||||
.switch-row :deep(.el-form-item) { margin-bottom: 12px; min-width: 104px; }
|
||||
.switch-row .lbl { cursor: help; white-space: nowrap; border-bottom: 1px dashed var(--line-soft); }
|
||||
.m-title { display: block; font-weight: 600; }
|
||||
.m-desc { display: block; font-size: 12px; opacity: 0.65; }
|
||||
/* 区块标题右侧的即时摘要(如「本次导出:金色印象 + 金色湖畔」) */
|
||||
.sec-tag { flex: 0 0 auto; font-size: 12px; opacity: 0.6; white-space: nowrap; }
|
||||
</style>
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+21
-21
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/xq0041/assets/index-CBLp7rYV.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/pui/xq0041/assets/index-Du0XtKs7.css">
|
||||
<script type="module" crossorigin src="/pui/xq0041/assets/index-BcCXU4Vw.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/pui/xq0041/assets/index-BVdn0lhW.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
||||
Reference in New Issue
Block a user