100], [['get_params', 'post_params', 'header_params', 'response_params', 'create_at','created_at_micro','addr_ip','request_method','name','role'], 'safe'] ]; } public function attributeLabels() { return [ 'id' => 'ID', 'route' => '路由', 'admin_id' => '管理员ID', 'type' => '类型', 'data_id' => '数据ID', 'created_at' => '创建时间', 'get_params' => 'GET参数', 'post_params' => 'POST参数', 'header_params' => 'HEADER参数', 'response_params' => '响应参数' ]; } public function beforeSave($insert) { if (parent::beforeSave($insert)) { if ($this->isNewRecord) { $this->created_at = date('Y-m-d H:i:s'); } return true; } return false; } public static function addLog($code,$route,$data_string){ try { $log = new self(); $log->type = 'log'; $log->route = $route; $log->admin_id = 1; $log->request_method = 'POST'; $log->spend_time = rand(1,100); $log->addr_ip = ''; $log->status = $code; $response['response'] =['code'=>$code,'data'=>$data_string] ; $log->response_params = Json::encode($response); $log->role = 'admin'; $log->name = 'admin'; $log->created_at_micro = microtime(true)*1000; if (!$log->save()){ //debug_log([__METHOD__, __LINE__, "actionLog:".$log->getErrorSummary(false)[0]], "app_debug.log"); } }catch (\Throwable $e){ //debug_log([__METHOD__, __LINE__, "actionLog:".$e->getMessage()], "app_debug.log"); } } }