get($key); } public static function set($key,$val){ $cache = self::getCacheIns(); return $cache->set($key,$val); } public static function getPromoteUserCnt($uid){ $cache = self::getCacheIns(); $userCntSet = $cache->get(self::$Key_PromoteUserCnt); if(empty($userCntSet)){ $userCntSet = array(); } else{ $userCntSet = json_decode($userCntSet,true); } $uNumber = $userCntSet[$uid]; // no data in cache get from db if(empty($uNumber)){ $res = self::getPromoteUserCntDB($uid); $uNumber = (is_array($res))? $res[0]['cnt'] : 0; // update data to cache $userCntSet[$uid] = $uNumber; $cache->set(self::$Key_PromoteUserCnt, json_encode($userCntSet)); } return $uNumber; } private static function getPromoteUserCntDB($uid){ $db = self::getDbIns(); $effectiveLevel = EFFECTIVE_PLAYER_LEVEL; $sql = "select count(id) cnt from onu_promote where uid='$uid' and player_grade =>$effectiveLevel;"; return $db->query($sql); } // set method must be called after get method public static function setPromoteUserCnt($uid,$number){ $cache = self::getCacheIns(); $userCntSet = $cache->get(self::$Key_PromoteUserCnt); $userCntSet = json_decode($userCntSet,true); if(is_array($userCntSet)){ $userCntSet[$uid] = $number; $cache->set(self::$Key_PromoteUserCnt, json_encode($userCntSet)); } } // private static function getDayTimeKey_BJ(){ date_default_timezone_set("Asia/Chongqing"); $today = date("Ymd"); return strtotime($today); } // // one ip can registe at most 5 users for one promote user in 3 days // public static function setUidIpPrmoteCnt_Plus($uid,$ip,$num){ $cache = self::getCacheIns(); $timeKey = self::getDayTimeKey_BJ(); $itemKey = "$uid-$ip"; $dataKey = ''; $dataSet = $cache->get(self::$Key_UidIpPromCntLimit); $dataSet = json_decode($dataSet, true); if(empty($dataSet)) $dataSet = array(); // set time period key if(count($dataSet) == 0){ $dataSet[$timeKey] = array(); $dataKey = $timeKey; } // set new key and clear the first key $oldPeriodKey = NULL; foreach($dataSet as $key=>$val){ // over 3 days if( ($timeKey - $key) >= 259200){ $oldPeriodKey = $key; } else{ $dataKey = $key; } break; } if(!empty($oldPeriodKey)){ $dataSet[$timeKey] = array(); $dataKey = $timeKey; unset($dataSet[$oldPeriodKey]); } // set item value if(empty($dataSet[$dataKey][$itemKey])){ $dataSet[$dataKey][$itemKey] = $num; } else{ $dataSet[$dataKey][$itemKey] ++; } // update cache $cache->set(self::$Key_UidIpPromCntLimit,json_encode($dataSet)); } public static function getUidIpPrmoteCnt($uid,$ip){ $cache = self::getCacheIns(); $itemKey = "$uid-$ip"; $dataKey = ''; $dataSet = $cache->get(self::$Key_UidIpPromCntLimit); $dataSet = json_decode($dataSet, true); if(empty($dataSet)) return 0; foreach($dataSet as $key=>$val){ $dataKey = $key; } return $dataSet[$dataKey][$itemKey]; } //Class end }