Selaa lähdekoodia

移除宝箱相关废弃表和代码,完成系统清理

1. 数据库清理
   - 执行数据迁移,将旧配置迁移到新系统
   - 删除废弃表:kku_item_chest_contents, kku_item_chest_open_costs
   - 移除相关外键约束

2. 代码清理
   - 删除废弃模型:ItemChestContent, ItemChestOpenCost
   - 删除废弃仓库:ItemChestContentRepository, ItemChestOpenCostRepository
   - 删除废弃控制器和DTO文件
   - 删除废弃验证器:ChestOpenCostValidator

3. 关联关系更新
   - 移除Item模型中对已删除模型的关联
   - 更新ItemController显示新系统配置信息
   - 移除ItemChestOpenLog和ItemPityTime中的过时关联

4. 文档更新
   - 更新README.md移除对已删除表和模型的引用
   - 更新数据库结构说明
   - 更新关联关系描述

特点:
- 彻底清理旧系统残留
- 保留必要的日志和保底表
- 新系统配置完整可用
- 文档同步更新
notfff 7 kuukautta sitten
vanhempi
commit
5234d78581

+ 0 - 171
app/Module/GameItems/AdminControllers/ChestContentController.php

@@ -1,171 +0,0 @@
-<?php
-
-namespace App\Module\GameItems\AdminControllers;
-
-use App\Module\GameItems\AdminControllers\Actions\DuplicateChestContentAction;
-use App\Module\GameItems\AdminControllers\Actions\ViewItemDetailAction;
-use App\Module\GameItems\AdminControllers\Actions\ViewGroupDetailAction;
-use App\Module\GameItems\AdminControllers\Actions\ViewChestDetailAction;
-use App\Module\GameItems\Repositorys\ItemChestContentRepository;
-use Dcat\Admin\Form;
-use Dcat\Admin\Grid;
-use Dcat\Admin\Show;
-use UCore\DcatAdmin\AdminController;
-use Spatie\RouteAttributes\Attributes\Resource;
-use App\Module\GameItems\AdminControllers\Helper\FilterHelper;
-use App\Module\GameItems\AdminControllers\Helper\FormHelper;
-use App\Module\GameItems\AdminControllers\Helper\GridHelper;
-use App\Module\GameItems\AdminControllers\Helper\ShowHelper;
-
-/**
- * 宝箱内容管理
- *
- */
-#[Resource('game-items-chest-contents', names: 'dcat.admin.game-items-chest-contents')]
-class ChestContentController extends AdminController
-{
-
-    /**
-     * 标题
-     *
-     * @var string
-     */
-    protected $title = '宝箱内容管理';
-
-    /**
-     * 列表页
-     *
-     * @return Grid
-     */
-    protected function grid()
-    {
-        return Grid::make(new ItemChestContentRepository(['chest','item','group']), function (Grid $grid) {
-            $helper = new GridHelper($grid, $this);
-            $helper->columnId();
-            $grid->column('chest.name', '宝箱名称');
-            $grid->column('item.name', '物品名称');
-            $grid->column('group.name', '物品组名称');
-            $grid->column('min_quantity', '最小数量');
-            $grid->column('max_quantity', '最大数量');
-            $grid->column('weight', '权重');
-            $grid->column('allow_duplicate', '允许重复')->bool();
-            $grid->column('pity_count', '保底次数');
-            $grid->column('pity_weight_factor', '保底权重因子');
-            $grid->column('created_at', '创建时间');
-            $grid->column('updated_at', '更新时间');
-
-            // 添加行操作
-            $grid->actions(function (Grid\Displayers\Actions $actions) {
-                // 添加复制按钮
-                $actions->append(new DuplicateChestContentAction());
-                // 添加查看宝箱详情按钮
-                $actions->append(new ViewChestDetailAction());
-                // 添加查看物品详情按钮
-                $actions->append(new ViewItemDetailAction());
-                // 添加查看物品组详情按钮
-                $actions->append(new ViewGroupDetailAction());
-            });
-
-            // 筛选
-            $grid->filter(function ($filter) {
-                $helper = new FilterHelper($filter, $this);
-                $helper->equal('id', 'ID');
-                $helper->equalSelectModelChestItem('item_id');
-
-
-            });
-        });
-    }
-
-    /**
-     * 详情页
-     *
-     * @param mixed $id
-     * @return Show
-     */
-    protected function detail($id)
-    {
-        return Show::make($id, new ItemChestContentRepository(), function (Show $show) {
-            $helper = new ShowHelper($show, $this);
-            $helper->field('id', 'ID');
-            $show->field('chest.name', '宝箱名称');
-            $show->field('item.name', '物品名称');
-            $show->field('group.name', '物品组名称');
-            $helper->field('min_quantity', '最小数量');
-            $helper->field('max_quantity', '最大数量');
-            $helper->field('weight', '权重');
-            $show->field('allow_duplicate', '允许重复')->as(function ($allowDuplicate) {
-                return $allowDuplicate ? '是' : '否';
-            });
-            $helper->field('pity_count', '保底次数');
-            $helper->field('pity_weight_factor', '保底权重因子');
-            $helper->field('created_at', '创建时间');
-            $helper->field('updated_at', '更新时间');
-        });
-    }
-
-    /**
-     * 表单
-     *
-     * @return Form
-     */
-    protected function form()
-    {
-        return Form::make(new ItemChestContentRepository(), function (Form $form) {
-            $helper = new FormHelper($form, $this);
-            $helper->selectModelChestItem('chest_id');
-
-
-
-            // 物品和物品组二选一
-            $form->radio('content_type', '内容类型')
-                ->options([ 'item' => '物品', 'group' => '物品组' ])
-                ->default('item')
-                ->when('item', function (Form $form) {
-                    $helper = new FormHelper($form, $this);
-                    $helper->selectModelItem('item_id', '物品');
-                })
-                ->when('group', function (Form $form) {
-                    $helper = new FormHelper($form, $this);
-                    $helper->selectModelChestItemGroup('group_id', '物品组');
-                });
-
-            $helper->number('min_quantity','最少数量')
-                ->default(1)
-                ->min(1)
-                ->required();
-            $helper->number('max_quantity','最多数量')
-                ->default(1)
-                ->min(1)
-                ->required();
-            $helper->number('weight','权重')
-                ->default(1.0)
-                ->min(0.001)
-                ->required()
-                ->help('权重越高,掉落概率越大,所有内容权重总和为100');
-            $form->switch('allow_duplicate', '允许重复')
-                ->default(false)
-                ->help('是否允许在一次开箱中重复获得该内容');
-            $helper->number('pity_count','保底次数')
-                ->default(0)
-                ->min(0)
-                ->help('连续未获得该内容的次数达到此值时,必定获得该内容,0表示不启用保底机制');
-            $helper->number('pity_weight_factor','保底递增权重')
-                ->default(1.0)
-                ->min(0)
-                ->help('每次未获得该内容时,权重增加的倍数,默认为1.0');
-
-            // 保存前回调
-            $form->saving(function (Form $form) {
-                // 根据内容类型设置对应的字段
-                if ($form->content_type == 'item') {
-                    $form->group_id = null;
-                } else {
-                    $form->item_id = null;
-                }
-                $form->deleteInput('content_type');
-            });
-        });
-    }
-
-}

