1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Minepic\Models; |
6
|
|
|
|
7
|
|
|
use Barryvdh\LaravelIdeHelper\Eloquent; |
8
|
|
|
use Illuminate\Database\Eloquent\Model; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class AccountsStats. |
12
|
|
|
* |
13
|
|
|
* @property string $uuid |
14
|
|
|
* @property int $count_request |
15
|
|
|
* @property null|\Carbon\Carbon $request_at |
16
|
|
|
* |
17
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|AccountStats newModelQuery() |
18
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|AccountStats newQuery() |
19
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|AccountStats query() |
20
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Account whereUuid($value) |
21
|
|
|
* @mixin Eloquent |
22
|
|
|
*/ |
23
|
|
|
class AccountStats extends Model |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* No primary key. |
27
|
|
|
*/ |
28
|
|
|
public $incrementing = false; |
29
|
|
|
|
30
|
|
|
public $timestamps = false; |
31
|
|
|
|
32
|
|
|
public $dates = [ |
33
|
|
|
'request_at', |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
public $casts = [ |
37
|
|
|
'uuid' => 'string', |
38
|
|
|
'count_request' => 'int', |
39
|
|
|
'request_at' => 'datetime', |
40
|
|
|
]; |
41
|
|
|
/** |
42
|
|
|
* Table name. |
43
|
|
|
* |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
protected $table = 'accounts_stats'; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Primary key. |
50
|
|
|
* |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
protected $primaryKey = 'uuid'; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var array<string> |
57
|
|
|
*/ |
58
|
|
|
protected $fillable = [ |
59
|
|
|
'uuid', |
60
|
|
|
'count_request', |
61
|
|
|
'request_at', |
62
|
|
|
]; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get most wanted users. |
66
|
|
|
*/ |
67
|
|
|
public static function getMostWanted(int $limit = 14): array |
68
|
|
|
{ |
69
|
|
|
return \DB::select( |
70
|
|
|
"SELECT a.`uuid`, a.`username`, s.`count_request` |
71
|
|
|
FROM ( |
72
|
|
|
SELECT `uuid`, `count_request` FROM `accounts_stats` |
73
|
|
|
ORDER BY `count_request` DESC |
74
|
|
|
LIMIT {$limit} |
75
|
|
|
) s |
76
|
|
|
INNER JOIN `accounts` AS a USING(`uuid`) |
77
|
|
|
ORDER BY s.`count_request` DESC" |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Get last users. |
83
|
|
|
*/ |
84
|
|
|
public static function getLastUsers(int $limit = 9): array |
85
|
|
|
{ |
86
|
|
|
return \DB::select( |
87
|
|
|
"SELECT a.`uuid`, a.`username`, s.`count_request` |
88
|
|
|
FROM ( |
89
|
|
|
SELECT `uuid`, `count_request` FROM `accounts_stats` |
90
|
|
|
ORDER BY `request_at` DESC |
91
|
|
|
LIMIT {$limit} |
92
|
|
|
) s |
93
|
|
|
INNER JOIN `accounts` a USING(`uuid`) |
94
|
|
|
ORDER BY s.`count_request` DESC" |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|