修复资源用mvc
This commit is contained in:
@@ -4,12 +4,14 @@
|
||||
*/
|
||||
namespace app\admin\controller;
|
||||
use app\admin\controller\Base;
|
||||
use app\admin\model\Article\Article;
|
||||
use app\admin\model\ArticleCategory;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
use think\facade\Request;
|
||||
use app\admin\controller\Log;
|
||||
|
||||
class Article extends Base
|
||||
class Articles extends Base
|
||||
{
|
||||
// 文章列表
|
||||
public function articlelist()
|
||||
@@ -21,14 +23,14 @@ class Article extends Base
|
||||
$title = input('post.title');
|
||||
$author = input('post.author');
|
||||
|
||||
$query = Db::table('yz_article')
|
||||
$query = Db::name('article')
|
||||
->where('delete_time', null)
|
||||
->where('status', '<>', 3);
|
||||
|
||||
// 分类筛选
|
||||
if (!empty($category)) {
|
||||
// 先获取分类ID
|
||||
$cateInfo = Db::table('yz_article_category')
|
||||
$cateInfo = Db::name('article_category')
|
||||
->where('name', $category)
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
@@ -58,7 +60,7 @@ class Article extends Base
|
||||
->select()
|
||||
->each(function ($item) {
|
||||
// 获取分类信息
|
||||
$cateInfo = Db::table('yz_article_category')
|
||||
$cateInfo = Db::name('article_category')
|
||||
->where('id', $item['cate'])
|
||||
->field('name, image')
|
||||
->find();
|
||||
@@ -86,7 +88,7 @@ class Article extends Base
|
||||
]);
|
||||
} else {
|
||||
// 获取所有分类并构建父子结构
|
||||
$allCategories = Db::table('yz_article_category')
|
||||
$allCategories = Db::name('article_category')
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->order('sort asc, id asc')
|
||||
@@ -129,7 +131,7 @@ class Article extends Base
|
||||
'create_time' => time()
|
||||
];
|
||||
|
||||
$insert = Db::table('yz_article')->insert($data);
|
||||
$insert = Db::name('article')->insert($data);
|
||||
if (empty($insert)) {
|
||||
Log::record('添加文章', 0, '添加文章失败', '文章管理');
|
||||
return json(['code' => 1, 'msg' => '添加失败', 'data' => []]);
|
||||
@@ -137,7 +139,7 @@ class Article extends Base
|
||||
Log::record('添加文章', 1, '', '文章管理');
|
||||
return json(['code' => 0, 'msg' => '添加成功', 'data' => []]);
|
||||
} else {
|
||||
$lists = Db::table('yz_article')
|
||||
$lists = Db::name('article')
|
||||
->order('id DESC')
|
||||
->select()
|
||||
->each(function ($item, $key) {
|
||||
@@ -167,7 +169,7 @@ class Article extends Base
|
||||
'update_time' => time()
|
||||
];
|
||||
|
||||
$update = Db::table('yz_article')->where('id', $id)->update($data);
|
||||
$update = Db::name('article')->where('id', $id)->update($data);
|
||||
if ($update === false) {
|
||||
Log::record('编辑文章', 0, '编辑文章失败', '文章管理');
|
||||
return json(['code' => 1, 'msg' => '更新失败', 'data' => []]);
|
||||
@@ -176,12 +178,12 @@ class Article extends Base
|
||||
return json(['code' => 0, 'msg' => '更新成功', 'data' => []]);
|
||||
} else {
|
||||
$id = input('get.id');
|
||||
$info = Db::table('yz_article')->where('id', $id)->find();
|
||||
$info = Db::name('article')->where('id', $id)->find();
|
||||
if ($info === null) {
|
||||
return json(['code' => 1, 'msg' => '文章不存在', 'data' => []]);
|
||||
}
|
||||
|
||||
$cates = Db::table('yz_article_category')
|
||||
$cates = Db::name('article_category')
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->order('sort asc, id asc')
|
||||
@@ -190,7 +192,7 @@ class Article extends Base
|
||||
|
||||
$info['content'] = !empty($info['content']) ? htmlspecialchars_decode(str_replace(["\r\n", "\r", "\n"], '', addslashes($info['content']))) : '';
|
||||
|
||||
$currentCate = Db::table('yz_article_category')
|
||||
$currentCate = Db::name('article_category')
|
||||
->where('id', $info['cate'])
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
@@ -212,7 +214,7 @@ class Article extends Base
|
||||
$data = [
|
||||
'delete_time' => time(),
|
||||
];
|
||||
$delete = Db::table('yz_article')->where('id', $id)->update($data);
|
||||
$delete = Db::name('article')->where('id', $id)->update($data);
|
||||
if ($delete === false) {
|
||||
Log::record('删除文章', 0, '删除文章失败', '文章管理');
|
||||
return json(['code' => 1, 'msg' => '删除失败', 'data' => []]);
|
||||
@@ -225,7 +227,7 @@ class Article extends Base
|
||||
public function articlecate()
|
||||
{
|
||||
if (Request::isPost()) {
|
||||
$lists = Db::table('yz_article_category')
|
||||
$lists = Db::name('article_category')
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->order('sort asc, id asc')
|
||||
@@ -268,7 +270,7 @@ class Article extends Base
|
||||
public function getcate()
|
||||
{
|
||||
// 获取所有分类
|
||||
$lists = Db::table('yz_article_category')
|
||||
$lists = Db::name('article_category')
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->order('sort asc, id asc')
|
||||
@@ -311,7 +313,7 @@ class Article extends Base
|
||||
'create_time' => time()
|
||||
];
|
||||
|
||||
$insert = Db::table('yz_article_category')->insert($data);
|
||||
$insert = Db::name('article_category')->insert($data);
|
||||
if (empty($insert)) {
|
||||
Log::record('添加文章分类', 0, '添加文章分类失败', '文章分类');
|
||||
return json(['code' => 1, 'msg' => '添加失败', 'data' => []]);
|
||||
@@ -320,7 +322,7 @@ class Article extends Base
|
||||
return json(['code' => 0, 'msg' => '添加成功', 'data' => []]);
|
||||
} else {
|
||||
// 获取所有可选的父级分类
|
||||
$parentCategories = Db::table('yz_article_category')
|
||||
$parentCategories = Db::name('article_category')
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->where('cid', 0)
|
||||
@@ -352,7 +354,7 @@ class Article extends Base
|
||||
'update_time' => time()
|
||||
];
|
||||
|
||||
$update = Db::table('yz_article_category')
|
||||
$update = Db::name('article_category')
|
||||
->where('id', $data['id'])
|
||||
->update($data);
|
||||
|
||||
@@ -364,10 +366,10 @@ class Article extends Base
|
||||
return json(['code' => 0, 'msg' => '更新成功', 'data' => []]);
|
||||
} else {
|
||||
$id = input('get.id');
|
||||
$info = Db::table('yz_article_category')->where('id', $id)->find();
|
||||
$info = Db::name('article_category')->where('id', $id)->find();
|
||||
|
||||
// 获取所有可选的父级分类
|
||||
$parentCategories = Db::table('yz_article_category')
|
||||
$parentCategories = Db::name('article_category')
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->where('id', '<>', $id) // 排除自己
|
||||
@@ -407,7 +409,7 @@ class Article extends Base
|
||||
$id = input('post.id');
|
||||
|
||||
// 检查是否有子分类
|
||||
$hasChildren = Db::table('yz_article_category')
|
||||
$hasChildren = Db::name('article_category')
|
||||
->where('cid', $id)
|
||||
->where('delete_time', null)
|
||||
->find();
|
||||
@@ -417,7 +419,7 @@ class Article extends Base
|
||||
return json(['code' => 1, 'msg' => '该分类下有子分类,无法删除', 'data' => []]);
|
||||
}
|
||||
|
||||
$delete = Db::table('yz_article_category')
|
||||
$delete = Db::name('article_category')
|
||||
->where('id', $id)
|
||||
->update(['delete_time' => time()]);
|
||||
|
||||
@@ -431,7 +433,7 @@ class Article extends Base
|
||||
|
||||
//统计文章数量
|
||||
public function counts() {
|
||||
$total = Db::table('yz_article')
|
||||
$total = Db::name('article')
|
||||
->where('delete_time', null)
|
||||
->where('status', '<>', 3)
|
||||
->count();
|
||||
@@ -15,7 +15,7 @@ class Index extends Base{
|
||||
$menus = [];
|
||||
$menu = [];
|
||||
$where = ['group_id'=>$this->aUser['group_id']];
|
||||
$role = Db::table('yz_admin_user_group')->where($where)->find();
|
||||
$role = Db::name('admin_user_group')->where($where)->find();
|
||||
if($role){
|
||||
$role['rights'] = (isset($role['rights']) && $role['rights']) ? json_decode($role['rights'],true) : [];
|
||||
}
|
||||
@@ -25,7 +25,7 @@ class Index extends Base{
|
||||
['status','=',1]
|
||||
];
|
||||
// 获取所有菜单
|
||||
$menus = Db::table('yz_admin_sys_menu')->order('type,sort desc')->where($where)->select()->toArray();
|
||||
$menus = Db::name('admin_sys_menu')->order('type,sort desc')->where($where)->select()->toArray();
|
||||
|
||||
// 构建树形结构菜单
|
||||
$menuTree = [];
|
||||
@@ -63,12 +63,12 @@ class Index extends Base{
|
||||
public function welcome(){
|
||||
// 获取今日统计数据
|
||||
$today = date('Y-m-d');
|
||||
$todayStats = Db::name('yz_daily_stats')
|
||||
$todayStats = Db::name('daily_stats')
|
||||
->where('date', $today)
|
||||
->find();
|
||||
|
||||
// 获取最近7天的访问趋势
|
||||
$last7Days = Db::name('yz_daily_stats')
|
||||
$last7Days = Db::name('daily_stats')
|
||||
->where('date', '>=', date('Y-m-d', strtotime('-7 days')))
|
||||
->where('date', '<=', $today)
|
||||
->order('date', 'asc')
|
||||
@@ -76,7 +76,7 @@ class Index extends Base{
|
||||
->toArray();
|
||||
|
||||
// 获取用户增长趋势
|
||||
$userGrowth = Db::name('yz_daily_stats')
|
||||
$userGrowth = Db::name('daily_stats')
|
||||
->where('date', '>=', date('Y-m-d', strtotime('-30 days')))
|
||||
->where('date', '<=', $today)
|
||||
->field('date, new_users, total_users')
|
||||
@@ -85,7 +85,7 @@ class Index extends Base{
|
||||
->toArray();
|
||||
|
||||
// 获取资源下载统计
|
||||
$resourceStats = Db::name('yz_daily_stats')
|
||||
$resourceStats = Db::name('daily_stats')
|
||||
->where('date', '>=', date('Y-m-d', strtotime('-7 days')))
|
||||
->where('date', '<=', $today)
|
||||
->field('date, daily_resources, resource_downloads')
|
||||
@@ -94,7 +94,7 @@ class Index extends Base{
|
||||
->toArray();
|
||||
|
||||
// 获取文章访问统计
|
||||
$articleStats = Db::name('yz_daily_stats')
|
||||
$articleStats = Db::name('daily_stats')
|
||||
->where('date', '>=', date('Y-m-d', strtotime('-7 days')))
|
||||
->where('date', '<=', $today)
|
||||
->field('date, daily_articles, article_views')
|
||||
@@ -137,7 +137,7 @@ class Index extends Base{
|
||||
$activities = [];
|
||||
|
||||
// 获取今日新用户
|
||||
$newUsers = Db::name('yz_daily_stats')
|
||||
$newUsers = Db::name('daily_stats')
|
||||
->where('date', $today)
|
||||
->value('new_users');
|
||||
if ($newUsers > 0) {
|
||||
@@ -149,7 +149,7 @@ class Index extends Base{
|
||||
}
|
||||
|
||||
// 获取今日文章
|
||||
$newArticles = Db::name('yz_daily_stats')
|
||||
$newArticles = Db::name('daily_stats')
|
||||
->where('date', $today)
|
||||
->value('daily_articles');
|
||||
if ($newArticles > 0) {
|
||||
@@ -161,7 +161,7 @@ class Index extends Base{
|
||||
}
|
||||
|
||||
// 获取今日资源
|
||||
$newResources = Db::name('yz_daily_stats')
|
||||
$newResources = Db::name('daily_stats')
|
||||
->where('date', $today)
|
||||
->value('daily_resources');
|
||||
if ($newResources > 0) {
|
||||
@@ -280,7 +280,7 @@ class Index extends Base{
|
||||
'create_time' => time(),
|
||||
'update_time' => time()
|
||||
];
|
||||
return Db::table('yz_attachments')->insertGetId($data);
|
||||
return Db::name('attachments')->insertGetId($data);
|
||||
}
|
||||
|
||||
# 图片上传
|
||||
|
||||
+125
-169
@@ -4,10 +4,13 @@
|
||||
*/
|
||||
namespace app\admin\controller;
|
||||
use app\admin\controller\Base;
|
||||
use think\facade\Db;
|
||||
use app\admin\model\Resource\Resource;
|
||||
use app\admin\model\Resource\ResourceCategory;
|
||||
use think\facade\View;
|
||||
use think\facade\Request;
|
||||
use think\facade\Db;
|
||||
use app\admin\controller\Log;
|
||||
use think\App;
|
||||
|
||||
class Resources extends Base
|
||||
{
|
||||
@@ -15,95 +18,75 @@ class Resources extends Base
|
||||
public function lists()
|
||||
{
|
||||
if (Request::isPost()) {
|
||||
$category = input('post.category');
|
||||
$page = input('post.page', 1);
|
||||
$limit = input('post.limit', 10);
|
||||
$name = input('post.name');
|
||||
$uploader = input('post.uploader');
|
||||
|
||||
$query = Db::table('yz_resources')
|
||||
->where('delete_time', null)
|
||||
->where('status', '<>', 3);
|
||||
$params = [
|
||||
'category' => input('post.category'),
|
||||
'name' => input('post.name'),
|
||||
'uploader' => input('post.uploader')
|
||||
];
|
||||
$page = (int)input('post.page', 1);
|
||||
$limit = (int)input('post.limit', 10);
|
||||
|
||||
$query = Resource::where('delete_time', null)
|
||||
->where('status', 1);
|
||||
|
||||
// 分类筛选
|
||||
if (!empty($category)) {
|
||||
// 先获取分类ID
|
||||
$cateInfo = Db::table('yz_resources_category')
|
||||
->where('name', $category)
|
||||
if (!empty($params['category'])) {
|
||||
$cateInfo = ResourceCategory::where('name', $params['category'])
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->field('id')
|
||||
->find();
|
||||
|
||||
if ($cateInfo) {
|
||||
$query = $query->where('cate', $cateInfo['id']);
|
||||
$query = $query->where('cate', (int)$cateInfo['id']);
|
||||
}
|
||||
}
|
||||
|
||||
// 名称搜索
|
||||
if (!empty($name)) {
|
||||
$query = $query->where('name', 'like', '%'.$name.'%');
|
||||
if (!empty($params['name'])) {
|
||||
$query = $query->where('name', 'like', '%'.$params['name'].'%');
|
||||
}
|
||||
|
||||
// 上传者搜索
|
||||
if (!empty($uploader)) {
|
||||
$query = $query->where('uploader', 'like', '%'.$uploader.'%');
|
||||
if (!empty($params['uploader'])) {
|
||||
$query = $query->where('uploader', 'like', '%'.$params['uploader'].'%');
|
||||
}
|
||||
|
||||
// 获取总记录数
|
||||
|
||||
$count = $query->count();
|
||||
|
||||
// 获取分页数据
|
||||
|
||||
$lists = $query->order('id DESC')
|
||||
->page($page, $limit)
|
||||
->select()
|
||||
->each(function ($item) {
|
||||
// 获取分类信息
|
||||
$cateInfo = Db::table('yz_resources_category')
|
||||
->where('id', $item['cate'])
|
||||
$cateInfo = ResourceCategory::where('id', (int)$item['cate'])
|
||||
->field('name, icon')
|
||||
->find();
|
||||
|
||||
// 设置分类名称
|
||||
$item['cate'] = $cateInfo['name'];
|
||||
|
||||
// 如果资源没有图标,使用分类的图标
|
||||
if (empty($item['icon']) && !empty($cateInfo['icon'])) {
|
||||
$item['icon'] = $cateInfo['icon'];
|
||||
if ($cateInfo) {
|
||||
$item['cate'] = $cateInfo['name'];
|
||||
if (empty($item['icon']) && !empty($cateInfo['icon'])) {
|
||||
$item['icon'] = $cateInfo['icon'];
|
||||
}
|
||||
}
|
||||
|
||||
// 格式化时间
|
||||
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
|
||||
|
||||
$item['create_time'] = date('Y-m-d H:i:s', (int)$item['create_time']);
|
||||
return $item;
|
||||
});
|
||||
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => '获取成功',
|
||||
'code' => 0,
|
||||
'msg' => '获取成功',
|
||||
'count' => $count,
|
||||
'data' => $lists
|
||||
]);
|
||||
} else {
|
||||
// 获取所有分类并构建父子结构
|
||||
$allCategories = Db::table('yz_resources_category')
|
||||
->where('delete_time', null)
|
||||
$allCategories = ResourceCategory::where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->field('id, name, cid, icon')
|
||||
->order('sort asc, id asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$categories = [];
|
||||
foreach ($allCategories as $category) {
|
||||
if ($category['cid'] == 0) {
|
||||
$category['children'] = [];
|
||||
foreach ($allCategories as $subCategory) {
|
||||
if ($subCategory['cid'] == $category['id']) {
|
||||
$category['children'][] = $subCategory;
|
||||
}
|
||||
}
|
||||
$categories[] = $category;
|
||||
}
|
||||
}
|
||||
|
||||
$categories = $this->buildParentChild($allCategories);
|
||||
|
||||
View::assign([
|
||||
'categories' => $categories
|
||||
@@ -128,7 +111,7 @@ class Resources extends Base
|
||||
'create_time' => time()
|
||||
];
|
||||
|
||||
$insert = Db::table('yz_resources')->insert($data);
|
||||
$insert = Resource::insert($data);
|
||||
if (empty($insert)) {
|
||||
Log::record('添加资源', 0, '添加资源失败', '资源管理');
|
||||
return json(['code' => 1, 'msg' => '添加失败', 'data' => []]);
|
||||
@@ -136,13 +119,10 @@ class Resources extends Base
|
||||
Log::record('添加资源', 1, '', '资源管理');
|
||||
return json(['code' => 0, 'msg' => '添加成功', 'data' => []]);
|
||||
} else {
|
||||
$lists = Db::table('yz_resources')
|
||||
->order('id DESC')
|
||||
$lists = Resource::where('delete_time', null)
|
||||
->where('status', '<>', 3)
|
||||
->select()
|
||||
->each(function ($item, $key) {
|
||||
$item['create_time'] = time();
|
||||
return $item;
|
||||
});
|
||||
->toArray();
|
||||
View::assign([
|
||||
'lists' => $lists
|
||||
]);
|
||||
@@ -154,10 +134,8 @@ class Resources extends Base
|
||||
public function delete()
|
||||
{
|
||||
$id = input('post.id');
|
||||
$data = [
|
||||
'delete_time' => time(),
|
||||
];
|
||||
$delete = Db::table('yz_resources')->where('id', $id)->update($data);
|
||||
$delete = Resource::where('id', $id)
|
||||
->update(['delete_time' => time()]);
|
||||
if ($delete === false) {
|
||||
Log::record('删除资源', 0, '删除资源失败', '资源管理');
|
||||
return json(['code' => 1, 'msg' => '删除失败', 'data' => []]);
|
||||
@@ -170,76 +148,26 @@ class Resources extends Base
|
||||
public function cate()
|
||||
{
|
||||
if (Request::isPost()) {
|
||||
$lists = Db::table('yz_resources_category')
|
||||
->where('delete_time', null)
|
||||
$lists = ResourceCategory::where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->order('sort asc, id asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 构建树形结构
|
||||
$tree = [];
|
||||
foreach ($lists as $item) {
|
||||
if ($item['cid'] == 0) {
|
||||
$node = [
|
||||
'id' => $item['id'],
|
||||
'title' => $item['name'],
|
||||
'children' => []
|
||||
];
|
||||
|
||||
// 查找子分类
|
||||
foreach ($lists as $subItem) {
|
||||
if ($subItem['cid'] == $item['id']) {
|
||||
$node['children'][] = [
|
||||
'id' => $subItem['id'],
|
||||
'title' => $subItem['name'],
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$tree[] = $node;
|
||||
}
|
||||
}
|
||||
|
||||
$tree = $this->buildTree($lists);
|
||||
return json(['code' => 0, 'msg' => '获取成功', 'data' => $tree]);
|
||||
}
|
||||
|
||||
// 非 POST 请求返回视图
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
//获取分类结构
|
||||
public function getcate()
|
||||
{
|
||||
// 获取所有分类
|
||||
$lists = Db::table('yz_resources_category')
|
||||
->where('delete_time', null)
|
||||
$lists = ResourceCategory::where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->order('sort asc, id asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 构建父子结构
|
||||
$tree = [];
|
||||
foreach ($lists as $item) {
|
||||
if ($item['cid'] == 0) {
|
||||
// 顶级分类
|
||||
$tree[] = $item;
|
||||
} else {
|
||||
// 子分类
|
||||
foreach ($tree as &$parent) {
|
||||
if ($parent['id'] == $item['cid']) {
|
||||
if (!isset($parent['children'])) {
|
||||
$parent['children'] = [];
|
||||
}
|
||||
$parent['children'][] = $item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$tree = $this->buildParentChild($lists);
|
||||
return json(['code' => 0, 'msg' => '获取成功', 'data' => $tree]);
|
||||
}
|
||||
|
||||
@@ -256,7 +184,7 @@ class Resources extends Base
|
||||
'create_time' => time()
|
||||
];
|
||||
|
||||
$insert = Db::table('yz_resources_category')->insert($data);
|
||||
$insert = ResourceCategory::insert($data);
|
||||
if (empty($insert)) {
|
||||
Log::record('添加资源分类', 0, '添加资源分类失败', '资源分类');
|
||||
return json(['code' => 1, 'msg' => '添加失败', 'data' => []]);
|
||||
@@ -264,15 +192,12 @@ class Resources extends Base
|
||||
Log::record('添加资源分类', 1, '', '资源分类');
|
||||
return json(['code' => 0, 'msg' => '添加成功', 'data' => []]);
|
||||
} else {
|
||||
// 获取所有可选的父级分类
|
||||
$parentCategories = Db::table('yz_resources_category')
|
||||
->where('delete_time', null)
|
||||
$parentCategories = ResourceCategory::where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->where('cid', 0)
|
||||
->field('id, name')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => '获取成功',
|
||||
@@ -297,10 +222,8 @@ class Resources extends Base
|
||||
'update_time' => time()
|
||||
];
|
||||
|
||||
$update = Db::table('yz_resources_category')
|
||||
->where('id', $data['id'])
|
||||
$update = ResourceCategory::where('id', $data['id'])
|
||||
->update($data);
|
||||
|
||||
if ($update === false) {
|
||||
Log::record('编辑资源分类', 0, '更新资源分类失败', '资源分类');
|
||||
return json(['code' => 1, 'msg' => '更新失败', 'data' => []]);
|
||||
@@ -309,38 +232,21 @@ class Resources extends Base
|
||||
return json(['code' => 0, 'msg' => '更新成功', 'data' => []]);
|
||||
} else {
|
||||
$id = input('get.id');
|
||||
$info = Db::table('yz_resources_category')->where('id', $id)->find();
|
||||
|
||||
// 获取所有可选的父级分类
|
||||
$parentCategories = Db::table('yz_resources_category')
|
||||
->where('delete_time', null)
|
||||
$info = ResourceCategory::where('id', $id)->find();
|
||||
$parentCategories = ResourceCategory::where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->where('id', '<>', $id) // 排除自己
|
||||
->where(function ($query) use ($id) {
|
||||
// 排除自己的所有子分类
|
||||
$query->where('cid', '<>', $id);
|
||||
})
|
||||
->field('id, name, cid')
|
||||
->where('cid', 0)
|
||||
->where('id', '<>', $id)
|
||||
->field('id, name')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 构建父级分类选项
|
||||
$parentOptions = [];
|
||||
foreach ($parentCategories as $category) {
|
||||
if ($category['cid'] == 0) {
|
||||
$parentOptions[] = [
|
||||
'id' => $category['id'],
|
||||
'name' => $category['name']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => '获取成功',
|
||||
'data' => [
|
||||
'info' => $info,
|
||||
'parentOptions' => $parentOptions
|
||||
'parentOptions' => $parentCategories
|
||||
]
|
||||
]);
|
||||
}
|
||||
@@ -352,20 +258,16 @@ class Resources extends Base
|
||||
$id = input('post.id');
|
||||
|
||||
// 检查是否有子分类
|
||||
$hasChildren = Db::table('yz_resources_category')
|
||||
->where('cid', $id)
|
||||
$hasChildren = ResourceCategory::where('cid', $id)
|
||||
->where('delete_time', null)
|
||||
->find();
|
||||
|
||||
if ($hasChildren) {
|
||||
Log::record('删除资源分类', 0, '该分类下有子分类,无法删除', '资源分类');
|
||||
return json(['code' => 1, 'msg' => '该分类下有子分类,无法删除', 'data' => []]);
|
||||
}
|
||||
|
||||
$delete = Db::table('yz_resources_category')
|
||||
->where('id', $id)
|
||||
$delete = ResourceCategory::where('id', $id)
|
||||
->update(['delete_time' => time()]);
|
||||
|
||||
if ($delete === false) {
|
||||
Log::record('删除资源分类', 0, '删除资源分类失败', '资源分类');
|
||||
return json(['code' => 1, 'msg' => '删除失败', 'data' => []]);
|
||||
@@ -385,8 +287,7 @@ class Resources extends Base
|
||||
return json(['code' => 1, 'msg' => '参数错误']);
|
||||
}
|
||||
|
||||
$resource = Db::table('yz_resources')
|
||||
->where('id', $id)
|
||||
$resource = Resource::where('id', $id)
|
||||
->where('delete_time', null)
|
||||
->find();
|
||||
|
||||
@@ -396,8 +297,7 @@ class Resources extends Base
|
||||
}
|
||||
|
||||
// 获取分类信息
|
||||
$cateInfo = Db::table('yz_resources_category')
|
||||
->where('id', $resource['cate'])
|
||||
$cateInfo = ResourceCategory::where('id', $resource['cate'])
|
||||
->field('name')
|
||||
->find();
|
||||
|
||||
@@ -417,14 +317,13 @@ class Resources extends Base
|
||||
if (Request::isPost()) {
|
||||
$data = input('post.');
|
||||
$id = input('id/d', 0);
|
||||
|
||||
|
||||
if (!$id) {
|
||||
Log::record('编辑资源', 0, '参数错误', '资源管理');
|
||||
return json(['code' => 1, 'msg' => '参数错误']);
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
$result = Db::table('yz_resources')->where('id', $id)->update([
|
||||
$updateData = [
|
||||
'title' => $data['title'],
|
||||
'cate' => $data['cate'],
|
||||
'desc' => $data['desc'],
|
||||
@@ -435,7 +334,10 @@ class Resources extends Base
|
||||
'code' => $data['code'],
|
||||
'sort' => $data['sort'],
|
||||
'update_time' => time()
|
||||
]);
|
||||
];
|
||||
|
||||
$result = Resource::where('id', $id)
|
||||
->update($updateData);
|
||||
|
||||
if ($result !== false) {
|
||||
Log::record('编辑资源', 1, '', '资源管理');
|
||||
@@ -452,7 +354,10 @@ class Resources extends Base
|
||||
$this->error('参数错误');
|
||||
}
|
||||
|
||||
$resource = Db::table('yz_resources')->where('id', $id)->find();
|
||||
$resource = Resource::where('id', $id)
|
||||
->where('delete_time', null)
|
||||
->find();
|
||||
|
||||
if (!$resource) {
|
||||
Log::record('编辑资源', 0, '资源不存在', '资源管理');
|
||||
$this->error('资源不存在');
|
||||
@@ -463,12 +368,11 @@ class Resources extends Base
|
||||
}
|
||||
|
||||
//统计资源数量
|
||||
public function counts() {
|
||||
$total = Db::table('yz_resources')
|
||||
->where('delete_time', null)
|
||||
public function counts()
|
||||
{
|
||||
$total = Resource::where('delete_time', null)
|
||||
->where('status', '<>', 3)
|
||||
->count();
|
||||
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => '获取成功',
|
||||
@@ -478,4 +382,56 @@ class Resources extends Base
|
||||
]);
|
||||
}
|
||||
|
||||
// 构建树形结构
|
||||
private function buildTree($lists)
|
||||
{
|
||||
$tree = [];
|
||||
foreach ($lists as $item) {
|
||||
if ($item['cid'] == 0) {
|
||||
$node = [
|
||||
'id' => $item['id'],
|
||||
'title' => $item['name'],
|
||||
'children' => []
|
||||
];
|
||||
|
||||
// 查找子分类
|
||||
foreach ($lists as $subItem) {
|
||||
if ($subItem['cid'] == $item['id']) {
|
||||
$node['children'][] = [
|
||||
'id' => $subItem['id'],
|
||||
'title' => $subItem['name'],
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$tree[] = $node;
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
|
||||
// 构建父子结构
|
||||
private function buildParentChild($lists)
|
||||
{
|
||||
$tree = [];
|
||||
foreach ($lists as $item) {
|
||||
if ($item['cid'] == 0) {
|
||||
// 顶级分类
|
||||
$tree[] = $item;
|
||||
} else {
|
||||
// 子分类
|
||||
foreach ($tree as &$parent) {
|
||||
if ($parent['id'] == $item['cid']) {
|
||||
if (!isset($parent['children'])) {
|
||||
$parent['children'] = [];
|
||||
}
|
||||
$parent['children'][] = $item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace app\admin\model\Article;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class Article extends Model
|
||||
{
|
||||
// 设置当前模型对应的数据表名称(不含前缀)
|
||||
protected $name = 'article';
|
||||
|
||||
// 设置主键
|
||||
protected $pk = 'id';
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace app\admin\model\Article;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class ArticleCategory extends Model
|
||||
{
|
||||
// 设置当前模型对应的数据表名称(不含前缀)
|
||||
protected $name = 'article_category';
|
||||
|
||||
// 设置主键
|
||||
protected $pk = 'id';
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace app\admin\model\Resource;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class Resource extends Model
|
||||
{
|
||||
// 设置当前模型对应的数据表名称(不含前缀)
|
||||
protected $name = 'resources';
|
||||
|
||||
// 设置主键
|
||||
protected $pk = 'id';
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace app\admin\model\Resource;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class ResourceCategory extends Model
|
||||
{
|
||||
// 设置当前模型对应的数据表名称(不含前缀)
|
||||
protected $name = 'resources_category';
|
||||
|
||||
// 设置主键
|
||||
protected $pk = 'id';
|
||||
}
|
||||
@@ -3,10 +3,17 @@
|
||||
* 配置表
|
||||
*/
|
||||
namespace app\admin\model;
|
||||
use app\admin\model\Base;
|
||||
|
||||
class YzAdminConfig extends Base{
|
||||
use think\Model;
|
||||
|
||||
class YzAdminConfig extends Model
|
||||
{
|
||||
// 设置当前模型对应的数据表名称(不含前缀)
|
||||
protected $name = 'admin_config';
|
||||
|
||||
// 设置主键
|
||||
protected $pk = 'config_id';
|
||||
|
||||
/**
|
||||
* 列出全部配置,key对应value
|
||||
*/
|
||||
@@ -22,6 +29,7 @@ class YzAdminConfig extends Base{
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 多条数据更新
|
||||
*/
|
||||
|
||||
@@ -322,7 +322,7 @@
|
||||
// 初始化分类列表
|
||||
that.initCategoryList = function () {
|
||||
$.ajax({
|
||||
url: '/admin/article/articlecate',
|
||||
url: '/admin/articles/articlecate',
|
||||
type: 'POST',
|
||||
success: function (res) {
|
||||
if (res.code === 0) {
|
||||
@@ -387,7 +387,7 @@
|
||||
|
||||
// 加载分类信息
|
||||
that.loadCategoryInfo = function (id) {
|
||||
$.get('/admin/article/cateedit?id=' + id, function (res) {
|
||||
$.get('/admin/articles/cateedit?id=' + id, function (res) {
|
||||
if (res.code === 0) {
|
||||
that.showCategoryForm(0, res.data);
|
||||
}
|
||||
@@ -413,7 +413,7 @@
|
||||
$select.empty().append('<option value="0">顶级分类</option>');
|
||||
// 获取所有分类作为父级选项
|
||||
$.ajax({
|
||||
url: '/admin/article/articlecate',
|
||||
url: '/admin/articles/articlecate',
|
||||
type: 'POST',
|
||||
async: false,
|
||||
success: function (res) {
|
||||
@@ -472,7 +472,7 @@
|
||||
|
||||
// 监听表单提交
|
||||
form.on('submit(saveCategory)', function (data) {
|
||||
var url = data.field.id ? '/admin/article/cateedit' : '/admin/article/cateadd';
|
||||
var url = data.field.id ? '/admin/articles/cateedit' : '/admin/articles/cateadd';
|
||||
$.post(url, data.field, function (res) {
|
||||
if (res.code === 0) {
|
||||
layer.msg(res.msg, { icon: 1 });
|
||||
@@ -490,7 +490,7 @@
|
||||
if (!id) return;
|
||||
|
||||
layer.confirm('确定要删除该分类吗?', function (index) {
|
||||
$.post('/admin/article/catedel', { id: id }, function (res) {
|
||||
$.post('/admin/articles/catedel', { id: id }, function (res) {
|
||||
if (res.code === 0) {
|
||||
layer.msg(res.msg, { icon: 1 });
|
||||
that.initCategoryList();
|
||||
|
||||
@@ -87,7 +87,7 @@
|
||||
// 初始化表格
|
||||
table.render({
|
||||
elem: '#articleTable',
|
||||
url: '/admin/article/articlelist',
|
||||
url: '/admin/articles/articlelist',
|
||||
method: 'post',
|
||||
cols: [[
|
||||
{ field: 'id', title: 'ID', align: 'center', width: 80 },
|
||||
@@ -174,18 +174,18 @@
|
||||
}
|
||||
|
||||
function add() {
|
||||
window.location.href = '/admin/article/add';
|
||||
window.location.href = '/admin/articles/add';
|
||||
}
|
||||
|
||||
function edit(id) {
|
||||
window.location.href = '/admin/article/edit?id=' + id;
|
||||
window.location.href = '/admin/articles/edit?id=' + id;
|
||||
}
|
||||
|
||||
function del(id) {
|
||||
layer.confirm('确定要删除该文章吗?', {
|
||||
btn: ['确定', '取消']
|
||||
}, function () {
|
||||
$.post('/admin/article/delete', { id: id }, function (res) {
|
||||
$.post('/admin/articles/delete', { id: id }, function (res) {
|
||||
if (res.code == 0) {
|
||||
layer.msg(res.msg, { icon: 1 });
|
||||
setTimeout(function () {
|
||||
|
||||
@@ -57,13 +57,13 @@
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="statusTemplate">
|
||||
{{# if(d.status === 0){ }}
|
||||
{{# if(d.status == '0'){ }}
|
||||
<span style="color:red;">未审核</span>
|
||||
{{# } else if(d.status === 1){ }}
|
||||
{{# } else if(d.status == '1'){ }}
|
||||
<span style="color:orange;">待审核</span>
|
||||
{{# } else if(d.status === 2){ }}
|
||||
{{# } else if(d.status == '2'){ }}
|
||||
<span style="color:green;">已发布</span>
|
||||
{{# } else if(d.status === 3){ }}
|
||||
{{# } else if(d.status == '3'){ }}
|
||||
<span style="color:gray;">已下架</span>
|
||||
{{# } }}
|
||||
</script>
|
||||
@@ -157,7 +157,13 @@
|
||||
|
||||
function reloadTable() {
|
||||
var categoryId = $('#categoryFilter').val();
|
||||
var categoryName = categoryId ? $('#categoryFilter option[value="' + categoryId + '"]').text() : '';
|
||||
var categoryName = '';
|
||||
if (categoryId) {
|
||||
var selectedOption = $('#categoryFilter option[value="' + categoryId + '"]');
|
||||
if (selectedOption.length > 0) {
|
||||
categoryName = selectedOption.text().trim();
|
||||
}
|
||||
}
|
||||
var nameKeyword = $('#nameSearch').val().trim();
|
||||
var uploaderKeyword = $('#uploaderSearch').val().trim();
|
||||
|
||||
|
||||
@@ -192,13 +192,14 @@
|
||||
|
||||
.prev-article a,
|
||||
.next-article a {
|
||||
color: #333;
|
||||
color: #333 !important;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.prev-article a:hover,
|
||||
.next-article a:hover {
|
||||
color: #f57005;
|
||||
color: #f57005 !important;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.disabled {
|
||||
|
||||
Reference in New Issue
Block a user