adjust medal cost
This commit is contained in:
parent
3eac8b091b
commit
110ac60883
@ -322,6 +322,75 @@ class SoloController
|
||||
));
|
||||
}
|
||||
|
||||
// consume medals
|
||||
public function consume()
|
||||
{
|
||||
$account_id = $_REQUEST['account_id'];
|
||||
//登录校验
|
||||
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
||||
if (!$login) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
||||
return;
|
||||
}
|
||||
$conn = $this->getMysql($account_id);
|
||||
if (!$conn) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
||||
return;
|
||||
}
|
||||
|
||||
$key = 'game2004api-cost-medals:' . $account_id;
|
||||
$r = $this->getRedis($key);
|
||||
if (!$r) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家 1');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$level = $_REQUEST['level'];
|
||||
$reqlevelcfg = $this->getGameLevelInfo($level);
|
||||
if (!$reqlevelcfg) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, '体力不足');
|
||||
return;
|
||||
}
|
||||
|
||||
$solorow = $conn->execQueryOne(
|
||||
'SELECT medals FROM solo WHERE accountid=:accountid;',
|
||||
array(
|
||||
':accountid' => $account_id
|
||||
)
|
||||
);
|
||||
|
||||
$medalcost = $reqlevelcfg['medal_cost'];
|
||||
if ($medalcost > $solorow['medals']) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, '体力不足 1');
|
||||
return;
|
||||
}
|
||||
|
||||
$ret = $conn->execScript(
|
||||
'UPDATE solo SET medals=:medals, modify_time=:modify_time' .
|
||||
' WHERE accountid=:accountid;',
|
||||
array(
|
||||
':accountid' => $account_id,
|
||||
':medals' => $solorow['medals'] - $medalcost,
|
||||
':modify_time' => time()
|
||||
)
|
||||
);
|
||||
|
||||
if (!$ret) {
|
||||
phpcommon\sendError(ERR_RETRY + 1, '系统繁忙');
|
||||
return;
|
||||
}
|
||||
|
||||
$infoobj = array(
|
||||
'level' => $level,
|
||||
);
|
||||
|
||||
$infostr = json_encode($infoobj);
|
||||
$r->set($key, $infostr);
|
||||
$r->pexpire($key, 1000 * 86400);
|
||||
error_log($key . ':' . $infostr);
|
||||
}
|
||||
|
||||
// 战斗结算
|
||||
public function settle()
|
||||
{
|
||||
@ -344,7 +413,7 @@ class SoloController
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, '奖励不存在');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$infostr = $r->get($key);
|
||||
if (empty($infostr)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, '奖励不存在 1');
|
||||
@ -772,7 +841,28 @@ class SoloController
|
||||
}
|
||||
|
||||
$medalcost = $reqlevelcfg['medal_cost'];
|
||||
if ($medalcost > $solorow['medals']) {
|
||||
if ($isbattle) {
|
||||
$key = 'game2004api-cost-medals:' . $account_id;
|
||||
$r = $this->getRedis($key);
|
||||
if (!$r) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家 1');
|
||||
return;
|
||||
}
|
||||
|
||||
$infostr = $r->get($key);
|
||||
if (empty($infostr)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, '奖励不存在 1');
|
||||
return;
|
||||
}
|
||||
|
||||
$infoobj = json_decode($infostr, true);
|
||||
if ($infoobj['level'] != $level) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, '奖励不存在 2');
|
||||
return;
|
||||
}
|
||||
|
||||
$r->del($key);
|
||||
} else if ($medalcost > $solorow['medals']) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 2, '体力不足');
|
||||
return;
|
||||
}
|
||||
@ -874,7 +964,7 @@ class SoloController
|
||||
}
|
||||
}
|
||||
|
||||
$curmedals = $solorow['medals'] - $medalcost;
|
||||
$curmedals = $isbattle ? $solorow['medals'] : ($solorow['medals'] - $medalcost);
|
||||
$lastredeem = $solorow['lastredeem'];
|
||||
$privilege = new classes\Privilege();
|
||||
$medalsgrowlimit = intval(metatable\getParameterById(MEDAL_LIMIT)['param_value']) + $privilege->getMedalLimitPlus($account_id);
|
||||
|
Loading…
x
Reference in New Issue
Block a user