LabelDealJob.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 Illuminate\Support\Facades\Log;
  11. use Symfony\Component\Console\Output\ConsoleOutput;
  12. use Symfony\Component\Console\Output\OutputInterface;
  13. class LabelDealJob implements ShouldQueue
  14. {
  15. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  16. protected $data;
  17. protected $header;
  18. protected $id;
  19. /**
  20. * Create a new job instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct($data,$header,$id)
  25. {
  26. $this->data = $data;
  27. $this->header = $header;
  28. $this->id = $id;
  29. }
  30. public function handle()
  31. {
  32. try {
  33. $data = $this->data;
  34. $dv = $data['key'];
  35. $return = $box_list = [];
  36. Log::channel('apiLog')->info('出库源数据', ["param" => $data]);
  37. //处理数据
  38. LabelDealService::getInstance()->clearData($data,$return,$box_list);
  39. Log::channel('apiLog')->info('出库(清洗数据)', ["param" => $return]);
  40. //调用外部方法
  41. list($lead_bind,$lead_out) = DwyService::getInstance()->setBoxData($this->header,$dv,$return,$box_list,$data);
  42. //删除限制
  43. DwyService::getInstance()->delLimitForBoxOut($lead_bind);
  44. //调用保存接口
  45. LabelDealService::getInstance()->boxOut($lead_bind,$lead_out,$this->header,$this->id);
  46. }catch (\Throwable $exception){
  47. Log::channel('apiLog')->info('队列捕获(出库异常)', ["message" => $exception->getFile() . "|" . $exception->getLine() . "|" . $exception->getMessage(). "|" . $exception->getCode()]);
  48. $this->delete();
  49. }
  50. }
  51. protected function echoMessage(OutputInterface $output)
  52. {
  53. $output->writeln($this->data);
  54. }
  55. }