FarmCrop.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace App\Module\Farm\Models;
  3. use App\Module\Farm\Enums\GROWTH_STAGE;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. /**
  7. * 作物信息模型
  8. *
  9. * field start
  10. * @property int $id 主键ID
  11. * @property int $land_id 土地ID
  12. * @property int $user_id 用户ID
  13. * @property int $seed_id 种子ID
  14. * @property \Carbon\Carbon $plant_time 种植时间
  15. * @property \App\Module\Farm\Enums\GROWTH_STAGE $growth_stage 生长阶段:1种子期,2发芽期,3生长期,4成熟期,5枯萎期
  16. * @property \Carbon\Carbon $stage_start_time 当前阶段结束时间
  17. * @property \Carbon\Carbon $stage_end_time 当前阶段结束时间
  18. * @property array $disasters 灾害情况
  19. * @property bool $fertilized 当前阶段是否已使用化肥
  20. * @property \Carbon\Carbon $last_disaster_check_time 上次灾害检查时间
  21. * @property bool $can_disaster 当前阶段是否可以产生灾害:0否,1是
  22. * @property int $final_output_item_id 最终产出果实ID(发芽期确定)
  23. * @property int $final_output_amount 最终产出数量(成熟期确定)
  24. * @property \Carbon\Carbon $created_at 创建时间
  25. * @property \Carbon\Carbon $updated_at 更新时间
  26. * field end
  27. *
  28. *
  29. */
  30. class FarmCrop extends Model
  31. {
  32. /**
  33. * 与模型关联的表名
  34. *
  35. * @var string
  36. */
  37. protected $table = 'farm_crops';
  38. /**
  39. * 可批量赋值的属性
  40. *
  41. * @var array
  42. */
  43. protected $fillable = [
  44. 'land_id',
  45. 'user_id',
  46. 'seed_id',
  47. 'plant_time',
  48. 'growth_stage',
  49. 'stage_start_time',
  50. 'stage_end_time',
  51. 'disasters',
  52. 'fertilized',
  53. 'last_disaster_check_time',
  54. 'can_disaster',
  55. 'final_output_item_id',
  56. 'final_output_amount',
  57. ];
  58. /**
  59. * 应该被转换为原生类型的属性
  60. *
  61. * @var array
  62. */
  63. protected $casts = [
  64. 'disasters' => 'json',
  65. 'growth_stage' => GROWTH_STAGE::class,
  66. 'fertilized' => 'boolean',
  67. 'plant_time' => 'datetime',
  68. 'stage_start_time' => 'datetime',
  69. 'stage_end_time' => 'datetime',
  70. 'last_disaster_check_time' => 'datetime',
  71. 'can_disaster' => 'boolean',
  72. ];
  73. /**
  74. * 获取关联的土地
  75. *
  76. * @return BelongsTo
  77. */
  78. public function land(): BelongsTo
  79. {
  80. return $this->belongsTo(FarmLand::class, 'land_id', 'id');
  81. }
  82. /**
  83. * 获取关联的种子
  84. *
  85. * @return BelongsTo
  86. */
  87. public function seed(): BelongsTo
  88. {
  89. return $this->belongsTo(FarmSeed::class, 'seed_id', 'id');
  90. }
  91. /**
  92. * 用户农场信息(房屋)
  93. * @return BelongsTo
  94. */
  95. public function user(): BelongsTo
  96. {
  97. return $this->belongsTo(FarmUser::class, 'user_id', 'user_id');
  98. }
  99. }