| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace App\Module\Farm\Models;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- /**
- * 房屋等级配置模型
- * field start
- * @property int $id 主键ID
- * @property int $level 等级
- * @property float $output_bonus 产出加成
- * @property int $special_land_limit 特殊土地上限
- * @property int $upgrade_materials 升级所需消耗组ID,关联game_consume_groups表
- * @property int $available_lands 该等级可用的土地数量
- * @property int $downgrade_days 降级天数,NULL表示不降级
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * field end
- *
- */
- class FarmHouseConfig extends Model
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'farm_house_configs';
- /**
- * 可批量赋值的属性
- *
- * @var array
- */
- protected $fillable = [
- 'level',
- 'output_bonus',
- 'special_land_limit',
- 'upgrade_materials',
- 'downgrade_days',
- 'available_lands',
- ];
- /**
- * 应该被转换为原生类型的属性
- *
- * @var array
- */
- protected $casts = [
- 'output_bonus' => 'float',
- 'available_lands' => 'integer',
- ];
- /**
- * 获取关联的消耗组
- *
- * @return BelongsTo
- */
- public function consumeGroup(): BelongsTo
- {
- return $this->belongsTo(\App\Module\Game\Models\GameConsumeGroup::class, 'upgrade_materials', 'id');
- }
- /**
- * 获取升级所需材料
- *
- * @return array
- */
- public function getUpgradeMaterials(): array
- {
- // 如果有关联的消耗组,则使用消耗组服务获取材料
- if ($this->upgrade_materials && is_numeric($this->upgrade_materials)) {
- return \App\Module\Game\Services\ConsumeGroupService::getConsumeMaterials($this->upgrade_materials);
- }
- return [];
- }
- }
|