Exemple #1
0
 /**
  * 用户缓存管理单例
  *
  * @access public
  * @param void
  * @return Memcache 单例对象
  */
 private static function getCacheInstance()
 {
     $get_instance = self::$cache_instance;
     if (is_null(self::$cache_instance)) {
         self::$cache_instance = MemcacheManager::instance();
     }
     return self::$cache_instance;
 }
 /**
  * get Instance (Singleton)
  *
  * @return MemcacheManager
  */
 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new MemcacheManager();
     }
     if (self::$instance->cache == null) {
         self::$instance->setup();
     }
     return self::$instance;
 }
Exemple #3
0
 /**
  * API:获取大事件信息
  *
  * @access public
  * @param 无
  * @return JsonView 响应json
  */
 public function getBigMessage()
 {
     $requestParam = $this->getAllParameters();
     Logger::debug('requestParam:' . print_r($requestParam, true));
     $requestJsonParam = $this->getDecodedJsonRequest();
     Logger::debug('requestJsonParam:' . print_r($requestJsonParam, true));
     // 取缓存数据
     $cache = MemcacheManager::instance();
     $memcacheArr = $cache->get(self::BULLETIN_LIST);
     if ($memcacheArr) {
         $messageArr = $memcacheArr;
     } else {
         // 读取csv类
         $csv = new Parsecsv();
         $dir = IniFileManager::getRootDir() . "files/csv/" . self::BULLETIN_LIST . ".csv";
         $csv->auto($dir);
         $messageArr = $csv->data;
     }
     return $messageArr;
 }
Exemple #4
0
 /**
  * API:读取CSv
  *
  * @access public
  * @param $file 路径 $str 读取条件OR
  * @return array()
  */
 public function readCsv($file, $str = null)
 {
     //先读缓存,foreach需要的数据,没有找到,在用condition读取CSV
     $fileName = basename($file, ".csv");
     /*$memcached = new Memcache();
       $memcached->connect("localhost", 11211);
       $CharacterDataArr=$memcached->get( $fileName );*/
     $cache = MemcacheManager::instance();
     $CharacterDataArr = $cache->get($fileName);
     if (!$CharacterDataArr) {
         $csv = new Parsecsv();
         $csv->conditions = $str;
         $csv->auto($file);
         $CharacterDataArr = $csv->data;
         return $CharacterDataArr;
     } else {
         if (is_null($str)) {
             return $CharacterDataArr;
         }
         $conditionArr = explode(" OR ", $str);
         foreach ($conditionArr as $key => $value) {
             $condition = explode(" = ", $value);
             $message[$key][$condition[0]] = $condition[1];
         }
         foreach ($message as $key => $value) {
             foreach ($value as $key2 => $value2) {
                 foreach ($CharacterDataArr as $key3 => $value3) {
                     if ($value2 == $CharacterDataArr[$key3][$key2]) {
                         $arr[] = $CharacterDataArr[$key3];
                     }
                 }
             }
         }
         return $arr;
     }
 }
Exemple #5
0
 /**
  * API:获取签到信息
  *
  * @access public
  * @param mixed $login_info 签到缓存信息
  * @return $loginArr 返回签到信息数组
  */
 public function getUserLoginInfo($login_info = "")
 {
     // 无初始数据
     if ($login_info == "") {
         $loginArr['con_day'] = 0;
         $loginArr['total_day'] = 0;
         // $loginArr['time'] = time();
         $loginArr['type'] = 0;
     } else {
         // 非当天首次登陆
         if ($login_info['time'] > strtotime(date('Y-m-d', time()))) {
             return false;
         }
         $loginArr['con_day'] = $login_info['con_day'];
         $loginArr['total_day'] = $login_info['total_day'];
         //$loginArr['time'] = time();
         $loginArr['type'] = 0;
         // // 非连续签到
         // if( strtotime( date( 'Y-m-d',time() ) ) - $login_info['check_time'] > 86400 )
         // {
         //     $loginArr['con_day'] = 1;
         // }
     }
     // 获取签到奖励内容
     $cache = MemcacheManager::instance();
     $memcacheArr = $cache->get(self::LOGIN_FILE);
     if ($memcacheArr) {
         $messageArr = $memcacheArr;
     } else {
         // 读取csv类
         $dir = IniFileManager::getRootDir() . "files/csv/" . self::LOGIN_FILE . ".csv";
         /*$str = "chest_id = " . 1;
           $messageArr = Util::readCsv( $dir, $str );*/
         $csv = new Parsecsv();
         $csv->auto($dir);
         $messageArr = $csv->data;
         /*echo "<pre>";var_dump($messageArr);exit;
         
                     $loginArr['reward'] = $messageArr[0];*/
     }
     /********************* 更新奖励列表 *****************/
     // 统计箱子个数
     $num = 1;
     foreach ($messageArr as $key => $value) {
         if ($value['chest_id'] == $messageArr[$key + 1]['chest_id']) {
             $rewardNumArr[$value['chest_id']] = ++$num;
         } else {
             $num = 1;
         }
     }
     // 随机箱子内容
     $num = 0;
     foreach ($rewardNumArr as $key => $value) {
         $rewardArr[$key] = $messageArr[$num + rand(0, $value - 1)];
         $probabilityArr[$key] = $rewardArr[$key]['probability'];
         $num = $num + $value;
     }
     $checkNum = Util::extractRandomAnswer($probabilityArr);
     $loginArr['rewardArr']['check'] = $checkNum;
     $loginArr['rewardArr']['box_info'] = $rewardArr;
     return $loginArr;
 }