1
This commit is contained in:
parent
91951ca51a
commit
88fdadd28c
@ -58,6 +58,8 @@ CREATE TABLE `user` (
|
||||
`create_time` int(11) NOT NULL COMMENT '创建时间',
|
||||
`modify_time` int(11) NOT NULL COMMENT '修改时间',
|
||||
`first_fight` int(11) NOT NULL COMMENT '是否是第一次战斗',
|
||||
`collect_status` int(11) NOT NULL COMMENT '收藏状态',
|
||||
`keys_num` int(11) NOT NULL COMMENT '钥匙数量',
|
||||
PRIMARY KEY (`idx`),
|
||||
UNIQUE KEY `accountid` (`accountid`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||
|
@ -122,5 +122,17 @@ function getRewardTimesConfig($rewardTimes_table, $rewardTimes_id)
|
||||
{
|
||||
return array_key_exists((int)$rewardTimes_id, $rewardTimes_table) ? $rewardTimes_table[(int)$rewardTimes_id] : null;
|
||||
}
|
||||
|
||||
function getShopConfig($shop_table, $shop_id)
|
||||
{
|
||||
$shop_id = (int)$shop_id;
|
||||
return array_key_exists($shop_id, $shop_table) ? $shop_table[$shop_id] : null;
|
||||
}
|
||||
|
||||
function getItemConfig($item_table, $item_id)
|
||||
{
|
||||
$item_id = (int)$item_id;
|
||||
return array_key_exists($item_id, $item_table) ? $item_table[$item_id] : null;
|
||||
}
|
||||
checkMysqlConfig();
|
||||
checkRedisConfig();
|
||||
|
@ -66,6 +66,7 @@ define('DOUBLE_SIGN_IN', 23); //每日签到翻倍率
|
||||
define('DOUBLE_END_WAR', 24); //战斗结束翻倍率
|
||||
define('DOUBLE_BOX', 25); //抽箱子奖励翻倍率
|
||||
define('FREE_DRESS_MAX_TIME', 30); //免费获取皮肤次数上限
|
||||
define('RAND_SHOP_GOLD', 39); //商店金币刷新价格
|
||||
|
||||
require 'config_loader.php';
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
require 'classes/Quest.php';
|
||||
|
||||
require 'classes/AddReward.php';
|
||||
|
||||
class RoleController{
|
||||
|
||||
@ -87,9 +87,9 @@ class RoleController{
|
||||
':accountid' => $account_id
|
||||
));
|
||||
if (!$row) {
|
||||
$ret = $conn->execScript('INSERT INTO user(accountid, user_name, avatar_url, game_times, win_times, kills, harm, add_HP, alive_time, coin_num, integral, kill_his, alive_time_his, harm_his, add_HP_his, act_share_time, act_share_status, create_time, modify_time, first_fight) ' .
|
||||
' VALUES(:accountid, :user_name, :avatar_url, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, create_time, :modify_time, 0) ' .
|
||||
' ON DUPLICATE KEY UPDATE accountid=:accountid, user_name=:user_name, avatar_url=:avatar_url, game_times=0, win_times=0, kills=0, harm=0, add_HP=0, alive_time=0, coin_num=0, integral=0, kill_his=0, alive_time_his=0, harm_his=0, add_HP_his=0, act_share_time=0, act_share_status=0, modify_time=:modify_time, first_fight=0;',
|
||||
$ret = $conn->execScript('INSERT INTO user(accountid, user_name, avatar_url, game_times, win_times, kills, harm, add_HP, alive_time, coin_num, integral, kill_his, alive_time_his, harm_his, add_HP_his, act_share_time, act_share_status, create_time, modify_time, first_fight, collect_status, keys_num) ' .
|
||||
' VALUES(:accountid, :user_name, :avatar_url, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, create_time, :modify_time, 0, 0, 0) ' .
|
||||
' ON DUPLICATE KEY UPDATE accountid=:accountid, user_name=:user_name, avatar_url=:avatar_url, game_times=0, win_times=0, kills=0, harm=0, add_HP=0, alive_time=0, coin_num=0, integral=0, kill_his=0, alive_time_his=0, harm_his=0, add_HP_his=0, act_share_time=0, act_share_status=0, modify_time=:modify_time, first_fight=0, collect_status=0, keys_num=0;',
|
||||
array(
|
||||
':accountid' => $account_id,
|
||||
':user_name' => $user_name,
|
||||
@ -113,7 +113,9 @@ class RoleController{
|
||||
'add_HP' => 0,
|
||||
'alive_time' => 0,
|
||||
'coin_num' => 0,
|
||||
'first_fight' => 0
|
||||
'first_fight' => 0,
|
||||
'collect_status' => 0,
|
||||
'keys_num' => 0
|
||||
));
|
||||
} else {
|
||||
echo json_encode(array(
|
||||
@ -128,7 +130,9 @@ class RoleController{
|
||||
'add_HP' => $row['add_HP'],
|
||||
'alive_time' => $row['alive_time'],
|
||||
'coin_num' => $row['coin_num'],
|
||||
'first_fight' => $row['first_fight']
|
||||
'first_fight' => $row['first_fight'],
|
||||
'collect_status' => $row['collect_status'],
|
||||
'keys_num' => $row['keys_num']
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -272,21 +276,31 @@ class RoleController{
|
||||
}
|
||||
}
|
||||
//触发活动任务
|
||||
$act = $this->getActivityRewardConfig(QUEST_ACTIVITY_LOGIN);
|
||||
/*$act = $this->getActivityRewardConfig(QUEST_ACTIVITY_LOGIN);
|
||||
$array = $this->getExplode($act['start_end_time']);
|
||||
$nowTime = phpcommon\getdayseconds(time());
|
||||
$start_time = $array[0][0] * 3600 + $array[0][1] * 60 + $nowTime;
|
||||
$end_time = $array[1][0] * 3600 + $array[1][1] * 60 + $nowTime;
|
||||
if (time() >= $start_time && time() < $start_time) {
|
||||
$quest->triggerQuest(QUEST_ACTIVITY_GAME, 3, 1, $account_id);
|
||||
}
|
||||
}*/
|
||||
//额外奖励
|
||||
$times = $this->getRewardTimes($coin_num);
|
||||
$extra_coin = $coin_num * ($times - 1);
|
||||
$skin_id = 13002;
|
||||
$skin_num = 6;
|
||||
srand($room_uuid);
|
||||
$randnum = Rand(0,100);
|
||||
error_log($randnum);
|
||||
$extra_drop = '10001:' . $extra_coin . '|10002:1' . '|' . $skin_id . ':' . $skin_num;
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg' => '',
|
||||
'kill_his' => $kill_his,
|
||||
'alive_time_his' => $alive_time_his,
|
||||
'harm_his' => $harm_his,
|
||||
'add_HP_his' => $add_HP_his
|
||||
'add_HP_his' => $add_HP_his,
|
||||
'extra_drop' => $extra_drop
|
||||
));
|
||||
}
|
||||
|
||||
@ -457,7 +471,73 @@ class RoleController{
|
||||
}
|
||||
return $times;
|
||||
}
|
||||
|
||||
protected function collectReward()
|
||||
{
|
||||
$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);
|
||||
$record_list = array();
|
||||
if (!$conn) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
||||
return;
|
||||
}
|
||||
$ret = $conn->execScript('UPDATE user SET collect_status=1, modify_time=:modify_time, ' .
|
||||
' WHERE accountid=:accountid;',
|
||||
array(
|
||||
':modify_time' => time()
|
||||
));
|
||||
if (!$ret) {
|
||||
die();
|
||||
return;
|
||||
}
|
||||
$d = $this->getDrop(24003);
|
||||
if (!$d) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励');
|
||||
return;
|
||||
}
|
||||
$item_id_array = $this->getExplode($d['item_id']);
|
||||
$num_array = $this->getExplode($d['num']);
|
||||
$weight_array = $this->getExplode($d['weight']);
|
||||
$i = 0;
|
||||
$mul = 1;
|
||||
if ($_REQUEST['double'] != 0) {
|
||||
$mul = 2;
|
||||
} else {
|
||||
$mul = 1;
|
||||
}
|
||||
foreach ($weight_array as $item) {
|
||||
if ($item[$i][0] >= Rand(0, 10000)) {
|
||||
$item_id = $item_id_array[$i][0];
|
||||
$item_num = $num_array[$i][0] * $mul;
|
||||
$addreward = new classes\AddReward();
|
||||
$addreward->addReward($item_id, $item_num, $account_id);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg' => '',
|
||||
));
|
||||
}
|
||||
|
||||
protected function getDrop($drop_id)
|
||||
{
|
||||
$g_conf_drop_cluster = require('../res/drop@drop.php');
|
||||
$drop_conf = getDropConfig($g_conf_drop_cluster, $drop_id);
|
||||
$d = array(
|
||||
'drop_id' => $drop_conf['drop_id'],
|
||||
'item_id' => $drop_conf['item_id'],
|
||||
'num' => $drop_conf['num'],
|
||||
'weight' => $drop_conf['weight'],
|
||||
'type' => $drop_conf['type']
|
||||
);
|
||||
return $d;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
334
webapp/controller/ShopController.class.php
Normal file
334
webapp/controller/ShopController.class.php
Normal file
@ -0,0 +1,334 @@
|
||||
<?php
|
||||
|
||||
require 'classes/AddReward.php';
|
||||
|
||||
class ShopController{
|
||||
|
||||
protected function getRedis($shop_uuid)
|
||||
{
|
||||
$redis_conf = getRedisConfig(crc32($shop_uuid));
|
||||
$r = new phpcommon\Redis(array(
|
||||
'host' => $redis_conf['host'],
|
||||
'port' => $redis_conf['port'],
|
||||
'passwd' => $redis_conf['passwd']
|
||||
|
||||
));
|
||||
return $r;
|
||||
}
|
||||
|
||||
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 getItem($item_id)
|
||||
{
|
||||
$g_conf_item_cluster = require('../res/item@item.php');
|
||||
$item_conf = getItemConfig($g_conf_item_cluster, $item_id);
|
||||
$it = array(
|
||||
'id' => $item_conf['id'],
|
||||
'price' => $item_conf['price'],
|
||||
);
|
||||
return $it;
|
||||
}
|
||||
|
||||
protected function getShop($shop_id)
|
||||
{
|
||||
$g_conf_shop_cluster = require('../res/shop@shop.php');
|
||||
$shop_conf = getShopConfig($g_conf_shop_cluster, $shop_id);
|
||||
$s = array(
|
||||
'shop_id' => $shop_conf['shop_id'],
|
||||
'item_id' => $shop_conf['item_id'],
|
||||
'num' => $shop_conf['num'],
|
||||
'item_weight' => $shop_conf['item_weight'],
|
||||
'discount' => $shop_conf['discount'],
|
||||
'discount_weight' => $shop_conf['discount_weight'],
|
||||
'tip' => $shop_conf['tip'],
|
||||
);
|
||||
return $s;
|
||||
}
|
||||
|
||||
protected function getParameter($para_id)
|
||||
{
|
||||
$g_conf_para_cluster = require('../res/parameter@parameter.php');
|
||||
$para_conf = getParameterConfig($g_conf_para_cluster, $para_id);
|
||||
$p = array(
|
||||
'id' => $para_conf['id'],
|
||||
'param_name' => $para_conf['param_name'],
|
||||
'param_value' => $para_conf['param_value'],
|
||||
);
|
||||
return $p;
|
||||
}
|
||||
|
||||
protected function getExplode($string)
|
||||
{
|
||||
$delim = "|";
|
||||
$drop_multiply = explode($delim, $string);
|
||||
$delim1 = ":";
|
||||
$arr = array();
|
||||
for ($i = 0; $i < count($drop_multiply); $i++) {
|
||||
$mul = explode($delim1, $drop_multiply[$i]);
|
||||
array_push($arr, $mul);
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
public function shopInfo()
|
||||
{
|
||||
$account_id = $_REQUEST['account_id'];
|
||||
//登录校验
|
||||
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
||||
if (!$login) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
||||
return;
|
||||
}
|
||||
$shop_uuid = 'game2001api_shop_uuid: ' . md5($_REQUEST['account_id']);
|
||||
$shop_list = array();
|
||||
$r = $this->getRedis($shop_uuid);
|
||||
if (!$r) {
|
||||
die();
|
||||
return;
|
||||
}
|
||||
$user_db_str = $r->get($shop_uuid);
|
||||
if (empty($user_db_str)) {
|
||||
$shop_list = $this->randomShop();
|
||||
$shop_db = array(
|
||||
'shop_uuid' => $shop_uuid,
|
||||
'shop_list' => $shop_list,
|
||||
);
|
||||
$r -> set($shop_uuid, json_encode($shop_db));
|
||||
$r -> pexpire($shop_uuid, 1000 * 3600 * 24);
|
||||
} else {
|
||||
$user_db = json_decode($user_db_str, true);
|
||||
if (empty($user_db)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1,'session失效');
|
||||
return;
|
||||
}
|
||||
foreach ($user_db['shop_list'] as $shop) {
|
||||
array_push($shop_list, array(
|
||||
'shop_id' => $shop['shop_id'],
|
||||
'item_id' => $shop['item_id'],
|
||||
'item_num' => $shop['item_num'],
|
||||
'discount' => $shop['discount'],
|
||||
'price' => $shop['price'],
|
||||
'tip' => $shop['tip'],
|
||||
'status' => $shop['status'],
|
||||
));
|
||||
}
|
||||
}
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg'=> '',
|
||||
'shop_uuid' => $shop_uuid,
|
||||
'shop_list' => $shop_list,
|
||||
));
|
||||
}
|
||||
|
||||
public function buyItem()
|
||||
{
|
||||
$account_id = $_REQUEST['account_id'];
|
||||
//登录校验
|
||||
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
||||
if (!$login) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
||||
return;
|
||||
}
|
||||
$shop_id = $_REQUEST['shop_id'];
|
||||
$shop_uuid = $_REQUEST['shop_uuid'];
|
||||
$item_id = 0;
|
||||
$item_num = 0;
|
||||
$price = 0;
|
||||
$status = 0;
|
||||
$flag = 0;
|
||||
$r = $this->getRedis($shop_uuid);
|
||||
$user_db_str = $r->get($shop_uuid);
|
||||
if (empty($user_db_str)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1,'session失效');
|
||||
return;
|
||||
}
|
||||
$user_db = json_decode($user_db_str, true);
|
||||
if (empty($user_db)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1,'session失效');
|
||||
return;
|
||||
}
|
||||
foreach ($user_db['shop_list'] as $shop) {
|
||||
if ($shop['shop_id'] == $shop_id) {
|
||||
$item_id = $shop['item_id'];
|
||||
$item_num = $shop['item_num'];
|
||||
$price = $shop['price'];
|
||||
$status = $shop['status'];
|
||||
$flag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($flag == 0) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个商品');
|
||||
return;
|
||||
}
|
||||
if ($status == 1) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 4, '商品已购买');
|
||||
return;
|
||||
}
|
||||
//扣除货币
|
||||
$this->SubCoin($price, $account_id);
|
||||
//修改购买状态
|
||||
foreach ($user_db['shop_list'] as &$shop) {
|
||||
if ($shop['shop_id'] == $shop_id) {
|
||||
$shop['status'] = 1;
|
||||
}
|
||||
}
|
||||
$r->set($shop_uuid, json_encode($user_db));
|
||||
//增加奖励
|
||||
$addreward = new classes\AddReward();
|
||||
$addreward->addReward($item_id, $item_num, $account_id);
|
||||
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg'=> '',
|
||||
));
|
||||
}
|
||||
|
||||
public function flushShop()
|
||||
{
|
||||
$account_id = $_REQUEST['account_id'];
|
||||
//登录校验
|
||||
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
||||
if (!$login) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
||||
return;
|
||||
}
|
||||
$shop_uuid = $_REQUEST['shop_uuid'];
|
||||
$shop_list = array();
|
||||
$r = $this->getRedis($shop_uuid);
|
||||
$user_db_str = $r->get($shop_uuid);
|
||||
if (empty($user_db_str)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1,'session失效');
|
||||
return;
|
||||
}
|
||||
$user_db = json_decode($user_db_str, true);
|
||||
if (empty($user_db)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1,'session失效');
|
||||
return;
|
||||
}
|
||||
if ($_REQUEST['type'] == 3) {
|
||||
$p = $this->getParameter(RAND_SHOP_GOLD);
|
||||
$this->SubCoin($p['param_value'], $account_id);
|
||||
}
|
||||
unset($user_db['shop_list']);
|
||||
$shop_list = $this->randomShop();
|
||||
$user_db['shop_list'] = $shop_list;
|
||||
$r -> set($shop_uuid, json_encode($user_db));
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg'=> '',
|
||||
'shop_uuid' => $shop_uuid,
|
||||
'shop_list' => $shop_list,
|
||||
));
|
||||
}
|
||||
|
||||
protected function randomShop()
|
||||
{
|
||||
$shop_list = array();
|
||||
$g_conf_shop_cluster = require('../res/shop@shop.php');
|
||||
for ($i = 1; $i <= count($g_conf_shop_cluster); $i++)
|
||||
{
|
||||
$item_id = 0;
|
||||
$item_num = 0;
|
||||
$discount = 0;
|
||||
$price = 0;
|
||||
$key = 0;
|
||||
$s = $this->getShop($i);
|
||||
//确定商品id和数量
|
||||
$weight_sum = 0;
|
||||
$weight_array = $this->getExplode($s['item_weight']);
|
||||
for ($ii = 0; $ii < count($weight_array); $ii++) {
|
||||
$weight_sum += $weight_array[$ii][0];
|
||||
}
|
||||
$random = Rand(0, $weight_sum);
|
||||
$weight = 0;
|
||||
for ($ii = 0; $ii < count($weight_array); $ii++) {
|
||||
$weight += $weight_array[$ii][0];
|
||||
if ($weight > $random) {
|
||||
$key = $ii;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$item_id_array = $this->getExplode($s['item_id']);
|
||||
$num_array = $this->getExplode($s['num']);
|
||||
$item_id = $item_id_array[$key][0];
|
||||
$item_num = $num_array[$key][0];
|
||||
//确定折扣和价格
|
||||
$it = $this->getItem($item_id);
|
||||
if ($s['tip'] != 3) {
|
||||
$discount = $s['discount'];
|
||||
$price = $it['price'];
|
||||
} else {
|
||||
$keys = 0;
|
||||
$weight_sum = 0;
|
||||
$weight_array = $this->getExplode($s['discount_weight']);
|
||||
for ($ii = 0; $ii < count($weight_array); $ii++) {
|
||||
$weight_sum += $weight_array[$ii][0];
|
||||
}
|
||||
$random = Rand(0, $weight_sum);
|
||||
$weight = 0;
|
||||
for ($ii = 0; $ii < count($weight_array); $ii++) {
|
||||
$weight += $weight_array[$ii][0];
|
||||
if ($weight > $random) {
|
||||
$keys = $ii;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$discount_array = $this->getExplode($s['discount']);
|
||||
$discount = $discount_array[$keys][0];
|
||||
$price = round($it['price'] * $item_num * ($discount * 1.0 / 10));
|
||||
}
|
||||
array_push($shop_list, array(
|
||||
'shop_id' => $s['shop_id'],
|
||||
'item_id' => $item_id,
|
||||
'item_num' => $item_num,
|
||||
'discount' => $discount,
|
||||
'price' => $price,
|
||||
'tip' => $s['tip'],
|
||||
'status' => 0,
|
||||
));
|
||||
}
|
||||
return $shop_list;
|
||||
}
|
||||
|
||||
protected function subCoin($coin_num, $account_id)
|
||||
{
|
||||
$conn = $this->getMysql($account_id);
|
||||
if (!$conn) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
|
||||
return;
|
||||
}
|
||||
//扣除货币
|
||||
$rowCoin = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;',
|
||||
array(
|
||||
':accountid' => $account_id
|
||||
));
|
||||
if ($rowCoin['coin_num'] < $coin_num) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 5, '金币不足');
|
||||
die();
|
||||
}
|
||||
$ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' .
|
||||
' WHERE accountid=:accountid;',
|
||||
array(
|
||||
':accountid' => $account_id,
|
||||
':coin_num' => $rowCoin['coin_num'] - $coin_num,
|
||||
':modify_time' => time()
|
||||
));
|
||||
if (!$ret) {
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user