Prechádzať zdrojové kódy

feat(consume): 实现 FUND_CONFIGS 多账户种类消耗- 在 CONSUME_TYPE 枚举中添加 FUND_CONFIGS 类型显示
- 实现 checkFundConfigsConsume 和 executeFundConfigsConsume 方法
- 支持按

notfff 7 mesiacov pred
rodič
commit
73b6d7434d

+ 171 - 0
AiWork/2025年06月/06日1102-消耗组进行功能扩展.md

@@ -0,0 +1,171 @@
+# 消耗组进行功能扩展
+
+**任务时间**: 2025年06月06日 11:02:00  
+**完成时间**: 2025年06月06日 11:45:00  
+**任务类型**: 功能扩展  
+
+## 任务概述
+
+扩展消耗组系统功能,实现 `FUND_CONFIGS` 多账户种类消耗类型,支持按配置顺序依次从多个账户种类扣除资金。
+
+## 任务背景
+
+用户选中了 `FUND_CONFIGS` 类型的代码,该类型已在枚举中定义但未完全实现。需要完善相关功能,使其能够支持多账户种类的依次消耗逻辑。
+
+## 实现内容
+
+### 1. 完善 CONSUME_TYPE 枚举
+
+**文件**: `app/Module/Game/Enums/CONSUME_TYPE.php`
+
+- 在 `getAll()` 方法中添加 `FUND_CONFIGS` 类型显示
+- 确保枚举类型的完整性
+
+### 2. 扩展 ConsumeService 服务
+
+**文件**: `app/Module/Game/Services/ConsumeService.php`
+
+**新增方法**:
+- `checkFundConfigsConsume()`: 检查多账户种类消耗条件
+- `executeFundConfigsConsume()`: 执行多账户种类消耗
+- `getFundConfigIds()`: 获取消耗项的账户种类ID列表
+
+**功能特点**:
+- 支持从 `target_id` 和 `extra_data.fund_config_ids` 获取账户列表
+- 按配置顺序依次消耗,优先从主账户扣除
+- 支持倍数参数,用于执行几倍消耗
+- 完整的事务处理,确保数据一致性
+- 详细的错误处理和日志记录
+
+**修复问题**:
+- 修复 `executeConsume()` 方法的事务处理问题
+- 移除未使用的导入 `UCore\Db\Helper`
+- 完善错误处理逻辑
+
+### 3. 更新模型支持
+
+**文件**: `app/Module/Game/Models/GameConsumeItem.php`
+
+- 扩展 `getTargetName()` 方法支持 `FUND_CONFIGS` 类型
+- 更新 `toDeductObject()` 方法支持多账户种类的 protobuf 对象转换
+- 支持从 `extra_data` 中解析多个账户种类ID
+
+**文件**: `app/Module/Game/Models/GameConsumeGroup.php`
+
+- 更新 `getTargetName()` 方法支持 `FUND_CONFIGS` 类型显示
+- 直接使用 `GameConsumeItem` 模型的方法避免重复代码
+
+### 4. 更新测试命令
+
+**文件**: `app/Module/Game/Commands/TestConsumeCommand.php`
+
+- 修复对 `Res` 对象和数组结果的处理
+- 支持更好的结果显示和错误处理
+
+### 5. 完善文档
+
+**文件**: `app/Module/Game/Docs/消耗组系统.md`
+
+**新增内容**:
+- `FUND_CONFIGS` 类型的详细说明
+- 多账户种类消耗的工作原理
+- 配置示例和注意事项
+- 更新数据库结构说明
+
+## 技术实现细节
+
+### 多账户消耗逻辑
+
+1. **账户ID获取**:
+   - 主账户: `target_id` 字段
+   - 额外账户: `extra_data.fund_config_ids` 数组
+
+2. **消耗顺序**:
+   - 优先从主账户(`target_id`)扣除
+   - 主账户不足时,依次从额外账户扣除
+   - 按配置顺序进行,确保可预测性
+
+3. **余额检查**:
+   - 计算所有账户的总余额
+   - 确保总余额满足消耗需求
+   - 支持倍数参数的余额计算
+
+4. **事务处理**:
+   - 使用数据库事务确保原子性
+   - 任何步骤失败都会回滚所有操作
+   - 完整的错误处理和日志记录
+
+### 配置示例
+
+```json
+{
+  "target_id": 1,
+  "quantity": 1000,
+  "extra_data": {
+    "fund_config_ids": [2, 3, 4]
+  }
+}
+```
+
+此配置表示:消耗1000单位资金,优先从账户种类1扣除,不足时依次从账户种类2、3、4扣除。
+
+## 测试验证
+
+### 测试用例1: 单账户消耗
+- 创建消耗组 `test_fund_configs`
+- 消耗100金币,主账户余额充足
+- 验证: 成功扣除100金币
+
+### 测试用例2: 多账户依次消耗
+- 创建消耗组 `test_fund_configs_insufficient`
+- 消耗10000000金币,需要从多个账户扣除
+- 验证: 
+  - 金币账户从9999912减少到0(扣除9999912)
+  - 钻石账户从93906减少到93818(扣除88)
+  - 总计扣除10000000,符合预期
+
+### 测试命令
+```bash
+# 检查消耗条件
+php artisan game:test-consume 10001 test_fund_configs --check
+
+# 执行消耗
+php artisan game:test-consume 10001 test_fund_configs
+```
+
+## 文件变更清单
+
+1. `app/Module/Game/Enums/CONSUME_TYPE.php` - 添加FUND_CONFIGS类型显示
+2. `app/Module/Game/Services/ConsumeService.php` - 实现多账户消耗逻辑
+3. `app/Module/Game/Models/GameConsumeItem.php` - 支持FUND_CONFIGS类型
+4. `app/Module/Game/Models/GameConsumeGroup.php` - 支持FUND_CONFIGS显示
+5. `app/Module/Game/Commands/TestConsumeCommand.php` - 修复结果处理
+6. `app/Module/Game/Docs/消耗组系统.md` - 更新文档说明
+
+## 提交信息
+
+```
+扩展消耗组功能:实现FUND_CONFIGS多账户种类消耗
+
+- 在CONSUME_TYPE枚举中添加FUND_CONFIGS类型到getAll()方法
+- 在ConsumeService中实现checkFundConfigsConsume()和executeFundConfigsConsume()方法
+- 支持按配置顺序依次从多个账户种类扣除资金
+- 更新GameConsumeItem模型支持FUND_CONFIGS类型的目标名称显示
+- 更新GameConsumeGroup模型支持FUND_CONFIGS类型的格式化显示
+- 完善toDeductObject()方法支持多账户种类的protobuf对象转换
+- 修复executeConsume()方法的事务处理问题
+- 更新消耗组系统文档,添加FUND_CONFIGS类型详细说明
+- 更新TestConsumeCommand支持Res对象和数组结果的处理
+- 通过测试验证功能正常:单账户消耗和多账户依次消耗均工作正常
+```
+
+## 任务状态
+
+✅ **已完成** - 功能已实现并通过测试验证,代码已提交并推送到远程仓库。
+
+## 后续建议
+
+1. **后台管理界面优化**: 可以考虑在后台管理中添加多账户种类选择的UI组件
+2. **性能优化**: 对于大量账户的情况,可以考虑批量查询优化
+3. **监控和日志**: 可以添加更详细的消耗日志,便于问题排查
+4. **文档完善**: 可以添加更多使用场景的示例

