input_param(); $this->start_time = microtime(true); } /** * Notes:获取参数 * Created on: 2022/9/2 16:57 * Created by: dengbw * @param string $key * @return mixed */ function input_param($key = '') { if ($key) { return $this->inputs[$key]; } $request = $this->input->method(); switch ($request) { case 'post': case 'put': case 'delete': $input = json_decode(file_get_contents('php://input'), true); break; default: $input = $this->input->get(); } $this->inputs = $input; return $this->inputs; } /** * Notes:返回json * Created on: 2022/9/8 15:35 * Created by: dengbw * @param string $message * @param int $code */ public function return_json($message = '', $code = 1) { header('Content-Type:application/json; charset=utf-8'); echo json_encode(['code' => $code, 'message' => $message], JSON_UNESCAPED_UNICODE); exit(); } /** * Notes:返回response * Created on: 2022/9/9 15:39 * Created by: dengbw * @param array $data */ public function return_response_list($data = []) { $this->return_response($data, '操作成功', 0, 1); } /** * Notes:返回response * Created on: 2022/9/8 15:21 * Created by: dengbw * @param array $data * @param string $message * @param int $code * @param int $if_list * @param int $http_code */ public function return_response($data = [], $message = '操作成功', $code = 0, $if_list = 0, $http_code = REST_Controller::HTTP_OK) { $set_data = ['code' => $code, 'message' => $message]; if ($if_list) {//列表显示空数据 $set_data['data'] = $data; } else { $data && $set_data['data'] = $data; } if ($_SESSION['operation_description']) {//添加操作日志 $this->load->library('api/record'); $method = lcfirst(get_class($this)); $end_time = microtime(true); $spendTime = ($end_time - $this->start_time) * 1000; //计算差值 毫秒 $this->record->operationRecord(['userId' => $_SESSION['userId'], 'username' => $_SESSION['username'] , 'nickname' => $_SESSION['nickname'], 'method' => $method, 'spendTime' => $spendTime , 'module' => $_SESSION['operation_module'], 'description' => $_SESSION['operation_description'] , 'params' => json_encode($this->inputs, JSON_UNESCAPED_UNICODE) , 'result' => json_encode($set_data, JSON_UNESCAPED_UNICODE)]); } $this->response($set_data, $http_code, TRUE); } }