FarmSeed.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 $min_output 最小产出
  15. * @property int $max_output 最大产出
  16. * @property int $item_id 对应的物品ID
  17. * @property object|array $disaster_resistance 灾害抵抗
  18. * @property object|array $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. 'sprout_time',
  41. 'growth_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. }