清水 FALSE=> 默认) */ public function showBook($channel_id, $uid='', $ip='') { LogService::info('WaterBookService:params:channel_id:' . $channel_id . ',uid:' . $uid . ',IP:' . $ip); $white_uids = array_filter(explode(',', Config::get('site.white_water_uids'))); if ($white_uids && in_array($uid, $white_uids)) { LogService::info('WaterBookService:params:清水书籍白名单用户'); return false; } $result = false; // 读取Hash中的规则 $waterRule = array_filter(Redis::instance()->hMGet(CacheConstants::LIGHT_RULE, ['*', $channel_id])); if($waterRule){ // 所有城市CODE $aim_city = []; foreach ($waterRule as $k=>$item) { $item_arr = json_decode($item, true); $waterRule[$k] = $item_arr['c'] ?? ''; } $waterRule = array_filter($waterRule); // 判断 * 的情况 if (!empty($waterRule['*'])) { if ($waterRule['*'] == '*') { LogService::info('WaterBookService:params:清水,*命中'); return true; } else { $aim_city = array_merge($aim_city, explode(',', $waterRule['*'])); } } // 校验渠道是否开启了清水 if (!empty($waterRule[$channel_id])) { if ($waterRule[$channel_id] == '*') { LogService::info('WaterBookService:params:清水,渠道城市为*命中'); return true; } else { $aim_city = array_merge($aim_city, explode(',', $waterRule[$channel_id])); } } $aim_city = array_unique(array_filter($aim_city)); if (!empty($ip)) { // ip 不为空,解析为 城市code $cityCode = Ip::citycode($ip); // 判断城市是否清水 if (in_array($cityCode, $aim_city)) { LogService::info('WaterBookService:params:清水,根据城市命中'); return true; } }else{ // 没有IP参数,说明是微信回调过来的,前台页面进来都需要传IP if(!empty($aim_city)){ LogService::info('WaterBookService:params:微信回调,根据城市命中'); // 微信回调,只要有匹配的城市,返回清水 TRUE return true; } } } if (!empty($uid)) { // uid 不为空,判断是否有uid 限制 $water_uids = Config::get('site.water_uids'); if (in_array($uid, explode(',', $water_uids))) { LogService::info('WaterBookService:params:清水,根据uid命中'); return true; } } return $result; } }