完善代码

This commit is contained in:
yumo 2023-11-15 20:23:39 +08:00
parent a96251cab4
commit b8002d2503
7 changed files with 23 additions and 53 deletions

View File

@ -27,14 +27,14 @@ if (!function_exists('auth_is_exit')) {
if (!function_exists('remove_cache')) {
/**
* 删除缓存
* 删除缓存文件
* @param string $path
* @return bool
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
function remove_cache(string $path): bool
{
$res = true;
$res = false;
if (is_dir($path)) {
if ($handle = opendir($path)) {
while (false !== ($item = readdir($handle))) {
@ -51,7 +51,6 @@ if (!function_exists('remove_cache')) {
}
}
if (!function_exists('to_int_array')) {
/**
* 字符串数组转int数组
@ -112,7 +111,7 @@ if (!function_exists('get_dir')) {
function get_dir($dir): mixed
{
$dirArray[] = NULL;
if (false != ($handle = opendir($dir))) {
if (($handle = opendir($dir))) {
$i = 0;
while (false !== ($file = readdir($handle))) {
//去掉"“.”、“..”以及带“.xxx”后缀的文件

View File

@ -55,17 +55,19 @@ class Admin extends AuthController
['status', ''],
['page', 1],
['limit', 20],
]);
],$request);
return app("json")->layui(aModel::systemPage($where));
}
/**
* 添加账号
* @param Request $request
* @return string
* @throws DataNotFoundException
* @throws DbException
* @throws FormBuilderException
* @throws ModelNotFoundException
*/
public function add(Request $request): string
public function add(): string
{
$form = array();
$form[] = Elm::input('username', '登录账号')->col(10);
@ -188,11 +190,10 @@ class Admin extends AuthController
/**
* 修改密码
* @param Request $request
* @return string
* @throws \Exception
*/
public function pwd(Request $request): string
public function pwd(): string
{
return $this->fetch();
}
@ -207,7 +208,7 @@ class Admin extends AuthController
$data = Util::postMore([
['oldpwd', ''],
['newpwd', '']
]);
],$request);
if ($data['oldpwd'] == '' || $data['newpwd'] == '') return app("json")->fail("参数有误,新旧密码为空!");
$adminInfo = aModel::find($this->adminId);
if ($adminInfo['password'] == md5(md5($data['oldpwd']))) return aModel::update(['password' => md5(md5($data['newpwd']))], ['id' => $this->adminId]) ? app("json")->success("操作成功") : app("json")->fail("操作失败");
@ -230,7 +231,7 @@ class Admin extends AuthController
* @param Request $request
* @return mixed
*/
public function changProfile(Request $request)
public function changProfile(Request $request): mixed
{
$data = Util::postMore([
['nickname', ''],

View File

@ -17,10 +17,10 @@ class FormBuilder
* 生成表单
* @param $rule
* @param $url
* @return string
* @return string|IviewForm
* @throws FormBuilderException
*/
public static function make_post_form($rule, $url)
public static function make_post_form($rule, $url): string|IviewForm
{
$form = new IviewForm($url);
$form->setMethod('POST');

View File

@ -164,7 +164,7 @@ class AdminAuth extends BaseModel
public static function myOptions(array $data, &$list, $num = 0, $clear = true)
{
foreach ($data as $k => $v) {
$list[] = ['value' => $v['id'], 'label' => self::cross($num) . $v['name']];
$list[] = ['value' => $v['id'], 'label' => cross($num) . $v['name']];
if (is_array($v['children']) && !empty($v['children'])) {
self::myOptions($v['children'], $list, $num + 1, false);
}
@ -186,21 +186,6 @@ class AdminAuth extends BaseModel
return $list;
}
/**
* 横线
* @param int $num
* @return string
*/
public static function cross(int $num = 0): string
{
$str = "";
if ($num == 1) $str .= "|--";
elseif ($num > 1) for ($i = 0; $i < $num; $i++)
if ($i == 0) $str .= "|--";
else $str .= "--";
return $str . " ";
}
/**
* 生成treeData
* @param int $pid

View File

@ -25,7 +25,7 @@ class AdminLog extends BaseModel
*/
public static function saveLog(array $adminInfo, string $module, string $controller, string $action): bool
{
return self::create([
return (bool)self::create([
'admin_id' => $adminInfo['id'],
'admin_name' => $adminInfo['username'],
'module' => $module,
@ -34,7 +34,7 @@ class AdminLog extends BaseModel
'ip' => request()->ip(),
'create_time' => time(),
'user_agent' => substr(request()->server('HTTP_USER_AGENT'), 0, 255),
]) ? true : false;
]);
}
/**
@ -43,7 +43,7 @@ class AdminLog extends BaseModel
* @return array
* @throws DbException
*/
public static function systemPage($where)
public static function systemPage($where): array
{
$model = new self;
$model = $model->order("id desc");

View File

@ -67,7 +67,7 @@ class Nav extends BaseModel
public static function myOptions(array $data, &$list, $num = 0, $clear = true)
{
foreach ($data as $k => $v) {
$list[] = ['value' => $v['id'], 'label' => self::cross($num) . $v['title']];
$list[] = ['value' => $v['id'], 'label' => cross($num) . $v['title']];
if (is_array($v['children']) && !empty($v['children'])) {
self::myOptions($v['children'], $list, $num + 1, false);
}
@ -89,21 +89,6 @@ class Nav extends BaseModel
return $list;
}
/**
* 横线
* @param int $num
* @return string
*/
public static function cross(int $num = 0): string
{
$str = "";
if ($num == 1) $str .= "|--";
elseif ($num > 1) for ($i = 0; $i < $num; $i++)
if ($i == 0) $str .= "|--";
else $str .= "--";
return $str . " ";
}
/**
* 生成单个节点
* @param $id

View File

@ -23,7 +23,7 @@ use think\facade\Db;
* @param $len
* @return string
*/
function cn_substr($str, $len)
function cn_substr($str, $len): string
{
return mb_substr($str, 0, $len, 'utf-8');
}
@ -31,7 +31,7 @@ function cn_substr($str, $len)
/**
* 过滤html标签
*/
function html2text($str)
function html2text($str): string
{
return strip_tags($str);
}
@ -1180,7 +1180,7 @@ function tpl_get_nav($type, $typeId, $row = 100, $where = '', $orderby = '')
function get_nav($x, $field = false)
{
if (!$x) {
throw new Exception('请指定要获取的栏目导航id');
return false;
}
//获取缓存的文章菜单
$list = get_nav_list();
@ -1213,7 +1213,7 @@ function get_nav_list()
return $navList;
}
function get_nav_all()
function get_nav_all(): array
{
$list = get_nav_list();
$tempArr = array();
@ -1232,7 +1232,7 @@ function get_nav_all()
* $pid=父级id
* $row=获取多少数目
*/
function get_nav_by_parent($pid, $row)
function get_nav_by_parent($pid, $row): array
{
$list = get_nav_list();
$x = 1;