game2001api/webapp/controller/SignController.class.php
wangwei01 dc09bfa3c4 1
2019-04-11 16:58:53 +08:00

108 lines
4.0 KiB
PHP

<?php
class SignController{
protected function getMysql($account_id)
{
$mysql_conf = getMysqlConfig(crc32($account_id));
$conn = new phpcommon\Mysql(array(
'host' => $mysql_conf['host'],
'port' => $mysql_conf['port'],
'user' => $mysql_conf['user'],
'passwd' => $mysql_conf['passwd'],
'dbname' => 'gamedb2001_' . $mysql_conf['instance_id']
));
return $conn;
}
protected function getSign($sign_id)
{
$g_conf_sign_cluster = require('../config/game2001api.sign.cluster.php');
$sign_conf = getSignConfig($g_conf_sign_cluster, $sign_id);
$s = array(
'sign_id' => $sign_conf['sign_id'],
'condition' => $sign_conf['condition'],
'item_id' => $sign_conf['item_id'],
'num' => $sign_conf['num'],
);
return $s;
}
public function signInfo()
{
$account_id = $_REQUEST['account_id'];
$conn = $this->getMysql($account_id);
$sign_days = 0;
$signable = 0;
if (!$conn) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$row = $conn->execQueryOne('SELECT * FROM sign WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
if (!$row) {
$ret = $conn->execScript('INSERT INTO sign(accountid, sign_days, signable, sign_time) ' .
' VALUES(:accountid, :sign_days, :signable, :sign_time);',
array(
':accountid' => $account_id,
':sign_days' => 1,
':signable' => 0,
':sign_time' => time()
));
if (!$ret) {
die();
return;
}
$sign_days = 1;
$signable = 0;
//获得奖励
$s = $this->getSign($sign_days + 90000);
$item_id = $s['item_id'];
$num = $s['num'];
} else {
if (phpcommon\getdayseconds(time()) - phpcommon\getdayseconds($row['sign_time']) > 0) {
$sign_days = $row['sign_days'] + 1;
$signable = 0;
$ret = $conn->execScript('UPDATE sign SET sign_days=:sign_days, sign_time=:sign_time, signable=:signable ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':sign_days' => $sign_days,
':sign_time' => time(),
':signable' => $signable
));
if (!$ret) {
die();
return;
}
//获得奖励
$s = $this->getSign($sign_days % 7 + 90000);
$item_id = $s['item_id'];
$num = $s['num'];
} else {
$sign_days = $row['sign_days'];
$signable = 1;
$ret = $conn->execScript('UPDATE sign SET signable=:signable ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':signable' => $signable
));
if (!$ret) {
die();
return;
}
}
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'sign_days' => $sign_days,
'signable' => $signable
));
}
}
?>