临时加-限制特定用户抽中巡乐会主奖品
This commit is contained in:
@@ -1136,10 +1136,10 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model
|
||||
}
|
||||
}
|
||||
// 从可用礼物中选择
|
||||
$selected_gift = $this->selectGiftFromAvailable($availableGifts);
|
||||
$selected_gift = $this->selectGiftFromAvailable($availableGifts,$user_id);
|
||||
if (!$selected_gift) {
|
||||
$gift_bag_detail = $this->resetPoolAndReload($gift_bag_id);
|
||||
$selected_gift = $this->selectGiftFromAvailable($gift_bag_detail);
|
||||
$selected_gift = $this->selectGiftFromAvailable($gift_bag_detail,$user_id);
|
||||
if(!$selected_gift){
|
||||
throw new \Exception('预计算抽奖失败,重置后无可用礼物');
|
||||
}
|
||||
@@ -1311,9 +1311,12 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model
|
||||
/**
|
||||
* 巡乐会抽奖-从可用礼物中选择一个
|
||||
*/
|
||||
private function selectGiftFromAvailable(array &$available_gifts)
|
||||
private function selectGiftFromAvailable(array &$available_gifts, $user_id = 0)
|
||||
{
|
||||
$remaining = array_sum(array_column($available_gifts, 'remaining_number'));
|
||||
// 添加针对特定用户和礼物的概率调整逻辑
|
||||
$adjusted_gifts = $this->adjustGiftProbabilities($available_gifts, $user_id);
|
||||
|
||||
$remaining = array_sum(array_column($adjusted_gifts, 'remaining_number'));
|
||||
if ($remaining <= 0) {
|
||||
return null;
|
||||
}
|
||||
@@ -1325,7 +1328,7 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model
|
||||
$rand_value = mt_rand(1, $remaining);
|
||||
$current_sum = 0;
|
||||
|
||||
foreach ($available_gifts as $gift) {
|
||||
foreach ($adjusted_gifts as $gift) {
|
||||
if ($gift['remaining_number'] <= 0) {
|
||||
continue;
|
||||
}
|
||||
@@ -1340,6 +1343,52 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model
|
||||
|
||||
return $selected_gift;
|
||||
}
|
||||
|
||||
/** [新加]
|
||||
* 调整特定用户和礼物的概率
|
||||
* @param array $gifts 可用礼物列表
|
||||
* @param int $user_id 用户ID
|
||||
* @return array 调整后的礼物列表
|
||||
*/
|
||||
private function adjustGiftProbabilities(array $gifts, $user_id = 0)
|
||||
{
|
||||
// 如果没有指定用户或该用户没有特殊概率调整,则直接返回原数组
|
||||
if ($user_id <= 0 || !isset($probability_adjustments[$user_id])) {
|
||||
return $gifts;
|
||||
}
|
||||
|
||||
$ext = $this->getCachedGiftBag(13); //获取转盘信息
|
||||
$selected_gift_id = $ext['locking_condition']['selected_gift_id'];
|
||||
// 定义需要降低概率的用户和礼物组合
|
||||
// 格式: [user_id => [gift_id => reduction_factor]]
|
||||
// reduction_factor 是概率降低倍数,例如 0.5 表示概率减半
|
||||
$probability_adjustments = [
|
||||
// 示例:用户ID为1001的用户抽中礼物ID为2001的概率降低为原来的50%
|
||||
// 1001 => [2001 => 0.5],
|
||||
|
||||
//测试数据
|
||||
20060 => [$selected_gift_id => 0.3],
|
||||
|
||||
// 在这里可以添加更多规则 【正式规则】
|
||||
// 21222 => [$selected_gift_id => 0.3],
|
||||
// 21259 => [$selected_gift_id => 0.3],
|
||||
];
|
||||
|
||||
$adjusted_gifts = [];
|
||||
foreach ($gifts as $gift) {
|
||||
$adjusted_gift = $gift;
|
||||
// 如果该礼物需要对当前用户降低概率
|
||||
if (isset($probability_adjustments[$user_id][$gift['foreign_id']])) {
|
||||
// 降低该礼物的剩余数量权重(相当于降低被抽中的概率)
|
||||
$reduction_factor = $probability_adjustments[$user_id][$gift['foreign_id']];
|
||||
$adjusted_gift['remaining_number'] = max(1, intval($gift['remaining_number'] * $reduction_factor));
|
||||
}
|
||||
$adjusted_gifts[] = $adjusted_gift;
|
||||
}
|
||||
|
||||
return $adjusted_gifts;
|
||||
}
|
||||
|
||||
/**
|
||||
* 巡乐会抽奖-计算结束时间
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user