增加异步日志和库存展示
This commit is contained in:
@@ -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 ""
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ func (c *HTTPClient) CallRPC(ctx context.Context, service, method string, reqStr
|
||||
httpReq = httpReq.WithContext(ctx)
|
||||
}
|
||||
|
||||
c.logf("[HTTP] POST %s.%s body=%dB", service, method, len(body))
|
||||
c.logf("[HTTP] 请求 %s.%s", service, method)
|
||||
httpResp, err := client.Do(httpReq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -141,6 +141,9 @@ func (c *HTTPClient) QueryUserScore(ctx context.Context, uid int64, cookie strin
|
||||
req := &GetUserScoreReq{User: c.buildUser(uid, cookie, ActivityWebUA), SID: sid}
|
||||
var resp GetUserScoreResp
|
||||
_, err := c.CallRPC(ctx, ServantWebActUI, FuncGetUserScore, req, &resp, CallOptions{UID: uid, Cookie: cookie, RequestID: 2})
|
||||
if err == nil {
|
||||
c.logf("[HTTP] 积分已解码 uid=%d sid=%d status=%d 可用=%d msg=%s", uid, sid, resp.Status, resp.AvailableScore(), resp.Msg)
|
||||
}
|
||||
return &resp, err
|
||||
}
|
||||
|
||||
@@ -148,6 +151,10 @@ func (c *HTTPClient) GetActPrizeList(ctx context.Context, uid int64, cookie stri
|
||||
req := &GetActPrizeListReq{User: c.buildUser(uid, cookie, ActivityWebUA), SID: sid}
|
||||
var resp GetActPrizeListResp
|
||||
_, err := c.CallRPC(ctx, ServantWebActUI, FuncPrizeList, req, &resp, CallOptions{UID: uid, Cookie: cookie, RequestID: 1})
|
||||
if err == nil {
|
||||
left, total, leftKnown, totalKnown := prizeListInventorySummary(resp.Prizes)
|
||||
c.logf("[HTTP] 商品列表已解码 uid=%d sid=%d status=%d count=%d 剩余=%d/%d项 总量=%d/%d项 msg=%s", uid, sid, resp.Status, len(resp.Prizes), left, leftKnown, total, totalKnown, resp.Msg)
|
||||
}
|
||||
return &resp, err
|
||||
}
|
||||
|
||||
@@ -157,6 +164,9 @@ func (c *HTTPClient) GetUserPrizeRecords(ctx context.Context, uid int64, cookie
|
||||
req := &GetUserPrizeRecordsReq{User: user, SID: sid}
|
||||
var resp GetUserPrizeRecordsResp
|
||||
_, err := c.CallRPC(ctx, ServantWebActUI, FuncPrizeRecords, req, &resp, CallOptions{UID: uid, Cookie: cookie, RequestID: 6})
|
||||
if err == nil {
|
||||
c.logf("[HTTP] 兑换记录已解码 uid=%d sid=%d status=%d count=%d msg=%s", uid, sid, resp.Status, len(resp.Records), resp.Msg)
|
||||
}
|
||||
return &resp, err
|
||||
}
|
||||
|
||||
@@ -170,5 +180,8 @@ func (c *HTTPClient) ScoreExchangePrize(ctx context.Context, uid int64, cookie s
|
||||
}
|
||||
var resp ScoreExchangePrizeResp
|
||||
_, err := c.CallRPC(ctx, ServantWebActUI, FuncExchangePrize, req, &resp, CallOptions{UID: uid, Cookie: cookie, RequestID: 1})
|
||||
if err == nil {
|
||||
c.logf("[HTTP] 兑换结果已解码 uid=%d sid=%d pid=%d status=%d order=%s msg=%s", uid, sid, pid, resp.Status, resp.OrderID, exchangeResponseMessage(&resp))
|
||||
}
|
||||
return &resp, err
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ func (s *WSSSession) readLoop() {
|
||||
case WSSCmdHeartBeatAck, WSSCmdHeartBeatRsp:
|
||||
// 心跳响应无需处理。
|
||||
case WSSCmdRegisterGroupRsp, WSSCmdVerifyCookieRsp, WSSCmdUpdateUserInfoRsp, WSSCmdUpdateUserExpsRsp:
|
||||
s.client.logf("[WSS] 收到控制响应 cmd=%d data=%dB", cmd.CmdType, len(cmd.Data))
|
||||
// 控制类响应频率高且没有业务字段,避免刷屏。
|
||||
default:
|
||||
s.client.logf("[WSS] 收到 cmd=%d data=%dB requestID=%d", cmd.CmdType, len(cmd.Data), cmd.RequestID)
|
||||
}
|
||||
@@ -456,7 +456,7 @@ func (s *WSSSession) callWUPWithRequestIDAndTrace(ctx context.Context, service,
|
||||
s.pendingMu.Lock()
|
||||
s.pending[requestID] = ch
|
||||
s.pendingMu.Unlock()
|
||||
s.client.logf("[WSS] WUP %s.%s requestID=%d body=%dB", service, method, requestID, len(data))
|
||||
s.client.logf("[WSS] 请求 %s.%s requestID=%d", service, method, requestID)
|
||||
if err := s.writePayload(ctx, payload); err != nil {
|
||||
s.removePending(requestID)
|
||||
return nil, err
|
||||
@@ -509,6 +509,9 @@ func (c *WSSClient) QueryUserScore(ctx context.Context, uid int64, cookie string
|
||||
req := &GetUserScoreReq{User: c.buildUser(uid, cookie), SID: sid}
|
||||
var resp GetUserScoreResp
|
||||
_, err = session.callRPC(ctx, ServantWebActUI, FuncGetUserScore, req, &resp)
|
||||
if err == nil {
|
||||
c.logf("[WSS] 积分已解码 uid=%d sid=%d status=%d 可用=%d msg=%s", uid, sid, resp.Status, resp.AvailableScore(), resp.Msg)
|
||||
}
|
||||
return &resp, err
|
||||
}
|
||||
|
||||
@@ -520,6 +523,10 @@ func (c *WSSClient) GetActPrizeList(ctx context.Context, uid int64, cookie strin
|
||||
req := &GetActPrizeListReq{User: c.buildUser(uid, cookie), SID: sid}
|
||||
var resp GetActPrizeListResp
|
||||
_, err = session.callRPC(ctx, ServantWebActUI, FuncPrizeList, req, &resp)
|
||||
if err == nil {
|
||||
left, total, leftKnown, totalKnown := prizeListInventorySummary(resp.Prizes)
|
||||
c.logf("[WSS] 商品列表已解码 uid=%d sid=%d status=%d count=%d 剩余=%d/%d项 总量=%d/%d项 msg=%s", uid, sid, resp.Status, len(resp.Prizes), left, leftKnown, total, totalKnown, resp.Msg)
|
||||
}
|
||||
return &resp, err
|
||||
}
|
||||
|
||||
@@ -531,6 +538,9 @@ func (c *WSSClient) GetUserPrizeRecords(ctx context.Context, uid int64, cookie s
|
||||
req := &GetUserPrizeRecordsReq{User: c.buildUser(uid, cookie), SID: sid}
|
||||
var resp GetUserPrizeRecordsResp
|
||||
_, err = session.callRPC(ctx, ServantWebActUI, FuncPrizeRecords, req, &resp)
|
||||
if err == nil {
|
||||
c.logf("[WSS] 兑换记录已解码 uid=%d sid=%d status=%d count=%d msg=%s", uid, sid, resp.Status, len(resp.Records), resp.Msg)
|
||||
}
|
||||
return &resp, err
|
||||
}
|
||||
|
||||
@@ -548,6 +558,9 @@ func (c *WSSClient) ScoreExchangePrize(ctx context.Context, uid int64, cookie st
|
||||
}
|
||||
var resp ScoreExchangePrizeResp
|
||||
_, err = session.callRPC(ctx, ServantWebActUI, FuncExchangePrize, req, &resp)
|
||||
if err == nil {
|
||||
c.logf("[WSS] 兑换结果已解码 uid=%d sid=%d pid=%d status=%d order=%s msg=%s", uid, sid, pid, resp.Status, resp.OrderID, exchangeResponseMessage(&resp))
|
||||
}
|
||||
return &resp, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user