LabelDealService.php 2.7 KB

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