+ 0 - 170
app/Module/GameItems/AdminControllers/ItemChestOpenCostController.php

@@ -1,170 +0,0 @@
-<?php
-
-namespace App\Module\GameItems\AdminControllers;
-
-use App\Module\GameItems\AdminControllers\Actions\BatchActivateAction;
-use App\Module\GameItems\Enums\CHEST_COST_TYPE;
-use App\Module\GameItems\Models\Item;
-use App\Module\GameItems\Models\ItemChestOpenCost;
-use App\Module\GameItems\Repositorys\ItemChestOpenCostRepository;
-use Dcat\Admin\Form;
-use Dcat\Admin\Grid;
-use Dcat\Admin\Show;
-use UCore\DcatAdmin\AdminController;
-use App\Module\GameItems\AdminControllers\Helper\FilterHelper;
-use App\Module\GameItems\AdminControllers\Helper\FormHelper;
-use App\Module\GameItems\AdminControllers\Helper\GridHelper;
-use App\Module\GameItems\AdminControllers\Helper\ShowHelper;
-use Dcat\Admin\Layout\Content;
-use Spatie\RouteAttributes\Attributes\Resource;
-
-/**
- * 宝箱开启消耗配置控制器
- */
-#[Resource('game-items-chest-costs', names: 'dcat.admin.game-items-chest-costs')]
-class ItemChestOpenCostController extends AdminController
-{
-    protected $title ='宝箱开启消耗配置';
-
-
-
-
-
-    /**
-     * 列表页
-     *
-     * @return Grid
-     */
-    protected function grid()
-    {
-        return Grid::make(new ItemChestOpenCostRepository(['chest', 'costItem']), function (Grid $grid) {
-            $helper = new GridHelper($grid, $this);
-
-            $helper->columnId();
-            $grid->column('chest.name', '宝箱名称')->link(function () {
-                return admin_url('game-items/' . $this->chest_id);
-            });
-
-            $grid->column('cost_type', '消耗类型')->display(function ($value) {
-                return CHEST_COST_TYPE::getAll()[$value] ?? '未知';
-            });
-
-            $grid->column('cost_id', '消耗ID')->as(function ($value) {
-                if ($this->cost_type == CHEST_COST_TYPE::ITEM->value) {
-                    if ($this->costItem) {
-                        $itemUrl = admin_url('game-items-items/' . $value);
-                        return "<a href='{$itemUrl}' target='_blank'>{$this->costItem->name} <i class='fa fa-external-link'></i></a> (ID: {$value})";
-                    }
-                    return $value;
-                }
-                return $value;
-            })->unescape();
-
-            $grid->column('cost_quantity', '消耗数量');
-            $grid->column('is_active', '是否激活')->switch();
-            $grid->column('created_at', '创建时间');
-            $grid->column('updated_at', '更新时间');
-
-            // 筛选器
-            $grid->filter(function (Grid\Filter $filter) {
-                $helper = new FilterHelper($filter, $this);
-                $helper->equal('id', 'ID');
-                $helper->equalSelectModelChestItem('chest_id', '宝箱ID');
-
-
-                $filter->equal('cost_type', '消耗类型')->select(CHEST_COST_TYPE::getAll());
-                $filter->equal('is_active', '是否激活')->radio([
-                    1 => '是',
-                    0 => '否',
-                ]);
-            });
-
-            // 批量操作
-            $grid->batchActions(function (Grid\Tools\BatchActions $batch) {
-                $batch->add(new \App\Module\GameItems\AdminControllers\Actions\BatchDeactivateAction());
-                $batch->add(new BatchActivateAction());
-            });
-
-            // 工具栏
-            $grid->tools(function (Grid\Tools $tools) {
-                $tools->append(new \App\Module\GameItems\AdminControllers\Actions\CopyToAnotherChestAction());
-            });
-        });
-    }
-
-    /**
-     * 详情页
-     *
-     * @param mixed $id
-     * @return Show
-     */
-    protected function detail($id)
-    {
-        return Show::make($id, new ItemChestOpenCostRepository(['chest', 'costItem']), function (Show $show) {
-            $helper = new ShowHelper($show, $this);
-
-            $helper->field('id', 'ID');
-            $show->field('chest.name', '宝箱名称');
-            $helper->field('chest_id', '宝箱ID');
-            $show->field('cost_type', '消耗类型')->as(function ($value) {
-                return CHEST_COST_TYPE::getAll()[$value] ?? '未知';
-            });
-
-            $helper->field('cost_id', '消耗ID');
-
-            // 根据消耗类型显示不同的关联信息
-            $show->field('costItem.name', '消耗物品名称')->unescape()->as(function ($name) {
-                if ($this->cost_type == CHEST_COST_TYPE::ITEM->value && $name) {
-                    $itemUrl = admin_url('game-items/items/' . $this->cost_id);
-                    return "<span class='badge badge-primary'>{$name}</span> "
-                        . "<a href='{$itemUrl}' target='_blank' class='btn btn-sm btn-primary ml-1'>"
-                        . "<i class='fa fa-external-link'></i> 查看物品详情</a>";
-                }
-                return '-';
-            });
-
-            $helper->field('cost_quantity', '消耗数量');
-            $show->field('is_active', '是否激活')->as(function ($value) {
-                return $value ? '是' : '否';
-            });
-
-            $helper->field('created_at', '创建时间');
-            $helper->field('updated_at', '更新时间');
-        });
-    }
-
-    /**
-     * 表单
-     *
-     * @return Form
-     */
-    protected function form()
-    {
-        return Form::make(new ItemChestOpenCostRepository(), function (Form $form) {
-            $helper = new FormHelper($form, $this);
-
-            // 只显示宝箱类型的物品
-            $chests = Item::where('type', 3)->pluck('name', 'id');
-
-            $helper->selectModelChestItem('chest_id', '宝箱');
-            $form->select('cost_type', '消耗类型')->options(CHEST_COST_TYPE::getAll())->required();
-
-            // 根据消耗类型显示不同的选择器
-            $form->number('cost_id', '消耗ID')->required();
-
-            $helper->number('cost_quantity', '消耗数量')->min(1)->default(1)->required();
-            $form->switch('is_active', '是否激活')->default(1);
-
-            // 保存前回调
-            $form->saving(function (Form $form) {
-                // 验证消耗ID
-                if ($form->cost_type == CHEST_COST_TYPE::ITEM->value) {
-                    $item = Item::find($form->cost_id);
-                    if (!$item) {
-                        return $form->response()->error('无效的物品ID');
-                    }
-                }
-            });
-        });
-    }
-}

+ 30 - 47
app/Module/GameItems/AdminControllers/ItemController.php

