LabelDealService.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. 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]);
  38. }
  39. public function post_helper($url, $data, $auth)
  40. {
  41. file_put_contents('msg_result.txt',date('Y-m-d H:i:s') . "请求参数:" . $data . PHP_EOL,8);
  42. $header = [
  43. 'Content-Type:application/json',
  44. 'Authorization: ' . $auth,
  45. ];
  46. $ch = curl_init();
  47. curl_setopt($ch, CURLOPT_POST, 1);
  48. curl_setopt($ch, CURLOPT_URL, $url);
  49. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  50. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  51. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  52. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  53. if (!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  54. $r = curl_exec($ch);
  55. curl_close($ch);
  56. return $r;
  57. }
  58. }