cqpCow hace 11 meses
padre
commit
7b6bb3b996
Se han modificado 2 ficheros con 82 adiciones y 56 borrados
  1. 8 56
      app/Jobs/LabelDealJob.php
  2. 74 0
      app/Service/LabelDealService.php

+ 8 - 56
app/Jobs/LabelDealJob.php

@@ -2,8 +2,8 @@
 
 namespace App\Jobs;
 
-use App\Model\BigKingCbj;
 use App\Service\DwyService;
+use App\Service\LabelDealService;
 use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Foundation\Bus\Dispatchable;
@@ -40,64 +40,16 @@ class LabelDealJob implements ShouldQueue
     public function handle()
     {
         $data = $this->data;
-        if( empty($data['lead_out']) || empty($data['lead_out']['brand_out_stock_list'])) return;
-        $token = $this->header;
         $dv = $data['key'];
-        $box_list = [];
+        $return = $box_list = [];
+        //处理数据
+        LabelDealService::getInstance()->clearData($data,$return,$box_list);
 
-        $return = [];
-        foreach ($data['lead_out']['brand_out_stock_list'] as $value){
-            $tmp = $value['brand_out_stock_dtl'];
-            $return[$value['send_box_code']] = [
-                'fake_qty' => $tmp['fake_qty'],
-                'detail' => explode(',',$tmp['brand_qr_code_list'])
-            ];
-            $box_list[] = $value['send_box_code'];
-        }
-
-        $result = DwyService::getInstance()->setBoxData($token,$dv,$return,$box_list);
-
-        $this->boxOut($data,$token,$result);
-    }
-
-    public function boxOut($data,$token,$result)
-    {
-        //商标绑定
-        $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/1';
-//        $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind';
-        $header = [
-            'Content-Type:application/json',
-            'Authorization: ' . $token,
-        ];
-        $lead_bind = $data['lead_bind'];
-        $return_bind = $this->post_helper($url, json_encode($lead_bind), $header);
-        $return_bind = json_decode($return_bind, true);
-
-        //商标出库
-//        $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind_out_stock';
-        $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/11';
-        $lead_out = $result;
-        $return_out = $this->post_helper($url, json_encode($lead_out), $header);
-        $return_out = json_decode($return_out, true);
-
-        BigKingCbj::where('id',$this->id)->update(['is_successful' => 1]);
-    }
-
-    public function post_helper($url, $data, $header)
-    {
-        $ch = curl_init();
-
-        curl_setopt($ch, CURLOPT_POST, 1);
-        curl_setopt($ch, CURLOPT_URL, $url);
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
-        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
-        if (!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
-        $r = curl_exec($ch);
-        curl_close($ch);
-        return $r;
+        //调用外部方法
+        $result = DwyService::getInstance()->setBoxData($this->header,$dv,$return,$box_list);
 
+        //调用保存接口
+        LabelDealService::getInstance()->boxOut($data,$this->header,$result,$this->id);
     }
 
     protected function echoMessage(OutputInterface $output)

+ 74 - 0
app/Service/LabelDealService.php

@@ -0,0 +1,74 @@
+<?php
+
+namespace App\Service;
+
+
+use App\Model\BigKingCbj;
+
+class LabelDealService extends Service
+{
+    protected static $instance;
+
+    public static function getInstance(): self
+    {
+        if (self::$instance == null) self::$instance = new LabelDealService();
+        return self::$instance;
+    }
+
+    public function clearData($data,&$return,&$box_list){
+        if( empty($data['lead_out']) || empty($data['lead_out']['brand_out_stock_list'])) return;
+
+        foreach ($data['lead_out']['brand_out_stock_list'] as $value){
+            $tmp = $value['brand_out_stock_dtl'];
+            $return[$value['send_box_code']] = [
+                'fake_qty' => $tmp['fake_qty'],
+                'detail' => explode(',',$tmp['brand_qr_code_list'])
+            ];
+            $box_list[] = $value['send_box_code'];
+        }
+    }
+
+    public function boxOut($data,$token,$result,$id)
+    {
+        //商标绑定
+        $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/1';
+//        $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind';
+        $header = [
+            'Content-Type:application/json',
+            'Authorization: ' . $token,
+        ];
+        $lead_bind = $data['lead_bind'];
+        $return_bind = $this->post_helper($url, json_encode($lead_bind), $header);
+        $return_bind = json_decode($return_bind, true);
+
+        //商标出库
+//        $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind_out_stock';
+        $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/11';
+        $lead_out = $result;
+        $return_out = $this->post_helper($url, json_encode($lead_out), $header);
+        $return_out = json_decode($return_out, true);
+
+        BigKingCbj::where('id',$id)->update(['is_successful' => 1]);
+    }
+
+    public function post_helper($url, $data, $auth)
+    {
+        $header = [
+            'Content-Type:application/json',
+            'Authorization: ' . $auth,
+        ];
+        $ch = curl_init();
+
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_URL, $url);
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
+        if (!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
+        $r = curl_exec($ch);
+        curl_close($ch);
+        return $r;
+
+    }
+}