231 lines
5.6 KiB
PHP
231 lines
5.6 KiB
PHP
<?php
|
|
|
|
use phpcommon\SqlHelper;
|
|
|
|
class BaseController {
|
|
|
|
private $nowtime = 0;
|
|
private $marketDbConn = null;
|
|
private $relationDbConn = null;
|
|
private $timeOffset = 0;
|
|
|
|
function __construct()
|
|
{
|
|
global $_myself;
|
|
$_myself = $this;
|
|
$this->timeZone = 0;
|
|
|
|
$this->nowtime = phpcommon\getNowTime();
|
|
}
|
|
|
|
public function _handlePre()
|
|
{
|
|
}
|
|
|
|
public function _handlePost()
|
|
{
|
|
}
|
|
|
|
public function _getNowTime()
|
|
{
|
|
return $this->nowtime + $this->timeOffset;
|
|
}
|
|
|
|
public function _getTimeOffset()
|
|
{
|
|
return $this->timeOffset;
|
|
}
|
|
|
|
public function _setTimeOffset($seconds)
|
|
{
|
|
$this->timeOffset = $seconds;
|
|
}
|
|
|
|
public function _getTodayLeadStr()
|
|
{
|
|
$leadStr = strftime('%y%m%d', $this->_getNowTime());
|
|
return $leadStr;
|
|
}
|
|
|
|
public function _getNowDaySeconds()
|
|
{
|
|
return $this->_getDaySeconds($this->_getNowTime());
|
|
}
|
|
|
|
public function _getDaySeconds($time)
|
|
{
|
|
return phpcommon\getDaySeconds($time, $this->timeZone);
|
|
}
|
|
|
|
public function _getTodayRemainSeconds()
|
|
{
|
|
return max(0, $this->_getNowDaySeconds() + 3600 * 24 - $this->_getNowTime());
|
|
}
|
|
|
|
public function _getMondaySeconds()
|
|
{
|
|
return phpcommon\getMondaySeconds($this->_getNowTime(), $this->timeZone);
|
|
}
|
|
|
|
public function _getMondaySecondsByTime($time)
|
|
{
|
|
return phpcommon\getMondaySeconds($time, $this->timeZone);
|
|
}
|
|
|
|
public function _getZid()
|
|
{
|
|
$net = getReqVal('_net', '');
|
|
$values = explode('-', $net);
|
|
$zid = $values[1];
|
|
return substr($zid, 1);
|
|
}
|
|
|
|
public function _rspErr($errcode, $errmsg)
|
|
{
|
|
if (SERVER_ENV != _ONLINE) {
|
|
error_log(json_encode(array(
|
|
'errcode' => $errcode,
|
|
'errmsg' => $errmsg,
|
|
)));
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => $errcode,
|
|
'errmsg' => $errmsg,
|
|
));
|
|
}
|
|
|
|
public function _rspOk()
|
|
{
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
));
|
|
}
|
|
|
|
public function _rspData($data)
|
|
{
|
|
$rawData = array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
);
|
|
foreach ($data as $key => $val) {
|
|
$rawData[$key] = $val;
|
|
}
|
|
echo json_encode($rawData);
|
|
}
|
|
|
|
public function _rspRawData($data)
|
|
{
|
|
echo json_encode($data);
|
|
}
|
|
|
|
public function _getMysql($data)
|
|
{
|
|
$mysql_conf = getMysqlConfig(crc32($data));
|
|
$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;
|
|
}
|
|
|
|
public function _getMarketMysql()
|
|
{
|
|
if ($this->marketDbConn) {
|
|
return $this->marketDbConn;
|
|
}
|
|
$mysql_conf = getMarketMysqlConfig(crc32(''));
|
|
$this->marketDbConn = new phpcommon\Mysql(array(
|
|
'host' => $mysql_conf['host'],
|
|
'port' => $mysql_conf['port'],
|
|
'user' => $mysql_conf['user'],
|
|
'passwd' => $mysql_conf['passwd'],
|
|
'dbname' => getXVal($mysql_conf, 'dbname', 'marketdb2006')
|
|
));
|
|
return $this->marketDbConn;
|
|
}
|
|
|
|
public function _getRelationDbMysql()
|
|
{
|
|
if ($this->relationDbConn) {
|
|
return $this->relationDbConn;
|
|
}
|
|
$mysql_conf = getRelationMysqlConfig(crc32(''));
|
|
$this->relationDbConn = new phpcommon\Mysql(array(
|
|
'host' => $mysql_conf['host'],
|
|
'port' => $mysql_conf['port'],
|
|
'user' => $mysql_conf['user'],
|
|
'passwd' => $mysql_conf['passwd'],
|
|
'dbname' => getXVal($mysql_conf, 'dbname', 'relationdb1')
|
|
));
|
|
return $this->relationDbConn;
|
|
}
|
|
|
|
|
|
public function _getRedis($data)
|
|
{
|
|
$redis_conf = getRedisConfig(crc32($data));
|
|
$r = new phpcommon\Redis(array(
|
|
'host' => $redis_conf['host'],
|
|
'port' => $redis_conf['port'],
|
|
'passwd' => $redis_conf['passwd']
|
|
|
|
));
|
|
return $r;
|
|
}
|
|
|
|
public function _redisSetAndExpire($pk, $key, $val, $time)
|
|
{
|
|
$r = $this->_getRedis($pk);
|
|
$r->set($key, $val);
|
|
$r->pexpire($key, $time);
|
|
}
|
|
|
|
public function _redisGetJson($pk, $key)
|
|
{
|
|
$r = $this->_getRedis($pk);
|
|
$dataStr = $r->get($key);
|
|
$result = null;
|
|
if (!empty($dataStr)) {
|
|
$result = json_decode($dataStr, true);
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
public function _addLogEx($accountId, $type, $subtype, $params)
|
|
{
|
|
$fieldsKv = array(
|
|
'account_id' => $accountId,
|
|
'type' => $type,
|
|
'subtype' => $subtype,
|
|
'param1' => getXVal($params, 'param1', ''),
|
|
'param2' => getXVal($params, 'param2', ''),
|
|
'param3' => getXVal($params, 'param3', ''),
|
|
'param4' => getXVal($params, 'param4', ''),
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime()
|
|
);
|
|
SqlHelper::insert(
|
|
myself()->_getMysql($accountId),
|
|
't_game_log',
|
|
$fieldsKv
|
|
);
|
|
}
|
|
|
|
public function _getAccountIdByAddress($address)
|
|
{
|
|
$row = SqlHelper::ormSelectOne(
|
|
myself()->_getMysql(''),
|
|
't_user',
|
|
array(
|
|
'address' => $address
|
|
)
|
|
);
|
|
return $row ? $row['account_id'] : null;
|
|
}
|
|
|
|
}
|