mirror of
https://github.com/v2board/v2board.git
synced 2025-01-25 15:39:10 +08:00
update: traffic fetch job
This commit is contained in:
parent
0c14652ff7
commit
decbae1413
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -13,4 +13,9 @@ class User extends Model
|
||||
'created_at' => 'timestamp',
|
||||
'updated_at' => 'timestamp'
|
||||
];
|
||||
protected $fillable = [
|
||||
'u',
|
||||
'd',
|
||||
't'
|
||||
];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user