| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace App\Module\GameItems\Models;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- use UCore\ModelCore;
- /**
- * 宝箱内容配置
- *
- * field start
- * @property int $id 记录ID,主键
- * @property int $chest_id 宝箱物品ID,外键关联kku_item_items表
- * @property int $item_id 可能获得的物品ID,外键关联kku_item_items表(与group_id二选一)
- * @property int $group_id 物品组ID,外键关联kku_item_groups表(与item_id二选一)
- * @property int $min_quantity 最小数量
- * @property int $max_quantity 最大数量
- * @property float $weight 权重,决定获取概率
- * @property bool $allow_duplicate 是否允许在同一宝箱中重复掉落(0:不允许, 1:允许)
- * @property int $pity_count 保底次数,当玩家连续未获得该内容达到次数后必定获得(0表示不启用保底)
- * @property float $pity_weight_factor 保底权重因子,用于递增概率计算(默认1.0)
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * field end
- */
- class ItemChestContent extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'item_chest_contents';
- // attrlist start
- protected $fillable = [
- 'id',
- 'chest_id',
- 'item_id',
- 'group_id',
- 'min_quantity',
- 'max_quantity',
- 'weight',
- 'allow_duplicate',
- 'pity_count',
- 'pity_weight_factor',
- ];
- // attrlist end
- /**
- * 应该被转换为原生类型的属性
- *
- * @var array
- */
- protected $casts = [
- 'weight' => 'float',
- 'min_quantity' => 'integer',
- 'max_quantity' => 'integer',
- 'allow_duplicate' => 'boolean',
- 'pity_count' => 'integer',
- 'pity_weight_factor' => 'float',
- ];
- /**
- * 获取关联的宝箱物品
- *
- * @return BelongsTo
- */
- public function chest(): BelongsTo
- {
- return $this->belongsTo(Item::class, 'chest_id');
- }
- /**
- * 获取关联的物品(如果有)
- *
- * @return BelongsTo
- */
- public function item(): BelongsTo
- {
- return $this->belongsTo(Item::class, 'item_id');
- }
- /**
- * 获取关联的物品组(如果有)
- *
- * @return BelongsTo
- */
- public function group(): BelongsTo
- {
- return $this->belongsTo(ItemGroup::class, 'group_id');
- }
- /**
- * 获取用户对该宝箱内容的保底计数
- *
- * @return HasMany
- */
- public function pityTimes(): HasMany
- {
- return $this->hasMany(ItemPityTime::class, 'chest_content_id');
- }
- }
|