503 lines
17 KiB
PHP
503 lines
17 KiB
PHP
<?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 listmail()
|
|
{
|
|
$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, expiretime 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="[]" OR recipients LIKE "%'.$account_id.'%");',
|
|
array(
|
|
':createtime' => $usercreate,
|
|
':nowtime' => $nowtime
|
|
)
|
|
);
|
|
|
|
$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,
|
|
)
|
|
);
|
|
|
|
foreach ($mailrows as $mailitem) {
|
|
$mailstatus = 0;
|
|
$found = false;
|
|
if ($usermailrows) {
|
|
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(account_id, mail_id, state, expiretime, createtime, modifytime) ' .
|
|
' VALUES(:account_id, :mailid, 0, :expiretime, :create_time, :modify_time) ' .
|
|
' ON DUPLICATE KEY UPDATE account_id=:account_id, mail_id=:mailid, state=0, expiretime=:expiretime, modifytime=:modify_time;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':mailid' => $newitem['mail_id'],
|
|
':expiretime' => $newitem['expiretime'],
|
|
':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="[]" OR recipients LIKE "%'.$account_id.'%")';
|
|
$params = array(
|
|
':createtime' => $usercreate,
|
|
':nowtime' => $nowtime
|
|
);
|
|
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 = '(';
|
|
$all_attachments = array();
|
|
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 account_id=:account_id AND mail_id IN '.$mailidlist.';',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':state' => $act,
|
|
':modify_time' => $nowtime
|
|
)
|
|
);
|
|
if (!$ret) {
|
|
error_log('update mail state error:' . $account_id . ',' . $act . ',' . $mailidlist);
|
|
phpcommon\sendError(ERR_INTERNAL + 1, '系统繁忙');
|
|
return;
|
|
}
|
|
|
|
$item_list = array();
|
|
if ($act == 2) {
|
|
foreach ($all_attachments as $attachment_item) {
|
|
$itemid = $attachment_item['item_id'];
|
|
$itemexists = false;
|
|
foreach ($item_list as $key => $item) {
|
|
if ($item['item_id'] == $itemid) {
|
|
$itemexists = true;
|
|
$item_list[$key]['item_num'] += $attachment_item['item_num'];
|
|
break;
|
|
}
|
|
}
|
|
if (!$itemexists) {
|
|
$item_list[] = array(
|
|
'item_id' => $attachment_item['item_id'],
|
|
'item_num' => $attachment_item['item_num']
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
$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, '没有邮件');
|
|
}
|
|
|
|
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://adminapi.kingsome.cn/api/v1/giftcode/query';
|
|
} else {
|
|
$url = 'https://adminapi-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 (is_null($rsp) || empty($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://adminapi.kingsome.cn/api/v1/giftcode/use';
|
|
} else {
|
|
$url = 'https://adminapi-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 (is_null($rsp) || empty($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,
|
|
));
|
|
}
|
|
}
|