fix(rock): 兼容 0666.pro 接口 points 字段字符串与数值自适应解析

1. 新增 FlexibleFloat64 类型,解决上游 /api/me 响应中 points 为字符串(如 '8271.2')导致反序列化失败的问题;
2. 服务层与数据库快照存储统一调用 Float64() 保持类型严谨;
3. 单元测试补充真实上游字符串响应场景并全绿通过。
This commit is contained in:
yml2213
2026-10-05 15:42:00 +08:00
parent 80554555d3
commit 7e5cbaf65e
3 changed files with 49 additions and 8 deletions
+2 -2
View File
@@ -150,7 +150,7 @@ func (s *RockService) TestConnection(ctx context.Context, bearerToken string) (*
now := time.Now()
_ = s.db.WithContext(ctx).Model(&model.RockConfig{}).Where("id = 1").Updates(map[string]interface{}{
"username": me.User.Username,
"points": me.User.Points,
"points": me.User.Points.Float64(),
"last_heartbeat_at": now,
}).Error
@@ -271,7 +271,7 @@ func (s *RockService) PurchaseTokens(ctx context.Context, count int, isAuto bool
defer cancel()
me, meErr := s.client.GetMe(bgCtx, cfg.BearerToken)
if meErr == nil && me != nil {
_ = s.db.Model(&model.RockConfig{}).Where("id = 1").Update("points", me.User.Points).Error
_ = s.db.Model(&model.RockConfig{}).Where("id = 1").Update("points", me.User.Points.Float64()).Error
}
}()