LabelDealJob.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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[] = [
  45. 'box_code' => $value['send_box_code'],
  46. 'fake_qty' => $tmp['fake_qty'],
  47. 'detail' => explode(',',$tmp['brand_qr_code_list'])
  48. ];
  49. $box_list[] = $value['send_box_code'];
  50. }
  51. $result = DwyService::getInstance()->setBoxData($token,$dv,$return,$box_list);
  52. $this->boxOut($data,$token,$result);
  53. }
  54. public function boxOut($data,$token,$result)
  55. {
  56. //商标绑定
  57. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/1';
  58. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind';
  59. $header = [
  60. 'Content-Type:application/json',
  61. 'Authorization: ' . $token,
  62. ];
  63. $lead_bind = $data['lead_bind'];
  64. $return_bind = $this->post_helper($url, json_encode($lead_bind), $header);
  65. $return_bind = json_decode($return_bind, true);
  66. //商标出库
  67. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind_out_stock';
  68. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/11';
  69. $lead_out = $result;
  70. $return_out = $this->post_helper($url, json_encode($lead_out), $header);
  71. $return_out = json_decode($return_out, true);
  72. BigKingCbj::where('id',$this->id)->update(['is_successful' => 1]);
  73. }
  74. public function post_helper($url, $data, $header)
  75. {
  76. $ch = curl_init();
  77. curl_setopt($ch, CURLOPT_POST, 1);
  78. curl_setopt($ch, CURLOPT_URL, $url);
  79. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  80. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  81. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  82. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  83. if (!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  84. $r = curl_exec($ch);
  85. curl_close($ch);
  86. return $r;
  87. }
  88. protected function echoMessage(OutputInterface $output)
  89. {
  90. $output->writeln($this->data);
  91. }
  92. }