FarmSeed.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 $sprout_time 发芽期时间(秒)
  13. * @property int $growth_time 成长期时间(秒)
  14. * @property int $mature_time 成熟期时间(秒,0表示无限)
  15. * @property int $wither_time 枯萎期时间(秒,0表示无限)
  16. * @property int $min_output 最小产出
  17. * @property int $max_output 最大产出
  18. * @property int $item_id 对应的物品ID
  19. * @property \App\Module\Farm\Casts\DisasterResistanceCast $disaster_resistance 灾害抵抗
  20. * @property \App\Module\Farm\Casts\DisplayAttributesCast $display_attributes 显示属性
  21. * @property \Carbon\Carbon $created_at 创建时间
  22. * @property \Carbon\Carbon $updated_at 更新时间
  23. * field end
  24. */
  25. class FarmSeed extends Model
  26. {
  27. /**
  28. * 与模型关联的表名
  29. *
  30. * @var string
  31. */
  32. protected $table = 'farm_seeds';
  33. /**
  34. * 可批量赋值的属性
  35. *
  36. * @var array
  37. */
  38. protected $fillable = [
  39. 'name',
  40. 'type',
  41. 'seed_time',
  42. 'min_output',
  43. 'max_output',
  44. 'item_id',
  45. 'disaster_resistance',
  46. 'display_attributes',
  47. ];
  48. /**
  49. * 应该被转换为原生类型的属性
  50. *
  51. * @var array
  52. */
  53. protected $casts = [
  54. 'disaster_resistance' => \App\Module\Farm\Casts\DisasterResistanceCast::class,
  55. 'display_attributes' => \App\Module\Farm\Casts\DisplayAttributesCast::class,
  56. ];
  57. /**
  58. * 获取种子的产出配置
  59. *
  60. * @return HasMany
  61. */
  62. public function outputs(): HasMany
  63. {
  64. return $this->hasMany(FarmSeedOutput::class, 'seed_id', 'id');
  65. }
  66. /**
  67. * 获取使用此种子的作物
  68. *
  69. * @return HasMany
  70. */
  71. public function crops(): HasMany
  72. {
  73. return $this->hasMany(FarmCrop::class, 'seed_id', 'id');
  74. }
  75. }