update: server log fetch

This commit is contained in:
tokumeikoi 2021-09-02 18:42:36 +09:00
parent 91418caf04
commit 0c14652ff7
3 changed files with 16 additions and 4 deletions

View File

@ -3,6 +3,7 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Models\Order; use App\Models\Order;
use App\Models\User;
use App\Utils\Helper; use App\Utils\Helper;
use Illuminate\Console\Command; use Illuminate\Console\Command;

View File

@ -13,4 +13,8 @@ class ServerLog extends Model
'created_at' => 'timestamp', 'created_at' => 'timestamp',
'updated_at' => 'timestamp' 'updated_at' => 'timestamp'
]; ];
protected $fillable = [
'u',
'd'
];
} }

View File

@ -9,6 +9,7 @@ use App\Models\Server;
use App\Models\ServerTrojan; use App\Models\ServerTrojan;
use App\Utils\CacheKey; use App\Utils\CacheKey;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
class ServerService class ServerService
{ {
@ -268,12 +269,18 @@ class ServerService
->where('user_id', $userId) ->where('user_id', $userId)
->where('rate', $rate) ->where('rate', $rate)
->where('method', $method) ->where('method', $method)
->lockForUpdate()
->first(); ->first();
if ($serverLog) { if ($serverLog) {
$serverLog->u = $serverLog->u + $u; try {
$serverLog->d = $serverLog->d + $d; $serverLog->update([
return $serverLog->save(); 'u' => DB::raw("u+{$u}"),
'd' => DB::raw("d+{$d}")
]);
return true;
} catch (\Exception $e) {
info($e);
return false;
}
} else { } else {
$serverLog = new ServerLog(); $serverLog = new ServerLog();
$serverLog->user_id = $userId; $serverLog->user_id = $userId;