fix:自动补货更新

This commit is contained in:
2026-11-02 18:30:51 +08:00
parent ce8d99ad95
commit 4dbec33dbd
9 changed files with 197 additions and 20 deletions
+17 -4
View File
@@ -43,10 +43,13 @@ type RockStatsResponse struct {
AutoDeliveryEnabled bool `json:"auto_delivery_enabled"`
TokenWarningStock int `json:"token_warning_stock"`
AutoPurchaseEnabled bool `json:"auto_purchase_enabled"`
Username string `json:"username"`
LastHeartbeatAt string `json:"last_heartbeat_at,omitempty"`
LastPurchaseError string `json:"last_purchase_error,omitempty"`
LastPurchaseErrorAt string `json:"last_purchase_error_at,omitempty"`
// 自动补货冷却状态:供页面提示“下次可补货时间”
AutoPurchaseCooldownSeconds int64 `json:"auto_purchase_cooldown_seconds"`
NextAutoPurchaseAt string `json:"next_auto_purchase_at,omitempty"`
Username string `json:"username"`
LastHeartbeatAt string `json:"last_heartbeat_at,omitempty"`
LastPurchaseError string `json:"last_purchase_error,omitempty"`
LastPurchaseErrorAt string `json:"last_purchase_error_at,omitempty"`
}
type RockDashboardResult struct {
@@ -324,5 +327,15 @@ func (s *RockService) GetStats(ctx context.Context) (*RockStatsResponse, error)
}
stats.DeletedStock = deletedCount
if cfg.AutoPurchaseEnabled {
if remain := rockAutoPurchaseCooldownRemaining(cfg, time.Now()); remain > 0 {
stats.AutoPurchaseCooldownSeconds = int64((remain + time.Second - 1) / time.Second)
if cfg.LastAutoAttemptAt != nil {
next := cfg.LastAutoAttemptAt.Add(time.Duration(cfg.PurchaseCooldownMinutes) * time.Minute)
stats.NextAutoPurchaseAt = next.Format("2006-01-02 15:04:05")
}
}
}
return &stats, nil
}