抢购控制台支持查看精英手册兑换记录,发布0.3.7
此前只有和平小店能在控制台查兑换记录,精英/电竞手册只能去别的页面或客户端看。 现在账号作战表直接带上"兑换记录"列:查询一次就能看到每个账号兑换了什么、什么时候、 花多少积分,点"记录"看该账号全部明细。 - 新增 QueryExchangeRecords 批量查询(手册类活动):复用既有的并发 lookupExchangeRecords, 记录不做任何过滤("看我的兑换记录"不该藏东西),记录自带商品名与积分 - 商品筛选为可选项:不选=看全部记录;选了则额外标记该账号是否兑换过它(已兑换/未兑换) - 手册的商品筛选用本地状态,不写回全局商品选择——免得只是想看记录却把抢购目标改掉; 和平小店沿用原来的全局商品选择 - 账号表"兑换记录"列对所有活动可见;手册侧展示条数与最近一条(商品名 + 时间), 小店的"已兑换/未兑换 + 订单状态"保持原样 - 每行"记录"弹窗:若已批量查询过就直接复用结果不再打接口;否则手册走 VerifyExchange, 小店走原有订单查询。弹窗表格按活动切换列(手册:商品/数量/兑换时间/积分/昵称) - 聚合逻辑抽成纯函数 buildExchangeRecordsResult 并补测试 (记录不过滤、命中按商品统计、空 Cookie 与查询失败分开计数、未选商品不做命中判断)
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"douyu_go/internal/types"
|
||||
)
|
||||
|
||||
// TestBuildExchangeRecordsResult 覆盖抢购控制台"查询兑换记录"的整理逻辑:
|
||||
// 记录不过滤、命中按商品统计、空 Cookie 与查询失败分开计数。
|
||||
func TestBuildExchangeRecordsResult(t *testing.T) {
|
||||
lookups := []exchangeLookupResult{
|
||||
{
|
||||
Account: types.Account{Name: "a"},
|
||||
Records: []types.ExchangeRecord{
|
||||
{CommodityID: "goods-1", CommodityName: "冥河战士大礼包", ExchangeNum: 1, Time: "2026-10-03 19:39:01", Score: "20"},
|
||||
{CommodityID: "goods-2", CommodityName: "幸运币礼包", ExchangeNum: 2, Time: "2026-10-03 12:00:00", Score: "10"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Account: types.Account{Name: "b"},
|
||||
Records: []types.ExchangeRecord{
|
||||
{CommodityID: "goods-2", CommodityName: "幸运币礼包", ExchangeNum: 1},
|
||||
},
|
||||
},
|
||||
{Account: types.Account{Name: "c"}, EmptyCookie: true},
|
||||
{Account: types.Account{Name: "d"}, Err: errors.New("接口超时")},
|
||||
// 商品ID为空的记录也要保留("看记录"不该藏东西)
|
||||
{Account: types.Account{Name: "e"}, Records: []types.ExchangeRecord{{CommodityName: "无ID记录"}}},
|
||||
}
|
||||
|
||||
result := buildExchangeRecordsResult(lookups, "goods-1", "冥河战士大礼包")
|
||||
if !result.Success {
|
||||
t.Fatal("结果应为成功")
|
||||
}
|
||||
if result.Total != 4 {
|
||||
t.Fatalf("记录总数 = %d, want 4", result.Total)
|
||||
}
|
||||
if result.Matched != 1 {
|
||||
t.Fatalf("命中当前商品账号数 = %d, want 1", result.Matched)
|
||||
}
|
||||
if result.Failed != 2 {
|
||||
t.Fatalf("失败账号数 = %d, want 2", result.Failed)
|
||||
}
|
||||
if got := result.Results["a"]; !got.Success || !got.Matched || len(got.Records) != 2 {
|
||||
t.Fatalf("a = %#v", got)
|
||||
}
|
||||
if got := result.Results["b"]; !got.Success || got.Matched {
|
||||
t.Fatalf("b 不应命中 goods-1: %#v", got)
|
||||
}
|
||||
if got := result.Results["c"]; got.Error != "Cookie 为空" {
|
||||
t.Fatalf("c 错误 = %q", got.Error)
|
||||
}
|
||||
if got := result.Results["d"]; got.Error != "接口超时" {
|
||||
t.Fatalf("d 错误 = %q", got.Error)
|
||||
}
|
||||
if got := result.Results["e"]; len(got.Records) != 1 {
|
||||
t.Fatalf("无商品ID的记录不应被过滤: %#v", got)
|
||||
}
|
||||
|
||||
// 不选商品时不做命中判断,但仍然返回全部记录
|
||||
all := buildExchangeRecordsResult(lookups, "", "")
|
||||
if all.Matched != 0 {
|
||||
t.Fatalf("未选商品时命中数应为 0, got %d", all.Matched)
|
||||
}
|
||||
if all.Total != 4 {
|
||||
t.Fatalf("未选商品时记录总数 = %d, want 4", all.Total)
|
||||
}
|
||||
}
|
||||
@@ -146,6 +146,66 @@ func (a *App) BindXiaodianRole(accountName string) types.XiaodianRole {
|
||||
return role
|
||||
}
|
||||
|
||||
// QueryExchangeRecords 批量查询手册类活动(精英手册/电竞手册)的兑换记录。
|
||||
//
|
||||
// 与和平小店的批量查询并列,供抢购控制台直接查看"每个账号兑换过什么",
|
||||
// 省得再去别的页面或客户端查。手册记录自带商品名与积分,商品可以不选;
|
||||
// 选了商品就额外标记该账号是否兑换过它。
|
||||
func (a *App) QueryExchangeRecords(commodityID, commodityName string) types.ExchangeRecordsBatchResult {
|
||||
result := types.ExchangeRecordsBatchResult{
|
||||
ProductID: strings.TrimSpace(commodityID),
|
||||
ProductName: strings.TrimSpace(commodityName),
|
||||
Results: make(map[string]types.ExchangeAccountRecords),
|
||||
}
|
||||
if a.getClient().Activity.IsXiaodian {
|
||||
result.Error = "和平小店请使用订单查询"
|
||||
return result
|
||||
}
|
||||
|
||||
accounts := a.scheduler.AccountSnapshot()
|
||||
result.Success = true
|
||||
if len(accounts) == 0 {
|
||||
return result
|
||||
}
|
||||
|
||||
return buildExchangeRecordsResult(a.lookupExchangeRecords("兑换记录", accounts), result.ProductID, result.ProductName)
|
||||
}
|
||||
|
||||
// buildExchangeRecordsResult 把批量查询结果整理成界面用的结构(纯函数,便于测试)。
|
||||
//
|
||||
// 刻意不对记录做过滤:这是"看我的兑换记录",任何一条都不该被藏起来。
|
||||
func buildExchangeRecordsResult(lookups []exchangeLookupResult, productID, productName string) types.ExchangeRecordsBatchResult {
|
||||
result := types.ExchangeRecordsBatchResult{
|
||||
Success: true,
|
||||
ProductID: productID,
|
||||
ProductName: productName,
|
||||
Results: make(map[string]types.ExchangeAccountRecords, len(lookups)),
|
||||
}
|
||||
for _, lookup := range lookups {
|
||||
item := types.ExchangeAccountRecords{}
|
||||
switch {
|
||||
case lookup.EmptyCookie:
|
||||
item.Error = "Cookie 为空"
|
||||
case lookup.Err != nil:
|
||||
item.Error = lookup.Err.Error()
|
||||
default:
|
||||
item.Success = true
|
||||
item.Records = lookup.Records
|
||||
item.Matched = productID != "" && hasCommodityRecord(item.Records, productID, 0, 0)
|
||||
}
|
||||
if item.Error != "" {
|
||||
result.Failed++
|
||||
} else {
|
||||
result.Total += len(item.Records)
|
||||
if item.Matched {
|
||||
result.Matched++
|
||||
}
|
||||
}
|
||||
result.Results[lookup.Account.Name] = item
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// VerifyExchange 查询兑换记录,用于复验抢购结果。
|
||||
func (a *App) VerifyExchange(accountName string) types.ExchangeRecordsResult {
|
||||
if accountName == "" {
|
||||
|
||||
@@ -3,7 +3,7 @@ package constants
|
||||
import "time"
|
||||
|
||||
// Version 应用版本号,与 wails.json version 同步。
|
||||
const Version = "0.3.6"
|
||||
const Version = "0.3.7"
|
||||
|
||||
// BuildTime 构建时间,由编译时 ldflags 注入。
|
||||
var BuildTime = "unknown"
|
||||
|
||||
@@ -89,6 +89,28 @@ type XiaodianAssetsResult struct {
|
||||
Results map[string]XiaodianAssets `json:"results"`
|
||||
}
|
||||
|
||||
// ExchangeRecordsBatchResult 手册类活动(精英手册/电竞手册)的兑换记录批量查询结果。
|
||||
// 与和平小店的批量查询对应,区别是手册记录自带商品名与积分,商品可以不选;
|
||||
// 选了商品就在每个账号上标记是否兑换过它(对应界面的"已兑换/未兑换")。
|
||||
type ExchangeRecordsBatchResult struct {
|
||||
Success bool `json:"success"`
|
||||
ProductID string `json:"productId,omitempty"`
|
||||
ProductName string `json:"productName,omitempty"`
|
||||
Results map[string]ExchangeAccountRecords `json:"results"`
|
||||
Total int `json:"total"`
|
||||
Matched int `json:"matched"`
|
||||
Failed int `json:"failed"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// ExchangeAccountRecords 单个账号的兑换记录。
|
||||
type ExchangeAccountRecords struct {
|
||||
Success bool `json:"success"`
|
||||
Records []ExchangeRecord `json:"records,omitempty"`
|
||||
Matched bool `json:"matched"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// ExchangeRecordsResult 兑换记录查询结果。
|
||||
type ExchangeRecordsResult struct {
|
||||
Success bool `json:"success"`
|
||||
|
||||
Reference in New Issue
Block a user