重构完成

This commit is contained in:
aozhiwei 2019-01-27 21:47:27 +08:00
parent a75e10e4af
commit 3cc69dfe1f

View File

@ -28,53 +28,6 @@ class KefuController {
return $conn; 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) private function getAwardConfig($gameid, $condition)
{ {
$url = ''; $url = '';
@ -161,8 +114,13 @@ class KefuController {
if ($errcode == 0) { if ($errcode == 0) {
$msg = json_decode($msg_str, true); $msg = json_decode($msg_str, true);
$accountid = phpcommon\createAccountId(WEIXIN_CHANNEL, $_REQUEST['gameid'], $msg['FromUserName']); $accountid = phpcommon\createAccountId(WEIXIN_CHANNEL, $_REQUEST['gameid'], $msg['FromUserName']);
switch ($msg['MsgType']) { switch ($msg['MsgType']) {
case 'event':
{
// 进入客服动作
$this->processEvent($msg, $accountid);
break;
}
case 'text': case 'text':
{ {
// 文本消息 // 文本消息
@ -172,13 +130,7 @@ class KefuController {
case 'image': case 'image':
{ {
// 图文消息 // 图文消息
$this->processImage($msg, $accountid); die('not implement');
break;
}
case 'event':
{
// 进入客服动作
$this->processEvent($msg, $accountid);
break; 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 if (phpcommon\md5Sign(array
( (
'exclude_accountids' => $_REQUEST['key'] 'exclude_accountids' => $_REQUEST['key']
@ -204,12 +154,16 @@ class KefuController {
)); ));
return; return;
} }
$mysqls = $this->getAllMysql(); $dbconfs = require('../config/kefu.mysql.cluster.php');;
foreach($mysqls as $mysql_conf) { foreach($dbconfs as $dbconf) {
$conn = $this->getAppointMysql($mysql_conf); $conn = new phpcommon\Mysql(array(
$minIdx = 10000; 'host' => $dbconf['host'],
$maxIdx = $this->getAwardDBMaxIdx($conn); 'port' => $dbconf['port'],
$this->sendOneDBInfo($minIdx, $maxIdx, $conn); '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; return !empty($ret_info) && $ret_info['errcode'] == 0;
} }
private function sendKefuMsgSomeUser($arrayInfo) private function sendOneDBInfo($conn)
{ {
foreach($arrayInfo as $userInfo) { $last_idx = 0;
$shareInfo = require('../config/kefu.share.config.php'); while (true) {
$miniprogrampateInfo = $shareInfo['1011']; $rows = $conn->execQuery('SELECT idx, accountid, openid, awardtime ' .
$data = array ( "FROM accounts_kefu WHERE idx > :last_idx LIMIT 0, 1000;",
"touser" => $userInfo['openid'], array(
"msgtype" => "miniprogrampage", ':last_idx' => $last_idx,
"miniprogrampage" => $miniprogrampateInfo ));
); if (!$rows || count($rows) <= 0) {
$this->sendKefuMsg($userInfo['accountid'], $data); 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) if ($row['idx'] > $last_idx) {
{ $last_idx = $row['idx'];
$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;
} }
} }
@ -344,11 +294,6 @@ class KefuController {
} }
} }
private function processImage($msg, $accountid)
{
die('not implement');
}
private function processEvent($msg, $accountid) private function processEvent($msg, $accountid)
{ {
if ($msg['Event'] == 'user_enter_tempsession') { if ($msg['Event'] == 'user_enter_tempsession') {