This commit is contained in:
aozhiwei 2021-11-26 16:11:54 +08:00
parent c14d089255
commit a04ed66629
2 changed files with 43 additions and 120 deletions

View File

@ -45,19 +45,6 @@ class BaseAuthedController extends BaseController {
return $registertime;
}
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 _getSelfMysql()
{
if (!$this->mysqlConn) {
@ -66,18 +53,6 @@ class BaseAuthedController extends BaseController {
return $this->mysqlConn;
}
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 _getUserInfo($fields)
{
$row = SqlHelper::selectOne
@ -269,83 +244,6 @@ class BaseAuthedController extends BaseController {
}
}
public function _deleteItem($item)
{
$tmpItemID = $item["item_id"];
$beDeleteNum = $item['item_num'];
$accountID = $this->_getAccountId();
$conn = $this->_getMysql($accountID);
$sqlStr = "SELECT id,num FROM bag WHERE accountid=:accountid AND id=:itemId";
$row = $conn->execQuery($sqlStr,array(':accountid' => $accountID,':itemId' =>$tmpItemID));
$code = 100;
if($row)
{
$num1 = $row[0]['num'];
if($num1 < $beDeleteNum)
{
$code = 98;//道具不足
}
}
else
{
$code = 99;//道具不存在
}
return $code;
}
public function _decGold($decGold)
{
SqlHelper::update
(
$this->_getSelfMysql(),
'user',
array(
'accountid' => $this->_getAccountId()
),
array(
'coin_num' => function () use($decGold) { return "CASE coin_num WHEN coin_num < {$decGold} THEN 0 ELSE coin_num - {$decGold} END"; }
)
);
// $this->incV(TN_CONSUME_GOLD, 0, $decGold);
// $this->incV(TN_CONSUME_GOLD, $this->_getNowDaySeconds(), $decGold);
}
public function _addGold($addGold)
{
SqlHelper::update
(
$this->_getSelfMysql(),
'user',
array(
'accountid' => $this->_getAccountId()
),
array(
'coin_num' => function () use($addGold) { return "coin_num + {$addGold}"; }
)
);
}
public function _getTalentLv($skillId, $skillTypeId)
{
$row = SqlHelper::selectOne
(
$this->_getSelfMysql(),
'gun_intensify',
array(
'gun_type_id',
'skill_id',
'skill_lv'
),
array(
'accountid' => $this->_getAccountId(),
'skill_id' => $skillId,
'gun_type_id' => $skillTypeId
)
);
return $row ? $row['skill_iv'] : 0;
}
public function _hasEnoughItemsEx($items, &$lackItem)
{
$userInfo = $this->_getUserInfo(array(
@ -367,22 +265,4 @@ class BaseAuthedController extends BaseController {
return true;
}
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;
}
}

View File

@ -64,4 +64,47 @@ class BaseController {
echo json_encode($rawData);
}
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 _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;
}
}