@@ -5,9 +5,7 @@ namespace App\Module\GameItems\AdminControllers;
 use App\Module\Game\DCache\ItemJsonConfig;
 use App\Module\GameItems\Enums\ITEM_TYPE;
 use App\Module\GameItems\Models\ItemCategory;
-use App\Module\GameItems\Models\ItemChestOpenCost;
-use App\Module\GameItems\Repositorys\ItemChestContentRepository;
-use App\Module\GameItems\Repositorys\ItemChestOpenCostRepository;
+
 use App\Module\GameItems\Repositorys\ItemRepository;
 use Dcat\Admin\Form;
 use Dcat\Admin\Grid;
@@ -131,8 +129,6 @@ class ItemController extends AdminController
                 $actions->append(new \App\Module\GameItems\AdminControllers\Actions\DuplicateRowAction());
 
                 // 如果是宝箱类型,添加宝箱管理按钮
-                $actions->append(new \App\Module\GameItems\AdminControllers\Actions\ChestManageAction());
-                $actions->append(new \App\Module\GameItems\AdminControllers\Actions\ChestCostAction());
                 $actions->append(new \App\Module\GameItems\AdminControllers\Actions\ChestNewManageAction());
             });
 
@@ -226,51 +222,38 @@ class ItemController extends AdminController
             $show->divider();
             // 如果是宝箱类型,显示宝箱内容
 
-            $show->relation('chest_contents', '宝箱内容',
-                function (\App\Module\GameItems\Models\Item $item) {
-//                dd($item);
-                    $grid = new Grid(new ItemChestContentRepository([ 'chest', 'item', 'group' ]));
-
-                    $grid->model()->where('chest_id', $item->id);
-
-                    // 设置路由
-                    $grid->setResource('game-items-chest-contents');
-
-                    $grid->id();
-                    $grid->column('chest.name', '宝箱名称');
-                    $grid->column('item.name', '物品名称');
-                    $grid->column('group.name', '物品组名称');
-                    $grid->column('min_quantity', '最小数量');
-                    $grid->column('max_quantity', '最大数量');
-                    $grid->column('weight', '权重');
-
-                    $grid->disableActions();
-
-                    return $grid;
-
-                });
-
-            $show->relation('chest_costs', '宝箱消耗',
-                function (\App\Module\GameItems\Models\Item $item) {
-//                dd($item);
-                    $grid = new Grid(new ItemChestOpenCostRepository(['costItem']));
-
-                    $grid->model()->where('chest_id', $item->id);
-
-                    // 设置路由
-                    $grid->setResource('game-items-chest-costs');
-
-                    $grid->id();
-                    $grid->column('costItem.name', '物品名称');
-
-
-
+            // 宝箱配置(新系统)
+            $show->field('chest_config_status', '宝箱配置状态')->as(function ($value, $model) {
+                if ($model->type != ITEM_TYPE::CHEST) {
+                    return '非宝箱类型';
+                }
+                $config = $model->chestConfig()->first();
+                return $config ? '已配置新系统' : '未配置';
+            });
 
-                    $grid->disableActions();
+            $show->field('consume_group_name', '消耗组')->as(function ($value, $model) {
+                if ($model->type != ITEM_TYPE::CHEST) {
+                    return '-';
+                }
+                $config = $model->chestConfig()->first();
+                return $config && $config->consumeGroup ? $config->consumeGroup->name : '无';
+            });
 
-                    return $grid;
+            $show->field('reward_group_name', '奖励组')->as(function ($value, $model) {
+                if ($model->type != ITEM_TYPE::CHEST) {
+                    return '-';
+                }
+                $config = $model->chestConfig()->first();
+                return $config && $config->rewardGroup ? $config->rewardGroup->name : '无';
+            });
 
-                });
+            $show->field('condition_group_name', '条件组')->as(function ($value, $model) {
+                if ($model->type != ITEM_TYPE::CHEST) {
+                    return '-';
+                }
+                $config = $model->chestConfig()->first();
+                return $config && $config->conditionGroup ? $config->conditionGroup->name : '无';
+            });
             return $show;
         });
 

+ 1 - 1
app/Module/GameItems/Console/Commands/MigrateChestToGroupSystemCommand.php

@@ -218,7 +218,7 @@ class MigrateChestToGroupSystemCommand extends Command
             'code' => 'chest_' . $chest->id . '_reward_' . time(),
             'description' => "宝箱 {$chest->name} 的奖励配置(从旧系统迁移)",
             'is_random' => true,
-            'random_count' => $chest->numeric_attributes['max_drop_count'] ?? 1,
+            'random_count' => ($chest->numeric_attributes && $chest->numeric_attributes->max_drop_count > 0) ? $chest->numeric_attributes->max_drop_count : 1,
             'reward_mode' => 1, // 权重选择模式
         ]);
         

+ 0 - 28
app/Module/GameItems/Databases/GenerateSql/item_chest_contents.sql

