FarmCrop.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_end_time 当前阶段结束时间
  17. * @property array $disasters 灾害情况
  18. * @property bool $fertilized 当前阶段是否已使用化肥
  19. * @property \Carbon\Carbon $created_at 创建时间
  20. * @property \Carbon\Carbon $updated_at 更新时间
  21. * field end
  22. */
  23. class FarmCrop extends Model
  24. {
  25. /**
  26. * 与模型关联的表名
  27. *
  28. * @var string
  29. */
  30. protected $table = 'farm_crops';
  31. /**
  32. * 可批量赋值的属性
  33. *
  34. * @var array
  35. */
  36. protected $fillable = [
  37. 'land_id',
  38. 'user_id',
  39. 'seed_id',
  40. 'plant_time',
  41. 'growth_stage',
  42. 'stage_end_time',
  43. 'disasters',
  44. 'fertilized',
  45. ];
  46. /**
  47. * 应该被转换为日期的属性
  48. *
  49. * @var array
  50. */
  51. protected $dates = [
  52. 'plant_time',
  53. 'stage_end_time',
  54. 'created_at',
  55. 'updated_at',
  56. ];
  57. /**
  58. * 应该被转换为原生类型的属性
  59. *
  60. * @var array
  61. */
  62. protected $casts = [
  63. 'disasters' => 'json',
  64. 'growth_stage'=>GROWTH_STAGE::class,
  65. 'fertilized' => 'boolean',
  66. ];
  67. /**
  68. * 获取关联的土地
  69. *
  70. * @return BelongsTo
  71. */
  72. public function land(): BelongsTo
  73. {
  74. return $this->belongsTo(FarmLand::class, 'land_id', 'id');
  75. }
  76. /**
  77. * 获取关联的种子
  78. *
  79. * @return BelongsTo
  80. */
  81. public function seed(): BelongsTo
  82. {
  83. return $this->belongsTo(FarmSeed::class, 'seed_id', 'id');
  84. }
  85. }