Your Name 8 месяцев назад
Родитель
Сommit
05fb922c5f

+ 32 - 0
app/Module/Game/DCache/ChestJsonConfig.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace App\Module\Game\DCache;
+
+use App\Module\GameItems\Commands\GenerateItemsJsonCommand;
+use App\Module\LCache\DQueueJob;
+
+class ChestJsonConfig extends DQueueJob
+{
+
+
+    static public function getNewData(array $parameter = [])
+    {
+        return GenerateItemsJsonCommand::generateJson();
+    }
+
+    static public function getTtl(): int
+    {
+        return 3600;
+    }
+
+    static public function getPreventDuplication(): int
+    {
+        return 600;
+    }
+
+    static public function getRequiredArgIndex(): array
+    {
+        return [];
+    }
+
+}

+ 84 - 0
app/Module/GameItems/Commands/GenerateChestJsonCommand.php

@@ -0,0 +1,84 @@
+<?php
+
+namespace App\Module\GameItems\Commands;
+
+use App\Module\Game\DCache\ItemJsonConfig;
+use App\Module\Game\Services\JsonConfigService;
+use Illuminate\Console\Command;
+use App\Module\GameItems\Models\Item;
+use Illuminate\Support\Facades\File;
+use Illuminate\Support\Facades\Log;
+
+class GenerateChestJsonCommand extends Command
+{
+
+    /**
+     * 命令名称和签名
+     *
+     * @var string
+     */
+    protected $signature = 'gameitems:generate-json';
+
+    /**
+     * 命令描述
+     *
+     * @var string
+     */
+    protected $description = 'Generate items.json from Item table';
+
+    /**
+     * 执行命令
+     */
+    /**
+     * 生成物品JSON数据
+     */
+    public static function generateJson()
+    {
+        try {
+            // 查询Item表中的数据
+            $items = Item::query()
+                ->select([
+                             'id',
+                             'name',
+                             'description',
+                             'sell_price',
+                             'display_attributes'
+                         ])
+                ->get()
+                ->map(function ($item) {
+                    return [
+                        'id'                 => $item->id,
+                        'name'               => $item->name,
+                        'description'        => $item->description,
+                        'sell_price'         => $item->sell_price,
+                        'display_attributes' => $item->display_attributes
+                    ];
+                })
+                ->toArray();
+
+
+
+            // 准备完整数据,包含生成时间
+            $data = [
+                'generated_at' => now()->toDateTimeString(),
+                'items'        => $items
+            ];
+
+            return $data;
+        } catch (\Exception $e) {
+            Log::error('Generate items.json failed: ' . $e->getMessage());
+
+            return false;
+        }
+    }
+
+    public function handle()
+    {
+        if (ItemJsonConfig::getData([], true)) {
+            $this->info('Successfully generated items.json with timestamp');
+        } else {
+            $this->error('Failed to generate items.json');
+        }
+    }
+
+}