更新若干代码
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
namespace app\admin\controller;
|
||||
use app\admin\controller\Base;
|
||||
use app\admin\model\Article\Article;
|
||||
use app\admin\model\ArticleCategory;
|
||||
use app\admin\model\Article\ArticleCategory;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
use think\facade\Request;
|
||||
@@ -18,20 +18,18 @@ class Articles extends Base
|
||||
{
|
||||
if (Request::isPost()) {
|
||||
$category = input('post.category');
|
||||
$page = input('post.page', 1);
|
||||
$limit = input('post.limit', 10);
|
||||
$page = intval(input('post.page', 1));
|
||||
$limit = intval(input('post.limit', 10));
|
||||
$title = input('post.title');
|
||||
$author = input('post.author');
|
||||
|
||||
$query = Db::name('article')
|
||||
->where('delete_time', null)
|
||||
$query = Article::where('delete_time', null)
|
||||
->where('status', '<>', 3);
|
||||
|
||||
// 分类筛选
|
||||
if (!empty($category)) {
|
||||
// 先获取分类ID
|
||||
$cateInfo = Db::name('article_category')
|
||||
->where('name', $category)
|
||||
$cateInfo = ArticleCategory::where('name', $category)
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->find();
|
||||
@@ -60,22 +58,21 @@ class Articles extends Base
|
||||
->select()
|
||||
->each(function ($item) {
|
||||
// 获取分类信息
|
||||
$cateInfo = Db::name('article_category')
|
||||
->where('id', $item['cate'])
|
||||
$cateInfo = ArticleCategory::where('id', $item['cate'])
|
||||
->field('name, image')
|
||||
->find();
|
||||
|
||||
// 设置分类名称
|
||||
$item['cate'] = $cateInfo['name'];
|
||||
$item['cate'] = $cateInfo ? $cateInfo['name'] : '';
|
||||
|
||||
// 如果文章没有图片,使用分类的图片
|
||||
if (empty($item['image']) && !empty($cateInfo['image'])) {
|
||||
if (empty($item['image']) && $cateInfo && !empty($cateInfo['image'])) {
|
||||
$item['image'] = $cateInfo['image'];
|
||||
}
|
||||
|
||||
// 格式化时间
|
||||
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
|
||||
$item['publishdate'] = $item['publishdate'] ? date('Y-m-d H:i:s', $item['publishdate']) : '';
|
||||
$item['create_time'] = is_numeric($item['create_time']) ? date('Y-m-d H:i:s', $item['create_time']) : $item['create_time'];
|
||||
$item['publishdate'] = is_numeric($item['publishdate']) ? date('Y-m-d H:i:s', $item['publishdate']) : '';
|
||||
|
||||
return $item;
|
||||
});
|
||||
@@ -88,8 +85,7 @@ class Articles extends Base
|
||||
]);
|
||||
} else {
|
||||
// 获取所有分类并构建父子结构
|
||||
$allCategories = Db::name('article_category')
|
||||
->where('delete_time', null)
|
||||
$allCategories = ArticleCategory::where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->order('sort asc, id asc')
|
||||
->select()
|
||||
@@ -131,7 +127,7 @@ class Articles extends Base
|
||||
'create_time' => time()
|
||||
];
|
||||
|
||||
$insert = Db::name('article')->insert($data);
|
||||
$insert = Article::insert($data);
|
||||
if (empty($insert)) {
|
||||
Log::record('添加文章', 0, '添加文章失败', '文章管理');
|
||||
return json(['code' => 1, 'msg' => '添加失败', 'data' => []]);
|
||||
@@ -139,8 +135,7 @@ class Articles extends Base
|
||||
Log::record('添加文章', 1, '', '文章管理');
|
||||
return json(['code' => 0, 'msg' => '添加成功', 'data' => []]);
|
||||
} else {
|
||||
$lists = Db::name('article')
|
||||
->order('id DESC')
|
||||
$lists = Article::order('id DESC')
|
||||
->select()
|
||||
->each(function ($item, $key) {
|
||||
$item['create_time'] = time();
|
||||
@@ -169,7 +164,7 @@ class Articles extends Base
|
||||
'update_time' => time()
|
||||
];
|
||||
|
||||
$update = Db::name('article')->where('id', $id)->update($data);
|
||||
$update = Article::where('id', $id)->update($data);
|
||||
if ($update === false) {
|
||||
Log::record('编辑文章', 0, '编辑文章失败', '文章管理');
|
||||
return json(['code' => 1, 'msg' => '更新失败', 'data' => []]);
|
||||
@@ -178,13 +173,12 @@ class Articles extends Base
|
||||
return json(['code' => 0, 'msg' => '更新成功', 'data' => []]);
|
||||
} else {
|
||||
$id = input('get.id');
|
||||
$info = Db::name('article')->where('id', $id)->find();
|
||||
$info = Article::where('id', $id)->find();
|
||||
if ($info === null) {
|
||||
return json(['code' => 1, 'msg' => '文章不存在', 'data' => []]);
|
||||
}
|
||||
|
||||
$cates = Db::name('article_category')
|
||||
->where('delete_time', null)
|
||||
$cates = ArticleCategory::where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->order('sort asc, id asc')
|
||||
->select()
|
||||
@@ -192,8 +186,7 @@ class Articles extends Base
|
||||
|
||||
$info['content'] = !empty($info['content']) ? htmlspecialchars_decode(str_replace(["\r\n", "\r", "\n"], '', addslashes($info['content']))) : '';
|
||||
|
||||
$currentCate = Db::name('article_category')
|
||||
->where('id', $info['cate'])
|
||||
$currentCate = ArticleCategory::where('id', $info['cate'])
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->find();
|
||||
@@ -214,7 +207,7 @@ class Articles extends Base
|
||||
$data = [
|
||||
'delete_time' => time(),
|
||||
];
|
||||
$delete = Db::name('article')->where('id', $id)->update($data);
|
||||
$delete = Article::where('id', $id)->update($data);
|
||||
if ($delete === false) {
|
||||
Log::record('删除文章', 0, '删除文章失败', '文章管理');
|
||||
return json(['code' => 1, 'msg' => '删除失败', 'data' => []]);
|
||||
@@ -227,8 +220,7 @@ class Articles extends Base
|
||||
public function articlecate()
|
||||
{
|
||||
if (Request::isPost()) {
|
||||
$lists = Db::name('article_category')
|
||||
->where('delete_time', null)
|
||||
$lists = ArticleCategory::where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->order('sort asc, id asc')
|
||||
->select()
|
||||
@@ -270,8 +262,7 @@ class Articles extends Base
|
||||
public function getcate()
|
||||
{
|
||||
// 获取所有分类
|
||||
$lists = Db::name('article_category')
|
||||
->where('delete_time', null)
|
||||
$lists = ArticleCategory::where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->order('sort asc, id asc')
|
||||
->select()
|
||||
@@ -313,7 +304,7 @@ class Articles extends Base
|
||||
'create_time' => time()
|
||||
];
|
||||
|
||||
$insert = Db::name('article_category')->insert($data);
|
||||
$insert = ArticleCategory::insert($data);
|
||||
if (empty($insert)) {
|
||||
Log::record('添加文章分类', 0, '添加文章分类失败', '文章分类');
|
||||
return json(['code' => 1, 'msg' => '添加失败', 'data' => []]);
|
||||
@@ -322,8 +313,7 @@ class Articles extends Base
|
||||
return json(['code' => 0, 'msg' => '添加成功', 'data' => []]);
|
||||
} else {
|
||||
// 获取所有可选的父级分类
|
||||
$parentCategories = Db::name('article_category')
|
||||
->where('delete_time', null)
|
||||
$parentCategories = ArticleCategory::where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->where('cid', 0)
|
||||
->field('id, name')
|
||||
@@ -354,8 +344,7 @@ class Articles extends Base
|
||||
'update_time' => time()
|
||||
];
|
||||
|
||||
$update = Db::name('article_category')
|
||||
->where('id', $data['id'])
|
||||
$update = ArticleCategory::where('id', $data['id'])
|
||||
->update($data);
|
||||
|
||||
if ($update === false) {
|
||||
@@ -366,11 +355,10 @@ class Articles extends Base
|
||||
return json(['code' => 0, 'msg' => '更新成功', 'data' => []]);
|
||||
} else {
|
||||
$id = input('get.id');
|
||||
$info = Db::name('article_category')->where('id', $id)->find();
|
||||
$info = ArticleCategory::where('id', $id)->find();
|
||||
|
||||
// 获取所有可选的父级分类
|
||||
$parentCategories = Db::name('article_category')
|
||||
->where('delete_time', null)
|
||||
$parentCategories = ArticleCategory::where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->where('id', '<>', $id) // 排除自己
|
||||
->where(function ($query) use ($id) {
|
||||
@@ -409,8 +397,7 @@ class Articles extends Base
|
||||
$id = input('post.id');
|
||||
|
||||
// 检查是否有子分类
|
||||
$hasChildren = Db::name('article_category')
|
||||
->where('cid', $id)
|
||||
$hasChildren = ArticleCategory::where('cid', $id)
|
||||
->where('delete_time', null)
|
||||
->find();
|
||||
|
||||
@@ -419,8 +406,7 @@ class Articles extends Base
|
||||
return json(['code' => 1, 'msg' => '该分类下有子分类,无法删除', 'data' => []]);
|
||||
}
|
||||
|
||||
$delete = Db::name('article_category')
|
||||
->where('id', $id)
|
||||
$delete = ArticleCategory::where('id', $id)
|
||||
->update(['delete_time' => time()]);
|
||||
|
||||
if ($delete === false) {
|
||||
@@ -433,8 +419,7 @@ class Articles extends Base
|
||||
|
||||
//统计文章数量
|
||||
public function counts() {
|
||||
$total = Db::name('article')
|
||||
->where('delete_time', null)
|
||||
$total = Article::where('delete_time', null)
|
||||
->where('status', '<>', 3)
|
||||
->count();
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ use think\facade\Db;
|
||||
use think\facade\Request;
|
||||
use think\facade\View;
|
||||
use think\facade\Cookie;
|
||||
use app\admin\model\Log\LogsLogin;
|
||||
use app\admin\model\Log\LogsOperation;
|
||||
|
||||
class Log extends Base
|
||||
{
|
||||
@@ -23,27 +25,25 @@ class Log extends Base
|
||||
$startTime = input('post.start_time');
|
||||
$endTime = input('post.end_time');
|
||||
|
||||
$query = Db::name('yz_logs_login');
|
||||
|
||||
// 搜索条件
|
||||
if ($username) {
|
||||
$query = $query->where('username', 'like', "%{$username}%");
|
||||
$query = LogsLogin::where('username', 'like', "%{$username}%");
|
||||
}
|
||||
if ($ip) {
|
||||
$query = $query->where('ip_address', 'like', "%{$ip}%");
|
||||
$query = LogsLogin::where('ip_address', 'like', "%{$ip}%");
|
||||
}
|
||||
if ($status !== '') {
|
||||
$query = $query->where('login_status', $status);
|
||||
$query = LogsLogin::where('login_status', $status);
|
||||
}
|
||||
if ($startTime) {
|
||||
$query = $query->where('login_time', '>=', $startTime);
|
||||
$query = LogsLogin::where('login_time', '>=', $startTime);
|
||||
}
|
||||
if ($endTime) {
|
||||
$query = $query->where('login_time', '<=', $endTime);
|
||||
$query = LogsLogin::where('login_time', '<=', $endTime);
|
||||
}
|
||||
|
||||
$count = $query->count();
|
||||
$list = $query->order('id desc')
|
||||
$count = LogsLogin::count();
|
||||
$list = LogsLogin::order('id desc')
|
||||
->page($page, $limit)
|
||||
->select();
|
||||
|
||||
@@ -67,8 +67,6 @@ class Log extends Base
|
||||
$page = $params['page'] ?? 1;
|
||||
$limit = $params['limit'] ?? 10;
|
||||
|
||||
$query = Db::name('yz_logs_operation');
|
||||
|
||||
// 构建搜索条件
|
||||
$searchFields = [
|
||||
'username' => ['field' => 'username', 'type' => 'like'],
|
||||
@@ -79,6 +77,8 @@ class Log extends Base
|
||||
'end_time' => ['field' => 'operation_time', 'type' => '<=']
|
||||
];
|
||||
|
||||
$query = LogsOperation::where('1=1');
|
||||
|
||||
foreach ($searchFields as $param => $config) {
|
||||
if (!empty($params[$param])) {
|
||||
$value = $params[$param];
|
||||
@@ -89,8 +89,9 @@ class Log extends Base
|
||||
}
|
||||
}
|
||||
|
||||
$count = $query->count();
|
||||
$list = $query->order('id desc')
|
||||
$count = LogsOperation::where('1=1')->count();
|
||||
$list = LogsOperation::where('1=1')
|
||||
->order('id desc')
|
||||
->page($page, $limit)
|
||||
->select();
|
||||
|
||||
@@ -129,7 +130,7 @@ class Log extends Base
|
||||
'execution_time' => 0
|
||||
];
|
||||
|
||||
Db::name('yz_logs_operation')->insert($data);
|
||||
LogsOperation::insert($data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,8 +143,7 @@ class Log extends Base
|
||||
return json(['code' => 1, 'msg' => '参数错误']);
|
||||
}
|
||||
|
||||
$info = Db::name('yz_logs_operation')
|
||||
->where('id', $id)
|
||||
$info = LogsOperation::where('id', $id)
|
||||
->find();
|
||||
|
||||
if (!$info) {
|
||||
|
||||
@@ -10,53 +10,104 @@ use think\facade\View;
|
||||
use think\facade\Cookie;
|
||||
use think\facade\Request;
|
||||
use app\admin\model\YzAdminConfig;
|
||||
use app\admin\model\AdminUser;
|
||||
use app\admin\model\Log\LogsLogin;
|
||||
|
||||
class Login
|
||||
{
|
||||
protected $app;
|
||||
protected $config;
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->config = new YzAdminConfig();
|
||||
}
|
||||
|
||||
// 登录页面
|
||||
public function index()
|
||||
{
|
||||
# 获取配置
|
||||
$YzAdminConfig = new YzAdminConfig();
|
||||
$this->config = $YzAdminConfig->getAll();
|
||||
$config = $this->config->getAll();
|
||||
View::assign([
|
||||
'config' => $this->config
|
||||
'config' => $config
|
||||
]);
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
// 记录登录日志
|
||||
protected function recordLoginLog($username, $status, $reason = '')
|
||||
{
|
||||
$data = [
|
||||
'username' => $username,
|
||||
'ip_address' => Request::ip(),
|
||||
'location' => $this->getLocation(Request::ip()),
|
||||
'device_type' => $this->getDeviceType(),
|
||||
'user_agent' => Request::header('user-agent'),
|
||||
'login_status' => $status,
|
||||
'failure_reason' => $reason,
|
||||
'login_time' => date('Y-m-d H:i:s')
|
||||
];
|
||||
LogsLogin::create($data);
|
||||
}
|
||||
|
||||
// 获取IP地址位置
|
||||
protected function getLocation($ip)
|
||||
{
|
||||
// 这里可以接入IP地址库或第三方API
|
||||
return '未知';
|
||||
}
|
||||
|
||||
// 获取设备类型
|
||||
protected function getDeviceType()
|
||||
{
|
||||
$agent = Request::header('user-agent');
|
||||
if (preg_match('/(iPhone|iPod|Android|ios|iPad|Mobile)/i', $agent)) {
|
||||
return '移动端';
|
||||
}
|
||||
return 'PC端';
|
||||
}
|
||||
|
||||
// 登录
|
||||
public function login()
|
||||
{
|
||||
if (Request::isPost()) {
|
||||
$account = trim(input('post.account'));
|
||||
if (empty($account)) {
|
||||
$this->returnCode(1, '账号不能为空');
|
||||
$this->recordLoginLog($account, 0, '账号不能为空');
|
||||
return json(['code' => 1, 'msg' => '账号不能为空']);
|
||||
}
|
||||
$pattern = "/^([0-9A-Za-z-_.]+)@([0-9a-z]+.[a-z]{2,3}(.[a-z]{2})?)$/i";
|
||||
if (!preg_match($pattern, $account)) {
|
||||
$this->returnCode(1, '邮箱格式不正确');
|
||||
$this->recordLoginLog($account, 0, '邮箱格式不正确');
|
||||
return json(['code' => 1, 'msg' => '邮箱格式不正确']);
|
||||
}
|
||||
$password = trim(input('post.password'));
|
||||
if (empty($password)) {
|
||||
$this->returnCode(1, '密码不能为空');
|
||||
$this->recordLoginLog($account, 0, '密码不能为空');
|
||||
return json(['code' => 1, 'msg' => '密码不能为空']);
|
||||
}
|
||||
$code = trim(input('post.code'));
|
||||
if ($code == '') {
|
||||
$this->returnCode(1, '验证码不能为空');
|
||||
$this->recordLoginLog($account, 0, '验证码不能为空');
|
||||
return json(['code' => 1, 'msg' => '验证码不能为空']);
|
||||
}
|
||||
if (!captcha_check($code)) {
|
||||
$this->returnCode(1, '验证码错误');
|
||||
$this->recordLoginLog($account, 0, '验证码错误');
|
||||
return json(['code' => 1, 'msg' => '验证码错误']);
|
||||
}
|
||||
$aUser = Db::table('yz_admin_user')->where('account', $account)->find();
|
||||
$aUser = AdminUser::where('account', $account)->find();
|
||||
if (empty($aUser)) {
|
||||
$this->returnCode(1, '账号不存在');
|
||||
$this->recordLoginLog($account, 0, '账号不存在');
|
||||
return json(['code' => 1, 'msg' => '账号不存在']);
|
||||
}
|
||||
if ($aUser['status'] != 1) {
|
||||
$this->returnCode(1, '账号已被禁用');
|
||||
$this->recordLoginLog($account, 0, '账号已被禁用');
|
||||
return json(['code' => 1, 'msg' => '账号已被禁用']);
|
||||
}
|
||||
if ($aUser['password'] != md5($password)) {
|
||||
$this->returnCode(1, '密码错误');
|
||||
$this->recordLoginLog($account, 0, '密码错误');
|
||||
return json(['code' => 1, 'msg' => '密码错误']);
|
||||
}
|
||||
$remember = input('post.remember');
|
||||
if (!empty($remember)) {
|
||||
@@ -66,10 +117,12 @@ class Login
|
||||
Cookie::set('admin_id', $aUser['uid']);
|
||||
Cookie::set('admin_name', $aUser['name']);
|
||||
}
|
||||
Db::table('yz_admin_user')->where('uid', $aUser['uid'])->update(
|
||||
AdminUser::where('uid', $aUser['uid'])->update(
|
||||
['login_count' => $aUser['login_count'] + 1, 'update_time' => time()]
|
||||
);
|
||||
$this->returnCode(0, [], '登录成功');
|
||||
// 记录登录成功日志
|
||||
$this->recordLoginLog($account, 1);
|
||||
return json(['code' => 0, 'msg' => '登录成功', 'data' => []]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,35 +131,7 @@ class Login
|
||||
{
|
||||
Cookie::delete('admin_id');
|
||||
Cookie::delete('admin_name');
|
||||
$this->returnCode(0, [], '退出成功');
|
||||
}
|
||||
|
||||
// 返回代码
|
||||
protected function returnCode($code, $data = [], $msg = '')
|
||||
{
|
||||
header('Content-type:application/json');
|
||||
if ($code == 0) {
|
||||
$arr = array(
|
||||
'code' => $code,
|
||||
'msg' => $msg,
|
||||
'data' => $data
|
||||
);
|
||||
} else if ($code == 1) {
|
||||
$arr = array(
|
||||
'code' => 1,
|
||||
'msg' => $data
|
||||
);
|
||||
} else {
|
||||
$appapi = new AppApi();
|
||||
$arr = array(
|
||||
'code' => $code,
|
||||
'msg' => $appapi::errorTip($code)
|
||||
);
|
||||
}
|
||||
echo json_encode($arr);
|
||||
if ($code != 0) {
|
||||
exit;
|
||||
}
|
||||
return json(['code' => 0, 'msg' => '退出成功', 'data' => []]);
|
||||
}
|
||||
|
||||
// 密码重置页面
|
||||
@@ -120,34 +145,34 @@ class Login
|
||||
{
|
||||
$account = trim(input('post.account'));
|
||||
if (empty($account)) {
|
||||
$this->returnCode(1, '账号不能为空');
|
||||
return json(['code' => 1, 'msg' => '账号不能为空']);
|
||||
}
|
||||
|
||||
$user = Db::table('yz_admin_user')->where('account', $account)->find();
|
||||
$user = AdminUser::where('account', $account)->find();
|
||||
|
||||
if (!$user) {
|
||||
$this->returnCode(1, '未找到该用户名');
|
||||
return json(['code' => 1, 'msg' => '未找到该用户名']);
|
||||
}
|
||||
|
||||
// 使用md5进行密码加密处理
|
||||
$password = md5('123456');
|
||||
|
||||
try {
|
||||
$res = Db::table('yz_admin_user')
|
||||
->where('account', $account)
|
||||
$res = AdminUser::where('account', $account)
|
||||
->update(['password' => $password]);
|
||||
|
||||
if ($res === false) {
|
||||
$this->returnCode(1, '数据库更新失败');
|
||||
return json(['code' => 1, 'msg' => '数据库更新失败']);
|
||||
}
|
||||
|
||||
if ($res === 0) {
|
||||
$this->returnCode(1, '密码未发生变化');
|
||||
return json(['code' => 1, 'msg' => '密码未发生变化']);
|
||||
}
|
||||
|
||||
$this->returnCode(0, [], '密码重置成功');
|
||||
return json(['code' => 0, 'msg' => '密码重置成功', 'data' => []]);
|
||||
} catch (\Exception $e) {
|
||||
$this->returnCode(1, '系统错误:' . $e->getMessage());
|
||||
return json(['code' => 1, 'msg' => '系统错误:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,11 +9,15 @@ use think\facade\View;
|
||||
use think\facade\Request;
|
||||
use app\admin\model\YzAdminConfig;
|
||||
use app\admin\controller\Log;
|
||||
use app\admin\model\AdminSysMenu;
|
||||
use app\admin\model\AdminUserGroup;
|
||||
use app\admin\model\AdminConfig;
|
||||
use app\admin\model\ZIconfont;
|
||||
|
||||
class Yunzer extends Base{
|
||||
# 菜单列表
|
||||
public function menuinfo(){
|
||||
$lists = Db::table('yz_admin_sys_menu')->where('parent_id',0)->order('sort DESC,smid DESC')->select();
|
||||
$lists = AdminSysMenu::where('parent_id', 0)->order('sort DESC,smid DESC')->select();
|
||||
View::assign([
|
||||
'lists' => $lists
|
||||
]);
|
||||
@@ -49,17 +53,17 @@ class Yunzer extends Base{
|
||||
$data['src'] = '';
|
||||
}
|
||||
// 保存菜单
|
||||
$res = Db::table('yz_admin_sys_menu')->insert($data);
|
||||
$res = AdminSysMenu::insert($data);
|
||||
if (!$res) {
|
||||
Log::record('添加菜单', 0, '添加菜单失败', '菜单管理');
|
||||
$this->returnCode(1, '添加菜单失败');
|
||||
}
|
||||
|
||||
// 获取新插入的菜单ID
|
||||
$newMenuId = Db::table('yz_admin_sys_menu')->getLastInsID();
|
||||
$newMenuId = AdminSysMenu::getLastInsID();
|
||||
|
||||
// 获取所有管理员用户组
|
||||
$adminGroups = Db::table('yz_admin_user_group')->select();
|
||||
$adminGroups = AdminUserGroup::select();
|
||||
foreach ($adminGroups as $group) {
|
||||
// 获取现有权限
|
||||
$rights = [];
|
||||
@@ -72,8 +76,7 @@ class Yunzer extends Base{
|
||||
$rights[] = $newMenuId;
|
||||
|
||||
// 更新用户组权限
|
||||
Db::table('yz_admin_user_group')
|
||||
->where('group_id', $group['group_id'])
|
||||
AdminUserGroup::where('group_id', $group['group_id'])
|
||||
->update(['rights' => json_encode($rights)]);
|
||||
}
|
||||
}
|
||||
@@ -81,7 +84,7 @@ class Yunzer extends Base{
|
||||
Log::record('添加菜单', 1, '', '菜单管理');
|
||||
$this->returnCode(0);
|
||||
} else {
|
||||
$iconfont = Db::table('yz_z_iconfont')->where('status', 1)->select();
|
||||
$iconfont = ZIconfont::where('status', 1)->select();
|
||||
View::assign([
|
||||
'iconfont' => $iconfont
|
||||
]);
|
||||
@@ -118,7 +121,7 @@ class Yunzer extends Base{
|
||||
$data['src'] = '';
|
||||
}
|
||||
// 保存用户
|
||||
$res = Db::table('yz_admin_sys_menu')->where('smid',$smid)->update($data);
|
||||
$res = AdminSysMenu::where('smid',$smid)->update($data);
|
||||
if(!$res){
|
||||
Log::record('编辑菜单', 0, '修改菜单失败', '菜单管理');
|
||||
$this->returnCode(1, '修改菜单失败');
|
||||
@@ -127,8 +130,8 @@ class Yunzer extends Base{
|
||||
$this->returnCode(0);
|
||||
}else{
|
||||
$smid = (int)input('get.smid');
|
||||
$lists = Db::table('yz_admin_sys_menu')->where('smid',$smid)->find();
|
||||
$iconfont = Db::table('yz_z_iconfont')->where('status',1)->select();
|
||||
$lists = AdminSysMenu::where('smid',$smid)->find();
|
||||
$iconfont = ZIconfont::where('status',1)->select();
|
||||
View::assign([
|
||||
'lists' => $lists,
|
||||
'iconfont' => $iconfont
|
||||
@@ -139,12 +142,12 @@ class Yunzer extends Base{
|
||||
# 菜单删除
|
||||
public function menudel(){
|
||||
$smid = (int)input('post.smid');
|
||||
$count = Db::table('yz_admin_sys_menu')->where('parent_id',$smid)->count();
|
||||
$count = AdminSysMenu::where('parent_id',$smid)->count();
|
||||
if($count > 0){
|
||||
Log::record('删除菜单', 0, '该菜单下还有子菜单,不能删除', '菜单管理');
|
||||
$this->returnCode(1, '该菜单下还有子菜单,不能删除');
|
||||
}
|
||||
$res = Db::table('yz_admin_sys_menu')->where('smid',$smid)->delete();
|
||||
$res = AdminSysMenu::where('smid',$smid)->delete();
|
||||
if(empty($res)){
|
||||
Log::record('删除菜单', 0, '删除菜单失败', '菜单管理');
|
||||
$this->returnCode(1, '删除菜单失败');
|
||||
@@ -155,7 +158,7 @@ class Yunzer extends Base{
|
||||
# 按钮管理
|
||||
public function buttoninfo(){
|
||||
$smid = (int)input('get.smid');
|
||||
$lists = Db::table('yz_admin_sys_menu')->where('parent_id',$smid)->order('sort DESC')->select()->toArray();
|
||||
$lists = AdminSysMenu::where('parent_id',$smid)->order('sort DESC')->select()->toArray();
|
||||
if(!empty($lists)){
|
||||
foreach($lists as &$v){
|
||||
switch ($v['type']) {
|
||||
@@ -212,7 +215,7 @@ class Yunzer extends Base{
|
||||
}
|
||||
}
|
||||
$data['parent_id'] = $smid;
|
||||
$res = Db::table('yz_admin_sys_menu')->insert($data);
|
||||
$res = AdminSysMenu::insert($data);
|
||||
if(!$res){
|
||||
Log::record('添加按钮', 0, '添加按钮失败', '按钮管理');
|
||||
$this->returnCode(1, '添加按钮失败');
|
||||
@@ -221,7 +224,7 @@ class Yunzer extends Base{
|
||||
$this->returnCode(0);
|
||||
}else{
|
||||
$smid = (int)input('get.smid');
|
||||
$iconfont = Db::table('yz_z_iconfont')->where('status',1)->select();
|
||||
$iconfont = ZIconfont::where('status',1)->select();
|
||||
View::assign([
|
||||
'smid' => $smid,
|
||||
'iconfont' => $iconfont
|
||||
@@ -260,7 +263,7 @@ class Yunzer extends Base{
|
||||
$this->returnCode(1, '请输入超链接地址');
|
||||
}
|
||||
}
|
||||
$res = Db::table('yz_admin_sys_menu')->where('smid',$smid)->update($data);
|
||||
$res = AdminSysMenu::where('smid',$smid)->update($data);
|
||||
if(!$res){
|
||||
Log::record('编辑按钮', 0, '修改按钮失败', '按钮管理');
|
||||
$this->returnCode(1, '修改按钮失败');
|
||||
@@ -269,8 +272,8 @@ class Yunzer extends Base{
|
||||
$this->returnCode(0);
|
||||
}else{
|
||||
$smid = (int)input('get.smid');
|
||||
$lists = Db::table('yz_admin_sys_menu')->where('smid',$smid)->find();
|
||||
$iconfont = Db::table('yz_z_iconfont')->where('status',1)->select();
|
||||
$lists = AdminSysMenu::where('smid',$smid)->find();
|
||||
$iconfont = ZIconfont::where('status',1)->select();
|
||||
View::assign([
|
||||
'lists' => $lists,
|
||||
'iconfont' => $iconfont
|
||||
@@ -281,7 +284,7 @@ class Yunzer extends Base{
|
||||
# 按钮删除
|
||||
public function buttondel(){
|
||||
$smid = (int)input('post.smid');
|
||||
$res = Db::table('yz_admin_sys_menu')->where('smid',$smid)->delete();
|
||||
$res = AdminSysMenu::where('smid',$smid)->delete();
|
||||
if(empty($res)){
|
||||
Log::record('删除按钮', 0, '删除按钮失败', '按钮管理');
|
||||
$this->returnCode(1, '删除按钮失败');
|
||||
@@ -295,8 +298,8 @@ class Yunzer extends Base{
|
||||
if($req->isPost()){
|
||||
$page = (int)input('post.page',1);
|
||||
$limit = (int)input('post.limit',$this->config['admin_page']);
|
||||
$count = Db::table('yz_admin_config')->count();
|
||||
$lists = Db::table('yz_admin_config')->page($page,$limit)->order('config_sort DESC,config_id DESC')->select();
|
||||
$count = AdminConfig::count();
|
||||
$lists = AdminConfig::page($page,$limit)->order('config_sort DESC,config_id DESC')->select();
|
||||
$this->returnCode(0,$lists,$count);
|
||||
}else{
|
||||
return View::fetch();
|
||||
@@ -320,7 +323,7 @@ class Yunzer extends Base{
|
||||
$data['config_desc'] = trim(input('post.config_desc'));
|
||||
$data['config_status'] = trim(input('post.config_status'));
|
||||
$data['config_sort'] = trim(input('post.config_sort'));
|
||||
$res = Db::table('yz_admin_config')->insert($data);
|
||||
$res = AdminConfig::insert($data);
|
||||
if(empty($res)){
|
||||
Log::record('添加配置', 0, '添加配置失败', '系统配置');
|
||||
$this->returnCode(1, '添加配置失败');
|
||||
@@ -354,7 +357,7 @@ class Yunzer extends Base{
|
||||
$data['config_desc'] = trim(input('post.config_desc'));
|
||||
$data['config_status'] = trim(input('post.config_status'));
|
||||
$data['config_sort'] = trim(input('post.config_sort'));
|
||||
$res = Db::table('yz_admin_config')->where('config_id',$config_id)->update($data);
|
||||
$res = AdminConfig::where('config_id',$config_id)->update($data);
|
||||
if(empty($res)){
|
||||
Log::record('编辑配置', 0, '修改配置失败', '系统配置');
|
||||
$this->returnCode(1, '修改配置失败');
|
||||
@@ -363,7 +366,7 @@ class Yunzer extends Base{
|
||||
$this->returnCode(0);
|
||||
}else{
|
||||
$config_id = (int)input('get.config_id');
|
||||
$find = Db::table('yz_admin_config')->where('config_id',$config_id)->find();
|
||||
$find = AdminConfig::where('config_id',$config_id)->find();
|
||||
View::assign([
|
||||
'find' => $find
|
||||
]);
|
||||
@@ -377,7 +380,7 @@ class Yunzer extends Base{
|
||||
Log::record('删除配置', 0, '请选择一条数据', '系统配置');
|
||||
$this->returnCode(1,'请选择一条数据');
|
||||
}
|
||||
$res = Db::table('yz_admin_config')->where('config_id',$config_id)->delete();
|
||||
$res = AdminConfig::where('config_id',$config_id)->delete();
|
||||
if(empty($res)){
|
||||
Log::record('删除配置', 0, '删除配置失败', '系统配置');
|
||||
$this->returnCode(1, '删除配置失败');
|
||||
@@ -403,7 +406,7 @@ class Yunzer extends Base{
|
||||
Log::record('更新配置值', 1, '', '系统配置');
|
||||
$this->returnCode(0);
|
||||
}else{
|
||||
$lists = Db::table('yz_admin_config')->order('config_sort DESC,config_id')->select();
|
||||
$lists = AdminConfig::order('config_sort DESC,config_id')->select();
|
||||
View::assign([
|
||||
'lists' => $lists
|
||||
]);
|
||||
|
||||
@@ -5,13 +5,18 @@ use think\facade\Db;
|
||||
use think\facade\View;
|
||||
use think\facade\Request;
|
||||
use app\admin\controller\Log;
|
||||
use app\admin\model\AdminSysMenu;
|
||||
use app\admin\model\AdminUserGroup;
|
||||
use app\admin\model\AdminUser;
|
||||
use app\admin\model\Banner;
|
||||
|
||||
|
||||
class Yunzeradmin extends Base
|
||||
{
|
||||
// 角色列表
|
||||
public function groupinfo()
|
||||
{
|
||||
$group = Db::table('yz_admin_user_group')->select();
|
||||
$group = AdminUserGroup::select();
|
||||
View::assign([
|
||||
'group' => $group
|
||||
]);
|
||||
@@ -27,13 +32,13 @@ class Yunzeradmin extends Base
|
||||
Log::record('添加角色', 0, '角色名称不能为空', '角色管理');
|
||||
return json(['code' => 1, 'msg' => '角色名称不能为空']);
|
||||
}
|
||||
$data['status'] = (int) trim(input('post.status'));
|
||||
$data['status'] = intval(trim(input('post.status')));
|
||||
$data['create_time'] = time();
|
||||
$menus = input('post.menu/a');
|
||||
if ($menus) {
|
||||
$data['rights'] = json_encode(array_keys($menus));
|
||||
}
|
||||
$res = Db::table('yz_admin_user_group')->insert($data);
|
||||
$res = AdminUserGroup::insert($data);
|
||||
if (!$res) {
|
||||
Log::record('添加角色', 0, '添加角色失败', '角色管理');
|
||||
return json(['code' => 1, 'msg' => '添加角色失败']);
|
||||
@@ -41,7 +46,7 @@ class Yunzeradmin extends Base
|
||||
Log::record('添加角色', 1, '', '角色管理');
|
||||
return json(['code' => 0, 'msg' => '添加成功']);
|
||||
} else {
|
||||
$menus = Db::table('yz_admin_sys_menu')->order('type,sort desc')->where('status', '=', 1)->select();
|
||||
$menus = AdminSysMenu::order('type,sort desc')->where('status', '=', 1)->select();
|
||||
$menu = [];
|
||||
|
||||
// 先处理所有父菜单
|
||||
@@ -83,7 +88,7 @@ class Yunzeradmin extends Base
|
||||
} else {
|
||||
$data['rights'] = '';
|
||||
}
|
||||
$res = Db::table('yz_admin_user_group')->where('group_id', $group_id)->update($data);
|
||||
$res = AdminUserGroup::where('group_id', $group_id)->update($data);
|
||||
if (!$res) {
|
||||
Log::record('编辑角色', 0, '更新角色失败', '角色管理');
|
||||
return json(['code' => 1, 'msg' => '更新角色失败']);
|
||||
@@ -92,12 +97,12 @@ class Yunzeradmin extends Base
|
||||
return json(['code' => 0, 'msg' => '更新成功']);
|
||||
} else {
|
||||
$group_id = (int) input('get.group_id');
|
||||
$group = Db::table('yz_admin_user_group')->where('group_id', $group_id)->find();
|
||||
$group = AdminUserGroup::where('group_id', $group_id)->find();
|
||||
if ($group && $group['rights']) {
|
||||
$group['rights'] = json_decode($group['rights']);
|
||||
}
|
||||
|
||||
$menus = Db::table('yz_admin_sys_menu')->order('type,sort desc')->where('status', '=', 1)->select();
|
||||
$menus = AdminSysMenu::order('type,sort desc')->where('status', '=', 1)->select();
|
||||
$menu = [];
|
||||
|
||||
// 先处理所有父菜单
|
||||
@@ -127,7 +132,7 @@ class Yunzeradmin extends Base
|
||||
public function groupdel()
|
||||
{
|
||||
$group_id = (int) input('post.group_id');
|
||||
$res = Db::table('yz_admin_user_group')->where('group_id', $group_id)->delete();
|
||||
$res = AdminUserGroup::where('group_id', $group_id)->delete();
|
||||
if (empty($res)) {
|
||||
Log::record('删除角色', 0, '删除角色失败', '角色管理');
|
||||
return json(['code' => 1, 'msg' => '删除角色失败']);
|
||||
@@ -139,9 +144,9 @@ class Yunzeradmin extends Base
|
||||
// 管理员列表
|
||||
public function userinfo()
|
||||
{
|
||||
$lists = Db::table('yz_admin_user')->select();
|
||||
$lists = AdminUser::select();
|
||||
$group = [];
|
||||
$groups = Db::table('yz_admin_user_group')->select();
|
||||
$groups = AdminUserGroup::select();
|
||||
foreach ($groups as $key => $value) {
|
||||
$group[$value['group_id']] = $value;
|
||||
}
|
||||
@@ -166,7 +171,7 @@ class Yunzeradmin extends Base
|
||||
Log::record('添加管理员', 0, '邮箱格式不正确', '管理员管理');
|
||||
return json(['code' => 1, 'msg' => '邮箱格式不正确']);
|
||||
}
|
||||
$item = Db::table('yz_admin_user')->where('account', $data['account'])->find();
|
||||
$item = AdminUser::where('account', $data['account'])->find();
|
||||
if ($item) {
|
||||
Log::record('添加管理员', 0, '该账号已存在', '管理员管理');
|
||||
return json(['code' => 1, 'msg' => '该账号已存在']);
|
||||
@@ -198,7 +203,7 @@ class Yunzeradmin extends Base
|
||||
}
|
||||
$data['create_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$res = Db::table('yz_admin_user')->insert($data);
|
||||
$res = AdminUser::insert($data);
|
||||
if (!$res) {
|
||||
Log::record('添加管理员', 0, '添加管理员失败', '管理员管理');
|
||||
return json(['code' => 1, 'msg' => '添加管理员失败']);
|
||||
@@ -207,7 +212,7 @@ class Yunzeradmin extends Base
|
||||
return json(['code' => 0, 'msg' => '添加成功']);
|
||||
} else {
|
||||
$group = [];
|
||||
$groups = Db::table('yz_admin_user_group')->select();
|
||||
$groups = AdminUserGroup::select();
|
||||
foreach ($groups as $key => $value) {
|
||||
$group[$value['group_id']] = $value;
|
||||
}
|
||||
@@ -241,7 +246,7 @@ class Yunzeradmin extends Base
|
||||
Log::record('编辑管理员', 0, '请选择角色', '管理员管理');
|
||||
return json(['code' => 1, 'msg' => '请选择角色']);
|
||||
}
|
||||
$res = Db::table('yz_admin_user')->where('uid', $uid)->update($data);
|
||||
$res = AdminUser::where('uid', $uid)->update($data);
|
||||
if (!$res) {
|
||||
Log::record('编辑管理员', 0, '更新管理员信息失败', '管理员管理');
|
||||
return json(['code' => 1, 'msg' => '更新管理员信息失败']);
|
||||
@@ -251,10 +256,10 @@ class Yunzeradmin extends Base
|
||||
} else {
|
||||
$uid = (int) input('get.uid');
|
||||
// 加载管理员
|
||||
$lists = Db::table('yz_admin_user')->where('uid', $uid)->find();
|
||||
$lists = AdminUser::where('uid', $uid)->find();
|
||||
// 加载角色
|
||||
$group = [];
|
||||
$groups = Db::table('yz_admin_user_group')->select();
|
||||
$groups = AdminUserGroup::select();
|
||||
foreach ($groups as $key => $value) {
|
||||
$group[$value['group_id']] = $value;
|
||||
}
|
||||
@@ -270,7 +275,7 @@ class Yunzeradmin extends Base
|
||||
public function userdel()
|
||||
{
|
||||
$uid = (int) input('post.uid');
|
||||
$res = Db::table('yz_admin_user')->where('uid', $uid)->delete();
|
||||
$res = AdminUser::where('uid', $uid)->delete();
|
||||
if (empty($res)) {
|
||||
Log::record('删除管理员', 0, '删除管理员失败', '管理员管理');
|
||||
return json(['code' => 1, 'msg' => '删除管理员失败']);
|
||||
@@ -283,7 +288,7 @@ class Yunzeradmin extends Base
|
||||
public function admininfo()
|
||||
{
|
||||
if (Request::isPost()) {
|
||||
$find = Db::table('yz_admin_user')->where('uid', $this->adminId)->find();
|
||||
$find = AdminUser::where('uid', $this->adminId)->find();
|
||||
if (empty($find)) {
|
||||
Log::record('修改个人信息', 0, '当前账户不存在', '个人信息');
|
||||
return json(['code' => 1, 'msg' => '当前账户不存在']);
|
||||
@@ -312,7 +317,7 @@ class Yunzeradmin extends Base
|
||||
$data['password'] = md5($new_pw);
|
||||
}
|
||||
|
||||
$res = Db::table('yz_admin_user')->where('uid', $this->adminId)->update($data);
|
||||
$res = AdminUser::where('uid', $this->adminId)->update($data);
|
||||
if (!$res) {
|
||||
Log::record('修改个人信息', 0, '更新管理员信息失败', '个人信息');
|
||||
return json(['code' => 1, 'msg' => '更新管理员信息失败']);
|
||||
@@ -334,11 +339,10 @@ class Yunzeradmin extends Base
|
||||
public function bannerlist()
|
||||
{
|
||||
if (Request::isGet()) {
|
||||
$page = input('page', 1);
|
||||
$limit = input('limit', 10);
|
||||
$page = intval(input('post.page', 1));
|
||||
$limit = intval(input('post.limit', 10));
|
||||
|
||||
$query = Db::table('yz_banner')
|
||||
->where('delete_time', null)
|
||||
$query = Banner::where('delete_time', null)
|
||||
->field('id, title, image, url, sort, create_time, update_time');
|
||||
|
||||
// 获取总记录数
|
||||
@@ -352,8 +356,8 @@ class Yunzeradmin extends Base
|
||||
|
||||
// 处理数据
|
||||
foreach ($lists as &$item) {
|
||||
$item['create_time'] = $item['create_time'] ? date('Y-m-d H:i:s', $item['create_time']) : '';
|
||||
$item['update_time'] = $item['update_time'] ? date('Y-m-d H:i:s', $item['update_time']) : '';
|
||||
$item['create_time'] = is_numeric($item['create_time']) ? date('Y-m-d H:i:s', $item['create_time']) : $item['create_time'];
|
||||
$item['update_time'] = is_numeric($item['update_time']) ? date('Y-m-d H:i:s', $item['update_time']) : $item['update_time'];
|
||||
}
|
||||
|
||||
return json([
|
||||
@@ -379,7 +383,7 @@ class Yunzeradmin extends Base
|
||||
'create_time' => time()
|
||||
];
|
||||
|
||||
$res = Db::table('yz_banner')->insert($data);
|
||||
$res = Banner::insert($data);
|
||||
if (!$res) {
|
||||
Log::record('添加Banner', 0, '添加Banner失败', 'Banner管理');
|
||||
return json(['code' => 1, 'msg' => '添加Banner失败']);
|
||||
@@ -408,7 +412,7 @@ class Yunzeradmin extends Base
|
||||
'update_time' => time()
|
||||
];
|
||||
|
||||
$res = Db::table('yz_banner')->where('id', $id)->update($data);
|
||||
$res = Banner::where('id', $id)->update($data);
|
||||
if ($res === false) {
|
||||
Log::record('编辑Banner', 0, '更新Banner失败', 'Banner管理');
|
||||
return json(['code' => 1, 'msg' => '更新Banner失败']);
|
||||
@@ -429,7 +433,7 @@ class Yunzeradmin extends Base
|
||||
return json(['code' => 1, 'msg' => 'ID不能为空']);
|
||||
}
|
||||
|
||||
$res = Db::table('yz_banner')->where('id', $id)->update(['delete_time' => time()]);
|
||||
$res = Banner::where('id', $id)->update(['delete_time' => time()]);
|
||||
if (!$res) {
|
||||
Log::record('删除Banner', 0, '删除Banner失败', 'Banner管理');
|
||||
return json(['code' => 1, 'msg' => '删除Banner失败']);
|
||||
@@ -452,7 +456,7 @@ class Yunzeradmin extends Base
|
||||
return json(['code' => 1, 'msg' => 'ID不能为空']);
|
||||
}
|
||||
|
||||
$res = Db::table('yz_banner')->where('id', $id)->update(['status' => $status]);
|
||||
$res = Banner::where('id', $id)->update(['status' => $status]);
|
||||
if ($res === false) {
|
||||
Log::record('修改Banner状态', 0, '更新状态失败', 'Banner管理');
|
||||
return json(['code' => 1, 'msg' => '更新状态失败']);
|
||||
|
||||
Reference in New Issue
Block a user