FarmCrop.php 3.4 KB

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