This commit is contained in:
wangwei01 2019-08-23 11:30:47 +08:00
parent 0f6e4e7bfc
commit 37b1c0e29a
6 changed files with 161 additions and 128 deletions

View File

@ -69,6 +69,7 @@ CREATE TABLE `user` (
`diamond_shop_flush_times` int(11) NOT NULL DEFAULT '0' COMMENT '每日钻石商店刷新次数',
`sum_coin` double NOT NULL DEFAULT '0' COMMENT '累计充值金额',
`pass_status` int(11) NOT NULL DEFAULT '0' COMMENT '通行证购买状态',
`score` 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;

@ -1 +1 @@
Subproject commit 7ecf558df93a2656631782e76c6d35697da72808
Subproject commit 1e3bb4df855f6d11df75545d10b0c2aacea34a06

View File

@ -78,7 +78,7 @@ def refreshData(row, data_list, data_info):
alive_time = safeDiv(row[4], row[7])
harm = safeDiv(row[5], row[7])
win_times = safeDiv(row[6], row[7])
data_list.append((row[0], row[1].decode('utf-8'), row[2], kill, alive_time, harm, win_times, row[6]))
data_list.append((row[0], row[1].decode('utf-8'), row[2], kill, alive_time, harm, win_times, row[6], row[9]))
data_list.sort(key=key_info, reverse=True)
if (len(data_list) > 50):
del data_list[50:]
@ -115,6 +115,12 @@ def updateRank(r, kill_list, alive_list, harm_list, rate_list, win_list):
win_rank.append(win_list[win_index])
r.set("game2001api: win_rank", json.dumps(win_rank))
integral_list.sort(key=take_integral_times, reverse=True)
integral_rank = []
for integral_index in range(min(50, len(integral_list))):
integral_rank.append(integral_list[integral_index])
r.set("game2001api: integral_rank", json.dumps(integral_rank))
#每日定时读取mysql里的数据生成排行榜写入redis后php读取redis返回客户端显示
def dayReadMysqlData(rushtime):
mysql_conf = json.loads(open(CONFIG_DIR + '/rankserver.mysql.cluster.json', 'r').read())
@ -123,6 +129,7 @@ def dayReadMysqlData(rushtime):
harm_list = []
rate_list = []
win_list = []
integral_list = []
for conf in mysql_conf:
conn = pymysql.connect(host = conf['host'],
port = conf['port'],
@ -136,7 +143,7 @@ def dayReadMysqlData(rushtime):
temp_idx = 0
while 1:
cursor.execute('SELECT accountid, user_name, avatar_url, kills, alive_time,'
' harm, win_times, game_times, idx FROM user WHERE idx > %s LIMIT 0, 1000' % (last_idx))
' harm, win_times, game_times, idx, integral FROM user WHERE idx > %s LIMIT 0, 1000' % (last_idx))
has_data = False
for row in cursor:
@ -151,6 +158,8 @@ def dayReadMysqlData(rushtime):
refreshData(row, rate_list, take_win_times)
#更新胜场榜
refreshData(row, win_list, take_game_times)
#更新积分榜
refreshData(row, integral_list, take_integral_times)
temp_idx = int(row[8])
if (temp_idx > last_idx) :
last_idx = int(row[8])
@ -159,7 +168,7 @@ def dayReadMysqlData(rushtime):
break
r = getRedis()
updateRank(r, kill_list, alive_list, harm_list, rate_list, win_list)
updateRank(r, kill_list, alive_list, harm_list, rate_list, win_list, integral_list)
tornado.ioloop.IOLoop.current().call_later(getDaySeconds(time.time(), 1) + rushtime,
lambda : dayReadMysqlData(rushtime)
)
@ -198,6 +207,12 @@ def readMysqlData(rushtime):
else:
win_list = json.loads(win_list_str)
integral_list_str = r.get("game2001api: integral_rank")
if (not integral_list_str):
integral_list = []
else:
integral_list = json.loads(integral_list_str)
for conf in mysql_conf:
conn = pymysql.connect(host = conf['host'],
port = conf['port'],
@ -207,17 +222,9 @@ def readMysqlData(rushtime):
charset = 'utf8'
)
cursor = conn.cursor()
last_idx = 0
temp_idx = 0
kill_flag = 0
alive_flag = 0
harm_flag = 0
rate_flag = 0
win_flag = 0
data = ''
while 1:
cursor.execute('SELECT accountid, user_name, avatar_url, kills, alive_time,'
' harm, win_times, game_times, idx, modify_time FROM user '
' harm, win_times, game_times, idx, integral, modify_time FROM user '
' WHERE modify_time > %s AND idx > %s LIMIT 0, 1000' % (time.time() - 300, last_idx))
has_data = False
for row in cursor:
@ -237,13 +244,16 @@ def readMysqlData(rushtime):
#更新胜场榜
delRepeatData(row, win_list)
refreshData(row, win_list, take_game_times)
#更新积分榜
delRepeatData(row, integral_list)
refreshData(row, integral_list, take_integral_times)
temp_idx = int(row[8])
if (temp_idx > last_idx) :
last_idx = int(row[8])
if not has_data:
break
updateRank(r, kill_list, alive_list, harm_list, rate_list, win_list)
updateRank(r, kill_list, alive_list, harm_list, rate_list, win_list, integral_list)
tornado.ioloop.IOLoop.current().call_later(rushtime,
lambda : readMysqlData(rushtime)
)

View File

@ -94,6 +94,32 @@ class PayController{
return $arr;
}
protected function getItemInfo($itemid)
{
$d = $this->getDrop($itemid);
if (!$d) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个道具');
die();
}
$item_list = array();
$item_id_array = $this->getExplode($d['item_id']);
$weight_sum = 0;
$keys = 0;
$item_num_array = $this->getExplode($d['num']);
$weight_array = $this->getExplode($d['weight']);
for ($i = 0; $i < count($weight_array); $i++) {
$random = Rand(0, 10000);
if ($weight_array[$i][0] > $random) {
$item_id = $item_id_array[$i][0];
$item_num = $item_num_array[$i][0];
array_push($item_list, array(
'itemid' => $item_id,
'itemnum' => $item_num,
));
}
}
return $item_list;
}
public function getPayInfo()
{
@ -115,6 +141,7 @@ class PayController{
for ($i = 1; $i <= count($diamond_meta_table); $i++) {
$diamond = $this->getDiamondShop($i);
$item = $this->getItem($diamond['item_id']);
$item_list = $this->getItemInfo($item['fuctionindex']);
if (!$item || !$diamond) {
continue;
}
@ -142,8 +169,12 @@ class PayController{
$coin_icon = $sub_item['icon'];
}
if ($diamond['open_time'] != '-1') {
$open_time = strtotime($diamond['open_time']);
$end_time = strtotime($diamond['open_time']) + $diamond['continue_time'];
if ($diamond['open_time'] != '1') {
$open_time = strtotime($diamond['open_time']);
} else {
$open_time = time();
}
$end_time = $open_time + $diamond['continue_time'];
}
array_push($info_list, array(
'shop_type' => $diamond['shop_type'],
@ -155,7 +186,8 @@ class PayController{
'open_time' => $open_time,
'end_time' => $end_time,
'buy_num' => $times,
'sort' => $diamond['sort']
'sort' => $diamond['sort'],
'item_list' => $item_list,
));
}
echo json_encode(array(
@ -342,10 +374,10 @@ class PayController{
$this->updateStatus($account_id, $vip_id, $type);
//发送奖励
$item_list = array();
if ($type == 1) {
if ($type == 2) {
$item_list = $this->getVipItemInfo($vip['reward']);
}
if ($type == 2) {
if ($type == 1) {
$item_list = $this->getVipItemInfo($vip['dailyreward']);
}
foreach ($item_list as $item) {

View File

@ -27,6 +27,20 @@ class RankController{
return $r;
}
protected function getSeasonPoint($seaPoint_id)
{
$seaPoint_meta_table = require('../res/seasomPoint@seasomPoint.php');
$seaPoint_meta = getSeasonPointConfig($seaPoint_meta_table, $seaPoint_id);
$seaPoint = array(
'id' => $seaPoint_meta['id'],
'min' => $seaPoint_meta['min_point'],
'max' => $seaPoint_meta['max_point'],
'des' => $seaPoint_meta['des'],
);
return $seaPoint;
}
public function rankInfo()
{
$account_id = $_REQUEST['account_id'];
@ -43,32 +57,40 @@ class RankController{
}
$kill_list = array();
$kill_rank = 0;
$alive_list = array();
$alive_rank = 0;
$harm_list = array();
$harm_rank = 0;
$rate_list = array();
$rate_rank = 0;
$win_list = array();
$win_rank = 0;
$user_list = array();
$integral_rank = 0;
$integral_list = array();
$score = 0;
//个人信息
$row = $conn->execQueryOne('SELECT user_name, avatar_url, kills, alive_time, harm, win_times, game_times FROM user ' .
$row = $conn->execQueryOne('SELECT user_name, avatar_url, kills, alive_time, harm, win_times, game_times, integral FROM user ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
if ($row) {
array_push($user_list, array(
'account_id' => $account_id,
'name' => $row['user_name'],
'avatar_url' => $row['avatar_url'],
'kill' => phpcommon\safediv($row['kills'], $row['game_times']),
'alive'=> phpcommon\safediv($row['alive_time'], $row['game_times']),
'harm' => phpcommon\safediv($row['harm'], $row['game_times']),
'win_rate' => phpcommon\safediv($row['win_times'], $row['game_times']),
'win_game' => $row['win_times']
));
$seaPoint_meta_table = require('../res/seasomPoint@seasomPoint.php');
for ($ii = 1; $ii <= count($seaPoint_meta_table); $ii++) {
$seaPoint = $this->getSeasonPoint($ii);
if ($row['integral'] >= $seaPoint['min'] && $row['integral'] <= $seaPoint['max']
|| $seaPoint['max'] == -1) {
$rank = $ii;
$score = $row['integral'] - $seaPoint['min'];
}
array_push($user_list, array(
'account_id' => $account_id,
'name' => $row['user_name'],
'avatar_url' => $row['avatar_url'],
'kill' => phpcommon\safediv($row['kills'], $row['game_times']),
'alive'=> phpcommon\safediv($row['alive_time'], $row['game_times']),
'harm' => phpcommon\safediv($row['harm'], $row['game_times']),
'win_rate' => phpcommon\safediv($row['win_times'], $row['game_times']),
'win_game' => $row['win_times'],
'score' => $score,
'level' => $rank,
));
}
}
ini_set('memory_limit','3072M');
//击杀榜
@ -80,90 +102,64 @@ class RankController{
if ($i > 49) {
break;
}
if ($kill_db[$i][0] == $account_id) {
$kill_rank = $i + 1;
$seaPoint_meta_table = require('../res/seasomPoint@seasomPoint.php');
for ($ii = 1; $ii <= count($seaPoint_meta_table); $ii++) {
$seaPoint = $this->getSeasonPoint($ii);
if ($kill_db[$i][8] >= $seaPoint['min'] && $kill_db[$i][8] <= $seaPoint['max']
|| $seaPoint['max'] == -1) {
$rank = $ii;
$score = $kill_db[$i][8] - $seaPoint['min'];
}
if ($kill_db[$i][0] == $account_id) {
$kill_rank = $i + 1;
}
array_push($kill_list, array(
'account_id' => $kill_db[$i][0],
'name' => $kill_db[$i][1],
'avatar_url' => $kill_db[$i][2],
'kill' => $kill_db[$i][3],
'alive'=> $kill_db[$i][4],
'harm' => $kill_db[$i][5],
'win_rate' => $kill_db[$i][6],
'win_game' => $kill_db[$i][7],
'score' => $score,
'level' => $rank,
));
$i++;
}
array_push($kill_list, array(
'account_id' => $kill_db[$i][0],
'name' => $kill_db[$i][1],
'avatar_url' => $kill_db[$i][2],
'kill' => $kill_db[$i][3],
'alive'=> $kill_db[$i][4],
'harm' => $kill_db[$i][5],
'win_rate' => $kill_db[$i][6],
'win_game' => $kill_db[$i][7]
));
$i++;
}
//生存榜
$alive_rank_db = $r->get("game2001api: alive_rank");
$alive_db = json_decode($alive_rank_db);
//胜场榜
$win_rank_db = $r->get("game2001api: win_rank");
$win_db = json_decode($win_rank_db);
$i = 0;
foreach ($alive_db as $alive) {
foreach ($win_db as $win) {
if ($i > 49) {
break;
}
if ($alive_db[$i][0] == $account_id) {
$alive_rank = $i + 1;
$seaPoint_meta_table = require('../res/seasomPoint@seasomPoint.php');
for ($ii = 1; $ii <= count($seaPoint_meta_table); $ii++) {
$seaPoint = $this->getSeasonPoint($ii);
if ($win_db[$i][8] >= $seaPoint['min'] && $win_db[$i][8] <= $seaPoint['max']
|| $seaPoint['max'] == -1) {
$rank = $ii;
$score = $win_db[$i][8] - $seaPoint['min'];
}
}
array_push($alive_list, array(
'account_id' => $alive_db[$i][0],
'name' => $alive_db[$i][1],
'avatar_url' => $alive_db[$i][2],
'kill' => $alive_db[$i][3],
'alive'=> $alive_db[$i][4],
'harm' => $alive_db[$i][5],
'win_rate' => $alive_db[$i][6],
'win_game' => $alive_db[$i][7]
));
$i++;
}
//伤害榜
$harm_rank_db = $r->get("game2001api: harm_rank");
$harm_db = json_decode($harm_rank_db);
$i = 0;
foreach ($harm_db as $harm) {
if ($i > 49) {
break;
if ($win_db[$i][0] == $account_id) {
$win_rank = $i + 1;
}
if ($harm_db[$i][0] == $account_id) {
$harm_rank = $i + 1;
}
array_push($harm_list, array(
'account_id' => $harm_db[$i][0],
'name' => $harm_db[$i][1],
'avatar_url' => $harm_db[$i][2],
'kill' => $harm_db[$i][3],
'alive'=> $harm_db[$i][4],
'harm' => $harm_db[$i][5],
'win_rate' => $harm_db[$i][6],
'win_game' => $harm_db[$i][7]
));
$i++;
}
//胜率榜
$rate_rank_db = $r->get("game2001api: rate_rank");
$rate_db = json_decode($rate_rank_db);
$i = 0;
foreach ($rate_db as $rate) {
if ($i > 49) {
break;
}
if ($rate_db[$i][0] == $account_id) {
$rate_rank = $i + 1;
}
array_push($rate_list, array(
'account_id' => $rate_db[$i][0],
'name' => $rate_db[$i][1],
'avatar_url' => $rate_db[$i][2],
'kill' => $rate_db[$i][3],
'alive'=> $rate_db[$i][4],
'harm' => $rate_db[$i][5],
'win_rate' => $rate_db[$i][6],
'win_game' => $rate_db[$i][7]
array_push($win_list, array(
'account_id' => $win_db[$i][0],
'name' => $win_db[$i][1],
'avatar_url' => $win_db[$i][2],
'kill' => $win_db[$i][3],
'alive'=> $win_db[$i][4],
'harm' => $win_db[$i][5],
'win_rate' => $win_db[$i][6],
'win_game' => $win_db[$i][7],
'score' => $score,
'level' => $rank,
));
$i++;
}
@ -198,17 +194,10 @@ class RankController{
'user_list' => $user_list,
'kill_rank' => $kill_rank,
'kill_list' => $kill_list,
'alive_rank' => $alive_rank,
'alive_list' => $alive_list,
'harm_rank' => $harm_rank,
'harm_list' => $harm_list,
'rate_rank' => $rate_rank,
'rate_list' => $rate_list,
'win_rank' => $win_rank,
'win_list' => $win_list
'win_list' => $win_list,
'integral_rank' => $integral_rank,
'integral_list' => $integral_list,
));
}
}
?>

View File

@ -100,9 +100,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) ' .
' 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) ' .
' 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;',
$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) ' .
' 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) ' .
' 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;',
array(
':accountid' => $account_id,
':user_name' => $user_name,
@ -190,8 +190,8 @@ class RoleController{
$alive_time_his = $alive_time;
$add_HP_his = $add_HP;
$coin_num = $_REQUEST['coin_num']; //金币
$integral = $_REQUEST['score']; //积分
$integral = $_REQUEST['rank_score']; //排位积分
$score = $_REQUEST['pass_score']; //通行证积分
if (!$map_id) {
$map_id = 0;
}
@ -226,7 +226,7 @@ class RoleController{
if ($row['box_num'] + 1 <= 20) {
$box_num = $row['box_num'] + 1;
}
$ret = $conn->execScript('UPDATE user SET game_times=:game_times, win_times=:win_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, integral=:integral, modify_time=:modify_time, first_fight=1, box_num=:box_num ' .
$ret = $conn->execScript('UPDATE user SET game_times=:game_times, win_times=:win_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, integral=:integral, modify_time=:modify_time, first_fight=1, box_num=:box_num, score=:score ' .
' WHERE accountid=:accountid;',
array(
':game_times' => $row['game_times'] + 1,
@ -243,7 +243,8 @@ class RoleController{
':coin_num' => $row['coin_num'] + $coin_num,
':integral' => $row['integral'] + $integral,
':modify_time' => time(),
':box_num' => $box_num
':box_num' => $box_num,
':score' => $row['score'] + $score,
));
if (!$ret) {
die();