/** * 为指定手机号用户插入一条「已审核」主播档案(若尚无 approved + userId 绑定) * 用法:pnpm exec tsx scripts/bind-approved-streamer.ts [手机号] * 默认:15880802661 */ import { config } from "dotenv" import { resolve } from "path" config({ path: resolve(process.cwd(), ".env.local") }) import { MongoClient, ObjectId } from "mongodb" import { COLLECTIONS } from "../lib/db/mongo/collections" const phone = (process.argv[2] || "15880802661").trim() function nowIso() { return new Date().toISOString() } async function main() { const uri = process.env.MONGODB_URI if (!uri) { console.error("缺少 MONGODB_URI") process.exit(1) } const client = new MongoClient(uri) await client.connect() try { const db = client.db("wanzhi_esports") const users = db.collection(COLLECTIONS.users) const streamers = db.collection(COLLECTIONS.streamers) const u = await users.findOne({ phone }) if (!u || !(u as { _id?: ObjectId })._id) { console.error(`未找到用户 phone=${phone},请先注册`) process.exit(1) } const uid = (u as { _id: ObjectId })._id.toString() const exists = await streamers.findOne({ userId: uid, status: "approved" }) if (exists) { console.log(`已有已审核主播绑定 userId=${uid},跳过`) return } await streamers.insertOne({ userId: uid, name: (u as { name?: string }).name || "主播", title: "玩值测试主播 · 工作台", game: "英雄联盟", gameId: 2, avatar: "/gamer-boy-esports-jersey.jpg", coverImage: "/lol-stream.jpg", tags: ["测试", "工作台"], level: 1, fans: 888, hotValue: 8.8, isLive: false, totalGifts: 0, totalIncome: 0, commissionRate: 0.7, status: "approved", verifiedAt: nowIso(), createdAt: nowIso(), updatedAt: nowIso(), }) console.log(`已为 ${phone} 创建已审核主播,userId=${uid}`) } finally { await client.close() } } main().catch((e) => { console.error(e) process.exit(1) })