fix:自动补货更新
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user