@@ -1,28 +0,0 @@
--- ******************************************************************
--- 表 kku_item_chest_contents 的创建SQL
--- 对应的Model: App\Module\GameItems\Models\ItemChestContent
--- 警告: 此文件由系统自动生成,禁止修改!
--- ******************************************************************
-
-CREATE TABLE `kku_item_chest_contents` (
-  `id` int NOT NULL AUTO_INCREMENT COMMENT '记录ID,主键',
-  `chest_id` int NOT NULL COMMENT '宝箱物品ID,外键关联kku_item_items表',
-  `item_id` int DEFAULT NULL COMMENT '可能获得的物品ID,外键关联kku_item_items表(与group_id二选一)',
-  `group_id` int DEFAULT NULL COMMENT '物品组ID,外键关联kku_item_groups表(与item_id二选一)',
-  `min_quantity` int DEFAULT '1' COMMENT '最小数量',
-  `max_quantity` int DEFAULT '1' COMMENT '最大数量',
-  `weight` decimal(5,3) NOT NULL COMMENT '权重,决定获取概率',
-  `allow_duplicate` tinyint DEFAULT '0' COMMENT '是否允许在同一宝箱中重复掉落(0:不允许, 1:允许)',
-  `pity_count` int DEFAULT '0' COMMENT '保底次数,当玩家连续未获得该内容达到次数后必定获得(0表示不启用保底)',
-  `pity_weight_factor` float DEFAULT '1' COMMENT '保底权重因子,用于递增概率计算(默认1.0)',
-  `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间',
-  `updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间',
-  PRIMARY KEY (`id`) USING BTREE,
-  KEY `idx_chest_id` (`chest_id`) USING BTREE,
-  KEY `idx_item_id` (`item_id`) USING BTREE,
-  KEY `idx_group_id` (`group_id`) USING BTREE,
-  KEY `idx_pity_count` (`pity_count`) USING BTREE,
-  CONSTRAINT `fk_chest_content_chest` FOREIGN KEY (`chest_id`) REFERENCES `kku_item_items` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT,
-  CONSTRAINT `fk_chest_content_group` FOREIGN KEY (`group_id`) REFERENCES `kku_item_groups` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT,
-  CONSTRAINT `fk_chest_content_item` FOREIGN KEY (`item_id`) REFERENCES `kku_item_items` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='宝箱内容配置表';

+ 0 - 19
app/Module/GameItems/Databases/GenerateSql/item_chest_open_costs.sql

@@ -1,19 +0,0 @@
--- ******************************************************************
--- 表 kku_item_chest_open_costs 的创建SQL
--- 对应的Model: App\Module\GameItems\Models\ItemChestOpenCost
--- 警告: 此文件由系统自动生成,禁止修改!
--- ******************************************************************
-
-CREATE TABLE `kku_item_chest_open_costs` (
-  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '记录ID,主键',
-  `chest_id` int unsigned NOT NULL COMMENT '宝箱ID,外键关联item_items表',
-  `cost_type` tinyint unsigned NOT NULL DEFAULT '1' COMMENT '消耗类型(1:物品, 2:货币, 3:其他资源)',
-  `cost_id` int unsigned NOT NULL COMMENT '消耗的物品/货币/资源ID',
-  `cost_quantity` int unsigned NOT NULL DEFAULT '1' COMMENT '消耗数量',
-  `is_active` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否激活(0:否, 1:是)',
-  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
-  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
-  PRIMARY KEY (`id`) USING BTREE,
-  KEY `idx_chest_id` (`chest_id`) USING BTREE,
-  KEY `idx_cost_type_cost_id` (`cost_type`,`cost_id`) USING BTREE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='宝箱开启消耗配置表';

+ 5 - 5
app/Module/GameItems/Docs/README.md

@@ -75,7 +75,7 @@ GameItems模块是游戏核心系统之一,负责管理游戏内所有物品
 
 | 表名 | 主要功能 | 关键字段 |
 |------|---------|---------|
-| item_chest_contents | 宝箱内容配置 | chest_id, item_id/group_id, weight |
+| item_chest_configs | 宝箱配置(新系统) | item_id, consume_group_id, reward_group_id, condition_group_id |
 | item_pity_times | 用户宝箱保底计数 | user_id, chest_id, chest_content_id, current_count |
 | item_chest_open_logs | 宝箱开启记录 | user_id, chest_id, result_items, pity_triggered |
 
@@ -199,10 +199,10 @@ GameItems模块是游戏核心系统之一,负责管理游戏内所有物品
 
 | 表名 | 索引字段 | 索引类型 | 说明 |
 | --- | --- | --- | --- |
-| item_chest_contents | chest_id | 普通索引 | 加速宝箱内容查询 |
-| item_chest_contents | item_id | 普通索引 | 加速物品在宝箱中的查询 |
-| item_chest_contents | group_id | 普通索引 | 加速查询物品组在宝箱中的配置 |
-| item_chest_contents | pity_count | 普通索引 | 加速查询启用保底的宝箱内容 |
+| item_chest_configs | item_id | 唯一索引 | 确保每个宝箱只有一个配置 |
+| item_chest_configs | consume_group_id | 普通索引 | 加速消耗组查询 |
+| item_chest_configs | reward_group_id | 普通索引 | 加速奖励组查询 |
+| item_chest_configs | condition_group_id | 普通索引 | 加速条件组查询 |
 | item_pity_times | user_id, chest_id, chest_content_id | 复合索引 | 加速查询用户对特定宝箱内容的保底计数 |
 | item_chest_open_logs | user_id, open_time | 复合索引 | 加速查询用户的宝箱开启历史 |
 | item_chest_open_logs | chest_id | 普通索引 | 加速查询特定宝箱的开启记录 |

+ 0 - 113
app/Module/GameItems/Dtos/ItemChestOpenCostDto.php

@@ -1,113 +0,0 @@
-<?php
-
-namespace App\Module\GameItems\Dtos;
-
-use App\Module\GameItems\Enums\CHEST_COST_TYPE;
-use App\Module\GameItems\Models\ItemChestOpenCost;
-use UCore\Dto\BaseDto;
-
-/**
- * 宝箱开启消耗配置DTO
- */
-class ItemChestOpenCostDto extends BaseDto
-{
-    /**
-     * 记录ID
-     *
-     * @var int|null
-     */
-    public ?int $id = null;
-
-    /**
-     * 宝箱ID
-     *
-     * @var int
-     */
-    public int $chestId;
-
-    /**
-     * 消耗类型
-     *
-     * @var int
-     */
-    public int $costType;
-
-    /**
-     * 消耗的物品/货币/资源ID
-     *
-     * @var int
-     */
-    public int $costId;
-
-    /**
-     * 消耗数量
-     *
-     * @var int
-     */
-    public int $costQuantity;
-
-    /**
-     * 是否激活
-     *
-     * @var bool
-     */
-    public bool $isActive;
-
-    /**
-     * 消耗类型文本描述
-     *
-     * @var string|null
-     */
-    public ?string $costTypeText = null;
-
-    /**
-     * 消耗物品名称(如果消耗类型为物品)
-     *
-     * @var string|null
-     */
-    public ?string $costItemName = null;
-
-    /**
-     * 从模型创建DTO
-     *
-     * @param ItemChestOpenCost $model
-     * @param bool $withRelations 是否加载关联数据
-     * @return self
-     */
-    public static function fromModel($model, bool $withRelations = false): self
-    {
-        $dto = new self();
-        $dto->id = $model->id;
-        $dto->chestId = $model->chest_id;
-        $dto->costType = $model->cost_type;
-        $dto->costId = $model->cost_id;
-        $dto->costQuantity = $model->cost_quantity;
-        $dto->isActive = (bool)$model->is_active;
-        $dto->costTypeText = $model->cost_type_text;
-
-        if ($withRelations && $model->cost_type == CHEST_COST_TYPE::ITEM->value && $model->relationLoaded('costItem')) {
-            $dto->costItemName = $model->costItem->name ?? null;
-        }
-
-        return $dto;
-    }
-
-    /**
-     * 转换为数组
-     *
-     * @return array
-     */
-    public function toArray(): array
-    {
-        return [
-            'id' => $this->id,
-            'chest_id' => $this->chestId,
-            'cost_type' => $this->costType,
-            'cost_id' => $this->costId,
-            'cost_quantity' => $this->costQuantity,
-            'is_active' => $this->isActive,
-            'cost_type_text' => $this->costTypeText,
-            'cost_item_name' => $this->costItemName,
-        ];
-    }
-}

+ 0 - 62
app/Module/GameItems/Logics/ChestContent.php

@@ -1,62 +0,0 @@
-<?php
-
-namespace App\Module\GameItems\Logics;
-
-use App\Module\GameItems\Models\ItemChestContent;
-
-/**
- * 宝箱内容逻辑类
- */
-class ChestContent
-{
-    /**
-     * 判断是否为物品组内容
-     *
-     * @param ItemChestContent $content 宝箱内容
-     * @return bool
-     */
-    public function isGroupContent(ItemChestContent $content): bool
-    {
-        return !empty($content->group_id);
-    }
-
-    /**
-     * 获取随机数量
-     *
-     * @param ItemChestContent $content 宝箱内容
-     * @return int
-     */
-    public function getRandomQuantity(ItemChestContent $content): int
-    {
-        if ($content->min_quantity == $content->max_quantity) {
-            return $content->min_quantity;
-        }
-
-        return mt_rand($content->min_quantity, $content->max_quantity);
-    }
-
-    /**
-     * 计算调整后的权重(考虑保底机制)
-     *
-     * @param ItemChestContent $content 宝箱内容
-     * @param int $currentPityCount 当前保底计数
-     * @return float
-     */
-    public function getAdjustedWeight(ItemChestContent $content, int $currentPityCount = 0): float
-    {
-        if (empty($content->pity_count) || $currentPityCount <= 0) {
-            return $content->weight;
-        }
-
-        // 如果达到保底次数,返回极大值确保必定获得
-        if ($currentPityCount >= $content->pity_count) {
-            return 999999.999;
-        }
-
-        // 计算权重调整因子
-        $pityFactor = ($currentPityCount / $content->pity_count) * $content->pity_weight_factor;
-
-        // 返回调整后的权重
-        return $content->weight * (1 + $pityFactor);
-    }
-}

+ 0 - 274
app/Module/GameItems/Logics/ChestOpenCostLogic.php

@@ -1,274 +0,0 @@
-<?php
-
-namespace App\Module\GameItems\Logics;
-
-use App\Module\GameItems\Dtos\ItemChestOpenCostDto;
-use App\Module\GameItems\Enums\CHEST_COST_TYPE;
-use App\Module\GameItems\Models\ItemChestOpenCost;
-use App\Module\GameItems\Repositorys\ItemChestOpenCostRepository;
-use App\Module\User\Services\UserCurrencyService;
-use Illuminate\Support\Facades\Log;
-
-/**
- * 宝箱开启消耗逻辑类
- */
-class ChestOpenCostLogic
-{
-    /**
-     * @var ItemChestOpenCostRepository
-     */
-    protected $costRepository;
-
-    /**
-     * @var ItemLogic
-     */
-    protected $itemLogic;
-
-    /**
-     * 构造函数
-     *
-     * @param ItemChestOpenCostRepository $costRepository
-     * @param ItemLogic $itemLogic
-     */
-    public function __construct(
-        ItemChestOpenCostRepository $costRepository,
-        ItemLogic $itemLogic
-    ) {
-        $this->costRepository = $costRepository;
-        $this->itemLogic = $itemLogic;
-    }
-
-    /**
-     * 获取宝箱的所有激活消耗配置
-     *
-     * @param int $chestId 宝箱ID
-     * @return ItemChestOpenCostDto[]
-     */
-    public function getActiveChestCosts(int $chestId): array
-    {
-        $costs = $this->costRepository->getActiveByChestId($chestId);
-        $result = [];
-
-        foreach ($costs as $cost) {
-            $result[] = ItemChestOpenCostDto::fromModel($cost, true);
-        }
-
-        return $result;
-    }
-
-    /**
-     * 验证用户是否有足够的资源支付宝箱开启消耗
-     *
-     * @param int $userId 用户ID
-     * @param int $chestId 宝箱ID
-     * @param int $quantity 开启数量
-     * @return array [bool $isValid, string $message, array $costs]
-     */
-    public function validateChestOpenCosts(int $userId, int $chestId, int $quantity = 1): array
-    {
-        $costs = $this->costRepository->getActiveByChestId($chestId);
-
-        if ($costs->isEmpty()) {
-            return [true, '无需额外消耗', []];
-        }
-
-        $costDetails = [];
-
-        foreach ($costs as $cost) {
-            $totalQuantity = $cost->cost_quantity * $quantity;
-            $costDetails[] = [
-                'type' => $cost->cost_type,
-                'id' => $cost->cost_id,
-                'quantity' => $totalQuantity,
-                'model' => $cost
-            ];
-
-            // 验证用户是否有足够的资源
-            switch ($cost->cost_type) {
-                case CHEST_COST_TYPE::ITEM->value:
-                    // 验证物品数量
-                    $userItem = $this->itemLogic->getUserItem($userId, $cost->cost_id);
-                    if (!$userItem || $userItem->quantity < $totalQuantity) {
-                        return [
-                            false,
-                            "物品不足,需要 {$totalQuantity} 个 " . ($cost->costItem->name ?? "ID:{$cost->cost_id}"),
-                            $costDetails
-                        ];
-                    }
-                    break;
-
-                case CHEST_COST_TYPE::CURRENCY->value:
-                    // 验证货币数量
-                    $userCurrency = UserCurrencyService::getUserCurrency($userId, $cost->cost_id);
-                    if ($userCurrency < $totalQuantity) {
-                        return [
-                            false,
-                            "货币不足,需要 {$totalQuantity} 个 ID:{$cost->cost_id}",
-                            $costDetails
-                        ];
-                    }
-                    break;
-
-                case CHEST_COST_TYPE::OTHER_RESOURCE->value:
-                    // 验证其他资源,根据实际情况实现
-                    // 这里仅作为示例,实际实现可能需要调用其他模块的服务
-                    $hasEnoughResource = true; // 假设有足够资源
-                    if (!$hasEnoughResource) {
-                        return [
-                            false,
-                            "资源不足,需要 {$totalQuantity} 个 ID:{$cost->cost_id}",
-                            $costDetails
-                        ];
-                    }
-                    break;
-            }
-        }
-
-        return [true, '验证通过', $costDetails];
-    }
-
-    /**
-     * 扣除宝箱开启所需的消耗资源
-     *
-     * @param int $userId 用户ID
-     * @param array $costDetails 消耗详情数组
-     * @param string $reason 消耗原因
-     * @return bool 是否成功扣除
-     */
-    public function deductChestOpenCosts(int $userId, array $costDetails, string $reason = '开启宝箱'): bool
-    {
-        // 检查事务是否已开启
-        \UCore\Db\Helper::check_tr();
-
-        try {
-
-            foreach ($costDetails as $detail) {
-                switch ($detail['type']) {
-                    case CHEST_COST_TYPE::ITEM->value:
-                        // 扣除物品
-                        $result = $this->itemLogic->consumeUserItem(
-                            $userId,
-                            $detail['id'],
-                            $detail['quantity'],
-                            $reason
-                        );
-
-                        if (!$result) {
-                            throw new \Exception("扣除物品失败: ID {$detail['id']}");
-                        }
-                        break;
-
-                    case CHEST_COST_TYPE::CURRENCY->value:
-                        // 扣除货币
-                        $result = UserCurrencyService::deductCurrency(
-                            $userId,
-                            $detail['id'],
-                            $detail['quantity'],
-                            $reason
-                        );
-
-                        if (!$result) {
-                            throw new \Exception("扣除货币失败: ID {$detail['id']}");
-                        }
-                        break;
-
-                    case CHEST_COST_TYPE::OTHER_RESOURCE->value:
-                        // 扣除其他资源,根据实际情况实现
-                        // 这里仅作为示例,实际实现可能需要调用其他模块的服务
-                        $deductSuccess = true; // 假设扣除成功
-
-                        if (!$deductSuccess) {
-                            throw new \Exception("扣除资源失败: ID {$detail['id']}");
-                        }
-                        break;
-                }
-            }
-
-            return true;
-        } catch (\Exception $e) {
-            Log::error('扣除宝箱开启消耗失败: ' . $e->getMessage(), [
-                'user_id' => $userId,
-                'cost_details' => $costDetails,
-                'exception' => $e
-            ]);
-            return false;
-        }
-    }
-
-    /**
-     * 创建宝箱开启消耗配置
-     *
-     * @param ItemChestOpenCostDto $dto
-     * @return ItemChestOpenCost|null
-     */
-    public function createChestOpenCost(ItemChestOpenCostDto $dto): ?ItemChestOpenCost
-    {
-        try {
-            return $this->costRepository->create([
-                'chest_id' => $dto->chestId,
-                'cost_type' => $dto->costType,
-                'cost_id' => $dto->costId,
-                'cost_quantity' => $dto->costQuantity,
-                'is_active' => $dto->isActive,
-            ]);
-        } catch (\Exception $e) {
-            Log::error('创建宝箱开启消耗配置失败: ' . $e->getMessage(), [
-                'dto' => $dto->toArray(),
-                'exception' => $e
-            ]);
-            return null;
-        }
-    }
-
-    /**
-     * 更新宝箱开启消耗配置
-     *
-     * @param int $id
-     * @param ItemChestOpenCostDto $dto
-     * @return bool
-     */
-    public function updateChestOpenCost(int $id, ItemChestOpenCostDto $dto): bool
-    {
-        try {
-            $cost = $this->costRepository->find($id);
-
-            if (!$cost) {
-                return false;
-            }
-
-            return $this->costRepository->update($id, [
-                'chest_id' => $dto->chestId,
-                'cost_type' => $dto->costType,
-                'cost_id' => $dto->costId,
-                'cost_quantity' => $dto->costQuantity,
-                'is_active' => $dto->isActive,
-            ]);
-        } catch (\Exception $e) {
-            Log::error('更新宝箱开启消耗配置失败: ' . $e->getMessage(), [
-                'id' => $id,
-                'dto' => $dto->toArray(),
-                'exception' => $e
-            ]);
-            return false;
-        }
-    }
-
-    /**
-     * 删除宝箱开启消耗配置
-     *
-     * @param int $id
-     * @return bool
-     */
-    public function deleteChestOpenCost(int $id): bool
-    {
-        try {
-            return $this->costRepository->delete($id);
-        } catch (\Exception $e) {
-            Log::error('删除宝箱开启消耗配置失败: ' . $e->getMessage(), [
-                'id' => $id,
-                'exception' => $e
-            ]);
-            return false;
-        }
-    }
-}

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

@@ -116,25 +116,7 @@ class Item extends ModelCore
         return $this->hasMany(ItemUser::class, 'item_id');
     }
 
-    /**
-     * 获取宝箱内容配置
-     *
-     * @return HasMany
-     */
-    public function chest_contents(): HasMany
-    {
-        return $this->hasMany(ItemChestContent::class, 'chest_id', 'id');
-    }
 
-    /**
-     * 宝箱开启消耗配置
-     *
-     * @return HasMany
-     */
-    public function chest_costs(): HasMany
-    {
-        return $this->hasMany(ItemChestOpenCost::class, 'chest_id', 'id');
-    }
 
     /**
      * 宝箱配置(新系统)

+ 0 - 107
app/Module/GameItems/Models/ItemChestContent.php

@@ -1,107 +0,0 @@
-<?php
-
-namespace App\Module\GameItems\Models;
-
-use Illuminate\Database\Eloquent\Relations\BelongsTo;
-use Illuminate\Database\Eloquent\Relations\HasMany;
-use UCore\ModelCore;
-
-/**
- * 宝箱内容配置
- *
- * field start 
- * @property  int  $id  记录ID,主键
- * @property  int  $chest_id  宝箱物品ID,外键关联kku_item_items表
- * @property  int  $item_id  可能获得的物品ID,外键关联kku_item_items表(与group_id二选一)
- * @property  int  $group_id  物品组ID,外键关联kku_item_groups表(与item_id二选一)
- * @property  int  $min_quantity  最小数量
- * @property  int  $max_quantity  最大数量
- * @property  float  $weight  权重,决定获取概率
- * @property  bool  $allow_duplicate  是否允许在同一宝箱中重复掉落(0:不允许, 1:允许)
- * @property  int  $pity_count  保底次数,当玩家连续未获得该内容达到次数后必定获得(0表示不启用保底)
- * @property  float  $pity_weight_factor  保底权重因子,用于递增概率计算(默认1.0)
- * @property  \Carbon\Carbon  $created_at  创建时间
- * @property  \Carbon\Carbon  $updated_at  更新时间
- * field end
- */
-class ItemChestContent extends ModelCore
-{
-    /**
-     * 与模型关联的表名
-     *
-     * @var string
-     */
-    protected $table = 'item_chest_contents';
-
-    // attrlist start 
-    protected $fillable = [
-        'id',
-        'chest_id',
-        'item_id',
-        'group_id',
-        'min_quantity',
-        'max_quantity',
-        'weight',
-        'allow_duplicate',
-        'pity_count',
-        'pity_weight_factor',
-    ];
-    // attrlist end
-
-    /**
-     * 应该被转换为原生类型的属性
-     *
-     * @var array
-     */
-    protected $casts = [
-        'weight' => 'float',
-        'min_quantity' => 'integer',
-        'max_quantity' => 'integer',
-        'allow_duplicate' => 'boolean',
-        'pity_count' => 'integer',
-        'pity_weight_factor' => 'float',
-    ];
-
-
-    /**
-     * 获取关联的宝箱物品
-     *
-     * @return BelongsTo
-     */
-    public function chest(): BelongsTo
-    {
-        return $this->belongsTo(Item::class, 'chest_id');
-    }
-
-    /**
-     * 获取关联的物品(如果有)
-     *
-     * @return BelongsTo
-     */
-    public function item(): BelongsTo
-    {
-        return $this->belongsTo(Item::class, 'item_id');
-    }
-
-    /**
-     * 获取关联的物品组(如果有)
-     *
-     * @return BelongsTo
-     */
-    public function group(): BelongsTo
-    {
-        return $this->belongsTo(ItemGroup::class, 'group_id');
-    }
-
-    /**
-     * 获取用户对该宝箱内容的保底计数
-     *
-     * @return HasMany
-     */
-    public function pityTimes(): HasMany
-    {
-        return $this->hasMany(ItemPityTime::class, 'chest_content_id');
-    }
-
-
-}

+ 0 - 89
app/Module/GameItems/Models/ItemChestOpenCost.php

@@ -1,89 +0,0 @@
-<?php
-
-namespace App\Module\GameItems\Models;
-
-use App\Module\GameItems\Enums\CHEST_COST_TYPE;
-use Illuminate\Database\Eloquent\Relations\BelongsTo;
-use UCore\ModelCore;
-
-/**
- * 宝箱开启消耗配置
- *
- * field start 
- * @property  int  $id  记录ID,主键
- * @property  int  $chest_id  宝箱ID,外键关联item_items表
- * @property  int  $cost_type  消耗类型(1:物品, 2:货币, 3:其他资源)
- * @property  int  $cost_id  消耗的物品/货币/资源ID
- * @property  int  $cost_quantity  消耗数量
- * @property  bool  $is_active  是否激活(0:否, 1:是)
- * @property  \Carbon\Carbon  $created_at  创建时间
- * @property  \Carbon\Carbon  $updated_at  更新时间
- * field end
- */
-class ItemChestOpenCost extends ModelCore
-{
-
-    /**
-     * 与模型关联的表名
-     *
-     * @var string
-     */
-    protected $table = 'item_chest_open_costs';
-
-    // attrlist start 
-    protected $fillable = [
-        'id',
-        'chest_id',
-        'cost_type',
-        'cost_id',
-        'cost_quantity',
-        'is_active',
-    ];
-    // attrlist end
-
-    /**
-     * 应该被转换为原生类型的属性
-     *
-     * @var array
-     */
-    protected $casts = [
-        'cost_type'     => 'integer',
-        'cost_id'       => 'integer',
-        'cost_quantity' => 'integer',
-        'is_active'     => 'boolean',
-    ];
-
-    /**
-     * 获取关联的宝箱物品
-     *
-     * @return BelongsTo
-     */
-    public function chest(): BelongsTo
-    {
-        return $this->belongsTo(Item::class, 'chest_id', 'id');
-    }
-
-    /**
-     * 获取关联的消耗物品(如果消耗类型为物品)
-     *
-     * @return BelongsTo|null
-     */
-    public function costItem(): ?BelongsTo
-    {
-
-        return $this->belongsTo(Item::class, 'cost_id');
-
-
-    }
-
-    /**
-     * 获取消耗类型的文本描述
-     *
-     * @return string
-     */
-    public function getCostTypeTextAttribute(): string
-    {
-        return CHEST_COST_TYPE::getAll()[$this->cost_type] ?? '未知';
-    }
-
-}

+ 1 - 9
app/Module/GameItems/Models/ItemChestOpenLog.php

@@ -88,13 +88,5 @@ class ItemChestOpenLog extends ModelCore
         return $this->belongsTo(Item::class, 'chest_id');
     }
 
