request->header('userId'); $token = cache('token'.$userId); if($token){ $this->token = $token; } $userInfo = cache('userinfo'.$userId); if($userInfo){ $this->userInfo = $userInfo; } } /** * 获取当前用户ID * * @return void */ public function getUserId() { return $this->userInfo['user_id']; } /** * 获取当前用户名 * * @return void */ public function getUserName() { return $this->userInfo['user_name']; } /** * 是否管理员 */ public function isAdmin() { return in_array("Biz_system_admin", $this->userInfo['roleCode']); } /** * 是否回价员 */ public function isAppraiser() { return in_array("Assistant_appraiser", $this->userInfo['roleCode']); } /** * Check if the current user has sign appraiser role * 是否签章估价师 * @return bool Returns true if user has sign_appraiser role, false otherwise */ public function isSignAppraiser() { return in_array("Sign_appraiser", $this->userInfo['roleCode']) || in_array("COM_TOP_ADMIN", $this->userInfo['roleCode']) || in_array("admin", $this->userInfo['roleCode']); } /** * 是否业务组长 */ public function isBusinessTeamLeader() { return in_array("BusinessTL", $this->userInfo['roleCode']); } /** * 返回封装后的API数据到客户端 * @access protected * @param mixed $data 要返回的数据 * @access protected * @param mixed $data 要返回的数据 * @param mixed $msg 提示信息 * @param integer $code 返回的code * @param boolean $isSerialized 是否序列化 * @return \think\Response */ protected function buildSuccess($data = [], $msg = '操作成功', $code = 1,$isSerialized = false) { $result = [ 'code' => $code, 'msg' => $msg, 'isSerialized' => $isSerialized, 'data' => $data, ]; // 如果$encryted为true,则对数据进行二进制序列化 if ($isSerialized) { $str_json = json_encode($result['data']); $result['data'] = bin2hex($str_json); } $response = Response::create($result, 'json'); return $response; } /** * 回复客户端成功 * * @param mixed $data 要返回的数据 * @param mixed $msg 提示信息 * @param integer $code 返回的code * @param boolean $isSerialized 是否序列化 * @return \think\Response */ protected function responseSuccess($data = [], $isCrypto = false) { $r =[ 'code' => 1, 'msg' => '回复成功', 'isCrypto' => $isCrypto, 'data' => $data, ]; if ($isCrypto) { $str_json = json_encode($r['data']); $r['data'] = bin2hex($str_json); } $response = Response::create($r, 'json'); return $response; } /** */ /** * 返回封装后的API数据到客户端 * @access protected * @param mixed $msg 提示信息 * @param mixed $data 要返回的数据 * @param integer $code 返回的code * @return \think\Response */ protected function buildFailed($msg = '', $data = [], $code = -1,$isSerialized = false) { if( $isSerialized ) $data = base64_encode(json_encode($data)); $result = [ 'code' => $code, 'msg' => $msg, 'data' => $data, ]; $response = Response::create($result, 'json'); return $response; } /** *时间段查询 时间戳 */ function getQueryDateTime() { $start_time = request()->param('start_time', ''); $end_time = request()->param('end_time', ''); $start_time_stamp = strtotime($start_time); $end_time_stamp = strtotime($end_time); $date_params = ''; if ($start_time && $end_time) { if ($start_time_stamp > $end_time_stamp) { $date_params = ['between', [$end_time, $start_time.' 23:59:59']]; } else if ($start_time_stamp < $end_time_stamp) { $date_params = ['between', [$start_time, $end_time.' 23:59:59']]; } else { $date_params = ['between', [$start_time, $end_time.' 23:59:59']]; } } else if (!$start_time && !$end_time) { $date_params = ['between', ['2025-02-01 00:00:00', date('Y-m-d', strtotime('+1 day')).' 23:59:59']]; } else { $start_time && $date_params = ['egt', $start_time]; $end_time && $date_params = ['elt', $end_time.' 23:59:59']; } return $date_params; } /** * 分页查询 */ public function getPage() { $page = request()->param('page', 1); $list_rows = request()->param('limit', config('apiBusiness.ADMIN_LIST_DEFAULT')); return [ 'list_rows' => $list_rows, 'page' => $page ]; } }