shouldDisplay = $shouldDisplay; } public function title() { return '检查状态'; } public function render() { if (!$this->shouldDisplay) { return ''; } return parent::render(); } /** * 检查配置表同步状态 * * @return array */ public static function checkSyncStatus(): array { try { $json = FundCurrencyJsonConfig::getData(); // 如果没有生成时间戳,说明需要生成 if (!isset($json['generated_ts'])) { return [ 'is_synced' => false, 'message' => '【货币配置表】需要生成,尚未找到配置数据', 'should_display' => true ]; } $generatedAt = \Carbon\Carbon::createFromTimestamp($json['generated_ts']); $lastUpdated = \Carbon\Carbon::parse(FundCurrencyModel::max('update_time') ?: '2000-01-01'); // 使用绝对时间差,避免相对时间导致的"X小时后"这样的显示问题 $options = ['syntax' => CarbonInterface::DIFF_ABSOLUTE]; if ($generatedAt->lt($lastUpdated)) { return [ 'is_synced' => false, 'message' => "【货币配置表】需要更新,生成于 {$generatedAt->diffForHumans(null, $options)},数据库最后更新于 {$lastUpdated->diffForHumans(null, $options)}", 'should_display' => true ]; } else { return [ 'is_synced' => true, 'message' => "【货币配置表】已同步,生成于 {$generatedAt->diffForHumans(null, $options)}", 'should_display' => false ]; } } catch (\Exception $e) { Log::error('Check fund currency config sync status failed: '.$e->getMessage()); return [ 'is_synced' => false, 'message' => '【货币配置表】检查状态失败:'.$e->getMessage(), 'should_display' => true ]; } } public static function shouldDisplay(): bool { return self::checkSyncStatus()['should_display']; } }