Example #1
0
 /**
  * 加载缓存数据
  */
 protected static function loadCache($moduleName, $param = array(), $num = 0)
 {
     if (!self::$cache) {
         self::$cache = ZOL_DAL_RefreshCacheLoader::getInstance();
     }
     $data = self::$cache->loadCacheObject($moduleName, $param);
     if ($num && $data && count($data) > $num) {
         $data = array_slice($data, 0, $num, true);
     }
     return $data;
 }
Example #2
0
 /**
  * 得到用户所在地区信息
  */
 public static function getUserArea()
 {
     $ip = self::getClientIpMulti();
     $ipArr = explode(",", $ip);
     $ipNum = count($ipArr);
     $ip = $ipArr[0];
     #这个是加了一个广告代理,所以ip变成三个了,取第一个 2010-06-18
     $cacheObj = ZOL_DAL_RefreshCacheLoader::getInstance();
     $tmpProvinceArr = $cacheObj->loadCacheObject('Province', array());
     $provinceArr = array();
     if ($tmpProvinceArr) {
         foreach ($tmpProvinceArr as $key => $value) {
             $provinceName = ZOL_String::substr($value, 4);
             $provinceArr[$provinceName] = $key;
         }
     }
     $ipName = self::ip2location($ip);
     if (strpos($ipName, '省')) {
         $ipName = explode('省', $ipName);
         $cityName = ZOL_String::substr($ipName[1], 4);
         $provinceName = ZOL_String::substr($ipName[0], 4);
     } else {
         $cityName = '';
         $provinceName = ZOL_String::substr($ipName, 4);
     }
     #省份
     $provinceId = 1;
     if ($cityName && array_key_exists($cityName, $provinceArr)) {
         $provinceId = $provinceArr[$cityName];
     } elseif ($provinceName && array_key_exists($provinceName, $provinceArr)) {
         $provinceId = $provinceArr[$provinceName];
     }
     #城市
     $cityId = 0;
     if ($cityName && $provinceId) {
         $tmpCityArr = $cacheObj->loadCacheObject('City', array('provinceId' => $provinceId));
         foreach ($tmpCityArr as $key => $val) {
             $val = ZOL_String::substr($val, 4);
             if ($val == $cityName) {
                 $cityId = $key;
                 break;
             }
         }
     }
     #locationId获得
     $tmpLocationArr = $cacheObj->loadCacheObject('Location', array('type' => 'LOCATION'));
     $locationArr = array();
     if ($tmpLocationArr) {
         foreach ($tmpLocationArr as $key => $value) {
             $locationName = ZOL_String::substr($value['name'], 4);
             $locationArr[$locationName] = $key;
         }
     }
     #根据省的名称和城市的名称,获得LocationId
     $locationId = 1;
     if ($cityName && isset($locationArr[$cityName])) {
         $locationId = $locationArr[$cityName];
     } elseif ($provinceName && isset($locationArr[$provinceName])) {
         $locationId = $locationArr[$provinceName];
         if (isset($tmpLocationArr[$locationId]['defaultId'])) {
             $locationId = $tmpLocationArr[$locationId]['defaultId'];
         }
     }
     setcookie('userProvinceId', $provinceId, SYSTEM_TIME + 86400, '/', '.zol.com.cn');
     setcookie('userCityId', $cityId, SYSTEM_TIME + 86400, '/', '.zol.com.cn');
     setcookie('userLocationId', $locationId, SYSTEM_TIME + 86400, '/', '.zol.com.cn');
     return array('provinceId' => $provinceId, 'cityId' => $cityId, 'userLocationId' => $locationId);
 }