diff --git a/sql/gamedb.sql b/sql/gamedb.sql index badadaa2..81b8df78 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -17,6 +17,7 @@ CREATE TABLE `version` ( PRIMARY KEY (`idx`), UNIQUE KEY `version` (`version`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `t_user` @@ -43,6 +44,7 @@ CREATE TABLE `t_user` ( PRIMARY KEY (`idx`), UNIQUE KEY `accountid` (`accountid`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `t_hero` @@ -67,6 +69,7 @@ CREATE TABLE `t_hero` ( PRIMARY KEY (`idx`), UNIQUE KEY `accountid_hero_id` (`accountid`, `hero_id`) ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `t_hero_skin` @@ -88,6 +91,7 @@ CREATE TABLE `t_hero_skin` ( PRIMARY KEY (`idx`), UNIQUE KEY `accountid_skinid` (`accountid`, `skin_id`) ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `t_bag` @@ -109,6 +113,11 @@ CREATE TABLE `t_bag` ( UNIQUE KEY `item_uuid` (`accountid`, `item_id`), KEY `accountid` (`accountid`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `t_gun_skin` +-- DROP TABLE IF EXISTS `t_gun_skin`; /*!40101 SET @saved_cs_client = @@character_set_client */; @@ -124,6 +133,10 @@ CREATE TABLE `t_gun_skin` ( UNIQUE KEY `accountid_skin_id` (`accountid`, `skin_id`) ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +-- +-- Table structure for table `t_gun_talent` +-- + DROP TABLE IF EXISTS `t_gun_talent`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; @@ -138,5 +151,6 @@ CREATE TABLE `t_gun_talent` ( PRIMARY KEY (`idx`), UNIQUE KEY `accountid_type_id_skill_id` (`accountid`, `type_id`,`skill_id`) ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; -- Dump completed on 2015-08-19 18:51:22 diff --git a/webapp/controller/ActivityController.class.php b/webapp/controller/ActivityController.class.php deleted file mode 100644 index 2a46d45f..00000000 --- a/webapp/controller/ActivityController.class.php +++ /dev/null @@ -1,1193 +0,0 @@ - $box_meta['box_type'], - 'item_id' => $box_meta['item_id'], - 'num' => $box_meta['num'], - 'weight' => $box_meta['weight'], - 'type' => $box_meta['type'], - 'time' => $box_meta['time'], - ); - return $b; - } - - protected function getLottery($lot_id) - { - $g_conf_lot_cluster = require('../res/lottery@lottery.php'); - $lot_conf = getLotteryConfig($g_conf_lot_cluster, $lot_id); - $l = array( - 'id' => $lot_conf['id'], - 'item_id' => $lot_conf['item_id'], - 'num' => $lot_conf['num'], - 'weight' => $lot_conf['weight'], - 'quailty' => $lot_conf['quailty'], - 'jilv' => $lot_conf['jilv'], - 'time' => $lot_conf['time'], - 'day' => $lot_conf['day'], - ); - return $l; - } - - protected function getDrawTableConfig($id) - { - $g_conf_lot_cluster = require('../res/lotterydraw@lotterydraw.php'); - $lot_conf = getLotteryConfig($g_conf_lot_cluster, $id); - $l = array( - 'id' => $lot_conf['id'], - 'item_id' => $lot_conf['item_id'], - 'num' => $lot_conf['num'], - 'weight' => $lot_conf['weight'], - 'quailty' => $lot_conf['quailty'], - 'jilv' => $lot_conf['jilv'], - 'time' => $lot_conf['time'], - ); - return $l; - } - - protected function getreward($re_id) - { - $g_conf_re_cluster = require('../res/randreward@randreward.php'); - $re_conf = getRandrewardConfig($g_conf_re_cluster, $re_id); - $re = array( - 'id' => $re_conf['id'], - 'reward' => $re_conf['reward'], - 'number' => $re_conf['number'], - 'weight' => $re_conf['weight'], - ); - return $re; - } - - protected function getRecommend($rec_id) - { - $g_conf_rec_cluster = require('../res/recommend@recommend.php'); - $rec_conf = getRecommendConfig($g_conf_rec_cluster, $rec_id); - $rec = array( - 'pool' => $rec_conf['pool'], - 'rank' => $rec_conf['rank'], - 'time' => $rec_conf['time'], - 'reward' => $rec_conf['reward'], - 're_reward' => $rec_conf['regular_reward'], - 'huge_reward' => $rec_conf['huge_reward'], - ); - return $rec; - } - - public function newLuckDrawInfo() - { - $account_id = $_REQUEST['account_id']; - $conn = $this->getMysql($account_id); - $draw_uuid = 'game2005api_newlot_uuid:' . $_REQUEST['account_id']; - $draw_list = array(); - $r = $this->getRedis($draw_uuid); - if (!$r) { - die(); - return; - } - //刷新次数 - $p_free = mt\Parameter::getOldParam(FREELOTTERY_TIME); - $p_video = mt\Parameter::getOldParam(VIDEOLOTTERY_TIME); - $free_times = $p_free['value']; - $video_times = $p_video['value']; - $flush_flag = 0; - $now_days = 1; - $row = $conn->execQueryOne('SELECT free_times, video_times, now_days, modify_time FROM activity WHERE accountid=:accountid;', - array( - ':accountid' => $account_id - )); - if (!$row) { - $ret = $conn->execScript('INSERT INTO activity(accountid, free_times, video_times, item_id, item_num, create_time, modify_time, now_days) ' . - ' VALUES(:accountid, 0, 0, 0, 0, :create_time, :modify_time, 1) ' . - ' ON DUPLICATE KEY UPDATE accountid=:accountid, free_times=0, video_times=0, item_id=0, item_num=0, modify_time=:modify_time, now_days=1;', - array( - ':accountid' => $account_id, - ':create_time' => phpcommon\getNowTime(), - ':modify_time' => phpcommon\getNowTime() - )); - if (!$ret) { - die(); - return; - } - $now_days = 1; - $free_times = $p_free['value']; - $video_times = $p_video['value']; - } else { - $free_times = $p_free['value'] - $row['free_times']; - $video_times = $p_video['value'] - $row['video_times']; - $now_days = $row['now_days']; - //刷新抽奖活动奖励 - if (phpcommon\getdayseconds(phpcommon\getNowTime()) - phpcommon\getdayseconds($row['modify_time']) > 0) { - $flush_flag = 1; - $lottery_ret = $conn->execScript('UPDATE activity SET free_times=0, video_times=0, modify_time=:modify_time ' . - ' WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - ':modify_time' => phpcommon\getNowTime(), - )); - if (!$lottery_ret) { - die(); - return; - } - $free_times = $p_free['value']; - $video_times = $p_video['value']; - } - } - //道具物品 - $user_db_str = $r->get($draw_uuid); - if (empty($user_db_str)) { - $draw_list = $this->randomNewReward(1,$account_id,$now_days); - $draw_db = array( - 'draw_uuid' => $draw_uuid, - 'draw_list' => $draw_list, - ); - $r -> set($draw_uuid, json_encode($draw_db)); - $r -> pexpire($draw_uuid, 1000 * 3600 * 24); - } else { - $draw_db = json_decode($user_db_str, true); - if ($flush_flag == 1) { - $user_db_str = $r->get($draw_uuid); - $draw_list = $this->randomNewReward(1,$account_id,$now_days); - $draw_db = json_decode($user_db_str, true); - $draw_db = array( - 'draw_uuid' => $draw_uuid, - 'draw_list' => $draw_list, - ); - $r -> set($draw_uuid, json_encode($draw_db)); - $r -> pexpire($draw_uuid, 1000 * 3600 * 24); - } else { - $user_db_str = $r->get($draw_uuid); - $user_db = json_decode($user_db_str, true); - if (empty($user_db)) { - phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); - return; - } - - foreach ($user_db['draw_list'] as $draw) { - $status = 0; - if (isset($draw['status'])) { - $status = $draw['status']; - } - array_push($draw_list, array( - 'item_id' => $draw['item_id'], - 'item_num' => $draw['item_num'], - 'quailty' => $draw['quailty'], - 'time' => $draw['time'], - 'status' => $status, - )); - } - } - } - echo json_encode(array( - 'errcode' => 0, - 'errmsg'=> '', - 'draw_uuid' => $draw_uuid, - 'free_times' => $free_times, - 'video_times' => $video_times, - 'item_list' => $draw_list, - )); - } - - public function getNewLuckDraw() - { - $account_id = $_REQUEST['account_id']; - $conn = $this->getMysql($account_id); - $row = $conn->execQueryOne('SELECT free_times, video_times, now_days FROM activity WHERE accountid=:accountid;', - array( - ':accountid' => $account_id - )); - if (!$row) { - phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); - return; - } - //随机确认奖励 - $weight_sum = 0; - $g_conf_lot_cluster = require('../res/lottery@lottery.php'); - $lot_array = array(); - $draw_uuid = $_REQUEST['draw_uuid']; - $item_id = 0; - $item_num = 0; - $flag = 0; - $weight = 0; - $key = 0; - $r = $this->getRedis($draw_uuid); - $user_db_str = $r->get($draw_uuid); - if (empty($user_db_str)) { - phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); - return; - } - $user_db = json_decode($user_db_str, true); - if (empty($user_db)) { - phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); - return; - } - if ($row['free_times'] + $row['video_times'] + 1 == 6) { - //$day = 1; - $day = $row['now_days']; - $g_conf_lot_cluster = require('../res/lottery@lottery.php'); - for($g = 1; $g <= count($g_conf_lot_cluster); $g++) { - $l = $this->getLottery($g); - if ($l['jilv'] == 0 && $l['day'] == $day) { - array_push($lot_array, array( - 'key' => $g - )); - } - } - $key = $lot_array[0]['key']; - } else { - foreach ($user_db['draw_list'] as $draw) { - if (isset($draw['status']) && $draw['status'] != 0) { - continue; - } - array_push($lot_array,array( - 'key' => $draw['key'] + 1, - )); - } - - for ($i = 0; $i < count($lot_array); $i++) { - $l = $this->getLottery($lot_array[$i]['key']); - - $weight_sum += $l['jilv']; - } - $random = Rand(1, $weight_sum); - for ($ii = 0; $ii < count($lot_array); $ii++) { - $l = $this->getLottery($lot_array[$ii]['key']); - $weight += $l['jilv']; - - if ($weight >= $random) { - $key = $lot_array[$ii]['key']; - break; - } - } - } - foreach ($user_db['draw_list'] as &$draw) { - if ($draw['key'] + 1 == $key) { - $item_id = $draw['item_id']; - $item_num = $draw['item_num']; - $time = $draw['time']; - $flag = 1; - $status = 1; - if (isset($draw['status'])) { - $draw['status'] = 1; - } else { - array_push($draw, array( - 'status' => 1, - )); - } - break; - } - } - - $r->set($draw_uuid, json_encode($user_db)); - $r -> pexpire($draw_uuid, 1000 * 3600 * 24); - if ($flag == 0) { - phpcommon\sendError(ERR_USER_BASE + 3, '没有这个物品'); - return; - } - //增加奖励 - $addreward = new classes\AddReward(); - $all_item_list = $addreward->addReward($item_id, $item_num, $account_id, $time, 0); - $coin_num = $addreward->getCoinNum($account_id); - $diamond_num = $addreward->getDiamondNum($account_id); - $item_list = array(); - $quest = new classes\Quest(); - $quest->triggerQuest(71004, 1, 1, $account_id); - array_push($item_list,array( - 'item_id' => $item_id, - 'item_num' => $item_num, - 'time' => $time - )); - - if ($_REQUEST['type'] == 0) { - $p_flush = mt\Parameter::getOldParam(FREELOTTERY_TIME); - if ($p_flush['value'] <= $row['free_times']) { - phpcommon\sendError(ERR_USER_BASE + 3, '今日刷新次数已满'); - return; - } - $ret = $conn->execScript('UPDATE activity SET free_times=:free_times, item_id=:item_id, item_num=:item_num, modify_time=:modify_time ' . - ' WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - ':free_times' => $row['free_times'] + 1, - ':item_id' => $item_id, - ':item_num' => $item_num, - ':modify_time' => phpcommon\getNowTime() - )); - if (!$ret) { - die(); - return; - } - } - if ($_REQUEST['type'] == 1) { - $p_flush = mt\Parameter::getOldParam(VIDEOLOTTERY_TIME); - $now_days = $row['now_days']; - if ($p_flush['value'] <= $row['video_times']) { - phpcommon\sendError(ERR_USER_BASE + 3, '今日刷新次数已满'); - return; - } - if ($p_flush['value'] == $row['video_times'] + 1) { - $last_conf = $this->getLottery(count($g_conf_lot_cluster)); - $now_days++; - if ($last_conf && $now_days >= $last_conf['day']) { - $now_days = $last_conf['day']; - } - if (!$now_days) { - $now_days = 1; - } - } - $ret = $conn->execScript('UPDATE activity SET video_times=:video_times,item_id=:item_id, item_num=:item_num, modify_time=:modify_time, now_days=:now_days ' . - ' WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - ':video_times' => $row['video_times'] + 1, - ':item_id' => $item_id, - ':item_num' => $item_num, - ':modify_time' => phpcommon\getNowTime(), - ':now_days' => $now_days - )); - if (!$ret) { - die(); - return; - } - } - - echo json_encode(array( - 'errcode' => 0, - 'errmsg'=> '', - 'item_id' => $item_id, - 'item_num' => $item_num, - 'coin_nums' => $coin_num, - 'diamond_nums' => $diamond_num, - 'item_list' => $item_list, - 'all_item_list' => $all_item_list, - 'status' => $status - )); - } - - public function drawTableInfo() - { - $account_id = $_REQUEST['account_id']; - - $conn = $this->getMysql($account_id); - $drawtable_uuid = 'game2005api_drawtable_uuid:' . $_REQUEST['account_id']; - $drawtable_list = array(); - $r = $this->getRedis($drawtable_uuid); - if (!$r) { - die(); - return; - } - - //道具物品 - //$user_db_str = $r->get($drawtable_uuid); - $drawtable_list = $this->randomReward(2,$account_id); - $drawtable_db = array( - 'drawtable_uuid' => $drawtable_uuid, - 'drawtable_list' => $drawtable_list, - ); - $r -> set($drawtable_uuid, json_encode($drawtable_db)); - $r -> pexpire($drawtable_uuid, 1000 * 3600 * 24); - - echo json_encode(array( - 'errcode' => 0, - 'errmsg'=> '', - 'drawtable_uuid' => $drawtable_uuid, - 'item_list' => $drawtable_list, - )); - } - - public function getDrawTable() - { - $account_id = $_REQUEST['account_id']; - $conn = $this->getMysql($account_id); - $row = $conn->execQueryOne('SELECT free_lot_ticket FROM user WHERE accountid=:accountid;', - array( - ':accountid' => $account_id - )); - if (!$row) { - phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); - return; - } - //随机确认奖励 - $weight_sum = 0; - $g_conf_lot_cluster = require('../res/lotterydraw@lotterydraw.php'); - for ($i = 1; $i <= count($g_conf_lot_cluster); $i++) { - $l = $this->getDrawTableConfig($i); - $weight_sum += $l['jilv']; - } - $random = Rand(0, $weight_sum); - $weight = 0; - $key = 0; - for ($ii = 1; $ii <= count($g_conf_lot_cluster); $ii++) { - $l = $this->getDrawTableConfig($ii); - $weight += $l['jilv']; - if ($weight >= $random) { - $key = $ii; - break; - } - } - - $drawtable_uuid = $_REQUEST['drawtable_uuid']; - $item_id = 0; - $item_num = 0; - $flag = 0; - $r = $this->getRedis($drawtable_uuid); - $user_db_str = $r->get($drawtable_uuid); - if (empty($user_db_str)) { - phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); - return; - } - $user_db = json_decode($user_db_str, true); - if (empty($user_db)) { - phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); - return; - } - $quest = new classes\Quest(); - $quest->triggerQuest(71004, 1, 1, $account_id); - - foreach ($user_db['drawtable_list'] as $draw) { - if ($draw['key'] == $key - 1) { - $item_id = $draw['item_id']; - $item_num = $draw['item_num']; - $time = $draw['time']; - $flag = 1; - break; - } - } - if ($flag == 0) { - phpcommon\sendError(ERR_USER_BASE + 3, '没有这个物品'); - return; - } - $ticket = $row['free_lot_ticket']; - if ($row['free_lot_ticket'] != 0) { - $ret = $conn->execScript('UPDATE user SET free_lot_ticket=:free_lot_ticket ' . - ' WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - ':free_lot_ticket' => $row['free_lot_ticket'] - 1, - )); - if (!$ret) { - die(); - return; - } - $ticket = $row['free_lot_ticket'] - 1; - } - $ret = $conn->execScript('UPDATE activity SET item_id=:item_id, item_num=:item_num ' . - ' WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - ':item_id' => $item_id, - ':item_num' => $item_num, - )); - if (!$ret) { - die(); - return; - } - //增加奖励 - $addreward = new classes\AddReward(); - $all_item_list = $addreward->addReward($item_id, $item_num, $account_id, $time,0); - $coin_num = $addreward->getCoinNum($account_id); - $rmb_num = $addreward->getRmbNum($account_id); - $item_list = array(); - array_push($item_list,array( - 'item_id' => $item_id, - 'item_num' => $item_num, - 'time' => $time, - )); - echo json_encode(array( - 'errcode' => 0, - 'errmsg'=> '', - 'coin_nums' => $coin_num, - 'rmb_nums' => $rmb_num, - 'item_list' => $item_list, - 'all_item_list' => $all_item_list, - 'ticket' => $ticket, - )); - } - - - public function doubleLuckDraw() - { - $account_id = $_REQUEST['account_id']; - $conn = $this->getMysql($account_id); - $row = $conn->execQueryOne('SELECT item_id, item_num FROM activity WHERE accountid=:accountid;', - array( - ':accountid' => $account_id - )); - if (!$row) { - phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); - return; - } - //增加奖励 - $p = mt\Parameter::getOldParam(REWARD_TIMES); - $times = $p['value'] - 1; - $addreward = new classes\AddReward(); - $addreward->addReward($row['item_id'], $row['item_num'] * $times, $account_id,0,0); - $coin_num = $addreward->getCoinNum($account_id); - echo json_encode(array( - 'errcode' => 0, - 'errmsg'=> '', - 'coin_nums' => $coin_num, - )); - } - protected function randomNewReward($type,$accountid,$days) - { - $draw_list = array(); - $g_conf_lot_cluster = array(); - if ($type == 1) { - $g_conf_lot_cluster = require('../res/lottery@lottery.php'); - } else { - $g_conf_lot_cluster = require('../res/lotterydraw@lotterydraw.php'); - } - - $day = 1; - if ($type == 1) { - $day = $days; - } - for ($i = 1; $i <= count($g_conf_lot_cluster); $i++) { - $item_id = 0; - $item_num = 0; - $key = 0; - $l = array(); - if ($type == 1) { - $l = $this->getLottery($i); - } else { - $l = $this->getDrawTableConfig($i); - } - //确定商品id和数量 - $weight_sum = 0; - $weight_array = $this->getExplode($l['weight']); - if ($type == 1) { - if ($l['day'] != $day) { - continue; - } - } - for ($ii = 0; $ii < count($weight_array); $ii++) { - $weight_sum += $weight_array[$ii][0]; - } - $random = Rand(0, $weight_sum); - $weight = 0; - for ($ii = 0; $ii < count($weight_array); $ii++) { - $weight += $weight_array[$ii][0]; - if ($weight > $random) { - $key = $ii; - break; - } - } - $item_id_array = $this->getExplode($l['item_id']); - $num_array = $this->getExplode($l['num']); - $quailty_array = $this->getExplode($l['quailty']); - $time_array = $this->getExplode($l['time']); - $item_id = $item_id_array[$key][0]; - $item_num = $num_array[$key][0]; - $quailty = $quailty_array[$key][0]; - $time = $time_array[$key][0]; - array_push($draw_list, array( - 'key' => $i - 1, - 'item_id' => $item_id, - 'item_num' => $item_num, - 'quailty' => $quailty, - 'time' => $time, - 'status' => 0, - )); - } - return $draw_list; - } - - public function lotteryReward() - { - $account_id = $_REQUEST['account_id']; - $pool = $_REQUEST['pool']; - $rec = $this->getRecommend($pool); - $reward_id = 0; - $item_list = array(); - $all_item_list = array(); - $reward_array = array(); - $addreward = new classes\AddReward(); - $delim = "|"; - $num_multiply = explode($delim, $rec['huge_reward']); - //随机奖励 - for($i = 0; $i < $rec['reward']; $i++) { - $item_num = 1; - $time = $this->randtime($rec['time']); - $reward_id = $this->randlottery($reward_array, $pool); - array_push($reward_array, array( - 'id' => $reward_id - )); - if ($reward_id == 10001) { - $item_num = $num_multiply[0]; - $time = 0; - } else if ($reward_id == 10003) { - $item_num = $num_multiply[1]; - $time = 0; - } - array_push($item_list, array( - 'item_id' => $reward_id, - 'item_num' => $item_num, - 'time' => $time, - )); - $items = $addreward->addReward($reward_id, $item_num, $account_id, $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'], - )); - } - } - //固定奖励 - $delim2 = ":"; - $re_multiply = explode($delim2, $rec['re_reward']);; - array_push($item_list, array( - 'item_id' => $re_multiply[0], - 'item_num' => $re_multiply[1], - 'time' => 0, - )); - $items = $addreward->addReward($re_multiply[0], $re_multiply[1], $account_id, 0, 0); - foreach($items as $s) { - array_push($all_item_list, array( - 'item_id' => $s['item_id'], - 'item_num' => $s['item_num'], - 'time' => $s['time'], - )); - } - $coin_num = $addreward->getCoinNum($account_id); - $diamond_num = $addreward->getDiamondNum($account_id); - $quest = new classes\Quest(); - $quest->triggerQuest(71004, 1, 1, $account_id); - echo json_encode(array( - 'errcode' => 0, - 'errmsg'=> '', - 'coin_nums' => $coin_num, - 'diamond_nums' => $diamond_num, - 'item_list' => $item_list, - 'all_item_list' => $all_item_list - )); - } - - protected function randtime($str_time) - { - $weight_sum = 0; - $weight_array = $this->getExplode($str_time); - for ($ii = 0; $ii < count($weight_array); $ii++) { - $weight_sum += $weight_array[$ii][1]; - } - $random = Rand(0, $weight_sum); - $weight = 0; - $key = 0; - for ($ii = 0; $ii < count($weight_array); $ii++) { - $weight += $weight_array[$ii][1]; - if ($weight > $random) { - $key = $weight_array[$ii][0]; - break; - } - } - return $key; - } - - protected function randlottery($id, $pool) - { - $weight_sum = 0; - $rand_array = array(); - $po = $pool - 1; - $g_conf_item_cluster = require('../res/item@item.php'); - foreach($g_conf_item_cluster as $items) { - $flag = 0; - $it = mt\Item::getOldItem($items['id']); - if ($it['id'] != 0) { - foreach ($id as $ids) { - if ($it['id'] == $ids['id']) { - $flag = 1; - break; - } - } - if ($flag == 1) { - continue; - } - $weight_array = $this->getExplode($it['pool_weight']); - $weight_sum += $weight_array[$po][0]; - array_push($rand_array, array( - 'id' => $it['id'], - 'weight' => $weight_array[$po][0] - )); - } - } - $random = Rand(0, $weight_sum); - $weight = 0; - $key = 0; - foreach ($rand_array as $r) { - $weight += $r['weight']; - if ($weight > $random) { - $key = $r['id']; - break; - } - } - return $key; - } - - public function getBoxOrder() - { - $account_id = $_REQUEST['account_id']; - $conn = $this->getMysql($account_id); - $row = $conn->execQueryOne('SELECT daily_order1, daily_order2, daily_order3 FROM user WHERE accountid=:accountid;', - array( - ':accountid' => $account_id - )); - if (!$row) { - phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); - return; - } - $item_list = array(); - $daily_order1 = $row['daily_order1']; - $daily_order2 = $row['daily_order2']; - $daily_order3 = $row['daily_order3']; - $p1 = mt\Parameter::getOldParam(LOGINBOX_TIME1); - $p2 = mt\Parameter::getOldParam(LOGINBOX_TIME2); - $p3 = mt\Parameter::getOldParam(LOGINBOX_TIME3); - $p = mt\Parameter::getOldParam(LOGINBOX_TIME); - $pt1 = $p1['value']; - $pt2 = $p2['value']; - $pt3 = $p3['value']; - $pt = $p['value']; - $nowTime = floor((phpcommon\getNowTime() - phpcommon\getdayseconds(phpcommon\getNowTime())) / 3600); - if ($nowTime < $pt1) { - $daily_order1 = 0; - $daily_order2 = 0; - $daily_order3 = 0; - } else if ($nowTime >= $pt1 && $nowTime < $pt1 + $pt) { - if ($daily_order1 == 0) { - $daily_order1 = 1; - } else { - $daily_order1 = $row['daily_order1']; - } - $daily_order2 = 0; - $daily_order3 = 0; - } else if ($nowTime >= $pt1 + $pt && $nowTime < $pt2) { - if ($daily_order1 <= 1) { - $daily_order1 = 3; - } else { - $daily_order1 = $row['daily_order1']; - } - $daily_order2 = 0; - $daily_order3 = 0; - } else if ($nowTime >= $pt2 && $nowTime < $pt2 + $pt) { - if ($daily_order1 <= 1) { - $daily_order1 = 3; - } else { - $daily_order1 = $row['daily_order1']; - } - if ($daily_order2 == 0) { - $daily_order2 = 1; - } else { - $daily_order2 = $row['daily_order2']; - } - $daily_order3 = 0; - } else if ($nowTime >= $pt2 + $pt && $nowTime < $pt3) { - if ($daily_order1 <= 1) { - $daily_order1 = 3; - } else { - $daily_order1 = $row['daily_order1']; - } - if ($daily_order2 <= 1) { - $daily_order2 = 3; - } else { - $daily_order2 = $row['daily_order2']; - } - $daily_order3 = 0; - } else if ($nowTime >= $pt3 && $nowTime < $pt3 + $pt) { - if ($daily_order1 <= 1) { - $daily_order1 = 3; - } else { - $daily_order1 = $row['daily_order1']; - } - if ($daily_order2 <= 1) { - $daily_order2 = 3; - } else { - $daily_order2 = $row['daily_order2']; - } - if ($daily_order3 == 0) { - $daily_order3 = 1; - } else { - $daily_order3 = $row['daily_order3']; - } - } else if ($nowTime >= $pt3 + $pt) { - if ($daily_order1 <= 1) { - $daily_order1 = 3; - } else { - $daily_order1 = $row['daily_order1']; - } - if ($daily_order2 <= 1) { - $daily_order2 = 3; - } else { - $daily_order2 = $row['daily_order2']; - } - if ($daily_order3 <= 1) { - $daily_order3 = 3; - } else { - $daily_order3 = $row['daily_order3']; - } - } - $stauts = 0; - for ($i = 0; $i < 3; $i++) { - if ($i == 0) { - $status = $daily_order1; - } else if ($i == 1) { - $status = $daily_order2; - } else if ($i == 2) { - $status = $daily_order3; - } - array_push($item_list, array( - 'status' => $status - )); - } - $ret = $conn->execScript('UPDATE user SET daily_order1=:daily_order1, daily_order2=:daily_order2, daily_order3=:daily_order3 ' . - ' WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - ':daily_order1' => $daily_order1, - ':daily_order2' => $daily_order2, - ':daily_order3' => $daily_order3 - )); - if (!$ret) { - die(); - return; - } - echo json_encode(array( - 'errcode' => 0, - 'errmsg'=> '', - 'item_list' => $item_list, - )); - } - - public function getOrderReward() - { - $account_id = $_REQUEST['account_id']; - $conn = $this->getMysql($account_id); - $id = $_REQUEST['id']; - $row = $conn->execQueryOne('SELECT daily_order1, daily_order2, daily_order3 FROM user WHERE accountid=:accountid;', - array( - ':accountid' => $account_id - )); - if (!$row) { - phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); - return; - } - if ($id == 1) { - if ($row['daily_order1'] != 1) { - phpcommon\sendError(ERR_USER_BASE + 3, '奖励不可领'); - return; - } - $ret = $conn->execScript('UPDATE user SET daily_order1=2 ' . - ' WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - )); - if (!$ret) { - die(); - return; - } - } else if ($id == 2) { - if ($row['daily_order2'] != 1) { - phpcommon\sendError(ERR_USER_BASE + 3, '奖励不可领'); - return; - } - $ret = $conn->execScript('UPDATE user SET daily_order2=2 ' . - ' WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - )); - if (!$ret) { - die(); - return; - } - } else if ($id == 3) { - if ($row['daily_order3'] != 1) { - phpcommon\sendError(ERR_USER_BASE + 3, '奖励不可领'); - return; - } - $ret = $conn->execScript('UPDATE user SET daily_order3=2 ' . - ' WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - )); - if (!$ret) { - die(); - return; - } - } - $all_item_list = array(); - $item_list = $this->randBoxReward(3); - $addreward = new classes\AddReward(); - foreach ($item_list as $item) { - $items = $addreward->addReward($item['item_id'], $item['item_num'], $account_id, $item['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); - $num = $addreward->getDiamondNum($account_id); - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - 'item_list' => $item_list, - 'diamond_nums' => $num, - 'all_item_list' => $all_item_list - )); - } - - protected function randBoxReward($drop_id) - { - //随机奖励 - $item_list = array(); - - $b = $this->getbox($drop_id); - if (!$b) { - phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); - die(); - } - $item_id_array = $this->getExplode($b['item_id']); - $weight_sum = 0; - $keys = 0; - $item_num_array = $this->getExplode($b['num']); - $weight_array = $this->getExplode($b['weight']); - $time_array = $this->getExplode($b['time']); - for ($i = 0; $i < count($weight_array); $i++) { - $weight_sum += $weight_array[$i][0]; - } - $random = Rand(0, $weight_sum); - $weight = 0; - for ($i = 0; $i < count($weight_array); $i++) { - $weight += $weight_array[$i][0]; - if ($weight > $random) { - $keys = $i; - break; - } - } - $item_id = $item_id_array[$keys][0]; - $item_num = $item_num_array[$keys][0]; - $time = $time_array[$keys][0]; - array_push($item_list, array( - 'item_id' => $item_id, - 'item_num' => $item_num, - 'time' => $time - )); - - return $item_list; - } - - protected function insertDrawDB($account_id, $id, $free_times, $isfree) - { - $conn = $this->getMysql($account_id); - $ret = $conn->execScript('INSERT INTO draw(accountid, id, isfree, free_times, draw_times, createtime, modifytime) ' . - ' VALUES(:account_id, :id, :isfree, :free_times, 0, :createtime, :modifytime) ' . - ' ON DUPLICATE KEY UPDATE accountid=:account_id, id=:id, isfree=:isfree, free_times=:free_times, draw_times=0, modifytime=:modifytime;', - array( - ':account_id' => $account_id, - ':id' => $id, - ':isfree' => $isfree, - ':createtime' => phpcommon\getNowTime(), - ':modifytime' => phpcommon\getNowTime(), - ':free_times' => $free_times, - )); - if(!$ret){ - die(); - return; - } - } - - public function drawBoxInfo() - { - $account_id = $_REQUEST['account_id']; - $conn = $this->getMysql($account_id); - $rows = $conn->execQuery('SELECT id, free_times FROM draw WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - )); - $info_list = array(); - if (!$rows) { - $draw_conf = metatable\getDrawConf(); - foreach ($draw_conf as $d) { - $free_times = 0; - if ($d['free_do'] != 1) { - $this->insertDrawDB($account_id, $d['id'], 0, 0); - } else { - $this->insertDrawDB($account_id, $d['id'], $d['free_do'], 1); - $free_times = $d['free_do']; - } - array_push($info_list, array( - 'id' => $d['id'], - 'times' => $free_times, - )); - } - } else { - foreach ($rows as $row) { - array_push($info_list, array( - 'id' => $row['id'], - 'times' => $row['free_times'], - )); - } - } - - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - 'info_list' => $info_list, - )); - } - - public function drawBoxReward() - { - $account_id = $_REQUEST['account_id']; - $conn = $this->getMysql($account_id); - $id = $_REQUEST['id']; - $type = $_REQUEST['type']; - $row = $conn->execQueryOne('SELECT rmb_num, coin_num FROM user WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - )); - $rowd = $conn->execQueryOne('SELECT free_times, draw_times FROM draw WHERE accountid=:accountid AND id=:id;', - array( - ':accountid' => $account_id, - ':id' => $id, - )); - if (!$row) { - phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); - return; - } - $dr = metatable\getDrawById($id); - if (!$dr) { - phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); - return; - } - $drop_id = $dr['one_drop']; - $cost = array(); - $times = 1; - $extra_id = 0; - $isfree = false; - $item_list = array(); - if ($type == 0) { - $cost = explode(':', $dr['onecost']); - if ($rowd && $rowd['free_times'] != 0) { - $isfree = true; - } - } else { - $cost = explode(':', $dr['tencost']); - $extra_id = $dr['ten_drop']; - $times = 9; - if (isset($_REQUEST['isnew']) && $_REQUEST['isnew'] == 1) { - if ($id == 1) { - $drop_id = metatable\getParameterByName('newbie_draw_cloth1'); - $extra_id = metatable\getParameterByName('newbie_draw_cloth10'); - $times = 8; - array_push($item_list, array( - 'item_id' => 15001, - 'item_num' => 1, - 'time' => 0, - )); - } else if ($id == 2) { - $drop_id = metatable\getParameterByName('newbie_draw_arms1'); - $extra_id = metatable\getParameterByName('newbie_draw_arms10'); - } - } - } - $coin_num = $row['coin_num']; - $rmb_num = $row['rmb_num']; - $draw_times = $rowd['draw_times'] + 1; - $free_times = $rowd['free_times']; - if (isset($_REQUEST['isnew']) && $_REQUEST['isnew'] == 1) { - } else { - if (!$isfree) { - if ($cost[0] == 10001) { - if ($row['coin_num'] < $cost[1]) { - phpcommon\sendError(ERR_USER_BASE + 2, '金币不足'); - return; - } - $coin_num = $row['coin_num'] - $cost[1]; - } else if ($cost[0] == 10003) { - if ($row['rmb_num'] < $cost[1]) { - phpcommon\sendError(ERR_USER_BASE + 3, '点券不足'); - return; - } - $rmb_num = $row['rmb_num'] - $cost[1]; - } - $ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, rmb_num=:rmb_num, modify_time=:modify_time ' . - ' WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - ':coin_num' => $coin_num, - ':rmb_num' => $rmb_num, - ':modify_time' => phpcommon\getNowTime() - )); - } else { - $free_times = $rowd['free_times'] - 1; - } - $ret = $conn->execScript('UPDATE draw SET free_times=:free_times, draw_times=:draw_times, modifytime=:modifytime ' . - ' WHERE accountid=:accountid AND id=:id;', - array( - ':accountid' => $account_id, - ':free_times' => $free_times, - ':draw_times' => $draw_times, - ':id' => $id, - ':modifytime' => phpcommon\getNowTime() - )); - if (!$ret) { - die(); - return; - } - } - if ($times == 1) { - if ($draw_times % 10 == 0) { - $item_list = metatable\getDropAllListById($extra_id, $item_list); - } else { - $item_list = metatable\getDropAllListById($drop_id, $item_list); - } - } else if ($times > 1) { - $item_list = metatable\getDropAllListById($extra_id, $item_list); - for ($i = 0; $i < $times; $i++) { - $item_list = metatable\getDropAllListById($drop_id, $item_list); - } - } - $all_item_list = array(); - $addreward = new classes\AddReward(); - if (is_array($item_list)) { - foreach ($item_list as $item) { - $items = $addreward->addReward($item['item_id'], $item['item_num'], $account_id, $item['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); - $rmb_ticket = $addreward->getRmbTicketNum($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, - 'rmb_lot_ticket' => $rmb_ticket, - )); - } -}