FarmCrop.php 2.6 KB

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