This commit is contained in:
Tokumeikoi 2020-05-11 17:19:58 +08:00
parent 9158697546
commit f7959dcd93
4 changed files with 27 additions and 7 deletions

View File

@ -3,6 +3,7 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class ServerLog extends Model class ServerLog extends Model
{ {

View File

@ -138,12 +138,27 @@ class ServerService
public function log(int $userId, int $serverId, int $u, int $d, float $rate) public function log(int $userId, int $serverId, int $u, int $d, float $rate)
{ {
if (($u + $d) <= 10240) return;
$timestamp = strtotime(date('Y-m-d H:0'));
$serverLog = ServerLog::where('log_at', '>=', $timestamp)
->where('log_at', '<', $timestamp + 3600)
->where('server_id', $serverId)
->where('user_id', $userId)
->where('rate', $rate)
->first();
if ($serverLog) {
$serverLog->u = $serverLog->u + $u;
$serverLog->d = $serverLog->d + $u;
$serverLog->save();
} else {
$serverLog = new ServerLog(); $serverLog = new ServerLog();
$serverLog->user_id = $userId; $serverLog->user_id = $userId;
$serverLog->server_id = $serverId; $serverLog->server_id = $serverId;
$serverLog->u = $u; $serverLog->u = $u;
$serverLog->d = $d; $serverLog->d = $d;
$serverLog->rate = $rate; $serverLog->rate = $rate;
$serverLog->log_at = $timestamp;
$serverLog->save(); $serverLog->save();
} }
} }
}

View File

@ -165,6 +165,7 @@ CREATE TABLE `v2_server_log` (
`u` varchar(255) NOT NULL, `u` varchar(255) NOT NULL,
`d` varchar(255) NOT NULL, `d` varchar(255) NOT NULL,
`rate` decimal(10,2) NOT NULL, `rate` decimal(10,2) NOT NULL,
`log_at` int(11) NOT NULL,
`created_at` int(11) NOT NULL, `created_at` int(11) NOT NULL,
`updated_at` int(11) NOT NULL, `updated_at` int(11) NOT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)

View File

@ -238,3 +238,6 @@ ADD `reset_price` int(11) NULL AFTER `onetime_price`;
ALTER TABLE `v2_server_log` ALTER TABLE `v2_server_log`
ADD `id` bigint NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST; ADD `id` bigint NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;
ALTER TABLE `v2_server_log`
ADD `log_at` int(11) NOT NULL AFTER `rate`;