初始化项目
This commit is contained in:
135
config/cc.php
Executable file
135
config/cc.php
Executable file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
return [
|
||||
/*
|
||||
* 过期时间配置
|
||||
*/
|
||||
'time_out' => [
|
||||
// 订单
|
||||
'product_order' => [
|
||||
'over_time' => 24*3600,//秒,自动取消时间
|
||||
// 'over_time' => 3,//秒,自动取消时间
|
||||
'received_time' => 7*24*3600,//自动确认收货时间
|
||||
'forbidden_refund_time' => 30*24*3600, //不允许退款时间
|
||||
'settlement_time' => 0//7*24*3600//订单发货 分账自动结算时间
|
||||
],
|
||||
// 处方
|
||||
'prescription' => [
|
||||
'over_time' => 24*3600 //处方审核自动失效时间
|
||||
// 'over_time' => 0 //处方审核自动失效时间
|
||||
],
|
||||
],
|
||||
/*
|
||||
* redis配置
|
||||
*/
|
||||
'redis' => [
|
||||
'jwt' => 'xk_login_',
|
||||
'jwt_ttl' => 360000,
|
||||
// 'jwt_ttl' => 360,
|
||||
'email' => 'xk_email_',
|
||||
'phone' => 'xk_phone_',
|
||||
'login_out_key' => 'xk_login_out_',
|
||||
'menu_key' => 'xk_menu_',
|
||||
],
|
||||
/*
|
||||
* api白名单
|
||||
*/
|
||||
'api' => [
|
||||
'white_list' => [
|
||||
'/api/admin/login',
|
||||
'/api/admin/register',
|
||||
]
|
||||
],
|
||||
/*
|
||||
* 阿里云oss配置
|
||||
*/
|
||||
'oss' => [
|
||||
'redis_key' => 'xk_oss_url_',
|
||||
'ali' => [
|
||||
'accessKeyId' => env('OSS_ACCESS_KEY_ID'),
|
||||
'accessKeySecret' => env('OSS_ACCESS_KEY_SECRET'),
|
||||
'endpoint' => env('OSS_ENDPOINT'),
|
||||
'bucket' => env('OSS_BUCKET'),
|
||||
'domain' => env('OSS_DOMAIN'),
|
||||
],
|
||||
'qiniu' => [
|
||||
'access_key' => 'RPQlZUd2yrL3kR8CC4BpTGV6FhGr11npBzf6IuCT',
|
||||
'secret_key' => 'b-796uVY1InOKSVecpY8VBpO7Cdubo1Tv4RcOfMY',
|
||||
'bucket' => 'ccspa',
|
||||
'domain' => 'http://o-spa.nailaoyun.cn',
|
||||
]
|
||||
],
|
||||
/*
|
||||
* 短信配置
|
||||
*/
|
||||
'sms' => [
|
||||
'ali' => [
|
||||
'status' => '1',
|
||||
'access_key_id' => env('ALIYUN_SMS_ACCESS_KEY_ID'),
|
||||
'access_key_secret' => env('ALIYUN_SMS_ACCESS_KEY_SECRET'),
|
||||
'sign_name' => env('ALIYUN_SMS_SIGN_NAME'),
|
||||
'captcha' => [
|
||||
"template_id" => "SMS_275060336", // 模板id
|
||||
"template_variable" => "code", //模板变量
|
||||
],
|
||||
"doctor" => [
|
||||
"register" => [ //挂号订单提醒
|
||||
"template_id" => "SMS_462205458",
|
||||
"template_variable" => ""
|
||||
],
|
||||
"prescription_pass" => [
|
||||
"template_id" => "SMS_462260412",
|
||||
"template_variable" => "order"
|
||||
],
|
||||
"prescription_refuse" => [
|
||||
"template_id" => "SMS_462230433",
|
||||
"template_variable" => [
|
||||
"order",
|
||||
"cause"
|
||||
]
|
||||
]
|
||||
],
|
||||
"pharmacist" => [
|
||||
"wait_approval" => [
|
||||
"template_id" => "SMS_462255406",
|
||||
"template_variable" => ""
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
/*
|
||||
* 旧接口配置
|
||||
*/
|
||||
'base_url' => [
|
||||
'old_api' => env('BASE_OLD_API_URL', ''),
|
||||
'old_shop_api' => env('BASE_OLD_SHOP_API_URL', ''),
|
||||
// 微信接口
|
||||
'we_chat_api' => env('BASE_WE_CHAT_API_URL', ''),
|
||||
],
|
||||
/*
|
||||
* 日志配置
|
||||
*/
|
||||
'log' => [
|
||||
// 不添加返回记录的api接口
|
||||
'no_insert' => [
|
||||
'api/admin/auth/login',
|
||||
'api/admin/auth/send-verification-code',
|
||||
'api/admin/auth/my-info',
|
||||
'api/admin/auth/codes',
|
||||
'api/admin/auth/menu',
|
||||
'api/admin/log/api-list',
|
||||
'api/admin/log/ledger-list',
|
||||
'api/admin/log/op-list',
|
||||
'api/admin/log/prescription-list',
|
||||
]
|
||||
],
|
||||
'app' => [
|
||||
'we_chat' => [
|
||||
'app_id' => '',
|
||||
'app_secret' => '',
|
||||
'merchant_id' => '',
|
||||
'merchant_key' => '',
|
||||
'apiclient_cert' => '',
|
||||
'apiclient_key' => ''
|
||||
]
|
||||
],
|
||||
];
|
||||
504
config/helpers.php
Executable file
504
config/helpers.php
Executable file
@@ -0,0 +1,504 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* 辅助函数封装
|
||||
*/
|
||||
|
||||
/**
|
||||
* 路由注册封装
|
||||
* 使用 cc_route_register 函数,路由名需要用连词符 "-" 来表示,并且控制器要使用小驼峰的命名规范
|
||||
* @param $router
|
||||
* @param $class
|
||||
* @return void
|
||||
*/
|
||||
|
||||
if ( !function_exists('cc_route_register') ) {
|
||||
function cc_route_register ($router,$class): void
|
||||
{
|
||||
foreach ( $router as [ $method, $router_name ] ) {
|
||||
// ds(Illuminate\Support\Facades\Route::$method( $router_name, [$class, conjunction_symbol_processing($router_name)] ));
|
||||
Illuminate\Support\Facades\Route::$method( $router_name, [$class, conjunction_symbol_processing($router_name)] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动路由注册封装
|
||||
* 使用 cc_auto_route_register 函数,路由名需要用连词符 "-" 来表示,并且控制器要使用小驼峰的命名规范
|
||||
* @param $class
|
||||
* @return void
|
||||
*/
|
||||
if ( !function_exists('cc_auto_route_register') ) {
|
||||
function cc_auto_route_register ($class): void
|
||||
{
|
||||
foreach ($class as $key => $value) {
|
||||
|
||||
// 获取控制器$value的所有方法
|
||||
$methods = (new ReflectionClass($value))->getMethods();
|
||||
|
||||
// 注册路由
|
||||
foreach ($methods as $method) {
|
||||
// 获取方法注释 @Method
|
||||
$docComment = $method->getDocComment();
|
||||
if ($method->name === '__construct' || preg_match('/@Method\s+(NO)\b/', $docComment, $matches)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$httpMethod = 'any';
|
||||
// 查询 @Method GET 或者 @Method POST
|
||||
if (preg_match('/@Method\s+(GET|POST|PUT|DELETE|PATCH|OPTIONS|HEAD|ANY)\b/', $docComment, $matches)) {
|
||||
$httpMethod = $matches[1];
|
||||
}
|
||||
Illuminate\Support\Facades\Route::$httpMethod( $key. '/'. cc_camel_case_to_dash($method->getName()), [$value, conjunction_symbol_processing($method->name)] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 无限极分类
|
||||
* @param $data
|
||||
* @param $pid
|
||||
* @return mixed
|
||||
*/
|
||||
if ( !function_exists('tree') ) {
|
||||
function tree($data, $pid = 0, $idField = 'id', $pidField = 'pid'): array
|
||||
{
|
||||
$tree = array();
|
||||
foreach ($data as &$v)
|
||||
{
|
||||
if ($v[$pidField] == $pid)
|
||||
{
|
||||
$v['children'] = tree($data, $v[$idField], $idField, $pidField);
|
||||
if (empty($v['children'])) unset($v['children']);
|
||||
$tree[] = $v;
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置不关闭
|
||||
* @return true
|
||||
*/
|
||||
if ( !function_exists('cc_set_time_limit') ) {
|
||||
function cc_set_time_limit(): bool {
|
||||
//让程序一直运行
|
||||
set_time_limit(0);
|
||||
//设置程序运行内存
|
||||
ini_set('memory_limit', '1024M');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取ip所属地
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
if ( !function_exists('cc_get_ip_lookup') ) {
|
||||
function cc_get_ip_lookup($ip = ''): array {
|
||||
$result = (new GuzzleHttp\Client())->get('https://api.vore.top/api/Weather?ip='. $ip);
|
||||
$weather = json_decode($result->getBody()->getContents(), true);
|
||||
if ( empty($weather) ) {
|
||||
$data = [
|
||||
'weather' => '未知',
|
||||
'temperature' => '未知',
|
||||
'winddirection' => '未知',
|
||||
'reporttime' => '未知',
|
||||
'area' => '未知',
|
||||
'info' => '未知',
|
||||
];
|
||||
} else {
|
||||
$data = [
|
||||
'area' => $weather['data']['ipdata']['area'],
|
||||
'info' => $weather['data']['ipdata']['info'],
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取ip
|
||||
*/
|
||||
if (!function_exists('get_ip')) {
|
||||
function get_ip() {
|
||||
return $_SERVER['HTTP_X_FORWARDED_FOR']?? request()->getClientIp();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取操作系统
|
||||
* @return string
|
||||
*/
|
||||
if ( !function_exists('cc_get_os') ) {
|
||||
function cc_get_os(): string {
|
||||
if (!empty($_SERVER['HTTP_USER_AGENT'])) {
|
||||
$os = $_SERVER['HTTP_USER_AGENT'];
|
||||
|
||||
return match (true) {
|
||||
str_contains($os, 'Windows') => 'Windows',
|
||||
str_contains($os, 'Macintosh') => 'Mac',
|
||||
str_contains($os, 'Linux') => 'Linux',
|
||||
str_contains($os, 'Android') => 'Android',
|
||||
str_contains($os, 'iOS') => 'iOS',
|
||||
str_contains($os, 'Api') => 'Api Post',
|
||||
default => 'Unknown',
|
||||
};
|
||||
} else {
|
||||
return "获取访客操作系统信息失败!";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取浏览器
|
||||
* @return string
|
||||
*/
|
||||
if ( !function_exists('cc_get_browser') ) {
|
||||
function cc_get_browser(): string {
|
||||
if (empty($_SERVER['HTTP_USER_AGENT'])) {
|
||||
return "获取浏览器信息失败!";
|
||||
}
|
||||
|
||||
$userAgent = $_SERVER['HTTP_USER_AGENT'];
|
||||
|
||||
foreach ([
|
||||
'MSIE' => 'MSIE',
|
||||
'Edg' => 'Microsoft Edge',
|
||||
'Firefox' => 'Firefox',
|
||||
'Chrome' => 'Chrome',
|
||||
'Safari' => 'Safari',
|
||||
'Opera' => 'Opera',
|
||||
'Api' => 'Api Post',
|
||||
] as $key => $browser) {
|
||||
if (str_contains($userAgent, $key)) {
|
||||
return $browser;
|
||||
}
|
||||
}
|
||||
|
||||
return 'Other';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 在二维数组其中某个值相同时,提取指定的字段
|
||||
* @param $arr // 数组
|
||||
* @param $extract // 提取字段
|
||||
* @param $repeat // 重复字段
|
||||
* @param $isUnset // 是否删除未重复的值
|
||||
* @return array
|
||||
*/
|
||||
if ( !function_exists('cc_get_repeat_values') ) {
|
||||
function cc_get_repeat_values($arr, $extract, $repeat , $isUnset = false): array {
|
||||
$key = [];
|
||||
$result = [];
|
||||
$len = count($arr);
|
||||
for ( $i=0; $i<$len; $i++ ) {
|
||||
if ( !in_array($arr[$i][$repeat], $key) ) {
|
||||
if ( !array_key_exists($arr[$i][$repeat], $result) ) $result[$arr[$i][$repeat]] = [];
|
||||
$result[$arr[$i][$repeat]][] = $arr[$i][$extract];
|
||||
continue;
|
||||
}
|
||||
$key[] = $arr[$i][$repeat];
|
||||
}
|
||||
if ( $isUnset === true ) {
|
||||
// 删除未重复的下标
|
||||
foreach ( $result as $k => &$v ) {
|
||||
if ( count($v) <= 1 ) {
|
||||
unset($result[$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据脱敏
|
||||
* @param string $str
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
if ( !function_exists('desensitization') ) {
|
||||
|
||||
function desensitization(string $str, string $type = 'phone'): string
|
||||
{
|
||||
if (empty($str)) return '';
|
||||
|
||||
if ($type === 'phone') {
|
||||
if (strlen($str) !== 11) {
|
||||
throw new Exception('手机号格式错误');
|
||||
}
|
||||
return substr($str, 0, 3) . '****' . substr($str, 7);
|
||||
} elseif ($type === 'id_card') {
|
||||
if (strlen($str) !== 18) {
|
||||
throw new Exception('身份证号格式错误');
|
||||
}
|
||||
return substr($str, 0, 6) . '********' . substr($str, 14);
|
||||
} else {
|
||||
throw new Exception('类型错误');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 连赐福转换小驼峰
|
||||
* @param $string
|
||||
* @return string
|
||||
*/
|
||||
if(!function_exists('conjunction_symbol_processing')) {
|
||||
function conjunction_symbol_processing($string): string
|
||||
{
|
||||
$string = str_replace('-', ' ', $string); // 将连字符替换为空格
|
||||
$string = ucwords($string); // 将每个单词的首字母大写
|
||||
$string = str_replace(' ', '', $string); // 空格删除
|
||||
$string[0] = lcfirst($string)[0]; // 首字母小写
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 小驼峰转换-
|
||||
if ( !function_exists('cc_camel_case_to_dash') ) {
|
||||
function cc_camel_case_to_dash($str): string
|
||||
{
|
||||
return strtolower(preg_replace('/([a-z])([A-Z])/', '$1-$2', $str));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将驼峰字符串转化为下划线区分
|
||||
* @param $str
|
||||
* @return string
|
||||
*/
|
||||
if ( !function_exists('cc_camel_case_to_underscore') ) {
|
||||
function cc_camel_case_to_underscore($str): string
|
||||
{
|
||||
return strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $str));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 身份证脱敏
|
||||
* @return true
|
||||
*/
|
||||
if ( !function_exists('cc_id_card_text') ) {
|
||||
function cc_id_card_text($idCard): string {
|
||||
return substr_replace($idCard, '********', 6, 8 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号脱敏
|
||||
* @return true
|
||||
*/
|
||||
if ( !function_exists('cc_phone_text') ) {
|
||||
function cc_phone_text($phone): string {
|
||||
return substr_replace($phone, '******', 3, 6 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 身份证号验证
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
if ( !function_exists('cc_is_id_card') ) {
|
||||
function cc_is_id_card($id): bool {
|
||||
$id = strtoupper($id);
|
||||
$regx = "/(^\d{15}$)|(^\d{17}([0-9]|X)$)/";
|
||||
$arr_split = array();
|
||||
if (!preg_match($regx, $id)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (15 == strlen($id)) //检查15位
|
||||
{
|
||||
$regx = "/^(\d{6})+(\d{2})+(\d{2})+(\d{2})+(\d{3})$/";
|
||||
@preg_match($regx, $id, $arr_split);
|
||||
//检查生日日期是否正确
|
||||
$dtm_birth = "19" . $arr_split[2] . '/' . $arr_split[3] . '/' . $arr_split[4];
|
||||
if (!strtotime($dtm_birth)) {
|
||||
return FALSE;
|
||||
} else {
|
||||
return TRUE;
|
||||
}
|
||||
} else { //检查18位
|
||||
$regx = "/^(\d{6})+(\d{4})+(\d{2})+(\d{2})+(\d{3})([0-9]|X)$/";
|
||||
@preg_match($regx, $id, $arr_split);
|
||||
$dtm_birth = $arr_split[2] . '/' . $arr_split[3] . '/' . $arr_split[4];
|
||||
if (!strtotime($dtm_birth)) //检查生日日期是否正确
|
||||
{
|
||||
return FALSE;
|
||||
} else {
|
||||
//检验18位身份证的校验码是否正确。
|
||||
//校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
|
||||
$arr_int = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
|
||||
$arr_ch = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
|
||||
$sign = 0;
|
||||
for ($i = 0; $i < 17; $i++) {
|
||||
$b = (int) $id[$i];
|
||||
$w = $arr_int[$i];
|
||||
$sign += $b * $w;
|
||||
}
|
||||
$n = $sign % 11;
|
||||
$val_num = $arr_ch[$n];
|
||||
if ($val_num != substr($id, 17, 1)) {
|
||||
return FALSE;
|
||||
} else {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分割数字
|
||||
*/
|
||||
if (!function_exists('money_format')) {
|
||||
function money_format($number) {
|
||||
return preg_replace("/(?=\B(\d{3})+$)/", ',', $number);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码加密处理
|
||||
* @param $password
|
||||
* @return string
|
||||
*/
|
||||
if (!function_exists('ase_password')) {
|
||||
function ase_password($password): string
|
||||
{
|
||||
return sha1($password. config('cc.configs.ase.slate'));
|
||||
}
|
||||
}
|
||||
|
||||
// 获取当前项目启动的地址
|
||||
if (!function_exists('cc_get_project_url')) {
|
||||
function cc_get_project_url(): string
|
||||
{
|
||||
$url = config('cc.configs.project_url');
|
||||
if (empty($url)) {
|
||||
$url = request()->root(true);
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密
|
||||
* @param $str
|
||||
* @return mixed|string
|
||||
*/
|
||||
if(!function_exists('ase_encode')) {
|
||||
function ase_encode($str)
|
||||
{
|
||||
if (empty($str)) return $str;
|
||||
return base64_encode(\Illuminate\Support\Str::random(config('ase.len')). base64_encode($str));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密
|
||||
* @param $str
|
||||
* @return false|string
|
||||
*/
|
||||
if (!function_exists('ase_decode')) {
|
||||
function ase_decode($str): bool|string
|
||||
{
|
||||
if (empty($str)) return $str?? '';
|
||||
$result = base64_decode($str);
|
||||
$result = base64_decode(substr($result, config('ase.len')));
|
||||
$pattern = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\xFF]|[\x{E000}-\x{F8FF}]/u';
|
||||
if (preg_match($pattern, $result)) return $str;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取选中的时间段有几天
|
||||
*
|
||||
* @param $startTime
|
||||
* @param $endTime
|
||||
* @return array
|
||||
*/
|
||||
if (!function_exists('get_day_list')) {
|
||||
function get_day_list($startTime, $endTime): array
|
||||
{
|
||||
$day = [];
|
||||
$currentTime = $startTime;
|
||||
while ($currentTime <= $endTime) {
|
||||
$day[] = date('m-d', $currentTime);
|
||||
$currentTime = strtotime('+1 day', $currentTime);
|
||||
}
|
||||
return $day;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取选中的时间段有几个月
|
||||
*
|
||||
* @param $startTime
|
||||
* @param $endTime
|
||||
* @return array
|
||||
*/
|
||||
if (!function_exists('get_month_list')) {
|
||||
function get_month_list($startTime, $endTime): array
|
||||
{
|
||||
$monthList = [];
|
||||
$currentTime = $startTime;
|
||||
while ($currentTime <= $endTime) {
|
||||
$monthList[] = date('Y-m', $currentTime);
|
||||
$currentTime = strtotime('+1 month', $currentTime);
|
||||
}
|
||||
return $monthList;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成32位的uuid
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
if (!function_exists('gen_uuid')) {
|
||||
function gen_uuid(): string
|
||||
{
|
||||
$chart = md5(uniqid(rand(), true));
|
||||
$hyphen = chr(45);// "-"
|
||||
return substr($chart, 0, 8) . $hyphen
|
||||
. substr($chart, 8, 4) . $hyphen
|
||||
. substr($chart, 12, 4) . $hyphen
|
||||
. substr($chart, 16, 4) . $hyphen
|
||||
. substr($chart, 20, 12);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时间
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
if (!function_exists('get_time')) {
|
||||
function get_time($isString = false, $format = 'Y-m-d H:i:s'): string
|
||||
{
|
||||
return $isString === true ? date($format) : time();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
if (!function_exists('format_time')) {
|
||||
function format_time($time, $format = 'Y-m-d H:i:s'): string
|
||||
{
|
||||
return !empty($time)? date($format, $time) : '';
|
||||
}
|
||||
}
|
||||
112
config/response.php
Executable file
112
config/response.php
Executable file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
|
||||
# 返回封装
|
||||
|
||||
/**
|
||||
* 请求成功返回
|
||||
* @param $data
|
||||
* @param $msg
|
||||
* @param $code
|
||||
* @return JsonResponse
|
||||
*/
|
||||
if ( !function_exists('jok') ) {
|
||||
function jok($data = [], $msg = '请求成功'): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'code' => 0,
|
||||
'message' => $msg,
|
||||
'result' => $data,
|
||||
'type' => 'success'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求失败返回
|
||||
* @param $data
|
||||
* @param $msg
|
||||
* @param $code
|
||||
* @return JsonResponse
|
||||
*/
|
||||
if ( !function_exists('jerr') ) {
|
||||
#[NoReturn]
|
||||
function jerr($msg = '', $data = [], $code = 500): JsonResponse
|
||||
{
|
||||
exit(json_encode([
|
||||
'code' => $code,
|
||||
'message' => $msg,
|
||||
'result' => $data,
|
||||
'type' => 'error'
|
||||
], JSON_UNESCAPED_UNICODE, JSON_PARTIAL_OUTPUT_ON_ERROR));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 异常返回(他会阻止后面所有代码的运行)
|
||||
* @param $data
|
||||
* @param $msg
|
||||
* @param $code
|
||||
* @return JsonResponse
|
||||
*/
|
||||
if ( !function_exists('jInstanceof') ) {
|
||||
function jInstanceof($code = 500, $msg = '错误返回', $data = []): JsonResponse
|
||||
{
|
||||
|
||||
// 转换成秒
|
||||
$timeDifference = microtime(true) - LARAVEL_START;
|
||||
|
||||
return response()->json([
|
||||
'code' => $code,
|
||||
'message' => $msg,
|
||||
'result' => $data,
|
||||
'type' => 'error',
|
||||
'interface_info' => [
|
||||
'result_time' => $timeDifference < 1? round($timeDifference * 1000) . ' ms': number_format($timeDifference, 1) . ' s',
|
||||
'ecs' => env('ECS')
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 (他会阻止后面所有代码的运行)
|
||||
* @param $data
|
||||
* @param $msg
|
||||
* @param $code
|
||||
* @return void
|
||||
*/
|
||||
if ( !function_exists('ds') ) {
|
||||
#[NoReturn]
|
||||
function ds($data = [], $msg = '测试返回'): void
|
||||
{
|
||||
exit(json_encode([
|
||||
'code' => 19522,
|
||||
'message' => $msg,
|
||||
'result' => $data,
|
||||
'type' => 'success'
|
||||
],JSON_UNESCAPED_SLASHES,JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 身份过期返回(他会阻止后面所有代码的运行)
|
||||
* @param $data
|
||||
* @param $msg
|
||||
* @param $code
|
||||
* @return void
|
||||
*/
|
||||
if ( !function_exists('jexpire') ) {
|
||||
#[NoReturn]
|
||||
function jexpire($msg = '身份过期', $data = []): void
|
||||
{
|
||||
exit(json_encode([
|
||||
'code' => 401,
|
||||
'message' => $msg,
|
||||
'result' => $data,
|
||||
'type' => 'jexpire'
|
||||
],JSON_UNESCAPED_SLASHES,JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user