LabelDealService.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Service;
  3. use App\Model\BigKingCbj;
  4. use Illuminate\Support\Facades\Log;
  5. class LabelDealService extends Service
  6. {
  7. protected static $instance;
  8. public static function getInstance(): self
  9. {
  10. if (self::$instance == null) self::$instance = new LabelDealService();
  11. return self::$instance;
  12. }
  13. public function clearData($data,&$return,&$box_list){
  14. if( empty($data['lead_out']) || empty($data['lead_out']['brand_out_stock_list'])) return;
  15. foreach ($data['lead_out']['brand_out_stock_list'] as $value){
  16. $box_list[] = $value['send_box_code'];
  17. foreach ($value['brand_out_stock_dtl'] as $tmp){
  18. if(! isset($return[$value['send_box_code']])){
  19. $return[$value['send_box_code']] = [
  20. 'fake_qty' => 0,
  21. 'detail' => [],
  22. ];
  23. }
  24. $return[$value['send_box_code']]['fake_qty'] += $tmp['fake_qty'] ?? 0;
  25. $return[$value['send_box_code']]['detail'] = array_merge($return[$value['send_box_code']]['detail'], explode(',',$tmp['brand_qr_code_list']));
  26. }
  27. }
  28. }
  29. public function boxOut($lead_bind,$lead_out,$token,$id)
  30. {
  31. //商标出库
  32. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind_out_stock';
  33. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/11';
  34. $return_out = $this->post_helper($url, $lead_out, $token);
  35. $return_out = json_decode($return_out, true);
  36. Log::channel('apiLog')->info('商标出库(返回结果)', ["message" => $return_out]);
  37. sleep(3);
  38. //商标绑定
  39. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/1';
  40. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind';
  41. $return_bind = $this->post_helper($url, $lead_bind, $token);
  42. $return_bind = json_decode($return_bind, true);
  43. Log::channel('apiLog')->info('商标绑定(返回结果)', ["message" => $return_bind]);
  44. if(isset($return_bind['status']) && $return_bind['status'] == 'success' && isset($return_out['status']) && $return_out['status'] == 'success') BigKingCbj::where('id',$id)->update(['is_successful' => 1]);
  45. }
  46. public function boxOut1($lead_bind,$lead_out,$token,$id)
  47. {
  48. //商标出库
  49. $url = 'http://122.112.196.99:7774/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind_out_stock';
  50. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/11';
  51. $return_out = $this->post_helper($url, $lead_out, $token);
  52. $return_out = json_decode($return_out, true);
  53. Log::channel('apiLog')->info('商标出库(返回结果)', ["message" => $return_out]);
  54. sleep(3);
  55. //商标绑定
  56. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/1';
  57. $url = 'http://122.112.196.99:7774/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind';
  58. $return_bind = $this->post_helper($url, $lead_bind, $token);
  59. $return_bind = json_decode($return_bind, true);
  60. Log::channel('apiLog')->info('商标绑定(返回结果)', ["message" => $return_bind]);
  61. if(isset($return_bind['status']) && $return_bind['status'] == 'success' && isset($return_out['status']) && $return_out['status'] == 'success') BigKingCbj::where('id',$id)->update(['is_successful' => 1]);
  62. }
  63. public function post_helper($url, $data, $auth)
  64. {
  65. Log::channel('apiLog')->info('商标(请求参数)', ["param" => $data]);
  66. $data = json_encode($data);
  67. $header = [
  68. 'Content-Type:application/json',
  69. 'Authorization: ' . $auth,
  70. ];
  71. $ch = curl_init();
  72. curl_setopt($ch, CURLOPT_POST, 1);
  73. curl_setopt($ch, CURLOPT_URL, $url);
  74. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  75. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  76. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  77. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  78. if (!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  79. $r = curl_exec($ch);
  80. curl_close($ch);
  81. return $r;
  82. }
  83. }