diff --git a/app/Jobs/TrafficFetchJob.php b/app/Jobs/TrafficFetchJob.php index 96af6fa9..0da5f375 100644 --- a/app/Jobs/TrafficFetchJob.php +++ b/app/Jobs/TrafficFetchJob.php @@ -9,6 +9,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; +use Illuminate\Support\Facades\DB; class TrafficFetchJob implements ShouldQueue { @@ -44,13 +45,18 @@ class TrafficFetchJob implements ShouldQueue */ public function handle() { - $user = User::lockForUpdate()->find($this->userId); + $user = User::find($this->userId); if (!$user) return; - $user->t = time(); - $user->u = $user->u + $this->u; - $user->d = $user->d + $this->d; - if (!$user->save()) throw new \Exception('流量更新失败'); + try { + $user->update([ + 't' => time(), + 'u' => DB::raw("u+{$this->u}"), + 'd' => DB::raw("d+{$this->d}") + ]); + } catch (\Exception $e) { + throw new \Exception('流量更新失败'); + } $mailService = new MailService(); - $mailService->remindTraffic($user); + $mailService->remindTraffic($user->first()); } } diff --git a/app/Models/User.php b/app/Models/User.php index 01c3eb51..219c9efc 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -13,4 +13,9 @@ class User extends Model 'created_at' => 'timestamp', 'updated_at' => 'timestamp' ]; + protected $fillable = [ + 'u', + 'd', + 't' + ]; }