예제 #1
0
 /**
  * API:购买商城物品
  *
  * @access public
  * @param 无
  * @return JsonView 响应json
  */
 public function exeBuyMall()
 {
     $requestParam = $this->getAllParameters();
     Logger::debug('requestParam:' . print_r($requestParam, true));
     $requestJsonParam = $this->getDecodedJsonRequest();
     Logger::debug('requestJsonParam:' . print_r($requestJsonParam, true));
     $user_id = $requestParam['user_id'];
     $mall_id = $requestJsonParam['mall_id'];
     $session_key = $requestParam['session_key'];
     $str = "mall_id = " . $mall_id;
     $file = IniFileManager::getRootDir() . "/files/csv/mall.csv";
     $itemInfo = CharacterAction::readCsv($file, $str);
     $price_type = self::$price_type;
     //余额判断
     $type1 = $price_type[$itemInfo[0]['price_type']];
     $type2 = $price_type[$itemInfo[0]['buy_type']];
     $money1 = UserCache::getByKey($user_id, $type1);
     $money2 = UserCache::getByKey($user_id, $type2);
     if (!$money1) {
         $userInfo = BuyPropModel::getUserInfo($user_id);
         $money1 = $userInfo[$type1];
     }
     if (!$money2) {
         $userInfo = BuyPropModel::getUserInfo($user_id);
         $money2 = $userInfo[$type2];
     }
     $money1 = $money1 - $itemInfo[0]['price_num'];
     $money2 = $money2 + $itemInfo[0]['buy_num'];
     if ($money1 < 0) {
         $messageArr['session_key'] = CharacterModel::setSessionKey($user_id, $session_key);
         $messageArr['error'] = "人生果/钻石不足!";
         $view = new JsonView();
         return $this->getViewByJson($view, $messageArr, 0, "buy_prop/buy_mall");
     }
     //任务成就统计
     if ($type2 == $price_type[1]) {
         TaskAndAchieveAction::taskStatistic($user_id, array('reward' => $itemInfo[0]['buy_num']));
     }
     if ($type1 == $price_type[1]) {
         TaskAndAchieveAction::achieveStatistic($user_id, array('cost' => $itemInfo[0]['price_num']));
     }
     //购买体力是更新体力时间
     if ($type2 == $price_type[3]) {
         $thewArr['n_thew'] = $money2;
         $thewArr['n_refresh_time'] = UserCache::getBykey($user_id, 'n_refresh_time');
         if (!$thewArr['n_refresh_time']) {
             $userInfo = MailModel::getUserInfo($user_id);
             $thewArr['n_refresh_time'] = $userInfo['n_refresh_time'];
         }
         $getArr = UserAction::refreshThew($thewArr);
         if (!$getArr) {
             $res = CharacterModel::update($thewArr, array('n_id' => $user_id));
             UserCache::setByKey($user_id, 'n_thew', $thewArr['n_thew']);
             UserCache::setByKey($user_id, 'n_refresh_time', $thewArr['n_refresh_time']);
         } else {
             $res = CharacterModel::update($getArr, array('n_id' => $user_id));
             UserCache::setByKey($user_id, 'n_thew', $getArr['n_thew']);
             UserCache::setByKey($user_id, 'n_refresh_time', $getArr['n_refresh_time']);
         }
         $res = BuyPropModel::update(array($type1 => $money1), array('n_id' => $user_id));
         UserCache::setByKey($user_id, $type1, $money1);
     } else {
         $res = BuyPropModel::update(array($type1 => $money1, $type2 => $money2), array('n_id' => $user_id));
         UserCache::setByKey($user_id, $type1, $money1);
         UserCache::setByKey($user_id, $type2, $money2);
     }
     $messageArr['moneyInfo'] = BuyPropModel::getUserInfo($user_id);
     $messageArr['session_key'] = CharacterModel::setSessionKey($user_id, $session_key);
     //任务成就界面
     $messageArr['achieveInfo'] = TaskAndAchieveAction::getAchieveInfo($user_id);
     $messageArr['taskInfo'] = TaskAndAchieveAction::getTaskInfo($user_id);
     $view = new JsonView();
     return $this->getViewByJson($view, $messageArr, 1, "buy_prop/buy_mall");
 }
