134 lines
3.8 KiB
PHP
134 lines
3.8 KiB
PHP
<?php
|
||
|
||
use Core\Db;
|
||
|
||
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'autoload.php';
|
||
|
||
/**
|
||
* Обновить рейтинг кланов.
|
||
* Раз в день.
|
||
*/
|
||
|
||
$add_exp_list = [];
|
||
$all_exp_list = [];
|
||
$exp_list = [];
|
||
$win_list = [];
|
||
$lose_list = [];
|
||
$nich_list = [];
|
||
$xu_list = [];
|
||
$level_list = [];
|
||
$log_list = [];
|
||
|
||
$clans = Db::getRows(
|
||
'
|
||
select
|
||
clan.id as cid,
|
||
clan.level,
|
||
clan.name,
|
||
count(*) as ucount,
|
||
clan.exp,
|
||
stats.id as sid,
|
||
sum(users.win) as win,
|
||
sum(users.lose) as lose,
|
||
sum(users.nich) as nich,
|
||
aaa_clan_reting_list.global
|
||
from
|
||
clan
|
||
left join users on clan.id = users.clan
|
||
left join stats on users.id = stats.id
|
||
left join aaa_clan_reting_list on aaa_clan_reting_list.clan = clan.id
|
||
where clan.id not in (62, 93) and users.admin = 0 and users.`real` = 1
|
||
'
|
||
);
|
||
|
||
foreach ($clans as $clan) {
|
||
$add_exp = 0;
|
||
$add_exp_list[$clan['cid']] = 0;
|
||
$all_exp_list[$clan['cid']] = 0;
|
||
$log_list[$clan['cid']] = $clan['name'];
|
||
$level_list[$clan['cid']] = $clan['level'];
|
||
$xu_list[$clan['cid']] = $clan['ucount'];
|
||
$exp_list[$clan['cid']] = $clan['exp'];
|
||
$win_list[$clan['cid']] = $clan['win'];
|
||
$lose_list[$clan['cid']] = $clan['lose'];
|
||
$nich_list[$clan['cid']] = $clan['nich'];
|
||
|
||
$clanMemberStats = Db::getRows(
|
||
'select
|
||
stats.id,
|
||
repexp
|
||
from
|
||
stats
|
||
left join users on users.id = stats.id
|
||
where clan = ?',
|
||
[$clan['cid']]
|
||
);
|
||
|
||
foreach ($clanMemberStats as $stat) {
|
||
$add_exp += $stat['repexp'];
|
||
Db::sql('update stats set repexp = 0 where id = ?', [$stat['id']]);
|
||
}
|
||
|
||
$global_exp = idate('d') != 1 ? round($clan['global']) : 0;
|
||
if ($clan['ucount'] > 0) {
|
||
$add_exp_list[$clan['cid']] = $add_exp; //записываем сколько опыта получил за сегодня
|
||
$all_exp_list[$clan['cid']] = $global_exp + $add_exp; //записываем сколько опыта получил всего + сегодняшний
|
||
}
|
||
}
|
||
|
||
arsort($all_exp_list);
|
||
|
||
$keys = array_keys($all_exp_list);
|
||
|
||
$i = 0;
|
||
foreach ($keys as $key) {
|
||
$i++;
|
||
if (!$key) {
|
||
continue;
|
||
}
|
||
Db::sql(
|
||
'insert into aaa_clan_reting_list (level, xu, win, lose, nich, exp_real, clan, pos, global, exp, date, time) values (?,?,?,?,?,?,?,?,?,?,?,unix_timestamp())',
|
||
[
|
||
$level_list[$key],
|
||
$xu_list[$key],
|
||
$win_list[$key],
|
||
$lose_list[$key],
|
||
$nich_list[$key],
|
||
$exp_list[$key],
|
||
$key,
|
||
$i,
|
||
$all_exp_list[$key],
|
||
$add_exp_list[$key],
|
||
date('dmY'),
|
||
]
|
||
);
|
||
}
|
||
|
||
$prize = [
|
||
1 => $xu_list[0] * 0.3,
|
||
2 => $xu_list[1] * 0.2,
|
||
3 => $xu_list[2] * 0.1,
|
||
];
|
||
const RATING_MSG = 'Клан %s получает %s екр. в казну клана за %s-е место в рейтинге!';
|
||
|
||
$stmt = Db::prepare('update clan set money2 = money2 + ? where id = ?');
|
||
$stmt->execute([$prize[1], $keys[0]]);
|
||
$stmt->execute([$prize[2], $keys[1]]);
|
||
$stmt->execute([$prize[3], $keys[2]]);
|
||
|
||
Db::sql(
|
||
'insert into chat (text, city, type, new, time) values
|
||
(?,\'capitalcity\',6,1,unix_timestamp()),
|
||
(?,\'capitalcity\',6,1,unix_timestamp()),
|
||
(?,\'capitalcity\',6,1,unix_timestamp()),
|
||
(?,\'capitalcity\',6,1,unix_timestamp())',
|
||
[
|
||
'<span style="color: red; font-weight: bold;">Рейтинг кланов ' . date('d-m-Y') . ' </span>',
|
||
sprintf(RATING_MSG, $log_list[0], $prize[1], 1),
|
||
sprintf(RATING_MSG, $log_list[1], $prize[2], 2),
|
||
sprintf(RATING_MSG, $log_list[2], $prize[3], 3),
|
||
]
|
||
);
|
||
|
||
Db::sql('update stats set repexp = 0 where repexp > 0');
|