Files
37duAutomation/plugins/xq0048/__init__.py
T
puddy 843ff244a6 feat: 新增多插件 UI 支持及运行日志集中回传功能
本次提交包含多项功能更新:
1. 为多个插件(xq0002/0003/0004/0008/0010/0011/0020/0031_xq0032/0033/0035/0037/0045_xq0046/0047/0048)新增 UI 界面及配置支持
2. 新增运行日志集中回传功能,客户端自动上传运行日志到中心机集中存储
3. 新增插件分类字段支持,用于场景库分组管理
4. 优化 xq0034/0037/0048 等插件的功能及描述
5. 修复控制面响应兼容问题,支持新旧版本数据格式
6. 新增 xq0033 插件的状态存储模块,用于历史记录管理
7. 优化 CRM 登录窗口模式,支持全屏置顶
2026-10-26 15:42:50 +08:00

80 lines
3.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""CRM数据导出 - webhost 场景插件(XQ0048)
流程:
1) 登录态预检(API 校验 %LOCALAPPDATA%\\37duAutomation\\.sessions\\crm_cookie_header.txt);
有效则全程免扫码,失效则打开可见浏览器等钉钉扫码一次(同次运行最多弹一次);
2) 打开「报表统计/储值卡余额」整页截图 → 储值卡余额-YYYYMMDD.png;
3) requests 复用同一登录态,按日期规则导出 18 张报表 xlsx
(礼品卡订单因接口限制跨度 ≤31 天,近 3 个自然月按月拆分)。
"""
import os
from webhost.backend.plugins.base import PLUGINS, ScenePlugin
from . import config
from .data import crm_export
class CrmDataExportPlugin(ScenePlugin):
id = "xq0048"
name = "CRM数据导出"
version = "1.1.6"
description = ("37du CRM(crm.37du.co)数据导出:储值卡余额整页截图 + 18 张报表自动导出(导出内容可勾选),"
"登录态钉钉扫码一次后缓存复用(约 30 分钟内免扫码),"
"按各报表日期规则自动计算区间,礼品卡订单按月拆分")
platform = "" # CRM 为钉钉扫码登录,插件内自带登录流程,不使用底座共享登录态
uses_month = False
capabilities = ["xq0048"]
permissions = {"platforms": []}
# 与 plugin.json.fields 一致
fields = {
"reports": {"type": "array", "title": "导出内容", "default": [],
"description": "勾选键列表(截图=__screenshot__,报表=接口#规则);空/缺省=全部导出"},
"save_dir": {"type": "string", "title": "保存目录", "default": "",
"description": "留空=D:\\资料\\财务\\CRM数据导出"},
"debug_mode": {"type": "boolean", "title": "调试日志", "default": False},
}
def run(self, fields, ctx) -> dict:
fields = fields or {}
config.set_log(ctx.log)
config.set_progress(ctx.progress)
config.set_debug(bool(fields.get("debug_mode")))
save_dir = str(fields.get("save_dir") or "").strip().strip('"') or config.default_output_dir()
os.makedirs(save_dir, exist_ok=True)
ctx.log(f"保存目录:{save_dir}")
report_keys = fields.get("reports")
reports, include_shot = config.filter_reports(report_keys)
if not reports and not include_shot:
raise RuntimeError("未勾选任何导出内容,请至少勾选一项")
if report_keys is None:
ctx.log("导出内容:全部(截图 + %d 张报表)" % len(reports))
else:
ctx.log(f"导出内容:{'截图、' if include_shot else ''}{len(reports)} 张报表(按勾选)")
result = crm_export.run_export(save_dir, report_keys=report_keys)
config.progress(100)
files = result.get("exports") or []
shot_part = f"截图 {1 if result.get('screenshot') else 0}/1," if include_shot else ""
summary = (f"{shot_part}"
f"报表 {result.get('done')}/{result.get('total')},"
f"共 {len(files) + (1 if result.get('screenshot') else 0)} 个文件")
return {
"summary": summary,
"detail": {
"screenshot": result.get("screenshot") or "",
"reports_done": result.get("done", 0),
"reports_total": result.get("total", 0),
"files": files,
"save_dir": save_dir,
},
"path": save_dir,
}
PLUGINS.append(CrmDataExportPlugin())