request->param('channel_id') ?? 0; $uid = (integer)$this->request->param('uid') ?? 0; // region 参数校验 if($channel_id == 0){ $this->error('参数channel_id错误'); } if($uid == 0){ $this->error('参数uid错误'); } // endregion // 广告库,所有广告计划,包括广告素材 $adFull = json_decode(Redis::instance()->get(AdConstants::AD_FULL), true); $target_data = []; if($adFull){ $target_data = $adFull; // (筛选所有非福利广告计划数据) 所有广告位 () $postions_arr = AdPlanService::instance()->getAllAdPositions(); if ($postions_arr) { foreach ($postions_arr as $k => $postion) { if (isset($target_data['positions'][$postion])) { $redisIdx = Redis::getRedisIndex(AdConstants::AD_JU_KEY); $redis = Redis::getRedisConnect($redisIdx); $pipe = $redis->multi(\Redis::PIPELINE); //$pipe = Redis::instance()->multi(\Redis::PIPELINE); foreach ($target_data['positions'][$postion] as $ad_id => $ad_plan) { $redis_key = AdConstants::AD_JU_KEY . $ad_id . ':' . $channel_id; $pipe->sIsMember($redis_key, $uid); } $rst = $pipe->exec(); $keys_arr = array_keys($target_data['positions'][$postion]); foreach ($rst as $sub_key => $value) { $real_key = $keys_arr[$sub_key]; if (isset($target_data['positions'][$postion][$real_key])) { $group_type = $target_data['positions'][$postion][$real_key]['group_type']; // 广告计划关联的用户组类型, 0 => 全部 1=>指定用户ID 2=>用户条件筛选 // $goup_type == 0 如果广告计划关联的是全部用户,则不删除 if ($group_type > 0) { // $value = true => 是集合中的成员 if (!$value) { //如果用户不在集合中, 删除位置 //array_splice($target_data['positions'][$postion], $sub_key, 1); unset($target_data['positions'][$postion][$real_key]); } } } } } } } // 筛选所有福利广告计划数据 if (isset($target_data['welfare_plans'])) { $redisIdx = Redis::getRedisIndex(AdConstants::AD_JU_KEY); $redis = Redis::getRedisConnect($redisIdx); $pipe = $redis->multi(\Redis::PIPELINE); foreach ($target_data['welfare_plans'] as $ad_id => $ad_plan) { $redis_key = AdConstants::AD_JU_KEY . $ad_id . ':' . $channel_id; $pipe->sIsMember($redis_key, $uid); } $rst = $pipe->exec(); $keys_arr = array_keys($target_data['welfare_plans']); foreach ($rst as $sub_key => $value) { $real_key = $keys_arr[$sub_key]; if (isset($target_data['welfare_plans'][$real_key])) { $group_type = $target_data['welfare_plans'][$real_key]['group_type']; // 广告计划关联的用户组类型, 0 => 全部 1=>指定用户ID 2=>用户条件筛选 // $goup_type == 0 如果广告计划关联的是全部用户,则不删除 if ($group_type > 0) { // $value = true => 是集合中的成员 if (!$value) { //如果用户不在集合中, 删除位置 unset($target_data['welfare_plans'][$real_key]); } } } } } // END 筛选所有福利广告计划数据 } $this->success('success', $target_data); } /** * API接口:用户点击福利广告后,记录用户信息 * @param channel_id 渠道ID * @param uid 用户ID */ public function welfareDot() { $uid = (integer)$this->request->param('uid') ?? 0; //$channel_id = (integer)$this->request->param('channel_id') ?? 0; if($uid == 0){ $this->error('参数uid错误'); } $redis_key = AdConstants::AD_WELFARE_USER . date('Ymd') . ':' . $uid; if (!Redis::instance()->get($redis_key)) { //Redis::instance()->set($redis_key, 1, 86400); Redis::instance()->set($redis_key, $uid, 86400); } // region 参数校验 /*if($channel_id == 0){ $this->error('参数channel_id错误'); }*/ // 记录用户点击 /*$redis_key = AdConstants::AD_WELFARE . $channel_id; Redis::instance()->sAdd($redis_key, $uid); // 计算过期时间 24点过期 $tomorrow_time = strtotime(date('Y-m-d 00:00:00', strtotime("+1 day"))); $ttl = $tomorrow_time - time(); Redis::instance()->expire($redis_key, $ttl);*/ $this->success('success'); } }