Your Name před 8 měsíci
rodič
revize
ba13ff4668

+ 38 - 0
app/Module/GameItems/AdminControllers/Actions/DuplicateRowAction.php

@@ -0,0 +1,38 @@
+<?php
+
+namespace App\Module\GameItems\AdminControllers\Actions;
+
+use App\Module\GameItems\Repositorys\ItemRepository;
+use Dcat\Admin\Grid\RowAction;
+use Illuminate\Http\Request;
+
+class DuplicateRowAction extends RowAction
+{
+    protected $title = '复制';
+
+    public function title()
+    {
+        return $this->title;
+    }
+
+    public function handle(Request $request)
+    {
+        try {
+            $id = $this->getKey();
+            $repository = app(ItemRepository::class);
+            $item = $repository->duplicate($id);
+            
+            return $this->response()
+                ->success("复制成功 [ID: {$item->id}]")
+                ->refresh();
+        } catch (\Exception $e) {
+            return $this->response()
+                ->error('复制失败: '.$e->getMessage());
+        }
+    }
+
+    public function confirm()
+    {
+        return ['确定要复制此物品吗?', '复制操作将创建一个新的物品记录'];
+    }
+}

+ 2 - 2
app/Module/GameItems/AdminControllers/CategoryController.php

@@ -144,7 +144,7 @@ class CategoryController extends AdminController
             // 父分类选择,排除自己及其子分类
             $form->select('parent_id', '父分类')
                 ->options(function () use ($form) {
-                    $categories = (new ItemCategoryRepository())->all();
+                    $categories = (new ItemCategory())->all();
                     $options = [0 => '无'];
 
                     // 如果是编辑状态,需要排除自己及其子分类
@@ -180,7 +180,7 @@ class CategoryController extends AdminController
     protected function getChildrenIds(int $categoryId): array
     {
         $ids = [];
-        $children = (new ItemCategoryRepository())->where('parent_id', $categoryId)->get();
+        $children = (new ItemCategory())->where('parent_id', $categoryId)->get();
 
         foreach ($children as $child) {
             $ids[] = $child->id;

+ 9 - 4
app/Module/GameItems/AdminControllers/ItemController.php

@@ -33,7 +33,7 @@ class ItemController extends AdminController
      */
     protected function grid()
     {
-        return Grid::make(new ItemRepository(), function (Grid $grid) {
+        return Grid::make(new ItemRepository(['category']), function (Grid $grid) {
             $helper = new GridHelper($grid, $this);
             $grid->column('id', 'ID')->sortable();
             $grid->column('name', '名称');
@@ -48,6 +48,11 @@ class ItemController extends AdminController
             $grid->column('created_at', '创建时间');
             $grid->column('updated_at', '更新时间');
 
+            // 添加复制行操作
+            $grid->actions(function (Grid\Displayers\Actions $actions) {
+                $actions->append(new \App\Module\GameItems\AdminControllers\Actions\DuplicateRowAction());
+            });
+
             // 筛选
             $grid->filter(function ($filter) {
                 $helper = new FilterHelper($filter, $this);
@@ -77,8 +82,8 @@ class ItemController extends AdminController
         });
 
 
-    }
 
+        }
     /**
      * 详情页
      *
@@ -113,7 +118,7 @@ class ItemController extends AdminController
             $show->field('updated_at', '更新时间');
 
             // 如果是宝箱类型,显示宝箱内容
-            if ($show->getModel()->type == ITEM_TYPE::OPENABLE) {
+            if ($show->getModel()->type == ITEM_TYPE::CHEST) {
                 $show->chestContents('宝箱内容', function ($chestContents) {
                     $chestContents->resource('/admin/game-items-chest-contents');
                     $chestContents->id('ID');
@@ -177,7 +182,7 @@ class ItemController extends AdminController
             // 保存前回调
             $form->saving(function (Form $form) {
                 // 如果是宝箱类型,确保有min_drop_count和max_drop_count属性
-                if ($form->type == ITEM_TYPE::OPENABLE) {
+                if ($form->type == ITEM_TYPE::CHEST) {
                     $numericAttributes = $form->numeric_attributes ?: [];
                     if (!isset($numericAttributes['min_drop_count'])) {
                         $numericAttributes['min_drop_count'] = 1;

+ 69 - 0
app/Module/GameItems/Commands/GenerateItemsJsonCommand.php

@@ -0,0 +1,69 @@
+<?php
+
+namespace App\Module\GameItems\Commands;
+
+use Illuminate\Console\Command;
+use App\Module\GameItems\Models\Item;
+use Illuminate\Support\Facades\File;
+
+class GenerateItemsJsonCommand extends Command
+{
+    /**
+     * 命令名称和签名
+     *
+     * @var string
+     */
+    protected $signature = 'gameitems:generate-json';
+
+    /**
+     * 命令描述
+     *
+     * @var string
+     */
+    protected $description = 'Generate items.json from Item table';
+
+    /**
+     * 执行命令
+     */
+    public function handle()
+    {
+        // 查询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();
+
+        // 确保public/json目录存在
+        $directory = public_path('json');
+        if (!File::exists($directory)) {
+            File::makeDirectory($directory, 0755, true);
+        }
+
+        // 准备完整数据,包含生成时间
+        $data = [
+            'generated_at' => now()->toDateTimeString(),
+            'items' => $items
+        ];
+
+        // 写入JSON文件
+        $json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
+        File::put($directory . '/items.json', $json);
+
+        $this->info('Successfully generated items.json with timestamp');
+    }
+}

+ 0 - 2
app/Module/GameItems/Models/Item.php

@@ -17,7 +17,6 @@ use UCore\ModelCore;
  * @property   int  $category_id  物品分类ID,外键关联kku_item_categories表
  * @property   int  $type  物品类型(1:可使用, 2:可装备, 3:可合成, 4:可交任务, 5:可开启...)
  * @property   int  $is_unique  是否是单独属性物品(0:否,默认, 1:是)
- * @property   string  $icon  物品图标路径
  * @property   int  $max_stack  最大堆叠数量
  * @property   int  $sell_price  出售价格
  * @property   int  $tradable  是否可交易(0:不可交易, 1:可交易,默认)
@@ -48,7 +47,6 @@ class Item extends ModelCore
         'category_id',
         'type',
         'is_unique',
-        'icon',
         'max_stack',
         'sell_price',
         'tradable',

+ 5 - 2
app/Module/GameItems/Providers/GameItemsServiceProvider.php

@@ -24,7 +24,10 @@ class GameItemsServiceProvider extends ServiceProvider
      */
     public function boot()
     {
-
-
+        if ($this->app->runningInConsole()) {
+            $this->commands([
+                \App\Module\GameItems\Commands\GenerateItemsJsonCommand::class,
+            ]);
+        }
     }
 }

+ 16 - 1
app/Module/GameItems/Repositorys/ItemRepository.php

@@ -8,4 +8,19 @@ use Dcat\Admin\Repositories\EloquentRepository;
 class ItemRepository extends EloquentRepository
 {
     protected $eloquentClass = Item::class;
-}
+
+    /**
+     * 复制物品
+     * @param int $id 物品ID
+     * @return Item
+     */
+    public function duplicate(int $id): Item
+    {
+        $item = $this->eloquentClass::findOrFail($id);
+        $newItem = $item->replicate();
+        $newItem->name = $item->name . ' (复制)';
+        $newItem->save();
+
+        return $newItem;
+    }
+}

+ 1 - 1
config/admin.php

@@ -169,7 +169,7 @@ return [
     'grid' => [
 
         // The global Grid action display class.
-        'grid_action_class' => Dcat\Admin\Grid\Displayers\Actions::class,
+        'grid_action_class' => \UCore\DcatAdmin\Grid\Displayers\LineActions::class,
 
         // The global Grid batch action display class.
         'batch_action_class' => Dcat\Admin\Grid\Tools\BatchActions::class,

+ 3 - 4
config/app.php

@@ -187,10 +187,9 @@ return [
         App\Module\China\Providers\ChinaServiceProvider::class,
         # Oauth
         App\Module\OAuth\OAuthServiceProvider::class,
-
-
-        //Transaction 模块  TransactionServiceProvider
-        \App\Module\Transaction\Providers\TransactionServiceProvider::class,
+        
+        // GameItems 模块
+        \App\Module\GameItems\Providers\GameItemsServiceProvider::class,
     ],
 
     /*

+ 2 - 0
noai.md

@@ -43,3 +43,5 @@ netresearch/jsonmapper
 参考 app/Module/Fund/GameItems/AdminControllers/ItemController.php ,修复物品模块后台其他控制器,不应使用模型,应该使用数据仓库
 
 Show::make 正确的使用方式`Show::make($id, new FundRepository(), function (Show $show) {`
+
+创建一个命令,根据Item表生成配置表json格式到  public/json/items.json,包含id/name/description/sell_price/display_attributes字段

+ 131 - 0
public/json/items.json

@@ -0,0 +1,131 @@
+{
+    "generated_at": "2025-04-25 08:38:49",
+    "items": [
+        {
+            "id": 1,
+            "name": "神秘种子",
+            "description": "神秘种子",
+            "sell_price": 0,
+            "display_attributes": []
+        },
+        {
+            "id": 2,
+            "name": "萝卜",
+            "description": "萝卜",
+            "sell_price": 0,
+            "display_attributes": []
+        },
+        {
+            "id": 3,
+            "name": "辣椒",
+            "description": "辣椒",
+            "sell_price": 0,
+            "display_attributes": []
+        },
+        {
+            "id": 4,
+            "name": "苹果",
+            "description": "苹果",
+            "sell_price": 0,
+            "display_attributes": []
+        },
+        {
+            "id": 5,
+            "name": "西瓜",
+            "description": "西瓜",
+            "sell_price": 0,
+            "display_attributes": []
+        },
+        {
+            "id": 6,
+            "name": "草莓",
+            "description": "草莓",
+            "sell_price": 0,
+            "display_attributes": []
+        },
+        {
+            "id": 7,
+            "name": "南瓜",
+            "description": "南瓜",
+            "sell_price": 0,
+            "display_attributes": []
+        },
+        {
+            "id": 8,
+            "name": "核桃",
+            "description": "核桃",
+            "sell_price": 0,
+            "display_attributes": []
+        },
+        {
+            "id": 9,
+            "name": "可可",
+            "description": "可可",
+            "sell_price": 0,
+            "display_attributes": []
+        },
+        {
+            "id": 10,
+            "name": "人参",
+            "description": "人参",
+            "sell_price": 0,
+            "display_attributes": []
+        },
+        {
+            "id": 11,
+            "name": "玫瑰",
+            "description": "玫瑰",
+            "sell_price": 0,
+            "display_attributes": []
+        },
+        {
+            "id": 12,
+            "name": "草莓种⼦",
+            "description": "草莓种⼦",
+            "sell_price": 0,
+            "display_attributes": []
+        },
+        {
+            "id": 13,
+            "name": "南⽠种⼦",
+            "description": "南⽠种⼦",
+            "sell_price": 0,
+            "display_attributes": []
+        },
+        {
+            "id": 14,
+            "name": "核桃种⼦",
+            "description": "核桃种⼦",
+            "sell_price": 0,
+            "display_attributes": []
+        },
+        {
+            "id": 15,
+            "name": "可可种⼦",
+            "description": "可可种⼦",
+            "sell_price": 0,
+            "display_attributes": []
+        },
+        {
+            "id": 16,
+            "name": "⼈参种⼦",
+            "description": "⼈参种⼦",
+            "sell_price": 0,
+            "display_attributes": []
+        },
+        {
+            "id": 17,
+            "name": "玫瑰种⼦",
+            "description": "玫瑰种⼦",
+            "sell_price": 0,
+            "display_attributes": []
+        },
+        {
+            "id": 18,
+            "name": "辣椒 (复制) (复制)",
+            "description": "辣椒",
+            "sell_price": 0,
+            "display_attributes": []
+        }
+    ]
+}