FarmCrop.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 string $plant_time 种植时间
  15. * @property int $growth_stage 生长阶段:1种子期,2发芽期,3生长期,4成熟期,5枯萎期
  16. * @property string $stage_start_time 当前阶段结束时间
  17. * @property string $stage_end_time 当前阶段结束时间
  18. * @property array $disasters 灾害情况
  19. * @property bool $fertilized 当前阶段是否已使用化肥
  20. * @property \Carbon\Carbon $created_at 创建时间
  21. * @property \Carbon\Carbon $updated_at 更新时间
  22. * field end
  23. */
  24. class FarmCrop extends Model
  25. {
  26. /**
  27. * 与模型关联的表名
  28. *
  29. * @var string
  30. */
  31. protected $table = 'farm_crops';
  32. /**
  33. * 可批量赋值的属性
  34. *
  35. * @var array
  36. */
  37. protected $fillable = [
  38. 'land_id',
  39. 'user_id',
  40. 'seed_id',
  41. 'plant_time',
  42. 'growth_stage',
  43. 'stage_start_time',
  44. 'stage_end_time',
  45. 'disasters',
  46. 'fertilized',
  47. ];
  48. /**
  49. * 应该被转换为日期的属性
  50. *
  51. * @var array
  52. */
  53. protected $dates = [
  54. 'plant_time',
  55. 'stage_start_time',
  56. 'stage_end_time',
  57. 'created_at',
  58. 'updated_at',
  59. ];
  60. /**
  61. * 应该被转换为原生类型的属性
  62. *
  63. * @var array
  64. */
  65. protected $casts = [
  66. 'disasters' => 'json',
  67. 'growth_stage'=>GROWTH_STAGE::class,
  68. 'fertilized' => '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. }