瀏覽代碼

Merge remote-tracking branch 'origin/master'

gogs 11 月之前
父節點
當前提交
eab5acadfe
共有 4 個文件被更改,包括 36 次插入34 次删除
  1. 8 2
      app/Http/Controllers/Api/JobController.php
  2. 16 16
      app/Jobs/LabelDealJob.php
  3. 10 14
      app/Service/LabelDealService.php
  4. 2 2
      routes/api.php

+ 8 - 2
app/Http/Controllers/Api/JobController.php

@@ -41,10 +41,16 @@ class JobController extends BaseController
     }
 
     public function labelDeal(Request $request){
-        $id = BigKingCbj::insert(['data'=> json_encode($request->all()), 'crt_time' => time()]);
+        //记录数据
+        $model = new BigKingCbj();
+        $model->data = json_encode($request->all());
+        $model->crt_time = time();
+        $model->save();
+        $id = $model->id;
+
         $header = $request->header('Authorization');
         dispatch(new LabelDealJob($request->all(), $header, $id))->onQueue('label_deal');
 
-        echo 'ok';die;
+        return ['status'=>200,'msg'=>'success'];
     }
 }

+ 16 - 16
app/Jobs/LabelDealJob.php

@@ -32,24 +32,24 @@ class LabelDealJob implements ShouldQueue
         $this->id = $id;
     }
 
-    /**
-     * Execute the job.
-     *
-     * @return void
-     */
     public function handle()
     {
-        $data = $this->data;
-        $dv = $data['key'];
-        $return = $box_list = [];
-        //处理数据
-        LabelDealService::getInstance()->clearData($data,$return,$box_list);
-
-        //调用外部方法
-        list($lead_bind,$lead_out) = DwyService::getInstance()->setBoxData($this->header,$dv,$return,$box_list,$data);
-
-        //调用保存接口
-        LabelDealService::getInstance()->boxOut($lead_bind,$lead_out,$this->header,$this->id);
+        try {
+            $data = $this->data;
+            $dv = $data['key'];
+            $return = $box_list = [];
+            //处理数据
+            LabelDealService::getInstance()->clearData($data,$return,$box_list);
+
+            //调用外部方法
+            list($lead_bind,$lead_out) = DwyService::getInstance()->setBoxData($this->header,$dv,$return,$box_list,$data);
+
+            //调用保存接口
+            LabelDealService::getInstance()->boxOut($lead_bind,$lead_out,$this->header,$this->id);
+        }catch (\Throwable $exception){
+            file_put_contents('msg_result.txt',date('Y-m-d H:i:s') . "队列捕获:" . $exception->getLine() . "|" . $exception->getMessage(). "|"  . $exception->getCode(). PHP_EOL,8);
+            $this->delete();
+        }
     }
 
     protected function echoMessage(OutputInterface $output)

+ 10 - 14
app/Service/LabelDealService.php

@@ -19,7 +19,7 @@ class LabelDealService extends Service
         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'];
+            $tmp = $value['brand_out_stock_dtl'][0] ?? [];
             $return[$value['send_box_code']] = [
                 'fake_qty' => $tmp['fake_qty'],
                 'detail' => explode(',',$tmp['brand_qr_code_list'])
@@ -31,29 +31,25 @@ class LabelDealService extends Service
     public function boxOut($lead_bind,$lead_out,$token,$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,
-        ];
-        $return_bind = $this->post_helper($url, json_encode($lead_bind), $header);
+//        $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';
+        $return_bind = $this->post_helper($url, json_encode($lead_bind), $token);
         file_put_contents('msg_result.txt',date('Y-m-d H:i:s') . "绑定:" . $return_bind. PHP_EOL,8);
         $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';
-        $return_out = $this->post_helper($url, json_encode($lead_out), $header);
+        $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';
+        $return_out = $this->post_helper($url, json_encode($lead_out), $token);
         file_put_contents('msg_result.txt',date('Y-m-d H:i:s') . "出库:" . $return_out. PHP_EOL,8);
         $return_out = json_decode($return_out, true);
 
-        //toDo
-        BigKingCbj::where('id',$id)->update(['is_successful' => 1]);
+        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]);
     }
 
     public function post_helper($url, $data, $auth)
     {
+        file_put_contents('msg_result.txt',date('Y-m-d H:i:s') . "请求参数:" . $data . PHP_EOL,8);
         $header = [
             'Content-Type:application/json',
             'Authorization: ' . $auth,
@@ -66,7 +62,7 @@ class LabelDealService extends Service
         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));
+        if (!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
         $r = curl_exec($ch);
         curl_close($ch);
         return $r;

+ 2 - 2
routes/api.php

@@ -23,7 +23,7 @@ Route::any('getOpenCommand', 'Api\DwyController@getOpenCommand');
 Route::any('openDoor', 'Api\DwyController@openDoor');
 Route::any('setLb', 'Api\DwyController@setLb');
 Route::any('boxList', 'Api\DwyController@boxList');
-Route::any('boxOut', 'Api\DwyController@boxOut');
+//Route::any('boxOut', 'Api\DwyController@boxOut');
 
 //贴标机
 Route::any('setTbData', 'Api\DwyController@setTbData');
@@ -57,7 +57,7 @@ Route::any('zjlb', 'Api\DwyController@zjlb');
 Route::any('tttt', 'Api\DwyController@tttt');
 Route::any('getBoxTrademark', 'Api\DwyController@getBoxTrademark');
 Route::any('aaaa', 'Api\DwyController@setBoxTrademark');
-Route::any('labelDeal', 'Api\JobController@labelDeal');
+Route::any('boxOut', 'Api\JobController@labelDeal');
 
 Route::group(['middleware'=> []],function ($route){
     $route->any('menuAdd', 'Api\SysMenuController@add');