JoinLiveEnlistJobs.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Jobs\Company\Lottery;
  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\Lottery\LiveEnlist as Model;
  10. use App\Facades\Servers\Logs\Log;
  11. /**
  12. * 参与下单抽奖
  13. *
  14. */
  15. class JoinLiveEnlistJobs 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('join_live_enlist_jobs',$result['error'],$recordData);
  44. return 0;
  45. }
  46. unset($recordData['company_id']);
  47. // 查询
  48. $result = (new Model())->add($recordData);
  49. // 返回结果
  50. if( !$result ) Log::error('join_live_enlist_jobs','写入失败',$recordData);
  51. // 返回结果
  52. return 0;
  53. } catch (\Throwable $th) {
  54. // 返回结果
  55. Log::error('join_live_enlist_jobs',$th->getMessage(),$th);
  56. }
  57. }
  58. public function failed(\Throwable $th)
  59. {
  60. Log::info('join_live_enlist_jobs', '直播参与下单抽奖队列失败', ['data' => $this->recordData, 'error' => $th->getMessage()]);
  61. }
  62. }