-    /**
-     * 获取触发保底的宝箱内容(如果有)
-     *
-     * @return BelongsTo
-     */
-    public function pityContent(): BelongsTo
-    {
-        return $this->belongsTo(ItemChestContent::class, 'pity_content_id');
-    }
+
 }

+ 1 - 9
app/Module/GameItems/Models/ItemPityTime.php

@@ -60,15 +60,7 @@ class ItemPityTime extends ModelCore
         return $this->belongsTo(Item::class, 'chest_id');
     }
 
-    /**
-     * 获取关联的宝箱内容
-     *
-     * @return BelongsTo
-     */
-    public function chestContent(): BelongsTo
-    {
-        return $this->belongsTo(ItemChestContent::class, 'chest_content_id');
-    }
+
 
 
 }

+ 13 - 57
app/Module/GameItems/README.md

@@ -103,7 +103,6 @@ Services
 
 Logics
   ├── Item - 物品逻辑
-  ├── ChestContent - 宝箱内容逻辑
   ├── PityTime - 保底计数逻辑
   ├── ItemInstance - 物品实例逻辑
   ├── UserRecipe - 用户配方逻辑
@@ -118,7 +117,7 @@ Models
   ├── ItemUser - 用户物品关联
   ├── ItemGroup - 物品组
   ├── ItemGroupItem - 物品组内容
