diff --git a/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php b/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php index 73c579e..733360f 100644 --- a/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php +++ b/application/api/model/BlindBoxTurntableGiftDrawWorldNew.php @@ -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,