+ 6 - 4
AiWork/WORK.md

@@ -17,6 +17,11 @@ shop_items 的 $max_buy 确认被替代后移除,使用mcp执行sql
 
 ## 已完成任务(保留最新的10条,多余的删除)
 
+- [x] 2025-06-06 11:02 - 消耗组进行功能扩展
+  - 任务记录: `AiWork/2025年06月/06日1102-消耗组进行功能扩展.md`
+  - 完成时间: 2025-06-06 11:45
+  - 描述: 扩展消耗组系统功能,实现FUND_CONFIGS多账户种类消耗类型,支持按配置顺序依次从多个账户种类扣除资金,完善相关模型、服务、文档和测试
+
 - [x] 2025-06-05 19:44 - ConsumeService增加倍数参数支持
   - 任务记录: `AiWork/2025年06月/05日1944-ConsumeService增加倍数参数支持.md`
   - 完成时间: 2025-06-05 19:44
@@ -67,10 +72,7 @@ shop_items 的 $max_buy 确认被替代后移除,使用mcp执行sql
   - 完成时间: 2025-06-04 10:35
   - 描述: 完成宝箱系统后台菜单的重新配置,包括新增宝箱配置管理和奖励组保底计数菜单,隐藏废弃菜单,创建完整的后台控制器和仓库,修复路由命名规范,清理旧系统残留文件
 
