Explorar o código

修改土地配置表的 upgrade_paths 输出,显示完整的 materials 和 conditions 内容而不仅是 ID

notfff hai 7 meses
pai
achega
ec50378a58

+ 0 - 69
app/Module/Dev/Models/Dev.php

@@ -1,69 +0,0 @@
-<?php
-
-namespace App\Module\Dev\Models;
-
-use Illuminate\Database\Eloquent\Model;
-use Illuminate\Database\Eloquent\SoftDeletes;
-
-/**
- * 开发工具模型
- *
- * @property int $id ID
- * @property string $name 名称
- * @property string $description 描述
- * @property int $status 状态
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * @property \Carbon\Carbon $deleted_at 删除时间
- */
-class Dev extends Model
-{
-    use SoftDeletes;
-
-    /**
-     * 表名
-     *
-     * @var string
-     */
-    protected $table = 'dev_tools';
-
-    /**
-     * 可批量赋值的属性
-     *
-     * @var array
-     */
-    protected $fillable = [
-        'name',
-        'description',
-        'status',
-    ];
-
-    /**
-     * 隐藏的属性
-     *
-     * @var array
-     */
-    protected $hidden = [
-        'deleted_at',
-    ];
-
-    /**
-     * 日期字段
-     *
-     * @var array
-     */
-    protected $dates = [
-        'created_at',
-        'updated_at',
-        'deleted_at',
-    ];
-
-    /**
-     * 属性类型转换
-     *
-     * @var array
-     */
-    protected $casts = [
-        'status' => 'integer',
-    ];
-}

+ 0 - 62
app/Module/Dev/Models/DevLog.php

@@ -1,62 +0,0 @@
-<?php
-
-namespace App\Module\Dev\Models;
-
-use Illuminate\Database\Eloquent\Model;
-
-/**
- * 开发日志模型
- *
- * @property int $id ID
- * @property string $type 日志类型
- * @property string $content 日志内容
- * @property string $ip IP地址
- * @property int $user_id 用户ID
- * @property string $user_agent 用户代理
- * @property array $extra_data 额外数据
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- */
-class DevLog extends Model
-{
-    /**
-     * 表名
-     *
-     * @var string
-     */
-    protected $table = 'dev_logs';
-
-    /**
-     * 可批量赋值的属性
-     *
-     * @var array
-     */
-    protected $fillable = [
-        'type',
-        'content',
-        'ip',
-        'user_id',
-        'user_agent',
-        'extra_data',
-    ];
-
-    /**
-     * 日期字段
-     *
-     * @var array
-     */
-    protected $dates = [
-        'created_at',
-        'updated_at',
-    ];
-
-    /**
-     * 属性类型转换
-     *
-     * @var array
-     */
-    protected $casts = [
-        'user_id' => 'integer',
-        'extra_data' => 'array',
-    ];
-}

+ 8 - 3
app/Module/Farm/Commands/GenerateFarmLandConfigJson.php

@@ -5,7 +5,6 @@ namespace App\Module\Farm\Commands;
 use App\Module\Farm\Models\FarmLandType;
 use App\Module\Farm\Models\FarmLandUpgradeConfig;
 use Illuminate\Console\Command;
