LabelDealService.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace App\Service;
  3. use App\Model\BigKingCbj;
  4. use Illuminate\Support\Facades\Log;
  5. class LabelDealService extends Service
  6. {
  7. protected static $instance;
  8. public static function getInstance(): self
  9. {
  10. if (self::$instance == null) self::$instance = new LabelDealService();
  11. return self::$instance;
  12. }
  13. public function clearData($data,&$return,&$box_list){
  14. if( empty($data['lead_out']) || empty($data['lead_out']['brand_out_stock_list'])) return;
  15. foreach ($data['lead_out']['brand_out_stock_list'] as $value){
  16. $box_list[] = $value['send_box_code'];
  17. foreach ($value['brand_out_stock_dtl'] as $tmp){
  18. if(! isset($return[$value['send_box_code']])){
  19. $return[$value['send_box_code']] = [
  20. 'fake_qty' => 0,
  21. 'detail' => [],
  22. ];
  23. }
  24. $return[$value['send_box_code']]['fake_qty'] += $tmp['fake_qty'] ?? 0;
  25. $return[$value['send_box_code']]['detail'] = array_merge($return[$value['send_box_code']]['detail'], explode(',',$tmp['brand_qr_code_list']));
  26. }
  27. }
  28. }
  29. public function boxOut($lead_bind,$lead_out,$token,$id)
  30. {
  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, $lead_out, $token);
  35. $return_out = json_decode($return_out, true);
  36. Log::channel('apiLog')->info('商标出库(返回结果)', ["message" => $return_out]);
  37. sleep(3);
  38. //商标绑定
  39. // $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/1';
  40. $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind';
  41. $return_bind = $this->post_helper($url, $lead_bind, $token);
  42. $return_bind = json_decode($return_bind, true);
  43. Log::channel('apiLog')->info('商标绑定(返回结果)', ["message" => $return_bind]);
  44. 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]);
  45. }
  46. public function post_helper($url, $data, $auth)
  47. {
  48. Log::channel('apiLog')->info('商标(请求参数)', ["param" => $data]);
  49. $data = json_encode($data);
  50. $header = [
  51. 'Content-Type:application/json',
  52. 'Authorization: ' . $auth,
  53. ];
  54. $ch = curl_init();
  55. curl_setopt($ch, CURLOPT_POST, 1);
  56. curl_setopt($ch, CURLOPT_URL, $url);
  57. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  58. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  59. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  60. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  61. if (!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  62. $r = curl_exec($ch);
  63. curl_close($ch);
  64. return $r;
  65. }
  66. }