FarmSeed.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 $sprout_time 发芽期时间(秒)
  13. * @property int $growth_time 成长期时间(秒)
  14. * @property int $mature_time 成熟期时间(秒,0表示无限)
  15. * @property int $wither_time 枯萎期时间(秒,0表示无限)
  16. * @property int $min_output 最小产出
  17. * @property int $max_output 最大产出
  18. * @property int $disaster_max_output 有灾害时最大产出
  19. * @property int $item_id 对应的物品ID
  20. * @property \App\Module\Farm\Casts\DisasterResistanceCast $disaster_resistance 灾害抵抗
  21. * @property \App\Module\Farm\Casts\DisplayAttributesCast $display_attributes 显示属性
  22. * @property \Carbon\Carbon $created_at 创建时间
  23. * @property \Carbon\Carbon $updated_at 更新时间
  24. * field end
  25. */
  26. class FarmSeed extends Model
  27. {
  28. /**
  29. * 与模型关联的表名
  30. *
  31. * @var string
  32. */
  33. protected $table = 'farm_seeds';
  34. /**
  35. * 可批量赋值的属性
  36. *
  37. * @var array
  38. */
  39. protected $fillable = [
  40. 'name',
  41. 'type',
  42. 'seed_time',
  43. 'min_output',
  44. 'max_output',
  45. 'disaster_max_output',
  46. 'item_id',
  47. 'disaster_resistance',
  48. 'display_attributes',
  49. ];
  50. /**
  51. * 应该被转换为原生类型的属性
  52. *
  53. * @var array
  54. */
  55. protected $casts = [
  56. 'disaster_resistance' => \App\Module\Farm\Casts\DisasterResistanceCast::class,
  57. 'display_attributes' => \App\Module\Farm\Casts\DisplayAttributesCast::class,
  58. ];
  59. /**
  60. * 获取种子的产出配置
  61. *
  62. * @return HasMany
  63. */
  64. public function outputs(): HasMany
  65. {
  66. return $this->hasMany(FarmSeedOutput::class, 'seed_id', 'id');
  67. }
  68. /**
  69. * 获取使用此种子的作物
  70. *
  71. * @return HasMany
  72. */
  73. public function crops(): HasMany
  74. {
  75. return $this->hasMany(FarmCrop::class, 'seed_id', 'id');
  76. }
  77. }