-- [x] 2025-06-04 10:14 - 宝箱保底机制实现
-  - 任务记录: `AiWork/2025年06月/041014-宝箱保底机制实现.md`
-  - 完成时间: 2025-06-04 10:14
-  - 描述: 为新的宝箱系统实现完整的保底机制,包括保底计数表、保底服务层、权重调整算法、系统集成等,支持多种保底策略和灵活配置,提升游戏公平性和用户体验
+
 
 
 

+ 1 - 3
app/Module/AppGame/Listeners/AppGameProtobufResponseListener.php

@@ -83,13 +83,11 @@ class AppGameProtobufResponseListener
         foreach ($pets as $pet){
             $p = new \Uraus\Kku\Common\DataPetSimple();
             $p->setId($pet->id);
-            $p->setTypeId($pet->newStatus);
             $p->setLevel($pet->level);
             $p->setName($pet->name);
             $p->setExp($pet->exp);
             $p->setPower($pet->power);
-            $p->setMaxpower($pet->maxpower);
-            $p->setScore($pet->score);
+
 //            $p->setGrade($pet->grade);
             $petLs[] = $p;
         }

+ 1 - 1
config/proto_route.php

@@ -90,7 +90,7 @@ return array (
       7 => 'query_data',
     ),
   ),
-  'generated_at' => '+08:00 2025-06-05 10:42:34',
+  'generated_at' => '+08:00 2025-06-06 11:23:26',
   'conventions' => 
   array (
     'handler_namespace' => 'App\\Module\\AppGame\\Handler',

+ 6 - 10
protophp/GPBMetadata/Proto/Game.php

@@ -16,7 +16,7 @@ class Game
         }
         $pool->internalAddGeneratedFile(
             '
-½Ÿ
+ûž
 proto/game.proto	uraus.kku"„4
 Request
 request_unid (	;
@@ -477,7 +477,7 @@ last_times (
 APPLYING	
 AGREE
 
-REFUSE"¥.
+REFUSE"ã-
 Common)
 KeyValue
 kname (	
@@ -615,20 +615,16 @@ DataHourse
 fight_attrsd (2.uraus.kku.Common.PetFightAttr6
 fight_statuse (2 .uraus.kku.Common.PetFightStatus
 fighting_capacityf (
-gradeg (¥
+gradeg (d
 
DataPetSimple
 
-id (
-type_id (
+id (
 name (	
 level (
 exp (
-power (
-maxpower (
-score	 (
+power (
 status
- (
-gradeg (,
+ (,
 PetFightStatus
 
 hp (

+ 0 - 136
protophp/Uraus/Kku/Common/DataPetSimple.php

@@ -21,12 +21,6 @@ class DataPetSimple extends \Google\Protobuf\Internal\Message
      * Generated from protobuf field <code>int64 id = 1;</code>
      */
     protected $id = 0;
-    /**
-     *宠物种族id
-     *
-     * Generated from protobuf field <code>int64 type_id = 2;</code>
-     */
-    protected $type_id = 0;
     /**
      *宠物名称
      *
@@ -51,30 +45,12 @@ class DataPetSimple extends \Google\Protobuf\Internal\Message
      * Generated from protobuf field <code>int64 power = 6;</code>
      */
     protected $power = 0;
-    /**
-     *宠物体力上限
-     *
-     * Generated from protobuf field <code>int64 maxpower = 7;</code>
-     */
-    protected $maxpower = 0;
-    /**
-     *宠物评分
-     *
-     * Generated from protobuf field <code>int64 score = 9;</code>
-     */
-    protected $score = 0;
     /**
      * 宠物状态
      *
      * Generated from protobuf field <code>int64 status = 10;</code>
      */
     protected $status = 0;
-    /**
-     * 宠物品阶
-     *
-     * Generated from protobuf field <code>int64 grade = 103;</code>
-     */
-    protected $grade = 0;
 
     /**
      * Constructor.
@@ -84,8 +60,6 @@ class DataPetSimple extends \Google\Protobuf\Internal\Message
      *
      *     @type int|string $id
      *           宠物唯一id
-     *     @type int|string $type_id
-     *          宠物种族id
      *     @type string $name
      *          宠物名称
      *     @type int|string $level
@@ -94,14 +68,8 @@ class DataPetSimple extends \Google\Protobuf\Internal\Message
      *          宠物经验值
      *     @type int|string $power
      *          宠物体力
-     *     @type int|string $maxpower
-     *          宠物体力上限
-     *     @type int|string $score
-     *          宠物评分
      *     @type int|string $status
      *           宠物状态
-     *     @type int|string $grade
-     *           宠物品阶
      * }
      */
     public function __construct($data = NULL) {
@@ -135,32 +103,6 @@ class DataPetSimple extends \Google\Protobuf\Internal\Message
         return $this;
     }
 
-    /**
-     *宠物种族id
-     *
-     * Generated from protobuf field <code>int64 type_id = 2;</code>
-     * @return int|string
-     */
-    public function getTypeId()
-    {
-        return $this->type_id;
-    }
-
-    /**
-     *宠物种族id
-     *
-     * Generated from protobuf field <code>int64 type_id = 2;</code>
-     * @param int|string $var
-     * @return $this
-     */
-    public function setTypeId($var)
-    {
-        GPBUtil::checkInt64($var);
-        $this->type_id = $var;
-
-        return $this;
-    }
-
     /**
      *宠物名称
      *
@@ -265,58 +207,6 @@ class DataPetSimple extends \Google\Protobuf\Internal\Message
         return $this;
     }
 
-    /**
-     *宠物体力上限
-     *
-     * Generated from protobuf field <code>int64 maxpower = 7;</code>
-     * @return int|string
-     */
-    public function getMaxpower()
-    {
-        return $this->maxpower;
-    }
-
-    /**
-     *宠物体力上限
-     *
-     * Generated from protobuf field <code>int64 maxpower = 7;</code>
-     * @param int|string $var
-     * @return $this
-     */
-    public function setMaxpower($var)
-    {
-        GPBUtil::checkInt64($var);
-        $this->maxpower = $var;
-
-        return $this;
-    }
-
-    /**
-     *宠物评分
-     *
-     * Generated from protobuf field <code>int64 score = 9;</code>
-     * @return int|string
-     */
-    public function getScore()
-    {
-        return $this->score;
-    }
-
-    /**
-     *宠物评分
-     *
-     * Generated from protobuf field <code>int64 score = 9;</code>
-     * @param int|string $var
-     * @return $this
-     */
-    public function setScore($var)
-    {
-        GPBUtil::checkInt64($var);
-        $this->score = $var;
-
-        return $this;
-    }
-
     /**
      * 宠物状态
      *
@@ -343,32 +233,6 @@ class DataPetSimple extends \Google\Protobuf\Internal\Message
         return $this;
     }
 
-    /**
-     * 宠物品阶
-     *
-     * Generated from protobuf field <code>int64 grade = 103;</code>
-     * @return int|string
-     */
-    public function getGrade()
-    {
-        return $this->grade;
-    }
-
-    /**
-     * 宠物品阶
-     *
-     * Generated from protobuf field <code>int64 grade = 103;</code>
-     * @param int|string $var
-     * @return $this
-     */
-    public function setGrade($var)
-    {
-        GPBUtil::checkInt64($var);
-        $this->grade = $var;
-
-        return $this;
-    }
-
 }
 
 // Adding a class alias for backwards compatibility with the previous class name.