This commit is contained in:
aozhiwei 2019-10-23 20:03:29 +08:00
parent ee1748d981
commit 3440887b98
3 changed files with 33 additions and 20 deletions

View File

@ -42,8 +42,9 @@ CREATE TABLE `accounts` (
`accountid` varchar(60) DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', `accountid` varchar(60) DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)',
`channel` int(11) NOT NULL COMMENT 'channel', `channel` int(11) NOT NULL COMMENT 'channel',
`gameid` int(11) NOT NULL COMMENT 'gameid', `gameid` int(11) NOT NULL COMMENT 'gameid',
`openid` varchar(50) NOT NULL COMMENT '平台openid', `openid` varchar(50) NOT NULL COMMENT '平台',
`awardtime` int(11) NOT NULL DEFAULT '0' COMMENT '最后领奖时间', `awardtime` int(11) NOT NULL DEFAULT '0' COMMENT '最后领奖时间',
`activetime` int(11) NOT NULL DEFAULT '0' COMMENT '最后交互时间',
PRIMARY KEY (`idx`), PRIMARY KEY (`idx`),
UNIQUE KEY `accountid` (`accountid`), UNIQUE KEY `accountid` (`accountid`),
UNIQUE KEY `channel_gameid_openid_index` (`channel`,`gameid`,`openid`), UNIQUE KEY `channel_gameid_openid_index` (`channel`,`gameid`,`openid`),

View File

@ -0,0 +1,8 @@
begin;
alter table accounts add `activetime` int(11) NOT NULL DEFAULT '0' COMMENT '最后交互时间';
UPDATE accounts set activetime=unix_timestamp(now()) WHERE 1=1;
insert into version (version) values(2019102301);
commit;

View File

@ -275,7 +275,7 @@ class KefuController {
$last_idx = 0; $last_idx = 0;
$share_conf = require('../config/kefu.share.config.php'); $share_conf = require('../config/kefu.share.config.php');
while (true) { while (true) {
$rows = $conn->execQuery('SELECT idx, accountid, openid, awardtime, gameid ' . $rows = $conn->execQuery('SELECT idx, accountid, openid, awardtime, gameid, activetime ' .
' FROM accounts WHERE idx > :last_idx LIMIT 0, 1000;', ' FROM accounts WHERE idx > :last_idx LIMIT 0, 1000;',
array( array(
':last_idx' => $last_idx, ':last_idx' => $last_idx,
@ -284,6 +284,7 @@ class KefuController {
break; break;
} }
foreach ($rows as $row) { foreach ($rows as $row) {
if (time() - $row['activetime'] < 3600) {
if (isset($share_conf[$row['gameid']])) { if (isset($share_conf[$row['gameid']])) {
$game_conf = $share_conf[$row['gameid']]; $game_conf = $share_conf[$row['gameid']];
if (!isset($media_conf[$row['gameid']])) { if (!isset($media_conf[$row['gameid']])) {
@ -298,6 +299,7 @@ class KefuController {
)); ));
} }
}
if ($row['idx'] > $last_idx) { if ($row['idx'] > $last_idx) {
$last_idx = $row['idx']; $last_idx = $row['idx'];
} }
@ -328,7 +330,7 @@ class KefuController {
return; return;
} }
$conn = $this->getMysql($accountid); $conn = $this->getMysql($accountid);
$row = $conn->execQueryOne('SELECT awardtime ' . $row = $conn->execQueryOne('SELECT awardtime, activetime ' .
' FROM accounts WHERE accountid = :accountid;', ' FROM accounts WHERE accountid = :accountid;',
array( array(
':accountid' => $accountid, ':accountid' => $accountid,
@ -352,11 +354,12 @@ class KefuController {
} }
if ($this->sendAwardMail($accountid, $awardConfig)) { if ($this->sendAwardMail($accountid, $awardConfig)) {
$ret = $conn->execScript('UPDATE accounts SET ' . $ret = $conn->execScript('UPDATE accounts SET ' .
' awardtime=:awardtime ' . ' awardtime=:awardtime, activetime=:activetime ' .
' WHERE accountid=:accountid; ', ' WHERE accountid=:accountid; ',
array( array(
':accountid' => $accountid, ':accountid' => $accountid,
':awardtime' => time() ':awardtime' => time(),
':activetime' => time()
)); ));
if ($ret) { if ($ret) {
$this->sendKefuMsg($accountid, array ( $this->sendKefuMsg($accountid, array (
@ -372,8 +375,8 @@ class KefuController {
{ {
if ($msg['Event'] == 'user_enter_tempsession') { if ($msg['Event'] == 'user_enter_tempsession') {
$conn = $this->getMysql($accountid); $conn = $this->getMysql($accountid);
$ret = $conn->execScript('INSERT INTO accounts(accountid, channel, gameid, openid, awardtime) ' . $ret = $conn->execScript('INSERT INTO accounts(accountid, channel, gameid, openid, awardtime, activetime) ' .
'SELECT :accountid, :channel, :gameid, :openid, :awardtime ' . 'SELECT :accountid, :channel, :gameid, :openid, :awardtime, :activetime ' .
'FROM DUAL ' . 'FROM DUAL ' .
'WHERE NOT EXISTS(SELECT accountid FROM accounts WHERE accountid=:accountid);', 'WHERE NOT EXISTS(SELECT accountid FROM accounts WHERE accountid=:accountid);',
array( array(
@ -381,7 +384,8 @@ class KefuController {
':channel' => WEIXIN_CHANNEL, ':channel' => WEIXIN_CHANNEL,
':gameid' => phpcommon\extractGameId($accountid), ':gameid' => phpcommon\extractGameId($accountid),
':openid' => $msg['FromUserName'], ':openid' => $msg['FromUserName'],
':awardtime' => 0 ':awardtime' => 0,
':activetime' => 0
)); ));
if ($ret) { if ($ret) {
$this->sendKefuMsg($accountid, array( $this->sendKefuMsg($accountid, array(