This commit is contained in:
aozhiwei 2020-04-08 19:28:42 +08:00
parent 0082f1122f
commit 429627c794
8 changed files with 494 additions and 90 deletions

View File

@ -75,6 +75,13 @@ CREATE TABLE `user` (
`daily_time` int(11) NOT NULL DEFAULT '0' COMMENT '每日刷新时间',
`free_box` int(11) NOT NULL DEFAULT '0' COMMENT '每日免费宝箱',
`update_time` int(11) NOT NULL DEFAULT '0' COMMENT '刷新活动时间',
`season_games` int(11) NOT NULL DEFAULT '0' COMMENT '赛季场次总数',
`season_win` int(11) NOT NULL DEFAULT '0' COMMENT '赛季胜利场次',
`sea_max_kill` int(11) NOT NULL DEFAULT '0' COMMENT '赛季最高击杀',
`sea_max_hart` int(11) NOT NULL DEFAULT '0' COMMENT '赛季最高伤害',
`sea_avg_kill` int(11) NOT NULL DEFAULT '0' COMMENT '赛季场均淘汰',
PRIMARY KEY (`idx`),
UNIQUE KEY `accountid` (`accountid`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
@ -192,4 +199,20 @@ CREATE TABLE `passinfo` (
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
DROP TABLE IF EXISTS `shop`;
/*!40101 SET @saved_cs_client = @@character_set_client*/;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `shop` (
`idx` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id',
`accountid` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id',
`coin_id` int(11) NOT NULL DEFAULT '0' COMMENT '金币商店物品id',
`coin_discount` int(11) NOT NULL DEFAULT '0' COMMENT '金币商店折扣',
`diamond_id` int(11) NOT NULL DEFAULT '0' COMMENT '钻石商店物品id',
`diamond_discount` int(11) NOT NULL DEFAULT '0' COMMENT '钻石商店折扣',
`create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modify_time` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),
UNIQUE KEY `accountid` (`accountid`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
-- Dump completed on 2015-08-19 18:51:22

View File

@ -0,0 +1,12 @@
begin;
alter table user add column `season_games` int(11) NOT NULL DEFAULT '0' COMMENT '赛季场次总数';
alter table user add column `season_win` int(11) NOT NULL DEFAULT '0' COMMENT '赛季胜利场次';
alter table user add column `sea_max_kill` int(11) NOT NULL DEFAULT '0' COMMENT '赛季最高击杀';
alter table user add column `sea_max_hart` int(11) NOT NULL DEFAULT '0' COMMENT '赛季最高伤害';
alter table user add column `sea_avg_kill` int(11) NOT NULL DEFAULT '0' COMMENT '赛季场均淘汰';
insert into version (version) values(20200408);
commit;

View File

@ -212,5 +212,11 @@ function getDrawTableConfig($drawbig_table, $drawbig_id)
$drawbig_id = (int)$drawbig_id;
return array_key_exists($drawbig_id, $drawbig_table) ? $drawbig_table[$drawbig_id] : null;
}
function getRecommendConfig($rec_table, $rec_id)
{
$rec_id = (int)$rec_id;
return array_key_exists($rec_id, $rec_table) ? $rec_table[$rec_id] : null;
}
checkMysqlConfig();
checkRedisConfig();

View File

@ -299,7 +299,27 @@ class AddReward {
$s = 0;
}
} else {
$s = 0;
$emoji_num = 0;
foreach ($bag_meta_table as $bag_info) {
$id = $bag_info['id'];
$bag = $this->getBag($id);
if ($bag['fuction'] != $b['fuction']) {
continue;
}
$row_emoji = $conn->execQueryOne('SELECT status FROM bag WHERE accountid=:accountid AND id=:id;',
array(
':accountid' => $accountid,
':id' => $id,
));
if ($row_emoji['status'] == 0) {
$emoji_num++;
}
}
if ($emoji_num >= 6) {
$s = 1;
} else {
$s = 0;
}
}
return $s;
}

View File

@ -86,10 +86,24 @@ class ActivityController{
return $l;
}
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'],
'diamond' => $item_conf['diamond'],
'type' => $item_conf['fuction'],
'diamond_hour' => $item_conf['diamond_hour'],
'pool_weight' => $item_conf['pool_weight'],
);
return $it;
}
protected function getDrawTableConfig($id)
{
$g_conf_lot_cluster = require('../res/lotterydraw@lotterydraw.php');
$lot_conf = getLotteryConfig($g_conf_lot_cluster, $lot_id);
$lot_conf = getLotteryConfig($g_conf_lot_cluster, $id);
$l = array(
'id' => $lot_conf['id'],
'item_id' => $lot_conf['item_id'],
@ -115,6 +129,21 @@ class ActivityController{
return $re;
}
protected function getRecommend($rec_id)
{
$g_conf_rec_cluster = require('../res/recommend@recommend.php');
$rec_conf = getRecommendConfig($g_conf_rec_cluster, $rec_id);
$rec = array(
'pool' => $rec_conf['pool'],
'rank' => $rec_conf['rank'],
'time' => $rec_conf['time'],
'reward' => $rec_conf['reward'],
're_reward' => $rec_conf['regular_reward'],
'huge_reward' => $rec_conf['huge_reward'],
);
return $rec;
}
public function drawTableInfo()
{
$account_id = $_REQUEST['account_id'];
@ -140,8 +169,15 @@ class ActivityController{
}
//道具物品
$user_db_str = $r->get($drawtable_uuid);
if (empty($user_db_str)) {
//$user_db_str = $r->get($drawtable_uuid);
$drawtable_list = $this->randomReward(2);
$drawtable_db = array(
'drawtable_uuid' => $drawtable_uuid,
'drawtable_list' => $drawtable_list,
);
$r -> set($drawtable_uuid, json_encode($drawtable_db));
$r -> pexpire($drawtable_uuid, 1000 * 3600 * 24);
/*if (empty($user_db_str)) {
$drawtable_list = $this->randomReward(2);
$drawtable_db = array(
'drawtable_uuid' => $drawtable_uuid,
@ -151,6 +187,13 @@ class ActivityController{
$r -> pexpire($drawtable_uuid, 1000 * 3600 * 24);
} else {
$drawtable_db = json_decode($user_db_str, true);
$drawtable_list = $this->randomReward(2);
$drawtable_db = array(
'drawtable_uuid' => $drawtable_uuid,
'drawtable_list' => $drawtable_list,
);
$r -> set($drawtable_uuid, json_encode($drawtable_db));
$r -> pexpire($drawtable_uuid, 1000 * 3600 * 24);
$rowTime = $conn->execQueryOne('SELECT modify_time FROM activity WHERE accountid=:accountid;',
array(
':accountid' => $account_id
@ -178,7 +221,7 @@ class ActivityController{
));
}
}
}
}*/
echo json_encode(array(
'errcode' => 0,
@ -310,14 +353,14 @@ class ActivityController{
$weight_sum = 0;
$g_conf_lot_cluster = require('../res/lotterydraw@lotterydraw.php');
for ($i = 1; $i <= count($g_conf_lot_cluster); $i++) {
$l = $this->getLottery($i);
$l = $this->getDrawTableConfig($i);
$weight_sum += $l['jilv'];
}
$random = Rand(0, $weight_sum);
$weight = 0;
$key = 0;
for ($ii = 1; $ii <= count($g_conf_lot_cluster); $ii++) {
$l = $this->getLottery($ii);
$l = $this->getDrawTableConfig($ii);
$weight += $l['jilv'];
if ($weight > $random) {
$key = $ii;
@ -567,7 +610,12 @@ class ActivityController{
$item_id = 0;
$item_num = 0;
$key = 0;
$l = $this->getLottery($i);
$l = array();
if ($type == 1) {
$l = $this->getLottery($i);
} else {
$l = $this->getDrawTableConfig($i);
}
//确定商品id和数量
$weight_sum = 0;
$weight_array = $this->getExplode($l['weight']);
@ -602,9 +650,140 @@ class ActivityController{
return $draw_list;
}
public function lotteryReward()
{
$account_id = $_REQUEST['account_id'];
//登录校验
$login = loginVerify($account_id, $_REQUEST['session_id']);
if (!$login) {
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
return;
}
$pool = $_REQUEST['pool'];
$rec = $this->getRecommend($pool);
$reward_id = 0;
$item_list = array();
$all_item_list = array();
$reward_array = array();
$addreward = new classes\AddReward();
$delim = "|";
$num_multiply = explode($delim, $rec['huge_reward']);
//随机奖励
for($i = 0; $i < $rec['reward']; $i++) {
$item_num = 1;
$time = $this->randtime($rec['time']);
$reward_id = $this->randlottery($reward_array, $pool);
array_push($reward_array, array(
'id' => $reward_id
));
if ($reward_id == 10001) {
$item_num = $num_multiply[0];
$time = 0;
} else if ($reward_id == 10003) {
$item_num = $num_multiply[1];
$time = 0;
}
array_push($item_list, array(
'item_id' => $reward_id,
'item_num' => $item_num,
'time' => $time,
));
$items = $addreward->addReward($reward_id, $item_num, $account_id, $time, 0);
foreach($items as $j) {
array_push($all_item_list, array(
'item_id' => $j['item_id'],
'item_num' => $j['item_num'],
'time' => $j['time'],
));
}
}
//固定奖励
$delim2 = ":";
$re_multiply = explode($delim2, $rec['re_reward']);;
array_push($item_list, array(
'item_id' => $re_multiply[0],
'item_num' => $re_multiply[1],
'time' => 0,
));
$items = $addreward->addReward($re_multiply[0], $re_multiply[1], $account_id, 0, 0);
foreach($items as $s) {
array_push($all_item_list, array(
'item_id' => $s['item_id'],
'item_num' => $s['item_num'],
'time' => $s['time'],
));
}
$coin_num = $addreward->getCoinNum($account_id);
$diamond_num = $addreward->getDiamondNum($account_id);
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'coin_nums' => $coin_num,
'diamond_nums' => $diamond_num,
'item_list' => $item_list,
'all_item_list' => $all_item_list
));
}
protected function randtime($str_time)
{
$weight_sum = 0;
$weight_array = $this->getExplode($str_time);
for ($ii = 0; $ii < count($weight_array); $ii++) {
$weight_sum += $weight_array[$ii][1];
}
$random = Rand(0, $weight_sum);
$weight = 0;
$key = 0;
for ($ii = 0; $ii < count($weight_array); $ii++) {
$weight += $weight_array[$ii][1];
if ($weight > $random) {
$key = $weight_array[$ii][0];
break;
}
}
return $key;
}
protected function randlottery($id, $pool)
{
$weight_sum = 0;
$rand_array = array();
$po = $pool - 1;
$g_conf_item_cluster = require('../res/item@item.php');
foreach($g_conf_item_cluster as $items) {
$flag = 0;
$it = $this->getItem($items['id']);
if ($it['id'] != 0) {
foreach ($id as $ids) {
if ($it['id'] == $ids['id']) {
$flag = 1;
break;
}
}
if ($flag == 1) {
continue;
}
$weight_array = $this->getExplode($it['pool_weight']);
$weight_sum += $weight_array[$po][0];
array_push($rand_array, array(
'id' => $it['id'],
'weight' => $weight_array[$po][0]
));
}
}
$random = Rand(0, $weight_sum);
$weight = 0;
$key = 0;
foreach ($rand_array as $r) {
$weight += $r['weight'];
if ($weight > $random) {
$key = $r['id'];
break;
}
}
return $key;
}
}
?>

View File

@ -116,9 +116,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, collect_status, keys_num, battle_re_times, shop_flush_times, kefu_status, sign_sum, box_num, diamond_num, sum_coin, pass_status, score, season_status, recharge_times_total, first_gift, season_time, free_coin, free_diamond, season_end_score, kill_modifytime, win_modifytime, rank_modifytime, vip_score, first_login, daily_first_login, daily_time, free_box, update_time) ' .
' 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, :daily_time, 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, battle_re_times=0, shop_flush_times=0, kefu_status=0, sign_sum=0, box_num=0, diamond_num=0, sum_coin=0, pass_status=0, score=0, season_status=1, recharge_times_total=0, first_gift=0, season_time=0, free_coin=0, free_diamond=0, season_end_score=0, kill_modifytime=0, win_modifytime=0, rank_modifytime=0, vip_score=0, first_login=0, daily_first_login=0, daily_time=:daily_time, free_box=0, update_time=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, battle_re_times, shop_flush_times, kefu_status, sign_sum, box_num, diamond_num, sum_coin, pass_status, score, season_status, recharge_times_total, first_gift, season_time, free_coin, free_diamond, season_end_score, kill_modifytime, win_modifytime, rank_modifytime, vip_score, first_login, daily_first_login, daily_time, free_box, update_time, season_games, season_win, sea_max_kill, sea_max_hart, sea_avg_kill) ' .
' 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, :daily_time, 0,0,0,0,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, battle_re_times=0, shop_flush_times=0, kefu_status=0, sign_sum=0, box_num=0, diamond_num=0, sum_coin=0, pass_status=0, score=0, season_status=1, recharge_times_total=0, first_gift=0, season_time=0, free_coin=0, free_diamond=0, season_end_score=0, kill_modifytime=0, win_modifytime=0, rank_modifytime=0, vip_score=0, first_login=0, daily_first_login=0, daily_time=:daily_time, free_box=0, update_time=0, season_games=0, season_win=0, sea_max_kill=0, sea_max_hart=0, sea_avg_kill=0;',
array(
':accountid' => $account_id,
':user_name' => $user_name,
@ -156,7 +156,12 @@ class RoleController{
'recharge_times_total' => 0,
'first_login' => 0,
'daily_first_login' => 0,
'free_box' => 0
'free_box' => 0,
'season_games' => 0,
'season_win' => 0,
'sea_max_kill' => 0,
'sea_max_hart' => 0,
'sea_avg_kill' => 0
));
} else {
$ret = $conn->execScript('UPDATE user SET first_login=1 ' .
@ -231,7 +236,12 @@ class RoleController{
'vip_score' => $row['vip_score'],
'coin_nums' => $row['coin_num'],
'diamond_nums' => $row['diamond_num'],
'free_box' => $row['free_box']
'free_box' => $row['free_box'],
'season_games' => $row['season_games'],
'season_win' => $row['season_win'],
'sea_max_kill' => $row['sea_max_kill'],
'sea_max_hart' => $row['sea_max_hart'],
'sea_avg_kill' => $row['sea_avg_kill']
));
}
}
@ -323,11 +333,12 @@ class RoleController{
}
//更新胜场信息时间
if ($rank == 1) {
$winret = $conn->execScript('UPDATE user SET win_times=:win_times, win_modifytime=:win_modifytime ' .
$winret = $conn->execScript('UPDATE user SET win_times=:win_times, season_win=:season_win, win_modifytime=:win_modifytime ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':win_times' => $row['win_times'] + 1,
':season_win' => $row['season_win'] + 1,
':win_modifytime' => time(),
));
if (!$winret) {
@ -356,6 +367,17 @@ class RoleController{
if ($harm_his < $row['harm_his']) {
$harm_his = $row['harm_his'];
}
$sea_max_hart = $harm;
if ($sea_max_hart < $row['sea_max_hart']) {
$sea_max_hart = $row['sea_max_hart'];
}
$sea_max_kill = $kills;
if ($sea_max_kill < $row['sea_max_kill']) {
$sea_max_kill = $row['sea_max_kill'];
}
if ($alive_time_his < $row['alive_time_his']) {
$alive_time_his = $row['alive_time_his'];
}
@ -377,7 +399,7 @@ class RoleController{
if ($switch == 1) {
$daily_first_login = $daily_first_login + 1;
}
$ret = $conn->execScript('UPDATE user SET game_times=:game_times, kills=:kills, harm=:harm, add_HP=:add_HP, alive_time=:alive_time, kill_his=:kill_his, alive_time_his=:alive_time_his, harm_his=:harm_his, add_HP_his=:add_HP_his, coin_num=:coin_num, modify_time=:modify_time, first_fight=1, box_num=:box_num, score=:score, daily_time=:daily_time, daily_first_login=:daily_first_login ' .
$ret = $conn->execScript('UPDATE user SET game_times=:game_times, kills=:kills, harm=:harm, add_HP=:add_HP, alive_time=:alive_time, kill_his=:kill_his, alive_time_his=:alive_time_his, harm_his=:harm_his, add_HP_his=:add_HP_his, coin_num=:coin_num, modify_time=:modify_time, first_fight=1, box_num=:box_num, score=:score, daily_time=:daily_time, daily_first_login=:daily_first_login, season_games=:season_games, sea_max_kill=:sea_max_kill, sea_max_hart=:sea_max_hart, sea_avg_kill=:sea_avg_kill ' .
'WHERE accountid=:accountid;',
array(
':game_times' => $row['game_times'] + 1,
@ -395,7 +417,11 @@ class RoleController{
':box_num' => $box_num,
':score' => $row['score'] + $score,
':daily_time' => $daily_time,
':daily_first_login' => $daily_first_login
':daily_first_login' => $daily_first_login,
':season_games' => $row['season_games'] + 1,
':sea_max_kill' => $sea_max_kill,
':sea_max_hart' => $sea_max_hart,
':sea_avg_kill' => $row['sea_avg_kill'] + $kills,
));
if (!$ret) {
die();

View File

@ -35,8 +35,10 @@ class ShopController{
$item_conf = getItemConfig($g_conf_item_cluster, $item_id);
$it = array(
'id' => $item_conf['id'],
'price' => $item_conf['price'],
'dprice' => $item_conf['dprice'],
'price' => $item_conf['gold'],
'dprice' => $item_conf['diamond_price'],
'discount' => $item_conf['discount'],
'shop_type' => $item_conf['shop_type'],
);
return $it;
}
@ -132,37 +134,180 @@ class ShopController{
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
return;
}
$shop_uuid = 'game2004api_shop_uuid: ' . md5($_REQUEST['account_id']);
$diamond_shop_uuid = 'game2004api_diamond_shop_uuid:' . md5($_REQUEST['account_id']);
//钻石商店信息
//$diamond_shop_list = $this->getShopInfo($diamond_shop_uuid, 2);
//商店信息
$shop_list = $this->getShopInfo($shop_uuid);
$conn = $this->getMysql($account_id);
if (!$conn) {
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
return;
}
$row = $conn->execQueryOne('SELECT shop_flush_times FROM user WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
if (!$row) {
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
return;
$shop_uuid = 'game2004api_shop_uuid: ' . md5($_REQUEST['account_id']);
$diamond_shop_uuid = 'game2004api_diamond_shop_uuid:' . md5($_REQUEST['account_id']);
//商店信息
$shop_list = $this->getShopInfo($shop_uuid);
$rand_coinshop = array();
$rand_diamondshop = array();
$g_conf_item_cluster = require('../res/item@item.php');
$rows = $conn->execQuery('SELECT * FROM bag WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
$status = 0;
$coin_shop = array();
$diamond_shop = array();
foreach($g_conf_item_cluster as $items) {
$it = $this->getItem($items['id']);
$status = 0;
foreach($rows as $r) {
if ($r['id'] != $it['id']) {
continue;
}
if ($r['status'] == 2 || $r['active_time'] != 0) {
continue;
}
$status = 1;
break;
}
if ($it['shop_type'] == 1) {
if ($status == 0) {
array_push($rand_coinshop,array(
'id' => $it['id'],
));
}
array_push($coin_shop,array(
'id' => $it['id'],
'price' => $it['price'],
'status' => $status,
'discount' => 0,
'coin_id' => 10001,
));
} else if ($it['shop_type'] == 2) {
if ($status == 0) {
array_push($rand_diamondshop,array(
'id' => $it['id'],
));
}
array_push($diamond_shop,array(
'id' => $it['id'],
'price' => $it['dprice'],
'status' => $status,
'discount' => 0,
'coin_id' => 10003,
));
}
}
$row_shop = $conn->execQueryOne('SELECT * FROM shop WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
$randcoin_id = 0;
$coin_discount = 0;
if (count($rand_coinshop) >= 1) {
$random_coin = Rand(0, count($rand_coinshop) - 1);
$randcoin_id = $rand_coinshop[$random_coin]['id'];
$cinfo = $this->getItem($randcoin_id);
$coin_discount = $this->randdiscount($cinfo['discount']);
}
$randdiamnod_id = 0;
$dia_discount = 0;
if (count($rand_diamondshop) >= 1) {
$random_diamond = Rand(0, count($rand_diamondshop) - 1);
$randdiamnod_id = $rand_diamondshop[$random_diamond]['id'];
$dinfo = $this->getItem($randdiamnod_id);
$dia_discount = $this->randdiscount($dinfo['discount']);
}
if (!$row_shop) {
$ret = $conn->execScript('INSERT INTO shop(accountid, coin_id, coin_discount, diamond_id, diamond_discount, create_time, modify_time) ' .
' VALUES(:account_id, :coin_id, :coin_discount, :diamond_id, :diamond_discount, :create_time, :modify_time) ' .
' ON DUPLICATE KEY UPDATE accountid=:account_id, coin_id=:coin_id, coin_discount=:coin_discount, diamond_id=:diamond_id, diamond_discount=:diamond_discount, modify_time=:modify_time;',
array(
':account_id' => $account_id,
':coin_id' => $randcoin_id,
':coin_discount' => $coin_discount,
':diamond_id' => $randdiamnod_id,
':diamond_discount' => $dia_discount,
':create_time' => time(),
':modify_time' => time()
));
if(!$ret){
die();
return;
}
} else {
if (phpcommon\getdayseconds(time()) - phpcommon\getdayseconds($row_shop['modify_time']) > 0) {
$ret = $conn->execScript('UPDATE shop SET coin_id=:coin_id, coin_discount=:coin_discount, diamond_id=:diamond_id, diamond_discount=:diamond_discount, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':coin_id' => $randcoin_id,
':coin_discount' => $coin_discount,
':diamond_id' => $randdiamnod_id,
':diamond_discount' => $dia_discount,
':modify_time' => time()
));
if (!$ret) {
die();
return;
}
} else {
$randcoin_id = $row_shop['coin_id'];
$coin_discount = $row_shop['coin_discount'];
$randdiamnod_id = $row_shop['diamond_id'];
$dia_discount = $row_shop['diamond_discount'];
}
}
foreach($coin_shop as &$co) {
if ($co['id'] == $randcoin_id && $co['status'] != 1) {
error_log($randcoin_id);
$co['discount'] = $coin_discount;
$co['price'] = round($co['price'] * $coin_discount / 10);
}
}
unset($co);
foreach($diamond_shop as &$di) {
if ($di['id'] == $randdiamnod_id && $di['status'] != 1) {
$di['discount'] = $dia_discount;
$di['price'] = round($di['price'] * $dia_discount / 10);
}
}
unset($di);
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'shop_uuid' => $shop_uuid,
'shop_list' => $shop_list,
'shop_flush_times' => $row['shop_flush_times'],
/*'diamond_shop_uuid' => $diamond_shop_uuid,
'diamond_shop_list' => $diamond_shop_list,
'diamond_shop_flush_times' => $row['diamond_shop_flush_times'],*/
'shop_flush_times' => 0,
'coin_shop' => $coin_shop,
'diamond_shop' => $diamond_shop,
));
}
protected function randdiscount($array)
{
$keys = 0;
$weight_sum = 0;
$weight_array = $this->getExplode($array);
for ($ii = 0; $ii < count($weight_array); $ii++) {
$weight_sum += $weight_array[$ii][1];
}
$random = Rand(0, $weight_sum);
$weight = 0;
for ($ii = 0; $ii < count($weight_array); $ii++) {
$weight += $weight_array[$ii][1];
if ($weight > $random) {
$keys = $ii;
break;
}
}
return $weight_array[$keys][0];
}
public function buyItem()
{
$account_id = $_REQUEST['account_id'];
@ -172,68 +317,60 @@ class ShopController{
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
return;
}
$shop_id = $_REQUEST['shop_id'];
if (!isset($_REQUEST['shop_uuid'])) {
$id = $_REQUEST['id'];
$conn = $this->getMysql($account_id);
if (!$conn) {
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
return;
}
$shop_uuid = $_REQUEST['shop_uuid'];
$item_id = 0;
$item_num = 0;
$price = 0;
$status = 0;
$flag = 0;
$tip = 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'];
$tip = $shop['tip'];
$time = $shop['time'];
$flag = 1;
break;
$row = $conn->execQueryOne('SELECT status, active_time FROM bag WHERE accountid=:accountid AND id=:id;',
array(
':accountid' => $account_id,
':id' => $id
));
if ($row) {
if ($row['status'] != 2 && $row['active_time'] == 0) {
phpcommon\sendError(ERR_USER_BASE + 4, '商品已购买');
return;
}
}
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, $tip);
//修改购买状态
foreach ($user_db['shop_list'] as &$shop) {
if ($shop['shop_id'] == $shop_id) {
$shop['status'] = 1;
$i = $this->getItem($id);
$price = 0;
if ($i['shop_type'] == 1) {
$row_c = $conn->execQueryOne('SELECT * FROM shop WHERE accountid=:accountid AND coin_id=:id;',
array(
':accountid' => $account_id,
':id' => $id
));
$price = $i['price'];
if ($row_c) {
$price = round($i['price'] * $row_c['coin_discount'] / 10);
}
$this->SubCoin($price, $account_id, 1);
} else if ($i['shop_type'] == 2) {
$price = $i['dprice'];
$row_d = $conn->execQueryOne('SELECT * FROM shop WHERE accountid=:accountid AND diamond_id=:id;',
array(
':accountid' => $account_id,
':id' => $id
));
if ($row_d) {
$price = round($i['dprice'] * $row_d['diamond_discount'] / 10);
}
$this->SubCoin($price, $account_id, 2);
}
$r->set($shop_uuid, json_encode($user_db));
$r -> pexpire($shop_uuid, 1000 * 3600 * 24);
//增加奖励
$addreward = new classes\AddReward();
$all_item_list = $addreward->addReward($item_id, $item_num, $account_id, $time, 0);
$all_item_list = $addreward->addReward($id, 1, $account_id, 0, 0);
$coin_num = $addreward->getCoinNum($account_id);
$diamond_num = $addreward->getDiamondNum($account_id);
$item_list = array();
array_push($item_list,array(
'item_id' => $item_id,
'item_num' => $item_num,
'time' => $time,
'item_id' => $id,
'item_num' => 1,
'time' => 0,
));
echo json_encode(array(
'errcode' => 0,
@ -515,7 +652,7 @@ class ShopController{
array(
':accountid' => $account_id
));
if ($tips == 3) {
if ($tips == 1) {
//扣除货币
if ($rowCoin['coin_num'] < $coin_num) {
phpcommon\sendError(ERR_USER_BASE + 5, '金币不足');
@ -532,7 +669,7 @@ class ShopController{
die();
}
}
if ($tips == 4) {
if ($tips == 2) {
//扣除货币
if ($rowCoin['diamond_num'] < $coin_num) {
phpcommon\sendError(ERR_USER_BASE + 5, '钻石不足');

View File

@ -140,8 +140,9 @@ class SignController{
if (phpcommon\getMondayseconds(time()) - phpcommon\getMondayseconds($rowuser['update_time']) > 0) {
$this->updateWeekReward($account_id);
}
}
if ($nowTime - phpcommon\getdayseconds($last_sign_time) > 0) {
$passed_days = floor(($nowTime - phpcommon\getdayseconds($last_sign_time)) / (3600 * 24));
if ($passed_days > 7 - $last_sign_id) {
//跨周时删除老数据
$num = 0;
@ -164,7 +165,7 @@ class SignController{
} else {
$sum = $num;
}*/
for ($i = $last_sign_id + 1; $i < 7; $i++) {
for ($i = $last_sign_id + 1; $i < 7 + 1; $i++) {
//插入补签列表
$this->insertSign($account_id, $i);
}
@ -455,7 +456,7 @@ class SignController{
':accountid' => $account_id,
));
if (time() > $rowUser['season_time'] && $rowUser['season_time'] != 0) {
$user_ret = $conn->execScript('UPDATE user SET pass_status=0, score=0, season_status=0, integral=0, season_end_score=:season_end_score, modify_time=:modify_time ' .
$user_ret = $conn->execScript('UPDATE user SET pass_status=0, score=0, season_status=0, integral=0, season_end_score=:season_end_score, modify_time=:modify_time, season_games=0, sea_max_kill=0, sea_max_hart=0, sea_avg_kill=0, season_win=0 ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,