| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace App\Module\Farm\AdminControllers\Tools;
- use App\Module\Game\DCache\FarmHouseJsonConfig;
- use Dcat\Admin\Grid\Tools\AbstractTool;
- use Illuminate\Support\Facades\Log;
- class RefreshCheckTool extends AbstractTool
- {
- protected $shouldDisplay;
- protected $style = 'btn btn-default waves-effect';
- public function __construct(bool $shouldDisplay = true)
- {
- $this->shouldDisplay = $shouldDisplay;
- }
- public function title()
- {
- return '检查状态';
- }
- public function render()
- {
- if (!$this->shouldDisplay) {
- return '';
- }
- return parent::render();
- }
- public static function checkSyncStatus(): array
- {
- try {
- $json = FarmHouseJsonConfig::getData([],true);
- $generatedAt = \Carbon\Carbon::createFromTimestamp($json['generated_ts']);
- $lastUpdated = \Carbon\Carbon::parse(\App\Module\Farm\Models\FarmHouseConfig::max('updated_at'));
- if ($generatedAt->lt($lastUpdated)) {
- return [
- 'is_synced' => false,
- 'message' => "配置文件需要更新(生成于 {$generatedAt->format('Y-m-d H:i:s')},最后修改于 {$lastUpdated->format('Y-m-d H:i:s')})",
- 'should_display' => true
- ];
- } else {
- return [
- 'is_synced' => true,
- 'message' => "配置文件已是最新(生成于 {$generatedAt->format('Y-m-d H:i:s')})",
- 'should_display' => false
- ];
- }
- } catch (\Exception $e) {
- Log::error('Check farm house config sync status failed: '.$e->getMessage());
- return [
- 'is_synced' => false,
- 'message' => '检查配置文件状态失败:'.$e->getMessage(),
- 'should_display' => true
- ];
- }
- }
- }
|