# -*- coding: utf-8 -*- """生成微信虚拟支付「批量创建道具」xlsx(运营货架文案)。""" from __future__ import annotations from pathlib import Path import openpyxl from openpyxl.styles import Alignment, Font # 图片须可被 mp.weixin.qq.com CORS 拉取;名称≤10字;备注≤50且不对外 IMG_BASE = "https://admin.nomadro.cn/props" # 按价位从低到高:给用户看的货架,不是开发草稿 ROWS = [ # (道具id, 道具名称, 图片URL, 价格元, 备注说明) ("nomad_lite", "轻享全书", f"{IMG_BASE}/nomad_lite.png", 29, "入门价·首次解锁单本推荐"), ("nomad", "漫游全书", f"{IMG_BASE}/nomad.png", 49, "标准漫游档·性价比主推"), ("tiktok", "短视频全书", f"{IMG_BASE}/tiktok.png", 88, "短视频向专题全书"), ("youtube", "长视频全书", f"{IMG_BASE}/youtube.png", 188, "长视频向·默认推荐档"), ("ebook_unlock_default", "经典全书", f"{IMG_BASE}/ebook.png", 188, "历史默认档·兼容旧订单"), ("nomad_plus", "进阶全书", f"{IMG_BASE}/nomad_plus.png", 298, "进阶价·高价值小册"), ("nomad_pro", "精英全书", f"{IMG_BASE}/nomad_pro.png", 588, "精英价·深度专题册"), ("svip", "超级会员", f"{IMG_BASE}/svip.png", 998, "旗舰会员·最高权益档"), ("pay_test", "联调占位", f"{IMG_BASE}/pay_test.png", 1, "仅内部联调·禁止对用户上架"), ] _DOCS = Path(__file__).resolve().parents[1] / "docs" OUT_DIRS = [ _DOCS / "wx-props-batch", _DOCS, Path(r"c:\Users\Administrator\Desktop"), ] def main() -> None: wb = openpyxl.Workbook() ws = wb.active ws.title = "Sheet1" # 微信模板列名以官方 example 为准(道具价格 / 备注) headers = ["道具id", "道具名称", "道具图片", "道具价格", "备注"] ws.append(headers) for cell in ws[1]: cell.font = Font(bold=True) cell.alignment = Alignment(wrap_text=True) for row in ROWS: pid, name, url, price, remark = row assert len(pid) <= 32 and pid.isascii() and all(c.isalnum() or c == "_" for c in pid) assert 1 <= len(name) <= 10 assert url.lower().endswith((".png", ".jpg", ".jpeg")) assert isinstance(price, int) and 1 <= price <= 10000 assert len(remark) <= 50 ws.append(list(row)) ws.column_dimensions["A"].width = 24 ws.column_dimensions["B"].width = 14 ws.column_dimensions["C"].width = 56 ws.column_dimensions["D"].width = 12 ws.column_dimensions["E"].width = 32 name = "nomadro_wx_props_batch_upload.xlsx" for d in OUT_DIRS: d.mkdir(parents=True, exist_ok=True) path = d / name wb.save(path) print("wrote", path, "rows", len(ROWS)) if __name__ == "__main__": main()