新增和平小店兑换记录查询

This commit is contained in:
yml2213
2026-08-08 19:44:39 +08:00
parent 57344c7874
commit c84940a5dc
7 changed files with 668 additions and 1 deletions
+93
View File
@@ -12,6 +12,7 @@ import (
)
const exchangeLookupConcurrency = 8
const xiaodianExchangeLookupConcurrency = 4
type exchangeLookupResult struct {
Account types.Account
@@ -108,6 +109,98 @@ func (a *App) VerifyAllExchange() types.VerifyAllExchangeResult {
return types.VerifyAllExchangeResult{Results: results}
}
// QueryXiaodianExchangeRecords 查询所有账号的和平小店真实订单,并标记当前商品是否已兑换。
func (a *App) QueryXiaodianExchangeRecords(commodityID, commodityName string) types.XiaodianExchangeRecordsResult {
result := types.XiaodianExchangeRecordsResult{
ProductID: strings.TrimSpace(commodityID),
ProductName: strings.TrimSpace(commodityName),
Results: make(map[string]types.XiaodianExchangeAccountResult),
}
if !a.getClient().Activity.IsXiaodian {
result.Error = "当前活动不是和平小店"
return result
}
if result.ProductID == "" {
result.Error = "请先选择商品"
return result
}
accounts := a.scheduler.AccountSnapshot()
if len(accounts) == 0 {
result.Success = true
return result
}
start := time.Now()
logger.LogEvent("兑换记录", "info", "和平小店兑换记录批量查询开始: 账号=%d 并发=%d", len(accounts), xiaodianExchangeLookupConcurrency)
type lookup struct {
account types.Account
records []types.XiaodianExchangeRecord
err error
}
lookups := make([]lookup, len(accounts))
jobs := make(chan int)
workerCount := xiaodianExchangeLookupConcurrency
if len(accounts) < workerCount {
workerCount = len(accounts)
}
var wg sync.WaitGroup
for worker := 0; worker < workerCount; worker++ {
wg.Add(1)
go func() {
defer wg.Done()
for index := range jobs {
account := accounts[index]
item := lookup{account: account}
if strings.TrimSpace(account.Cookie) == "" {
item.err = fmt.Errorf("Cookie 为空")
} else {
item.records, item.err = a.getClient().XiaodianExchangeList(account.Cookie)
}
lookups[index] = item
}
}()
}
for index := range accounts {
jobs <- index
}
close(jobs)
wg.Wait()
failed := 0
matched := 0
for _, lookup := range lookups {
if lookup.err != nil {
failed++
result.Results[lookup.account.Name] = types.XiaodianExchangeAccountResult{Error: lookup.err.Error()}
continue
}
isMatched := false
for _, record := range lookup.records {
if record.CommodityID == result.ProductID {
isMatched = true
break
}
}
if isMatched {
matched++
}
result.Results[lookup.account.Name] = types.XiaodianExchangeAccountResult{
Success: true,
Records: lookup.records,
Matched: isMatched,
}
}
result.Success = true
level := "success"
if failed > 0 {
level = "warn"
}
logger.LogEvent("兑换记录", level, "和平小店兑换记录批量查询完成: 账号=%d 命中=%d 失败=%d 耗时=%s",
len(accounts), matched, failed, time.Since(start).Round(time.Millisecond))
return result
}
// VerifyAndExport 复验并导出结果。
func (a *App) VerifyAndExport(commodityID string) types.VerifyAndExportResult {
accounts := a.scheduler.AccountSnapshot()