FarmSeedOutput.php 1.5 KB

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