Item.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace App\Module\GameItems\Models;
  3. use App\Module\GameItems\Enums\ITEM_TYPE;
  4. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  5. use Illuminate\Database\Eloquent\Relations\HasMany;
  6. use UCore\ModelCore;
  7. /**
  8. * 物品基础信息
  9. *
  10. * field start
  11. * @property int $id 物品ID,主键
  12. * @property string $name 物品名称
  13. * @property string $description 物品描述
  14. * @property int $category_id 物品分类ID,外键关联kku_item_categories表
  15. * @property int $type 物品类型(1:可使用, 2:可装备, 3:可合成, 4:可交任务, 5:可开启...)
  16. * @property int $is_unique 是否是单独属性物品(0:否,默认, 1:是)
  17. * @property int $max_stack 最大堆叠数量
  18. * @property int $sell_price 出售价格
  19. * @property int $tradable 是否可交易(0:不可交易, 1:可交易,默认)
  20. * @property int $dismantlable 是否可分解(0:不可分解, 1:可分解,默认)
  21. * @property int $default_expire_seconds 玩家获取物品后的默认有效秒数(0表示永久有效)
  22. * @property object|array $display_attributes 展示属性,以JSON格式存储键值对,用于界面展示和描述的属性
  23. * @property object|array $numeric_attributes 数值属性,以JSON格式存储键值对,用于计算和游戏逻辑的属性
  24. * @property string $global_expire_at 物品全局过期时间(可为空)
  25. * @property \Carbon\Carbon $created_at 创建时间
  26. * @property \Carbon\Carbon $updated_at 更新时间
  27. * field end
  28. */
  29. class Item extends ModelCore
  30. {
  31. /**
  32. * 与模型关联的表名
  33. *
  34. * @var string
  35. */
  36. protected $table = 'item_items';
  37. // attrlist start
  38. protected $fillable = [
  39. 'id',
  40. 'name',
  41. 'description',
  42. 'category_id',
  43. 'type',
  44. 'is_unique',
  45. 'max_stack',
  46. 'sell_price',
  47. 'tradable',
  48. 'dismantlable',
  49. 'default_expire_seconds',
  50. 'display_attributes',
  51. 'numeric_attributes',
  52. 'global_expire_at',
  53. ];
  54. // attrlist end
  55. /**
  56. * 应该被转换为日期的属性
  57. *
  58. * @var array
  59. */
  60. protected $dates = [
  61. 'global_expire_at',
  62. 'created_at',
  63. 'updated_at',
  64. ];
  65. /**
  66. * 应该被转换为原生类型的属性
  67. *
  68. * @var array
  69. */
  70. protected $casts = [
  71. 'display_attributes' => \App\Module\GameItems\Casts\DisplayAttributesCast::class,
  72. 'numeric_attributes' => \App\Module\GameItems\Casts\NumericAttributesCast::class,
  73. 'type' => ITEM_TYPE::class,
  74. 'is_unique' => 'boolean',
  75. 'tradable' => 'boolean',
  76. 'dismantlable' => 'boolean',
  77. ];
  78. /**
  79. * 获取物品所属分类
  80. *
  81. * @return BelongsTo
  82. */
  83. public function category(): BelongsTo
  84. {
  85. return $this->belongsTo(ItemCategory::class, 'category_id');
  86. }
  87. /**
  88. * 获取物品的所有实例
  89. *
  90. * @return HasMany
  91. */
  92. public function instances(): HasMany
  93. {
  94. return $this->hasMany(ItemInstance::class, 'item_id');
  95. }
  96. /**
  97. * 获取拥有该物品的用户
  98. *
  99. * @return HasMany
  100. */
  101. public function users(): HasMany
  102. {
  103. return $this->hasMany(ItemUser::class, 'item_id');
  104. }
  105. /**
  106. * 获取宝箱内容配置
  107. *
  108. * @return HasMany
  109. */
  110. public function chest_contents(): HasMany
  111. {
  112. return $this->hasMany(ItemChestContent::class, 'chest_id', 'id');
  113. }
  114. /**
  115. * 宝箱开启消耗配置
  116. *
  117. * @return HasMany
  118. */
  119. public function chest_costs(): HasMany
  120. {
  121. return $this->hasMany(ItemChestOpenCost::class, 'chest_id', 'id');
  122. }
  123. }