Exemplo n.º 1
0
 /**
  * API:获取世界排行
  *
  * @access public
  * @param 无
  * @return JsonView 响应json
  */
 public function getWorldRank($user_id)
 {
     UserCache::deleteAllUserCache(Constants::WORLD_RANK);
     //$rankArr = UserCache::getAllUserCache( Constants::WORLD_RANK );
     $friendList = FriendAction::getFriend($user_id);
     if (!$rankArr) {
         //$worldRank = rankModel::selectlimit( $wheres = "",$limit = array( "page" => 1, "limit" => Constants::WORLD_RANKY_MAX_NUM ), $columns = array( "n_id", 'n_battle', 'n_max_checkpoint' ) );
         $worldRank = RankModel::getRank(Constants::WORLD_RANKY_MAX_NUM);
         foreach ($worldRank as $key => $value) {
             $result['max_checkpoint'] = $value['n_max_checkpoint'];
             $result['battle'] = $value['n_battle'];
             $result['n_id'] = $value['n_id'];
             $rankArr[$value['n_id']] = $result;
         }
         //echo "<pre>";var_dump($worldRank);exit;
         UserCache::setAllUserCache(Constants::WORLD_RANK, $rankArr);
     }
     // uasort($rankArr, function($a, $b) {
     //     $al = $a['max_checkpoint'];
     //     $bl = $b['max_checkpoint'];
     //     if ($al == $bl)
     //     {
     //         $al2 = $a['battle'];
     //         $bl2 = $b['battle'];
     //         return ($al2 > $bl2) ? -1 : 1;
     //     }
     //     return ($al > $bl) ? -1 : 1;
     // });
     $rankArr = array_slice($rankArr, 0, Constants::WORLD_RANKY_MAX_NUM);
     //echo "<pre>";
     foreach ($rankArr as $key => $value) {
         $now_id = $value['n_id'];
         $userInfo = UserCache::getAllUserCache($now_id);
         if (!$userInfo['n_id'] || !$userInfo['n_head'] || !$userInfo['s_name'] || !$userInfo['n_sex'] || !$userInfo['n_level'] || !$userInfo['n_max_checkpoint']) {
             $userInfo = UserAction::iniUserInfo($now_id);
         }
         //var_dump($userInfo);echo "<br />";
         $rankInfo['id'] = $userInfo['n_id'];
         $rankInfo['head'] = $userInfo['n_head'];
         $rankInfo['name'] = $userInfo['s_name'];
         $rankInfo['sex'] = $userInfo['n_sex'];
         $rankInfo['level'] = $userInfo['n_level'];
         $rankInfo['checkpoint'] = $userInfo['n_max_checkpoint'];
         $rankInfo['battle'] = $value['battle'];
         // 好友列表加入缓存后此处需要修改
         //$rankInfo['friend_type'] = FriendModel::isFriend( $user_id, $now_id );
         if ($friendList && in_array($now_id, $friendList)) {
             $rankInfo['friend_type'] = 1;
         } else {
             $rankInfo['friend_type'] = 0;
         }
         $worldRankInfo[$key + 1] = $rankInfo;
     }
     return $worldRankInfo;
 }
Exemplo n.º 2
0
 /**
  * API:初始化用户数据
  *
  * @access public
  * @param 无
  * @return JsonView 响应json
  */
 public function iniUserInfo($user_id)
 {
     $userInfo = UserModel::getUserInfo($user_id);
     $userInfo['s_checkpoint_info'] = unserialize($userInfo['s_checkpoint_info']);
     $userInfo['s_role_info'] = unserialize($userInfo['s_role_info']);
     $userInfo['s_general_info'] = unserialize($userInfo['s_general_info']);
     $userInfo['s_item_info'] = unserialize($userInfo['s_item_info']);
     $userInfo['s_task_info'] = unserialize($userInfo['s_task_info']);
     $userInfo['s_achievement_info'] = unserialize($userInfo['s_achievement_info']);
     $userInfo['s_login_info'] = unserialize($userInfo['s_login_info']);
     UserCache::setAllUserCache($user_id, $userInfo);
     return $userInfo;
 }