优化和平小店兑换记录查询

This commit is contained in:
yml2213
2026-08-09 12:54:37 +08:00
parent 8919d020c5
commit 1cd94c0179
7 changed files with 396 additions and 842 deletions
+20
View File
@@ -279,6 +279,26 @@ func (a *App) QueryXiaodianExchangeRecords(commodityID, commodityName string) ty
return result
}
// QueryXiaodianAccountExchangeRecords 查询一个账号的和平小店真实订单,供账号表按需展开使用。
func (a *App) QueryXiaodianAccountExchangeRecords(accountName string) types.XiaodianExchangeAccountResult {
accountName = strings.TrimSpace(accountName)
if !a.getClient().Activity.IsXiaodian {
return types.XiaodianExchangeAccountResult{Error: "当前活动不是和平小店"}
}
if accountName == "" {
return types.XiaodianExchangeAccountResult{Error: "缺少账号名"}
}
cookie, ok := a.scheduler.AccountCookieByName(accountName)
if !ok || strings.TrimSpace(cookie) == "" {
return types.XiaodianExchangeAccountResult{Error: "账号不存在或 Cookie 为空"}
}
records, err := a.getClient().XiaodianExchangeList(cookie)
if err != nil {
return types.XiaodianExchangeAccountResult{Error: "查询失败: " + err.Error()}
}
return types.XiaodianExchangeAccountResult{Success: true, Records: records}
}
// VerifyAndExport 复验并导出结果。
func (a *App) VerifyAndExport(commodityID string) types.VerifyAndExportResult {
accounts := a.scheduler.AccountSnapshot()
+12 -5
View File
@@ -307,10 +307,13 @@ type xiaodianOrderList struct {
}
type xiaodianOrder struct {
BuyTime string `json:"dtBuyTime"`
PayTime string `json:"dtPayTime"`
Status string `json:"iStatus"`
GoodsRaw string `json:"sGoodsInfo"`
BuyTime string `json:"dtBuyTime"`
PayTime string `json:"dtPayTime"`
Status string `json:"iStatus"`
Price xiaodianFlexibleString `json:"iPrice"`
PayAmount xiaodianFlexibleString `json:"iPayAmount"`
RoleName string `json:"sRoleName"`
GoodsRaw string `json:"sGoodsInfo"`
}
type xiaodianOrderGoods struct {
@@ -896,10 +899,14 @@ func (c *DouyuClient) XiaodianExchangeList(cookie string) ([]types.XiaodianExcha
}
}
for _, item := range goods.List {
price := parseXiaodianInt(string(order.PayAmount))
if strings.TrimSpace(string(order.PayAmount)) == "" {
price = parseXiaodianInt(string(order.Price))
}
all = append(all, types.XiaodianExchangeRecord{
CommodityID: item.GoodsID, CommodityName: item.GoodsName,
Quantity: parseXiaodianInt(string(item.Quantity)), BuyTime: order.BuyTime,
PayTime: order.PayTime, Status: order.Status,
PayTime: order.PayTime, Price: price, RoleName: order.RoleName, Status: order.Status,
})
}
}
+4 -1
View File
@@ -331,7 +331,7 @@ func TestXiaodianExchangeListUsesOrderListAndParsesGoods(t *testing.T) {
if got := r.URL.Query().Get("_sid"); got != "8" {
t.Errorf("_sid = %q", got)
}
_, _ = w.Write([]byte(`var info={"data":{"cnt":1,"list":[{"dtBuyTime":"2026-08-08 01:00:42","dtPayTime":"2026-08-08 01:00:55","iStatus":"3","sGoodsInfo":"{\"list\":[{\"iGoodsId\":\"1565395\",\"sGoodsName\":\"改名卡\",\"iQuantity\":\"2\"}]}"}]}};`))
_, _ = w.Write([]byte(`var info={"data":{"cnt":1,"list":[{"dtBuyTime":"2026-08-08 01:00:42","dtPayTime":"2026-08-08 01:00:55","iStatus":"3","iPrice":"200","iPayAmount":"180","sRoleName":"测试角色","sGoodsInfo":"{\"list\":[{\"iGoodsId\":\"1565395\",\"sGoodsName\":\"改名卡\",\"iQuantity\":\"2\"}]}"}]}};`))
default:
http.NotFound(w, r)
}
@@ -356,6 +356,9 @@ func TestXiaodianExchangeListUsesOrderListAndParsesGoods(t *testing.T) {
if got.CommodityID != "1565395" || got.CommodityName != "改名卡" || got.Quantity != 2 || got.Status != "3" {
t.Fatalf("记录解析异常: %#v", got)
}
if got.Price != 180 || got.RoleName != "测试角色" {
t.Fatalf("订单扩展字段异常: %#v", got)
}
}
func testCTNClient(t *testing.T, ctnURL string) *DouyuClient {
+2
View File
@@ -266,5 +266,7 @@ type XiaodianExchangeRecord struct {
Quantity int `json:"quantity"`
BuyTime string `json:"buyTime"`
PayTime string `json:"payTime"`
Price int `json:"price"`
RoleName string `json:"roleName"`
Status string `json:"status"`
}