FarmSeedOutput.php 1.7 KB

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