增加和平小店关键词固定抢购

This commit is contained in:
yml2213
2026-08-08 18:40:53 +08:00
parent 51e91b0483
commit a4fed8befb
5 changed files with 214 additions and 3 deletions
+69
View File
@@ -432,6 +432,75 @@ func (s *Scheduler) RunNow(accountProducts map[string]string) {
len(successAccounts), totalAccounts, len(stoppedAccounts)-len(successAccounts), totalAttempts, utils.RoundDuration(time.Since(startTime)))
}
// RunFixed 按固定轮数和轮间隔抢购,账号成功后不再参与后续轮次。
func (s *Scheduler) RunFixed(accountProducts map[string]string, attempts, delayMs int) {
defer s.finishRun()
s.ClearResults()
settings := s.settingsSnapshot()
if attempts < 1 {
attempts = 1
}
if attempts > 100 {
attempts = 100
}
if delayMs < 0 {
delayMs = 0
}
if delayMs > 60000 {
delayMs = 60000
}
accounts := make([]types.Account, 0, len(accountProducts))
for name, commodityID := range accountProducts {
cookie, ok := s.AccountCookieByName(name)
if !ok {
continue
}
product := s.productForCommodityID(commodityID)
if product.CommodityID == "" {
product.CommodityID = commodityID
}
accounts = append(accounts, types.Account{Name: name, Cookie: cookie})
}
if len(accounts) == 0 {
logger.LogEvent("抢购", "warn", "固定次数抢购没有可执行账号")
return
}
stopped := make(map[string]bool)
start := time.Now()
logger.LogEvent("抢购", "info", "固定次数抢购开始: %d 个账号,次数=%d,间隔=%dms", len(accounts), attempts, delayMs)
for round := 1; round <= attempts; round++ {
roundAttempts := make([]types.ExchangeAttempt, 0, len(accounts))
for _, account := range accounts {
if stopped[account.Name] {
continue
}
commodityID := accountProducts[account.Name]
product := s.productForCommodityID(commodityID)
if product.CommodityID == "" {
product.CommodityID = commodityID
}
roundAttempts = append(roundAttempts, types.ExchangeAttempt{Account: account, Product: product, Index: round})
}
if len(roundAttempts) == 0 {
break
}
if round > 1 && delayMs > 0 {
time.Sleep(time.Duration(delayMs) * time.Millisecond)
}
outcome := s.executeRound(roundAttempts, settings)
for name := range outcome.successAccounts {
stopped[name] = true
}
for name := range outcome.stoppedAccounts {
stopped[name] = true
}
logger.LogEvent("抢购", "info", "固定抢购第%d/%d轮完成: 成功=%d,剩余账号=%d", round, attempts, len(outcome.successAccounts), len(accounts)-len(stopped))
}
logger.LogEvent("抢购", "info", "固定次数抢购结束: 成功=%d/%d,耗时=%v", len(stopped), len(accounts), utils.RoundDuration(time.Since(start)))
}
// filterPendingAttempts 过滤掉已终止账号和已确认无库存的商品。
func (s *Scheduler) filterPendingAttempts(allAttempts []types.ExchangeAttempt, stoppedAccounts, stoppedProducts map[string]string) []types.ExchangeAttempt {
var pending []types.ExchangeAttempt