shouldDisplay = $shouldDisplay; } public function title() { return '生成JSON'; } public function confirm() { return '确定要生成房屋配置JSON数据吗?'; } public function handle(Request $request) { try { // 直接调用缓存类刷新数据,这会同时生成JSON文件 FarmHouseJsonConfig::getData([], true); return $this->response()->success('生成成功')->refresh(); } catch (\Exception $e) { Log::error('Generate farm_house.json exception: '.$e->getMessage()); return $this->response()->error('生成失败:'.$e->getMessage()); } } public function render() { if (!$this->shouldDisplay) { return ''; } return parent::render(); } public static function shouldDisplay(): bool { $json = FarmHouseJsonConfig::getData(); $generatedAt = \Carbon\Carbon::parse($json['generated_ts']); $lastUpdated = \Carbon\Carbon::parse(\App\Module\Farm\Models\FarmHouseConfig::max('updated_at')); return $generatedAt->lt($lastUpdated); } }