\n(\s+)/m', '] => ', $output); if (PHP_SAPI == 'cli') { $output = PHP_EOL . $output . PHP_EOL; } else { if (!extension_loaded('xdebug')) { $output = htmlspecialchars($output, ENT_SUBSTITUTE); } $output = '
' . $output . '
'; } echo $output; } /** * 成功返回 * @param array $data 需返回数据 * @param int $code code枚举码 * @param string $message 返回提示信息 * @return array */ function success(array $data = [], int $code = HttpEnumCode::HTTP_SUCCESS, string $message = ""): array { if (empty($message)) { $message = HttpEnumCode::getMessage($code); } return [ 'code' => $code, 'data' => $data, 'message' => $message ]; } /** * 失败返回 * @param int $code code枚举码 * @param string $message 返回提示信息 * @param array $data 需返回数据 * @return array */ function fail(int $code = HttpEnumCode::HTTP_ERROR, string $message = "", array $data = []): array { if (empty($message)) { $message = HttpEnumCode::getMessage($code); } return [ 'code' => $code, 'data' => $data, 'message' => $message ]; } /** * 转换用户类型-字符串 * @param int|string $user_type 用户类型(1:患者 2:医生 3:药师) * @return string */ function UserTypeToString(int|string $user_type): string { if ($user_type == 1) { $result = "患者端"; } elseif ($user_type == 2) { $result = "医生端"; } elseif ($user_type == 3) { $result = "药师端"; } else { $result = "未知"; } return $result; } /** * 获取身份证年龄 * @param $idCard * @return false|int|mixed|string */ function getIdCardAge(string $idCard): mixed { $age_time = strtotime(substr($idCard, 6, 8)); if ($age_time === false) { return false; } list($y1, $m1, $d1) = explode("-", date("Y-m-d", $age_time)); $now_time = strtotime("now"); list($y2, $m2, $d2) = explode("-", date("Y-m-d", $now_time)); $age = $y2 - $y1; if ((int)($m2 . $d2) < (int)($m1 . $d1)) { $age -= 1; } return $age; } /** * 获取身份证性别 * @param string $idCard * @return int */ function getIdCardSex(string $idCard): int { if(empty($idCard)) { return 0; } $sexint = (int) substr($idCard, 16, 1); return $sexint % 2 === 0 ? 2 : 1; } /** * 添加阿里云oss前缀网址 * @param $path * @return string */ function addAliyunOssWebsite($path): string { if (empty($path)){ return ""; } return config('alibaba.oss.custom_domain_name') . '/' . $path; }