905086
2026-11-07 7c8e509c95c2af0c0d076b13fbbc5aa63a06cb69
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package config
 
import (
    "fmt"
    "log"
    "time"
 
    "gamebox-server/models"
 
    "golang.org/x/crypto/bcrypt"
    "gorm.io/driver/mysql"
    "gorm.io/gorm"
    "gorm.io/gorm/logger"
)
 
var DB *gorm.DB
 
func InitDB() {
    dsn := "root:123qwe@tcp(127.0.0.1:3306)/gamebox?charset=utf8mb4&parseTime=True&loc=Local"
    db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
        Logger: logger.Default.LogMode(logger.Warn),
    })
    if err != nil {
        log.Fatalf("连接数据库失败: %v", err)
    }
    DB = db
 
    err = DB.AutoMigrate(
        &models.Admin{}, &models.User{}, &models.Category{}, &models.Game{},
        &models.Tool{}, &models.MemberKey{}, &models.Favorite{},
        &models.LibraryItem{}, &models.Announcement{},
    )
    if err != nil {
        log.Fatalf("数据库迁移失败: %v", err)
    }
    fmt.Println("数据库连接成功")
    seed()
}
 
func hashPassword(pwd string) string {
    b, _ := bcrypt.GenerateFromPassword([]byte(pwd), bcrypt.DefaultCost)
    return string(b)
}
 
