LabelDealJob.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace App\Jobs;
  3. use App\Model\BigKingCbj;
  4. use App\Service\DwyService;
  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. /**
  30. * Execute the job.
  31. *
  32. * @return void
  33. */
  34. public function handle()
  35. {
  36. $data = $this->data;
  37. if( empty($data['lead_out']) || empty($data['lead_out']['brand_out_stock_list'])) return;
  38. $token = $this->header;
  39. $dv = $data['key'];
  40. $box_list = [];
  41. $return = [];
  42. foreach ($data['lead_out']['brand_out_stock_list'] as $value){
  43. $tmp = $value['brand_out_stock_dtl'];
  44. $return[$value['send_box_code']] = [
  45. 'fake_qty' => $tmp['fake_qty'],
  46. 'detail' => explode(',',$tmp['brand_qr_code_list'])
  47. ];
  48. $box_list[] = $value['send_box_code'];
  49. }
  50. $result = DwyService::getInstance()->setBoxData($token,$dv,$return,$box_list);
  51. $this->boxOut($data,$token,$result);
  52. }
  53. public function boxOut($data,$token,$result)
  54. {
  55. //商标绑定
  56. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/1';
  57. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind';
  58. $header = [
  59. 'Content-Type:application/json',
  60. 'Authorization: ' . $token,
  61. ];
  62. $lead_bind = $data['lead_bind'];
  63. $return_bind = $this->post_helper($url, json_encode($lead_bind), $header);
  64. $return_bind = json_decode($return_bind, true);
  65. //商标出库
  66. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind_out_stock';
  67. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/11';
  68. $lead_out = $result;
  69. $return_out = $this->post_helper($url, json_encode($lead_out), $header);
  70. $return_out = json_decode($return_out, true);
  71. BigKingCbj::where('id',$this->id)->update(['is_successful' => 1]);
  72. }
  73. public function post_helper($url, $data, $header)
  74. {
  75. $ch = curl_init();
  76. curl_setopt($ch, CURLOPT_POST, 1);
  77. curl_setopt($ch, CURLOPT_URL, $url);
  78. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  79. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  80. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  81. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  82. if (!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  83. $r = curl_exec($ch);
  84. curl_close($ch);
  85. return $r;
  86. }
  87. protected function echoMessage(OutputInterface $output)
  88. {
  89. $output->writeln($this->data);
  90. }
  91. }