Align live pay catalog with WeChat ops SKUs and shelf names.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Eric 2026-11-22 11:18:12 +08:00
parent ac1239c828
commit 76c22c23f4
9 changed files with 280 additions and 13 deletions

View File

@ -0,0 +1,109 @@
# -*- coding: utf-8 -*-
"""Push ops prop catalog (products.py / vip_config) to api.nomadro.cn + migrate old SKUs."""
from __future__ import annotations
from pathlib import Path
import paramiko
REPO = Path(__file__).resolve().parents[3]
HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805"
FILES = [
(
REPO / "apps/api/services/ebook_svc/domains/books/products.py",
"/opt/nomadmini/backend/app/domains/books/products.py",
),
(
REPO / "apps/api/services/ebook_svc/services/vip_config.py",
"/opt/nomadmini/backend/app/services/vip_config.py",
),
]
def rewrite(text: str) -> str:
return text.replace("ebook_svc.", "app.")
def main() -> None:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, username=USER, password=PASS, timeout=40, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
for src, dest in FILES:
data = rewrite(src.read_text(encoding="utf-8")).encode("utf-8")
tmp = f"/tmp/{Path(dest).name}"
with sftp.file(tmp, "wb") as rf:
rf.write(data)
print("up", src.name, "->", dest, len(data))
sftp.close()
remote = r"""
set -e
sudo cp /tmp/products.py /opt/nomadmini/backend/app/domains/books/products.py
sudo cp /tmp/vip_config.py /opt/nomadmini/backend/app/services/vip_config.py
sudo chown -R ubuntu:ubuntu /opt/nomadmini/backend/app/domains/books/products.py /opt/nomadmini/backend/app/services/vip_config.py
# 旧微信草稿 id → 新运营 SKU(书籍 + 商城商品)
python3 <<'PY'
import sqlite3
db = "/opt/nomadmini/data/nomadmini.db"
con = sqlite3.connect(db)
maps = {
"29": "nomad_lite",
"298": "nomad_plus",
"588": "nomad_pro",
"test": "pay_test",
}
# books.product_id
for old, new in maps.items():
cur = con.execute("update books set product_id=? where product_id=?", (new, old))
print("books", old, "->", new, "rows", cur.rowcount)
# shop products wxProductId if column exists
cols = {r[1] for r in con.execute("pragma table_info(shop_products)").fetchall()} if con.execute(
"select name from sqlite_master where type='table' and name='shop_products'"
).fetchone() else set()
if "wxProductId" in cols or "wx_product_id" in cols:
col = "wxProductId" if "wxProductId" in cols else "wx_product_id"
for old, new in maps.items():
cur = con.execute(f"update shop_products set {col}=? where {col}=?", (new, old))
print("shop", old, "->", new, "rows", cur.rowcount)
# goods table variants
for table in ("products", "goods"):
row = con.execute(
"select name from sqlite_master where type='table' and name=?", (table,)
).fetchone()
if not row:
continue
cols = {r[1] for r in con.execute(f"pragma table_info({table})").fetchall()}
for col in ("wxProductId", "wx_product_id", "product_id"):
if col not in cols:
continue
for old, new in maps.items():
cur = con.execute(f"update {table} set {col}=? where {col}=?", (new, old))
if cur.rowcount:
print(table, col, old, "->", new, "rows", cur.rowcount)
con.commit()
# show current book SKUs
print("--- books product_id ---")
for r in con.execute("select id, title, product_id, price_fen from books order by id").fetchall():
print(r)
con.close()
PY
sudo systemctl restart nomadmini-api.service
sleep 2
systemctl is-active nomadmini-api.service
curl -s http://127.0.0.1:8010/health || true
echo
"""
_, o, e = c.exec_command(remote, timeout=120)
print(o.read().decode())
err = e.read().decode()
if err:
print("stderr", err[-2000:])
c.close()
if __name__ == "__main__":
main()