func seed() {
    // 管理员账号
    var adminCount int64
    DB.Model(&models.Admin{}).Count(&adminCount)
    if adminCount == 0 {
        DB.Create(&models.Admin{Username: "admin", Password: hashPassword("123456")})
        fmt.Println("已创建管理员账号: admin / 123456")
    }
 
    // 类别
    var catCount int64
    DB.Model(&models.Category{}).Count(&catCount)
    if catCount == 0 {
        cats := []models.Category{
            {Name: "角色扮演", Sort: 1}, {Name: "动作冒险", Sort: 2},
            {Name: "射击游戏", Sort: 3}, {Name: "格斗游戏", Sort: 4},
            {Name: "竞速体育", Sort: 5}, {Name: "模拟经营", Sort: 6},
            {Name: "即时战略", Sort: 7}, {Name: "经典怀旧", Sort: 8},
            {Name: "常用工具", Sort: 9},
        }
        DB.Create(&cats)
    }
 
    // 公告
    var annCount int64
    DB.Model(&models.Announcement{}).Count(&annCount)
    if annCount == 0 {
        DB.Create(&models.Announcement{Content: "平台客服上班时间:早8点到晚10点!\n下载速度慢的,把下载窗口拍照发给客服看下。\n下载好的游戏,下载完直接创建快捷方式!\n打开盒子资源库,右键安装好的游戏图片,创建快捷方式!\n平台客服在线时间:早8点--晚10点。其余时间请留言\n国产游戏不会有,不用问!都是单机游戏,无法联机!"})
    }
 
    // 工具
    var toolCount int64
    DB.Model(&models.Tool{}).Count(&toolCount)
    if toolCount == 0 {
        tools := []models.Tool{
            {Name: "DX修复", Size: "435.7 MB", Description: "DirectX修复工具增强版", Cover: "/static/covers/tool_dx.png", FileURL: ""},
            {Name: "Windows 10 21H2", Size: "13.3 GB", Description: "Windows 10 21H2 系统镜像", Cover: "/static/covers/tool_win10.png", FileURL: ""},
            {Name: "微软常用运行库合集", Size: "158.6 MB", Description: "Microsoft Common Runtime Libraries", Cover: "/static/covers/tool_runtime.png", FileURL: ""},
            {Name: "一修大师修改器", Size: "85.3 MB", Description: "一修大师修改器", Cover: "/static/covers/tool_master.png", FileURL: ""},
            {Name: "NTE游戏运行库等工具", Size: "3.3 GB", Description: "NTE游戏运行库合集", Cover: "/static/covers/tool_nte.png", FileURL: ""},
            {Name: "免费体验", Size: "387.2 MB", Description: " Plants vs. Zombies 免费体验版", Cover: "/static/covers/tool_pvz.png", FileURL: ""},
        }
        DB.Create(&tools)
    }
 
    // 示例游戏
    var gameCount int64
    DB.Model(&models.Game{}).Count(&gameCount)
    if gameCount == 0 {
        var catMap = map[string]uint{}
        var cats []models.Category
        DB.Find(&cats)
        for _, c := range cats {
            catMap[c.Name] = c.ID
        }
        games := []models.Game{
            {
                Title: "真·三国无双 起源", CategoryID: catMap["动作冒险"], Platform: "pc", Tags: "动作冒险",
                Size: "82 GB", InstallSize: "131.3 GB", OSReq: "Windows 10 64bit", CPUReq: "Intel i5-4460 / AMD Ryzen 5 1600",
                GPUReq: "GTX 1060 6GB / RX 580 8GB", RAMReq: "16 GB RAM",
                VersionNote: "Build 24|豪华中文版|官方简体中文|支持键盘.鼠标.手柄",
                Cover: "/static/covers/game1.png", Screenshots: "[]", Files: "[]", IsBanner: true,
                Description: "真·三国无双 起源(Dynasty Warriors: Origins)豪华中文版,包含全部DLC。\n支持键盘、鼠标、手柄操作。",
            },
            {
                Title: "极限竞速:地平线5 v1.685.421顶级版", CategoryID: catMap["竞速体育"], Platform: "pc", Tags: "竞速体育",
                Size: "232.6 GB", InstallSize: "411.6 GB", OSReq: "Windows 10 64bit (18362.0及以上)", CPUReq: "Intel i5-4460 or AMD Ryzen 3 1200",
                GPUReq: "NVIDIA GeForce GTX 1050 4GB / AMD Radeon RX 480 4GB", RAMReq: "16 GB RAM",
                VersionNote: "V1.685.421顶级版|容量175GB|官方简体中文|支持键盘.鼠标.手柄|赠全车辆收藏.原厂调教涂装.剧情故事全三星.DLC全通存档",
                Cover: "/static/covers/game2.png", Screenshots: "[]", Files: "[]", IsBanner: true,
                Description: "V1.685.421顶级版|容量175GB|官方简体中文|支持键盘.鼠标.手柄|赠全车辆收藏.原厂调教涂装.剧情故事全三星.DLC全通存档\n\n【存档使用方法→直往下拉即可】\n1.首先在游戏根目录里把steam_emu.ini里的#AccountId的#去掉,\n2.改成 AccountId=2535446289078643\n3.游戏名字可以改:UserName=xxxxxxxx/随意",
            },
            {
                Title: "使命召唤23:现代战争4/Call of Duty: Modern Warfare IV", CategoryID: catMap["射击游戏"], Platform: "pc", Tags: "射击游戏",
                Size: "173.8 GB", InstallSize: "340.8 GB", OSReq: "Windows 10 64bit", CPUReq: "Intel i5-4460 / AMD Ryzen 3 1200",
                GPUReq: "GTX 1060 6GB / RX 580 8GB", RAMReq: "16 GB RAM",
                VersionNote: "V1.0|容量160GB|官方简体中文|支持键盘.鼠标",
                Cover: "/static/covers/game3.png", Screenshots: "[]", Files: "[]", IsBanner: true,
                Description: "使命召唤23:现代战争4 精简版系统玩不了!打开系统安全中心,关闭实时防护后再运行游戏。",
            },
            {
                Title: "我独自升级 起立·觉醒豪华中文版v1.1.100", CategoryID: catMap["角色扮演"], Platform: "pc", Tags: "角色扮演",
                Size: "53.9 GB", InstallSize: "95.3 GB", OSReq: "Windows 10 / 11", CPUReq: "i5 4460 3.2 GHz Or AMD equivalent",
                GPUReq: "GTX1060 / Radeon RX 580", RAMReq: "16 GB RAM",
                VersionNote: "V1.1.100|容量44.9GB|官方简体中文|支持键盘.鼠标.手柄",
                Cover: "/static/covers/game4.png", Screenshots: "[]", Files: "[]", IsBanner: true,
                Description: "V1.1.100|容量44.9GB|官方简体中文|支持键盘.鼠标.手柄\n含齐州岛攻略队特别篇章+全DLC。",
            },
            {
                Title: "红警2/红色警戒2高清版(游戏菜单界面中文)", CategoryID: catMap["经典怀旧"], Platform: "pc", Tags: "即时战略,经典怀旧",
                Size: "3.3 GB", InstallSize: "5 GB", OSReq: "Windows 7/10/11", CPUReq: "Intel Core 2 Duo",
                GPUReq: "集成显卡", RAMReq: "4 GB RAM",
                VersionNote: "高清版|容量3.3GB|中文|右键打开游戏安装目录,然后按照游戏详情页教程运行",
                Cover: "/static/covers/game5.png", Screenshots: "[]", Files: "[]",
                Description: "右键打开游戏安装目录,然后按照游戏详情页的教程运行游戏即可。",
            },
            {
                Title: "女神异闻录5皇家版", CategoryID: catMap["角色扮演"], Platform: "switch", Tags: "角色扮演",
                Size: "31.6 GB", InstallSize: "40 GB", OSReq: "Windows 10 64bit(需模拟器)", CPUReq: "Intel i5-8400 / AMD Ryzen 5 3600",
                GPUReq: "GTX 1650 4GB", RAMReq: "16 GB RAM",
                VersionNote: "皇家版|容量31.6GB|官方简体中文|需Yuzu/Ryujinx模拟器",
                Cover: "/static/covers/game6.png", Screenshots: "[]", Files: "[]",
                Description: "设置中文:先打开模拟器,右击游戏图片,选择属性,语言设置为简体中文。",
            },
            {
                Title: "塞尔达传说:旷野之息", CategoryID: catMap["动作冒险"], Platform: "switch", Tags: "动作冒险",
                Size: "38.9 GB", InstallSize: "45 GB", OSReq: "Windows 10 64bit(需模拟器)", CPUReq: "Intel i5-8400 / AMD Ryzen 5 3600",
                GPUReq: "GTX 1650 4GB", RAMReq: "16 GB RAM",
                VersionNote: "Switch版|容量38.9GB|中文|需Yuzu/Ryujinx模拟器",
                Cover: "/static/covers/game7.png", Screenshots: "[]", Files: "[]",
                Description: "点击启动运行游戏即可,建议使用YuzuEA最新版模拟器。",
            },
            {
                Title: "精灵宝可梦Let's Go!皮卡丘", CategoryID: catMap["角色扮演"], Platform: "switch", Tags: "角色扮演",
                Size: "4.1 GB", InstallSize: "6 GB", OSReq: "Windows 10 64bit(需模拟器)", CPUReq: "Intel i5-8400",
                GPUReq: "GTX 1650 4GB", RAMReq: "16 GB RAM",
                VersionNote: "Switch版|容量4.1GB|中文|需模拟器",
                Cover: "/static/covers/game8.png", Screenshots: "[]", Files: "[]",
                Description: "点击启动运行游戏即可。",
            },
            {
                Title: "鬼武者:剑之道 Build.24769601+预购特典", CategoryID: catMap["动作冒险"], Platform: "pc", Tags: "动作冒险",
                Size: "131.3 GB", InstallSize: "180 GB", OSReq: "Windows 10 64bit", CPUReq: "Intel i5-4460",
                GPUReq: "GTX 1060 6GB", RAMReq: "16 GB RAM",
                VersionNote: "Build.24769601|豪华中文版|支持键盘.鼠标.手柄",
                Cover: "/static/covers/game9.png", Screenshots: "[]", Files: "[]",
                Description: "鬼武者:剑之道 豪华中文版,包含预购特典。",
            },
            {
                Title: "使命召唤20:现代战争3/Call of Duty: MW III", CategoryID: catMap["射击游戏"], Platform: "pc", Tags: "射击游戏",
                Size: "340.8 GB", InstallSize: "500 GB", OSReq: "Windows 10 64bit", CPUReq: "Intel i5-4460",
                GPUReq: "GTX 1060 6GB", RAMReq: "16 GB RAM",
                VersionNote: "V1.0|容量300GB|官方简体中文",
                Cover: "/static/covers/game10.png", Screenshots: "[]", Files: "[]",
                Description: "使命召唤20:现代战争3 完整版。",
            },
        }
        DB.Create(&games)
    }
 
    // 更新时间戳,让"最新更新"排序有区分度
    DB.Exec("UPDATE games SET updated_at = ? WHERE updated_at = ?", time.Now(), time.Time{})
}