LabelDealJob.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Jobs;
  3. use App\Service\DwyService;
  4. use App\Service\LabelDealService;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Foundation\Bus\Dispatchable;
  8. use Illuminate\Queue\InteractsWithQueue;
  9. use Illuminate\Queue\SerializesModels;
  10. use Symfony\Component\Console\Output\ConsoleOutput;
  11. use Symfony\Component\Console\Output\OutputInterface;
  12. class LabelDealJob implements ShouldQueue
  13. {
  14. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  15. protected $data;
  16. protected $header;
  17. protected $id;
  18. /**
  19. * Create a new job instance.
  20. *
  21. * @return void
  22. */
  23. public function __construct($data,$header,$id)
  24. {
  25. $this->data = $data;
  26. $this->header = $header;
  27. $this->id = $id;
  28. }
  29. public function handle()
  30. {
  31. try {
  32. $data = $this->data;
  33. $dv = $data['key'];
  34. $return = $box_list = [];
  35. //处理数据
  36. LabelDealService::getInstance()->clearData($data,$return,$box_list);
  37. file_put_contents('msg_result.txt',date('Y-m-d H:i:s') . "清洗数据:" . json_encode($return) . PHP_EOL,8);
  38. //调用外部方法
  39. list($lead_bind,$lead_out) = DwyService::getInstance()->setBoxData($this->header,$dv,$return,$box_list,$data);
  40. //删除限制
  41. DwyService::getInstance()->delLimitForBoxOut($lead_bind);
  42. //调用保存接口
  43. LabelDealService::getInstance()->boxOut($lead_bind,$lead_out,$this->header,$this->id);
  44. }catch (\Throwable $exception){
  45. file_put_contents('msg_result.txt',date('Y-m-d H:i:s') . "队列捕获:" . $exception->getFile() . "|" . $exception->getLine() . "|" . $exception->getMessage(). "|" . $exception->getCode(). PHP_EOL,8);
  46. $this->delete();
  47. }
  48. }
  49. protected function echoMessage(OutputInterface $output)
  50. {
  51. $output->writeln($this->data);
  52. }
  53. }