-  ├── ItemChestContent - 宝箱内容配置
+  ├── ItemChestConfig - 宝箱配置(新系统)
   ├── ItemPityTime - 宝箱保底计数
   ├── ItemChestOpenLog - 宝箱开启记录
   ├── ItemRecipe - 物品合成配方
@@ -153,7 +152,7 @@ Models
 | item_users | 用户物品关联 | user_id, item_id, instance_id, quantity |
 | item_groups | 物品组定义 | id, name, code |
 | item_group_items | 物品组内容 | group_id, item_id, weight |
-| item_chest_contents | 宝箱内容配置 | chest_id, item_id/group_id, weight |
+| item_chest_configs | 宝箱配置(新系统) | item_id, consume_group_id, reward_group_id, condition_group_id |
 | item_pity_times | 用户宝箱保底计数 | user_id, chest_id, chest_content_id, current_count |
 | item_chest_open_logs | 宝箱开启记录 | user_id, chest_id, result_items, pity_triggered |
 | item_recipes | 合成配方定义 | id, result_item_id, success_rate |
@@ -520,30 +519,26 @@ class Item extends ModelCore
 }
 ```
 
-#### 5.1.2 ItemChestContent
+#### 5.1.2 ItemChestConfig
 
-宝箱内容配置模型,定义宝箱可能掉落的物品
+宝箱配置模型(新系统),使用消耗组/奖励组/条件组来定义宝箱的开启消耗和产出
 
 ```php
 /**
- * 宝箱内容配置
+ * 宝箱配置(新系统)
  *
  * field start
  * @property   int  $id  记录ID,主键
- * @property   int  $chest_id  宝箱物品ID,外键关联kku_item_items表
- * @property   int  $item_id  可能获得的物品ID,外键关联kku_item_items表(与group_id二选一)
- * @property   int  $group_id  物品组ID,外键关联kku_item_groups表(与item_id二选一)
- * @property   int  $min_quantity  最小数量
- * @property   int  $max_quantity  最大数量
- * @property   float  $weight  权重,决定获取概率
- * @property   int  $allow_duplicate  是否允许在同一宝箱中重复掉落(0:不允许, 1:允许)
- * @property   int  $pity_count  保底次数,当玩家连续未获得该内容达到次数后必定获得(0表示不启用保底)
- * @property   float  $pity_weight_factor  保底权重因子,用于递增概率计算(默认1.0)
+ * @property   int  $item_id  宝箱物品ID,外键关联kku_item_items表
+ * @property   int  $consume_group_id  消耗组ID,外键关联kku_game_consume_groups表(可为空)
+ * @property   int  $reward_group_id  奖励组ID,外键关联kku_game_reward_groups表
+ * @property   int  $condition_group_id  条件组ID,外键关联kku_game_condition_groups表(可为空)
+ * @property   bool  $is_active  是否激活(0:否, 1:是)
  * @property   \Carbon\Carbon  $created_at  创建时间
  * @property   \Carbon\Carbon  $updated_at  更新时间
  * field end
  */
