FarmSeed.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace App\Module\Farm\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\Relations\HasMany;
  5. /**
  6. * 种子配置模型
  7. * field start
  8. * @property int $id 主键ID
  9. * @property string $name 种子名称
  10. * @property int $type 种子类型:1普通,2神秘,3巨化
  11. * @property int $seed_time 种子期时间(秒)
  12. * @property int $min_output 最小产出
  13. * @property int $max_output 最大产出
  14. * @property int $disaster_min_output 有灾害时最小产出
  15. * @property int $disaster_max_output 有灾害时最大产出
  16. * @property int $item_id 对应的物品ID
  17. * @property \App\Module\Farm\Casts\DisasterResistanceCast $disaster_resistance 灾害抵抗
  18. * @property \App\Module\Farm\Casts\DisplayAttributesCast $display_attributes 显示属性
  19. * @property bool $pick_enabled 是否允许摘取
  20. * @property float $pick_max_ratio 最大摘取比例
  21. * @property float $pick_min_reserve_ratio 最小保留比例
  22. * @property int $pick_cooldown_seconds 摘取冷却时间(秒)
  23. * @property \Carbon\Carbon $created_at 创建时间
  24. * @property \Carbon\Carbon $updated_at 更新时间
  25. * field end
  26. */
  27. class FarmSeed extends Model
  28. {
  29. /**
  30. * 与模型关联的表名
  31. *
  32. * @var string
  33. */
  34. protected $table = 'farm_seeds';
  35. /**
  36. * 可批量赋值的属性
  37. *
  38. * @var array
  39. */
  40. protected $fillable = [
  41. 'name',
  42. 'type',
  43. 'seed_time',
  44. 'min_output',
  45. 'max_output',
  46. 'disaster_max_output',
  47. 'disaster_min_output',
  48. 'item_id',
  49. 'disaster_resistance',
  50. 'display_attributes',
  51. 'pick_enabled',
  52. 'pick_max_ratio',
  53. 'pick_min_reserve_ratio',
  54. 'pick_cooldown_seconds',
  55. ];
  56. /**
  57. * 应该被转换为原生类型的属性
  58. *
  59. * @var array
  60. */
  61. protected $casts = [
  62. 'seed_time' => 'integer',
  63. 'disaster_resistance' => \App\Module\Farm\Casts\DisasterResistanceCast::class,
  64. 'display_attributes' => \App\Module\Farm\Casts\DisplayAttributesCast::class,
  65. 'pick_enabled' => 'boolean',
  66. 'pick_max_ratio' => 'decimal:4',
  67. 'pick_min_reserve_ratio' => 'decimal:4',
  68. 'pick_cooldown_seconds' => 'integer',
  69. ];
  70. /**
  71. * 获取种子的产出配置
  72. *
  73. * @return HasMany
  74. */
  75. public function outputs(): HasMany
  76. {
  77. return $this->hasMany(FarmSeedOutput::class, 'seed_id', 'id');
  78. }
  79. /**
  80. * 获取使用此种子的作物
  81. *
  82. * @return HasMany
  83. */
  84. public function crops(): HasMany
  85. {
  86. return $this->hasMany(FarmCrop::class, 'seed_id', 'id');
  87. }
  88. }