FarmHouseConfig.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Module\Farm\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  5. /**
  6. * 房屋等级配置模型
  7. * field start
  8. * @property int $id 主键ID
  9. * @property int $level 等级
  10. * @property float $output_bonus 产出加成
  11. * @property int $special_land_limit 特殊土地上限
  12. * @property int $upgrade_materials 升级所需消耗组ID,关联game_consume_groups表
  13. * @property int $available_lands 该等级可用的土地数量
  14. * @property int $downgrade_days 降级天数,NULL表示不降级
  15. * @property \Carbon\Carbon $created_at 创建时间
  16. * @property \Carbon\Carbon $updated_at 更新时间
  17. * field end
  18. *
  19. */
  20. class FarmHouseConfig extends Model
  21. {
  22. /**
  23. * 与模型关联的表名
  24. *
  25. * @var string
  26. */
  27. protected $table = 'farm_house_configs';
  28. /**
  29. * 可批量赋值的属性
  30. *
  31. * @var array
  32. */
  33. protected $fillable = [
  34. 'level',
  35. 'output_bonus',
  36. 'special_land_limit',
  37. 'upgrade_materials',
  38. 'downgrade_days',
  39. 'available_lands',
  40. ];
  41. /**
  42. * 应该被转换为原生类型的属性
  43. *
  44. * @var array
  45. */
  46. protected $casts = [
  47. 'output_bonus' => 'float',
  48. 'available_lands' => 'integer',
  49. ];
  50. /**
  51. * 获取关联的消耗组
  52. *
  53. * @return BelongsTo
  54. */
  55. public function consumeGroup(): BelongsTo
  56. {
  57. return $this->belongsTo(\App\Module\Game\Models\GameConsumeGroup::class, 'upgrade_materials', 'id');
  58. }
  59. /**
  60. * 获取升级所需材料
  61. *
  62. * @return array
  63. */
  64. public function getUpgradeMaterials(): array
  65. {
  66. // 如果有关联的消耗组,则使用消耗组服务获取材料
  67. if ($this->upgrade_materials && is_numeric($this->upgrade_materials)) {
  68. return \App\Module\Game\Services\ConsumeGroupService::getConsumeMaterials($this->upgrade_materials);
  69. }
  70. return [];
  71. }
  72. }