mirror of
				https://github.com/v2board/v2board.git
				synced 2025-11-04 11:21:46 +08:00 
			
		
		
		
	update: traffic fetch job
This commit is contained in:
		@@ -9,6 +9,7 @@ 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
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -44,13 +45,18 @@ class TrafficFetchJob implements ShouldQueue
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function handle()
 | 
					    public function handle()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $user = User::lockForUpdate()->find($this->userId);
 | 
					        $user = User::find($this->userId);
 | 
				
			||||||
        if (!$user) return;
 | 
					        if (!$user) return;
 | 
				
			||||||
        $user->t = time();
 | 
					        try {
 | 
				
			||||||
        $user->u = $user->u + $this->u;
 | 
					            $user->update([
 | 
				
			||||||
        $user->d = $user->d + $this->d;
 | 
					                't' => time(),
 | 
				
			||||||
        if (!$user->save()) throw new \Exception('流量更新失败');
 | 
					                'u' => DB::raw("u+{$this->u}"),
 | 
				
			||||||
 | 
					                'd' => DB::raw("d+{$this->d}")
 | 
				
			||||||
 | 
					            ]);
 | 
				
			||||||
 | 
					        } catch (\Exception $e) {
 | 
				
			||||||
 | 
					            throw new \Exception('流量更新失败');
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        $mailService = new MailService();
 | 
					        $mailService = new MailService();
 | 
				
			||||||
        $mailService->remindTraffic($user);
 | 
					        $mailService->remindTraffic($user->first());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,4 +13,9 @@ class User extends Model
 | 
				
			|||||||
        'created_at' => 'timestamp',
 | 
					        'created_at' => 'timestamp',
 | 
				
			||||||
        'updated_at' => 'timestamp'
 | 
					        'updated_at' => 'timestamp'
 | 
				
			||||||
    ];
 | 
					    ];
 | 
				
			||||||
 | 
					    protected $fillable = [
 | 
				
			||||||
 | 
					        'u',
 | 
				
			||||||
 | 
					        'd',
 | 
				
			||||||
 | 
					        't'
 | 
				
			||||||
 | 
					    ];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user