-use Illuminate\Support\Facades\DB;
 
 /**
  * 生成土地配置表JSON数据命令
@@ -68,11 +67,17 @@ class GenerateFarmLandConfigJson extends Command
 
             // 处理土地升级路径数据
             foreach ($upgradeConfigs as $config) {
+                // 获取完整的材料内容和条件内容
+                $materials = $config->getUpgradeMaterials();
+                $conditions = $config->getUpgradeConditions();
+
                 $jsonData['upgrade_paths'][] = [
                     'from_type_id' => $config->from_type_id,
                     'to_type_id' => $config->to_type_id,
-                    'materials' => $config->materials,
-                    'conditions' => $config->conditions,
+                    'materials' => ['materials' => $materials], // 保持与旧版本兼容的格式
+                    'conditions' => $conditions,
+                    'materials_group_id' => $config->materials,
+                    'conditions_group_id' => $config->conditions,
                 ];
             }
 

+ 92 - 23
app/Module/Farm/Models/FarmLandUpgradeConfig.php

@@ -9,7 +9,7 @@ use App\Module\Game\Models\GameConditionGroup;
 
 /**
  * 土地升级配置模型
- * field start 
+ * field start
  * @property  int  $id  主键ID
  * @property  int  $from_type_id  起始土地类型ID
  * @property  int  $to_type_id  目标土地类型ID
@@ -121,28 +121,52 @@ class FarmLandUpgradeConfig extends Model
     public function getUpgradeMaterials(): array
     {
         // 如果有关联的消耗组,则使用消耗组中的消耗项
-        if ($this->materials_group_id && $this->materialsGroup) {
-            $consumeItems = $this->materialsGroup->consumeItems;
-            $materials = [];
-
-            foreach ($consumeItems as $item) {
-                if ($item->consume_type == \App\Module\Game\Enums\CONSUME_TYPE::ITEM->value) {
-                    $materials[] = [
-                        'item_id' => $item->target_id,
-                        'amount' => $item->quantity
-                    ];
+        if ($this->materials && is_numeric($this->materials)) {
+            // 获取消耗组
+            $consumeGroup = \App\Module\Game\Models\GameConsumeGroup::find($this->materials);
+            if ($consumeGroup && $consumeGroup->consumeItems) {
+                $materials = [];
+
+                foreach ($consumeGroup->consumeItems as $item) {
+                    if ($item->consume_type == \App\Module\Game\Enums\CONSUME_TYPE::ITEM->value) {
+                        // 获取物品信息
+                        $itemInfo = \App\Module\GameItems\Models\Item::find($item->target_id);
+                        $materials[] = [
+                            'item_id' => $item->target_id,
+                            'item_name' => $itemInfo ? $itemInfo->name : "物品 {$item->target_id}",
+                            'amount' => $item->quantity
+                        ];
+                    } elseif ($item->consume_type == \App\Module\Game\Enums\CONSUME_TYPE::CURRENCY->value) {
+                        // 获取货币信息
+                        $currencyInfo = \App\Module\Fund\Models\FundCurrencyModel::find($item->target_id);
+                        $materials[] = [
+                            'currency_id' => $item->target_id,
+                            'currency_name' => $currencyInfo ? $currencyInfo->name : "货币 {$item->target_id}",
+                            'amount' => $item->quantity
+                        ];
+                    } elseif ($item->consume_type == \App\Module\Game\Enums\CONSUME_TYPE::FUND->value) {
+                        // 获取代币账户信息
+                        $fundInfo = \App\Module\Fund\Models\FundConfigModel::find($item->target_id);
+                        $materials[] = [
+                            'fund_id' => $item->target_id,
+                            'fund_name' => $fundInfo ? $fundInfo->name : "代币账户 {$item->target_id}",
+                            'amount' => $item->quantity
+                        ];
+                    }
                 }
-            }
 
-            return $materials;
+                return $materials;
+            }
         }
 
         // 否则使用 materials 字段
         if (is_string($this->materials)) {
             return json_decode($this->materials, true)['materials'] ?? [];
+        } elseif (is_array($this->materials)) {
+            return $this->materials['materials'] ?? [];
         }
 
-        return $this->materials['materials'] ?? [];
+        return [];
     }
 
     /**
@@ -155,20 +179,65 @@ class FarmLandUpgradeConfig extends Model
     public function getUpgradeConditions(): array
     {
         // 如果有关联的条件组,则使用条件组
-        if ($this->conditions_group_id && $this->conditionsGroup) {
-            return [
-                'conditions_group_id' => $this->conditions_group_id,
-                'conditions_group_code' => $this->conditionsGroup->code,
-                'logic_type' => $this->conditionsGroup->logic_type
-            ];
+        if ($this->conditions && is_numeric($this->conditions)) {
+            // 获取条件组
+            $conditionGroup = \App\Module\Game\Models\GameConditionGroup::find($this->conditions);
+            if ($conditionGroup) {
+                $conditions = [
+                    'conditions_group_id' => $this->conditions,
+                    'conditions_group_code' => $conditionGroup->code,
+                    'conditions_group_name' => $conditionGroup->name,
+                    'logic_type' => $conditionGroup->logic_type,
+                    'items' => []
+                ];
+
+                // 获取条件项
+                if ($conditionGroup->conditionItems) {
+                    foreach ($conditionGroup->conditionItems as $item) {
+                        $conditionItem = [
+                            'id' => $item->id,
+                            'condition_type' => $item->condition_type,
+                            'target_id' => $item->target_id,
+                            'operator' => $item->operator,
+                            'value' => $item->value
+                        ];
+
+                        // 根据条件类型获取目标名称
+                        if ($item->condition_type == \App\Module\Game\Enums\CONDITION_TYPE::LAND_LEVEL->value) {
+                            $landType = \App\Module\Farm\Models\FarmLandType::find($item->target_id);
+                            $conditionItem['target_name'] = $landType ? $landType->name : "土地类型 {$item->target_id}";
+                        } elseif ($item->condition_type == \App\Module\Game\Enums\CONDITION_TYPE::HOUSE_LEVEL->value) {
+                            $conditionItem['target_name'] = "房屋";
+                        } elseif ($item->condition_type == \App\Module\Game\Enums\CONDITION_TYPE::PET_LEVEL->value) {
+                            $pet = \App\Module\Pet\Models\PetConfig::find($item->target_id);
+                            $conditionItem['target_name'] = $pet ? $pet->name : "宠物 {$item->target_id}";
+                        } elseif ($item->condition_type == \App\Module\Game\Enums\CONDITION_TYPE::ITEM_COUNT->value) {
+                            $itemInfo = \App\Module\GameItems\Models\Item::find($item->target_id);
+                            $conditionItem['target_name'] = $itemInfo ? $itemInfo->name : "物品 {$item->target_id}";
+                        } elseif ($item->condition_type == \App\Module\Game\Enums\CONDITION_TYPE::CURRENCY_COUNT->value) {
+                            $currency = \App\Module\Fund\Models\FundCurrencyModel::find($item->target_id);
+                            $conditionItem['target_name'] = $currency ? $currency->name : "货币 {$item->target_id}";
+                        } elseif ($item->condition_type == \App\Module\Game\Enums\CONDITION_TYPE::FUND_COUNT->value) {
+                            $fund = \App\Module\Fund\Models\FundConfigModel::find($item->target_id);
+                            $conditionItem['target_name'] = $fund ? $fund->name : "代币账户 {$item->target_id}";
+                        }
+
+                        $conditions['items'][] = $conditionItem;
+                    }
+                }
+
+                return $conditions;
+            }
         }
 
         // 否则使用 conditions 字段
         if (is_string($this->conditions)) {
             return json_decode($this->conditions, true) ?? [];
+        } elseif (is_array($this->conditions)) {
+            return $this->conditions ?? [];
         }
 
-        return $this->conditions ?? [];
+        return [];
     }
 
     /**
@@ -180,8 +249,8 @@ class FarmLandUpgradeConfig extends Model
     public function checkUpgradeConditions(int $userId): array
     {
         // 如果有关联的条件组,则使用条件组检查
-        if ($this->conditions_group_id && $this->conditionsGroup) {
-            return \App\Module\Game\Services\ConditionService::checkCondition($userId, $this->conditions_group_id);
+        if ($this->conditions && is_numeric($this->conditions)) {
+            return \App\Module\Game\Services\ConditionService::checkCondition($userId, $this->conditions);
         }
 
         // 否则使用旧版本的条件检查逻辑