backend: 接入 SQLite 数据库 + 开单后台按功能重写
- store.py(新):卡密 / 订单信息 / 爱发电账本 / 呼叫记录 / 小块状态进 <DATA_DIR>/ys.db; 第一次启动自动建库并导入旧 JSON(旧文件不动),admin.py db check/backup/export - server.py / admin.py 存取换到库上,路由与接口字段不变;calls.jsonl 照旧追加 - 管理接口新增 calls / call-done / retry,codes 支持 q 搜索 - ys_admin.py 页面重写:待处理 / 订单 / 卡密 / 福利券 / 呼叫·反馈 / 开单工具 - tests/数据库测试.py(37 条,假数据);回归 27 条照旧全过 - 交接说明(数据库一节、面板一节)、回执第二轮、交付清单更新 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
python3 admin.py calls 看「呼叫金钻」记录
|
||||
python3 admin.py sweep 清理超过保留期的成品
|
||||
python3 admin.py stat 概览
|
||||
python3 admin.py db [check|backup|export [目录]] 数据库:体检 / 热备份 / 导回旧版 JSON
|
||||
python3 admin.py audit [行数] 看兑换码失败/被拒记录
|
||||
"""
|
||||
import csv, json, os, shutil, sys, time
|
||||
@@ -267,15 +268,33 @@ def cmd_retry(argv):
|
||||
print("%s 已退回队列" % oid)
|
||||
|
||||
|
||||
def cmd_db(argv):
|
||||
"""数据库(<DATA_DIR>/ys.db,2026-10-05 起)。服务器不用停。"""
|
||||
sub = (argv or ["check"])[0]
|
||||
if sub == "check":
|
||||
ok, n, imp = S.STORE.check()
|
||||
print("库文件:%s" % S.STORE.path)
|
||||
print("完整性:%s" % ok)
|
||||
for k, v in n.items():
|
||||
print(" %-10s %d 行" % (k, v))
|
||||
print("订单(按状态):%s" % (S.STORE.order_counts() or "无"))
|
||||
print("卡密(按状态):%s" % (S.STORE.code_counts() or "无"))
|
||||
print("旧数据导入:%s" % (imp or "(没导过)"))
|
||||
elif sub == "backup":
|
||||
print("备份好了:%s" % S.STORE.backup())
|
||||
elif sub == "export":
|
||||
print("已导出到 %s" % S.STORE.export_legacy(argv[1] if len(argv) > 1 else None))
|
||||
else:
|
||||
print("用法:admin.py db [check|backup|export [目录]]")
|
||||
|
||||
|
||||
def cmd_calls(argv):
|
||||
try:
|
||||
for line in open(S.CALLS_FILE, encoding="utf-8"):
|
||||
if line.strip():
|
||||
r = json.loads(line)
|
||||
print("%s 订单=%s IP=%s %s" % (r["ts"], r.get("order") or "-",
|
||||
r.get("ip"), "已通知" if r.get("notified") else "未通知"))
|
||||
except OSError:
|
||||
rows = S.STORE.calls() # 数据库 calls 表(2026-10-05 起;calls.jsonl 只是给手机通知的副本)
|
||||
if not rows:
|
||||
print("(没有呼叫记录)")
|
||||
for r in rows:
|
||||
print("%s 订单=%s IP=%s %s %s" % (r.get("ts"), r.get("order") or "-", r.get("ip"),
|
||||
"已通知" if r.get("notified") else "未通知", r.get("kind") or "呼叫"))
|
||||
|
||||
|
||||
def cmd_sweep(argv):
|
||||
@@ -285,8 +304,8 @@ def cmd_sweep(argv):
|
||||
⚠️ 删文件之前先把卡密核销 —— 否则文件没了、码还挂在「已激活」,账永远对不上。
|
||||
"""
|
||||
n = freed = settled = 0
|
||||
for oid in list(os.listdir(S.ORDERS)):
|
||||
d = os.path.join(S.ORDERS, oid)
|
||||
for oid in S.STORE.order_ids():
|
||||
d = S.order_dir(oid)
|
||||
m = S.read_meta(oid)
|
||||
if not m:
|
||||
continue
|
||||
@@ -306,7 +325,7 @@ def cmd_sweep(argv):
|
||||
freed += os.path.getsize(os.path.join(root, f))
|
||||
except OSError:
|
||||
pass
|
||||
shutil.rmtree(d, ignore_errors=True)
|
||||
S.purge_order(oid) # 删文件;库里那一行留着记账(之后当它不存在)
|
||||
n += 1
|
||||
# 文件还在、但开放下载已满 72 小时的,也一起核销
|
||||
settled += sum(x[1] for x in S.settle_due())
|
||||
@@ -534,7 +553,7 @@ def cmd_gift(argv):
|
||||
CMDS = {"gen": cmd_gen, "codes": cmd_codes, "ls": cmd_ls, "show": cmd_show,
|
||||
"gift": cmd_gift,
|
||||
"price": cmd_price,
|
||||
"retry": cmd_retry, "calls": cmd_calls, "sweep": cmd_sweep, "stat": cmd_stat,
|
||||
"retry": cmd_retry, "calls": cmd_calls, "db": cmd_db, "sweep": cmd_sweep, "stat": cmd_stat,
|
||||
"audit": cmd_audit, "activate": cmd_activate, "pending": cmd_pending,
|
||||
"edit": cmd_edit}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user