LiveOnlinePeopleJobs.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Jobs\ReportStatistics\Reception;
  3. use App\Servers\DB\DbService;
  4. use Illuminate\Bus\Queueable;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Foundation\Bus\Dispatchable;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Queue\SerializesModels;
  9. use App\Models\Manager\LiveOnlinePeople as Model;
  10. use App\Facades\Servers\Logs\Log;
  11. /**
  12. * 数据上报任务
  13. *
  14. */
  15. class LiveOnlinePeopleJobs implements ShouldQueue
  16. {
  17. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  18. protected $recordData;
  19. /**
  20. * Create a new job instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct(array $recordData)
  25. {
  26. $this->recordData = $recordData;
  27. }
  28. /**
  29. * Execute the job.
  30. *
  31. * @return void
  32. */
  33. public function handle()
  34. {
  35. try {
  36. // 接收参数
  37. $recordData = $this->recordData;
  38. // 切换数据
  39. $result = (new DbService())->getConnectionNameByCompanyId($recordData['company_id']);
  40. // 错误提示
  41. if( isset($result['error']) ) {
  42. // 返回结果
  43. Log::error('live_online_people_jobs',$result['error'],$recordData);
  44. return 0;
  45. }
  46. // 查询
  47. $result = (new Model())::query()->upsert($recordData,'id');
  48. // 返回结果
  49. if( !$result ) Log::error('live_online_people_jobs','写入失败',$recordData);
  50. // 返回结果
  51. return 0;
  52. } catch (\Throwable $th) {
  53. // 返回结果
  54. Log::error('live_online_people_jobs',$th->getMessage(),$recordData);
  55. // 返回结果
  56. return 0;
  57. }
  58. }
  59. }