407 lines
9.8 KiB
PHP
407 lines
9.8 KiB
PHP
<?php
|
||
|
||
use App\Constants\DoctorTitleCode;
|
||
use App\Constants\HttpEnumCode;
|
||
|
||
|
||
/**
|
||
* @method:打印使用,格式化打印数据
|
||
* @param mixed ...$vars
|
||
*/
|
||
function dump(...$vars)
|
||
{
|
||
ob_start();
|
||
var_dump(...$vars);
|
||
|
||
$output = ob_get_clean();
|
||
$output = preg_replace('/\]\=\>\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 = '<pre>' . $output . '</pre>';
|
||
}
|
||
|
||
echo $output;
|
||
}
|
||
|
||
/**
|
||
* 成功返回
|
||
* @param array $data 需返回数据
|
||
* @param int $code code枚举码
|
||
* @param string $message 返回提示信息
|
||
* @return array
|
||
*/
|
||
function success(array|string|null $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 string $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;
|
||
}
|
||
|
||
/**
|
||
* 转换性别至im识别的性别
|
||
* @param string|int $sex
|
||
* @return string
|
||
*/
|
||
function sexToImSex(string|int $sex): string
|
||
{
|
||
$result = "Gender_Type_Unknown";
|
||
if ($sex == 1){
|
||
$result = "Gender_Type_Male";
|
||
}elseif ($sex == 2){
|
||
$result = "Gender_Type_Female";
|
||
}
|
||
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 转换订单类型-字符串
|
||
* @param int|string $inquiry_type 订单类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
|
||
* @return string
|
||
*/
|
||
function inquiryTypeToString(int|string $inquiry_type): string
|
||
{
|
||
if ($inquiry_type == 1) {
|
||
$result = "专家问诊";
|
||
} elseif ($inquiry_type == 2) {
|
||
$result = "快速问诊";
|
||
} elseif ($inquiry_type == 3) {
|
||
$result = "公益问诊";
|
||
} elseif ($inquiry_type == 4) {
|
||
$result = "问诊购药";
|
||
} elseif ($inquiry_type == 5) {
|
||
$result = "检测问诊";
|
||
} else {
|
||
$result = "未知";
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 转换问诊订单取消原因-字符串
|
||
* @param int|string $cancel_reason 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||
* @return string
|
||
*/
|
||
function inquiryCancelReasonToString(int|string $cancel_reason): string
|
||
{
|
||
if ($cancel_reason == 1) {
|
||
$result = "医生未接诊";
|
||
} elseif ($cancel_reason == 2) {
|
||
$result = "主动取消";
|
||
} elseif ($cancel_reason == 3) {
|
||
$result = "无可分配医生";
|
||
} elseif ($cancel_reason == 4) {
|
||
$result = "客服取消";
|
||
} elseif ($cancel_reason == 5) {
|
||
$result = "支付超时";
|
||
} else {
|
||
$result = NULL;
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 转换问诊订单取消原因-字符串
|
||
* @param int|string $cancel_reason 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||
* @return string
|
||
*/
|
||
function inquiryCancelReasonToPushString(int|string $cancel_reason): string
|
||
{
|
||
if ($cancel_reason == 1) {
|
||
$result = "医生未接诊";
|
||
} elseif ($cancel_reason == 2) {
|
||
$result = "用户主动取消";
|
||
} elseif ($cancel_reason == 3) {
|
||
$result = "未分配到合适的医生";
|
||
} elseif ($cancel_reason == 4) {
|
||
$result = "平台取消问诊订单";
|
||
} elseif ($cancel_reason == 5) {
|
||
$result = "平台取消问诊订单";
|
||
} else {
|
||
$result = "未知";
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 转换药品订单取消原因-字符串
|
||
* @param int|string $cancel_reason 订单取消原因(1:主动取消 2:复核失败/库存不足 3:支付超时 4:客服取消)
|
||
* @return string
|
||
*/
|
||
function productCancelReasonToString(int|string $cancel_reason): string
|
||
{
|
||
if ($cancel_reason == 1) {
|
||
$result = "主动取消";
|
||
} elseif ($cancel_reason == 2) {
|
||
$result = "复核失败/库存不足";
|
||
} elseif ($cancel_reason == 3) {
|
||
$result = "支付超时";
|
||
} elseif ($cancel_reason == 4) {
|
||
$result = "客服取消";
|
||
} else {
|
||
$result = "未知";
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 转换检测订单取消原因-字符串
|
||
* @param int|string $cancel_reason 取消订单原因(1:主动取消 2:客服取消 3:支付超时)
|
||
* @return string
|
||
*/
|
||
function detectionCancelReasonToString(int|string $cancel_reason): string
|
||
{
|
||
if ($cancel_reason == 1) {
|
||
$result = "主动取消";
|
||
} elseif ($cancel_reason == 2) {
|
||
$result = "客服取消";
|
||
} elseif ($cancel_reason == 3) {
|
||
$result = "支付超时";
|
||
} else {
|
||
$result = "";
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 转换性别至字符串
|
||
* @param string|int $sex
|
||
* @return string
|
||
*/
|
||
function sexToStringSex(string|int $sex): string
|
||
{
|
||
$result = "未知";
|
||
if ($sex == 1){
|
||
$result = "男";
|
||
}elseif ($sex == 2){
|
||
$result = "女";
|
||
}
|
||
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 检测并创建目录
|
||
* @param string $dir 文件目录
|
||
* @param int $mode 权限
|
||
* @return bool
|
||
*/
|
||
function mkdirs(string $dir, int $mode = 0755): bool
|
||
{
|
||
if (is_dir($dir) || @mkdir($dir, $mode)) return TRUE;
|
||
|
||
if (!mkdirs(dirname($dir), $mode)) return FALSE;
|
||
|
||
return @mkdir($dir, $mode);
|
||
|
||
}
|
||
|
||
/**
|
||
* 转换优惠卷适用范围为汉字
|
||
* @param int|string $application_scope
|
||
* @return string
|
||
*/
|
||
function couponScopeToString(int|string $application_scope): string
|
||
{
|
||
if ($application_scope == 1) {
|
||
$result = "所有问诊类型";
|
||
} elseif ($application_scope == 2) {
|
||
$result = "快速问诊";
|
||
} elseif ($application_scope == 3) {
|
||
$result = "专家问诊";
|
||
} elseif ($application_scope == 4) {
|
||
$result = "公益问诊";
|
||
} elseif ($application_scope == 5) {
|
||
$result = "问诊购药";
|
||
} else {
|
||
$result = "";
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 转换服务包订单类型为汉字
|
||
* @param int|string $order_service_type 服务包类型(1:健康包 2:随访包)
|
||
* @return string
|
||
*/
|
||
function orderServiceTypeToString(int|string $order_service_type): string
|
||
{
|
||
if ($order_service_type == 1) {
|
||
$result = "健康包";
|
||
} elseif ($order_service_type == 2) {
|
||
$result = "随访包";
|
||
} else {
|
||
$result = "服务包";
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 转换每月次数为汉字
|
||
* @param int|string $monthly_frequency 服务包类型(1:健康包 2:随访包)
|
||
* @return string
|
||
*/
|
||
function monthlyFrequencyToString(int|string $monthly_frequency): string
|
||
{
|
||
$result = $monthly_frequency;
|
||
if ($monthly_frequency == 0) {
|
||
$result = "不限";
|
||
}
|
||
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 转换问诊订单订单接诊方式-字符串
|
||
* @param int|string $inquiry_mode 接诊方式(1:图文 2:视频 3:语音 4:电话 5:会员 6:疑难会诊 7:附赠 8:健康包 9:随访包)
|
||
* @return string
|
||
*/
|
||
function inquiryModeToString(int|string $inquiry_mode): string
|
||
{
|
||
if ($inquiry_mode == 1) {
|
||
$result = "图文";
|
||
} elseif ($inquiry_mode == 2) {
|
||
$result = "视频";
|
||
} elseif ($inquiry_mode == 3) {
|
||
$result = "语音";
|
||
} elseif ($inquiry_mode == 4) {
|
||
$result = "电话";
|
||
} elseif ($inquiry_mode == 5) {
|
||
$result = "会员";
|
||
} elseif ($inquiry_mode == 6) {
|
||
$result = "疑难会诊";
|
||
} elseif ($inquiry_mode == 7) {
|
||
$result = "附赠";
|
||
} elseif ($inquiry_mode == 8) {
|
||
$result = "健康包";
|
||
} elseif ($inquiry_mode == 9) {
|
||
$result = "随访包";
|
||
} else {
|
||
$result = "未知";
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 转换订单类型为汉字
|
||
* @param int|string $order_type
|
||
* @return string
|
||
*/
|
||
function orderTypeToString(int|string $order_type): string
|
||
{
|
||
if ($order_type == 1) {
|
||
$result = "问诊订单";
|
||
} elseif ($order_type == 2) {
|
||
$result = "药品订单";
|
||
} elseif ($order_type == 3) {
|
||
$result = "检测订单";
|
||
} elseif ($order_type == 4) {
|
||
$result = "随访包";
|
||
} elseif ($order_type == 5) {
|
||
$result = "健康包";
|
||
} else {
|
||
$result = "未知";
|
||
}
|
||
return $result;
|
||
} |