FarmSeed.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_min_output 有灾害时最小产出
  19. * @property int $disaster_max_output 有灾害时最大产出
  20. * @property int $item_id 对应的物品ID
  21. * @property \App\Module\Farm\Casts\DisasterResistanceCast $disaster_resistance 灾害抵抗
  22. * @property \App\Module\Farm\Casts\DisplayAttributesCast $display_attributes 显示属性
  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. ];
  52. /**
  53. * 应该被转换为原生类型的属性
  54. *
  55. * @var array
  56. */
  57. protected $casts = [
  58. 'disaster_resistance' => \App\Module\Farm\Casts\DisasterResistanceCast::class,
  59. 'display_attributes' => \App\Module\Farm\Casts\DisplayAttributesCast::class,
  60. ];
  61. /**
  62. * 获取种子的产出配置
  63. *
  64. * @return HasMany
  65. */
  66. public function outputs(): HasMany
  67. {
  68. return $this->hasMany(FarmSeedOutput::class, 'seed_id', 'id');
  69. }
  70. /**
  71. * 获取使用此种子的作物
  72. *
  73. * @return HasMany
  74. */
  75. public function crops(): HasMany
  76. {
  77. return $this->hasMany(FarmCrop::class, 'seed_id', 'id');
  78. }
  79. }