LabelDealService.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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'][0] ?? [];
  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($lead_bind,$lead_out,$token,$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. $return_bind = $this->post_helper($url, json_encode($lead_bind), $token);
  29. file_put_contents('msg_result.txt',date('Y-m-d H:i:s') . "绑定:" . $return_bind. PHP_EOL,8);
  30. $return_bind = json_decode($return_bind, true);
  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, json_encode($lead_out), $token);
  35. file_put_contents('msg_result.txt',date('Y-m-d H:i:s') . "出库:" . $return_out. PHP_EOL,8);
  36. $return_out = json_decode($return_out, true);
  37. //toDo
  38. BigKingCbj::where('id',$id)->update(['is_successful' => 1]);
  39. }
  40. public function post_helper($url, $data, $auth)
  41. {
  42. file_put_contents('msg_result.txt',date('Y-m-d H:i:s') . "请求参数:" . $data . PHP_EOL,8);
  43. $header = [
  44. 'Content-Type:application/json',
  45. 'Authorization: ' . $auth,
  46. ];
  47. $ch = curl_init();
  48. curl_setopt($ch, CURLOPT_POST, 1);
  49. curl_setopt($ch, CURLOPT_URL, $url);
  50. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  51. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  52. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  53. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  54. if (!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  55. $r = curl_exec($ch);
  56. curl_close($ch);
  57. return $r;
  58. }
  59. }