This commit is contained in:
yangduo 2025-02-07 11:03:20 +08:00
parent a494eb1851
commit 76526f4e56
2 changed files with 383 additions and 0 deletions

View File

@ -388,4 +388,46 @@ CREATE TABLE `buy_his` (
PRIMARY KEY (`idx`),
UNIQUE KEY `accountid_goodsid` (`accountid`, `goodsid`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE TABLE `t_mail` (
`idx` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增id',
`mail_id` bigint(20) NOT NULL COMMENT '邮件id',
`mail_type` int(11) NOT NULL DEFAULT '0' COMMENT '邮件类型',
`unikey` varchar(255) CHARACTER SET utf8 DEFAULT NULL COMMENT 'unikey',
`subject` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '' COMMENT 'subject',
`content` text COLLATE utf8_bin NOT NULL COMMENT '消息内容',
`recipients` text COLLATE utf8_bin NOT NULL COMMENT '收件人列表',
`attachments` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '' COMMENT '附件',
`deleted` int(11) NOT NULL DEFAULT '0' COMMENT '是否已删除',
`sendtime` int(11) NOT NULL DEFAULT '0' COMMENT '发送时间',
`user_reg_start_time` int(11) NOT NULL DEFAULT '0' COMMENT '用户注册开始时间',
`user_reg_end_time` int(11) NOT NULL DEFAULT '0' COMMENT '用户注册结束时间',
`tag1` int(11) NOT NULL DEFAULT '0' COMMENT 'tag1',
`tag2` int(11) NOT NULL DEFAULT '0' COMMENT 'tag2',
`expiretime` int(11) NOT NULL DEFAULT '0' COMMENT '过期时间',
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
`create_address` varchar(60) CHARACTER SET utf8 DEFAULT NULL COMMENT '创建邮件的钱包地址',
`update_address` varchar(60) CHARACTER SET utf8 DEFAULT NULL COMMENT '更新邮件的钱包地址',
PRIMARY KEY (`idx`),
UNIQUE KEY `mail_id` (`mail_id`),
UNIQUE KEY `unikey` (`unikey`),
KEY `idx_create_address` (`create_address`),
KEY `idx_tag1` (`tag1`),
KEY `idx_tag2` (`tag2`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE TABLE `t_inbox` (
`idx` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增id',
`account_id` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT '账号id',
`mail_id` bigint(20) NOT NULL COMMENT '邮件id',
`state` int(11) NOT NULL DEFAULT '0' COMMENT '1:已读取 2:已领取 3:已删除',
`expiretime` int(11) NOT NULL DEFAULT '0' COMMENT '过期时间',
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),
UNIQUE KEY `idx_account_id_mail_id` (`account_id`,`mail_id`),
KEY `idx_state` (`state`),
KEY `idx_expiretime` (`expiretime`)
) ENGINE=InnoDB AUTO_INCREMENT=10123 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
-- Dump completed on 2015-08-19 18:51:22

View File

@ -0,0 +1,341 @@
<?php
require 'classes/Quest.php';
require 'classes/AddReward.php';
require 'classes/Privilege.php';
require 'classes/RechargeActivity.php';
require_once 'metatable/shopGoods.php';
require_once 'metatable/privilegecard.php';
require_once 'metatable/rechargeActivity.php';
require_once 'metatable/item.php';
class MailController
{
protected function getRedis($key)
{
$redis_conf = getRedisConfig(crc32($key));
$r = new phpcommon\Redis(array(
'host' => $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 getMailMysql()
{
$mysql_conf = getMysqlConfig(1);
$conn = new phpcommon\Mysql(array(
'host' => $mysql_conf['host'],
'port' => $mysql_conf['port'],
'user' => $mysql_conf['user'],
'passwd' => $mysql_conf['passwd'],
'dbname' => MAILDBNAME
));
return $conn;
}
public function list()
{
$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;
}
$mailconn = $this->getMailMysql();
if (!$mailconn) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家1');
return;
}
$userrow = $conn->execQueryOne(
'SELECT create_time FROM user WHERE accountid=:accountid;',
array(
':accountid' => $account_id
)
);
if (!$userrow) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$usercreate = $userrow['create_time'];
$nowtime = time();
$mailrows = $mailconn->execQuery(
' SELECT mail_id, subject, content, attachments FROM t_mail WHERE 1=1 AND deleted=0 ' .
' AND (user_reg_start_time=0 OR user_reg_end_time=0 OR (user_reg_start_time<:createtime AND user_reg_end_time>:createtime) ' .
' AND expiretime>:nowtime ' .
' AND recipients="" OR recipients LIKE "%:accountid%";',
array(
':createtime' => $usercreate,
':nowtime' => $nowtime,
':accountid' => $account_id
)
);
$usermails = array();
$newmails = array();
if ($mailrows) {
$usermailrows = $conn->execQuery(
'SELECT * FROM t_inbox WHERE account_id=:accountid AND expiretime>:nowtime AND createtime>:nowtime-86400*30 ORDER BY idx DESC LIMIT 30;',
array(
':accountid' => $account_id,
':nowtime' => $nowtime,
)
);
if ($usermailrows) {
foreach ($mailrows as $mailitem) {
$mailstatus = 0;
$found = false;
foreach ($usermailrows as $usermailitem) {
if ($mailitem['mail_id'] != $usermailitem['mail_id']) {
continue;
}
$found = true;
if ($usermailitem['state'] > 2) { //user deleted
continue;
}
$mailstatus = $usermailitem['state'];
}
$tmpmail = array(
'id' => $mailitem['mail_id'],
'status' => $mailstatus,
'title' => $mailitem['subject'],
'from' => 'system',
'content' => $mailitem['content'],
'attachment' => json_decode($mailitem['attachments'])
);
array_push($usermails, $tmpmail);
if (!$found) {
array_push($newmails, array(
'mail_id' => $mailitem['mail_id'],
'expiretime' => $mailitem['expiretime']
));
}
}
}
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'mails' => $usermails,
));
foreach ($newmails as $newitem) {
$ret = $conn->execScript(
'INSERT INTO t_inbox(accoun_id, mail_id, state, expiretime, createtime, modifytime) ' .
' VALUES(:account_id, :mailid, 0, :status, :expiretime, :create_time, :modify_time) ' .
' ON DUPLICATE KEY UPDATE account_id=:account_id, mail_id=:mailid, state=:status, expiretime=:expiretime, modifytime=:modify_time;',
array(
':account_id' => $account_id,
':mailid' => $newitem['mail_id'],
':expiretime' => $newitem['expiretime'],
':status' => 0,
':create_time' => $nowtime,
':modify_time' => $nowtime
)
);
if (!$ret) {
error_log("insert new mail error:" . $account_id . "," . $newitem['mail_id']);
}
}
}
public function action()
{
$account_id = $_REQUEST['account_id'];
$act = $_REQUEST['type'];
if ($act < 1 || $act > 3) {
phpcommon\sendError(ERR_USER_BASE + 1, 'type无效');
return;
}
//登录校验
$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;
}
$mailconn = $this->getMailMysql();
if (!$mailconn) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家1');
return;
}
$userrow = $conn->execQueryOne(
'SELECT create_time FROM user WHERE accountid=:accountid;',
array(
':accountid' => $account_id
)
);
if (!$userrow) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$usercreate = $userrow['create_time'];
$nowtime = time();
$mailid = $_REQUEST['mailid'];
$querystr = 'SELECT mail_id, subject, content, attachments FROM t_mail WHERE 1=1 AND deleted=0 ' .
' AND (user_reg_start_time=0 OR user_reg_end_time=0 OR (user_reg_start_time<:createtime AND user_reg_end_time>:createtime) ' .
' AND expiretime>:nowtime ' .
' AND recipients="" OR recipients LIKE "%:accountid%"';
$params = array(
':createtime' => $usercreate,
':nowtime' => $nowtime,
':accountid' => $account_id
);
if ($mailid > 0) {
$querystr = $querystr . ' AND mail_id=:mailid';
$params[':mailid'] = $mailid;
}
$mailrows = $mailconn->execQuery(
$querystr . ';',
$params
);
if ($mailrows) {
$querystr = 'SELECT * FROM t_inbox WHERE account_id=:accountid AND state<:state AND expiretime>:nowtime AND createtime>:nowtime-86400*30 ';
$params = array(
':accountid' => $account_id,
':nowtime' => $nowtime,
':state' => $act
);
if ($mailid > 0) {
$querystr = $querystr . ' AND mail_id=:mailid';
$params[':mailid'] = $mailid;
}
$usermailrows = $conn->execQuery(
$querystr . ' ORDER BY idx DESC LIMIT 30;',
$params
);
if ($usermailrows) {
$mailidlist = '(';
foreach ($mailrows as $mailitem) {
foreach ($usermailrows as $usermailitem) {
if ($mailitem['mail_id'] != $usermailitem['mail_id']) {
continue;
}
$mailidlist = $mailidlist . $mailitem['mail_id'] . ',';
if ($act == 2 && $mailitem['attachments'] != '') { //提取附件
$attachments = json_decode($mailitem['attachments'], true);
$all_attachments = array_merge($all_attachments, $attachments);
}
}
}
$mailidlist = $mailidlist . '0)';
$ret = $conn->execScript(
'UPDATE t_inbox SET state=:state, modifytime=:modify_time ' .
' WHERE accountid=:account_id AND mail_id IN :mailidlist;',
array(
':account_id' => $account_id,
':state' => $act,
':mailidlist' => $mailidlist,
':modify_time' => $nowtime
)
);
if (!$ret) {
error_log('update mail state error:' . $account_id . ',' . $act . ',' . $mailidlist);
phpcommon\sendError(ERR_INTERNAL + 1, '系统繁忙');
return;
}
$item_list = array();
$all_attachments = array();
if ($act == 2) {
foreach ($all_attachments as $attachment_item) {
$itemid = $attachment_item['itemid'];
$itemexists = false;
foreach ($item_list as $key => $item) {
if ($item['item_id'] == $itemid) {
$itemexists = true;
$item_list[$key]['item_num'] += $attachment_item['itemnum'];
break;
}
}
if (!$itemexists) {
$item_list[] = array(
'item_id' => $attachment_item['itemid'],
'item_num' => $attachment_item['itemnum']
);
}
}
}
$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' => '',
'mailid' => $mailid,
'type' => $act,
'coin_nums' => $coin_num,
'diamond_nums' => $diamond_num,
'adfree' => $adfree,
'vip_plustime' => $plustimes,
'item_list' => $item_list,
'all_item_list' => $all_item_list,
));
return;
}
}
phpcommon\sendError(ERR_USER_BASE + 1, '没有邮件');
}
}