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)',
`channel` int(11) NOT NULL COMMENT 'channel',
`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 '最后领奖时间',
`activetime` int(11) NOT NULL DEFAULT '0' COMMENT '最后交互时间',
PRIMARY KEY (`idx`),
UNIQUE KEY `accountid` (`accountid`),
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;
$share_conf = require('../config/kefu.share.config.php');
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;',
array(
':last_idx' => $last_idx,
@ -284,19 +284,21 @@ class KefuController {
break;
}
foreach ($rows as $row) {
if (isset($share_conf[$row['gameid']])) {
$game_conf = $share_conf[$row['gameid']];
if (!isset($media_conf[$row['gameid']])) {
$media_conf[$row['gameid']] = $this->getMediaId($row['gameid']);
}
$game_conf['thumb_media_id'] = $media_conf[$row['gameid']];
$this->sendKefuMsg($row['accountid'],
array (
"touser" => $row['openid'],
"msgtype" => "miniprogrampage",
"miniprogrampage" => $game_conf
));
if (time() - $row['activetime'] < 3600) {
if (isset($share_conf[$row['gameid']])) {
$game_conf = $share_conf[$row['gameid']];
if (!isset($media_conf[$row['gameid']])) {
$media_conf[$row['gameid']] = $this->getMediaId($row['gameid']);
}
$game_conf['thumb_media_id'] = $media_conf[$row['gameid']];
$this->sendKefuMsg($row['accountid'],
array (
"touser" => $row['openid'],
"msgtype" => "miniprogrampage",
"miniprogrampage" => $game_conf
));
}
}
if ($row['idx'] > $last_idx) {
$last_idx = $row['idx'];
@ -328,7 +330,7 @@ class KefuController {
return;
}
$conn = $this->getMysql($accountid);
$row = $conn->execQueryOne('SELECT awardtime ' .
$row = $conn->execQueryOne('SELECT awardtime, activetime ' .
' FROM accounts WHERE accountid = :accountid;',
array(
':accountid' => $accountid,
@ -352,11 +354,12 @@ class KefuController {
}
if ($this->sendAwardMail($accountid, $awardConfig)) {
$ret = $conn->execScript('UPDATE accounts SET ' .
' awardtime=:awardtime ' .
' awardtime=:awardtime, activetime=:activetime ' .
' WHERE accountid=:accountid; ',
array(
':accountid' => $accountid,
':awardtime' => time()
':awardtime' => time(),
':activetime' => time()
));
if ($ret) {
$this->sendKefuMsg($accountid, array (
@ -372,8 +375,8 @@ class KefuController {
{
if ($msg['Event'] == 'user_enter_tempsession') {
$conn = $this->getMysql($accountid);
$ret = $conn->execScript('INSERT INTO accounts(accountid, channel, gameid, openid, awardtime) ' .
'SELECT :accountid, :channel, :gameid, :openid, :awardtime ' .
$ret = $conn->execScript('INSERT INTO accounts(accountid, channel, gameid, openid, awardtime, activetime) ' .
'SELECT :accountid, :channel, :gameid, :openid, :awardtime, :activetime ' .
'FROM DUAL ' .
'WHERE NOT EXISTS(SELECT accountid FROM accounts WHERE accountid=:accountid);',
array(
@ -381,7 +384,8 @@ class KefuController {
':channel' => WEIXIN_CHANNEL,
':gameid' => phpcommon\extractGameId($accountid),
':openid' => $msg['FromUserName'],
':awardtime' => 0
':awardtime' => 0,
':activetime' => 0
));
if ($ret) {
$this->sendKefuMsg($accountid, array(