mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
80 lines
2.1 KiB
PHP
80 lines
2.1 KiB
PHP
<?php
|
|
/**
|
|
*
|
|
* @since 2017-11-01
|
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
*/
|
|
|
|
namespace app\util;
|
|
|
|
|
|
class Tools {
|
|
|
|
public static function getDate($timestamp) {
|
|
$now = time();
|
|
$diff = $now - $timestamp;
|
|
if ($diff <= 60) {
|
|
return $diff . '秒前';
|
|
} elseif ($diff <= 3600) {
|
|
return floor($diff / 60) . '分钟前';
|
|
} elseif ($diff <= 86400) {
|
|
return floor($diff / 3600) . '小时前';
|
|
} elseif ($diff <= 2592000) {
|
|
return floor($diff / 86400) . '天前';
|
|
} else {
|
|
return '一个月前';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 二次封装的密码加密
|
|
* @param $str
|
|
* @param string $auth_key
|
|
* @return string
|
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
*/
|
|
public static function userMd5($str, $auth_key = '') {
|
|
if (!$auth_key) {
|
|
$auth_key = config('apiAdmin.AUTH_KEY');
|
|
}
|
|
|
|
return '' === $str ? '' : md5(sha1($str) . $auth_key);
|
|
}
|
|
|
|
/**
|
|
* 判断当前用户是否是超级管理员
|
|
* @param string $uid
|
|
* @return bool
|
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
*/
|
|
public static function isAdministrator($uid = '') {
|
|
if (!empty($uid)) {
|
|
$adminConf = config('apiAdmin.USER_ADMINISTRATOR');
|
|
if (is_array($adminConf)) {
|
|
if (is_array($uid)) {
|
|
$m = array_intersect($adminConf, $uid);
|
|
if (count($m)) {
|
|
return true;
|
|
}
|
|
} else {
|
|
if (in_array($uid, $adminConf)) {
|
|
return true;
|
|
}
|
|
}
|
|
} else {
|
|
if (is_array($uid)) {
|
|
if (in_array($adminConf, $uid)) {
|
|
return true;
|
|
}
|
|
} else {
|
|
if ($uid == $adminConf) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|