2022-12-30 19:03:37 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use Core\Db;
|
|
|
|
|
|
|
|
|
|
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'autoload.php';
|
|
|
|
|
|
|
|
|
|
/**
|
2023-01-10 16:29:32 +00:00
|
|
|
|
* Обновить рейтинг кланов.
|
|
|
|
|
* Раз в день.
|
2022-12-30 19:03:37 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
$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) {
|
2023-01-10 16:29:32 +00:00
|
|
|
|
$add_exp_list[$clan['cid']] = $add_exp; //записываем сколько опыта получил за сегодня
|
|
|
|
|
$all_exp_list[$clan['cid']] = $global_exp + $add_exp; //записываем сколько опыта получил всего + сегодняшний
|
2022-12-30 19:03:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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'),
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-07 10:52:16 +00:00
|
|
|
|
$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-е место в рейтинге!';
|
|
|
|
|
|
2022-12-30 19:03:37 +00:00
|
|
|
|
$stmt = Db::prepare('update clan set money2 = money2 + ? where id = ?');
|
2023-08-07 10:52:16 +00:00
|
|
|
|
$stmt->execute([$prize[1], $keys[0]]);
|
|
|
|
|
$stmt->execute([$prize[2], $keys[1]]);
|
|
|
|
|
$stmt->execute([$prize[3], $keys[2]]);
|
2022-12-30 19:03:37 +00:00
|
|
|
|
|
|
|
|
|
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())',
|
|
|
|
|
[
|
2023-01-10 16:29:32 +00:00
|
|
|
|
'<span style="color: red; font-weight: bold;">Рейтинг кланов ' . date('d-m-Y') . ' </span>',
|
2023-08-07 10:52:16 +00:00
|
|
|
|
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),
|
2022-12-30 19:03:37 +00:00
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Db::sql('update stats set repexp = 0 where repexp > 0');
|