重构完成
This commit is contained in:
parent
a75e10e4af
commit
3cc69dfe1f
@ -28,53 +28,6 @@ class KefuController {
|
||||
return $conn;
|
||||
}
|
||||
|
||||
private function getAppointMysql($mysql_conf)
|
||||
{
|
||||
$conn = new phpcommon\Mysql(array(
|
||||
'host' => $mysql_conf['host'],
|
||||
'port' => $mysql_conf['port'],
|
||||
'user' => $mysql_conf['user'],
|
||||
'passwd' => $mysql_conf['passwd'],
|
||||
'dbname' => 'kefudb'
|
||||
));
|
||||
return $conn;
|
||||
}
|
||||
|
||||
private function getAllMysql()
|
||||
{
|
||||
return require('../config/kefu.mysql.cluster.php');
|
||||
}
|
||||
|
||||
private function getAwardDBMaxIdx($conn)
|
||||
{
|
||||
$select_tbl_name = 'accounts_kefu';
|
||||
$row = $conn->execQueryOne('SELECT idx ' .
|
||||
"FROM $select_tbl_name GROUP BY idx DESC LIMIT 1;"
|
||||
);
|
||||
if ($row) {
|
||||
return $row['idx'];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
private function getAccountsKefuInfo($min_idx, $max_idx, $conn)
|
||||
{
|
||||
$select_tbl_name = 'accounts_kefu';
|
||||
$row = $conn->execQuery("SELECT * FROM $select_tbl_name " .
|
||||
"WHERE idx >= :min_idx AND idx < :max_idx;",
|
||||
array(
|
||||
':min_idx' => $min_idx,
|
||||
':max_idx' => $max_idx
|
||||
));
|
||||
#error_log('getAccountsKefuInfo:' . json_encode($row));
|
||||
if ($row) {
|
||||
return $row;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
private function getAwardConfig($gameid, $condition)
|
||||
{
|
||||
$url = '';
|
||||
@ -161,8 +114,13 @@ class KefuController {
|
||||
if ($errcode == 0) {
|
||||
$msg = json_decode($msg_str, true);
|
||||
$accountid = phpcommon\createAccountId(WEIXIN_CHANNEL, $_REQUEST['gameid'], $msg['FromUserName']);
|
||||
|
||||
switch ($msg['MsgType']) {
|
||||
case 'event':
|
||||
{
|
||||
// 进入客服动作
|
||||
$this->processEvent($msg, $accountid);
|
||||
break;
|
||||
}
|
||||
case 'text':
|
||||
{
|
||||
// 文本消息
|
||||
@ -172,13 +130,7 @@ class KefuController {
|
||||
case 'image':
|
||||
{
|
||||
// 图文消息
|
||||
$this->processImage($msg, $accountid);
|
||||
break;
|
||||
}
|
||||
case 'event':
|
||||
{
|
||||
// 进入客服动作
|
||||
$this->processEvent($msg, $accountid);
|
||||
die('not implement');
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -187,10 +139,8 @@ class KefuController {
|
||||
}
|
||||
}
|
||||
|
||||
public function sendKefuMsgAllUser()
|
||||
public function notifyAllUser()
|
||||
{
|
||||
error_log('sendKefuMsgAllUser:');
|
||||
error_log('request:' . json_encode($_REQUEST));
|
||||
if (phpcommon\md5Sign(array
|
||||
(
|
||||
'exclude_accountids' => $_REQUEST['key']
|
||||
@ -204,12 +154,16 @@ class KefuController {
|
||||
));
|
||||
return;
|
||||
}
|
||||
$mysqls = $this->getAllMysql();
|
||||
foreach($mysqls as $mysql_conf) {
|
||||
$conn = $this->getAppointMysql($mysql_conf);
|
||||
$minIdx = 10000;
|
||||
$maxIdx = $this->getAwardDBMaxIdx($conn);
|
||||
$this->sendOneDBInfo($minIdx, $maxIdx, $conn);
|
||||
$dbconfs = require('../config/kefu.mysql.cluster.php');;
|
||||
foreach($dbconfs as $dbconf) {
|
||||
$conn = new phpcommon\Mysql(array(
|
||||
'host' => $dbconf['host'],
|
||||
'port' => $dbconf['port'],
|
||||
'user' => $dbconf['user'],
|
||||
'passwd' => $dbconf['passwd'],
|
||||
'dbname' => 'kefudb'
|
||||
));
|
||||
$this->sendOneDBInfo($conn);
|
||||
}
|
||||
}
|
||||
|
||||
@ -264,35 +218,31 @@ class KefuController {
|
||||
return !empty($ret_info) && $ret_info['errcode'] == 0;
|
||||
}
|
||||
|
||||
private function sendKefuMsgSomeUser($arrayInfo)
|
||||
private function sendOneDBInfo($conn)
|
||||
{
|
||||
foreach($arrayInfo as $userInfo) {
|
||||
$shareInfo = require('../config/kefu.share.config.php');
|
||||
$miniprogrampateInfo = $shareInfo['1011'];
|
||||
$data = array (
|
||||
"touser" => $userInfo['openid'],
|
||||
"msgtype" => "miniprogrampage",
|
||||
"miniprogrampage" => $miniprogrampateInfo
|
||||
);
|
||||
$this->sendKefuMsg($userInfo['accountid'], $data);
|
||||
}
|
||||
}
|
||||
$last_idx = 0;
|
||||
while (true) {
|
||||
$rows = $conn->execQuery('SELECT idx, accountid, openid, awardtime ' .
|
||||
"FROM accounts_kefu WHERE idx > :last_idx LIMIT 0, 1000;",
|
||||
array(
|
||||
':last_idx' => $last_idx,
|
||||
));
|
||||
if (!$rows || count($rows) <= 0) {
|
||||
break;
|
||||
}
|
||||
foreach ($rows as $row) {
|
||||
$shareInfo = require('../config/kefu.share.config.php');
|
||||
$this->sendKefuMsg($userInfo['accountid'],
|
||||
array (
|
||||
"touser" => $row['openid'],
|
||||
"msgtype" => "miniprogrampage",
|
||||
"miniprogrampage" =>$shareInfo['1011']
|
||||
));
|
||||
|
||||
private function sendOneDBInfo($minIdx, $maxIdx, $conn)
|
||||
{
|
||||
$selectOneCount = 20;
|
||||
$selectCount = $maxIdx - $minIdx;
|
||||
$selectTimes = ceil($selectCount / $selectOneCount);
|
||||
|
||||
#error_log('selectCount:' . $selectCount);
|
||||
#error_log('selectTimes:' . $selectTimes);
|
||||
|
||||
$selectMin = $minIdx;
|
||||
for ($i = 0; $i < $selectTimes; $i++ ) {
|
||||
#error_log('selectMin:' . $selectMin);
|
||||
$arrayInfo = $this->getAccountsKefuInfo($selectMin, $selectMin + $selectOneCount, $conn);
|
||||
$this->sendKefuMsgSomeUser($arrayInfo);
|
||||
$selectMin = $selectMin + $selectOneCount;
|
||||
if ($row['idx'] > $last_idx) {
|
||||
$last_idx = $row['idx'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -344,11 +294,6 @@ class KefuController {
|
||||
}
|
||||
}
|
||||
|
||||
private function processImage($msg, $accountid)
|
||||
{
|
||||
die('not implement');
|
||||
}
|
||||
|
||||
private function processEvent($msg, $accountid)
|
||||
{
|
||||
if ($msg['Event'] == 'user_enter_tempsession') {
|
||||
|
Loading…
x
Reference in New Issue
Block a user