View File

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
from __future__ import annotations
import paramiko
HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805"
CMD = r"""
set -e
echo '=== file head ==='
head -8 /opt/nomadmini/backend/app/domains/books/products.py
echo '=== grep nomad_lite ==='
grep -n nomad_lite /opt/nomadmini/backend/app/domains/books/products.py || true
echo '=== processes ==='
ps aux | grep -E 'uvicorn|nomadmini|gunicorn|8010' | grep -v grep || true
echo '=== pm2 ==='
pm2 list 2>/dev/null || true
echo '=== systemd units ==='
ls /etc/systemd/system/*nom* /etc/systemd/system/*ebook* /etc/systemd/system/*api* 2>/dev/null || true
echo '=== how 8010 listens ==='
sudo ss -lntp | grep -E '8010|8000' || true
echo '=== find restart scripts ==='
ls /opt/nomadmini/*.sh /opt/nomadmini/backend/*.sh 2>/dev/null || true
cat /opt/nomadmini/ecosystem.config.* 2>/dev/null || true
"""
def main() -> None:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, username=USER, password=PASS, timeout=40, allow_agent=False, look_for_keys=False)
_, o, e = c.exec_command(CMD, timeout=60)
print(o.read().decode())
err = e.read().decode()
if err:
print("STDERR", err[-1500:])
c.close()
if __name__ == "__main__":
main()

View File

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
from __future__ import annotations
from pathlib import Path
import paramiko
REPO = Path(__file__).resolve().parents[3]
HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805"
SRC = REPO / "apps/api/services/ebook_svc/routers/admin.py"
DEST = "/opt/nomadmini/backend/app/routers/admin.py"
def main() -> None:
data = SRC.read_text(encoding="utf-8").replace("ebook_svc.", "app.").encode("utf-8")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, username=USER, password=PASS, timeout=40, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
with sftp.file("/tmp/admin.py", "wb") as rf:
rf.write(data)
sftp.close()
_, o, e = c.exec_command(
"sudo cp /tmp/admin.py /opt/nomadmini/backend/app/routers/admin.py && "
"sudo systemctl restart nomadmini-api.service && sleep 2 && "
"systemctl is-active nomadmini-api.service && curl -s http://127.0.0.1:8010/health",
timeout=60,
)
print(o.read().decode())
err = e.read().decode()
if err:
print("STDERR", err[-800:])
c.close()
if __name__ == "__main__":
main()

View File

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
from __future__ import annotations
import json
import urllib.request
import paramiko
HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805"
def main() -> None:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, username=USER, password=PASS, timeout=40, allow_agent=False, look_for_keys=False)
_, o, e = c.exec_command(
"sudo systemctl restart nomadmini-api.service && sleep 2 && "
"systemctl is-active nomadmini-api.service && "
"curl -s http://127.0.0.1:8010/health",
timeout=60,
)
print(o.read().decode())
err = e.read().decode()
if err:
print("STDERR", err[-1000:])
c.close()
req = urllib.request.Request(
"https://api.nomadro.cn/api/admin/login",
data=json.dumps({"username": "admin", "password": "Xiao4669805"}).encode(),
headers={"Content-Type": "application/json"},
method="POST",
)
tok = json.loads(urllib.request.urlopen(req, timeout=20).read()).get("token", "")
req2 = urllib.request.Request(
"https://api.nomadro.cn/api/admin/product-offers",
headers={"Authorization": "Bearer " + tok},
)
items = json.loads(urllib.request.urlopen(req2, timeout=20).read()).get("items") or []
for o in items:
print(o.get("key"), o.get("product_id"), o.get("name"), o.get("price_yuan"), o.get("remark"))
if __name__ == "__main__":
main()

View File

@ -21,6 +21,7 @@ type Book = {
chapter_count?: number
word_count?: number
offer_key?: string
offer_name?: string
is_free?: boolean
}
@ -312,7 +313,7 @@ export default function BookEdit() {
<span className="live-preview-sub">
{isFree
? '免费模式 · 无支付墙'
: `道具 ${book.product_id || '-'} · 试读 ${Math.min(99, book.unlock_percent)}%`}
: `${book.offer_name || book.product_id || '-'} · 试读 ${Math.min(99, book.unlock_percent)}%`}
</span>
</div>
</div>
@ -336,9 +337,9 @@ export default function BookEdit() {
) : (
<div className="offer-free-badge">{o.product_id.slice(0, 6)}</div>
)}
<strong>{o.label}</strong>
<strong>{o.name || o.label}</strong>
<span className="offer-id">
{o.free ? 'unlock=100%' : o.product_id}
{o.free ? '免费加入' : o.product_id}
</span>
<em>{o.price_yuan}</em>
{o.remark ? <i className="offer-remark">{o.remark}</i> : null}

View File

