140 lines
3.1 KiB
PHP
140 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace app\crm\utils;
|
|
|
|
use Firebase\JWT\JWT;
|
|
use Firebase\JWT\Key;
|
|
use Firebase\JWT\ExpiredException;
|
|
use Firebase\JWT\SignatureInvalidException;
|
|
use support\exception\BusinessException;
|
|
use support\Log;
|
|
use support\Request;
|
|
|
|
class Util
|
|
{
|
|
/**
|
|
* 参数是否为空
|
|
*/
|
|
public static function isEmpty($param)
|
|
{
|
|
if(!empty($param) || $param == 0){
|
|
$result = false;
|
|
}else{
|
|
$result = true;
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 参数是否为空
|
|
*/
|
|
public static function getParam(Request $request,$param,$default='')
|
|
{
|
|
$param = $request->input($param,$default);
|
|
if(empty($param) && $default!==''){
|
|
$param = $default;
|
|
}
|
|
return $param;
|
|
}
|
|
|
|
/**
|
|
* 失败
|
|
*/
|
|
public static function fail($data = [],$message = '', $code = -1)
|
|
{
|
|
$result = [
|
|
'code' => $code,
|
|
'message' => $message,
|
|
'data' => $data
|
|
];
|
|
return json($result);
|
|
}
|
|
|
|
/**
|
|
* 成功
|
|
*/
|
|
public static function success($data = [],$message = '', $code = 0)
|
|
{
|
|
$result = [
|
|
'code' => $code,
|
|
'message' => $message,
|
|
'data' => $data
|
|
];
|
|
return json($result);
|
|
}
|
|
|
|
/**
|
|
* 分页查询返回
|
|
*/
|
|
public static function page($data,$message = '', $code = 0)
|
|
{
|
|
$result = [
|
|
'code' => $code,
|
|
'message' => $message
|
|
];
|
|
|
|
$result['data'] = [
|
|
'list' => $data->items(), // 当前页数据
|
|
'total' => $data->total(), // 总记录数
|
|
'current_page' => $data->currentPage(),
|
|
'per_page' => $data->perPage(),
|
|
'last_page' => $data->lastPage()
|
|
];
|
|
return json($result);
|
|
}
|
|
|
|
/**
|
|
* 日期格式转化
|
|
*/
|
|
public static function timeTotDate($time = 0, $format = 'Y-m-d H:i:s')
|
|
{
|
|
if (empty($time)) {
|
|
return '';
|
|
}
|
|
return date($format, $time);
|
|
}
|
|
|
|
/**
|
|
* 格式化创建时间
|
|
*/
|
|
public static function formatDate($value,$key = ['created_at','updated_at'])
|
|
{
|
|
foreach ($key as $k){
|
|
// 如果是整数,可能是 UNIX 时间戳
|
|
if (is_numeric($value[$k]) && $value[$k] > 0) {
|
|
// 检查是否是合理的时间戳范围(1970-2100年)
|
|
if ($value[$k] >= 0 && $value[$k] <= 4102444800) {
|
|
$value[$k]= self::timeTotDate($value[$k]);
|
|
}
|
|
}
|
|
}
|
|
return $value;
|
|
}
|
|
|
|
/**
|
|
* 格式化创建时间
|
|
*/
|
|
public static function language($language,$en,$zh_CN,$ru)
|
|
{
|
|
if ($language == 'zh_CN'){
|
|
return $zh_CN;
|
|
}elseif ($language == 'ru'){
|
|
return $ru;
|
|
}
|
|
return $en;
|
|
}
|
|
|
|
public static function mask($str)
|
|
{
|
|
$length = mb_strlen($str);
|
|
|
|
if(empty($str)){
|
|
return '';
|
|
}
|
|
if($length <= 6){
|
|
return $str;
|
|
}
|
|
return substr($str, 0, 3) . '****' . substr($str, -4);
|
|
}
|
|
|
|
} |