diff --git a/webapp/controller/NShopController.class.php b/webapp/controller/NShopController.class.php deleted file mode 100644 index 1259133..0000000 --- a/webapp/controller/NShopController.class.php +++ /dev/null @@ -1,643 +0,0 @@ -getMysql($account_id); - - $sqlStr = "SELECT id FROM hero WHERE accountid=:accountid; "; - $heroData = $conn->execQuery($sqlStr,array(':accountid' => $account_id)); - - $sqlStr = "SELECT skin_id FROM hero_skin WHERE accountid=:accountid; "; - $heroSkinData = $conn->execQuery($sqlStr,array(':accountid' => $account_id)); - - $sqlStr = "SELECT skin_id FROM gun_skin WHERE accountid=:accountid; "; - $gunSkinData = $conn->execQuery($sqlStr,array(':accountid' => $account_id)); - $goodsID = ""; - $allItemCfg = $this->getAllItem(); - $resultArr = array("heroData"=>$heroData,"heroSkin"=>$heroSkinData,"gunSkin"=>$gunSkinData,"allItem"=>$allItemCfg); - $this->sendDataToClient(100,"getShopData",$resultArr); - } - private function getAllItem() - { - $draw_uuid = 'game2005api_newShopAllItem_uuid:' . $_REQUEST['account_id']; - $allItemCfg = null; - $r = $this->getRedis($draw_uuid); - if($r) - { - $tmpItemCfg = null; - $tmpItemCfg = $r->get($draw_uuid); - if(!empty($tmpItemCfg)) - { - $allItemCfg = json_decode($tmpItemCfg); - } - else - { - $randN = rand(1,10000); - $this->resetTimeSeed($randN); - } - if($allItemCfg) - { - - $allItemCfg->goodsData;//$tmpAllData["goodsData"]; - $goodsData = null; - $len = count($allItemCfg->goodsData); - for($i = 0 ;$i < $len; $i++) - { - $len2 = count($allItemCfg->goodsData[$i]); - for($j = 0; $j < $len2; $j ++) - { - $limitType = $allItemCfg->goodsData[$i][$j]->limitType; - if($limitType !=0 ) - { - $itemID01 = $allItemCfg->goodsData[$i][$j]->goodsID; - $tmpCnt= $this->getLimitTypeCnt($itemID01); - $allItemCfg->goodsData[$i][$j]->buyCnt = $tmpCnt; - } - } - } - } - } - else - { - error_log("ErrorRedis===="); - } - - if(!$allItemCfg) - { - $allItemCfg = $this->initAllItem(); - $r -> set($draw_uuid, json_encode($allItemCfg)); - //if (phpcommon\getMondayseconds(phpcommon\getNowTime()) - phpcommon\getMondayseconds($rowuser['update_time']) > 0) - $nowSeconds = phpcommon\getNowTime(); - $nextDaySeconds = phpcommon\getNextDaySeconds($nowSeconds); - $daySeconds = phpcommon\getdayseconds($nowSeconds); - $nextWeekSeconds = phpcommon\getMondaySeconds($nowSeconds); - //$deadline = phpcommon\getNextDaySeconds()-phpcommon\getNowTime(); - $dayDeadLine = $nextDaySeconds - $nowSeconds; - $weekDeadLine = ($nextWeekSeconds + 86400*7)-$nowSeconds; - $r -> pexpire($draw_uuid, 200 * 1000); - $encodeArr = json_encode($allItemCfg); - $allItemCfg = json_decode($encodeArr); - //error_log("已经过期重新获得====".$nextDaySeconds."==".$nowSeconds."==".$daySeconds."==".$nextWeekSeconds); - } - return $allItemCfg; - } - private function getLimitTypeCnt($_itemID) - { - $tmpCnt = 0; - $draw_uuid = 'game2005api_newShopLimit'.$_itemID.'_uuid:' . $_REQUEST['account_id']; - - $r = $this->getRedis($draw_uuid); - $limitGoods = $r->get($draw_uuid); - if(empty($limitGoods)) - { - - - } - else - { - $limitGoods = json_decode($limitGoods); - $buyCnt = $limitGoods->buyCnt; - $tmpCnt = $buyCnt; - } - return $tmpCnt; - } - private function rnd($_seed) - { - $tmpSeed = ($_seed * 9301 + 49297) % 233280; //神奇数字 - $this->m_timeSeed = $tmpSeed; - return $tmpSeed / (233280.0); - } - private function resetTimeSeed($_timeSeed) - { - $this->m_timeSeed = $_timeSeed; - } - private function getRandN($_num) - { - $tmpN = $this->rnd($this->m_timeSeed); - $randN = floor($tmpN*$_num); - return $randN; - } - private function getItemIDByGoodsID($_goodsID) - { - $itemCfg = null; - $shopMeta = mt\NewItem::getItemCfgByID($_goodsID); - if($shopMeta) - { - - $itemType = $shopMeta["type"]; - //error_log("道具测试01=====".$itemType); - if($itemType == 19)//英雄表 - { - $itemCfg = mt\Player::getPlayerCfgByGoodsID($_goodsID); - } - else if($itemType == 13)//枪皮肤 - { - $itemCfg = mt\GunSkin::getGunSkinCfgByGoodsID($_goodsID); - } - else if($itemType == 12)//英雄皮肤 - { - $itemCfg = mt\PlayerSkin::getPlayerSkinCfgByGoodsID($_goodsID); - - } - else - { - $itemCfg = $shopMeta;//道具信息 - } - } - - return $itemCfg; - } - private function buyGunSkin($gunID,$skinID) - { - phpcommon\SqlHelper::insertOrUpdate - ($this->getSelfMysql(), - 'gun_skin', - array( - 'accountid' => $this->getAccountId(), - 'gun_id' => $gunID, - 'skin_id' => $skinID - ), - array( - 'accountid' => $this->getAccountId(), - 'gun_id' => $gunID, - 'skin_id' =>$skinID, - 'trytime' =>0, - 'createtime' => $this->getNowTime(), - 'modifytime' => $this->getNowTime() - ), - array( - 'trytime' => 0, - 'modifytime' => $this->getNowTime() - ) - ); - } - public function buyItem() - { - $code = 100; - $account_id = $_REQUEST['account_id']; - $goodsID = $_REQUEST['goodsID']; - $goodsType = $_REQUEST['goodsType']; - $buyCnt = $_REQUEST['buyCnt']; - $conn = $this->getMysql($account_id); - $sqlStr = "SELECT id FROM hero WHERE accountid=:accountid; "; - - $itemCfg = null; - - $skinData = null; - $priceID = 0; - $priceNum = 0; - $leftMoney = 0; - $leftDiamond = 0; - $curBuyCnt = -1; - $buyGoodsCfg = $this->calculateLimitGoods($goodsID);//当前购买的道具的配置信息 - if(!$buyGoodsCfg) - { - $code = 91;//道具被重新刷新,请重新打开页面 - } - if($code == 100) - { - if($buyGoodsCfg->limitType !=0) - { - $tmpCnt = $buyGoodsCfg->buyCnt; - $curBuyCnt = $tmpCnt ; - $maxCntStrArr = explode(":",$buyGoodsCfg->limitType); - $maxCnt = $maxCntStrArr[1]; - //error_log("购买限购商品======".$curBuyCnt."==".$maxCnt); - if($tmpCnt+1 > $maxCnt) - { - $code = 92;//购买上限 - } - - } - } - - if($code == 100) - { - - - $shopMeta = mt\NewShop::getShopItemByID($goodsID); - if($shopMeta) - { - $priceNum = $shopMeta["priceNum"]; - $priceID = $shopMeta["priceID"]; - $priceNum = $priceNum * $buyCnt; - if($buyGoodsCfg->isSpecail == 1) - { - $srcPrice = $priceNum; - $zkN = (int)$buyGoodsCfg->specailPrice; - $priceNum = $priceNum * ($zkN/100); - //error_log("购买的价格是否打折======".$srcPrice."==".$zkN."==".$priceNum); - } - $code = $this->checkPriceEnough($priceNum,$priceID);//检查是否现有货币是否足够购买道具 - } - else - { - $code = 99;//商品不存在 - } - if($code == 100) - { - $itemCfg = $this->getItemIDByGoodsID($goodsID); - if(!$itemCfg) - { - //error_log("商品部存在===".$goodsID); - $code = 98;//商品对应的道具不存在 - } - } - - } - $itemID = 0; - - - if($code == 100) - { - $itemID = null; - if(array_key_exists("itemid",$itemCfg)) - { - $itemID = $itemCfg["itemid"]; - } - else - { - $itemID = $itemCfg["id"]; - } - - //error_log("购买道具======".$itemID); - if($goodsType == 19)//购买英雄 - { - - $heroCfg = mt\Player::getPlayerCfgByGoodsID($itemID); - $this->addHeroToDB($itemID,$heroCfg); - //error_log("准备购买英雄======".json_encode($heroCfg)); - } - else if($goodsType == 12)//购买英雄皮肤 - { - $tmpHeroID = $itemCfg["playerid"]; - $this->buySkin($itemID,$tmpHeroID); - } - else if($goodsType == 13)//购买枪皮肤 - { - $tmpGunID = $itemCfg["gunid"]; - $this->buyGunSkin($tmpGunID,$itemID); - } - else //背包道具 - { - $itemData =array("item_id"=>$itemID,"item_num"=>1); - $item_list = array(); - array_push($item_list,$itemData); - $this->addItem($item_list); - } - // if ($item['item_id'] == $this->goldID) { - // $this->addGold($item['item_num']); - // error_log("添加金币=====".$item['item_num']); - // } - // else if ($item['item_id'] == $this->lotteryID){ - // $this->addLottery($item['item_num']); - // error_log("添加奖券=====".$item['item_num']); - // } - } - if($code == 100)//更新货币 - { - $conn = $this->getMysql($account_id); - $sqlStr3 = "SELECT coin_num,diamond_num FROM user WHERE accountid=:accountid; "; - $row = $conn->execQuery($sqlStr3,array(':accountid' => $account_id)); - - if($row) - { - $money = $row[0]["coin_num"]; - $diamond = $row[0]["diamond_num"]; - $leftMoney = $money; - $leftDiamond = $diamond; - } - else - { - $code = 90; - } - if($priceID == "10001") - { - $leftMoney = $leftMoney -$priceNum; - } - else if($priceID == "10003") - { - $leftDiamond = $leftDiamond -$priceNum; - } - //更新货币到数据库 - $this->updateCurrency($leftMoney,$leftDiamond); - // error_log("限购测试=====".$itemID."==".$curBuyCnt); - if($curBuyCnt >=0) - { - $curBuyCnt ++; - $draw_uuid = 'game2005api_newShopLimit'.$itemID.'_uuid:' . $_REQUEST['account_id']; - $r = $this->getRedis($draw_uuid); - $limitGoods = $r->get($draw_uuid); - $tmpData = array("goodsID"=>$itemID,"buyCnt"=>$curBuyCnt); - $r -> set($draw_uuid, json_encode($tmpData)); - - } - - } - - $resultArr = array("goodsID"=>$goodsID,"goodsType"=>$goodsType,"buyCnt"=>$curBuyCnt); - $this->sendDataToClient($code,"getShopData",$resultArr); - } - private function calculateLimitGoods($_goodsID) - { - $tmpAllData = $this->getAllItem(); - $allItemCfg = $tmpAllData->goodsData;//$tmpAllData["goodsData"]; - $goodsData = null; - $len = count($allItemCfg); - for($i = 0 ;$i < $len; $i++) - { - - $len2 = count($allItemCfg[$i]); - //error_log("当前列表======".$len2."==".$i); - for($j = 0; $j < $len2; $j ++) - { - $tmpGoodsID = $allItemCfg[$i][$j]->goodsID; - // error_log("获得道具信息========="."==".$tmpGoodsID."==".$_goodsID.json_encode($allItemCfg[$i][$j])); - if($tmpGoodsID == $_goodsID) - { - $goodsData = $allItemCfg[$i][$j]; - break; - } - } - } - return $goodsData; - } - private function initAllItem() - { - $shopCfg = mt\NewShop::getShopCfg(); - $tmpInex = 0; - $randRnage = 1000; - $allItemCfg = array(); - $tableNameArr = array(); - $limitGoodsArr = array();//限购商品 - $perDayArr = array();//每日刷新 - - foreach ($shopCfg as $item) - { - $tmpCfg = $item; - $shopTableName = $tmpCfg["shopname"];//页签名称 - $goodsListStr = $tmpCfg["goods"]; - $goodsListStr1 = explode("|",$goodsListStr); - $allItemIDArr = array(); - $tmpItemIDArr = array(); - $randN = 0; - $bargainNum = $tmpCfg["bargain"]; - $shopUIIndex = $tmpCfg["shopui"]; - $len1 = count($goodsListStr1); - for($i = 0; $i < $len1 ;$i++) - { - $goodsListStrArr2 = explode(":",$goodsListStr1[$i]); - $tmpItemID = $goodsListStrArr2[0]; - array_push($tmpItemIDArr,$tmpItemID); - } - if($tmpCfg["random"]) - { - $randN = $tmpCfg["random"]; - } - if($randN > 0) - { - while($randN > 0) - { - $randN --; - $tmpN2 = $this->getRandN($randRnage); - $per = $tmpN2 / $randRnage; - $index = floor($per * count($tmpItemIDArr)); - - $tmpID = $tmpItemIDArr[$index]; - array_push($allItemIDArr,$tmpID); - array_splice($tmpItemIDArr,$index,1); - //error_log("随机结果====".$tmpN2."==".json_encode($tmpItemIDArr)); - } - } - else - { - $allItemIDArr = $tmpItemIDArr; - } - $itemCfg = array(); - $specialArr = array(); - //获得特价商品开始-- - if($bargainNum > 0) - { - $tmpSpecailArr = array(); - $len2 = count($allItemIDArr); - for($i = 0; $i < $len2;$i++) - { - $tmpGoods = mt\NewShop::getShopItemByID($allItemIDArr[$i]); - $tmpNum = $tmpGoods["specailPrice"]; - if($tmpNum > 0) - { - array_push($tmpSpecailArr,$tmpGoods["goodsID"]); - } - } - //获得随机特价商品开始-- - - for($i = 0; $i < $bargainNum; $i++) - { - $specailRandN = $this->getRandN($randRnage); - $per = $specailRandN / $randRnage; - $len3 = count($tmpSpecailArr); - $index02 = floor($per * $len3); - - if($len3 > 0) - { - //error_log("获得随机的特价商品====".$index02."==".json_encode($tmpSpecailArr)); - array_push($specialArr,$tmpSpecailArr[$index02]); - array_splice($tmpSpecailArr,$index02,1); - } - } - //error_log("特价商品===".json_encode($specialArr)); - //获得随机特价商品结束-- - } - //获得特价商品结束-- - //记录向客户端发送的商品列表开始-- - $len4 = count($allItemIDArr); - for($i = 0; $i < $len4 ;$i++) - { - $tmpGoods = mt\NewShop::getShopItemByID($allItemIDArr[$i]); - $isSpecail = 0; - $len5 = count($specialArr); - for($j =0 ; $j < $len5 ; $j++) - { - $tmpGoodsID = $specialArr[$j]; - if($tmpGoodsID == $tmpGoods["goodsID"]) - { - $isSpecail = 1; - } - } - $tmpGoods["isSpecail"] = $isSpecail; - $tmpGoods["shopUIIndex"] = $shopUIIndex; - $tmpGoods["buyCnt"] = 0;//已经购买了多少个 - array_push($itemCfg,$tmpGoods); - } - array_push($tableNameArr,$shopTableName); - array_push($allItemCfg,$itemCfg); - //记录向客户端发送的商品列表结束-- - } - - $nowSeconds = phpcommon\getNowTime(); - $nextDaySeconds = phpcommon\getNextDaySeconds($nowSeconds); - //$daySeconds = phpcommon\getdayseconds($nowSeconds); - $nextWeekSeconds = phpcommon\getMondaySeconds($nowSeconds); - //$deadline = phpcommon\getNextDaySeconds()-phpcommon\getNowTime(); - $dayDeadLine = $nextDaySeconds - $nowSeconds; - $weekDeadLine = ($nextWeekSeconds + 86400*7)-$nowSeconds; - //查询周限购 和 每日限购 开始 - $lenAllItem = count($allItemCfg); - for($i = 0 ; $i < $lenAllItem; $i++) - { - $lenRows = count($allItemCfg[$i]); - for($j = 0; $j < $lenRows; $j++) - { - $itemID = $allItemCfg[$i][$j]["goodsID"]; - $limitType = $allItemCfg[$i][$j]["limitType"]; - if($limitType != 0)//是限购商品 - { - $limitTypeStrArr = explode(":",$limitType); - $draw_uuid = 'game2005api_newShopLimit'.$itemID.'_uuid:' . $_REQUEST['account_id']; - $updateTime = 0; - if($limitTypeStrArr[0] == 1)//每日更新 - { - $updateTime = $dayDeadLine; - } - else if($limitTypeStrArr[0] == 2)//每周更新 - { - $updateTime = $weekDeadLine; - } - $r = $this->getRedis($draw_uuid); - $limitGoods = $r->get($draw_uuid); - if(empty($limitGoods)) - { - $tmpData = array("goodsID"=>$itemID,"buyCnt"=>0); - $r -> set($draw_uuid, json_encode($tmpData)); - $r -> pexpire($draw_uuid, $updateTime * 1000); - //error_log("过期了,不存在======".$itemID); - } - else - { - $limitGoods = json_decode($limitGoods); - $buyCnt = $limitGoods->buyCnt; - $allItemCfg[$i][$j]["buyCnt"] = $buyCnt;//赋值已经购买了多少个 - //error_log("FromRadis======".json_encode($limitGoods)); - } - } - - } - } - //查询周限购 和 每日限购 结束 - - $resultArr = array("goodsData"=>$allItemCfg,"tableName"=>$tableNameArr); - - return $resultArr; - - //$this->sendDataToClient(100,"InitAllItem",$resultArr); - } - private function addHeroToDB($heroID,$_heroCfg) - { - $itemArr = array(); - $resultArr = array(); - $heroCfg = $_heroCfg; - $skinListStr = $heroCfg["skinlist"]; - $skinIDArr = explode("|",$skinListStr); - $skinID = $skinIDArr[0]; - $itemData = array("hero_id"=>$heroID,"skin_id"=>$skinID); - array_push($itemArr,$itemData); - - $skinData = array( - 'accountid' => $this->getAccountId(),'hero_id' => $heroID,'skin_id' => $skinID, - 'skin_state' => 0, - 'get_from' => 0, - 'consume_num' => 0, - 'trytime' => 0 - ); - $this->addHeroSkin($skinData); - $this->addAllHero($itemArr); - } - private function addAllHero($items) - { - foreach ($items as $item) { - phpcommon\SqlHelper::insertOrUpdate - ($this->getSelfMysql(), - 'hero', - array( - 'accountid' => $this->getAccountId(), - 'id' => $item['hero_id'] - ), - array( - 'accountid' => $this->getAccountId(), - 'id' => $item['hero_id'], - 'lv' => 1, - 'skinid' => $item['skin_id'], - 'skill1_lv1' =>1, - 'skill1_lv2' =>1, - 'yokeexp' => 0, - 'yoketotalexp' => 0, - 'createtime' => $this->getNowTime(), - 'modifytime' => $this->getNowTime() - ), - array( - 'skill_lv1' => 1, - 'modifytime' => $this->getNowTime() - ) - ); - } - } - private function addHeroSkin($item) - { - phpcommon\SqlHelper::insertOrUpdate - ($this->getSelfMysql(), - 'hero_skin', - array( - 'accountid' => $this->getAccountId(), - 'hero_id' => $item['hero_id'], - 'skin_id' => $item['skin_id'] - ), - array( - 'accountid' => $this->getAccountId(), - 'hero_id' => $item['hero_id'], - 'skin_id' => $item['skin_id'], - 'skin_state' => $item['skin_state'], - 'get_from' => $item['get_from'], - 'consume_num' => $item['consume_num'], - 'trytime' => $item['trytime'], - 'createtime' => $this->getNowTime(), - 'modifytime' => $this->getNowTime() - ), - array( - 'skin_state' => 3, - 'modifytime' => $this->getNowTime() - ) - ); - } - private function buySkin($_skinID,$_heroID)//购买英雄皮肤 - { - $skinID = $_skinID; - $heroID = $_heroID; - $code = 100; - $skinData = array( - 'accountid' => $this->getAccountId(),'hero_id' => $heroID,'skin_id' => $skinID, - 'skin_state' => 0, - 'get_from' => 0, - 'consume_num' => 0, - 'trytime' => 0 - ); - $this->addHeroSkin($skinData); - } - private function updateCurrency($_money,$_diamond) - { - $account_id = $_REQUEST['account_id']; - $conn = $this->getMysql($account_id); - - $sqlStr2 = "Update user set coin_num =:coin_num,diamond_num =:diamond_num WHERE accountid=:accountid "; - $row = $conn->execQuery($sqlStr2,array(':accountid' => $account_id,':coin_num' => $_money,':diamond_num' => $_diamond)); - - } -} diff --git a/webapp/controller/PassController.class.php b/webapp/controller/PassController.class.php deleted file mode 100644 index 7a9b009..0000000 --- a/webapp/controller/PassController.class.php +++ /dev/null @@ -1,583 +0,0 @@ -rspErr(ERR_USER_BASE + 2, '赛季未开启'); - return; - } - //判断当前赛季 - $number = 0; - $sea_reward = array(); - $sea_reward2 = array(); - $rank_status = 0; - $item_multiply = $this->getExplode($season['season_reward']); - $item_multiply2 = $this->getExplode($season['season_reward2']); - for($ii = 1; $ii <= count($item_multiply); $ii++) { - $rank_status = 0; - $rank_status2 = 0; - phpcommon\SqlHelper::upsert - ($this->getSelfMysql(), - 'passinfo', - array( - 'accountid' => $this->getAccountId(), - 'passid' => $ii, - ), - array( - ), - array( - 'accountid' => $this->getAccountId(), - 'passid' => $ii, - 'active_status' => 0, - 'honor_status' => 0, - 'create_time' => $this->getNowTime(), - 'modify_time' => $this->getNowTime() - ) - ); - $key = $ii - 1; - array_push($sea_reward, array( - 'item_id' => $item_multiply[$key][0], - 'item_num' => $item_multiply[$key][1], - 'time' => $item_multiply[$key][2], - 'status' => $rank_status, - 'type' => 0, - )); - - array_push($sea_reward2, array( - 'item_id' => $item_multiply2[$key][0], - 'item_num' => $item_multiply2[$key][1], - 'time' => $item_multiply2[$key][2], - 'status' => $rank_status2, - 'type' => 1, - )); - } - - //当前段位及积分 - $rank = 0; - $rank_score = 0; - $max_rank_score = 0; - $min_rank_score = 0; - $reward = array(); - $week_reward = array(); - $max_rank = 0; - $row = $conn->execQueryOne('SELECT integral, pass_status, score, max_integral FROM user WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - )); - if (!$row) { - phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); - return; - } - $rank_status = 0; - $seaPoint_meta_table = require('../res/seasomPoint@seasomPoint.php'); - for ($ii = 1; $ii <= count($seaPoint_meta_table); $ii++) { - $seaPoint = mt\SeasonPoint::getOldSeasonPoint($ii); - if ($row['integral'] >= $seaPoint['min'] && $row['integral'] <= $seaPoint['max'] - || $row['integral'] >= $seaPoint['min'] && $seaPoint['max'] == -1) - { - - $rank = $ii; - $max_rank_score = $seaPoint['max'] + 1 - $seaPoint['min']; - $min_rank_score = $seaPoint['min']; - $rank_score = $row['integral'] - $seaPoint['min'] + 1; - if ($seaPoint['max'] == -1) { - $max_rank_score = $seaPoint['min']; - $rank_score = $row['integral']; - } - } - - if ($row['max_integral'] >= $seaPoint['min'] && $row['max_integral'] <= $seaPoint['max'] - || $row['max_integral'] >= $seaPoint['min'] && $seaPoint['max'] == -1) - { - - $max_rank = $ii; - } - } - - if ($rank == 0) { - phpcommon\sendError(ERR_USER_BASE + 3, '未达到段位要求'); - return; - } - //等级积分 - $pass_array = metatable\getNowSeasoncard($row['score']); - $pass_lv = metatable\getNowSeasoncardInfo($row['score']); - $delim1 = '|'; - $drop_multiply = explode($delim1, $season['week_reward']); - - $delim2 = ';'; - $mul = explode($delim2, $drop_multiply[$pass_lv - 1]); - - $delim = ':'; - $week_array = array(); - for ($i2 = 0; $i2 < count($mul); $i2++) { - $mul1 = explode($delim, $mul[$i2]); - array_push($week_array, $mul1); - } - - for($s = 0; $s < count($week_array); $s++) { - array_push($week_reward, array( - 'item_id' => $week_array[$s][0], - 'item_num' => $week_array[$s][1], - 'time' => $week_array[$s][2], - 'status' => $row['pass_status'] - )); - } - - $cost = metatable\getParameterByName('season_card_cost'); - - echo json_encode(array( - 'errcode' => 0, - 'errmsg'=> '', - 'pass_status' => $row['pass_status'], - 'season' => $number, - 'open_time' => strtotime($season['time1']), - 'end_time' => strtotime($season['time2']), - 'rank' => $rank, - 'rank_score' => $rank_score, - 'max_rank_score' => $max_rank_score, - 'reward' => $reward, - 'week' => $week_reward, - 'seareward' => $sea_reward, - 'min_rank_score' => $min_rank_score, - 'seareward2' => $sea_reward2, - 'cost' => $cost, - 'pass_array' => $pass_array, - 'max_rank' => $max_rank, - )); - } - - public function getPassReward() - { - $account_id = $_REQUEST['account_id']; - $conn = $this->getMysql($account_id); - $passid = $_REQUEST['id']; - $type = $_REQUEST['type']; - $status = 0; - $rowPass = $conn->execQueryOne('SELECT active_status, honor_status ' . - ' FROM passinfo WHERE accountid=:accountid AND passid=:passid;', - array( - ':accountid' => $account_id, - ':passid' => $passid - )); - if ($rowPass) { - $status = $rowPass['active_status']; - if ($type == 1) { - $status = $rowPass['honor_status']; - } - if ($status == 1) { - phpcommon\sendError(ERR_USER_BASE + 2, '该奖励已领取'); - return; - } - } - $row = $conn->execQueryOne('SELECT integral, passcard FROM user WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - )); - if (!$row) { - phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); - return; - } - if ($type == 1 && $row['passcard'] == 0) { - phpcommon\sendError(ERR_USER_BASE + 3, '赛季手册未解锁'); - return; - } - - - $this->updateStatus($account_id, $passid, $type); - //增加奖励 - $season = array(); - $season_meta_table = require('../res/season@season.php'); - for ($i = 1; $i <= count($season_meta_table); $i++) { - $season = mt\Season::getOldSeason($i); - if (phpcommon\getNowTime() >= strtotime($season['open_time']) && phpcommon\getNowTime() <= strtotime($season['end_time'])) { - break; - } - } - $item_multiply = $this->getExplode($season['reward']); - if ($type == 1) { - $item_multiply = $this->getExplode($season['reward2']); - } - $items = $item_multiply[$passid - 1]; - $reward = array(); - array_push($reward, array( - 'item_id' => $items[0], - 'item_num' => $items[1], - 'time' => $items[2], - )); - $addreward = new classes\AddReward(); - $all_item_list = $addreward->addReward($items[0], $items[1], $account_id, $items[2],0); - - $coin_num = $addreward->getCoinNum($account_id); - $rmb_num = $addreward->getRmbNum($account_id); - echo json_encode(array( - 'errcode' => 0, - 'errmsg'=> '', - 'status' => 1, - 'item_list' => $reward, - 'coin_nums' => $coin_num, - 'rmb_nums' => $rmb_num, - 'all_item_list' => $all_item_list - )); - } - - protected function updateStatus($accountid, $passid, $type) - { - $conn = $this->getMysql($accountid); - if ($type == 1) { - $ret = $conn->execScript('UPDATE passinfo SET honor_status=1, modify_time=:modify_time ' . - ' WHERE accountid=:accountid AND passid=:passid;', - array( - ':accountid' => $accountid, - ':passid' => $passid, - ':modify_time' => phpcommon\getNowTime() - )); - } else { - $ret = $conn->execScript('UPDATE passinfo SET active_status=1, modify_time=:modify_time ' . - ' WHERE accountid=:accountid AND passid=:passid;', - array( - ':accountid' => $accountid, - ':passid' => $passid, - ':modify_time' => phpcommon\getNowTime() - )); - } - if (!$ret) { - die(); - return; - } - } - - public function getWeekReward() - { - $account_id = $_REQUEST['account_id']; - $conn = $this->getMysql($account_id); - $row = $conn->execQueryOne('SELECT pass_status, integral FROM user WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - )); - if (!$row) { - phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); - return; - } - - if ($row['pass_status'] == 1) { - phpcommon\sendError(ERR_USER_BASE + 2, '奖励已领取'); - return; - } - - $reward = array(); - $level = 0; - $seaPoint_meta_table = require('../res/seasomPoint@seasomPoint.php'); - for ($ii = 1; $ii <= count($seaPoint_meta_table); $ii++) { - $seaPoint = mt\SeasonPoint::getOldSeasonPoint($ii); - if ($row['integral'] >= $seaPoint['min'] && $row['integral'] <= $seaPoint['max'] - || $row['integral'] >= $seaPoint['min'] && $seaPoint['max'] == -1) - { - $season = array(); - $season_meta_table = require('../res/season@season.php'); - for ($i = 1; $i <= count($season_meta_table); $i++) { - $season = mt\Season::getOldSeason($i); - if (phpcommon\getNowTime() >= strtotime($season['open_time']) && phpcommon\getNowTime() <= strtotime($season['end_time'])) { - break; - } - } - $delim1 = '|'; - $drop_multiply = explode($delim1, $season['weekreward']); - - $delim2 = ';'; - $mul = explode($delim2, $drop_multiply[$ii - 1]); - - $delim = ':'; - $week_array = array(); - for ($i2 = 0; $i2 < count($mul); $i2++) { - $mul1 = explode($delim, $mul[$i2]); - array_push($week_array, $mul1); - } - - for($s = 0; $s < count($week_array); $s++) { - array_push($reward, array( - 'item_id' => $week_array[$s][0], - 'item_num' => $week_array[$s][1], - 'time' => $week_array[$s][2], - )); - } - $level = $ii; - } - } - $addreward = new classes\AddReward(); - $all_item_list = array(); - foreach ($reward as $r) { - $items = $addreward->addReward($r['item_id'], $r['item_num'], $account_id, $r['time'], 0); - foreach($items as $i) { - array_push($all_item_list, array( - 'item_id' => $i['item_id'], - 'item_num' => $i['item_num'], - 'time' => $i['time'], - )); - } - } - $ret = $conn->execScript('UPDATE user SET pass_status=1, modify_time=:modify_time ' . - ' WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - ':modify_time' => phpcommon\getNowTime() - )); - if (!$ret) { - die(); - return; - } - $coin_num = $addreward->getCoinNum($account_id); - $rmb_num = $addreward->getRmbNum($account_id); - echo json_encode(array( - 'errcode' => 0, - 'errmsg'=> '', - 'item_list' => $reward, - 'level' => $level, - 'coin_nums' => $coin_num, - 'rmb_nums' => $rmb_num, - 'all_item_list' => $all_item_list - )); - } - - public function getSeaReward() - { - $account_id = $_REQUEST['account_id']; - $conn = $this->getMysql($account_id); - $row = $conn->execQueryOne('SELECT season_end_score, season_status FROM user WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - )); - if (!$row) { - phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); - return; - } - - if ($row['season_status'] == 1) { - phpcommon\sendError(ERR_USER_BASE + 2, '赛季未结束'); - return; - } - $reward = array(); - $level = 0; - //积分结算 - $seaPoint_meta_table = require('../res/seasomPoint@seasomPoint.php'); - for ($ii = 1; $ii <= count($seaPoint_meta_table); $ii++) { - $seaPoint = mt\SeasonPoint::getOldSeasonPoint($ii); - if ($row['season_end_score'] >= $seaPoint['min'] && $row['season_end_score'] <= $seaPoint['max'] - || $row['season_end_score'] >= $seaPoint['min'] && $seaPoint['max'] == -1) - { - $level = $ii; - break; - } - } - //奖励结算 - $season_meta_table = require('../res/season@season.php'); - $id = 0; - for ($i = 1; $i <= count($season_meta_table); $i++) { - $season = mt\Season::getOldSeason($i); - if (phpcommon\getNowTime() >= strtotime($season['open_time']) && phpcommon\getNowTime() <= strtotime($season['end_time'])) { - $open_time = strtotime($season['open_time']); - $end_time = strtotime($season['end_time']); - $id = $i - 1; - break; - } - } - $s = mt\Season::getOldSeason($id); - if ($s) { - - $delim1 = '|'; - $item_multiply = explode($delim1, $s['season_overreward']); - - $delim2 = ';'; - $mul = explode($delim2, $item_multiply[$level - 1]); - - $delim = ':'; - $week_array = array(); - for ($i2 = 0; $i2 < count($mul); $i2++) { - $mul1 = explode($delim, $mul[$i2]); - array_push($week_array, $mul1); - } - - for($s = 0; $s < count($week_array); $s++) { - array_push($reward, array( - 'item_id' => $week_array[$s][0], - 'item_num' => $week_array[$s][1], - 'time' => $week_array[$s][2], - )); - } - } - $all_item_list = array(); - $addreward = new classes\AddReward(); - foreach ($reward as $r) { - $items = $addreward->addReward($r['item_id'], $r['item_num'], $account_id, $r['time'], 0); - foreach($items as $j) { - array_push($all_item_list, array( - 'item_id' => $j['item_id'], - 'item_num' => $j['item_num'], - 'time' => $j['time'], - )); - } - } - $ret = $conn->execScript('UPDATE user SET season_status=1, modify_time=:modify_time ' . - ' WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - ':modify_time' => phpcommon\getNowTime() - )); - if (!$ret) { - die(); - return; - } - $rmb_num = $addreward->getRmbNum($account_id); - $coin_num = $addreward->getCoinNum($account_id); - echo json_encode(array( - 'errcode' => 0, - 'errmsg'=> '', - 'item_list' => $reward, - 'level' => $level, - 'all_item_list' => $all_item_list, - 'rmb_nums' => $rmb_num, - 'coin_nums' => $coin_num - )); - } - - public function buyExp() - { - $account_id = $_REQUEST['account_id']; - $conn = $this->getMysql($account_id); - $row = $conn->execQueryOne('SELECT score, rmb_num FROM user WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - )); - if (!$row) { - phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); - return; - } - $score = metatable\getNowSeasoncardMaxExp($row['score']) + 1; - $cost = metatable\getNowSeasoncardCost($row['score']); - if ($row['rmb_num'] < $cost) { - phpcommon\sendError(ERR_USER_BASE + 2, '点券不足'); - return; - } - $ret = $conn->execScript('UPDATE user SET score=:score, rmb_num=:rmb_num, modify_time=:modify_time ' . - ' WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - ':score' => $score, - ':modify_time' => phpcommon\getNowTime(), - ':rmb_num' => $row['rmb_num'] - $cost, - )); - if (!$ret) { - die(); - return; - } - echo json_encode(array( - 'errcode' => 0, - 'errmsg'=> '', - 'rmb_nums' => $row['rmb_num'] - $cost - )); - } - - public function getAllPassReward() - { - $account_id = $_REQUEST['account_id']; - $conn = $this->getMysql($account_id); - $row = $conn->execQueryOne('SELECT score, passcard FROM user WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - )); - if (!$row) { - phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); - return; - } - $passid = metatable\getNowSeasoncardInfo($row['score']); - - $rowPass = $conn->execQuery('SELECT passid, active_status, honor_status ' . - ' FROM passinfo WHERE accountid=:accountid AND passid<=:passid;', - array( - ':accountid' => $account_id, - ':passid' => $passid - )); - if (!$rowPass) { - phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); - return; - } - $item_list = array(); - $all_item_list = array(); - foreach($rowPass as $rp) { - $passid = $rp['passid']; - if ($rp['active_status'] == 0) { - $this->updateStatus($account_id, $passid, 0); - $item_list = $this->getpassrewardinfo($passid, 0, $item_list); - if ($row['passcard'] == 1 && $rp['honor_status'] == 0) { - $this->updateStatus($account_id, $passid, 1); - $item_list = $this->getpassrewardinfo($passid, 1, $item_list); - } - } else { - if ($row['passcard'] == 1 && $rp['honor_status'] == 0) { - $this->updateStatus($account_id, $passid, 1); - $item_list = $this->getpassrewardinfo($passid, 1, $item_list); - } - } - } - $addreward = new classes\AddReward(); - foreach ($item_list as $r) { - $items = $addreward->addReward($r['item_id'], $r['item_num'], $account_id, $r['time'], 0); - foreach($items as $i) { - array_push($all_item_list, array( - 'item_id' => $i['item_id'], - 'item_num' => $i['item_num'], - 'time' => $i['time'], - )); - } - } - $coin_num = $addreward->getCoinNum($account_id); - $rmb_num = $addreward->getRmbNum($account_id); - echo json_encode(array( - 'errcode' => 0, - 'errmsg'=> '', - 'item_list' => $item_list, - 'coin_nums' => $coin_num, - 'rmb_nums' => $rmb_num, - 'all_item_list' => $all_item_list - )); - - } - - protected function getpassrewardinfo($pass_id, $type, $item_list) - { - //增加奖励 - $season = array(); - $season_meta_table = require('../res/season@season.php'); - for ($i = 1; $i <= count($season_meta_table); $i++) { - $season = mt\Season::getOldSeason($i); - if (phpcommon\getNowTime() >= strtotime($season['open_time']) && phpcommon\getNowTime() <= strtotime($season['end_time'])) { - break; - } - } - $item_multiply = $this->getExplode($season['reward']); - if ($type == 1) { - $item_multiply = $this->getExplode($season['reward2']); - } - $items = $item_multiply[$pass_id - 1]; - if ($items[0] != 0) { - array_push($item_list, array( - 'item_id' => $items[0], - 'item_num' => $items[1], - 'time' => $items[2], - )); - } - return $item_list; - } -}