-class ItemChestContent extends ModelCore
+class ItemChestConfig extends ModelCore
 {
     // 模型实现...
 }
@@ -582,10 +577,8 @@ class ItemUser extends ModelCore
 - **Item** 与 **ItemInstance** 是一对多关系
 - **Item** 与 **ItemUser** 是一对多关系
 - **ItemInstance** 与 **ItemUser** 是一对多关系
-- **Item** 与 **ItemChestContent** 是一对多关系(作为宝箱)
-- **Item** 与 **ItemChestContent** 是一对多关系(作为内容)
+- **Item** 与 **ItemChestConfig** 是一对一关系(作为宝箱)
 - **ItemGroup** 与 **ItemGroupItem** 是一对多关系
-- **ItemGroup** 与 **ItemChestContent** 是一对多关系
 - **ItemRecipe** 与 **ItemRecipeMaterial** 是一对多关系
 - **ItemRecipe** 与 **ItemUserRecipe** 是一对多关系
 
@@ -623,44 +616,7 @@ class Item
 }
 ```
 
-#### 6.1.2 ChestContent
-
-宝箱内容逻辑类,处理宝箱内容相关的业务逻辑。
-
-```php
-/**
- * 宝箱内容逻辑类
- */
-class ChestContent
-{
-    /**
-     * 判断是否为物品组内容
-     *
-     * @param ItemChestContent $content 宝箱内容
-     * @return bool
-     */
-    public function isGroupContent(ItemChestContent $content): bool;
-
-    /**
-     * 获取随机数量
-     *
-     * @param ItemChestContent $content 宝箱内容
-     * @return int
-     */
-    public function getRandomQuantity(ItemChestContent $content): int;
-
-    /**
-     * 计算调整后的权重(考虑保底机制)
-     *
-     * @param ItemChestContent $content 宝箱内容
-     * @param int $currentPityCount 当前保底计数
-     * @return float
-     */
-    public function getAdjustedWeight(ItemChestContent $content, int $currentPityCount = 0): float;
-}
-```
-
-#### 6.1.3 PityTime
+#### 6.1.2 PityTime
 
 保底计数逻辑类,处理宝箱保底机制相关的业务逻辑。
 

+ 0 - 17
app/Module/GameItems/Repositorys/ItemChestContentRepository.php

@@ -1,17 +0,0 @@
-<?php
-
-namespace App\Module\GameItems\Repositorys;
-
-use App\Module\GameItems\Models\ItemChestContent;
-use Dcat\Admin\Repositories\EloquentRepository;
-
-/**
- * 宝箱内容数据仓库类
- *
- * 提供宝箱内容数据的访问和操作功能。
- * 该类是宝箱内容模块与后台管理系统的桥梁,用于处理宝箱内容配置数据的CRUD操作。
- */
-class ItemChestContentRepository extends EloquentRepository
-{
-    protected $eloquentClass = ItemChestContent::class;
-}

+ 0 - 68
app/Module/GameItems/Repositorys/ItemChestOpenCostRepository.php

@@ -1,68 +0,0 @@
-<?php
-
-namespace App\Module\GameItems\Repositorys;
-
-use App\Module\GameItems\Models\ItemChestOpenCost;
-use UCore\DcatAdmin\Repository\EloquentRepository;
-
-
-/**
- * 宝箱开启消耗配置数据仓库
- */
-class ItemChestOpenCostRepository extends EloquentRepository
-{
-    /**
-     * 关联的Eloquent模型类
-     *
-     * @var string
-     */
-    protected $eloquentClass = ItemChestOpenCost::class;
-
-    /**
-     * 获取指定宝箱的所有激活消耗配置
-     *
-     * @param int $chestId 宝箱ID
-     * @return \Illuminate\Database\Eloquent\Collection
-     */
-    public function getActiveByChestId(int $chestId)
-    {
-        return $this->eloquentClass::where('chest_id', $chestId)
-            ->where('is_active', true)
-            ->get();
-    }
-
-    /**
-     * 批量更新消耗配置的激活状态
-     *
-     * @param array $ids 消耗配置ID数组
-     * @param bool $isActive 是否激活
-     * @return int 更新的记录数
-     */
-    public function batchUpdateActiveStatus(array $ids, bool $isActive): int
-    {
-        return $this->eloquentClass::whereIn('id', $ids)
-            ->update(['is_active' => $isActive]);
-    }
-
-    /**
-     * 复制消耗配置到另一个宝箱
-     *
-     * @param int $sourceChestId 源宝箱ID
-     * @param int $targetChestId 目标宝箱ID
-     * @return int 复制的记录数
-     */
-    public function copyToAnotherChest(int $sourceChestId, int $targetChestId): int
-    {
-        $sourceCosts = $this->eloquentClass::where('chest_id', $sourceChestId)->get();
-        $count = 0;
-
-        foreach ($sourceCosts as $cost) {
-            $newCost = $cost->replicate();
-            $newCost->chest_id = $targetChestId;
-            $newCost->save();
-            $count++;
-        }
-
-        return $count;
-    }
-}

+ 0 - 61
app/Module/GameItems/Validators/ChestOpenCostValidator.php

@@ -1,61 +0,0 @@
-<?php
-
-namespace App\Module\GameItems\Validators;
-
-use App\Module\GameItems\Logics\ChestOpenCostLogic;
-use App\Module\GameItems\Repositorys\ItemChestOpenCostRepository;
-use App\Module\GameItems\Logics\Item as ItemLogic;
-use UCore\Validator;
-
-/**
- * 宝箱开启消耗验证器
- * 
- * 验证用户是否有足够的资源开启宝箱
- */
-class ChestOpenCostValidator extends Validator
-{
-    /**
-     * 验证宝箱开启消耗
-     *
-     * @param mixed $value 物品ID
-     * @param array $data 包含用户ID和数量的数组
-     * @return bool 验证是否通过
-     */
-    public function validate(mixed $value, array $data): bool
-    {
-        $itemId = (int)$value;
-        
-        // 从 args 获取参数键名
-        $userIdKey = $this->args[0] ?? 'user_id';
-        $quantityKey = $this->args[1] ?? 'quantity';
-
-        $userId = $data[$userIdKey] ?? null;
-        $quantity = $data[$quantityKey] ?? 1;
-
-        if (!$userId) {
-            $this->addError('用户ID不能为空');
-            return false;
-        }
-
-        try {
-            // 创建消耗逻辑实例
-            $chestOpenCostLogic = new ChestOpenCostLogic(
-                app(ItemChestOpenCostRepository::class),
-                new ItemLogic()
-            );
-
-            // 验证宝箱开启消耗
-            list($isValid, $message, $costDetails) = $chestOpenCostLogic->validateChestOpenCosts($userId, $itemId, $quantity);
-            
-            if (!$isValid) {
-                $this->addError($message);
-                return false;
-            }
-
-            return true;
-        } catch (\Exception $e) {
-            $this->addError('验证宝箱开启消耗时发生错误: ' . $e->getMessage());
-            return false;
-        }
-    }
-}