🚀 202405重置版

This commit is contained in:
wolfcode
2024-05-13 11:16:20 +08:00
parent 504ab4c4cf
commit a6fd81b0ed
242 changed files with 1169 additions and 2698 deletions

View File

@@ -2,6 +2,9 @@
// 应用公共文件
use app\common\service\AuthService;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Cache;
if (!function_exists('__url')) {
@@ -14,7 +17,7 @@ if (!function_exists('__url')) {
* @param bool $domain
* @return string
*/
function __url(string $url = '', array $vars = [], $suffix = true, $domain = false)
function __url(string $url = '', array $vars = [], bool $suffix = true, bool $domain = false): string
{
return url($url, $vars, $suffix, $domain)->build();
}
@@ -24,11 +27,10 @@ if (!function_exists('password')) {
/**
* 密码加密算法
* @param $value 需要加密的值
* @param $type 加密类型默认为md5 md5, hash
* @return mixed
* @param $value
* @return string
*/
function password($value)
function password($value): string
{
$value = sha1('blog_') . md5($value) . md5('_encrypt') . sha1($value);
return sha1($value);
@@ -36,49 +38,27 @@ if (!function_exists('password')) {
}
if (!function_exists('xdebug')) {
/**
* debug调试
* @param string|array $data 打印信息
* @param string $type 类型
* @param string $suffix 文件后缀名
* @param bool $force
* @param null $file
* @deprecated 不建议使用建议直接使用框架自带的log组件
*/
function xdebug($data, $type = 'xdebug', $suffix = null, $force = false, $file = null)
{
!is_dir(runtime_path() . 'xdebug/') && mkdir(runtime_path() . 'xdebug/');
if (is_null($file)) {
$file = is_null($suffix) ? runtime_path() . 'xdebug/' . date('Ymd') . '.txt' : runtime_path() . 'xdebug/' . date('Ymd') . "_{$suffix}" . '.txt';
}
file_put_contents($file, "[" . date('Y-m-d H:i:s') . "] " . "========================= {$type} ===========================" . PHP_EOL, FILE_APPEND);
$str = ((is_string($data) ? $data : (is_array($data) || is_object($data))) ? print_r($data, true) : var_export($data, true)) . PHP_EOL;
$force ? file_put_contents($file, $str) : file_put_contents($file, $str, FILE_APPEND);
}
}
if (!function_exists('sysconfig')) {
if (!function_exists('sysConfig')) {
/**
* 获取系统配置信息
* @param $group
* @param null $name
* @return array|mixed
* @param $name
* @return mixed
*/
function sysconfig($group, $name = null)
function sysConfig($group, $name = null): mixed
{
$where = ['group' => $group];
$value = empty($name) ? Cache::get("sysconfig_{$group}") : Cache::get("sysconfig_{$group}_{$name}");
$value = empty($name) ? Cache::get("sysConfig_{$group}") : Cache::get("sysConfig_{$group}_{$name}");
if (empty($value)) {
if (!empty($name)) {
$where['name'] = $name;
$value = \app\admin\model\SystemConfig::where($where)->value('value');
Cache::tag('sysconfig')->set("sysconfig_{$group}_{$name}", $value, 3600);
} else {
Cache::tag('sysConfig')->set("sysConfig_{$group}_{$name}", $value, 3600);
}else {
$value = \app\admin\model\SystemConfig::where($where)->column('value', 'name');
Cache::tag('sysconfig')->set("sysconfig_{$group}", $value, 3600);
Cache::tag('sysConfig')->set("sysConfig_{$group}", $value, 3600);
}
}
return $value;
@@ -93,7 +73,7 @@ if (!function_exists('array_format_key')) {
* @param $key
* @return array
*/
function array_format_key($array, $key)
function array_format_key($array, $key): array
{
$newArray = [];
foreach ($array as $vo) {
@@ -110,15 +90,14 @@ if (!function_exists('auth')) {
* auth权限验证
* @param $node
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
function auth($node = null)
function auth($node = null): bool
{
$authService = new AuthService(session('admin.id'));
$check = $authService->checkNode($node);
return $check;
return $authService->checkNode($node);
}
/**
@@ -129,11 +108,11 @@ if (!function_exists('auth')) {
*/
function editor_textarea(string $detail, string $name = 'desc', string $placeholder = '请输入'): string
{
$editor_type = sysconfig('site', 'editor_type');
$editor_type = sysConfig('site', 'editor_type');
return match ($editor_type) {
'ckeditor' => "<textarea name='{$name}' rows='20' class='layui-textarea editor' placeholder='{$placeholder}'>{$detail}</textarea>",
'ckeditor' => "<textarea name='{$name}' rows='20' class='layui-textarea editor' placeholder='{$placeholder}'>{$detail}</textarea>",
'wangEditor' => "<div class='wangEditor_div'><textarea name='{$name}' rows='20' class='layui-textarea editor layui-hide'>{$detail}</textarea><div id='editor_toolbar_{$name}'></div><div id='editor_{$name}' style='height: 300px'></div></div>",
default => "<script type='text/plain' id='{$name}' name='{$name}' class='editor' data-content='{$detail}'></script>",
default => "<script type='text/plain' id='{$name}' name='{$name}' class='editor' data-content='{$detail}'></script>",
};
}
}