diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 3a1a333..55628e6 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -293,8 +293,9 @@ CREATE TABLE `buy_his` ( `itemid` int(11) NOT NULL DEFAULT '0' COMMENT 'itemid', `sum_times` int(11) NOT NULL DEFAULT '0' COMMENT '累计充值次数', `today_times` 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 '修改时间', + `last_buy_time` 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 '修改时间', PRIMARY KEY (`idx`), KEY `accountid` (`accountid`), UNIQUE KEY `accountid_itemid` (`accountid`, `itemid`) @@ -314,8 +315,9 @@ CREATE TABLE `orderinfo` ( `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modify_time` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`), + UNIQUE KEY `orderid` (`orderid`), KEY `accountid` (`accountid`), - UNIQUE KEY `orderid` (`orderid`) + KEY `accountid_itemid` (`accountid`, `itemid`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; DROP TABLE IF EXISTS `vipinfo`; diff --git a/webapp/controller/PayController.class.php b/webapp/controller/PayController.class.php index 8e9d622..769c1a0 100644 --- a/webapp/controller/PayController.class.php +++ b/webapp/controller/PayController.class.php @@ -408,15 +408,74 @@ class PayController{ phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } - $itemid = $_REQUEST['itemid']; $itemnum = $_REQUEST['itemnum']; + $itemnum = 1; + $item_meta_table = require('../res/item@item.php'); + $item_meta = getItemConfig($item_meta_table, $itemid); + if ($item_meta) { + + } + + $params = array( + 'account_id' => $_REQUEST['account_id'], + 'itemid' => $itemid, + 'itemnum' => 1, + 'price' => 0.01 + ); + $timestamp = time(); + $params['sign'] = phpcommon\md5Sign($params, '06ba97e28ea905b0b7ed5477746b07f1', $timestamp); + $params['timestamp'] = $timestamp; + $iv = '1dd2f605f4f8496b'; + $key = 'c868a478c81ff3c168b35d703f787d3c'; + $str_encoded = '2001_' . base64_encode(phpcommon\aesEncrypt(json_encode($params), $iv, $key)); echo json_encode(array( 'errcode' => 0, 'errmsg'=> '', - 'data' => 'hello' + 'data' => $str_encoded )); } + + public function getOrderInfo() + { + if (!loginVerify($_REQUEST['account_id'], + $_REQUEST['session_id'])) { + phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); + return; + } + + $conn = $this->getMysql($_REQUEST['account_id']); + $row = $conn->execQueryOne('SELECT orderid, status FROM orderinfo WHERE orderid=:orderid;', + array( + ':orderid' => $_REQUEST['orderid'] + )); + if (!$row || $row['status'] == 0) { + echo json_encode(array( + 'errcode' => 0, + 'errmsg'=> '', + 'order_state' => 1, + )); + die(); + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg'=> '', + 'order_state' => 0, + 'buy_itemid' => 0, + 'buy_itemnum' => 0, + 'item_list' => array( + array( + 'itemid' => 10001, + 'itemnum' => 1000, + ), + array( + 'itemid' => 10003, + 'itemnum' => 1000, + ), + ) + )); + } + } ?> diff --git a/webapp/controller/ServerSwitchController.class.php b/webapp/controller/ServerSwitchController.class.php new file mode 100644 index 0000000..c0c3dd6 --- /dev/null +++ b/webapp/controller/ServerSwitchController.class.php @@ -0,0 +1,14 @@ + 0, + 'errmsg' => '', + 'payable' => 1 + )); + } + +} diff --git a/webapp/controller/SignController.class.php b/webapp/controller/SignController.class.php new file mode 100644 index 0000000..a4f3ba4 --- /dev/null +++ b/webapp/controller/SignController.class.php @@ -0,0 +1,357 @@ + $mysql_conf['host'], + 'port' => $mysql_conf['port'], + 'user' => $mysql_conf['user'], + 'passwd' => $mysql_conf['passwd'], + 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] + )); + return $conn; + } + + protected function getSign($sign_id) + { + $g_conf_sign_cluster = require('../res/signDaily@signDaily.php'); + $sign_conf = getSignConfig($g_conf_sign_cluster, $sign_id); + $s = array( + 'sign_id' => $sign_conf['sign_id'], + 'condition' => $sign_conf['condition'], + 'item_id' => $sign_conf['item_id'], + 'num' => $sign_conf['num'], + ); + return $s; + } + + 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 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 insertSign($account_id, $sign_days) + { + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + die(); + } + $ret = $conn->execScript('INSERT INTO sign(accountid, sign_id, signable, sign_time, create_time, modify_time) ' . + ' VALUES(:accountid, :sign_id, 0, :sign_time, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:accountid, sign_id=:sign_id, signable=0, sign_time=:sign_time, modify_time=:modify_time;', + array( + ':accountid' => $account_id, + ':sign_id' => $sign_days, + ':sign_time' => time(), + ':create_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + } + } + + public function signInfo() + { + $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); + $last_sign_id = 0; + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + + $rows = $conn->execQuery('SELECT sign_id, sign_time FROM sign WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + $nowTime = phpcommon\getdayseconds(time()); + if (!$rows) { + $last_sign_id = 1; + //插入签到列表 + $this->insertSign($account_id, $last_sign_id); + //更新签到总天数 + $this->updateSignSum($account_id, $last_sign_id); + //完成签到任务 + $quest = new classes\Quest(); + $quest->triggerQuest(QUEST_DAY_LOGIN, 1, 1, $account_id); + $quest->triggerQuest(QUEST_SUM_LOGIN, 2, 1, $account_id); + } else { + $last_sign_time = 0; + foreach ($rows as $row) { + if ($row['sign_id'] > $last_sign_id) { + $last_sign_time = $row['sign_time']; + $last_sign_id = $row['sign_id']; + } + } + if ($nowTime - phpcommon\getdayseconds($last_sign_time) > 0) { + //每日刷新 + $this->updateDaily($account_id); + $passed_days = floor(($nowTime - phpcommon\getdayseconds($last_sign_time)) / (3600 * 24)); + if ($passed_days > 7 - $last_sign_id) { + //跨周时删除老数据 + $ret = $conn->execScript('DELETE from sign WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + )); + if (!$ret) { + die(); + return; + } + $num = ($passed_days - 7 + $last_sign_id) % 7; + for ($i = $last_sign_id + 1; $i < $num + $last_sign_id + 1; $i++) { + //插入补签列表 + $this->insertSign($account_id, $i); + } + } else { + for ($i = $last_sign_id + 1; $i < $passed_days + $last_sign_id + 1; $i++) { + //插入补签列表 + $this->insertSign($account_id, $i); + } + } + //更新签到总天数 + $this->updateSignSum($account_id, $passed_days); + //完成签到任务 + $quest = new classes\Quest(); + $quest->triggerQuest(QUEST_DAY_LOGIN, 1, 1, $account_id); + $quest->triggerQuest(QUEST_SUM_LOGIN, 2, 1, $account_id); + } + } + $sign_list = array(); + $rows = $conn->execQuery('SELECT sign_id, signable FROM sign WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + foreach ($rows as $row) { + array_push($sign_list, array( + 'sign_id' => $row['sign_id'], + 'signable' => $row['signable'] + )); + } + $rowUser = $conn->execQueryOne('SELECT sign_sum FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'sign_days' => $rowUser['sign_sum'], + 'sign_list' => $sign_list + )); + } + + public function signReward() + { + $account_id = $_REQUEST['account_id']; + $double = $_REQUEST['double']; + //登录校验 + $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; + } + $row = $conn->execQueryOne('SELECT signable FROM sign WHERE accountid=:accountid AND sign_id=:sign_id;', + array( + ':accountid' => $account_id, + ':sign_id' => $_REQUEST['sign_id'], + )); + if (!$row || $row['signable'] == 1) { + phpcommon\sendError(ERR_USER_BASE + 2, '已签到'); + return; + } + $ret = $conn->execScript('UPDATE sign SET sign_time=:sign_time, signable=1, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND sign_id=:sign_id;', + array( + ':accountid' => $account_id, + ':sign_id' => $_REQUEST['sign_id'], + ':sign_time' => time(), + ':modify_time' => time() + )); + if (!$ret) { + die(); + return; + } + $rowUser = $conn->execQueryOne('SELECT sign_sum FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + //获得奖励 + $g_conf_sign_cluster = require('../res/signDaily@signDaily.php'); + $day = ($rowUser['sign_sum'] / 7 + $_REQUEST['sign_id']) % count($g_conf_sign_cluster); + if ($day == 0) { + $day = count($g_conf_sign_cluster); + } + $s = $this->getSign($day + 90000); + $item_id = $s['item_id']; + $num = $s['num']; + $addreward = new classes\AddReward(); + $addreward->addReward($item_id, $num, $account_id); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + )); + + } + + public function signDoubleReward() + { + $account_id = $_REQUEST['account_id']; + $double = $_REQUEST['double']; + //登录校验 + $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; + } + $rowUser = $conn->execQueryOne('SELECT sign_sum FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + //获得奖励 + $g_conf_sign_cluster = require('../res/signDaily@signDaily.php'); + $day = ($rowUser['sign_sum'] / 7 + $_REQUEST['sign_id']) % count($g_conf_sign_cluster); + if ($day == 0) { + $day = count($g_conf_sign_cluster); + } + $s = $this->getSign($day + 90000); + $item_id = $s['item_id']; + $num = $s['num']; + $p = $this->getParameter(REWARD_TIMES); + $times = $p['param_value'] - 1; + $num = $num * $times; + $addreward = new classes\AddReward(); + $addreward->addReward($item_id, $num, $account_id); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + )); + } + + + protected function updateSignSum($account_id, $sign_num) + { + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + die(); + } + $row = $conn->execQueryOne('SELECT sign_sum FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + $ret = $conn->execScript('UPDATE user SET sign_sum=:sign_sum, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':sign_sum' => $row['sign_sum'] + $sign_num, + ':modify_time' => time() + )); + if (!$ret) { + die(); + } + } + + protected function updateDaily($account_id) + { + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + die(); + } + //刷新每日任务和活动任务 + $rowCount = $conn->execQueryRowCount('SELECT * FROM quest WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + )); + if ($rowCount != 0) { + for ($i = 0; $i < $rowCount; $i++) { + $ret = $conn->execScript('UPDATE quest SET quest_state=:quest_state, quest_num=:quest_num, modify_time=:modify_time ' . + ' WHERE accountid=:accountid AND quest_type=:quest_type1;', + array( + ':accountid' => $account_id, + ':quest_num' => 0, + ':quest_type1' => 1, + ':quest_state' => 0, + ':modify_time' => time() + )); + } + if (!$ret) { + die(); + } + } + //刷新战斗结算奖励次数,商店刷新次数,客服 + $battle_ret = $conn->execScript('UPDATE user SET battle_re_times=0, shop_flush_times=0, kefu_status=0, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':modify_time' => time() + )); + if (!$battle_ret) { + die(); + } + //刷新抽奖活动奖励 + $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(); + } + //刷新邀请好友奖励 + $share_ret = $conn->execScript('UPDATE share_achievement SET status=0, modify_time=:modify_time ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':modify_time' => time() + )); + if (!$share_ret) { + die(); + } + } +} +?>