docs: 更新 AGENTS/README 平台架构说明与月度总结,运行日志视图支持已取消状态
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
"""XQ0041 新美大平台核对 —— webhost 场景插件入口。
|
||||
|
||||
执行过程由 action 决定(UI 的两个开关派生):
|
||||
action='download' → 只下载:登录经营宝,按勾选下载打款记录 / 团购收益明细 / 预订收益明细;
|
||||
action='download' → 只下载:登录经营宝(界面配了账号密码则自动填写提交,验证码/选商家仍需人工),
|
||||
按勾选下载打款记录 / 团购收益明细 / 预订收益明细;
|
||||
action='reconcile' → 只核对:**不开浏览器**,直接用本机最新的台账与收益明细并入台账、
|
||||
更新核对统计(适合数据已下载、只想重算的场景);
|
||||
action='all' → 下载后再核对(默认)。
|
||||
@@ -68,16 +69,20 @@ def _resolve_action(fields):
|
||||
class Xq0041Plugin(ScenePlugin):
|
||||
id = 'xq0041'
|
||||
name = '新美大平台核对'
|
||||
version = '1.1.8'
|
||||
version = '1.1.14'
|
||||
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': '',
|
||||
'format': 'password'},
|
||||
'action': {'type': 'string', 'title': '执行过程', 'default': 'all',
|
||||
'enum': ['all', 'download', 'reconcile']},
|
||||
'do_download': {'type': 'boolean', 'title': '下载数据', 'default': True},
|
||||
@@ -89,6 +94,8 @@ class Xq0041Plugin(ScenePlugin):
|
||||
'profit_booking': {'type': 'boolean', 'title': '下载预订收益明细', 'default': True},
|
||||
'profit_date_from': {'type': 'string', 'title': '收益明细-开始日期', 'default': ''},
|
||||
'profit_date_to': {'type': 'string', 'title': '收益明细-结束日期', 'default': ''},
|
||||
'save_dir': {'type': 'string', 'title': '保存目录', 'default': ''},
|
||||
'force_login': {'type': 'boolean', 'title': '强制重新登录', 'default': False},
|
||||
'run_merge': {'type': 'boolean', 'title': '并入台账', 'default': True},
|
||||
'run_links': {'type': 'boolean', 'title': '更新核对统计', 'default': True},
|
||||
'dry_run': {'type': 'boolean', 'title': '只核对不写入', 'default': False},
|
||||
@@ -118,7 +125,13 @@ class Xq0041Plugin(ScenePlugin):
|
||||
dry_run = bool(fields.get('dry_run'))
|
||||
run_merge = bool(fields.get('run_merge', True))
|
||||
run_links = bool(fields.get('run_links', True))
|
||||
save_dir = str(fields.get('save_dir') or config.WORK_DIR).strip().strip('"') or config.WORK_DIR
|
||||
force_login = bool(fields.get('force_login'))
|
||||
# 保存目录同时是台账目录:并入台账 / 更新核对统计都读它
|
||||
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()
|
||||
|
||||
if do_download and not pay_on and not codes:
|
||||
raise RuntimeError('请至少勾选一项要下载的内容(打款记录 / 团购 / 预订)')
|
||||
@@ -145,7 +158,7 @@ class Xq0041Plugin(ScenePlugin):
|
||||
plan.append('更新核对统计' if run_links else '')
|
||||
plan = [p for p in plan if p]
|
||||
config.log(('本次执行:' + ';'.join(plan) if plan else '本次没有可执行的动作')
|
||||
+ (f';目录 {save_dir}' if do_download else '')
|
||||
+ f';目录 {save_dir}'
|
||||
+ ('(只核对不写入)' if dry_run else ''))
|
||||
|
||||
detail = {'action': action, 'pay': None, 'profit': None, 'merge': None, 'links': None}
|
||||
@@ -154,9 +167,11 @@ class Xq0041Plugin(ScenePlugin):
|
||||
# ---------- 1~3:登录 + 下载 ----------
|
||||
if do_download:
|
||||
ctx.progress(2)
|
||||
page = browser.open_page()
|
||||
page = browser.open_page(force_login=force_login)
|
||||
try:
|
||||
ok, msg = meituan_login.ensure_login(page)
|
||||
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}')
|
||||
@@ -167,7 +182,10 @@ class Xq0041Plugin(ScenePlugin):
|
||||
if not r1.get('ok'):
|
||||
raise RuntimeError(f'打款记录下载失败:{r1.get("message")}')
|
||||
config.log(r1.get('message') or '')
|
||||
if r1.get('path'):
|
||||
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)
|
||||
@@ -209,6 +227,8 @@ class Xq0041Plugin(ScenePlugin):
|
||||
|
||||
# ---------- 汇总 ----------
|
||||
parts = []
|
||||
if detail['pay'] and detail['pay'].get('empty'):
|
||||
parts.append(f'打款记录 {pay_from}~{pay_to} 无数据')
|
||||
if files:
|
||||
parts.append(f'下载 {len(files)} 个文件')
|
||||
if detail['merge'] and detail['merge'].get('appended'):
|
||||
|
||||
@@ -44,7 +44,8 @@ PROFIT_LINK_API = 'https://e.dianping.com/finance/ajax/downloadManagement/downlo
|
||||
PROFIT_FILE_TYPE = 201 # 201 = 收益明细
|
||||
|
||||
# ==================== 台账 ====================
|
||||
WORK_DIR = r'D:\资料\财务\新美大平台核对' # 账单 + 台账统一目录
|
||||
DEFAULT_WORK_DIR = r'D:\资料\财务\新美大平台核对' # 界面「保存目录」留空时用它
|
||||
WORK_DIR = DEFAULT_WORK_DIR # 账单 + 台账统一目录(运行期可被覆盖)
|
||||
LEDGER_GLOB = '新美大到账统计*.xlsx'
|
||||
LEDGER_SHEET = '金色印象--新美大导出(收)'
|
||||
STAT_SHEET = '新美大核对统计'
|
||||
@@ -58,8 +59,41 @@ SHARE_ROOT = r'\\caiwu01\共享文件夹\1111\TG'
|
||||
LINK_BOOK = '马敏团购总表'
|
||||
LINK_SHEET = '资金组取数'
|
||||
|
||||
|
||||
def set_work_dir(path=None):
|
||||
"""界面「保存目录」覆盖默认目录(账单 + 台账同目录)。
|
||||
|
||||
merge_ledger / stat_links 都在调用时读 config.WORK_DIR,改这里即全局生效。
|
||||
留空 = 回到默认目录(避免上一次的目录串到下一次运行)。返回实际生效目录。
|
||||
"""
|
||||
global WORK_DIR
|
||||
p = str(path or '').strip().strip('"').strip()
|
||||
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"
|
||||
# src="https://epassport.meituan.com/portal/login?...">),跨域但可由 CDP 直接执行 JS。
|
||||
LOGIN_FRAME_HINTS = (
|
||||
'epassport.meituan.com', 'passport.meituan.com',
|
||||
'passport.dianping.com', 'account.dianping.com',
|
||||
)
|
||||
|
||||
# 登录后的「选择商家版本」页(epassport,main .biz-item 卡片):
|
||||
# 「我是餐饮商家(餐饮商家版)」/「我是非餐饮商家(服务零售商家版)」
|
||||
# 金色印象属服务零售(足浴/休闲)→ 自动点「我是非餐饮商家」,避免手工点错版本进错后台。
|
||||
BIZ_LINE_KEYWORD = '非餐饮'
|
||||
BIZ_LINE_MARKERS = ('我是餐饮商家', '我是非餐饮商家')
|
||||
BIZ_LINE_MAX_TRIES = 3 # 最多尝试 3 次(卡片容器 → 确定按钮 → 卡片本身)
|
||||
BIZ_LINE_INTERVAL = 6 # 每次尝试的最小间隔(秒)
|
||||
|
||||
# ==================== 运行参数 ====================
|
||||
LOGIN_WAIT = 600 # 等待人工登录(含选商家)超时
|
||||
LOGIN_WAIT = 600 # 等待人工登录(含验证码/选商家)超时
|
||||
BACKEND_STABLE = 20 # 后台页连续稳定秒数(/meishi 未登录也会停留约 20s 再跳)
|
||||
SETTLE_WAIT = 8 # 登录成功后等首屏请求结束再抓 cookie
|
||||
POLL_SECONDS = 2
|
||||
|
||||
@@ -9,7 +9,7 @@ from DrissionPage import ChromiumPage, ChromiumOptions
|
||||
from .. import config
|
||||
|
||||
|
||||
def open_page():
|
||||
def open_page(force_login=False):
|
||||
co = ChromiumOptions()
|
||||
if config.HEADLESS:
|
||||
co.headless()
|
||||
@@ -22,6 +22,13 @@ def open_page():
|
||||
co.set_user_data_path(profile)
|
||||
config.log(f'浏览器用户目录:{profile}', 'DEBUG')
|
||||
page = ChromiumPage(co)
|
||||
if force_login:
|
||||
# 「强制重新登录」:清掉档案里的 Cookie,等于换账号 / 排查登录问题
|
||||
try:
|
||||
page.set.cookies.clear()
|
||||
config.log('已清空浏览器 Cookie(强制重新登录)')
|
||||
except Exception as e:
|
||||
config.log(f'清空 Cookie 失败(继续按残留登录态走):{e}', 'WARN')
|
||||
if not config.HEADLESS:
|
||||
# 登录要人工操作(账密/短信/扫码/选商家),全屏 + 置顶避免被其它窗口挡住
|
||||
config.apply_window_mode(page)
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""美团经营宝登录态:打开官方页面 → 人工登录(含选商家)→ 检测完成 → 落盘 cookies/票据。
|
||||
"""美团经营宝登录态:打开官方页面 → 自动/人工登录(含选商家)→ 检测完成 → 落盘 cookies/票据。
|
||||
|
||||
自动登录(可选):插件界面配置了账号 + 密码时,用页面上下文 JS 填写登录表单并点「登录」;
|
||||
滑块/短信验证码、选商家无法自动完成,脚本保持等待,由人工在浏览器窗口处理。
|
||||
未配置账号密码或自动填写失败 → 退回原手工登录流程,不影响业务。
|
||||
|
||||
为什么不用 requests 校验:经营宝所有业务接口带 mtgsig 动态签名(页面 H5guard 秒级生成),
|
||||
requests 复刻必然 403。登录态有效性只由浏览器判定,取数也一律在页面上下文发请求。
|
||||
@@ -125,12 +129,348 @@ def _save_login_state(page):
|
||||
f'localStorage {len(ls)} 项 / sessionStorage {len(ss)} 项')
|
||||
|
||||
|
||||
# ==================== 账号密码自动填写(可选) ====================
|
||||
# 说明:只在「界面里配了账号 + 密码」时才动手;滑块/短信验证码、选商家仍交人工,
|
||||
# 自动填写失败一律降级为原来的手工登录,不阻塞流程。
|
||||
|
||||
_TARGET_SELECTOR_JS = r'''
|
||||
(function () {
|
||||
function visible(el) {
|
||||
if (!el || !el.getBoundingClientRect) return false;
|
||||
var r = el.getBoundingClientRect();
|
||||
if (r.width <= 2 || r.height <= 2) return false;
|
||||
var st = window.getComputedStyle(el);
|
||||
return st.display !== 'none' && st.visibility !== 'hidden' && st.opacity !== '0';
|
||||
}
|
||||
window.__xq41Visible = visible;
|
||||
return 1;
|
||||
})()
|
||||
'''
|
||||
|
||||
_FILL_JS = r'''
|
||||
(function () {
|
||||
var USER = %(user)s, PWD = %(pwd)s;
|
||||
var visible = window.__xq41Visible || function (el) {
|
||||
if (!el || !el.getBoundingClientRect) return false;
|
||||
var r = el.getBoundingClientRect();
|
||||
return r.width > 2 && r.height > 2;
|
||||
};
|
||||
function setValue(el, v) {
|
||||
try {
|
||||
var proto = el.tagName === 'TEXTAREA' ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
|
||||
var d = Object.getOwnPropertyDescriptor(proto, 'value');
|
||||
if (d && d.set) d.set.call(el, v); else el.value = v;
|
||||
} catch (e) { el.value = v; }
|
||||
el.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
el.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
el.dispatchEvent(new KeyboardEvent('keyup', { bubbles: true, key: 'Enter' }));
|
||||
}
|
||||
// 密码框:优先 id=password / placeholder 含「密码」(实测 epassport: <input id="password" placeholder="输入密码">)
|
||||
var pwds = [].slice.call(document.querySelectorAll('input[type="password"]')).filter(visible);
|
||||
if (!pwds.length) return JSON.stringify({ ok: false, reason: 'no-password' });
|
||||
var pwd = pwds.filter(function (el) {
|
||||
return (el.id || '') === 'password' || /密码/.test(el.placeholder || '');
|
||||
})[0] || pwds[0];
|
||||
|
||||
// 账号框:先试 id=login(实测 epassport: <input id="login" placeholder="输入账号">),
|
||||
// 再从密码框往上找首个含普通文本框的容器,按 placeholder/name/id 关键词取最优
|
||||
var ACC_KEY = /手机|账号|帐号|邮箱|用户名|工号|account|user|login/i;
|
||||
var acc = null;
|
||||
var direct = document.querySelector('input#login, input[name="login"], input#account, input[name="account"]');
|
||||
if (direct && direct !== pwd && visible(direct)) acc = direct;
|
||||
if (!acc) {
|
||||
var cands = [], node = pwd.parentElement;
|
||||
for (var i = 0; i < 8 && node; i++) {
|
||||
var list = [].slice.call(node.querySelectorAll('input,textarea')).filter(function (el) {
|
||||
if (el === pwd || !visible(el) || el.disabled || el.readOnly) return false;
|
||||
var t = (el.getAttribute('type') || 'text').toLowerCase();
|
||||
return ['text', 'tel', 'email', 'number', ''].indexOf(t) >= 0;
|
||||
});
|
||||
if (list.length) { cands = list; break; }
|
||||
node = node.parentElement;
|
||||
}
|
||||
if (cands.length) {
|
||||
acc = cands.filter(function (el) {
|
||||
return ACC_KEY.test((el.placeholder || '') + (el.name || '') + (el.id || ''));
|
||||
})[0] || cands[0];
|
||||
}
|
||||
}
|
||||
if (!acc) return JSON.stringify({ ok: false, reason: 'no-account' });
|
||||
|
||||
setValue(acc, USER);
|
||||
setValue(pwd, PWD);
|
||||
|
||||
var out = { ok: true, filled_account: !!acc.value, filled_pwd: !!pwd.value,
|
||||
checked_agreement: false, submitted: false };
|
||||
|
||||
// 协议复选框(实测 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) {
|
||||
var tip = el.getAttribute('aria-label') || '';
|
||||
var scope = el.closest ? el.closest('.ep-protocol, .protocol, .agreement, .agree') : null;
|
||||
if (scope) tip += scope.textContent || '';
|
||||
else if (el.parentElement && el.parentElement.parentElement) {
|
||||
tip += el.parentElement.parentElement.textContent || '';
|
||||
}
|
||||
if (el.id) {
|
||||
var lab = document.querySelector('label[for="' + el.id + '"]');
|
||||
if (lab) tip += lab.textContent || '';
|
||||
}
|
||||
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) {}
|
||||
}
|
||||
|
||||
// 登录按钮:先试实测结构(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);
|
||||
})()
|
||||
'''
|
||||
|
||||
_TAB_JS = r'''
|
||||
(function () {
|
||||
var visible = window.__xq41Visible || function (el) {
|
||||
if (!el || !el.getBoundingClientRect) return false;
|
||||
var r = el.getBoundingClientRect();
|
||||
return r.width > 2 && r.height > 2;
|
||||
};
|
||||
var want = /^(账号登录|账号密码登录|密码登录)$/;
|
||||
var nodes = [].slice.call(document.querySelectorAll('button,a,span,div,li'));
|
||||
var hit = nodes.filter(function (el) {
|
||||
if (!visible(el)) return false;
|
||||
if (!want.test((el.textContent || '').replace(/\s+/g, ''))) return false;
|
||||
var inner = [].slice.call(el.querySelectorAll('button,a,span,div,li'));
|
||||
return !inner.some(function (c) { return want.test((c.textContent || '').replace(/\s+/g, '')); });
|
||||
});
|
||||
if (!hit.length) return '0';
|
||||
hit[0].click();
|
||||
return '1';
|
||||
})()
|
||||
'''
|
||||
|
||||
|
||||
def _targets(page):
|
||||
"""登录表单可能不在主文档:实测 ecom 的登录页把表单放在
|
||||
<iframe class="loginFormContent" src="https://epassport.meituan.com/portal/login?..."> 里。
|
||||
|
||||
返回尝试顺序:统一登录域 iframe → 其它 iframe → 主页面。跨域 iframe 由 CDP 直接执行 JS。
|
||||
"""
|
||||
frames = []
|
||||
try:
|
||||
frames = list(page.get_frames() or [])
|
||||
except Exception as e:
|
||||
config.log(f'枚举 iframe 失败(仅试主页面):{e}', 'DEBUG')
|
||||
|
||||
def _rank(f):
|
||||
try:
|
||||
url = (f.url or '').lower()
|
||||
except Exception:
|
||||
return 1
|
||||
if any(h in url for h in config.LOGIN_FRAME_HINTS):
|
||||
config.log(f'登录相关 iframe:{url}', 'DEBUG')
|
||||
return 0
|
||||
return 1
|
||||
|
||||
frames.sort(key=lambda f: _rank(f))
|
||||
return frames + [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
|
||||
except Exception as e:
|
||||
config.log(f'自动填写尝试异常:{e}', 'DEBUG')
|
||||
return None
|
||||
|
||||
|
||||
def _switch_account_tab(frame):
|
||||
try:
|
||||
return str(frame.run_js(_TAB_JS) or '') == '1'
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def autofill_login(page, username, password):
|
||||
"""用配置的账号密码自动填写并提交登录表单。
|
||||
|
||||
返回 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):
|
||||
tab_clicked = True
|
||||
config.log('登录页默认非账密方式,已切换到「账号登录」', 'DEBUG')
|
||||
time.sleep(config.AUTOFILL_POLL)
|
||||
time.sleep(config.AUTOFILL_POLL)
|
||||
config.log(f'未找到账号密码输入框(等 {config.AUTOFILL_WAIT}s),请在浏览器窗口手动登录', 'WARN')
|
||||
return False
|
||||
|
||||
|
||||
_CAPTCHA_JS = r'''
|
||||
(function () {
|
||||
var sels = ['iframe[src*="captcha"]', 'iframe[src*="gtimg"]', '.geetest_panel',
|
||||
'.nc-container', '.nc_wrapper', '.yidun_popup', '.smc-captcha',
|
||||
'.yoda-slider', '[id*="captcha"]'];
|
||||
for (var i = 0; i < sels.length; i++) {
|
||||
var el = document.querySelector(sels[i]);
|
||||
if (!el) continue;
|
||||
var r = el.getBoundingClientRect ? el.getBoundingClientRect() : null;
|
||||
if (r && r.width > 10 && r.height > 10) return 1;
|
||||
}
|
||||
return 0;
|
||||
})()
|
||||
'''
|
||||
|
||||
|
||||
def _has_captcha(page):
|
||||
"""滑块/图形验证码是否可见(跨 iframe 一起看)。"""
|
||||
for t in _targets(page):
|
||||
try:
|
||||
if str(t.run_js(_CAPTCHA_JS) or '') == '1':
|
||||
return True
|
||||
except Exception:
|
||||
continue
|
||||
return False
|
||||
|
||||
|
||||
# 登录后的「选择商家版本」页探测(实测 DOM:main[data-v] > div.biz-item > .item-container + h2)
|
||||
_BIZ_PROBE_JS = r'''
|
||||
(function () {
|
||||
var MARKS = %(marks)s;
|
||||
var VISIBLE = function (el) {
|
||||
if (!el || !el.getBoundingClientRect) return false;
|
||||
var r = el.getBoundingClientRect();
|
||||
return r.width > 2 && r.height > 2;
|
||||
};
|
||||
var cards = [].slice.call(document.querySelectorAll('.biz-item, [class*="biz-item"]'))
|
||||
.filter(VISIBLE);
|
||||
if (!cards.length) return JSON.stringify({ found: false });
|
||||
var text = cards.map(function (el) {
|
||||
return (el.textContent || '').replace(/\s+/g, '');
|
||||
}).join('|');
|
||||
var hit = 0;
|
||||
MARKS.forEach(function (m) { if (text.indexOf(m) >= 0) hit++; });
|
||||
return JSON.stringify({ found: hit >= 1, cards: cards.length, marks: hit });
|
||||
})()
|
||||
'''
|
||||
|
||||
# 点中目标商家版本:container=卡片内 .item-container,card=整卡,confirm=该页的「确定/下一步」
|
||||
_BIZ_CLICK_JS = r'''
|
||||
(function () {
|
||||
var KEY = %(keyword)s, MODE = %(mode)s;
|
||||
var VISIBLE = function (el) {
|
||||
if (!el || !el.getBoundingClientRect) return false;
|
||||
var r = el.getBoundingClientRect();
|
||||
return r.width > 2 && r.height > 2;
|
||||
};
|
||||
var clicked = false;
|
||||
if (MODE === 'confirm') {
|
||||
var want = /^(确定|下一步|继续|确认|进入|进入后台)$/;
|
||||
var btns = [].slice.call(document.querySelectorAll('button,a,div,span')).filter(function (el) {
|
||||
if (!VISIBLE(el)) return false;
|
||||
if (!want.test((el.textContent || '').replace(/\s+/g, ''))) return false;
|
||||
var inner = [].slice.call(el.querySelectorAll('button,a'));
|
||||
return !inner.some(function (c) { return want.test((c.textContent || '').replace(/\s+/g, '')); });
|
||||
});
|
||||
if (btns.length) { btns[0].click(); clicked = true; }
|
||||
return JSON.stringify({ found: true, clicked: clicked, mode: MODE });
|
||||
}
|
||||
var cards = [].slice.call(document.querySelectorAll('.biz-item, [class*="biz-item"]'))
|
||||
.filter(VISIBLE);
|
||||
var marked = '我是' + KEY + '商家';
|
||||
var hit = cards.filter(function (el) {
|
||||
return (el.textContent || '').replace(/\s+/g, '').indexOf(marked) >= 0;
|
||||
})[0] || cards.filter(function (el) {
|
||||
return (el.textContent || '').indexOf(KEY) >= 0;
|
||||
})[0];
|
||||
if (!hit) return JSON.stringify({ found: false, clicked: false, mode: MODE });
|
||||
var target = MODE === 'card' ? hit : (hit.querySelector('.item-container') || hit);
|
||||
target.click();
|
||||
return JSON.stringify({ found: true, clicked: true, mode: MODE });
|
||||
})()
|
||||
'''
|
||||
|
||||
|
||||
def _biz_line_page(page):
|
||||
"""当前页面是否为「选择商家版本」页(我是餐饮商家 / 我是非餐饮商家 两张卡)。"""
|
||||
js = _BIZ_PROBE_JS % {'marks': json.dumps(list(config.BIZ_LINE_MARKERS), ensure_ascii=False)}
|
||||
for t in _targets(page):
|
||||
try:
|
||||
raw = t.run_js(js)
|
||||
info = json.loads(raw) if raw else None
|
||||
if info and info.get('found'):
|
||||
return True
|
||||
except Exception:
|
||||
continue
|
||||
return False
|
||||
|
||||
|
||||
def _click_biz_line(page, mode):
|
||||
js = _BIZ_CLICK_JS % {'keyword': json.dumps(config.BIZ_LINE_KEYWORD, ensure_ascii=False),
|
||||
'mode': json.dumps(mode)}
|
||||
for t in _targets(page):
|
||||
try:
|
||||
raw = t.run_js(js)
|
||||
info = json.loads(raw) if raw else None
|
||||
if info and info.get('clicked'):
|
||||
return info
|
||||
except Exception:
|
||||
continue
|
||||
return {}
|
||||
|
||||
|
||||
def _wait_backend(page):
|
||||
"""等人工完成「登录 + 选商家」。返回 True/False。"""
|
||||
"""等人工完成「验证码 / 登录 / 选商家」。返回 True/False。"""
|
||||
deadline = time.time() + config.LOGIN_WAIT
|
||||
last_url, last_state = None, None
|
||||
backend_since = None
|
||||
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
|
||||
|
||||
while time.time() < deadline:
|
||||
try:
|
||||
@@ -143,6 +483,25 @@ def _wait_backend(page):
|
||||
last_url = url
|
||||
config.log(f'页面状态 = {state} | {url}', 'DEBUG')
|
||||
|
||||
# 「选择商家版本」页(我是餐饮商家 / 我是非餐饮商家):自动点「我是非餐饮商家」,
|
||||
# 依次尝试「卡片容器 → 该页确定按钮 → 整卡」,最多 BIZ_LINE_MAX_TRIES 次
|
||||
if time.time() - biz_at > config.BIZ_LINE_INTERVAL:
|
||||
biz_at = time.time()
|
||||
if _biz_line_page(page):
|
||||
if biz_tries < config.BIZ_LINE_MAX_TRIES:
|
||||
mode = ('container', 'confirm', 'card')[biz_tries]
|
||||
r = _click_biz_line(page, mode)
|
||||
biz_tries += 1
|
||||
if r.get('clicked'):
|
||||
config.log(f'已在「选择商家版本」页点选「我是'
|
||||
f'{config.BIZ_LINE_KEYWORD}商家」({mode})')
|
||||
time.sleep(config.POLL_SECONDS)
|
||||
continue
|
||||
elif not biz_gave_up:
|
||||
biz_gave_up = True
|
||||
config.log(f'「选择商家版本」页自动点选失败,请手动点「我是'
|
||||
f'{config.BIZ_LINE_KEYWORD}商家」', 'WARN')
|
||||
|
||||
if state != last_state:
|
||||
last_state = state
|
||||
if state == 'login' and time.time() - login_hint_at > 30:
|
||||
@@ -162,13 +521,20 @@ def _wait_backend(page):
|
||||
if backend_since is not None:
|
||||
config.log('又回到登录/选商家页,重新计时', 'WARN')
|
||||
backend_since = None
|
||||
# 验证码提示:提交后常弹滑块/点选,最多每 10 秒探一次、每 60 秒提示一次
|
||||
if state != 'other' and time.time() - captcha_checked_at > 10:
|
||||
captcha_checked_at = time.time()
|
||||
if _has_captcha(page) and time.time() - captcha_hint_at > 60:
|
||||
captcha_hint_at = time.time()
|
||||
config.log('检测到滑块/图形验证码,请在浏览器窗口手动完成'
|
||||
'(完成后脚本自动继续)')
|
||||
|
||||
time.sleep(config.POLL_SECONDS)
|
||||
return False
|
||||
|
||||
|
||||
def ensure_login(page):
|
||||
"""确保 page 已进入商家后台;必要时停在前台等人工登录。"""
|
||||
def ensure_login(page, username='', password=''):
|
||||
"""确保 page 已进入商家后台;必要时用配置的账号密码自动登录,失败则等人工。"""
|
||||
config.log(f'打开经营宝:{config.HOME_URL}')
|
||||
page.get(config.HOME_URL)
|
||||
time.sleep(config.POLL_SECONDS)
|
||||
@@ -185,7 +551,20 @@ def ensure_login(page):
|
||||
break
|
||||
time.sleep(config.POLL_SECONDS)
|
||||
|
||||
config.log(f'需要人工登录,最多等待 {config.LOGIN_WAIT} 秒…')
|
||||
username = (username or '').strip()
|
||||
password = (password or '').strip()
|
||||
if username and password:
|
||||
if classify(page.url) == 'biz_choice':
|
||||
config.log('账号已登录,仅需选择商家(自动登录不需要再填账号密码)')
|
||||
else:
|
||||
config.log('检测到未登录,尝试用界面配置的账号密码自动登录…')
|
||||
autofill_login(page, username, password)
|
||||
time.sleep(config.AUTOFILL_SUBMIT_DELAY)
|
||||
elif username or password:
|
||||
config.log('账号 / 密码只填了一项,本次跳过自动登录,请手工登录', 'WARN')
|
||||
|
||||
config.log(f'等待进入商家后台,最多 {config.LOGIN_WAIT} 秒'
|
||||
f'(滑块验证码 / 选商家需在浏览器窗口人工完成)…')
|
||||
if not _wait_backend(page):
|
||||
cookies = _cookies(page)
|
||||
config.log('当前 Cookie:' + ', '.join(sorted({c.get('name') for c in cookies if c.get('name')})),
|
||||
|
||||
@@ -87,7 +87,10 @@ def download(page, d_from, d_to, save_dir, dry_run=False):
|
||||
config.log(f' 首条 {s.get("payTime")} | {s.get("productCodeName")} | '
|
||||
f'{s.get("amount")} | {s.get("payStatusName")}')
|
||||
if not total:
|
||||
return {'ok': False, 'message': f'{d_from}~{d_to} 没有打款记录'}
|
||||
# 区间内没有任何打款(周末/节假日/未结算)属正常业务状态,不算失败,
|
||||
# 由调用方跳过本项、继续后续下载与核对。
|
||||
return {'ok': True, 'empty': True, 'rows': 0,
|
||||
'message': f'{d_from}~{d_to} 没有打款记录,跳过'}
|
||||
|
||||
# ② 已有记录时效内复用
|
||||
before = _history_items(frame)
|
||||
|
||||
@@ -2,26 +2,45 @@
|
||||
"schema_version": 1,
|
||||
"id": "xq0041",
|
||||
"name": "新美大平台核对",
|
||||
"version": "1.1.8",
|
||||
"description": "美团经营宝账单自动下载与台账核对:按需下载打款记录、团购收益明细、预订收益明细,把新产生的收益按验券时间并入月份台账,并按日期把核对统计表整行同源取数公式([n]资金组取数!$B$xx,实测 V/W/Y/Z)换成当天共享总表的链接。登录一次后可长期复用。",
|
||||
"version": "1.1.14",
|
||||
"description": "美团经营宝账单自动下载与台账核对:按需下载打款记录、团购收益明细、预订收益明细,把新产生的收益按验券时间并入月份台账,并按日期把核对统计表整行同源取数公式([n]资金组取数!$B$xx,实测 V/W/Y/Z)换成当天共享总表的链接。界面可配经营宝账号密码自动登录,并自动选「非餐饮商家版」(验证码/具体门店仍需人工),登录一次后可长期复用。",
|
||||
"category": "财务",
|
||||
"icon": "",
|
||||
"platform": "",
|
||||
"uses_month": false,
|
||||
"runTimeoutSeconds": 0,
|
||||
"ui": true,
|
||||
"capabilities": ["xq0041"],
|
||||
"capabilities": [
|
||||
"xq0041"
|
||||
],
|
||||
"permissions": {
|
||||
"platforms": []
|
||||
},
|
||||
"fields": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"mt_username": {
|
||||
"type": "string",
|
||||
"title": "经营宝账号",
|
||||
"default": "",
|
||||
"description": "美团经营宝登录账号(手机号/账号)。与密码一起填写后自动登录;留空=手工登录"
|
||||
},
|
||||
"mt_password": {
|
||||
"type": "string",
|
||||
"title": "经营宝登录密码",
|
||||
"default": "",
|
||||
"format": "password",
|
||||
"description": "仅保存在本机(%LOCALAPPDATA%\\37duAutomation\\plugin_configs),下次免填;滑块/短信验证码仍需人工完成"
|
||||
},
|
||||
"action": {
|
||||
"type": "string",
|
||||
"title": "执行过程",
|
||||
"default": "all",
|
||||
"enum": ["all", "download", "reconcile"],
|
||||
"enum": [
|
||||
"all",
|
||||
"download",
|
||||
"reconcile"
|
||||
],
|
||||
"description": "all=下载后核对;download=只下载;reconcile=只核对(不下载)"
|
||||
},
|
||||
"do_download": {
|
||||
@@ -78,6 +97,18 @@
|
||||
"default": "",
|
||||
"description": "YYYY-MM-DD;留空=今天"
|
||||
},
|
||||
"save_dir": {
|
||||
"type": "string",
|
||||
"title": "保存目录",
|
||||
"default": "",
|
||||
"description": "账单下载到这里,台账也从这个目录读;留空=D:\\资料\\财务\\新美大平台核对"
|
||||
},
|
||||
"force_login": {
|
||||
"type": "boolean",
|
||||
"title": "强制重新登录",
|
||||
"default": false,
|
||||
"description": "清空浏览器 Cookie,忽略残留登录态直接等人工登录(换账号/排查登录问题)"
|
||||
},
|
||||
"run_merge": {
|
||||
"type": "boolean",
|
||||
"title": "并入台账",
|
||||
|
||||
@@ -21,16 +21,44 @@
|
||||
<span>{{ notice.text }}</span>
|
||||
</div>
|
||||
|
||||
<!-- 01 下载内容 -->
|
||||
<!-- 01 登录账号 -->
|
||||
<section v-show="form.do_download" class="sec">
|
||||
<div class="sec-head">
|
||||
<span class="sec-badge">01</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>
|
||||
<div class="tip">
|
||||
两项都填:登录时自动填写并提交(<b>失败自动降级为手工登录</b>);滑块 / 短信验证码、选商家
|
||||
无法自动完成,脚本会停在浏览器窗口等你处理。<br>
|
||||
都不填:完全手工登录(密码不会出现在「恢复上次参数」里)。
|
||||
</div>
|
||||
</el-form>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 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" />
|
||||
</div>
|
||||
<div class="sec-body">
|
||||
<el-form label-position="top">
|
||||
<div class="grid grid-switch">
|
||||
<div class="grid grid-mix">
|
||||
<el-form-item label="打款记录">
|
||||
<el-switch v-model="form.pay_enabled" :disabled="running" />
|
||||
</el-form-item>
|
||||
@@ -40,6 +68,14 @@
|
||||
<el-form-item label="预订收益明细">
|
||||
<el-switch v-model="form.profit_booking" :disabled="running" />
|
||||
</el-form-item>
|
||||
<el-form-item label="保存目录">
|
||||
<div class="dir-ctrl">
|
||||
<el-input v-model="form.save_dir" class="dir-input" :disabled="running" clearable
|
||||
placeholder="留空 = D:\资料\财务\新美大平台核对" />
|
||||
<el-button class="dir-btn" :disabled="running || picking" :loading="picking"
|
||||
@click="pickDir">选择</el-button>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</div>
|
||||
<div class="grid grid-date">
|
||||
<el-form-item label="打款记录 日期">
|
||||
@@ -54,39 +90,130 @@
|
||||
</el-form-item>
|
||||
</div>
|
||||
<div class="tip">
|
||||
打款记录:平台打款到门店的明细;收益明细:每笔券号/订单号、结算价、总收入、技术服务费、营销费用、渠道佣金。<br>
|
||||
默认昨天到今天;今天的账单次日才齐,需完整数据请选到昨天。
|
||||
打款记录:平台打款到门店的明细(金额 / 到账卡 / 状态 / 账单周期);
|
||||
收益明细:每笔券号、订单号、结算价、总收入、技术服务费、营销费用、渠道佣金。<br>
|
||||
默认昨天到今天;今天的账单次日才齐,需完整数据请选到昨天。区间内没有打款记录会跳过,不算失败。
|
||||
</div>
|
||||
</el-form>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 02 执行过程 -->
|
||||
<!-- 03 执行过程 -->
|
||||
<section class="sec">
|
||||
<div class="sec-head">
|
||||
<span class="sec-badge">02</span>
|
||||
<span class="sec-badge">03</span>
|
||||
<span class="sec-name">执行过程</span>
|
||||
<span class="sec-line" />
|
||||
</div>
|
||||
<div class="sec-body">
|
||||
<el-form label-position="top">
|
||||
<div class="grid grid-switch">
|
||||
<el-form-item label="下载数据">
|
||||
<el-switch v-model="form.do_download" :disabled="running" />
|
||||
</el-form-item>
|
||||
<el-form-item label="更新核对">
|
||||
<el-switch v-model="form.do_reconcile" :disabled="running" />
|
||||
</el-form-item>
|
||||
<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>
|
||||
<div class="tip">
|
||||
下载数据:登录经营宝,把账单下载到本机目录。<br>
|
||||
更新核对:读本机最新的台账与收益明细,把新记录并入台账并更新核对统计,不重新下载。
|
||||
只勾「更新核对」可单独补账(不开浏览器);下载与核对都勾则先下载再核对。
|
||||
</div>
|
||||
</el-form>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 操作区 -->
|
||||
<!-- 04 台账合并与核对表 -->
|
||||
<section v-show="form.do_reconcile" class="sec">
|
||||
<div class="sec-head">
|
||||
<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">收益明细按「验券/退款/调整时间」增量追加,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>
|
||||
<div class="tip">
|
||||
只勾这两项、不勾下载时可单独补账(不开浏览器);写入前自动备份(_备份 + 时间戳),
|
||||
写入期间请关闭该台账。
|
||||
</div>
|
||||
</el-form>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 流程说明:大段口径收进折叠区 -->
|
||||
<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 落盘到
|
||||
<b>%LOCALAPPDATA%\37duAutomation\.sessions\meituan_*</b>,浏览器档案在
|
||||
<b>browser_sessions\xq0041</b>,下次直接复用,过期才会再要求登录。</div>
|
||||
<div class="hb-line"><b>② 打款记录</b>:走 h5 账单页 iframe 里的 smartBill 三接口(查询 → 生成 → 导出记录 → 预签名直下),
|
||||
10 分钟内同区间记录直接复用不重复生成;<b>区间内没有打款记录按「跳过」处理</b>,不影响后续核对。</div>
|
||||
<div class="hb-line"><b>③ 收益明细</b>:走 PC 商户中心 downloadManagement,一次生成团购 + 预订两个文件;
|
||||
任一类型缺失或记录超过复用时效就整体重新生成,避免只拿到半套数据。</div>
|
||||
<div class="hb-line"><b>④ 并入台账</b>:明细并入保存目录里月份最新的
|
||||
<b>新美大到账统计YYYY.M月.xlsx</b> → sheet「金色印象--新美大导出(收)」。
|
||||
比台账最大验券时间旧的行剔除,其余按表头同名追加;<b>AF~AP 计算列按模板行自动下拉</b>
|
||||
(共享公式先找主定义再平移),尾部只剩公式的空行会先清掉。</div>
|
||||
<div class="hb-line"><b>⑤ 更新核对统计</b>:扫「新美大核对统计」整行所有
|
||||
<b>[n]资金组取数!$B$xx</b> 公式(实测 V/W/Y/Z),按 A 列日期把 [n] 换成当天那份共享总表
|
||||
\\caiwu01\共享文件夹\1111\TG\YYYY年M月\M.D\马敏团购总表M.D.xlsx;已是目标链接的单元格保留不动。</div>
|
||||
<div class="hb-line"><b>⑥ 注意</b>:保存目录同时是台账目录(并入台账 / 更新核对统计只读这个目录);
|
||||
共享盘不可达时公式照写,回内网点「更新链接」取值;写入期间请关闭该台账。</div>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<!-- 操作 -->
|
||||
<div class="actions">
|
||||
<el-button type="primary" class="btn-run" :loading="running" @click="start">
|
||||
{{ running ? '执行中 ' + progress + '%' : '一键执行' }}
|
||||
@@ -109,7 +236,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, watch } from 'vue'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { usePluginUI } from './usePluginUI'
|
||||
|
||||
@@ -121,17 +248,29 @@ function defaultRange() {
|
||||
return [fmt(y), fmt(today)]
|
||||
}
|
||||
|
||||
const DEFAULTS = () => ({
|
||||
do_download: true,
|
||||
do_reconcile: true,
|
||||
pay_enabled: true,
|
||||
pay_date_from: '',
|
||||
pay_date_to: '',
|
||||
profit_group: true,
|
||||
profit_booking: true,
|
||||
profit_date_from: '',
|
||||
profit_date_to: '',
|
||||
})
|
||||
// 首屏即带出「昨天 ~ 今天」,不依赖配置接口
|
||||
const DEFAULTS = () => {
|
||||
const [from, to] = defaultRange()
|
||||
return {
|
||||
mt_username: '',
|
||||
mt_password: '',
|
||||
do_download: true,
|
||||
do_reconcile: true,
|
||||
pay_enabled: true,
|
||||
pay_date_from: from,
|
||||
pay_date_to: to,
|
||||
profit_group: true,
|
||||
profit_booking: true,
|
||||
profit_date_from: from,
|
||||
profit_date_to: to,
|
||||
save_dir: '',
|
||||
force_login: false,
|
||||
run_merge: true,
|
||||
run_links: true,
|
||||
dry_run: false,
|
||||
debug_mode: false,
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
form, loaded, notice, lastSavedAt, running, progress, stopping,
|
||||
@@ -142,20 +281,31 @@ const {
|
||||
defaults: DEFAULTS,
|
||||
validate() {
|
||||
if (!form.do_download && !form.do_reconcile) {
|
||||
ElMessage.warning('请至少勾选一个执行过程(下载数据 / 更新核对)')
|
||||
ElMessage.warning('请至少选择一项执行过程(下载数据 / 更新核对)')
|
||||
return false
|
||||
}
|
||||
if (form.do_download && !form.pay_enabled && !form.profit_group && !form.profit_booking) {
|
||||
ElMessage.warning('请至少勾选一项要下载的内容(打款记录 / 团购 / 预订)')
|
||||
return false
|
||||
}
|
||||
const pairs = [
|
||||
['打款记录', form.pay_date_from, form.pay_date_to],
|
||||
['收益明细', form.profit_date_from, form.profit_date_to],
|
||||
]
|
||||
for (const [label, f, t] of pairs) {
|
||||
const a = (f || '').trim()
|
||||
const b = (t || '').trim()
|
||||
if (form.do_reconcile && !form.run_merge && !form.run_links) {
|
||||
ElMessage.warning('更新核对里请至少勾选一项(并入台账 / 更新核对统计)')
|
||||
return false
|
||||
}
|
||||
const user = (form.mt_username || '').trim()
|
||||
const pwd = (form.mt_password || '').trim()
|
||||
if (form.do_download && (user || pwd) && !(user && pwd)) {
|
||||
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) {
|
||||
pairs.push(['收益明细', form.profit_date_from, form.profit_date_to])
|
||||
}
|
||||
for (const [label, rawA, rawB] of pairs) {
|
||||
const a = (rawA || '').trim()
|
||||
const b = (rawB || '').trim()
|
||||
if (a && b && a > b) {
|
||||
ElMessage.warning(`${label}的开始日期不能晚于结束日期`)
|
||||
return false
|
||||
@@ -167,6 +317,8 @@ const {
|
||||
const t = (v) => (v || '').trim()
|
||||
const action = 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),
|
||||
action,
|
||||
pay_enabled: !!f.pay_enabled,
|
||||
pay_date_from: t(f.pay_date_from),
|
||||
@@ -175,11 +327,12 @@ const {
|
||||
profit_booking: !!f.profit_booking,
|
||||
profit_date_from: t(f.profit_date_from),
|
||||
profit_date_to: t(f.profit_date_to),
|
||||
// 核对就是完整流程:并入台账 + 更新核对统计,不做演练
|
||||
run_merge: true,
|
||||
run_links: true,
|
||||
dry_run: false,
|
||||
debug_mode: false,
|
||||
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),
|
||||
debug_mode: !!f.debug_mode,
|
||||
}
|
||||
},
|
||||
})
|
||||
@@ -188,9 +341,29 @@ function start() {
|
||||
run()
|
||||
}
|
||||
|
||||
// 调用壳子本机接口打开原生「选择文件夹」对话框(壳子 /api/dialog/directory,仅返回路径)
|
||||
const picking = ref(false)
|
||||
async function pickDir() {
|
||||
picking.value = true
|
||||
try {
|
||||
const r = await fetch('/api/dialog/directory', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ title: '选择保存目录', current: form.save_dir || '' }),
|
||||
})
|
||||
const d = await r.json().catch(() => ({}))
|
||||
if (!r.ok) throw new Error(d.detail || d.error || ('HTTP ' + r.status))
|
||||
if (d.path) form.save_dir = d.path
|
||||
} catch (e) {
|
||||
ElMessage.warning('打开文件夹选择失败:' + e.message)
|
||||
} finally {
|
||||
picking.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const profitOn = computed(() => form.profit_group || form.profit_booking)
|
||||
|
||||
// 日期范围选择器 ↔ 两个字段(plugin.json 仍以 *_date_from/to 为契约,定时任务兼容)
|
||||
// 日期区间选择器 ↔ 两个字段(plugin.json 仍以 *_date_from/to 为契约,定时任务兼容)
|
||||
function makeRange(getFrom, getTo, setFrom, setTo) {
|
||||
return computed({
|
||||
get: () => {
|
||||
@@ -228,3 +401,12 @@ watch(loaded, (v) => {
|
||||
}
|
||||
}, { immediate: true })
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 插件差异样式:只用壳子 token,不写字面色值;左右内边距由壳子提供 */
|
||||
/* 三个开关(窄列)+ 保存目录(撑满剩余宽度)排一行 */
|
||||
.grid-mix { grid-template-columns: 96px 110px 110px minmax(220px, 1fr); }
|
||||
.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; }
|
||||
</style>
|
||||
|
||||
@@ -99,7 +99,7 @@ export function usePluginUI(opts = {}) {
|
||||
let pollTimer = null
|
||||
let saveTimer = null
|
||||
|
||||
// 传空 type 视为清除横幅(不能留 {type:null},否则会渲染成只有"!"的空横幅)
|
||||
// 传空 type 视为清除横幅(不能留 {type:null},否则会渲染成只有"!"的空横幅)
|
||||
const notify = (type, text) => { notice.value = type ? { type, text } : null }
|
||||
|
||||
// ---------- 当前配置:加载 / 防抖自动保存 ----------
|
||||
@@ -303,7 +303,8 @@ export function usePluginUI(opts = {}) {
|
||||
ws = connectWS((ev) => {
|
||||
if (ev.run_id && ev.run_id !== runId) return
|
||||
if (ev.t === 'progress') progress.value = Math.max(progress.value, ev.pct || 0)
|
||||
else if (ev.t === 'run_done') ev.ok ? finished() : failed(ev.error || '执行失败')
|
||||
// 用户强制停止 / 排队取消 / 排队超时 → 「已取消」,不显示成「执行失败」
|
||||
else if (ev.t === 'run_done') ev.ok ? finished() : (ev.status === 'cancelled' ? cancelled(ev.error) : failed(ev.error || '执行失败'))
|
||||
})
|
||||
ws.onclose = () => { ws = null }
|
||||
}
|
||||
@@ -315,6 +316,7 @@ export function usePluginUI(opts = {}) {
|
||||
try {
|
||||
const r = await getRun(runId)
|
||||
if (r.status === 'done') finished(r.result?.summary)
|
||||
else if (r.status === 'cancelled') cancelled(r.error)
|
||||
else if (r.status === 'error') failed(r.error || '执行失败')
|
||||
} catch (_) { /* 下轮再试 */ }
|
||||
}, 5000)
|
||||
@@ -332,6 +334,13 @@ export function usePluginUI(opts = {}) {
|
||||
if (summary) notify('ok', summary)
|
||||
}
|
||||
|
||||
// 用户主动停止 / 排队取消 / 排队超时:不算失败,给中性的「已取消」提示
|
||||
function cancelled(err) {
|
||||
stopPolling()
|
||||
running.value = false
|
||||
notify('warn', '任务已取消:' + (err || '用户已停止'))
|
||||
}
|
||||
|
||||
function failed(err) {
|
||||
stopPolling()
|
||||
running.value = false
|
||||
|
||||
+23
-23
File diff suppressed because one or more lines are too long
+1
-1
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-BrrwpQZq.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/pui/xq0041/assets/index-DNbLqZHI.css">
|
||||
<script type="module" crossorigin src="/pui/xq0041/assets/index-CBLp7rYV.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/pui/xq0041/assets/index-Du0XtKs7.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>␍
|
||||
|
||||
Reference in New Issue
Block a user