diff --git a/sql/gamedb.sql b/sql/gamedb.sql index a0a0afb..0c00a53 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -430,4 +430,17 @@ CREATE TABLE `t_inbox` ( KEY `idx_state` (`state`), KEY `idx_expiretime` (`expiretime`) ) ENGINE=InnoDB AUTO_INCREMENT=10123 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +CREATE TABLE `code_his` ( + `idx` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增id', + `account_id` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT '账号id', + `code_type` bigint(20) NOT NULL COMMENT 'giftcode type', + `code` varchar(60) CHARACTER SET utf8 NOT NULL DEFAULT '' COMMENT 'code', + `content` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '' COMMENT 'giftcode 内容', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `idx_account_id_code_type` (`account_id`,`code_type`), + KEY `idx_code` (`code`) +) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; -- Dump completed on 2015-08-19 18:51:22 diff --git a/webapp/controller/MailController.class.php b/webapp/controller/MailController.class.php index 6e9c153..c3b0437 100644 --- a/webapp/controller/MailController.class.php +++ b/webapp/controller/MailController.class.php @@ -248,6 +248,7 @@ class MailController if ($usermailrows) { $mailidlist = '('; + $all_attachments = array(); foreach ($mailrows as $mailitem) { foreach ($usermailrows as $usermailitem) { if ($mailitem['mail_id'] != $usermailitem['mail_id']) { @@ -280,7 +281,6 @@ class MailController } $item_list = array(); - $all_attachments = array(); if ($act == 2) { foreach ($all_attachments as $attachment_item) { $itemid = $attachment_item['itemid']; @@ -338,4 +338,169 @@ class MailController phpcommon\sendError(ERR_USER_BASE + 1, '没有邮件'); } + + public function usecode() + { + $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; + } + + $giftcode = $_REQUEST['code']; + + $url = ''; + if (SERVER_ENV == _ONLINE) { + $url = 'https://admin.kingsome.cn/api/v1/giftcode/query'; + } else { + $url = 'https://admin-test.kingsome.cn/api/v1/giftcode/query'; + } + + $params = array( + 'gameid' => 2004, + 'code' => $giftcode, + ); + $rsp = ''; + if (!phpcommon\HttpClient::post($url, json_encode($params), $rsp)) { + phpcommon\sendError(ERR_RETRY, '系统繁忙'); + return; + } + + if ($rsp == null || $rsp == '') { + phpcommon\sendError(ERR_RETRY, '系统繁忙2'); + return; + } + + $response = json_decode($rsp, true); + if ($response['errcode'] != 0) { + phpcommon\sendError($response['errcode'], $response['errmsg']); + return; + } + + if ($response['status'] != 0) { + phpcommon\sendError(ERR_RETRY + 1, '不可用'); + return; + } + + $codetype = $response['type']; + $coderow = $conn->execQueryOne( + 'SELECT * FROM code_his WHERE account_id=:accountid AND code_type=:codetype;', + array( + ':accountid' => $account_id, + ':codetype' => $codetype + ) + ); + + if ($coderow) { + phpcommon\sendError(ERR_USER_BASE + 1, '已用过'); + return; + } + + if (SERVER_ENV == _ONLINE) { + $url = 'https://admin.kingsome.cn/api/v1/giftcode/use'; + } else { + $url = 'https://admin-test.kingsome.cn/api/v1/giftcode/use'; + } + + $params = array( + 'gameid' => 2004, + 'account_id' => $account_id, + 'code' => $giftcode, + ); + + if (!phpcommon\HttpClient::post($url, json_encode($params), $rsp)) { + phpcommon\sendError(ERR_RETRY, '系统繁忙3'); + return; + } + + if ($rsp == null || $rsp == '') { + phpcommon\sendError(ERR_RETRY, '系统繁忙4'); + return; + } + + $response = json_decode($rsp, true); + if ($response['errcode'] != 0) { + phpcommon\sendError($response['errcode'], $response['errmsg']); + return; + } + + if ($response['status'] != 0) { + phpcommon\sendError(ERR_RETRY + 1, '不可用'); + return; + } + + $nowtime = time(); + $ret = $conn->execScript( + 'INSERT INTO code_his(account_id, code_type, code, content, ' . + ' createtime, modifytime)' . + ' VALUES(:accountid, :codetype, :code, :content, ' . + ' :create_time, :modify_time);', + array( + ':accountid' => $account_id, + ':codetype' => $codetype, + ':code' => $giftcode, + ':content' => $response['content'], + ':create_time' => $nowtime, + ':modify_time' => $nowtime + ) + ); + if (!$ret) { + echo json_encode(array( + 'errcode' => 2, + 'errmsg' => '服务器内部错误' + )); + return; + } + + $item_list = array(); + $str_list = explode('|', $response['content']); + foreach($str_list as $stritem) { + $itemstrs = explode(':', $stritem); + if (count($itemstrs) < 2) { + continue; + } + + $item_list[] = array( + 'item_id' => $itemstrs[0], + 'item_num' => $itemstrs[1], + ); + } + + $addreward = new classes\AddReward(); + $all_item_list = array(); + foreach ($item_list as $item) { + $items = $addreward->addReward($item['item_id'], $item['item_num'], $account_id, 0, 0); + foreach ($items as $i) { + array_push($all_item_list, array( + 'item_id' => $i['item_id'], + 'item_num' => $i['item_num'], + 'time' => 0, + )); + } + } + + $coin_num = $addreward->getCoinNum($account_id); + $diamond_num = $addreward->getDiamondNum($account_id); + $adfree = $addreward->getAdfree($account_id); + $privilege = new classes\Privilege(); + $plustimes = $privilege->getCoinTimesPlus($account_id); + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'code' => $giftcode, + 'coin_nums' => $coin_num, + 'diamond_nums' => $diamond_num, + 'adfree' => $adfree, + 'vip_plustime' => $plustimes, + 'item_list' => $item_list, + 'all_item_list' => $all_item_list, + )); + } }