888 lines
28 KiB
TypeScript
888 lines
28 KiB
TypeScript
// 数据库初始化种子数据
|
||
import { db } from "./schema"
|
||
import type { User, Game, Streamer, Star, Guild, Companion, EsportsVenue, Product, GamePointCard } from "./schema"
|
||
|
||
export async function seedDatabase() {
|
||
// 检查是否已初始化
|
||
const existingUsers = await db.users.count()
|
||
if (existingUsers > 0) {
|
||
console.log("[v0] Database already seeded")
|
||
return
|
||
}
|
||
|
||
console.log("[v0] Seeding database...")
|
||
|
||
// 1. 初始化游戏数据
|
||
const games: Omit<Game, "id">[] = [
|
||
{
|
||
name: "王者荣耀",
|
||
shortName: "wzry",
|
||
logo: "/wzry.jpg",
|
||
coverImage: "/wzry-cover.jpg",
|
||
category: "moba",
|
||
platform: ["mobile"],
|
||
publisher: "腾讯",
|
||
isHot: true,
|
||
sortOrder: 1,
|
||
status: "active",
|
||
createdAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
name: "英雄联盟",
|
||
shortName: "lol",
|
||
logo: "/lol.jpg",
|
||
coverImage: "/lol-cover.jpg",
|
||
category: "moba",
|
||
platform: ["pc"],
|
||
publisher: "腾讯",
|
||
isHot: true,
|
||
sortOrder: 2,
|
||
status: "active",
|
||
createdAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
name: "和平精英",
|
||
shortName: "pubgm",
|
||
logo: "/pubgm.jpg",
|
||
coverImage: "/pubgm-cover.jpg",
|
||
category: "fps",
|
||
platform: ["mobile"],
|
||
publisher: "腾讯",
|
||
isHot: true,
|
||
sortOrder: 3,
|
||
status: "active",
|
||
createdAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
name: "原神",
|
||
shortName: "ys",
|
||
logo: "/ys.jpg",
|
||
coverImage: "/ys-cover.jpg",
|
||
category: "mmorpg",
|
||
platform: ["pc", "mobile"],
|
||
publisher: "米哈游",
|
||
isHot: true,
|
||
sortOrder: 4,
|
||
status: "active",
|
||
createdAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
name: "无畏契约",
|
||
shortName: "valorant",
|
||
logo: "/valorant.jpg",
|
||
coverImage: "/valorant-cover.jpg",
|
||
category: "fps",
|
||
platform: ["pc"],
|
||
publisher: "拳头",
|
||
isHot: true,
|
||
sortOrder: 5,
|
||
status: "active",
|
||
createdAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
name: "穿越火线",
|
||
shortName: "cf",
|
||
logo: "/cf.jpg",
|
||
coverImage: "/cf-cover.jpg",
|
||
category: "fps",
|
||
platform: ["pc", "mobile"],
|
||
publisher: "腾讯",
|
||
isHot: false,
|
||
sortOrder: 6,
|
||
status: "active",
|
||
createdAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
name: "梦幻西游",
|
||
shortName: "mhxy",
|
||
logo: "/mhxy.jpg",
|
||
coverImage: "/mhxy-cover.jpg",
|
||
category: "mmorpg",
|
||
platform: ["pc", "mobile"],
|
||
publisher: "网易",
|
||
isHot: false,
|
||
sortOrder: 7,
|
||
status: "active",
|
||
createdAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
name: "三角洲行动",
|
||
shortName: "delta",
|
||
logo: "/delta.jpg",
|
||
coverImage: "/delta-cover.jpg",
|
||
category: "fps",
|
||
platform: ["pc", "mobile"],
|
||
publisher: "腾讯",
|
||
isHot: true,
|
||
sortOrder: 8,
|
||
status: "active",
|
||
createdAt: new Date().toISOString(),
|
||
},
|
||
]
|
||
await db.games.bulkAdd(games)
|
||
|
||
// 2. 初始化默认用户
|
||
const defaultUser: Omit<User, "id"> = {
|
||
odlId: "888888",
|
||
phone: "13800138000",
|
||
name: "卡若",
|
||
avatar: "/gamer-boy-esports-jersey.jpg",
|
||
level: 12,
|
||
experience: 2450,
|
||
isVip: false,
|
||
gender: "male",
|
||
tags: ["英雄联盟", "王者荣耀"],
|
||
activity: 128,
|
||
following: 45,
|
||
followers: 892,
|
||
visitors: 1205,
|
||
balance: 6880,
|
||
totalRecharge: 10000,
|
||
totalSpent: 3120,
|
||
registerSource: "app",
|
||
registerTime: "2023-01-15",
|
||
lastLoginTime: new Date().toISOString(),
|
||
status: "active",
|
||
createdAt: "2023-01-15",
|
||
updatedAt: new Date().toISOString(),
|
||
}
|
||
await db.users.add(defaultUser)
|
||
|
||
// 2b. 补充用户(真实感姓名与手机号,供明星/公会等关联)
|
||
const realNames = ["张伟", "李娜", "王芳", "刘洋", "陈静", "杨磊", "赵敏", "黄强", "周杰", "吴磊", "徐丽", "孙浩"]
|
||
const phonePrefixes = ["138", "159", "186", "188", "137", "135", "139", "158", "136", "187", "151", "177"]
|
||
for (let i = 0; i < 12; i++) {
|
||
await db.users.add({
|
||
odlId: `U${String(100 + i).padStart(3, "0")}`,
|
||
phone: `${phonePrefixes[i]}${String(10000000 + i * 123456).slice(-8)}`,
|
||
name: realNames[i],
|
||
avatar: "/placeholder.svg",
|
||
level: 3 + (i % 5),
|
||
experience: 100 * (i + 1),
|
||
isVip: i % 3 === 0,
|
||
gender: i % 2 === 0 ? "male" : "female",
|
||
tags: [],
|
||
activity: 20 + i * 5,
|
||
following: 10,
|
||
followers: 30,
|
||
visitors: 80,
|
||
balance: 300 + i * 100,
|
||
totalRecharge: 500,
|
||
totalSpent: 200,
|
||
registerSource: "app",
|
||
registerTime: "2024-03-01",
|
||
lastLoginTime: new Date().toISOString(),
|
||
status: "active",
|
||
createdAt: "2024-03-01",
|
||
updatedAt: new Date().toISOString(),
|
||
} as Omit<User, "id">)
|
||
}
|
||
|
||
// 3. 初始化主播数据
|
||
const streamers: Omit<Streamer, "id">[] = [
|
||
{
|
||
userId: 1,
|
||
name: "GM-远洋",
|
||
avatar: "/streamer-1.jpg",
|
||
coverImage: "/lol-stream.jpg",
|
||
title: "国服第一盲僧",
|
||
game: "英雄联盟",
|
||
gameId: 2,
|
||
tags: ["打野", "教学"],
|
||
level: 28,
|
||
fans: 1256000,
|
||
hotValue: 125.6,
|
||
isLive: true,
|
||
totalGifts: 89000,
|
||
totalIncome: 156000,
|
||
commissionRate: 0.7,
|
||
status: "approved",
|
||
verifiedAt: "2023-02-01",
|
||
createdAt: "2023-01-20",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
userId: 2,
|
||
name: "小狐狸",
|
||
avatar: "/streamer-2.jpg",
|
||
coverImage: "/valorant-stream.jpg",
|
||
title: "无畏契约电竞女神",
|
||
game: "无畏契约",
|
||
gameId: 5,
|
||
tags: ["竞技", "颜值"],
|
||
level: 25,
|
||
fans: 856000,
|
||
hotValue: 89.2,
|
||
isLive: true,
|
||
totalGifts: 67000,
|
||
totalIncome: 98000,
|
||
commissionRate: 0.7,
|
||
status: "approved",
|
||
verifiedAt: "2023-03-01",
|
||
createdAt: "2023-02-15",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
userId: 3,
|
||
name: "王者阿杰",
|
||
avatar: "/streamer-3.jpg",
|
||
coverImage: "/wzry-stream.jpg",
|
||
title: "国服最强边路",
|
||
game: "王者荣耀",
|
||
gameId: 1,
|
||
tags: ["边路", "上分"],
|
||
level: 30,
|
||
fans: 2100000,
|
||
hotValue: 168.5,
|
||
isLive: false,
|
||
totalGifts: 125000,
|
||
totalIncome: 230000,
|
||
commissionRate: 0.75,
|
||
status: "approved",
|
||
verifiedAt: "2023-01-10",
|
||
createdAt: "2022-12-01",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
userId: 4,
|
||
name: "原神小可爱",
|
||
avatar: "/streamer-4.jpg",
|
||
coverImage: "/ys-stream.jpg",
|
||
title: "深渊满星攻略",
|
||
game: "原神",
|
||
gameId: 4,
|
||
tags: ["攻略", "抽卡"],
|
||
level: 22,
|
||
fans: 568000,
|
||
hotValue: 56.8,
|
||
isLive: true,
|
||
totalGifts: 45000,
|
||
totalIncome: 78000,
|
||
commissionRate: 0.65,
|
||
status: "approved",
|
||
verifiedAt: "2023-04-01",
|
||
createdAt: "2023-03-10",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
userId: 5,
|
||
name: "吃鸡大魔王",
|
||
avatar: "/streamer-5.jpg",
|
||
coverImage: "/pubgm-stream.jpg",
|
||
title: "单排上分王",
|
||
game: "和平精英",
|
||
gameId: 3,
|
||
tags: ["吃鸡", "技巧"],
|
||
level: 26,
|
||
fans: 980000,
|
||
hotValue: 98.0,
|
||
isLive: true,
|
||
totalGifts: 72000,
|
||
totalIncome: 135000,
|
||
commissionRate: 0.7,
|
||
status: "approved",
|
||
verifiedAt: "2023-02-15",
|
||
createdAt: "2023-01-25",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
userId: 6,
|
||
name: "魔兽老玩家",
|
||
avatar: "/streamer-6.jpg",
|
||
coverImage: "/wow-stream.jpg",
|
||
title: "怀旧服金团领队",
|
||
game: "魔兽世界",
|
||
gameId: 9,
|
||
tags: ["怀旧", "金团"],
|
||
level: 20,
|
||
fans: 320000,
|
||
hotValue: 32.5,
|
||
isLive: false,
|
||
totalGifts: 28000,
|
||
totalIncome: 52000,
|
||
commissionRate: 0.65,
|
||
status: "approved",
|
||
verifiedAt: "2023-05-01",
|
||
createdAt: "2023-04-20",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
]
|
||
await db.streamers.bulkAdd(streamers)
|
||
|
||
// 4. 初始化明星数据
|
||
const stars: Omit<Star, "id">[] = [
|
||
{
|
||
userId: 10,
|
||
name: "Faker",
|
||
avatar: "/star-faker.jpg",
|
||
coverImage: "/star-faker-cover.jpg",
|
||
title: "LOL传奇中单",
|
||
game: "英雄联盟",
|
||
gameId: 2,
|
||
tags: ["世界冠军", "中单"],
|
||
fans: 46800000,
|
||
hotValue: 468.0,
|
||
achievements: ["三冠王", "S赛MVP"],
|
||
teamName: "T1",
|
||
socialLinks: { weibo: "faker_lol" },
|
||
partyRoomId: "faker-party",
|
||
hourlyRate: 9999,
|
||
isOnline: true,
|
||
status: "active",
|
||
verifiedAt: "2022-01-01",
|
||
createdAt: "2022-01-01",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
userId: 11,
|
||
name: "Uzi",
|
||
avatar: "/star-uzi.jpg",
|
||
coverImage: "/star-uzi-cover.jpg",
|
||
title: "永远的神",
|
||
game: "英雄联盟",
|
||
gameId: 2,
|
||
tags: ["ADC", "传奇"],
|
||
fans: 38500000,
|
||
hotValue: 385.0,
|
||
achievements: ["MSI冠军", "LPL冠军"],
|
||
teamName: "RNG",
|
||
socialLinks: { weibo: "uzi_lol", douyin: "uzi" },
|
||
partyRoomId: "uzi-party",
|
||
hourlyRate: 8888,
|
||
isOnline: false,
|
||
status: "active",
|
||
verifiedAt: "2022-01-01",
|
||
createdAt: "2022-01-01",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
userId: 12,
|
||
name: "梦泪",
|
||
avatar: "/star-menglei.jpg",
|
||
coverImage: "/star-menglei-cover.jpg",
|
||
title: "国服第一韩信",
|
||
game: "王者荣耀",
|
||
gameId: 1,
|
||
tags: ["韩信", "打野"],
|
||
fans: 52000000,
|
||
hotValue: 520.0,
|
||
achievements: ["KPL冠军", "最佳打野"],
|
||
teamName: "AG超玩会",
|
||
socialLinks: { douyin: "menglei" },
|
||
partyRoomId: "menglei-party",
|
||
hourlyRate: 6666,
|
||
isOnline: true,
|
||
status: "active",
|
||
verifiedAt: "2022-06-01",
|
||
createdAt: "2022-06-01",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
userId: 13,
|
||
name: "不求人",
|
||
avatar: "/star-buqiuren.jpg",
|
||
coverImage: "/star-buqiuren-cover.jpg",
|
||
title: "和平精英一哥",
|
||
game: "和平精英",
|
||
gameId: 3,
|
||
tags: ["吃鸡", "主播"],
|
||
fans: 41000000,
|
||
hotValue: 410.0,
|
||
achievements: ["PEL冠军", "全明星MVP"],
|
||
socialLinks: { douyin: "buqiuren" },
|
||
partyRoomId: "buqiuren-party",
|
||
hourlyRate: 5888,
|
||
isOnline: true,
|
||
status: "active",
|
||
verifiedAt: "2022-03-01",
|
||
createdAt: "2022-03-01",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
]
|
||
await db.stars.bulkAdd(stars)
|
||
|
||
// 5. 初始化公会数据
|
||
const guilds: Omit<Guild, "id">[] = [
|
||
{
|
||
name: "星耀电竞",
|
||
logo: "/guild-xingyao.jpg",
|
||
coverImage: "/guild-xingyao-cover.jpg",
|
||
description: "顶级电竞公会,培养众多职业选手",
|
||
ownerId: 1,
|
||
memberCount: 1280,
|
||
maxMembers: 2000,
|
||
level: 8,
|
||
totalIncome: 2580000,
|
||
commissionRate: 0.1,
|
||
tags: ["职业", "培训"],
|
||
games: ["英雄联盟", "王者荣耀"],
|
||
requirements: "段位王者以上",
|
||
benefits: ["签约底薪", "流量扶持", "赛事推荐"],
|
||
status: "active",
|
||
createdAt: "2022-01-01",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
name: "凤凰涅槃",
|
||
logo: "/guild-fenghuang.jpg",
|
||
coverImage: "/guild-fenghuang-cover.jpg",
|
||
description: "女主播孵化基地",
|
||
ownerId: 2,
|
||
memberCount: 860,
|
||
maxMembers: 1500,
|
||
level: 6,
|
||
totalIncome: 1680000,
|
||
commissionRate: 0.12,
|
||
tags: ["颜值", "才艺"],
|
||
games: ["王者荣耀", "和平精英"],
|
||
requirements: "颜值在线,有才艺",
|
||
benefits: ["形象包装", "运营指导", "商务对接"],
|
||
status: "active",
|
||
createdAt: "2022-06-01",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
name: "暗影战队",
|
||
logo: "/guild-anying.jpg",
|
||
coverImage: "/guild-anying-cover.jpg",
|
||
description: "FPS游戏专业公会",
|
||
ownerId: 3,
|
||
memberCount: 520,
|
||
maxMembers: 1000,
|
||
level: 5,
|
||
totalIncome: 980000,
|
||
commissionRate: 0.1,
|
||
tags: ["FPS", "硬核"],
|
||
games: ["和平精英", "无畏契约", "穿越火线"],
|
||
requirements: "FPS游戏高段位",
|
||
benefits: ["战队训练", "比赛机会", "装备赞助"],
|
||
status: "active",
|
||
createdAt: "2023-01-01",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
]
|
||
await db.guilds.bulkAdd(guilds)
|
||
|
||
// 6. 初始化CP/陪练数据
|
||
const companions: Omit<Companion, "id">[] = [
|
||
{
|
||
userId: 20,
|
||
name: "甜心小姐姐",
|
||
avatar: "/cp-avatar-1.jpg",
|
||
coverImage: "/cp-cover-1.jpg",
|
||
gender: "female",
|
||
age: 22,
|
||
tags: ["甜美", "温柔", "会撒娇"],
|
||
games: ["王者荣耀", "和平精英"],
|
||
bio: "声音甜美,陪你上分更开心~",
|
||
price: 30,
|
||
originalPrice: 50,
|
||
rating: 4.9,
|
||
ordersCount: 1256,
|
||
responseRate: 98,
|
||
onlineStatus: "online",
|
||
category: "cp",
|
||
commissionRate: 0.3,
|
||
status: "active",
|
||
createdAt: "2023-01-01",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
userId: 21,
|
||
name: "电竞小王子",
|
||
avatar: "/cp-avatar-2.jpg",
|
||
coverImage: "/cp-cover-2.jpg",
|
||
gender: "male",
|
||
age: 24,
|
||
tags: ["阳光", "幽默", "技术好"],
|
||
games: ["英雄联盟", "无畏契约"],
|
||
bio: "王者段位,带你轻松上分",
|
||
price: 35,
|
||
originalPrice: 60,
|
||
rating: 4.8,
|
||
ordersCount: 986,
|
||
responseRate: 95,
|
||
onlineStatus: "online",
|
||
category: "cp",
|
||
commissionRate: 0.3,
|
||
status: "active",
|
||
createdAt: "2023-02-01",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
userId: 22,
|
||
name: "职业选手小明",
|
||
avatar: "/coach-avatar-1.jpg",
|
||
coverImage: "/coach-cover-1.jpg",
|
||
gender: "male",
|
||
age: 26,
|
||
tags: ["职业", "教学", "耐心"],
|
||
games: ["英雄联盟"],
|
||
voiceSample: "/voice-sample-1.mp3",
|
||
bio: "前职业选手,专业教学",
|
||
price: 100,
|
||
originalPrice: 150,
|
||
rating: 4.95,
|
||
ordersCount: 568,
|
||
responseRate: 99,
|
||
onlineStatus: "online",
|
||
category: "coach",
|
||
coachType: "pro",
|
||
rank: "王者",
|
||
commissionRate: 0.25,
|
||
status: "active",
|
||
createdAt: "2023-01-15",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
userId: 23,
|
||
name: "王者大神",
|
||
avatar: "/coach-avatar-2.jpg",
|
||
coverImage: "/coach-cover-2.jpg",
|
||
gender: "male",
|
||
age: 23,
|
||
tags: ["上分", "技术流", "细节"],
|
||
games: ["王者荣耀"],
|
||
bio: "国服百星,带你冲击荣耀王者",
|
||
price: 80,
|
||
originalPrice: 120,
|
||
rating: 4.88,
|
||
ordersCount: 892,
|
||
responseRate: 97,
|
||
onlineStatus: "busy",
|
||
category: "coach",
|
||
coachType: "master",
|
||
rank: "荣耀王者100星",
|
||
commissionRate: 0.25,
|
||
status: "active",
|
||
createdAt: "2023-03-01",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
]
|
||
await db.companions.bulkAdd(companions)
|
||
|
||
// 7. 初始化电竞酒店/网咖数据
|
||
const venues: Omit<EsportsVenue, "id">[] = [
|
||
{
|
||
name: "玩值电竞酒店(旗舰店)",
|
||
type: "hotel",
|
||
logo: "/hotel-logo-1.jpg",
|
||
images: ["/hotel-1.jpg"],
|
||
description: "五星级电竞酒店体验",
|
||
address: "厦门市思明区软件园二期",
|
||
city: "厦门",
|
||
district: "思明区",
|
||
latitude: 24.4798,
|
||
longitude: 118.0894,
|
||
phone: "0592-12345678",
|
||
rating: 4.9,
|
||
reviewCount: 1256,
|
||
pricePerNight: 399,
|
||
facilities: ["RTX4090", "电竞椅", "144Hz显示器", "独立卫浴"],
|
||
tags: ["热门", "高端"],
|
||
openTime: "00:00",
|
||
closeTime: "24:00",
|
||
isOpen24Hours: true,
|
||
status: "active",
|
||
createdAt: "2022-01-01",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
name: "极客空间电竞公寓",
|
||
type: "hotel",
|
||
logo: "/hotel-logo-2.jpg",
|
||
images: ["/hotel-2.jpg"],
|
||
description: "年轻人的电竞乐园",
|
||
address: "厦门市湖里区五缘湾",
|
||
city: "厦门",
|
||
district: "湖里区",
|
||
latitude: 24.5102,
|
||
longitude: 118.1456,
|
||
phone: "0592-23456789",
|
||
rating: 4.7,
|
||
reviewCount: 896,
|
||
pricePerNight: 299,
|
||
facilities: ["RTX3080", "电竞椅", "双人房"],
|
||
tags: ["性价比"],
|
||
openTime: "00:00",
|
||
closeTime: "24:00",
|
||
isOpen24Hours: true,
|
||
status: "active",
|
||
createdAt: "2022-06-01",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
name: "网鱼网咖(万达店)",
|
||
type: "cafe",
|
||
logo: "/cafe-logo-1.jpg",
|
||
images: ["/cafe-1.jpg"],
|
||
description: "专业电竞网咖",
|
||
address: "厦门市思明区万达广场",
|
||
city: "厦门",
|
||
district: "思明区",
|
||
latitude: 24.4656,
|
||
longitude: 118.1023,
|
||
phone: "0592-34567890",
|
||
rating: 4.8,
|
||
reviewCount: 2356,
|
||
pricePerHour: 12,
|
||
facilities: ["3080显卡", "特权公馆", "现磨咖啡"],
|
||
tags: ["连锁", "环境好"],
|
||
openTime: "00:00",
|
||
closeTime: "24:00",
|
||
isOpen24Hours: true,
|
||
status: "active",
|
||
createdAt: "2021-01-01",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
name: "杰拉电竞馆",
|
||
type: "cafe",
|
||
logo: "/cafe-logo-2.jpg",
|
||
images: ["/cafe-2.jpg"],
|
||
description: "赛事级电竞馆",
|
||
address: "厦门市集美区银泰城",
|
||
city: "厦门",
|
||
district: "集美区",
|
||
latitude: 24.5789,
|
||
longitude: 118.0956,
|
||
phone: "0592-45678901",
|
||
rating: 4.6,
|
||
reviewCount: 1568,
|
||
pricePerHour: 10,
|
||
facilities: ["赛事级配置", "美女陪玩", "独立包间"],
|
||
tags: ["比赛场地"],
|
||
openTime: "09:00",
|
||
closeTime: "02:00",
|
||
isOpen24Hours: false,
|
||
status: "active",
|
||
createdAt: "2022-03-01",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
]
|
||
await db.esportsVenues.bulkAdd(venues)
|
||
|
||
// 8. 初始化商品数据
|
||
const products: Omit<Product, "id">[] = [
|
||
{
|
||
name: "王者荣耀皮肤礼包",
|
||
description: "稀有皮肤随机礼包",
|
||
image: "/product-skin-1.jpg",
|
||
images: ["/product-skin-1.jpg"],
|
||
category: "skin",
|
||
game: "王者荣耀",
|
||
price: 199,
|
||
originalPrice: 299,
|
||
stock: 1000,
|
||
sales: 5680,
|
||
rating: 4.8,
|
||
tags: ["热销", "限定"],
|
||
status: "active",
|
||
createdAt: "2023-01-01",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
name: "电竞机械键盘",
|
||
description: "青轴机械键盘,RGB背光",
|
||
image: "/product-keyboard.jpg",
|
||
images: ["/product-keyboard.jpg"],
|
||
category: "peripheral",
|
||
price: 299,
|
||
originalPrice: 399,
|
||
stock: 500,
|
||
sales: 2356,
|
||
rating: 4.9,
|
||
tags: ["外设", "推荐"],
|
||
status: "active",
|
||
createdAt: "2023-02-01",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
{
|
||
name: "游戏鼠标垫",
|
||
description: "超大电竞鼠标垫",
|
||
image: "/product-mousepad.jpg",
|
||
images: ["/product-mousepad.jpg"],
|
||
category: "peripheral",
|
||
price: 59,
|
||
originalPrice: 99,
|
||
stock: 2000,
|
||
sales: 8956,
|
||
rating: 4.7,
|
||
tags: ["热销"],
|
||
status: "active",
|
||
createdAt: "2023-03-01",
|
||
updatedAt: new Date().toISOString(),
|
||
},
|
||
]
|
||
await db.products.bulkAdd(products)
|
||
|
||
// 9. 初始化游戏点卡数据
|
||
const pointCards: Omit<GamePointCard, "id">[] = [
|
||
{
|
||
game: "王者荣耀",
|
||
gameId: 1,
|
||
gameLogo: "/wzry.jpg",
|
||
name: "点券充值",
|
||
description: "官方点券直充",
|
||
faceValue: 100,
|
||
price: 98,
|
||
discount: 0.98,
|
||
stock: 9999,
|
||
sales: 12568,
|
||
deliveryType: "instant",
|
||
instructions: "请提供游戏账号",
|
||
status: "active",
|
||
createdAt: "2023-01-01",
|
||
},
|
||
{
|
||
game: "英雄联盟",
|
||
gameId: 2,
|
||
gameLogo: "/lol.jpg",
|
||
name: "点券充值",
|
||
description: "官方点券直充",
|
||
faceValue: 100,
|
||
price: 97,
|
||
discount: 0.97,
|
||
stock: 9999,
|
||
sales: 9856,
|
||
deliveryType: "instant",
|
||
instructions: "请提供游戏账号",
|
||
status: "active",
|
||
createdAt: "2023-01-01",
|
||
},
|
||
{
|
||
game: "原神",
|
||
gameId: 4,
|
||
gameLogo: "/ys.jpg",
|
||
name: "创世结晶",
|
||
description: "官方充值",
|
||
faceValue: 648,
|
||
price: 628,
|
||
discount: 0.97,
|
||
stock: 9999,
|
||
sales: 15689,
|
||
deliveryType: "instant",
|
||
instructions: "请提供UID",
|
||
status: "active",
|
||
createdAt: "2023-01-01",
|
||
},
|
||
]
|
||
await db.gamePointCards.bulkAdd(pointCards)
|
||
|
||
// 10. 模拟订单、充值、典当、流水、直播间、动态、派对(管理端可见)
|
||
const now = new Date().toISOString()
|
||
const productList = await db.products.toArray()
|
||
const venueList = await db.esportsVenues.toArray()
|
||
const streamerList = await db.streamers.toArray()
|
||
const starList = await db.stars.toArray()
|
||
|
||
if (productList.length > 0) {
|
||
await db.productOrders.bulkAdd([
|
||
{
|
||
orderNo: "WZPO20240115001",
|
||
userId: 1,
|
||
items: [{ productId: productList[0].id!, productName: productList[0].name, productImage: productList[0].image, price: productList[0].price, quantity: 1 }],
|
||
totalAmount: productList[0].price,
|
||
discountAmount: 0,
|
||
finalAmount: productList[0].price,
|
||
status: "completed",
|
||
paidAt: now,
|
||
createdAt: now,
|
||
updatedAt: now,
|
||
},
|
||
{
|
||
orderNo: "WZPO20240116002",
|
||
userId: 1,
|
||
items: [{ productId: productList[1]?.id ?? productList[0].id!, productName: productList[1]?.name ?? productList[0].name, productImage: productList[1]?.image ?? productList[0].image, price: productList[1]?.price ?? 299, quantity: 1 }],
|
||
totalAmount: productList[1]?.price ?? 299,
|
||
discountAmount: 0,
|
||
finalAmount: productList[1]?.price ?? 299,
|
||
status: "paid",
|
||
paidAt: now,
|
||
createdAt: now,
|
||
updatedAt: now,
|
||
},
|
||
])
|
||
}
|
||
|
||
await db.rechargeOrders.bulkAdd([
|
||
{ orderNo: "WZRC20240101001", userId: 1, amount: 100, bonusAmount: 10, totalAmount: 110, paymentMethod: "wechat", status: "paid", paidAt: now, createdAt: now },
|
||
{ orderNo: "WZRC20240105002", userId: 1, amount: 500, bonusAmount: 50, totalAmount: 550, paymentMethod: "alipay", status: "paid", paidAt: now, createdAt: now },
|
||
{ orderNo: "WZRC20240110003", userId: 2, amount: 200, bonusAmount: 20, totalAmount: 220, paymentMethod: "wechat", status: "paid", paidAt: now, createdAt: now },
|
||
])
|
||
|
||
if (venueList.length > 0) {
|
||
await db.venueBookings.bulkAdd([
|
||
{ orderNo: "WZVB20240112001", userId: 1, venueId: venueList[0].id!, type: "hotel", checkInTime: "2024-01-15 14:00", checkOutTime: "2024-01-16 12:00", duration: 22, price: 399, totalAmount: 399, guests: 1, contactName: "卡若", contactPhone: "13800138000", status: "completed", createdAt: now, confirmedAt: now },
|
||
{ orderNo: "WZVB20240118002", userId: 2, venueId: venueList[2]?.id ?? venueList[0].id!, type: "cafe", checkInTime: "2024-01-18 10:00", checkOutTime: "2024-01-18 18:00", duration: 8, price: 12, totalAmount: 96, guests: 1, contactName: "用户小张", contactPhone: "13800138001", status: "confirmed", createdAt: now },
|
||
])
|
||
}
|
||
|
||
await db.transactions.bulkAdd([
|
||
{ userId: 1, orderNo: "WZRC20240101001", type: "recharge", category: "充值", amount: 110, balanceBefore: 0, balanceAfter: 110, description: "微信充值", status: "completed", createdAt: now },
|
||
{ userId: 1, orderNo: "WZRC20240105002", type: "recharge", category: "充值", amount: 550, balanceBefore: 110, balanceAfter: 660, description: "支付宝充值", status: "completed", createdAt: now },
|
||
{ userId: 1, orderNo: "WZPO20240115001", type: "purchase", category: "商城", amount: -199, balanceBefore: 660, balanceAfter: 461, description: "商品购买", status: "completed", createdAt: now },
|
||
])
|
||
|
||
if (streamerList.length > 0) {
|
||
await db.liveRooms.bulkAdd([
|
||
{ streamerId: streamerList[0].id!, title: "国服盲僧教学局", coverImage: "/lol-stream.jpg", game: "英雄联盟", viewers: 12500, peakViewers: 15800, likes: 3200, gifts: [], status: "live", startTime: now, createdAt: now },
|
||
{ streamerId: streamerList[1].id!, title: "无畏契约排位", coverImage: "/valorant-stream.jpg", game: "无畏契约", viewers: 8600, peakViewers: 9200, likes: 2100, gifts: [], status: "live", startTime: now, createdAt: now },
|
||
{ streamerId: streamerList[2].id!, title: "王者边路教学", coverImage: "/wzry-stream.jpg", game: "王者荣耀", viewers: 0, peakViewers: 0, likes: 0, gifts: [], status: "offline", createdAt: now },
|
||
{ streamerId: streamerList[3].id!, title: "原神深渊直播", coverImage: "/ys-stream.jpg", game: "原神", viewers: 5600, peakViewers: 6100, likes: 980, gifts: [], status: "live", startTime: now, createdAt: now },
|
||
])
|
||
}
|
||
|
||
await db.moments.bulkAdd([
|
||
{ userId: 1, userName: "卡若", userAvatar: "/gamer-boy-esports-jersey.jpg", content: "今天上王者了,开心!", images: [], tags: ["王者荣耀"], game: "王者荣耀", likes: 128, comments: 32, shares: 8, isLiked: false, visibility: "public", status: "active", createdAt: now, updatedAt: now },
|
||
{ userId: 1, userName: "卡若", userAvatar: "/gamer-boy-esports-jersey.jpg", content: "新赛季冲分中,欢迎组队。", images: [], tags: ["英雄联盟"], game: "英雄联盟", likes: 56, comments: 12, shares: 3, isLiked: false, visibility: "public", status: "active", createdAt: now, updatedAt: now },
|
||
{ userId: 2, userName: "用户小张", userAvatar: "/placeholder.svg", content: "打卡今日首胜~", images: [], tags: [], game: "王者荣耀", likes: 24, comments: 5, shares: 0, isLiked: false, visibility: "public", status: "active", createdAt: now, updatedAt: now },
|
||
])
|
||
|
||
if (starList.length > 0) {
|
||
await db.starPartyRooms.bulkAdd([
|
||
{ starId: starList[0].id!, name: "Faker 粉丝派对", memberCount: 28, maxMembers: 50, entryFee: 99, description: "与Faker同屏互动", rules: ["文明发言"], isActive: true, createdAt: now },
|
||
{ starId: starList[1].id!, name: "Uzi 水友房", memberCount: 15, maxMembers: 30, entryFee: 66, description: "Uzi 水友赛", rules: [], isActive: true, createdAt: now },
|
||
{ starId: starList[2].id!, name: "梦泪开黑房", memberCount: 42, maxMembers: 100, entryFee: 88, description: "梦泪带队开黑", rules: ["听从指挥"], isActive: true, createdAt: now },
|
||
{ starId: starList[3].id!, name: "不求人吃鸡房", memberCount: 0, maxMembers: 20, entryFee: 50, description: "待开放", rules: [], isActive: false, createdAt: now },
|
||
])
|
||
}
|
||
|
||
// 11. 游戏账号与典当(需先有 gameAccounts)
|
||
const gameAccounts = await db.gameAccounts.toArray()
|
||
if (gameAccounts.length === 0) {
|
||
const firstAccountId = await db.gameAccounts.add({
|
||
sellerId: 1,
|
||
game: "英雄联盟",
|
||
gameId: 2,
|
||
server: "艾欧尼亚",
|
||
title: "王者账号",
|
||
description: "全皮肤",
|
||
images: [],
|
||
level: 200,
|
||
skins: ["至臻"],
|
||
heroes: [],
|
||
assets: {},
|
||
price: 5000,
|
||
status: "listed",
|
||
viewCount: 0,
|
||
favoriteCount: 0,
|
||
createdAt: now,
|
||
updatedAt: now,
|
||
})
|
||
await db.accountPawns.bulkAdd([
|
||
{ userId: 1, accountId: firstAccountId as number, game: "英雄联盟", evaluatedValue: 5000, pawnAmount: 3000, serviceFee: 150, redeemAmount: 3180, period: 30, phone: "13800138000", screenshots: [], antiAddiction: "none", canRename: "no", selectedSkins: [], agreementSigned: true, status: "approved", approvedAt: now, createdAt: now, updatedAt: now },
|
||
{ userId: 2, accountId: firstAccountId as number, game: "英雄联盟", evaluatedValue: 4500, pawnAmount: 2500, serviceFee: 125, redeemAmount: 2650, period: 15, phone: "13800138001", screenshots: [], antiAddiction: "none", canRename: "no", selectedSkins: [], agreementSigned: true, status: "pending", createdAt: now, updatedAt: now },
|
||
])
|
||
}
|
||
|
||
console.log("[v0] Database seeded successfully!")
|
||
}
|
||
|
||
// 清空数据库
|
||
export async function clearDatabase() {
|
||
await db.delete()
|
||
await db.open()
|
||
console.log("[v0] Database cleared")
|
||
}
|