|
|
@@ -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);
|
|
|
}
|
|
|
|
|
|
// 否则使用旧版本的条件检查逻辑
|