예제 #2
0
 /**
  * API:成就统计
  *
  * @access public
  * @param int $user_id 用户ID
  * @return array
  */
 public function achieveStatistic($user_id, $dataArr)
 {
     $pointArr = array(6 => 1, 12 => 2, 22 => 3, 30 => 4);
     $userAchieve = UserCache::getByKey($user_id, self::ACHIEVEMENT_STRING);
     if (!$userAchieve) {
         $userAchieve = TaskAchieveModel::getUserInfoByCondition($user_id, self::ACHIEVEMENT_STRING);
         UserCache::setByKey($user_id, self::ACHIEVEMENT_STRING, $userAchieve);
     }
     foreach ($userAchieve as $key => $value) {
         $str = "achievement_id = " . $key . "_" . ($userAchieve[$key]['n_level'] + 1);
         $file = IniFileManager::getRootDir() . "/files/csv/achievement.csv";
         $achieveInfo = CharacterAction::readCsv($file, $str);
         if ($userAchieve[$key]['n_level'] < $userAchieve[$key]['max_level'] && $userAchieve[$key]['n_num'] < $achieveInfo[0]['condition']) {
             //1
             if ($dataArr['friend_help'] == 1 && $key == 1) {
                 $totalNum = $userAchieve[$key]['n_num'] + $dataArr['friend_help'];
                 if ($totalNum >= $achieveInfo[0]['condition']) {
                     $totalNum = $achieveInfo[0]['condition'];
                 }
                 $userAchieve[$key]['n_num'] = $totalNum;
             }
             //2
             if ($dataArr['login_day'] == 1 && $key == 2) {
                 $totalNum = $userAchieve[$key]['n_num'] + $dataArr['login_day'];
                 if ($totalNum >= $achieveInfo[0]['condition']) {
                     $totalNum = $achieveInfo[0]['condition'];
                 }
                 $userAchieve[$key]['n_num'] = $totalNum;
             }
             //3
             if ($dataArr['monster'] && $key == 3) {
                 $totalNum = $userAchieve[$key]['n_num'] + $dataArr['monster'];
                 if ($totalNum >= $achieveInfo[0]['condition']) {
                     $totalNum = $achieveInfo[0]['condition'];
                 }
                 $userAchieve[$key]['n_num'] = $totalNum;
             }
             //4
             if ($dataArr['star_num'] && $key == 4) {
                 $totalNum = $userAchieve[$key]['n_num'] + $dataArr['star_num'];
                 if ($totalNum >= $achieveInfo[0]['condition']) {
                     $totalNum = $achieveInfo[0]['condition'];
                 }
                 $userAchieve[$key]['n_num'] = $totalNum;
             }
             //5
             if ($dataArr['pro_num'] && $key == 5) {
                 $totalNum = $userAchieve[$key]['n_num'] + $dataArr['pro_num'];
                 if ($totalNum >= $achieveInfo[0]['condition']) {
                     $totalNum = $achieveInfo[0]['condition'];
                 }
                 $userAchieve[$key]['n_num'] = $totalNum;
             }
             //6
             if (($dataArr['pass'] === 0 || $dataArr['pass'] === 1) && $key == 6) {
                 $totalNum = $userAchieve[$key]['n_num'] + 1;
                 if ($totalNum >= $achieveInfo[0]['condition']) {
                     $totalNum = $achieveInfo[0]['condition'];
                 }
                 $userAchieve[$key]['n_num'] = $totalNum;
             }
             //7
             if ($dataArr['away'] === 0 && $dataArr['attack'] === 0 && $key == 7) {
                 $totalNum = $userAchieve[$key]['n_num'] + 1;
                 if ($totalNum >= $achieveInfo[0]['condition']) {
                     $totalNum = $achieveInfo[0]['condition'];
                 }
                 $userAchieve[$key]['n_num'] = $totalNum;
             }
             //8
             if ($dataArr['skill_num'] && $key == 8) {
                 $totalNum = $userAchieve[$key]['n_num'] + $dataArr['skill_num'];
                 if ($totalNum >= $achieveInfo[0]['condition']) {
                     $totalNum = $achieveInfo[0]['condition'];
                 }
                 $userAchieve[$key]['n_num'] = $totalNum;
             }
             //9
             if ($dataArr['cost'] && $key == 9) {
                 $totalNum = $userAchieve[$key]['n_num'] + $dataArr['cost'];
                 if ($totalNum >= $achieveInfo[0]['condition']) {
                     $totalNum = $achieveInfo[0]['condition'];
                 }
                 $userAchieve[$key]['n_num'] = $totalNum;
             }
             //11
             if ($dataArr['pass'] === 0 && $key == 11) {
                 $totalNum = $userAchieve[$key]['n_num'] + 1;
                 if ($totalNum >= $achieveInfo[0]['condition']) {
                     $totalNum = $achieveInfo[0]['condition'];
                 }
                 $userAchieve[$key]['n_num'] = $totalNum;
             }
             //12
             if ($dataArr['soul'] && $key == 12) {
                 $totalNum = $userAchieve[$key]['n_num'] + $dataArr['soul'];
                 if ($totalNum >= $achieveInfo[0]['condition']) {
                     $totalNum = $achieveInfo[0]['condition'];
                 }
                 $userAchieve[$key]['n_num'] = $totalNum;
             }
             //15
             if ($dataArr['check_point_id'] == 1 && $dataArr['pass'] == 1 && $key == 15) {
                 $totalNum = $userAchieve[$key]['n_num'] + 1;
                 if ($totalNum >= $achieveInfo[0]['condition']) {
                     $totalNum = $achieveInfo[0]['condition'];
                 }
                 $userAchieve[$key]['n_num'] = $totalNum;
             }
         }
         if ($userAchieve[$key]['n_level'] < $userAchieve[$key]['max_level']) {
             //10
             if ($dataArr['pass'] == 1 && $pointArr[$dataArr['check_point_id']] > $userAchieve[$key]['n_num'] && $key == 10) {
                 if ($value['n_level'] < Constants::CHAPTER_NUM) {
                     $totalNum = $userAchieve[$key]['n_num'] + 1;
                     // if ($totalNum>=$achieveInfo[0]['condition'])
                     // {
                     //     $totalNum=$achieveInfo[0]['condition'];
                     // }
                     $userAchieve[$key]['n_num'] = $totalNum;
                 }
             }
             //13
             if ($dataArr['generl_full'] && $key == 13) {
                 $totalNum = $userAchieve[$key]['n_num'] + $dataArr['generl_full'];
                 // if ($totalNum>=$achieveInfo[0]['condition'])
                 // {
                 //     $totalNum=$achieveInfo[0]['condition'];
                 // }
                 $userAchieve[$key]['n_num'] = $totalNum;
             }
             //14
             if ($dataArr['update_times'] && $key == 14) {
                 $totalNum = $userAchieve[$key]['n_num'] + $dataArr['update_times'];
                 // if ($totalNum>=$achieveInfo[0]['condition'])
                 // {
                 //     $totalNum=$achieveInfo[0]['condition'];
                 // }
                 $userAchieve[$key]['n_num'] = $totalNum;
             }
         }
     }
     $s_achievement_info = serialize($userAchieve);
     $res = TaskAchieveModel::update(array('s_achievement_info' => $s_achievement_info), array('n_id' => $user_id));
     UserCache::setByKey($user_id, self::ACHIEVEMENT_STRING, $userAchieve);
 }
