盲盒转盘优化-重构-调试

This commit is contained in:
2025-10-29 12:55:17 +08:00
parent 678f2f5cea
commit d6eacc53ce

View File

@@ -141,7 +141,7 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model
$pan_total_remaining = $this->getCachedPanTotalRemaining($gift_bag_id); //剩余数量
//获取可用礼物
$availableGifts = $this->getAvailableGifts($gift_bag_id,$pan_total_draw_times+$total_num);
$giftInfoMap = cache::get("pan_gift_info_map".$gift_bag_id); //预加载礼物信息
$giftInfoMap = $this->getCachedPanGiftInfoMap($gift_bag_id);//预加载礼物信息
$remaining_available_gifts = [];
if (empty($availableGifts) ||$pan_total_remaining ==0) {
//重置奖池
@@ -589,6 +589,31 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model
}
return $xlh_periods_num;
}
/**
* 获取奖池总库存
*/
private function getCachedPanGiftInfoMap($gift_bag_id) {
$cacheKey = "pan_gift_info_map".$gift_bag_id;
$gift_info_map = Cache::get($cacheKey);
if(!$gift_info_map) {
$gift_bag_detail = Db::name("vs_gift_bag_detail")
->field('foreign_id')
->where(['gift_bag_id' => $gift_bag_id])
->select();
$gift_info_map = [];
$gift_ids = array_unique(array_column($gift_bag_detail, 'foreign_id'));
if (!empty($gift_ids)) {
foreach ($gift_ids as $gift_id) {
$gift_info_map[$gift_id] = db::name("vs_gift")
->field('gid,gift_name,gift_price,base_image')
->where(['gid' => $gift_id])
->find();
}
}
Cache::set($cacheKey, $gift_info_map, $this->cache_time);
}
return $gift_info_map;
}
//开始更新操作:
/**
@@ -1172,7 +1197,7 @@ class BlindBoxTurntableGiftDrawWorldNew extends Model
// 批量插入礼包发放记录
$gift_records = [];
$periods = $this->getCachedXlhPeriods('get') ?? 0;
$giftInfoMap =cache::get("pan_gift_info_map".$gift_bag_id);
$giftInfoMap = $this->getCachedPanGiftInfoMap($gift_bag_id);
foreach ($drawn_gifts as $gift_id => $count) {
$gift_records[] = [
'user_id' => $user_id,