From d86c55c9622a2a7378f2ff46cd1c0aa2978db25a Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 22 Oct 2020 17:36:31 +0800 Subject: [PATCH] 1 --- sql/gamedb.sql | 16 +- sql/gamedb2004_n_migrate_200426_01.sql | 2 +- sql/gamedb2004_n_migrate_201022_01.sql | 16 + .../FesActivityController.class.php | 333 ++++++++++++++++++ webapp/metatable/activity.php | 106 ++++++ 5 files changed, 468 insertions(+), 5 deletions(-) create mode 100644 sql/gamedb2004_n_migrate_201022_01.sql create mode 100644 webapp/controller/FesActivityController.class.php create mode 100644 webapp/metatable/activity.php diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 305959c..fbba173 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -100,7 +100,6 @@ CREATE TABLE `user` ( `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 '精英礼包视频场次', - `guildcoin_num` int(11) NOT NULL DEFAULT '0' COMMENT '战队货币', `new_second_equip` int(11) NOT NULL DEFAULT '2' COMMENT '新玩家隔天结算武器', PRIMARY KEY (`idx`), @@ -200,8 +199,6 @@ 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`) @@ -290,5 +287,16 @@ CREATE TABLE `shop_data` ( UNIQUE KEY `accountid` (`accountid`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; - +DROP TABLE IF EXISTS `festival_activity`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `festival_activity` ( + `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_200426_01.sql b/sql/gamedb2004_n_migrate_200426_01.sql index d32a7b5..dee533f 100644 --- a/sql/gamedb2004_n_migrate_200426_01.sql +++ b/sql/gamedb2004_n_migrate_200426_01.sql @@ -1,6 +1,6 @@ begin; -alter table user add column `free_lot_ticket` int(11) NOT NULL DEFAULT '0' COMMENT '免费抽奖券'; +alter table user add column `free_lot_ticket` int(11) NOT NULL DEFAULT '0' COMMENT '免费抽奖券';xes alter table user add column `free_dou_lot_ticket` int(11) NOT NULL DEFAULT '0' COMMENT '免费十倍抽奖券'; UPDATE user set sign_sum=7 WHERE sign_sum >= 7; UPDATE actitity set free_times=0, video_times=0; diff --git a/sql/gamedb2004_n_migrate_201022_01.sql b/sql/gamedb2004_n_migrate_201022_01.sql new file mode 100644 index 0000000..a77bc14 --- /dev/null +++ b/sql/gamedb2004_n_migrate_201022_01.sql @@ -0,0 +1,16 @@ +begin; + +CREATE TABLE `festival_activity` ( + `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(20200324); + +commit; diff --git a/webapp/controller/FesActivityController.class.php b/webapp/controller/FesActivityController.class.php new file mode 100644 index 0000000..e58c654 --- /dev/null +++ b/webapp/controller/FesActivityController.class.php @@ -0,0 +1,333 @@ + $redis_conf['host'], + 'port' => $redis_conf['port'], + 'passwd' => $redis_conf['passwd'] + + )); + return $r; + } + + protected function getMysql($account_id) + { + $mysql_conf = getMysqlConfig(crc32($account_id)); + $conn = new phpcommon\Mysql(array( + 'host' => $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => DBNAME_PREFIX . $mysql_conf['instance_id'] + )); + return $conn; + } + + protected function getParameter($para_id) + { + $g_conf_para_cluster = require('../res/parameter@parameter.php'); + $para_conf = getParameterConfig($g_conf_para_cluster, $para_id); + $p = array( + 'id' => $para_conf['id'], + 'param_name' => $para_conf['param_name'], + 'param_value' => $para_conf['param_value'], + ); + return $p; + } + + protected 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; + } + + protected function readFesActDB($account_id) { + $conn = $this->getMysql($account_id); + $row = $conn->execQueryOne('SELECT blobdata FROM festival_activity WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if (!empty($row)) { + $fes_db_str = $row['blobdata']; + $fes_db = json_decode($fes_db_str, true); + return $fes_db; + } else { + return null; + } + } + + protected function saveFesActDB($account_id, $fes_db) { + $conn = $this->getMysql($account_id); + $row = $conn->execQueryOne('SELECT accountid FROM festival_activity WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + $fes_db_str = ""; + if (!empty($fes_db)) { + $fes_db_str = json_encode($fes_db); + } + if (!empty($row)) { + //update + $row = $conn->execScript('UPDATE festival_activity SET blobdata=:blobdata, modify_time=:modify_time WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':blobdata' => $fes_db_str, + ':modify_time' => time() + )); + } else { + //insert + $row = $conn->execScript('INSERT INTO festival_activity(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' => $fes_db_str, + ':create_time' => time(), + ':modify_time' => time(), + )); + } + } + + //节日活动 + public function acitivityInfo() + { + $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; + } + //节日活动信息 + $this->getfesActInfo($account_id); + $user_db = $this->readFesActDB($account_id); + //metatable\getRewardInfo(1,1,1); + echo json_encode(array( + 'errcode' => 0, + 'errmsg'=> '', + 'isopen' => $user_db['isopen'], + 'id' => $user_db['act_id'], + 'info_list' => $user_db['info_list'], + )); + } + + protected function getfesActInfo($account_id) + { + $user_db = $this->readFesActDB($account_id); + $act = metatable\getNowActivity(); + $info_list = array(); + if (!$act) { + //活动未开启 + $act_db = array( + 'isopen' => 0, + 'act_id' => 0, + 'info_list' => $info_list, + ); + $this->saveFesActDB($account_id, $act_db); + } else { + //活动开启 + if (empty($user_db) || empty($user_db['info_list'])) { + $info_list = $this->getActItem($act['id']); + $act_db = array( + 'isopen' => 1, + 'act_id' => $act['id'], + 'info_list' => $info_list, + ); + $this->saveFesActDB($account_id, $act_db); + } + } + } + + protected function getActItem($id) + { + $act_conf = metatable\getActivityById($id); + if (!$act_conf) { + die(); + return; + } + return metatable\getActInfo($act_conf); + } + + public function getActReward() + { + $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; + } + $user_db = $this->readFesActDB($account_id); + if (empty($user_db) || $user_db['isopen'] == 0) { + phpcommon\sendError(ERR_USER_BASE + 3, '活动未开启'); + return; + } + $reward = array(); + $id = $_REQUEST['id']; + $status = 1; + foreach ($user_db['info_list'] as &$us) { + if ($us['id'] == $id) { + if ($us['status'] != 1) { + phpcommon\sendError(ERR_USER_BASE + 4, '奖励不可领'); + return; + } + $us['status'] = 2; + $status = 2; + $reward = metatable\getRewardInfo($user_db['act_id'], $id, 0); + break; + } + } + if (empty($reward) || !$reward) { + phpcommon\sendError(ERR_USER_BASE + 5, '没有这个奖励'); + return; + } + //更新奖励状态 + $this->saveFesActDB($account_id, $user_db); + //领取奖励 + $item_list = array(); + $all_item_list = array(); + $addreward = new classes\AddReward(); + for ($i = 0; $i < count($reward); $i++) { + $item_id = $reward[$i][0]; + $num = $reward[$i][1]; + $time = $reward[$i][2]; + array_push($item_list, array( + 'item_id' => $item_id, + 'item_num' => $num, + 'time' => $time, + )); + $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'], + )); + } + } + $coin_num = $addreward->getCoinNum($account_id); + $diamond_num = $addreward->getDiamondNum($account_id); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'item_list' => $item_list, + 'coin_nums' => $coin_num, + 'diamond_nums' => $diamond_num, + 'all_item_list' => $all_item_list, + 'status' => $status, + 'id' => $id, + )); + } + + public function getActExtraReward() + { + $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; + } + + $user_db = $this->readFesActDB($account_id); + if (empty($user_db) || $user_db['isopen'] == 0) { + phpcommon\sendError(ERR_USER_BASE + 3, '活动未开启'); + return; + } + $reward = array(); + $id = $_REQUEST['id']; + $status = 0; + $times = 0; + foreach ($user_db['info_list'] as &$us) { + if ($us['id'] == $id) { + if ($us['status'] != 0) { + phpcommon\sendError(ERR_USER_BASE + 4, '奖励不可领'); + return; + } + if ($us['times'] + 1 >= $us['condition']) { + $status = 1; + $us['status'] = 1; + } + $times = $us['times'] + 1; + $us['times']++; + $reward = metatable\getRewardInfo($user_db['act_id'], $id, 1); + break; + } + } + //更新奖励状态 + $this->saveFesActDB($account_id, $user_db); + // if (empty($reward) || !$reward) { + // phpcommon\sendError(ERR_USER_BASE + 5, '没有这个奖励'); + // return; + // } + $item_list = array(); + $all_item_list = array(); + $addreward = new classes\AddReward(); + if ($reward && !empty($reward)) { + //领取奖励 + for ($i = 0; $i < count($reward); $i++) { + $item_id = $reward[$i][0]; + $num = $reward[$i][1]; + $time = $reward[$i][2]; + array_push($item_list, array( + 'item_id' => $item_id, + 'item_num' => $num, + 'time' => $time, + )); + $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'], + )); + } + } + } + $coin_num = $addreward->getCoinNum($account_id); + $diamond_num = $addreward->getDiamondNum($account_id); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'item_list' => $item_list, + 'coin_nums' => $coin_num, + 'diamond_nums' => $diamond_num, + 'all_item_list' => $all_item_list, + 'times' => $times, + 'status' => $status, + 'id' => $id, + )); + } +} +?> diff --git a/webapp/metatable/activity.php b/webapp/metatable/activity.php new file mode 100644 index 0000000..6467413 --- /dev/null +++ b/webapp/metatable/activity.php @@ -0,0 +1,106 @@ += strtotime($act['time1']) && time() <= strtotime($act['time2'])) { + return $act; + } + } + return null; +} + +function getActInfo($act_conf) +{ + $info_list = array(); + $conditions = getExplode($act_conf['condition']); + for ($i = 0; $i < count($conditions); $i++) { + array_push($info_list,array( + 'id' => $i, + 'status' => 0, + 'times' => 0, + 'type' => $conditions[$i][0], + 'condition' => $conditions[$i][1], + )); + } + return $info_list; +} + +function getRewardInfo($act_id, $id, $type) +{ + $act_conf = getActivityById($act_id); + if (!$act_conf) { + return null; + } + $items = explode('|', $act_conf['reward']); + if ($type == 1) { + if (empty($act_conf['extra_reward'])) { + return null; + } + $items = explode('|', $act_conf['extra_reward']); + } + $arr = array(); + for ($i = 0; $i < count($items); $i++) { + $mul = explode(';', $items[$i]); + array_push($arr, $mul); + } + $arr2 = array(); + $str = $arr[$id]; + for ($i = 0; $i < count($str); $i++) { + $mul = explode(':', $str[$i]); + array_push($arr2, $mul); + } + return $arr2; +}