This repository was archived by the owner on Jun 4, 2025. It is now read-only.
forked from kbs1/openxdagpool
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathUser.php
More file actions
executable file
·123 lines (98 loc) · 3.79 KB
/
Copy pathUser.php
File metadata and controls
executable file
·123 lines (98 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
namespace App\Users;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Miners\Miner;
use App\Payouts\Payout;
use Carbon\Carbon;
use Auth;
class User extends Authenticatable
{
use Notifiable;
use \App\Support\HasUuid;
protected $fillable = ['nick', 'email', 'password'];
protected $hidden = ['password', 'remember_token'];
protected $dates = ['created_at', 'updated_at', 'last_seen_at'];
/* relations */
public function miners()
{
return $this->hasMany(Miner::class);
}
/* attributes */
public function getDisplayNickAttribute()
{
if (!$this->anonymous_profile)
return $this->nick;
$user = Auth::user();
if ($user && ($user->isAdministrator() || $user->id === $this->id))
return $this->nick;
return 'anonymous';
}
/* methods */
public function isActive()
{
return $this->active;
}
public function isAdministrator()
{
return $this->administrator;
}
public function getPayoutsListingNonPaged()
{
$addresses = $this->miners->pluck('address');
return Payout::whereIn('recipient', $addresses ?: ['none'])->orderBy('made_at', 'asc')->orderBy('id', 'asc')->get();
}
public function getPayoutsListing($page = null)
{
$addresses = $this->miners->pluck('address');
$query = Payout::whereIn('recipient', $addresses ?: ['none'])->orderBy('made_at', 'asc')->orderBy('id', 'asc');
if (!$page) {
$count = clone $query;
return $query->paginate(500, ['*'], 'page', ceil($count->count('*') / 500));
}
return $query->paginate(500);
}
public function getPayoutsSum()
{
$addresses = $this->miners->pluck('address');
return Payout::whereIn('recipient', $addresses ?: ['none'])->sum('amount');
}
public function getPayoutsCount()
{
$addresses = $this->miners->pluck('address');
return Payout::whereIn('recipient', $addresses ?: ['none'])->count();
}
public function getDailyPayouts()
{
$addresses = $this->miners->pluck('address');
return Payout::selectRaw('sum(amount) total, DATE_FORMAT(made_at, "%Y-%m-%d") date')->whereIn('recipient', $addresses ?: ['none'])->groupBy('date')->orderBy('date')->get();
}
public function exportPayoutsToCsv($filename)
{
$addresses = $this->miners->pluck('address');
$in_clause = array_fill(0, count($addresses), '?');
return \DB::statement('SELECT "_Date and time" made_at, "Sender" sender, "Recipient" recipient, "Amount" amount
UNION ALL SELECT CONCAT(p.made_at, ".", LPAD(p.made_at_milliseconds, 3, "0")) made_at, b.address sender, p.recipient, p.amount FROM payouts p
LEFT JOIN found_blocks b ON p.found_block_id = b.id WHERE p.recipient IN (' . implode(', ', $in_clause) . ')
ORDER BY made_at ASC, p.id ASC
INTO OUTFILE ' . \DB::getPdo()->quote($filename) . ' FIELDS TERMINATED BY "," ENCLOSED BY \'"\' LINES TERMINATED BY "\n"', $addresses->toArray());
}
public function getHashrateSum()
{
return $this->miners()->sum('hashrate');
}
public function getAverageHashrateSum()
{
return $this->miners()->sum('average_hashrate');
}
public function getDailyHashrate()
{
$miner_ids = $this->miners->pluck('id');
return \DB::select('select sum(hashrate) hashrate, date from (select avg(hashrate) hashrate, DATE_FORMAT(created_at, "%Y-%m-%d") date from miner_stats where miner_id in (' . implode(', ', $miner_ids->count() ? $miner_ids->toArray() : [0]) . ') group by miner_id, date order by date) ums group by date');
}
public function getLatestHashrate()
{
$miner_ids = $this->miners->pluck('id');
return \DB::select('select sum(hashrate) hashrate, date from (select avg(hashrate) hashrate, DATE_FORMAT(created_at, "%Y-%m-%d %H:00") date from miner_stats where created_at >= NOW() - INTERVAL 3 DAY and miner_id in (' . implode(', ', $miner_ids->count() ? $miner_ids->toArray() : [0]) . ') group by miner_id, date order by date) ums group by date');
}
}