FarmSeedOutput.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 float $probability 产出概率(0-1)
  15. * @property bool $is_default 是否为默认产出
  16. * @property \Carbon\Carbon $created_at 创建时间
  17. * @property \Carbon\Carbon $updated_at 更新时间
  18. * field end
  19. */
  20. class FarmSeedOutput extends Model
  21. {
  22. /**
  23. * 与模型关联的表名
  24. *
  25. * @var string
  26. */
  27. protected $table = 'farm_seed_outputs';
  28. /**
  29. * 可批量赋值的属性
  30. *
  31. * @var array
  32. */
  33. protected $fillable = [
  34. 'seed_id',
  35. 'item_id',
  36. 'min_amount',
  37. 'max_amount',
  38. 'probability',
  39. 'is_default',
  40. ];
  41. /**
  42. * 应该被转换为原生类型的属性
  43. *
  44. * @var array
  45. */
  46. protected $casts = [
  47. 'probability' => 'float',
  48. 'is_default' => 'boolean',
  49. ];
  50. /**
  51. * 获取关联的种子
  52. *
  53. * @return BelongsTo
  54. */
  55. public function seed(): BelongsTo
  56. {
  57. return $this->belongsTo(FarmSeed::class, 'seed_id', 'id');
  58. }
  59. // 物品关联
  60. public function item(): BelongsTo
  61. {
  62. return $this->belongsTo(Item::class, 'item_id', 'id');
  63. }
  64. }