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;
use App\Models\Order;
use App\Models\User;
use App\Utils\Helper;
use Illuminate\Console\Command;

View File

@ -13,4 +13,8 @@ class ServerLog extends Model
'created_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\Utils\CacheKey;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
class ServerService
{
@ -268,12 +269,18 @@ class ServerService
->where('user_id', $userId)
->where('rate', $rate)
->where('method', $method)
->lockForUpdate()
->first();
if ($serverLog) {
$serverLog->u = $serverLog->u + $u;
$serverLog->d = $serverLog->d + $d;
return $serverLog->save();
try {
$serverLog->update([
'u' => DB::raw("u+{$u}"),
'd' => DB::raw("d+{$d}")
]);
return true;
} catch (\Exception $e) {
info($e);
return false;
}
} else {
$serverLog = new ServerLog();
$serverLog->user_id = $userId;