ItemGroupItem.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Module\GameItems\Models;
  3. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  4. use UCore\ModelCore;
  5. /**
  6. * 物品组内容
  7. *
  8. * field start
  9. * @property int $id 记录ID,主键
  10. * @property int $group_id 物品组ID,外键关联kku_item_groups表
  11. * @property int $item_id 物品ID,外键关联kku_item_items表
  12. * @property float $weight 权重,决定从物品组中选择该物品的概率
  13. * @property \Carbon\Carbon $created_at 创建时间
  14. * @property \Carbon\Carbon $updated_at 更新时间
  15. * field end
  16. */
  17. class ItemGroupItem extends ModelCore
  18. {
  19. /**
  20. * 与模型关联的表名
  21. *
  22. * @var string
  23. */
  24. protected $table = 'item_group_items';
  25. // attrlist start
  26. protected $fillable = [
  27. 'id',
  28. 'group_id',
  29. 'item_id',
  30. 'weight',
  31. ];
  32. // attrlist end
  33. /**
  34. * 应该被转换为原生类型的属性
  35. *
  36. * @var array
  37. */
  38. protected $casts = [
  39. 'weight' => 'float',
  40. ];
  41. /**
  42. * 获取关联的物品组
  43. *
  44. * @return BelongsTo
  45. */
  46. public function group(): BelongsTo
  47. {
  48. return $this->belongsTo(ItemGroup::class, 'group_id');
  49. }
  50. /**
  51. * 获取关联的物品
  52. *
  53. * @return BelongsTo
  54. */
  55. public function item(): BelongsTo
  56. {
  57. return $this->belongsTo(Item::class, 'item_id');
  58. }
  59. }