Browse Source

Merge remote-tracking branch 'origin/master'

gogs 9 tháng trước cách đây
mục cha
commit
906c760f03
3 tập tin đã thay đổi với 24 bổ sung10 xóa
  1. 5 2
      app/Jobs/LabelDealJob.php
  2. 11 7
      app/Service/LabelDealService.php
  3. 8 1
      config/logging.php

+ 5 - 2
app/Jobs/LabelDealJob.php

@@ -9,6 +9,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Foundation\Bus\Dispatchable;
 use Illuminate\Queue\InteractsWithQueue;
 use Illuminate\Queue\SerializesModels;
+use Illuminate\Support\Facades\Log;
 use Symfony\Component\Console\Output\ConsoleOutput;
 use Symfony\Component\Console\Output\OutputInterface;
 
@@ -38,9 +39,11 @@ class LabelDealJob implements ShouldQueue
             $data = $this->data;
             $dv = $data['key'];
             $return = $box_list = [];
+            Log::channel('apiLog')->info('出库源数据', ["param" => $data]);
+
             //处理数据
             LabelDealService::getInstance()->clearData($data,$return,$box_list);
-            file_put_contents('msg_result.txt',date('Y-m-d H:i:s') . "清洗数据:" . json_encode($return) . PHP_EOL,8);
+            Log::channel('apiLog')->info('出库(清洗数据)', ["param" => $return]);
 
             //调用外部方法
             list($lead_bind,$lead_out) = DwyService::getInstance()->setBoxData($this->header,$dv,$return,$box_list,$data);
@@ -51,7 +54,7 @@ class LabelDealJob implements ShouldQueue
             //调用保存接口
             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->getFile() . "|" . $exception->getLine() . "|" . $exception->getMessage(). "|"  . $exception->getCode(). PHP_EOL,8);
+            Log::channel('apiLog')->info('队列捕获(出库异常)', ["message" => $exception->getFile() . "|" . $exception->getLine() . "|" . $exception->getMessage(). "|"  . $exception->getCode()]);
             $this->delete();
         }
     }

+ 11 - 7
app/Service/LabelDealService.php

@@ -4,6 +4,7 @@ namespace App\Service;
 
 
 use App\Model\BigKingCbj;
+use Illuminate\Support\Facades\Log;
 
 class LabelDealService extends Service
 {
@@ -27,7 +28,7 @@ class LabelDealService extends Service
                         'detail' => [],
                     ];
                 }
-                $return[$value['send_box_code']]['fake_qty'] += $tmp['fake_qty'];
+                $return[$value['send_box_code']]['fake_qty'] += $tmp['fake_qty'] ?? 0;
                 $return[$value['send_box_code']]['detail'] = array_merge($return[$value['send_box_code']]['detail'], explode(',',$tmp['brand_qr_code_list']));
             }
         }
@@ -38,25 +39,28 @@ class LabelDealService extends Service
         //商标出库
         $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 = $this->post_helper($url, $lead_out, $token);
         $return_out = json_decode($return_out, true);
+        Log::channel('apiLog')->info('商标出库(返回结果)', ["message" => $return_out]);
 
         sleep(3);
 
         //商标绑定
 //        $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 = $this->post_helper($url, $lead_bind, $token);
         $return_bind = json_decode($return_bind, true);
+        Log::channel('apiLog')->info('商标绑定(返回结果)', ["message" => $return_bind]);
 
         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);
+        Log::channel('apiLog')->info('商标(请求参数)', ["param" => $data]);
+
+        $data = json_encode($data);
+
         $header = [
             'Content-Type:application/json',
             'Authorization: ' . $auth,
@@ -72,7 +76,7 @@ class LabelDealService extends Service
         if (!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
         $r = curl_exec($ch);
         curl_close($ch);
-        return $r;
 
+        return $r;
     }
 }

+ 8 - 1
config/logging.php

@@ -106,13 +106,20 @@ return [
             'path' => storage_path('logs/login.log'),
             'permission' => 0666
         ],
-        //登录日志记录
+        //日志记录
         'request' => [
             'driver' => 'daily',
             'path' => storage_path('logs/request.log'),
             'level' => 'debug',
             'days' => 7,
         ],
+        //接口日志记录
+        'apiLog' => [
+            'driver' => 'daily',
+            'path' => storage_path('logs/api_log.log'),
+            'level' => 'debug',
+            'days' => 7,
+        ],
     ],
 
 ];