'integer', 'pity_threshold' => 'integer', 'last_attempt_at' => 'datetime', 'last_hit_at' => 'datetime', ]; /** * 获取关联的用户 * * @return BelongsTo */ public function user(): BelongsTo { return $this->belongsTo(\App\Models\User::class, 'user_id'); } /** * 获取关联的奖励组 * * @return BelongsTo */ public function rewardGroup(): BelongsTo { return $this->belongsTo(GameRewardGroup::class, 'reward_group_id'); } /** * 获取关联的奖励项 * * @return BelongsTo */ public function rewardItem(): BelongsTo { return $this->belongsTo(GameRewardItem::class, 'reward_item_id'); } /** * 检查是否达到保底阈值 * * @return bool */ public function isAtPityThreshold(): bool { return $this->count >= $this->pity_threshold && $this->pity_threshold > 0; } /** * 增加计数 * * @return void */ public function incrementCount(): void { $this->increment('count'); $this->update(['last_attempt_at' => now()]); } /** * 重置计数 * * @return void */ public function resetCount(): void { $this->update([ 'count' => 0, 'last_hit_at' => now(), ]); } /** * 获取调整后的权重 * * @param float $baseWeight 基础权重 * @param float $weightFactor 权重因子 * @return float */ public function getAdjustedWeight(float $baseWeight, float $weightFactor): float { if ($this->pity_threshold <= 0) { return $baseWeight; } // 如果达到保底阈值,权重设为极大值确保必中 if ($this->isAtPityThreshold()) { return 999999.0; } // 根据当前计数调整权重 $progressRatio = $this->count / $this->pity_threshold; $adjustedWeight = $baseWeight * (1 + $progressRatio * $weightFactor); return $adjustedWeight; } }