diff --git a/internal/service/voiceroomrocket/mapper.go b/internal/service/voiceroomrocket/mapper.go index e09973a..eedcc97 100644 --- a/internal/service/voiceroomrocket/mapper.go +++ b/internal/service/voiceroomrocket/mapper.go @@ -73,16 +73,16 @@ func pointerTimeValue(value *time.Time) time.Time { return *value } -func decimalPercent(current, need int64) (string, int) { +func decimalPercent(current, need int64) (string, float64) { if need <= 0 || current <= 0 { return "0.0000", 0 } - percent := float64(current) * 100 / float64(need) - display := int(math.Floor(percent)) - if display > 100 { - display = 100 + if current >= need { + return "1.0000", 1 } - return fmt.Sprintf("%.4f", percent), display + // App 端按 0-1 比例换算百分比;截断而非四舍五入,避免未充满时提前显示 100%。 + ratio := math.Floor(float64(current)/float64(need)*10000) / 10000 + return fmt.Sprintf("%.4f", ratio), ratio } func parsePercent(value string) float64 { diff --git a/internal/service/voiceroomrocket/types.go b/internal/service/voiceroomrocket/types.go index d616f4f..5dde3eb 100644 --- a/internal/service/voiceroomrocket/types.go +++ b/internal/service/voiceroomrocket/types.go @@ -422,7 +422,7 @@ type StatusResponse struct { CurrentEnergy int64 `json:"currentEnergy"` NeedEnergy int64 `json:"needEnergy"` EnergyPercent string `json:"energyPercent"` - DisplayPercent int `json:"displayPercent"` + DisplayPercent float64 `json:"displayPercent"` LaunchCountdownSeconds int `json:"launchCountdownSeconds,omitempty"` Shake bool `json:"shake"` PreviewRocketURL string `json:"previewRocketUrl,omitempty"` diff --git a/scripts/voice_room_rocket_local_verify.go b/scripts/voice_room_rocket_local_verify.go index 20d49c9..1668d01 100644 --- a/scripts/voice_room_rocket_local_verify.go +++ b/scripts/voice_room_rocket_local_verify.go @@ -182,7 +182,7 @@ func main() { mid, err := service.GetStatus(ctx, user, room.RoomID) must(err, "mid status") - assert(mid.CurrentLevel == 1 && mid.CurrentEnergy == 60 && mid.DisplayPercent == 60, "mid status mismatch") + assert(mid.CurrentLevel == 1 && mid.CurrentEnergy == 60 && mid.DisplayPercent == 0.6, "mid status mismatch") secondPayload := mqEnvelope(giftPayload("LOCAL_VERIFY_TRACK_2", igniteUserID, room.RoomID, 80, now.Add(time.Second))) second, err := service.ProcessGiftPayload(ctx, secondPayload)