JoinLuckyBagJobs.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Jobs\Company\LiveLuckyBag;
  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\LiveLuckyBagParticipate as Model;
  10. use App\Facades\Servers\Logs\Log;
  11. /**
  12. * 参与福袋队列
  13. *
  14. */
  15. class JoinLuckyBagJobs implements ShouldQueue
  16. {
  17. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  18. protected $recordDatas;
  19. /**
  20. * Create a new job instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct(array $recordDatas)
  25. {
  26. $this->recordDatas = $recordDatas;
  27. }
  28. /**
  29. * Execute the job.
  30. *
  31. * @return void
  32. */
  33. public function handle()
  34. {
  35. try {
  36. // 接收参数
  37. $recordData = $this->recordDatas;
  38. // 切换数据
  39. $result = (new DbService())->getConnectionNameByCompanyId($recordData['company_id']);
  40. // 错误提示
  41. if( isset($result['error']) ) {
  42. // 返回结果
  43. Log::error('join_lucky_bag_jobs',$result['error'],$recordData);
  44. return 0;
  45. }
  46. // 查询
  47. $result = (new Model())->add($recordData);
  48. // 返回结果
  49. if( !$result ) Log::error('join_lucky_bag_jobs','写入失败',$recordData);
  50. // 返回结果
  51. return 0;
  52. } catch (\Throwable $th) {
  53. // 返回结果
  54. Log::error('join_lucky_bag_jobs',$th->getMessage(),$th);
  55. }
  56. }
  57. public function failed(\Throwable $th)
  58. {
  59. Log::info('join_lucky_bag_jobs', '直播参与福袋队列失败', ['data' => $this->recordDatas, 'error' => $th->getMessage()]);
  60. }
  61. }