diff --git a/sql/gamedb.sql b/sql/gamedb.sql index fbb84dc..53eac75 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -91,12 +91,16 @@ CREATE TABLE `user` ( `newInfo` mediumblob NOT NULL COMMENT '新手引导信息', `first_day_ad` int(11) NOT NULL DEFAULT '0' COMMENT '每日看广告次数', `share_video_times` int(11) NOT NULL DEFAULT '0' COMMENT '每日分享视频次数', - `act_video_status` int(11) NOT NULL DEFAULT '0' COMMENT '分享录频奖励领取状态', `act_ad_status` int(11) NOT NULL DEFAULT '0' COMMENT '观看广告奖励领取状态', `share_video_sums` int(11) NOT NULL DEFAULT '0' COMMENT '分享录频次数', - `biogame_times` int(11) NOT NULL DEFAULT '0' COMMENT '生化模式场次', + + `shop_view_times` int(11) NOT NULL DEFAULT '0' COMMENT '商店看广告次数', + `new_first_equip` int(11) NOT NULL DEFAULT '0' COMMENT '新玩家结算武器', + `newhand2` int(11) NOT NULL DEFAULT '0' COMMENT '精英礼包领取状态', + `game_times2` int(11) NOT NULL DEFAULT '0' COMMENT '精英礼包战斗场次', + `view_times2` int(11) NOT NULL DEFAULT '0' COMMENT '精英礼包视频场次', PRIMARY KEY (`idx`), UNIQUE KEY `accountid` (`accountid`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; @@ -194,6 +198,9 @@ CREATE TABLE `activity` ( `item_num` int(11) NOT NULL DEFAULT '0' COMMENT '物品数量', `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modify_time` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + + + `now_days` int(11) NOT NULL DEFAULT '0' COMMENT '当前第几天', PRIMARY KEY (`idx`), UNIQUE KEY `accountid` (`accountid`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; @@ -268,5 +275,18 @@ CREATE TABLE `equip` ( UNIQUE KEY `accountid_id` (`accountid`, id) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +DROP TABLE IF EXISTS `shop_data`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `shop_data` ( + `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `accountid` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', + `blobdata` mediumblob COMMENT '商店数据json', + `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modify_time` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `accountid` (`accountid`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + -- Dump completed on 2015-08-19 18:51:22 diff --git a/sql/gamedb2004_n_migrate_200829_01.sql b/sql/gamedb2004_n_migrate_200829_01.sql new file mode 100644 index 0000000..ae13702 --- /dev/null +++ b/sql/gamedb2004_n_migrate_200829_01.sql @@ -0,0 +1,27 @@ +begin; + +alter table user add column `shop_view_times` int(11) NOT NULL DEFAULT '0' COMMENT '商店看广告次数'; +alter table user add column `new_first_equip` int(11) NOT NULL DEFAULT '0' COMMENT '新玩家结算武器'; +alter table user add column `newhand2` int(11) NOT NULL DEFAULT '0' COMMENT '精英礼包领取状态'; +alter table user add column `game_times2` int(11) NOT NULL DEFAULT '0' COMMENT '精英礼包战斗场次'; +alter table user add column `view_times2` int(11) NOT NULL DEFAULT '0' COMMENT '精英礼包视频场次'; + +alter table activity add column `now_days` int(11) NOT NULL DEFAULT '0' COMMENT '当前第几天'; + +DROP TABLE IF EXISTS `shop_data`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `shop_data` ( + `idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `accountid` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', + `blobdata` mediumblob COMMENT '商店数据json', + `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modify_time` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `accountid` (`accountid`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + + +insert into version (version) values(2020082901); + +commit; diff --git a/webapp/bootstrap/init.php b/webapp/bootstrap/init.php index 1e02ee2..db7b68e 100644 --- a/webapp/bootstrap/init.php +++ b/webapp/bootstrap/init.php @@ -92,6 +92,10 @@ define('DAILYCOIN_NUM', 132); //每日金币基准数 define('SHARE_VIDEO_REWARD', 147); //分享视频奖励 define('EQUIPREWARD_PARAMETER', 152); //结算比例 define('DIAMONDTOCOIN_NUM', 153); //钻石换金币 +define('CREAM_TASK_01', 155); //钻石换金币 +define('CREAM_TASK_02', 156); //钻石换金币 + + require 'config_loader.php'; function getConfigBaseDir() diff --git a/webapp/controller/ActivityController.class.php b/webapp/controller/ActivityController.class.php index 9abc03f..fca4062 100644 --- a/webapp/controller/ActivityController.class.php +++ b/webapp/controller/ActivityController.class.php @@ -160,6 +160,334 @@ class ActivityController{ return $rec; } + public function newLuckDrawInfo() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $draw_uuid = 'game2004api_newlot_uuid:' . md5($_REQUEST['account_id']); + $draw_list = array(); + $r = $this->getRedis($draw_uuid); + if (!$r) { + die(); + return; + } + //刷新次数 + $p_free = $this->getParameter(FREELOTTERY_TIME); + $p_video = $this->getParameter(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' => time(), + ':modify_time' => time() + )); + 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(time()) - 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' => time(), + )); + 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']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); + return; + } + $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 == 5) { + $day = 1; + if (phpcommon\extractChannel($account_id) == 6001 || + phpcommon\extractChannel($account_id) == 6000) { + $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 + )); + } + } + for ($i1 = 0; $i1 < count($lot_array); $i1++) { + $l = $this->getLottery($lot_array[$i1]['key']); + $weight_sum += $l['jilv']; + } + $random = Rand(0, 100); + if ($random >= 50) { + $key = $lot_array[0]['key']; + } else { + $key = $lot_array[1]['key']; + } + } else if ($row['free_times'] + $row['video_times'] + 1 == 6) { + foreach ($user_db['draw_list'] as $draw) { + if (isset($draw['status']) && $draw['status'] != 0) { + continue; + } + $key = $draw['key'] + 1; + } + } 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); + // error_log($random); + 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 = $this->getParameter(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' => time() + )); + if (!$ret) { + die(); + return; + } + } + if ($_REQUEST['type'] == 1) { + $p_flush = $this->getParameter(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']; + } + } + $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' => time(), + ':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']; @@ -390,13 +718,12 @@ class ActivityController{ phpcommon\sendError(ERR_USER_BASE + 3, '没有这个物品'); return; } - $ret = $conn->execScript('UPDATE activity SET item_id=:item_id, item_num=:item_num, modify_time=:modify_time ' . + $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, - ':modify_time' => time() )); if (!$ret) { die(); @@ -468,10 +795,19 @@ class ActivityController{ } if ($row['free_times'] + $row['video_times'] + 1 == 5) { + $day = 1; + if (phpcommon\extractChannel($account_id) == DOUYIN_CHANNEL || + phpcommon\extractChannel($account_id) == 6001 || + phpcommon\extractChannel($account_id) == 6000) { + $day = date('w', time()); + if ($day == 0) { + $day = 7; + } + } $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) { + if ($l['jilv'] == 0 && $l['day'] == $day) { array_push($lot_array, array( 'key' => $g )); @@ -652,6 +988,72 @@ class ActivityController{ '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) { + if (phpcommon\extractChannel($accountid) == 6001 || + phpcommon\extractChannel($accountid) == 6000) { + $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; + } protected function randomReward($type,$accountid) { @@ -663,10 +1065,14 @@ class ActivityController{ $g_conf_lot_cluster = require('../res/lotterydraw@lotterydraw.php'); } $day = 1; - if ($type == 1 && phpcommon\extractChannel($accountid) == 6006) { - $day = date('w', time()); - if ($day == 0) { - $day = 7; + if ($type == 1) { + if (phpcommon\extractChannel($accountid) == 6001 || + phpcommon\extractChannel($accountid) == 6006 || + phpcommon\extractChannel($accountid) == 6000) { + $day = date('w', time()); + if ($day == 0) { + $day = 7; + } } } diff --git a/webapp/controller/EquipController.class.php b/webapp/controller/EquipController.class.php index 76f4739..3a863b0 100644 --- a/webapp/controller/EquipController.class.php +++ b/webapp/controller/EquipController.class.php @@ -1067,6 +1067,7 @@ class EquipController{ 'coin_nums' => $coin_num, 'diamond_nums' => $num, 'flag' => $flag, + 'id' => $equip_id, )); } } diff --git a/webapp/controller/FriendController.class.php b/webapp/controller/FriendController.class.php index ab35ec9..b9d1c0b 100644 --- a/webapp/controller/FriendController.class.php +++ b/webapp/controller/FriendController.class.php @@ -89,7 +89,7 @@ class FriendController{ phpcommon\sendError(ERR_USER_BASE + 1, '玩家不存在'); return; } - $row = $conn->execQueryOne('SELECT accountid FROM user WHERE accountid=:account_id;', + $row = $conn->execQueryOne('SELECT user_name FROM user WHERE accountid=:account_id;', array( ':account_id' => $account_id, )); @@ -101,6 +101,7 @@ class FriendController{ echo json_encode(array( 'errcode' => 0, 'errmsg' => '', + 'name' => $row['user_name'], )); } } diff --git a/webapp/controller/GameOverController.class.php b/webapp/controller/GameOverController.class.php index 5801e68..6aafd7a 100644 --- a/webapp/controller/GameOverController.class.php +++ b/webapp/controller/GameOverController.class.php @@ -164,7 +164,8 @@ class GameOverController{ } //道具物品 $first_list = array(); - if (phpcommon\extractChannel($account_id) == 6001) { + if (phpcommon\extractChannel($account_id) == 6001 || + phpcommon\extractChannel($account_id) == 6000) { array_push($first_list, array( 'item_id' => 18006, 'item_num' => $num, diff --git a/webapp/controller/PayController.class.php b/webapp/controller/PayController.class.php index bddce2d..efb90c1 100644 --- a/webapp/controller/PayController.class.php +++ b/webapp/controller/PayController.class.php @@ -717,7 +717,7 @@ class PayController{ phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } - $row = $conn->execQueryOne('SELECT vip_score, game_times, newhand, act_ad_status FROM user WHERE accountid=:accountid;', + $row = $conn->execQueryOne('SELECT vip_score, shop_view_times, game_times, newhand, newhand2, view_times2, act_ad_status, game_times2, first_day_ad FROM user WHERE accountid=:accountid;', array( ':accountid' => $account_id, )); @@ -726,18 +726,30 @@ class PayController{ return; } $newhand = $row['newhand']; + $newhand2 = $row['newhand2']; + $rview_times2 = $row['view_times2']; $p1 = $this->getParameter(NEWHAND_NUM1); $fight_times = $p1['value']; $p2 = $this->getParameter(NEWHAND_NUM2); $view_times = $p2['value']; + $p3 = $this->getParameter(CREAM_TASK_01); + $fight_times2 = $p3['value']; + $p4 = $this->getParameter(CREAM_TASK_02); + $view_times2 = $p4['value']; if ($row['game_times'] >= $fight_times && $row['vip_score'] + 1 == $view_times && $newhand == 0) { $newhand = 1; } + if ($newhand == 2) { + if ($row['game_times2'] >= $fight_times2 && $row['view_times2'] + 1 == $view_times2 && $newhand2 == 0) { + $newhand = 1; + } + $rview_times2++; + } $status = $row['act_ad_status']; if ($row['vip_score'] + 1 >= 5 && $row['act_ad_status'] < 1){ $status = 1; } - $ret = $conn->execScript('UPDATE user SET vip_score=:vip_score, modify_time=:modify_time, newhand=:newhand, act_ad_status=:act_ad_status ' . + $ret = $conn->execScript('UPDATE user SET vip_score=:vip_score, shop_view_times=:shop_view_times, modify_time=:modify_time, newhand=:newhand, act_ad_status=:act_ad_status, newhand2=:newhand2, view_times2=:view_times2, first_day_ad=:first_day_ad ' . ' WHERE accountid=:accountid;', array( ':accountid' => $account_id, @@ -745,6 +757,10 @@ class PayController{ ':vip_score' => $row['vip_score'] + 1, ':newhand' => $newhand, ':act_ad_status' => $status, + ':shop_view_times' => $row['shop_view_times'] + 1, + ':newhand2' => $newhand2, + ':view_times2' => $rview_times2, + ':first_day_ad' => $row['first_day_ad'] + 1 )); if (!$ret) { die(); diff --git a/webapp/controller/RoleController.class.php b/webapp/controller/RoleController.class.php index d86b4b4..55db541 100644 --- a/webapp/controller/RoleController.class.php +++ b/webapp/controller/RoleController.class.php @@ -199,9 +199,9 @@ class RoleController{ break; } } - $ret = $conn->execScript('INSERT INTO user(accountid, user_name, avatar_url, game_times, win_times, kills, harm, add_HP, alive_time, coin_num, integral, kill_his, alive_time_his, harm_his, add_HP_his, act_share_time, act_share_status, create_time, modify_time, first_fight, collect_status, keys_num, battle_re_times, shop_flush_times, kefu_status, sign_sum, box_num, diamond_num, sum_coin, pass_status, score, season_status, recharge_times_total, first_gift, season_time, free_coin, free_diamond, season_end_score, kill_modifytime, win_modifytime, rank_modifytime, vip_score, first_login, daily_first_login, daily_time, free_box, update_time, season_games, season_win, sea_max_kill, sea_max_hart, sea_avg_kill, free_lot_ticket, free_dou_lot_ticket, daily_order1, daily_order2, daily_order3, first_bee, newhand, coin_times, newInfo, first_day_ad, share_video_times, share_video_sums, act_video_status, act_ad_status, biogame_times) ' . - ' VALUES(:accountid, :user_name, :avatar_url, 0, 0, 0, 0, 0, 0, 10000, 0, 0, 0, 0, 0, 0, 0, :create_time, :modify_time, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, :season_time, 0, 0, 0, 0, 0, 0, 0, 0, 0, :daily_time, 0,:update_time,0,0,0,0,0,0,0,0,0,0,0,0,0,:newInfo,0,0,0,0,0,0) ' . - ' ON DUPLICATE KEY UPDATE accountid=:accountid, user_name=:user_name, avatar_url=:avatar_url, game_times=0, win_times=0, kills=0, harm=0, add_HP=0, alive_time=0, coin_num=0, integral=0, kill_his=0, alive_time_his=0, harm_his=0, add_HP_his=0, act_share_time=0, act_share_status=0, modify_time=:modify_time, first_fight=0, collect_status=0, keys_num=0, battle_re_times=0, shop_flush_times=0, kefu_status=0, sign_sum=0, box_num=0, diamond_num=0, sum_coin=0, pass_status=0, score=0, season_status=1, recharge_times_total=0, first_gift=0, season_time=:season_time, free_coin=0, free_diamond=0, season_end_score=0, kill_modifytime=0, win_modifytime=0, rank_modifytime=0, vip_score=0, first_login=0, daily_first_login=0, daily_time=:daily_time, free_box=0, update_time=:update_time, season_games=0, season_win=0, sea_max_kill=0, sea_max_hart=0, sea_avg_kill=0, free_lot_ticket=0, free_dou_lot_ticket=0, daily_order1=0, daily_order2=0, daily_order3=0, first_bee=0, newhand=0, coin_times=0, newInfo=:newInfo, first_day_ad=0, share_video_times=0, share_video_sums=0, act_video_status=0, act_ad_status=0, biogame_times=0;', + $ret = $conn->execScript('INSERT INTO user(accountid, user_name, avatar_url, game_times, win_times, kills, harm, add_HP, alive_time, coin_num, integral, kill_his, alive_time_his, harm_his, add_HP_his, act_share_time, act_share_status, create_time, modify_time, first_fight, collect_status, keys_num, battle_re_times, shop_flush_times, kefu_status, sign_sum, box_num, diamond_num, sum_coin, pass_status, score, season_status, recharge_times_total, first_gift, season_time, free_coin, free_diamond, season_end_score, kill_modifytime, win_modifytime, rank_modifytime, vip_score, first_login, daily_first_login, daily_time, free_box, update_time, season_games, season_win, sea_max_kill, sea_max_hart, sea_avg_kill, free_lot_ticket, free_dou_lot_ticket, daily_order1, daily_order2, daily_order3, first_bee, newhand, coin_times, newInfo, first_day_ad, share_video_times, share_video_sums, act_video_status, act_ad_status, biogame_times, shop_view_times, new_first_equip, newhand2,game_times2, view_times2) ' . + ' VALUES(:accountid, :user_name, :avatar_url, 0, 0, 0, 0, 0, 0, 10000, 0, 0, 0, 0, 0, 0, 0, :create_time, :modify_time, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, :season_time, 0, 0, 0, 0, 0, 0, 0, 0, 0, :daily_time, 0,:update_time,0,0,0,0,0,0,0,0,0,0,0,0,0,:newInfo,0,0,0,0,0,0,0,0,0,0,0) ' . + ' ON DUPLICATE KEY UPDATE accountid=:accountid, user_name=:user_name, avatar_url=:avatar_url, game_times=0, win_times=0, kills=0, harm=0, add_HP=0, alive_time=0, coin_num=0, integral=0, kill_his=0, alive_time_his=0, harm_his=0, add_HP_his=0, act_share_time=0, act_share_status=0, modify_time=:modify_time, first_fight=0, collect_status=0, keys_num=0, battle_re_times=0, shop_flush_times=0, kefu_status=0, sign_sum=0, box_num=0, diamond_num=0, sum_coin=0, pass_status=0, score=0, season_status=1, recharge_times_total=0, first_gift=0, season_time=:season_time, free_coin=0, free_diamond=0, season_end_score=0, kill_modifytime=0, win_modifytime=0, rank_modifytime=0, vip_score=0, first_login=0, daily_first_login=0, daily_time=:daily_time, free_box=0, update_time=:update_time, season_games=0, season_win=0, sea_max_kill=0, sea_max_hart=0, sea_avg_kill=0, free_lot_ticket=0, free_dou_lot_ticket=0, daily_order1=0, daily_order2=0, daily_order3=0, first_bee=0, newhand=0, coin_times=0, newInfo=:newInfo, first_day_ad=0, share_video_times=0, share_video_sums=0, act_video_status=0, act_ad_status=0, biogame_times=0, shop_view_times=0, new_first_equip=0, newhand2=0, game_times2=0,view_times2=0;', array( ':accountid' => $account_id, ':user_name' => $user_name, @@ -264,6 +264,11 @@ class RoleController{ 'biogame_times' => 0, 'coin_nums' => 10000, 'diamond_times' => 0, + 'shop_view_times' => 0, + 'new_first_equip' => 0, + 'newhand2' =>0, + 'game_times2'=>0, + 'view_times2'=>0, )); } else { if ($avatar_url != '') { @@ -369,13 +374,18 @@ class RoleController{ 'newhand' => $row['newhand'], 'coin_times' => $coin_times, 'newInfo' => $row['newInfo'], - 'first_day_ad' => 0, + 'first_day_ad' => $first_day_ad, 'integral' => $row['integral'], 'share_video_times' => $share_video_times, 'share_video_sums' => $row['share_video_sums'], 'act_video_status' => $row['act_video_status'], 'act_ad_status' => $act_ad_status, 'biogame_times' => $row['biogame_times'], + 'shop_view_times' => $row['shop_view_times'], + 'new_first_equip' => $row['new_first_equip'], + 'newhand2' =>$row['newhand2'], + 'game_times2'=>$row['game_times2'], + 'view_times2'=>$row['view_times2'], )); } } @@ -575,15 +585,26 @@ class RoleController{ } $daily_first_login = $row['daily_first_login']; $newhand = $row['newhand']; + $newhand2 = $row['newhand2']; + $game_times2 = $row['game_times2']; $p1 = $this->getParameter(NEWHAND_NUM1); $fight_times = $p1['param_value']; $p2 = $this->getParameter(NEWHAND_NUM2); $view_times = $p2['param_value']; + $p3 = $this->getParameter(CREAM_TASK_01); + $fight_times2 = $p3['param_value']; + $p4 = $this->getParameter(CREAM_TASK_02); + $view_times2 = $p4['param_value']; if ($row['game_times'] + 1 == $fight_times && $row['vip_score'] >= $view_times) { $newhand = 1; } - - $ret = $conn->execScript('UPDATE user SET game_times=:game_times, kills=:kills, harm=:harm, alive_time=:alive_time, kill_his=:kill_his, alive_time_his=:alive_time_his, harm_his=:harm_his, coin_num=:coin_num, modify_time=:modify_time, first_fight=1, daily_time=:daily_time, season_games=:season_games, sea_max_kill=:sea_max_kill, sea_max_hart=:sea_max_hart, sea_avg_kill=:sea_avg_kill, newhand=:newhand ' . + if ($newhand == 2) { + if ($row['game_times2'] + 1 == $fight_times2 && $row['view_times2'] >= $view_times2) { + $newhand2 = 1; + } + $game_times2++; + } + $ret = $conn->execScript('UPDATE user SET game_times=:game_times, kills=:kills, harm=:harm, alive_time=:alive_time, kill_his=:kill_his, alive_time_his=:alive_time_his, harm_his=:harm_his, coin_num=:coin_num, modify_time=:modify_time, first_fight=1, daily_time=:daily_time, season_games=:season_games, sea_max_kill=:sea_max_kill, sea_max_hart=:sea_max_hart, sea_avg_kill=:sea_avg_kill, newhand=:newhand, newhand2=:newhand2, game_times2=:game_times2 ' . 'WHERE accountid=:accountid;', array( ':game_times' => $row['game_times'] + 1, @@ -602,6 +623,8 @@ class RoleController{ ':sea_max_hart' => $sea_max_hart, ':sea_avg_kill' => $row['sea_avg_kill'] + $kills, ':newhand' => $newhand, + ':newhand2' => $newhand2, + ':game_times2' => $game_times2, )); if (!$ret) { die(); @@ -846,15 +869,27 @@ class RoleController{ }*/ $newhand = $row['newhand']; + $newhand2 = $row['newhand2']; + $game_times2 = $row['game_times2']; $p1 = $this->getParameter(NEWHAND_NUM1); $fight_times = $p1['param_value']; $p2 = $this->getParameter(NEWHAND_NUM2); $view_times = $p2['param_value']; + $p3 = $this->getParameter(CREAM_TASK_01); + $fight_times2 = $p3['param_value']; + $p4 = $this->getParameter(CREAM_TASK_02); + $view_times2 = $p4['param_value']; if ($row['game_times'] + 1 == $fight_times && $row['vip_score'] >= $view_times) { $newhand = 1; } + if ($newhand == 2) { + if ($row['game_times2'] + 1 == $fight_times2 && $row['view_times2'] >= $view_times2) { + $newhand2 = 1; + } + $game_times2++; + } - $ret = $conn->execScript('UPDATE user SET game_times=:game_times, kills=:kills, harm=:harm, add_HP=:add_HP, alive_time=:alive_time, kill_his=:kill_his, alive_time_his=:alive_time_his, harm_his=:harm_his, add_HP_his=:add_HP_his, coin_num=:coin_num, modify_time=:modify_time, first_fight=1, box_num=:box_num, score=:score, daily_time=:daily_time, season_games=:season_games, sea_max_kill=:sea_max_kill, sea_max_hart=:sea_max_hart, sea_avg_kill=:sea_avg_kill, newhand=:newhand ' . + $ret = $conn->execScript('UPDATE user SET game_times=:game_times, kills=:kills, harm=:harm, add_HP=:add_HP, alive_time=:alive_time, kill_his=:kill_his, alive_time_his=:alive_time_his, harm_his=:harm_his, add_HP_his=:add_HP_his, coin_num=:coin_num, modify_time=:modify_time, first_fight=1, box_num=:box_num, score=:score, daily_time=:daily_time, season_games=:season_games, sea_max_kill=:sea_max_kill, sea_max_hart=:sea_max_hart, sea_avg_kill=:sea_avg_kill, newhand=:newhand, newhand2=:newhand2, game_times2=:game_times2 ' . 'WHERE accountid=:accountid;', array( ':game_times' => $row['game_times'] + 1, @@ -877,6 +912,8 @@ class RoleController{ ':sea_max_hart' => $sea_max_hart, ':sea_avg_kill' => $row['sea_avg_kill'] + $kills, ':newhand' => $newhand, + ':newhand2' => $newhand2, + ':game_times2' => $game_times2, )); if (!$ret) { die(); @@ -1231,25 +1268,51 @@ class RoleController{ phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } - $row = $conn->execQueryOne('SELECT newhand FROM user WHERE accountid=:account_id;', + $row = $conn->execQueryOne('SELECT newhand, newhand2 FROM user WHERE accountid=:account_id;', array( ':account_id' => $account_id )); - if (!$row || $row['newhand'] != 1) { - phpcommon\sendError(ERR_USER_BASE + 2, '未达到领取条件'); - return; + $type = 1; + if (isset($_REQUEST['type'])) { + $type = $_REQUEST['type']; } - $ret = $conn->execScript('UPDATE user SET newhand=2, modify_time=:modify_time ' . - ' WHERE accountid=:accountid;', - array( - ':modify_time' => time(), - ':accountid' => $account_id - )); - if (!$ret) { - die(); - return; + $reward_id = 29001; + if ($type == 1) { + $reward_id = 29001; + if (!$row || $row['newhand'] != 1) { + phpcommon\sendError(ERR_USER_BASE + 2, '未达到领取条件'); + return; + } + $ret = $conn->execScript('UPDATE user SET newhand=2, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':modify_time' => time(), + ':accountid' => $account_id + )); + if (!$ret) { + die(); + return; + } + } else if ($type == 2) { + $reward_id = 29002; + if (!$row || $row['newhand2'] != 1) { + phpcommon\sendError(ERR_USER_BASE + 2, '未达到领取条件'); + return; + } + $ret = $conn->execScript('UPDATE user SET newhand2=2, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':modify_time' => time(), + ':accountid' => $account_id + )); + if (!$ret) { + die(); + return; + } } - $d = $this->getDrop(29001); + + + $d = $this->getDrop($reward_id); if (!$d) { phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); return; @@ -1834,5 +1897,58 @@ class RoleController{ 'errmsg'=> '', )); } + + public function getFightEquip() + { + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $id = $_REQUEST['id']; + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + + } + $addreward = new classes\AddReward(); + $item_list = array(); + array_push($item_list, array( + 'item_id' => $id, + 'item_num' => 1, + 'time' => 0 + )); + $all_item_list = $addreward->addReward($id, 1, $account_id, 0, 0); + $ret = $conn->execScript('UPDATE user SET new_first_equip=1, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':modify_time' => time(), + )); + if (!$ret) { + die(); + return; + } + $ret = $conn->execScript('UPDATE equip SET using_id=:using_id, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':using_id' => $id, + ':modify_time' => time(), + )); + if (!$ret) { + die(); + return; + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg'=> '', + 'item_list' => $item_list, + 'all_item_list' => $all_item_list, + )); + } } ?> diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 56f3662..2949e01 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -34,6 +34,9 @@ class ShopController{ { $g_conf_item_cluster = require('../res/item@item.php'); $item_conf = getItemConfig($g_conf_item_cluster, $item_id); + if (!$item_conf) { + return null; + } $it = array( 'id' => $item_conf['id'], 'price' => $item_conf['gold'], @@ -45,6 +48,7 @@ class ShopController{ 'shop_list' => $item_conf['shop_list'], 'bug_groupnum' => $item_conf['bug_groupnum'], 'Isbug_again' => $item_conf['Isbug_again'], + 'fuctionindex' => $item_conf['fuctionindex'], ); return $it; } @@ -67,11 +71,22 @@ class ShopController{ return $it; } - protected function getShop($shop_id) + protected function getDrop($drop_id) { - + $drop_meta_table = require('../res/drop@drop.php'); + $drop_meta = getDropConfig($drop_meta_table, $drop_id); + if (!$drop_meta) { + return null; + } + $d = array( + 'drop_id' => $drop_meta['drop_id'], + 'item_id' => $drop_meta['item_id'], + 'num' => $drop_meta['num'], + 'weight' => $drop_meta['weight'], + 'type' => $drop_meta['type'] + ); + return $d; } - protected function getParameter($para_id) { $g_conf_para_cluster = require('../res/parameter@parameter.php'); @@ -97,6 +112,53 @@ class ShopController{ return $arr; } + protected function readShopDB($account_id) { + $conn = $this->getMysql($account_id); + $row = $conn->execQueryOne('SELECT blobdata FROM shop_data WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if (!empty($row)) { + $shop_db_str = $row['blobdata']; + $shop_db = json_decode($shop_db_str, true); + return $shop_db; + } else { + return null; + } + } + + protected function saveShopDB($account_id, $shop_db) { + $conn = $this->getMysql($account_id); + $row = $conn->execQueryOne('SELECT accountid FROM shop_data WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + $shop_db_str = ""; + if (!empty($shop_db)) { + $shop_db_str = json_encode($shop_db); + } + if (!empty($row)) { + //update + $row = $conn->execScript('UPDATE shop_data SET blobdata=:blobdata, modify_time=:modify_time WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':blobdata' => $shop_db_str, + ':modify_time' => time() + )); + } else { + //insert + $row = $conn->execScript('INSERT INTO shop_data(accountid, blobdata, create_time, modify_time) ' . + ' VALUES(:account_id, :blobdata, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:account_id, blobdata=:blobdata, modify_time=:modify_time;', + array( + ':account_id' => $account_id, + ':blobdata' => $shop_db_str, + ':create_time' => time(), + ':modify_time' => time(), + )); + } + } + //新版商店 public function newShopInfo() { @@ -113,28 +175,16 @@ class ShopController{ phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); return; } - $new_shop_uuid = 'game2004api_new_shop_uuid: ' . md5($_REQUEST['account_id']); + $new_shop_uuid = 'game2004api_shop_uuid_new:' . $_REQUEST['account_id']; //商店信息 - $this->getNewShopInfo($new_shop_uuid); - $r = $this->getRedis($new_shop_uuid); - if (!$r) { - phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); - return; - } - $user_db_str = $r->get($new_shop_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; - } + $this->getNewShopInfo($new_shop_uuid, $account_id); + $user_db = $this->readShopDB($account_id); + echo json_encode(array( 'errcode' => 0, 'errmsg'=> '', 'shop_uuid' => $new_shop_uuid, + 'active_time' => $user_db['active_time'], 'act_list' => $user_db['act_list'], 'free_list' => $user_db['free_list'], 'sel_list' => $user_db['sel_list'], @@ -144,43 +194,64 @@ class ShopController{ )); } - protected function getNewShopInfo($shop_uuid) + protected function getNewShopInfo($shop_uuid, $account_id) { - $r = $this->getRedis($shop_uuid); - if (!$r) { - die(); - return; - } $act_list = array(); $free_list = array(); $sel_list = array(); $equ_list = array(); $clo_list = array(); $item_list = array(); - $user_db_str = $r->get($shop_uuid); - if (empty($user_db_str)) { + $user_db = $this->readShopDB($account_id); + $shop_conf = metatable\getShopConf(); + if (!$shop_conf) { + phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); + return; + } + $active_time = 0; + if (empty($user_db)) { $act_list = $this->randomNewShop(1); $free_list = $this->randomNewShop(2); $sel_list = $this->randomNewShop(3); $equ_list = $this->randomNewShop(4); $clo_list = $this->randomNewShop(5); $item_list = $this->randomNewShop(6); + $active_time = time(); } else { - $user_db = json_decode($user_db_str, true); - if (empty($user_db)) { - phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); - return; + $act_list = $user_db['act_list']; + $free_list = $user_db['free_list']; + $sel_list = $user_db['sel_list']; + $equ_list = $user_db['equ_list']; + $clo_list = $user_db['clo_list']; + $item_list = $user_db['item_list']; + $active_time = $user_db['active_time']; + $nowTime = phpcommon\getdayseconds(time()); + $passed_days = floor(($nowTime - phpcommon\getdayseconds($user_db['active_time'])) / (3600 * 24)); + if ($passed_days >= 1) { + for ($i = 1; $i <= count($shop_conf); $i++) { + if ($shop_conf[$i]['isrefresh'] == 0) { + continue; + } + if ($shop_conf[$i]['shop_id'] == 1) { + $act_list = $this->randomNewShop(1); + } else if($shop_conf[$i]['shop_id'] == 2) { + $free_list = $this->randomNewShop(2); + } else if($shop_conf[$i]['shop_id'] == 3) { + $sel_list = $this->randomNewShop(3); + } else if($shop_conf[$i]['shop_id'] == 4) { + $equ_list = $this->randomNewShop(4); + } else if($shop_conf[$i]['shop_id'] == 5) { + $clo_list = $this->randomNewShop(5); + } else if($shop_conf[$i]['shop_id'] == 6) { + $item_list = $this->randomNewShop(6); + } + } + $active_time = $nowTime; } - $act_list = $this->getNewShopList($user_db['act_list'], 1); - $free_list = $this->getNewShopList($user_db['free_list'],2); - $sel_list = $this->getNewShopList($user_db['sel_list'], 3); - $equ_list = $this->getNewShopList($user_db['equ_list'], 4); - $clo_list = $this->getNewShopList($user_db['clo_list'], 5); - $item_list = $this->getNewShopList($user_db['item_list'],6); } - $shop_db = array( 'shop_uuid' => $shop_uuid, + 'active_time' => $active_time, 'act_list' => $act_list, 'free_list' => $free_list, 'sel_list' => $sel_list, @@ -188,8 +259,7 @@ class ShopController{ 'clo_list' => $clo_list, 'item_list' => $item_list, ); - $r -> set($shop_uuid, json_encode($shop_db)); - $r -> pexpire($shop_uuid, 1000 * 3600 * 24 * 7); + $this->saveShopDB($account_id, $shop_db); } protected function randomNewShop($id) @@ -203,46 +273,235 @@ class ShopController{ return metatable\randGoods($shop_conf, $shop_list); } - protected function getNewShopList($list, $id) + public function newBuyShopItem() { - $exclude_goods = array(); - $shop_conf = metatable\getShopById($id); - $nowTime = phpcommon\getdayseconds(time()); - $remove_list = array(); - foreach ($list as $s) { - $sgoods_conf = metatable\getShopGoodsById($s['id']); - $passed_days = floor(($nowTime - phpcommon\getdayseconds($s['active_time'])) / (3600 * 24)); - //小于一天不刷新 - if ($passed_days < 1) { - $exclude_goods[$s['id']]= 1; - //小于两天未购买道具不刷新 - } else if ($sgoods_conf['time'] == 2 && $passed_days < 2) { - if ($s['status'] == 0 || $passed_days < 1) { - $exclude_goods[$s['id']]= 1; - } else if ($s['status'] == 1 && $passed_days >= 1){ - $remove_list[$s['id']]= 1; + $account_id = $_REQUEST['account_id']; + //登录校验 + $login = loginVerify($account_id, $_REQUEST['session_id']); + if (!$login) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + $id = $_REQUEST['id']; + $type = $_REQUEST['type']; + $num = $_REQUEST['num']; + $user_db = $this->readShopDB($account_id); + $redis_goods = $this->getGoodsDiscount($id, $type, $user_db); + $shop_conf = metatable\getShopById($type); + if (!$shop_conf || !$redis_goods) { + phpcommon\sendError(ERR_USER_BASE + 2,'没有这个商品'); + return; + } + if ($redis_goods['status'] == 1) { + phpcommon\sendError(ERR_USER_BASE + 4,'商品已购买'); + return; + } + $price = $redis_goods['price'] * $num; + if ($redis_goods['isdiscount']) { + $price = ceil($price * $redis_goods['dis_num'] / 100); + } + $item_conf = $this->getItem($id); + $item_fuctionindex = $item_conf['fuctionindex']; + $drop_conf = $this->getDrop($item_fuctionindex); + if (!$item_conf) { + phpcommon\sendError(ERR_USER_BASE + 5,'没有这个道具'); + return; + } + //扣除货币 + if ($redis_goods['buy'] != 0) { + $this->subCoin($price, $account_id, $redis_goods['buy'], $shop_conf['istodayad']); + } + //增加奖励 + $addreward = new classes\AddReward(); + $item_list = array(); + $all_item_list = array(); + if ($item_conf['type'] == 13) { + $item_list = $this->getRandomShopReward($item_fuctionindex); + foreach ($item_list as $it) { + $item_id = $it['item_id']; + $num = $it['item_num']; + $time = 0; + + $items = $addreward->addReward($item_id, $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'], + )); } - //刷新时间两天并大于两天刷新 - } else if ($sgoods_conf['time'] == 2 && $passed_days >= 2) { - $remove_list[$s['id']]= 1; - //刷新时间一天并大于一天刷新 - } else if ($sgoods_conf['time'] == 1 && $passed_days >= 1) { - $remove_list[$s['id']]= 1; + } + } else { + array_push($item_list,array( + 'item_id' => $redis_goods['id'], + 'item_num' => $num, + 'time' => 0, + )); + $items = $addreward->addReward($redis_goods['id'], $num, $account_id, 0, 0); + foreach($items as $j) { + array_push($all_item_list, array( + 'item_id' => $j['item_id'], + 'item_num' => $j['item_num'], + 'time' => $j['time'], + )); } } - //删除多余的道具 - if (!empty($remove_list)) { - for ($i = count($list) - 1; $i >= 0; --$i) { - if (array_key_exists($list[$i]['id'], $remove_list)) { - array_splice($list, $i, 1); + //修改购买状态 + if ($shop_conf['isrepeat'] == 0) { + $this->updateShopRedis($account_id, $id, $type, $user_db); + } + $coin_num = $addreward->getCoinNum($account_id); + $diamond_num = $addreward->getDiamondNum($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 getRandomShopReward($drop_id) + { + $airReward_list = array(); + //随机奖励 + $d = $this->getDrop($drop_id); + if (!$d) { + phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); + die(); + } + $item_id_array = $this->getExplode($d['item_id']); + $item_num_array = $this->getExplode($d['num']); + $weight_array = $this->getExplode($d['weight']); + if ($d['type'] == 2) { + $weight_sum = 0; + $keys = 0; + 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]; + array_push($airReward_list, array( + 'item_id' => $item_id, + 'item_num' => $item_num, + 'time' => 0, + )); + } + if ($d['type'] == 1) { + for ($i = 0; $i < count($weight_array); $i++) { + $random = Rand(0, 10000); + if ($weight_array[$i][0] < $random) { + continue; + } + array_push($airReward_list, array( + 'item_id' => $item_id_array[$i][0], + 'item_num' => $item_num_array[$i][0], + 'time' => 0, + )); + } + } + return $airReward_list; + } + + protected function updateShopRedis($account_id, $id, $type, $user_db) + { + if ($type == 1) { + foreach ($user_db['act_list'] as &$re) { + if ($re['id'] == $id) { + $re['status'] = 1; + break; + } + } + } else if ($type == 2) { + foreach ($user_db['free_list'] as &$re) { + if ($re['id'] == $id) { + $re['status'] = 1; + break; + } + } + } else if ($type == 3) { + foreach ($user_db['sel_list'] as &$re) { + if ($re['id'] == $id) { + $re['status'] = 1; + break; + } + } + } else if ($type == 4) { + foreach ($user_db['equ_list'] as &$re) { + if ($re['id'] == $id) { + $re['status'] = 1; + break; + } + } + } else if ($type == 5) { + foreach ($user_db['clo_list'] as &$re) { + if ($re['id'] == $id) { + $re['status'] = 1; + break; + } + } + } else if ($type == 6) { + foreach ($user_db['item_list'] as &$re) { + if ($re['id'] == $id) { + $re['status'] = 1; + break; } } } - $good_list = metatable\randGoods($shop_conf, $exclude_goods); - if (!empty($remove_list)) { - array_push($list, $good_list); + $this->saveShopDB($account_id, $user_db); + } + + protected function getGoodsDiscount($id, $type, $user_db) + { + if ($type == 1) { + foreach ($user_db['act_list'] as $re) { + if ($re['id'] == $id) { + return $re; + } + } + } else if ($type == 2) { + foreach ($user_db['free_list'] as $re) { + if ($re['id'] == $id) { + return $re; + } + } + } else if ($type == 3) { + foreach ($user_db['sel_list'] as $re) { + if ($re['id'] == $id) { + return $re; + } + } + } else if ($type == 4) { + foreach ($user_db['equ_list'] as $re) { + if ($re['id'] == $id) { + return $re; + } + } + } else if ($type == 5) { + foreach ($user_db['clo_list'] as $re) { + if ($re['id'] == $id) { + return $re; + } + } + } else if ($type == 6) { + foreach ($user_db['item_list'] as $re) { + if ($re['id'] == $id) { + return $re; + } + } } - return $list; + return null; } @@ -542,7 +801,7 @@ class ShopController{ if ($row_c) { $price = round($i['price'] * $num * $row_c['coin_discount'] / 10); } - $this->SubCoin($price, $account_id, 1); + $this->SubCoin($price, $account_id, 1, 0); } else if ($i['shop_type'] == 2) { $price = $i['dprice'] * $num; $row_d = $conn->execQueryOne('SELECT * FROM shop WHERE accountid=:accountid AND diamond_id=:id;', @@ -553,7 +812,7 @@ class ShopController{ if ($row_d) { $price = round($i['dprice'] * $num * $row_d['diamond_discount'] / 10); } - $this->SubCoin($price, $account_id, 2); + $this->SubCoin($price, $account_id, 2, 0); } else if ($i['shop_type'] == 3) { if ($type == 0) { $row_c = $conn->execQueryOne('SELECT * FROM shop WHERE accountid=:accountid AND coin_id=:id;', @@ -565,7 +824,7 @@ class ShopController{ if ($row_c) { $price = round($i['price'] * $num * $row_c['coin_discount'] / 10); } - $this->SubCoin($price, $account_id, 1); + $this->SubCoin($price, $account_id, 1, 0); } else if ($type == 1) { $price = $i['dprice'] * $num; $row_d = $conn->execQueryOne('SELECT * FROM shop WHERE accountid=:accountid AND diamond_id=:id;', @@ -576,7 +835,7 @@ class ShopController{ if ($row_d) { $price = round($i['dprice'] * $num * $row_d['diamond_discount'] / 10); } - $this->SubCoin($price, $account_id, 2); + $this->SubCoin($price, $account_id, 2, 0); } } //增加奖励 @@ -646,7 +905,7 @@ class ShopController{ if ($row_c) { $price = round($i['price'] * $row_c['coin_discount'] / 10); } - $this->SubCoin($price, $account_id, 1); + $this->SubCoin($price, $account_id, 1, 0); } else if ($i['shop_type'] == 2) { $price = $i['dprice']; if ($i['type'] == 10) { @@ -661,7 +920,7 @@ class ShopController{ if ($row_d) { $price = round($i['dprice'] * $row_d['diamond_discount'] / 10); } - $this->SubCoin($price, $account_id, 2); + $this->SubCoin($price, $account_id, 2,0); } else if ($i['shop_type'] == 3) { if ($type == 0) { $row_c = $conn->execQueryOne('SELECT * FROM shop WHERE accountid=:accountid AND coin_id=:id;', @@ -676,7 +935,7 @@ class ShopController{ if ($row_c) { $price = round($i['price'] * $row_c['coin_discount'] / 10); } - $this->SubCoin($price, $account_id, 1); + $this->SubCoin($price, $account_id, 1, 0); } else if ($type == 1) { $price = $i['dprice']; if ($i['type'] == 10) { @@ -691,7 +950,7 @@ class ShopController{ if ($row_d) { $price = round($i['dprice'] * $row_d['diamond_discount'] / 10); } - $this->SubCoin($price, $account_id, 2); + $this->SubCoin($price, $account_id, 2, 0); } } //增加奖励 @@ -796,7 +1055,7 @@ class ShopController{ if ($shop_type == 2) { $p = $this->getParameter(RAND_DIAMONDSHOP_GOLD); } - $this->SubCoin($p['param_value'], $account_id, $_REQUEST['type']); + $this->SubCoin($p['param_value'], $account_id, $_REQUEST['type'], 0); } $conn = $this->getMysql($account_id); if (!$conn) { @@ -974,14 +1233,14 @@ class ShopController{ return $shop_list; } - protected function subCoin($coin_num, $account_id, $tips) + protected function subCoin($coin_num, $account_id, $tips, $isview) { $conn = $this->getMysql($account_id); if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); return; } - $rowCoin = $conn->execQueryOne('SELECT coin_num, diamond_num FROM user WHERE accountid=:accountid;', + $rowCoin = $conn->execQueryOne('SELECT coin_num, diamond_num, shop_view_times, first_day_ad FROM user WHERE accountid=:accountid;', array( ':accountid' => $account_id )); @@ -990,6 +1249,7 @@ class ShopController{ if ($rowCoin['coin_num'] < $coin_num) { phpcommon\sendError(ERR_USER_BASE + 3, '金币不足'); die(); + return; } $ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' . ' WHERE accountid=:accountid;', @@ -1007,6 +1267,7 @@ class ShopController{ if ($rowCoin['diamond_num'] < $coin_num) { phpcommon\sendError(ERR_USER_BASE + 5, '钻石不足'); die(); + return; } $ret = $conn->execScript('UPDATE user SET diamond_num=:diamond_num, modify_time=:modify_time ' . ' WHERE accountid=:accountid;', @@ -1019,6 +1280,22 @@ class ShopController{ die(); } } + + if ($tips == 3) { + if ($isview == 1) { + if ($rowCoin['first_day_ad'] < $coin_num) { + phpcommon\sendError(ERR_USER_BASE + 7, '每日视频次数不足'); + die(); + return; + } + } else { + if ($rowCoin['shop_view_times'] < $coin_num) { + phpcommon\sendError(ERR_USER_BASE + 6, '视频次数不足'); + die(); + return; + } + } + } } } ?> diff --git a/webapp/metatable/shop.php b/webapp/metatable/shop.php index c68226a..7398619 100644 --- a/webapp/metatable/shop.php +++ b/webapp/metatable/shop.php @@ -16,6 +16,19 @@ use phpcommon; !!!注意必须使用require_once */ +function getExplode($string) +{ + $delim = "|"; + $drop_multiply = explode($delim, $string); + $delim1 = ":"; + $arr = array(); + for ($i = 0; $i < count($drop_multiply); $i++) { + $mul = explode($delim1, $drop_multiply[$i]); + array_push($arr, $mul); + } + return $arr; +} + function getShopConf() { return _internalGetShopConf(); @@ -33,16 +46,18 @@ function randGoods($shop_conf, $exclude_goods) $num = $shop_conf['num']; $goods_list = explode('|', $shop_conf['goods_list']); $goods_weight = explode('|', $shop_conf['goods_weight']); + $goods_buy = getExplode($shop_conf['price']); + $goods_discount = explode('|', $shop_conf['discount']); $discount_num = $shop_conf['discount_num']; - if (!empty($exclude_goods)) { - for ($i = count($goods_list) - 1; $i >= 0; --$i) { - if (array_key_exists($goods_list[$i], $exclude_goods)) { - array_splice($goods_list, $i, 1); - array_splice($goods_weight, $i, 1); - --$num; - } - } - } + // if (!empty($exclude_goods)) { + // for ($i = count($goods_list) - 1; $i >= 0; --$i) { + // if (array_key_exists($goods_list[$i], $exclude_goods)) { + // array_splice($goods_list, $i, 1); + // array_splice($goods_weight, $i, 1); + // --$num; + // } + // } + // } $goods = array(); for ($i = 0; $i < $num; ++$i) { $rand_space = 0; @@ -65,12 +80,16 @@ function randGoods($shop_conf, $exclude_goods) if ($rnd_val <= $curr_val) { array_push($goods, array( 'id' => $goods_list[$ii], - 'active_time' => time(), + 'buy' => $goods_buy[$ii][0], + 'price' => $goods_buy[$ii][1], 'status' => 0, 'isdiscount' => $discount, + 'dis_num' => $goods_discount[$ii] )); array_splice($goods_list, $ii, 1); array_splice($goods_weight, $ii, 1); + array_splice($goods_buy, $ii, 1); + array_splice($goods_discount, $ii, 1); break; } }