feat: improve xiaodian seckill flow

This commit is contained in:
yml2213
2026-08-08 23:04:40 +08:00
parent 16972b41cd
commit dde2b43d82
19 changed files with 871 additions and 64 deletions
+4
View File
@@ -7,6 +7,7 @@ import (
"time"
"github.com/golang/freetype/truetype"
"github.com/wailsapp/wails/v2/pkg/runtime"
"douyu_go/internal/activity"
"douyu_go/internal/client"
@@ -140,6 +141,9 @@ func (a *App) Startup(ctx context.Context) {
a.client = client.New(act, a.cfg.TimeAPIURL, a.getTrace())
a.font = imgpkg.LoadFont(a.paths.FontFiles)
a.scheduler = seckill.New(a.client, a.paths, a.font, a.cfg.Concurrency, a.cfg.Attempts, a.cfg.RetryStages, a.cfg.SeckillMode)
a.scheduler.SetStateChangeCallback(func(state string) {
runtime.EventsEmit(a.ctx, seckillStateEvent, state)
})
a.scheduler.LoadAccounts()
if err := os.MkdirAll(a.paths.SuccessDir, 0755); err != nil {
+26 -2
View File
@@ -9,6 +9,8 @@ import (
"douyu_go/internal/utils"
)
const seckillStateEvent = "seckill:state"
// StartSeckill 立即启动抢购。
func (a *App) StartSeckill(accountProducts map[string]string) types.MessageResult {
if len(accountProducts) == 0 {
@@ -21,8 +23,30 @@ func (a *App) StartSeckill(accountProducts map[string]string) types.MessageResul
return types.MessageResult{Success: true, Msg: "抢购已启动"}
}
// StartXiaodianSeckill 启动和平小店专用次数/间隔抢购。
func (a *App) StartXiaodianSeckill(req types.FixedSeckillRequest) types.MessageResult {
return a.startXiaodianSeckill(req, "和平小店抢购已启动")
}
// StopSeckill 停止当前正在运行的抢购任务。
func (a *App) StopSeckill() types.MessageResult {
if !a.scheduler.StopRun() {
return types.MessageResult{Success: true, Msg: "当前没有正在运行的抢购任务"}
}
return types.MessageResult{Success: true, Msg: "已发送停止指令"}
}
// GetSeckillStatus 返回当前抢购运行状态。
func (a *App) GetSeckillStatus() types.SimpleResult {
return types.SimpleResult{Success: a.scheduler.IsRunning()}
}
// StartFixedSeckill 启动和平小店固定次数/间隔抢购。
func (a *App) StartFixedSeckill(req types.FixedSeckillRequest) types.MessageResult {
return a.startXiaodianSeckill(req, "固定次数抢购已启动")
}
func (a *App) startXiaodianSeckill(req types.FixedSeckillRequest, message string) types.MessageResult {
if !a.getClient().Activity.IsXiaodian {
return types.MessageResult{Error: "固定次数抢购仅支持和平小店"}
}
@@ -38,8 +62,8 @@ func (a *App) StartFixedSeckill(req types.FixedSeckillRequest) types.MessageResu
if !a.scheduler.TryStartRun() {
return types.MessageResult{Error: "抢购任务正在运行,请勿重复提交"}
}
go a.scheduler.RunFixed(utils.CloneStringMap(req.AccountProducts), req.Attempts, req.DelayMs)
return types.MessageResult{Success: true, Msg: "固定次数抢购已启动"}
go a.scheduler.RunXiaodian(utils.CloneStringMap(req.AccountProducts), req.Attempts, req.DelayMs)
return types.MessageResult{Success: true, Msg: message}
}
// SetSchedule 设置定时抢购。