LabelDealService.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Service;
  3. use App\Model\BigKingCbj;
  4. class LabelDealService extends Service
  5. {
  6. protected static $instance;
  7. public static function getInstance(): self
  8. {
  9. if (self::$instance == null) self::$instance = new LabelDealService();
  10. return self::$instance;
  11. }
  12. public function clearData($data,&$return,&$box_list){
  13. if( empty($data['lead_out']) || empty($data['lead_out']['brand_out_stock_list'])) return;
  14. foreach ($data['lead_out']['brand_out_stock_list'] as $value){
  15. $tmp = $value['brand_out_stock_dtl'];
  16. $return[$value['send_box_code']] = [
  17. 'fake_qty' => $tmp['fake_qty'],
  18. 'detail' => explode(',',$tmp['brand_qr_code_list'])
  19. ];
  20. $box_list[] = $value['send_box_code'];
  21. }
  22. }
  23. public function boxOut($data,$token,$result,$id)
  24. {
  25. //商标绑定
  26. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/1';
  27. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind';
  28. $header = [
  29. 'Content-Type:application/json',
  30. 'Authorization: ' . $token,
  31. ];
  32. $lead_bind = $data['lead_bind'];
  33. $return_bind = $this->post_helper($url, json_encode($lead_bind), $header);
  34. $return_bind = json_decode($return_bind, true);
  35. //商标出库
  36. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind_out_stock';
  37. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/11';
  38. $lead_out = $result;
  39. $return_out = $this->post_helper($url, json_encode($lead_out), $header);
  40. $return_out = json_decode($return_out, true);
  41. BigKingCbj::where('id',$id)->update(['is_successful' => 1]);
  42. }
  43. public function post_helper($url, $data, $auth)
  44. {
  45. $header = [
  46. 'Content-Type:application/json',
  47. 'Authorization: ' . $auth,
  48. ];
  49. $ch = curl_init();
  50. curl_setopt($ch, CURLOPT_POST, 1);
  51. curl_setopt($ch, CURLOPT_URL, $url);
  52. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  53. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  54. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  55. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  56. if (!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  57. $r = curl_exec($ch);
  58. curl_close($ch);
  59. return $r;
  60. }
  61. }