@ -366,7 +366,7 @@ export default function Shop() {
) : (
<div className="offer-free-badge">{o.product_id.slice(0, 6)}</div>
)}
<strong>{o.label}</strong>
<strong>{o.name || o.label}</strong>
<span className="offer-id">{o.product_id}</span>
<em>{o.price_yuan}</em>
{o.remark ? <i className="offer-remark">{o.remark}</i> : null}

View File

@ -484,7 +484,7 @@ export default function Vip() {
<em>
{isFree
? '免费模式 · 不拉起虚拟支付'
: `道具 ${draft.vipProductId || '-'} · ¥${(draft.vipPriceFen / 100).toFixed(0)}`}
: `${offers.find((o) => o.product_id === draft.vipProductId)?.name || draft.vipProductId || '-'} · ¥${(draft.vipPriceFen / 100).toFixed(0)}`}
</em>
</div>
</div>
@ -508,7 +508,7 @@ export default function Vip() {
) : (
<div className="offer-free-badge">{o.product_id.slice(0, 6)}</div>
)}
<strong>{o.label}</strong>
<strong>{o.name || o.label}</strong>
<span className="offer-id">{o.free ? '免费加入' : o.product_id}</span>
<em>{o.price_yuan}</em>
{o.remark && !o.remark.includes('unlock_percent') ? (

View File

@ -138,7 +138,12 @@ async def admin_book(book_id: str, _: str = Depends(require_admin)):
if not book:
raise HTTPException(404, "不存在")
offer = match_offer(book)
return {**book, "offer_key": offer["key"], "is_free": is_book_free(book)}
return {
**book,
"offer_key": offer["key"],
"offer_name": offer.get("name") or offer.get("label"),
"is_free": is_book_free(book),
}
@router.put("/books/{book_id}")
@ -160,7 +165,12 @@ async def admin_update_book(book_id: str, body: BookPatch, _: str = Depends(requ
except Exception:
pass
offer = match_offer(book)
return {**book, "offer_key": offer["key"], "is_free": is_book_free(book)}
return {
**book,
"offer_key": offer["key"],
"offer_name": offer.get("name") or offer.get("label"),
"is_free": is_book_free(book),
}
@router.post("/books/{book_id}/offer")
@ -181,7 +191,12 @@ async def admin_apply_offer(
except Exception:
pass
offer = match_offer(updated)
return {**updated, "offer_key": offer["key"], "is_free": is_book_free(updated)}
return {
**updated,
"offer_key": offer["key"],
"offer_name": offer.get("name") or offer.get("label"),
"is_free": is_book_free(updated),
}
@router.get("/books/{book_id}/markdown")

View File

@ -108,7 +108,12 @@ async def admin_create_book(body: BookCreateBody, _: str = Depends(require_admin
except Exception:
pass
offer = match_offer(book)
return {**book, "offer_key": offer["key"], "is_free": is_book_free(book)}
return {
**book,
"offer_key": offer["key"],
"offer_name": offer.get("name") or offer.get("label"),
"is_free": is_book_free(book),
}
@router.delete("/books/{book_id}")
@ -138,7 +143,12 @@ async def admin_book(book_id: str, _: str = Depends(require_admin)):
if not book:
raise HTTPException(404, "不存在")
offer = match_offer(book)
return {**book, "offer_key": offer["key"], "is_free": is_book_free(book)}
return {
**book,
"offer_key": offer["key"],
"offer_name": offer.get("name") or offer.get("label"),
"is_free": is_book_free(book),
}
@router.put("/books/{book_id}")
@ -160,7 +170,12 @@ async def admin_update_book(book_id: str, body: BookPatch, _: str = Depends(requ
except Exception:
pass
offer = match_offer(book)
return {**book, "offer_key": offer["key"], "is_free": is_book_free(book)}
return {
**book,
"offer_key": offer["key"],
"offer_name": offer.get("name") or offer.get("label"),
"is_free": is_book_free(book),
}
@router.post("/books/{book_id}/offer")
@ -181,7 +196,12 @@ async def admin_apply_offer(
except Exception:
pass
offer = match_offer(updated)
return {**updated, "offer_key": offer["key"], "is_free": is_book_free(updated)}
return {
**updated,
"offer_key": offer["key"],
"offer_name": offer.get("name") or offer.get("label"),
"is_free": is_book_free(updated),
}
@router.get("/books/{book_id}/markdown")