game/_incl_data/crons/rating_clans.php

127 lines
3.6 KiB
PHP
Raw Normal View History

2022-12-30 19:03:37 +00:00
<?php
use Core\Db;
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'autoload.php';
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
* <EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
*/
$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; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
$all_exp_list[$clan['cid']] = $global_exp + $add_exp; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> + <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}
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'),
]
);
}
$stmt = Db::prepare('update clan set money2 = money2 + ? where id = ?');
$stmt->execute([$xu_list[0] * 0.3, $keys[0]]);
$stmt->execute([$xu_list[1] * 0.2, $keys[1]]);
$stmt->execute([$xu_list[2] * 0.1, $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;"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ' . date('d-m-Y') . ' </span>',
'<27><><EFBFBD><EFBFBD> ' . $log_list[0] . ' <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ' . $xu_list[0] * 0.3 . ' <20><><EFBFBD>. <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> 1-<2D> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!',
'<27><><EFBFBD><EFBFBD> ' . $log_list[1] . ' <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ' . $xu_list[1] * 0.2 . ' <20><><EFBFBD>. <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> 2-<2D> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!',
'<27><><EFBFBD><EFBFBD> ' . $log_list[2] . ' <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ' . $xu_list[2] * 0.1 . ' <20><><EFBFBD>. <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> 3-<2D> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!',
]
);
Db::sql('update stats set repexp = 0 where repexp > 0');