game/_incl_data/crons/rating_pers.php
2023-08-08 17:42:05 +03:00

136 lines
3.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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],
]
);
}
const PRIZE_MSG = 'Игрок %s получает %s екр. за %s-е место в рейтинге!';
$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>',
sprintf(PRIZE_MSG, $log_list[0], 1, 1),
sprintf(PRIZE_MSG, $log_list[1], 0.75, 2),
sprintf(PRIZE_MSG, $log_list[2], 0.5, 3),
sprintf(PRIZE_MSG, $log_list[3], 0.25, 4),
sprintf(PRIZE_MSG, $log_list[4], 0.15, 5),
]
);