FarmSeedOutput.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Module\Farm\Models;
  3. use App\Module\GameItems\Models\Item;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. /**
  7. * 种子产出配置模型
  8. * field start
  9. * @property int $id 主键ID
  10. * @property int $seed_id 种子ID
  11. * @property int $item_id 产出物品ID
  12. * @property int $min_amount 最小产出数量
  13. * @property int $max_amount 最大产出数量
  14. * @property int $disaster_min_amount 有灾害时最小产出数量
  15. * @property int $disaster_max_amount 有灾害时最大产出数量
  16. * @property float $probability 产出概率(0-1)
  17. * @property bool $is_default 是否为默认产出
  18. * @property \Carbon\Carbon $created_at 创建时间
  19. * @property \Carbon\Carbon $updated_at 更新时间
  20. * field end
  21. */
  22. class FarmSeedOutput extends Model
  23. {
  24. /**
  25. * 与模型关联的表名
  26. *
  27. * @var string
  28. */
  29. protected $table = 'farm_seed_outputs';
  30. /**
  31. * 可批量赋值的属性
  32. *
  33. * @var array
  34. */
  35. protected $fillable = [
  36. 'seed_id',
  37. 'item_id',
  38. 'min_amount',
  39. 'max_amount',
  40. 'disaster_max_amount',
  41. 'disaster_min_amount',
  42. 'probability',
  43. 'is_default',
  44. ];
  45. /**
  46. * 应该被转换为原生类型的属性
  47. *
  48. * @var array
  49. */
  50. protected $casts = [
  51. 'probability' => 'float',
  52. 'is_default' => 'boolean',
  53. ];
  54. /**
  55. * 获取关联的种子
  56. *
  57. * @return BelongsTo
  58. */
  59. public function seed(): BelongsTo
  60. {
  61. return $this->belongsTo(FarmSeed::class, 'seed_id', 'id');
  62. }
  63. // 物品关联
  64. public function item(): BelongsTo
  65. {
  66. return $this->belongsTo(Item::class, 'item_id', 'id');
  67. }
  68. }