lizhen_gitee il y a 8 mois
Parent
commit
94e6cdc5b7

+ 2 - 2
addons/exam/controller/Base.php

@@ -7,9 +7,9 @@ use think\Lang;
 
 
 class Base extends Api
 class Base extends Api
 {
 {
-    public function _initialize()
+    public function __construct()
     {
     {
-        parent::_initialize();
+        parent::__construct();
 
 
         $this->loadCommonFile();
         $this->loadCommonFile();
 
 

+ 19 - 0
addons/exam/helper.php

@@ -19,6 +19,7 @@ if (!function_exists('fail')) {
             'msg'  => is_array($message) ? json_encode($message) : $message,
             'msg'  => is_array($message) ? json_encode($message) : $message,
         ];
         ];
 
 
+        request_log_update($result);
         // 如果未设置类型则自动判断
         // 如果未设置类型则自动判断
         $type     = 'json';
         $type     = 'json';
         $response = \think\Response::create($result, $type, 200);
         $response = \think\Response::create($result, $type, 200);
@@ -39,6 +40,7 @@ if (!function_exists('succ')) {
             'msg'  => $message,
             'msg'  => $message,
         ];
         ];
 
 
+        request_log_update($result);
         // 如果未设置类型则自动判断
         // 如果未设置类型则自动判断
         $type     = 'json';
         $type     = 'json';
         $response = \think\Response::create($result, $type, 200);
         $response = \think\Response::create($result, $type, 200);
@@ -291,4 +293,21 @@ if (!function_exists('generate_no')) {
         $milliseconds = round(($u_timestamp - $timestamp) * 100); // 改这里的数值控制毫秒位数
         $milliseconds = round(($u_timestamp - $timestamp) * 100); // 改这里的数值控制毫秒位数
         return $pre . $date . date(preg_replace('`(?<!\\\\)u`', $milliseconds, 'u'), $timestamp);
         return $pre . $date . date(preg_replace('`(?<!\\\\)u`', $milliseconds, 'u'), $timestamp);
     }
     }
+}
+
+function request_log_update($log_result){
+
+    /*if ($this->logType === 1){
+        if (strlen(json_encode($log_result['data'])) > 1000) {
+            $log_result['data'] = '数据太多,不记录';
+        }
+        LogUtil::info('result', 'Api-Middleware-Log', 'request_log', $log_result);
+    }else{*/
+        if(defined('API_REQUEST_ID')) { //记录app正常返回结果
+            if(strlen(json_encode($log_result['data'])) > 1000) {
+                $log_result['data'] = '数据太多,不记录';
+            }
+            db('api_request_log')->where('id',API_REQUEST_ID)->update(['result'=>json_encode($log_result)]);
+        }
+    /*}*/
 }
 }

+ 2 - 6
application/common/controller/Api.php

@@ -69,7 +69,7 @@ class Api
     /**
     /**
      * @var int 日志类型 1 文件;2sql
      * @var int 日志类型 1 文件;2sql
      */
      */
-    public $logType = 1;
+    public $logType = 2;
 
 
     /**
     /**
      * 构造方法
      * 构造方法
@@ -95,7 +95,7 @@ class Api
         //日志
         //日志
         $this->request_log();
         $this->request_log();
         //用户活跃
         //用户活跃
-        $this->user_active();
+        //$this->user_active();
 
 
         // 前置操作方法
         // 前置操作方法
         if ($this->beforeActionList) {
         if ($this->beforeActionList) {
@@ -449,10 +449,6 @@ class Api
     }
     }
 
 
     protected function request_log_update($log_result){
     protected function request_log_update($log_result){
-        $actionname     = $this->request->action();
-        if(strtolower($actionname) == 'givegifttoyou'){
-            //return true;
-        }
 
 
         if ($this->logType === 1){
         if ($this->logType === 1){
             if (strlen(json_encode($log_result['data'])) > 1000) {
             if (strlen(json_encode($log_result['data'])) > 1000) {