| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- namespace App\Module\GameItems\Models;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use UCore\ModelCore;
- /**
- * 宝箱配置
- *
- * field start
- * @property int $id 记录ID,主键
- * @property int $item_id 宝箱物品ID,外键关联kku_item_items表
- * @property int $consume_group_id 消耗组ID,外键关联kku_game_consume_groups表(可为空)
- * @property int $reward_group_id 奖励组ID,外键关联kku_game_reward_groups表
- * @property int $condition_group_id 条件组ID,外键关联kku_game_condition_groups表(可为空)
- * @property bool $is_active 是否激活(0:否, 1:是)
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * field end
- */
- class ItemChestConfig extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'item_chest_configs';
- // attrlist start
- protected $fillable = [
- 'id',
- 'item_id',
- 'consume_group_id',
- 'reward_group_id',
- 'condition_group_id',
- 'is_active',
- ];
- // attrlist end
- /**
- * 应该被转换为原生类型的属性
- *
- * @var array
- */
- protected $casts = [
- 'is_active' => 'boolean',
- ];
- /**
- * 获取关联的宝箱物品
- *
- * @return BelongsTo
- */
- public function item(): BelongsTo
- {
- return $this->belongsTo(Item::class, 'item_id');
- }
- /**
- * 获取关联的消耗组
- *
- * @return BelongsTo
- */
- public function consumeGroup(): BelongsTo
- {
- return $this->belongsTo(\App\Module\Game\Models\GameConsumeGroup::class, 'consume_group_id');
- }
- /**
- * 获取关联的奖励组
- *
- * @return BelongsTo
- */
- public function rewardGroup(): BelongsTo
- {
- return $this->belongsTo(\App\Module\Game\Models\GameRewardGroup::class, 'reward_group_id');
- }
- /**
- * 获取关联的条件组
- *
- * @return BelongsTo
- */
- public function conditionGroup(): BelongsTo
- {
- return $this->belongsTo(\App\Module\Game\Models\GameConditionGroup::class, 'condition_group_id');
- }
- /**
- * 获取消耗组名称
- *
- * @return string
- */
- public function getConsumeGroupNameAttribute(): string
- {
- return $this->consumeGroup ? $this->consumeGroup->name : '无消耗';
- }
- /**
- * 获取奖励组名称
- *
- * @return string
- */
- public function getRewardGroupNameAttribute(): string
- {
- return $this->rewardGroup ? $this->rewardGroup->name : '未配置';
- }
- /**
- * 获取条件组名称
- *
- * @return string
- */
- public function getConditionGroupNameAttribute(): string
- {
- return $this->conditionGroup ? $this->conditionGroup->name : '无条件';
- }
- /**
- * 检查配置是否完整
- *
- * @return bool
- */
- public function isConfigComplete(): bool
- {
- return $this->reward_group_id && $this->is_active;
- }
- /**
- * 获取配置状态文本
- *
- * @return string
- */
- public function getStatusTextAttribute(): string
- {
- if (!$this->is_active) {
- return '未激活';
- }
-
- if (!$this->reward_group_id) {
- return '缺少奖励组';
- }
-
- return '正常';
- }
- }
|