ItemChestConfig.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 $item_id 宝箱物品ID,外键关联kku_item_items表
  11. * @property int $consume_group_id 消耗组ID,外键关联kku_game_consume_groups表(可为空)
  12. * @property int $reward_group_id 奖励组ID,外键关联kku_game_reward_groups表
  13. * @property int $condition_group_id 条件组ID,外键关联kku_game_condition_groups表(可为空)
  14. * @property bool $is_active 是否激活(0:否, 1:是)
  15. * @property \Carbon\Carbon $created_at 创建时间
  16. * @property \Carbon\Carbon $updated_at 更新时间
  17. * field end
  18. */
  19. class ItemChestConfig extends ModelCore
  20. {
  21. /**
  22. * 与模型关联的表名
  23. *
  24. * @var string
  25. */
  26. protected $table = 'item_chest_configs';
  27. // attrlist start
  28. protected $fillable = [
  29. 'id',
  30. 'item_id',
  31. 'consume_group_id',
  32. 'reward_group_id',
  33. 'condition_group_id',
  34. 'is_active',
  35. ];
  36. // attrlist end
  37. /**
  38. * 应该被转换为原生类型的属性
  39. *
  40. * @var array
  41. */
  42. protected $casts = [
  43. 'is_active' => 'boolean',
  44. ];
  45. /**
  46. * 获取关联的宝箱物品
  47. *
  48. * @return BelongsTo
  49. */
  50. public function item(): BelongsTo
  51. {
  52. return $this->belongsTo(Item::class, 'item_id');
  53. }
  54. /**
  55. * 获取关联的消耗组
  56. *
  57. * @return BelongsTo
  58. */
  59. public function consumeGroup(): BelongsTo
  60. {
  61. return $this->belongsTo(\App\Module\Game\Models\GameConsumeGroup::class, 'consume_group_id');
  62. }
  63. /**
  64. * 获取关联的奖励组
  65. *
  66. * @return BelongsTo
  67. */
  68. public function rewardGroup(): BelongsTo
  69. {
  70. return $this->belongsTo(\App\Module\Game\Models\GameRewardGroup::class, 'reward_group_id');
  71. }
  72. /**
  73. * 获取关联的条件组
  74. *
  75. * @return BelongsTo
  76. */
  77. public function conditionGroup(): BelongsTo
  78. {
  79. return $this->belongsTo(\App\Module\Game\Models\GameConditionGroup::class, 'condition_group_id');
  80. }
  81. /**
  82. * 获取消耗组名称
  83. *
  84. * @return string
  85. */
  86. public function getConsumeGroupNameAttribute(): string
  87. {
  88. return $this->consumeGroup ? $this->consumeGroup->name : '无消耗';
  89. }
  90. /**
  91. * 获取奖励组名称
  92. *
  93. * @return string
  94. */
  95. public function getRewardGroupNameAttribute(): string
  96. {
  97. return $this->rewardGroup ? $this->rewardGroup->name : '未配置';
  98. }
  99. /**
  100. * 获取条件组名称
  101. *
  102. * @return string
  103. */
  104. public function getConditionGroupNameAttribute(): string
  105. {
  106. return $this->conditionGroup ? $this->conditionGroup->name : '无条件';
  107. }
  108. /**
  109. * 检查配置是否完整
  110. *
  111. * @return bool
  112. */
  113. public function isConfigComplete(): bool
  114. {
  115. return $this->reward_group_id && $this->is_active;
  116. }
  117. /**
  118. * 获取配置状态文本
  119. *
  120. * @return string
  121. */
  122. public function getStatusTextAttribute(): string
  123. {
  124. if (!$this->is_active) {
  125. return '未激活';
  126. }
  127. if (!$this->reward_group_id) {
  128. return '缺少奖励组';
  129. }
  130. return '正常';
  131. }
  132. }