This commit is contained in:
wangwei01 2019-04-10 14:21:24 +08:00
parent fcb7c02a54
commit a3756dadda
4 changed files with 125 additions and 6 deletions

View File

@ -100,6 +100,24 @@ CREATE TABLE `supplybox` (
PRIMARY KEY (`idx`),
KEY `accountid` (`accountid`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
--
-- Table structure for table `sign`
--
DROP TABLE IF EXISTS `sign`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `sign` (
`idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id',
`accountid` varchar(60) DEFAULT '' COMMENT '账号id',
`sign_days` int(11) NOT NULL COMMENT '已签天数',
`signable` int(11) NOT NULL COMMENT '是否可签',
`sign_time` varchar(50) NOT NULL DEFAULT '签到时间',
PRIMARY KEY (`idx`),
KEY `accountid` (`accountid`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40101 SET character_set_client = utf8 */;

View File

@ -71,5 +71,10 @@ function getDropConfig($drop_table, $drop_id)
{
return array_key_exists($drop_id, $drop_table) ? $drop_table[$drop_id] : null;
}
function getSignConfig($sign_table, $sign_id)
{
return array_key_exists($sign_id, $sign_table) ? $sign_table[$sign_id] : null;
}
checkMysqlConfig();
checkRedisConfig();

View File

@ -0,0 +1,95 @@
<?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' => 1,
':sign_time' => time()
));
if (!$ret) {
die();
return;
}
$sign_days = 1;
$signable = 1;
//获得奖励
$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 = 1;
$ret = $conn->execScript('UPDATE sign SET sign_days=:sign_days, sign_time=:sign_time ' .
' WHERE accountid=:accountid;',
array(
':sign_days' => $sign_days,
':sign_time' => time()
));
if (!$ret) {
die();
return;
}
//获得奖励
$s = $this->getSign($sign_days + 90000);
$item_id = $s['item_id'];
$num = $s['num'];
} else {
$sign_days = $row['sign_days'];
$signable = 1;
}
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'sign_days' => $sign_days,
'signable' => $signable
));
}
}
?>

View File

@ -67,12 +67,12 @@ class SupplyBoxController{
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$rowCount = $conn->execQueryRowCount('SELECT * FROM supplybox WHERE accountid = :account_id',
$rowCount = $conn->execQueryRowCount('SELECT * FROM supplybox WHERE accountid = :account_id;',
array(
':account_id' => $account_id
));
if ($rowCount != 0) {
$rows = $conn->execQuery('SELECT * FROM supplybox WHERE accountid = :account_id',
$rows = $conn->execQuery('SELECT * FROM supplybox WHERE accountid = :account_id;',
array(
':account_id' => $account_id
));
@ -120,7 +120,7 @@ class SupplyBoxController{
}
$item_list = array();
$row = $conn->execQueryOne('SELECT * FROM supplybox WHERE accountid=:accountid AND box_id=:box_id',
$row = $conn->execQueryOne('SELECT * FROM supplybox WHERE accountid=:accountid AND box_id=:box_id;',
array(
':accountid' => $account_id,
':box_id' => $box_id
@ -206,7 +206,7 @@ class SupplyBoxController{
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个宝箱');
return;
}
$row = $conn->execQueryOne('SELECT * FROM supplybox WHERE accountid=:account_id AND box_id=:box_id',
$row = $conn->execQueryOne('SELECT * FROM supplybox WHERE accountid=:account_id AND box_id=:box_id;',
array(
':account_id' => $account_id,
':box_id' => $box_id
@ -230,7 +230,7 @@ class SupplyBoxController{
return;
}
} else {
if (phpcommon\getdayseconds(time()) - phpcommon\getdayseconds($row['time']) > 0) {
if (phpcommon\getdayseconds(time()) - phpcommon\getdayseconds($row['last_buy_time']) > 0) {
$ret = $conn->execScript('UPDATE supplybox SET buy_times=:buy_times, last_buy_time=:time ' .
' WHERE accountid=:accountid AND box_id=:box_id;',
array(
@ -247,14 +247,15 @@ class SupplyBoxController{
phpcommon\sendError(ERR_USER_BASE + 3, '金币不足');
return;
}
$buy_times = 1;
} else {
if ($coin_num < $s['price'] * pow($s['parameter'], ($row['box_num'] - 1))) {
phpcommon\sendError(ERR_USER_BASE + 3, '金币不足');
return;
}
$buy_times = $row['buy_times'] + 1;
}
$box_num = $row['box_num'] + 1;
$buy_times = $row['buy_times'] + 1;
$ret = $conn->execScript('UPDATE supplybox SET box_num=:box_num, buy_times=:buy_times, last_buy_time=:time ' .
' WHERE accountid=:accountid AND box_id=:box_id;',
array(