mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 09:21:46 +08:00 
			
		
		
		
	update: rollback
This commit is contained in:
		| @@ -9,7 +9,6 @@ use Illuminate\Contracts\Queue\ShouldQueue; | |||||||
| use Illuminate\Foundation\Bus\Dispatchable; | use Illuminate\Foundation\Bus\Dispatchable; | ||||||
| use Illuminate\Queue\InteractsWithQueue; | use Illuminate\Queue\InteractsWithQueue; | ||||||
| use Illuminate\Queue\SerializesModels; | use Illuminate\Queue\SerializesModels; | ||||||
| use Illuminate\Support\Facades\DB; |  | ||||||
|  |  | ||||||
| class TrafficFetchJob implements ShouldQueue | class TrafficFetchJob implements ShouldQueue | ||||||
| { | { | ||||||
| @@ -45,18 +44,14 @@ class TrafficFetchJob implements ShouldQueue | |||||||
|      */ |      */ | ||||||
|     public function handle() |     public function handle() | ||||||
|     { |     { | ||||||
|         $user = User::find($this->userId); |         $user = User::lockForUpdate()->find($this->userId); | ||||||
|         if (!$user) return; |         if (!$user) return; | ||||||
|         try { |          | ||||||
|             $user->update([ |         $user->t = time(); | ||||||
|                 't' => time(), |         $user->u = $user->u + $this->u; | ||||||
|                 'u' => DB::raw("u+{$this->u}"), |         $user->d = $user->d + $this->d; | ||||||
|                 'd' => DB::raw("d+{$this->d}") |         if (!$user->save()) throw new \Exception('流量更新失败'); | ||||||
|             ]); |  | ||||||
|         } catch (\Exception $e) { |  | ||||||
|             throw new \Exception('流量更新失败'); |  | ||||||
|         } |  | ||||||
|         $mailService = new MailService(); |         $mailService = new MailService(); | ||||||
|         $mailService->remindTraffic($user->first()); |         $mailService->remindTraffic($user); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -13,8 +13,4 @@ class ServerLog extends Model | |||||||
|         'created_at' => 'timestamp', |         'created_at' => 'timestamp', | ||||||
|         'updated_at' => 'timestamp' |         'updated_at' => 'timestamp' | ||||||
|     ]; |     ]; | ||||||
|     protected $fillable = [ |  | ||||||
|         'u', |  | ||||||
|         'd' |  | ||||||
|     ]; |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -13,9 +13,4 @@ class User extends Model | |||||||
|         'created_at' => 'timestamp', |         'created_at' => 'timestamp', | ||||||
|         'updated_at' => 'timestamp' |         'updated_at' => 'timestamp' | ||||||
|     ]; |     ]; | ||||||
|     protected $fillable = [ |  | ||||||
|         'u', |  | ||||||
|         'd', |  | ||||||
|         't' |  | ||||||
|     ]; |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -9,7 +9,6 @@ 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 | ||||||
| { | { | ||||||
| @@ -269,18 +268,12 @@ 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) { | ||||||
|             try { |             $serverLog->u = $serverLog->u + $u; | ||||||
|                 $serverLog->update([ |             $serverLog->d = $serverLog->d + $d; | ||||||
|                     'u' => DB::raw("u+{$u}"), |             return $serverLog->save(); | ||||||
|                     '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; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user