FarmSeed.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Module\Farm\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\Relations\HasMany;
  5. /**
  6. * 种子配置模型
  7. * field start
  8. * @property int $id 主键ID
  9. * @property string $name 种子名称
  10. * @property int $type 种子类型:1普通,2神秘,3巨化
  11. * @property int $seed_time 种子期时间(秒)
  12. * @property int $min_output 最小产出
  13. * @property int $max_output 最大产出
  14. * @property int $disaster_min_output 有灾害时最小产出
  15. * @property int $disaster_max_output 有灾害时最大产出
  16. * @property int $item_id 对应的物品ID
  17. * @property \App\Module\Farm\Casts\DisasterResistanceCast $disaster_resistance 灾害抵抗
  18. * @property \App\Module\Farm\Casts\DisplayAttributesCast $display_attributes 显示属性
  19. * @property \Carbon\Carbon $created_at 创建时间
  20. * @property \Carbon\Carbon $updated_at 更新时间
  21. * field end
  22. */
  23. class FarmSeed extends Model
  24. {
  25. /**
  26. * 与模型关联的表名
  27. *
  28. * @var string
  29. */
  30. protected $table = 'farm_seeds';
  31. /**
  32. * 可批量赋值的属性
  33. *
  34. * @var array
  35. */
  36. protected $fillable = [
  37. 'name',
  38. 'type',
  39. 'seed_time',
  40. 'min_output',
  41. 'max_output',
  42. 'disaster_max_output',
  43. 'disaster_min_output',
  44. 'item_id',
  45. 'disaster_resistance',
  46. 'display_attributes',
  47. ];
  48. /**
  49. * 应该被转换为原生类型的属性
  50. *
  51. * @var array
  52. */
  53. protected $casts = [
  54. 'seed_time' => 'integer',
  55. 'disaster_resistance' => \App\Module\Farm\Casts\DisasterResistanceCast::class,
  56. 'display_attributes' => \App\Module\Farm\Casts\DisplayAttributesCast::class,
  57. ];
  58. /**
  59. * 获取种子的产出配置
  60. *
  61. * @return HasMany
  62. */
  63. public function outputs(): HasMany
  64. {
  65. return $this->hasMany(FarmSeedOutput::class, 'seed_id', 'id');
  66. }
  67. /**
  68. * 获取使用此种子的作物
  69. *
  70. * @return HasMany
  71. */
  72. public function crops(): HasMany
  73. {
  74. return $this->hasMany(FarmCrop::class, 'seed_id', 'id');
  75. }
  76. }