예제 #3
0
 /**
  * API:武将解锁直接拥有
  *
  * @access public
  * @param int $user_id 用户ID $general_id主角ID
  * @return array
  */
 public function isUnlock($user_id)
 {
     $starNum = GameAction::getUserStar($user_id);
     $userGeneral = UserCache::getByKey($user_id, 's_general_info');
     if (!$userGeneral) {
         $userGeneral = GeneralModel::getUserGeneralInfo($user_id);
         UserCache::setByKey($user_id, 's_general_info', $userGeneral);
     }
     //读取系统武将,属性列表
     $file = IniFileManager::getRootDir() . "/files/csv/general.csv";
     $generalArr = CharacterAction::readCsv($file);
     foreach ($generalArr as $key => $value) {
         if (!$userGeneral[$value['general_id']]) {
             if ($starNum >= $value['unlock_star']) {
                 //添加新武将到武将信息字段、更新用户金钱
                 $userGeneral[$value['general_id']] = array('n_continue_level' => 0, 'n_cool_level' => 0);
                 $unlockInfo = $value['general_id'];
             }
         }
     }
     $s_general_info = serialize($userGeneral);
     $ret = GeneralModel::update(array('s_general_info' => $s_general_info), array('n_id' => $user_id));
     UserCache::setByKey($user_id, 's_general_info', $userGeneral);
     //更新战斗力
     $battle = UserAction::getUserBattle($user_id);
     GeneralModel::update(array('n_battle' => $battle), array('n_id' => $user_id));
     UserCache::setByKey($user_id, 'n_battle', $battle);
     return $unlockInfo ? $unlockInfo : 0;
 }