LabelDealService.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. $box_list[] = $value['send_box_code'];
  16. foreach ($value['brand_out_stock_dtl'] as $tmp){
  17. if(! isset($return[$value['send_box_code']])){
  18. $return[$value['send_box_code']] = [
  19. 'fake_qty' => 0,
  20. 'detail' => [],
  21. ];
  22. }
  23. $return[$value['send_box_code']]['fake_qty'] += $tmp['fake_qty'];
  24. $return[$value['send_box_code']]['detail'] = array_merge($return[$value['send_box_code']]['detail'], explode(',',$tmp['brand_qr_code_list']));
  25. }
  26. }
  27. }
  28. public function boxOut($lead_bind,$lead_out,$token,$id)
  29. {
  30. //商标出库
  31. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind_out_stock';
  32. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/11';
  33. $return_out = $this->post_helper($url, json_encode($lead_out), $token);
  34. file_put_contents('msg_result.txt',date('Y-m-d H:i:s') . "出库:" . $return_out. PHP_EOL,8);
  35. $return_out = json_decode($return_out, true);
  36. sleep(3);
  37. //商标绑定
  38. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/1';
  39. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind';
  40. $return_bind = $this->post_helper($url, json_encode($lead_bind), $token);
  41. file_put_contents('msg_result.txt',date('Y-m-d H:i:s') . "绑定:" . $return_bind. PHP_EOL,8);
  42. $return_bind = json_decode($return_bind, true);
  43. 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]);
  44. }
  45. public function post_helper($url, $data, $auth)
  46. {
  47. file_put_contents('msg_result.txt',date('Y-m-d H:i:s') . "请求参数:" . $data . PHP_EOL,8);
  48. $header = [
  49. 'Content-Type:application/json',
  50. 'Authorization: ' . $auth,
  51. ];
  52. $ch = curl_init();
  53. curl_setopt($ch, CURLOPT_POST, 1);
  54. curl_setopt($ch, CURLOPT_URL, $url);
  55. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  56. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  57. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  58. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  59. if (!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  60. $r = curl_exec($ch);
  61. curl_close($ch);
  62. return $r;
  63. }
  64. }