增加异步日志和库存展示

This commit is contained in:
yml2213
2026-07-07 08:04:54 +08:00
parent 327b996079
commit 72d59670d4
7 changed files with 313 additions and 20 deletions
+44 -4
View File
@@ -261,18 +261,26 @@ func (p PrizeInfo) Price() int64 {
}
func (p PrizeInfo) EstimatedLeft() int64 {
left, ok := p.InventoryLeft()
if ok {
return left
}
return 0
}
func (p PrizeInfo) InventoryLeft() (int64, bool) {
if p.LeftNum > 0 {
return p.LeftNum
return p.LeftNum, true
}
text := strings.TrimSuffix(strings.TrimSpace(p.Percent), "%")
if text == "" || p.Num <= 0 {
return 0
return 0, false
}
percent, err := strconv.ParseFloat(text, 64)
if err != nil {
return 0
return 0, false
}
return int64(math.Floor(float64(p.Num)*percent/100.0 + 1e-9))
return int64(math.Floor(float64(p.Num)*percent/100.0 + 1e-9)), true
}
type PrizeTag struct {
@@ -579,3 +587,35 @@ func (r *ScoreExchangePrizeResp) ReadFrom(rd *taf.Reader) error {
func (r ScoreExchangePrizeResp) Success() bool {
return r.Status == 200 && (r.Msg == "" || strings.Contains(r.Msg, "成功"))
}
func prizeListInventorySummary(prizes []PrizeInfo) (left, total int64, leftKnown, totalKnown int) {
for _, prize := range prizes {
if prize.Num > 0 {
total += prize.Num
totalKnown++
}
if itemLeft, ok := prize.InventoryLeft(); ok {
left += itemLeft
leftKnown++
}
}
return left, total, leftKnown, totalKnown
}
func exchangeResponseMessage(resp *ScoreExchangePrizeResp) string {
if resp == nil {
return ""
}
for _, text := range []string{
resp.Msg,
resp.ActPreCondition.Tip,
resp.ActPreCondition.ButtonDesc,
resp.ExchangeInfo.Desc,
resp.OrderID,
} {
if strings.TrimSpace(text) != "" {
return strings.TrimSpace(text)
}
}
return ""
}