game/_incl_data/crons/rating_pers.php
2022-12-30 21:03:50 +02:00

134 lines
3.7 KiB
PHP

<?php
use Core\Db;
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'autoload.php';
/**
* Îáíîâèòü ðåéòèíã èãðîêîâ.
* Ðàç â äåíü.
*/
//Ðåéòèíã ïî âêëàäàì
$ub = [];
$ui = [];
$payOperations = Db::getRows('select * from pay_operation where good > 0 order by id desc');
foreach ($payOperations as $operation) {
if (!isset($ub[$operation['uid']])) {
$ui[] = $operation['uid'];
}
$ub[$operation['uid']][date('d.m.Y', $operation['good'])] = $operation['ekr'];
}
// ×ÒÎ ÒÛ ÁËßÒÜ ÒÀÊÎÅ?!
foreach ($ui as $item) {
if (!$item) {
continue;
}
$k = 0;
$nj = 0;
for ($i = 0; $i <= 1000; $i++) {
$date = date('d.m.Y', time() - (86400 * $i));
if (isset($ub[$item][$date])) {
$k++;
$nj = 0;
} elseif ($i > 0 && $nj >= 6) {
$j = 1000;
} else {
$nj++;
}
}
Db::sql('replace into users_paybonus (id, level) values (?,?)', [$item, $k]);
}
$log_list = [];
$add_exp_list = [];
$all_exp_list = [];
$exp_list = [];
$win_list = [];
$global_exp = 0;
Db::sql('delete from aaa_reting_list where date = ?', [date('dmY')]);
$users = Db::getRows(
'
select
stats.id,
login,
users.win as uwin,
stats.exp as sexp,
repexp,
aaa_reting_list.exp as aexp,
global,
exp_real
from users
left join stats on stats.id = users.id
left join aaa_reting_list on users.id = uid
where `real` = 1 and admin = 0 and bot = 0
'
);
foreach ($users as $user) {
$exp_list[$user['id']] = $user['sexp'];
$win_list[$user['id']] = $user['uwin'];
$log_list[$user['id']] = $user['login'];
$add_exp = $user['sexp'];
if (idate('d') !== 1) { //çíà÷åíèå ðåéòèíãà îáíóëÿåòñÿ 1ãî ÷èñëà
$global_exp = round($user['global']);
}
$global_exp = $global_exp + round($user['repexp']);
$add_exp_list[$user['id']] = $add_exp; //çàïèñûâàåì ñêîëüêî îïûòà ïîëó÷èë çà ñåãîäíÿ
$all_exp_list[$user['id']] = $global_exp;// + $add_exp; //çàïèñûâàåì ñêîëüêî îïûòà ïîëó÷èë âñåãî + ñåãîäíÿøíèé
}
arsort($all_exp_list);
$keys = array_keys($all_exp_list);
$i = 0;
foreach ($keys as $key) {
if (!$key) {
continue;
}
$i++;
Db::sql(
'insert into aaa_reting_list (uid, pos, global, exp, exp_real, date, time, win) values (?,?,?,?,?,?,unix_timestamp(),?)',
[
$key,
$i,
$all_exp_list[$key],
$add_exp_list[$key],
$exp_list[$key],
date('dmY'),
$win_list[$key],
]
);
}
$stmt = Db::prepare('update users set money2 = money2 + ? where id = ?');
$stmt->execute([1, $keys[0]]);
$stmt->execute([0.75, $keys[1]]);
$stmt->execute([0.5, $keys[2]]);
$stmt->execute([0.25, $keys[3]]);
$stmt->execute([0.15, $keys[4]]);
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()),
(?,\'capitalcity\',6,1,unix_timestamp()),
(?,\'capitalcity\',6,1,unix_timestamp())',
[
'<span style="color: red; font-weight: bold;">Ðåéòèíã èãðîêîâ ' . date('d-m-Y') . ' </span>',
'Èãðîê ' . $log_list[0] . ' ïîëó÷àåò 1 Åêð. çà 1-å ìåñòî â ðåéòèíãå!',
'Èãðîê ' . $log_list[1] . ' ïîëó÷àåò 0.75 Åêð. çà 2-å ìåñòî â ðåéòèíãå!',
'Èãðîê ' . $log_list[2] . ' ïîëó÷àåò 0.5 Åêð. çà 3-å ìåñòî â ðåéòèíãå!',
'Èãðîê ' . $log_list[3] . ' ïîëó÷àåò 0.25 Åêð. çà 4-å ìåñòî â ðåéòèíãå!',
'Èãðîê ' . $log_list[4] . ' ïîëó÷àåò 0.15 Åêð. çà 5-å ìåñòî â ðåéòèíãå!',
]
);