Skip to content

Commit 1332587

Browse files
committed
Feat: 新增自定义发货人功能 (支持在/setup中配置)
1 parent e7e672b commit 1332587

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

database/storage.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
points_loss INTEGER DEFAULT 30,
5050
5151
limit_post_daily INTEGER DEFAULT 5,
52-
rank_config JSON
52+
rank_config JSON,
53+
54+
seller_id INTEGER -- [新增] 发货人ID
5355
);
5456
5557
-- 2. 用户资产表
@@ -155,6 +157,13 @@ async def check_and_migrate_schema():
155157
except Exception:
156158
try: await db.execute("ALTER TABLE groups ADD COLUMN limit_post_daily INTEGER DEFAULT 5")
157159
except: pass
160+
161+
# [新增] 检查 seller_id 字段
162+
try:
163+
await db.execute("SELECT seller_id FROM groups LIMIT 1")
164+
except Exception:
165+
try: await db.execute("ALTER TABLE groups ADD COLUMN seller_id INTEGER")
166+
except: pass
158167

159168
# 3. products / orders 表
160169
try: await db.execute("SELECT group_id FROM products LIMIT 1")

handlers/setup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ async def setup_menu_callback(update: Update, context: ContextTypes.DEFAULT_TYPE
8888
"set_p_lose": ("points_loss", "晒损送多少分?"),
8989
"set_p_limit": ("limit_post_daily", "每日晒单上限是多少次?\n(输入 -2 表示无限制)"),
9090
"set_rank": ("rank_config", "请输入段位规则 JSON (建议5档):\n例如: `{\"0\":\"🌱茁壮韭菜\", \"100\":\"💎钻石双手\", \"500\":\"🐋潜水巨鲸\", \"2000\":\"📈K线主宰\", \"5000\":\"🚀交易战神\"}`"),
91+
# [新增] 设置发货人ID
92+
"set_seller": ("seller_id", "请输入 **发货人** 的 Telegram ID (数字):\n(让他对自己发送 /id 即可获取,如果不设置则不显示)")
9193
}
9294

9395
if data in input_map:
@@ -136,6 +138,9 @@ def limit_str(v): return "♾️无限" if v == -2 else f"{v}次"
136138
[InlineKeyboardButton("设晒盈分", callback_data="set_p_win"), InlineKeyboardButton("设晒损分", callback_data="set_p_lose")],
137139
[InlineKeyboardButton("🏅 设置段位表", callback_data="set_rank")],
138140

141+
# [新增] 发货人设置
142+
[InlineKeyboardButton(f"📦 发货人ID: {val(info['seller_id'])}", callback_data="set_seller")],
143+
139144
[InlineKeyboardButton(f"早报 {ic(info['sub_news'])}", callback_data="tg_news"), InlineKeyboardButton("设ID", callback_data="set_news")],
140145
[InlineKeyboardButton(f"分析 {ic(info['sub_analysis'])}", callback_data="tg_analysis"), InlineKeyboardButton("设ID", callback_data="set_ana")],
141146
[InlineKeyboardButton(f"战绩 {ic(info['sub_marketing'])}", callback_data="tg_marketing"), InlineKeyboardButton("设ID", callback_data="set_mkt")],
@@ -153,7 +158,7 @@ async def save_input(update: Update, context: ContextTypes.DEFAULT_TYPE):
153158
text = update.message.text.strip()
154159

155160
# 1. 数字校验
156-
if any(x in key for x in ["points", "topic", "limit"]):
161+
if any(x in key for x in ["points", "topic", "limit", "seller_id"]):
157162
try:
158163
val = int(text)
159164
if val == -1 and "topic" in key: val = None

handlers/shop.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,21 @@ async def callback_buy_confirm(update: Update, context: ContextTypes.DEFAULT_TYP
246246
prod = await get_product(pid)
247247
p_name = prod['name'] if prod else "商品"
248248

249+
# [新增] 尝试获取群组设置的发货人ID
250+
group_info = await get_group(chat.id)
251+
seller_text = "请把此码发给本群管理员"
252+
253+
if group_info and group_info['seller_id']:
254+
seller_id = group_info['seller_id']
255+
# 生成点击链接,这里会直接触发Telegram的@功能
256+
seller_text = f"请联系发货人: [点击联系](tg://user?id={seller_id})"
257+
249258
txt = (
250259
f"🎉 **购买成功!**\n\n"
251260
f"🏠 群组: {html.escape(chat.title)}\n"
252261
f"📦 商品: {p_name}\n"
253262
f"🔑 **核销码**: `{code}`\n\n"
254-
f"⚠️ 请把此码发给本群管理员进行兑换。"
263+
f"⚠️ {seller_text} 进行兑换。"
255264
)
256265
try:
257266
await context.bot.send_message(user.id, txt, parse_mode=ParseMode.MARKDOWN)
@@ -260,6 +269,7 @@ async def callback_buy_confirm(update: Update, context: ContextTypes.DEFAULT_TYP
260269
await query.message.reply_text(
261270
f"✅ {user.full_name} 购买成功!\n"
262271
f"您的核销码: `{code}`\n"
272+
f"⚠️ {seller_text}\n"
263273
f"请截图保存 (无法私聊您)",
264274
parse_mode=ParseMode.MARKDOWN
265275
)

0 commit comments

Comments
 (0)