更新代码

This commit is contained in:
李志强 2025-05-19 17:34:40 +08:00
parent 1587524031
commit 7bd072add9
32 changed files with 1465 additions and 139 deletions

View File

@ -3,16 +3,25 @@
* 后台管理系统-文章管理 * 后台管理系统-文章管理
*/ */
namespace app\admin\controller; namespace app\admin\controller;
use app\admin\controller\Base; use app\admin\model\Article\Articles;
use app\admin\model\Article\Article; use app\admin\model\Article\ArticlesCategory;
use app\admin\model\Article\ArticleCategory;
use think\facade\Db; use think\facade\Db;
use think\facade\View; use think\facade\View;
use think\facade\Request; use think\facade\Request;
use app\admin\controller\Log; use app\admin\controller\Log;
use app\admin\controller\BaseController;
class Articles extends Base class Article extends BaseController
{ {
/**
* 获取控制器名称
* @return string
*/
public function getControllerName()
{
return 'Article';
}
// 文章列表 // 文章列表
public function articlelist() public function articlelist()
{ {
@ -23,13 +32,13 @@ class Articles extends Base
$title = input('post.title'); $title = input('post.title');
$author = input('post.author'); $author = input('post.author');
$query = Article::where('delete_time', null) $query = Articles::where('delete_time', null)
->where('status', '<>', 3); ->where('status', '<>', 3);
// 分类筛选 // 分类筛选
if (!empty($category)) { if (!empty($category)) {
// 先获取分类ID // 先获取分类ID
$cateInfo = ArticleCategory::where('name', $category) $cateInfo = ArticlesCategory::where('name', $category)
->where('delete_time', null) ->where('delete_time', null)
->where('status', 1) ->where('status', 1)
->find(); ->find();
@ -58,7 +67,7 @@ class Articles extends Base
->select() ->select()
->each(function ($item) { ->each(function ($item) {
// 获取分类信息 // 获取分类信息
$cateInfo = ArticleCategory::where('id', $item['cate']) $cateInfo = ArticlesCategory::where('id', $item['cate'])
->field('name, image') ->field('name, image')
->find(); ->find();
@ -85,7 +94,7 @@ class Articles extends Base
]); ]);
} else { } else {
// 获取所有分类并构建父子结构 // 获取所有分类并构建父子结构
$allCategories = ArticleCategory::where('delete_time', null) $allCategories = ArticlesCategory::where('delete_time', null)
->where('status', 1) ->where('status', 1)
->order('sort asc, id asc') ->order('sort asc, id asc')
->select() ->select()
@ -127,7 +136,7 @@ class Articles extends Base
'create_time' => time() 'create_time' => time()
]; ];
$insert = Article::insert($data); $insert = Articles::insert($data);
if (empty($insert)) { if (empty($insert)) {
Log::record('添加文章', 0, '添加文章失败', '文章管理'); Log::record('添加文章', 0, '添加文章失败', '文章管理');
return json(['code' => 1, 'msg' => '添加失败', 'data' => []]); return json(['code' => 1, 'msg' => '添加失败', 'data' => []]);
@ -135,7 +144,7 @@ class Articles extends Base
Log::record('添加文章', 1, '', '文章管理'); Log::record('添加文章', 1, '', '文章管理');
return json(['code' => 0, 'msg' => '添加成功', 'data' => []]); return json(['code' => 0, 'msg' => '添加成功', 'data' => []]);
} else { } else {
$lists = Article::order('id DESC') $lists = Articles::order('id DESC')
->select() ->select()
->each(function ($item, $key) { ->each(function ($item, $key) {
$item['create_time'] = time(); $item['create_time'] = time();
@ -164,7 +173,7 @@ class Articles extends Base
'update_time' => time() 'update_time' => time()
]; ];
$update = Article::where('id', $id)->update($data); $update = Articles::where('id', $id)->update($data);
if ($update === false) { if ($update === false) {
Log::record('编辑文章', 0, '编辑文章失败', '文章管理'); Log::record('编辑文章', 0, '编辑文章失败', '文章管理');
return json(['code' => 1, 'msg' => '更新失败', 'data' => []]); return json(['code' => 1, 'msg' => '更新失败', 'data' => []]);
@ -173,12 +182,12 @@ class Articles extends Base
return json(['code' => 0, 'msg' => '更新成功', 'data' => []]); return json(['code' => 0, 'msg' => '更新成功', 'data' => []]);
} else { } else {
$id = input('get.id'); $id = input('get.id');
$info = Article::where('id', $id)->find(); $info = Articles::where('id', $id)->find();
if ($info === null) { if ($info === null) {
return json(['code' => 1, 'msg' => '文章不存在', 'data' => []]); return json(['code' => 1, 'msg' => '文章不存在', 'data' => []]);
} }
$cates = ArticleCategory::where('delete_time', null) $cates = ArticlesCategory::where('delete_time', null)
->where('status', 1) ->where('status', 1)
->order('sort asc, id asc') ->order('sort asc, id asc')
->select() ->select()
@ -186,7 +195,7 @@ class Articles extends Base
$info['content'] = !empty($info['content']) ? htmlspecialchars_decode(str_replace(["\r\n", "\r", "\n"], '', addslashes($info['content']))) : ''; $info['content'] = !empty($info['content']) ? htmlspecialchars_decode(str_replace(["\r\n", "\r", "\n"], '', addslashes($info['content']))) : '';
$currentCate = ArticleCategory::where('id', $info['cate']) $currentCate = ArticlesCategory::where('id', $info['cate'])
->where('delete_time', null) ->where('delete_time', null)
->where('status', 1) ->where('status', 1)
->find(); ->find();
@ -207,7 +216,7 @@ class Articles extends Base
$data = [ $data = [
'delete_time' => time(), 'delete_time' => time(),
]; ];
$delete = Article::where('id', $id)->update($data); $delete = Articles::where('id', $id)->update($data);
if ($delete === false) { if ($delete === false) {
Log::record('删除文章', 0, '删除文章失败', '文章管理'); Log::record('删除文章', 0, '删除文章失败', '文章管理');
return json(['code' => 1, 'msg' => '删除失败', 'data' => []]); return json(['code' => 1, 'msg' => '删除失败', 'data' => []]);
@ -220,7 +229,7 @@ class Articles extends Base
public function articlecate() public function articlecate()
{ {
if (Request::isPost()) { if (Request::isPost()) {
$lists = ArticleCategory::where('delete_time', null) $lists = ArticlesCategory::where('delete_time', null)
->where('status', 1) ->where('status', 1)
->order('sort asc, id asc') ->order('sort asc, id asc')
->select() ->select()
@ -262,7 +271,7 @@ class Articles extends Base
public function getcate() public function getcate()
{ {
// 获取所有分类 // 获取所有分类
$lists = ArticleCategory::where('delete_time', null) $lists = ArticlesCategory::where('delete_time', null)
->where('status', 1) ->where('status', 1)
->order('sort asc, id asc') ->order('sort asc, id asc')
->select() ->select()
@ -304,7 +313,7 @@ class Articles extends Base
'create_time' => time() 'create_time' => time()
]; ];
$insert = ArticleCategory::insert($data); $insert = ArticlesCategory::insert($data);
if (empty($insert)) { if (empty($insert)) {
Log::record('添加文章分类', 0, '添加文章分类失败', '文章分类'); Log::record('添加文章分类', 0, '添加文章分类失败', '文章分类');
return json(['code' => 1, 'msg' => '添加失败', 'data' => []]); return json(['code' => 1, 'msg' => '添加失败', 'data' => []]);
@ -313,7 +322,7 @@ class Articles extends Base
return json(['code' => 0, 'msg' => '添加成功', 'data' => []]); return json(['code' => 0, 'msg' => '添加成功', 'data' => []]);
} else { } else {
// 获取所有可选的父级分类 // 获取所有可选的父级分类
$parentCategories = ArticleCategory::where('delete_time', null) $parentCategories = ArticlesCategory::where('delete_time', null)
->where('status', 1) ->where('status', 1)
->where('cid', 0) ->where('cid', 0)
->field('id, name') ->field('id, name')
@ -344,7 +353,7 @@ class Articles extends Base
'update_time' => time() 'update_time' => time()
]; ];
$update = ArticleCategory::where('id', $data['id']) $update = ArticlesCategory::where('id', $data['id'])
->update($data); ->update($data);
if ($update === false) { if ($update === false) {
@ -355,10 +364,10 @@ class Articles extends Base
return json(['code' => 0, 'msg' => '更新成功', 'data' => []]); return json(['code' => 0, 'msg' => '更新成功', 'data' => []]);
} else { } else {
$id = input('get.id'); $id = input('get.id');
$info = ArticleCategory::where('id', $id)->find(); $info = ArticlesCategory::where('id', $id)->find();
// 获取所有可选的父级分类 // 获取所有可选的父级分类
$parentCategories = ArticleCategory::where('delete_time', null) $parentCategories = ArticlesCategory::where('delete_time', null)
->where('status', 1) ->where('status', 1)
->where('id', '<>', $id) // 排除自己 ->where('id', '<>', $id) // 排除自己
->where(function ($query) use ($id) { ->where(function ($query) use ($id) {
@ -397,7 +406,7 @@ class Articles extends Base
$id = input('post.id'); $id = input('post.id');
// 检查是否有子分类 // 检查是否有子分类
$hasChildren = ArticleCategory::where('cid', $id) $hasChildren = ArticlesCategory::where('cid', $id)
->where('delete_time', null) ->where('delete_time', null)
->find(); ->find();
@ -406,7 +415,7 @@ class Articles extends Base
return json(['code' => 1, 'msg' => '该分类下有子分类,无法删除', 'data' => []]); return json(['code' => 1, 'msg' => '该分类下有子分类,无法删除', 'data' => []]);
} }
$delete = ArticleCategory::where('id', $id) $delete = ArticlesCategory::where('id', $id)
->update(['delete_time' => time()]); ->update(['delete_time' => time()]);
if ($delete === false) { if ($delete === false) {
@ -419,7 +428,7 @@ class Articles extends Base
//统计文章数量 //统计文章数量
public function counts() { public function counts() {
$total = Article::where('delete_time', null) $total = Articles::where('delete_time', null)
->where('status', '<>', 3) ->where('status', '<>', 3)
->count(); ->count();

View File

@ -1,16 +1,16 @@
<?php <?php
declare (strict_types = 1); declare (strict_types = 1);
namespace app; namespace app\admin\controller;
use think\App; use think\App;
use think\exception\ValidateException; use think\exception\ValidateException;
use think\Validate; use think\Validate;
/** /**
* 控制器基础类 * 后台控制器基础类
*/ */
abstract class BaseController abstract class BaseController extends Base
{ {
/** /**
* Request实例 * Request实例
@ -43,16 +43,54 @@ abstract class BaseController
*/ */
public function __construct(App $app) public function __construct(App $app)
{ {
parent::__construct();
$this->app = $app; $this->app = $app;
$this->request = $this->app->request; $this->request = $this->app->request;
// 控制器初始化 // 控制器初始化
$this->initialize(); $this->initialize($app);
} }
// 初始化 /**
protected function initialize() * 初始化
{} * @access public
* @param App $app 应用对象
*/
public function initialize(App $app)
{
// 注册控制器映射
$this->registerControllerMap();
}
/**
* 注册控制器映射
*/
protected function registerControllerMap()
{
// 获取当前控制器类名
$className = get_class($this);
// 获取不带命名空间的类名
$shortName = substr($className, strrpos($className, '\\') + 1);
// 移除Controller后缀
$mapName = str_replace('Controller', '', $shortName);
// 调试信息
trace("Controller Mapping: {$mapName} => {$className}", 'debug');
// 注册控制器映射
$this->app->route->setControllerMap($mapName, $className);
}
/**
* 获取控制器名称移除Controller后缀
* @return string
*/
public function getControllerName()
{
$className = get_class($this);
$className = substr($className, strrpos($className, '\\') + 1);
return str_replace('Controller', '', $className);
}
/** /**
* 验证数据 * 验证数据
@ -90,5 +128,4 @@ abstract class BaseController
return $v->failException(true)->check($data); return $v->failException(true)->check($data);
} }
}
}

View File

@ -3,7 +3,7 @@
* 后台管理系统-资源管理 * 后台管理系统-资源管理
*/ */
namespace app\admin\controller; namespace app\admin\controller;
use app\admin\controller\Base; use app\admin\controller\BaseController;
use app\admin\model\Resource\Resource; use app\admin\model\Resource\Resource;
use app\admin\model\Resource\ResourceCategory; use app\admin\model\Resource\ResourceCategory;
use think\facade\View; use think\facade\View;
@ -12,7 +12,7 @@ use think\facade\Db;
use app\admin\controller\Log; use app\admin\controller\Log;
use think\App; use think\App;
class Resources extends Base class Resources extends BaseController
{ {
// 资源列表 // 资源列表
public function lists() public function lists()

View File

@ -1,13 +0,0 @@
<?php
namespace app\admin\model\Article;
use think\Model;
class Article extends Model
{
// 设置当前模型对应的数据表名称(不含前缀)
protected $name = 'article';
// 设置主键
protected $pk = 'id';
}

View File

@ -1,13 +0,0 @@
<?php
namespace app\admin\model\Article;
use think\Model;
class ArticleCategory extends Model
{
// 设置当前模型对应的数据表名称(不含前缀)
protected $name = 'article_category';
// 设置主键
protected $pk = 'id';
}

View File

@ -1,5 +1,5 @@
<?php <?php
namespace app\index\model; namespace app\admin\model\Article;
use think\Model; use think\Model;

View File

@ -1,5 +1,5 @@
<?php <?php
namespace app\index\model; namespace app\admin\model\Article;
use think\Model; use think\Model;

View File

@ -322,7 +322,7 @@
// 初始化分类列表 // 初始化分类列表
that.initCategoryList = function () { that.initCategoryList = function () {
$.ajax({ $.ajax({
url: '/admin/articles/articlecate', url: '/admin/article/articlecate',
type: 'POST', type: 'POST',
success: function (res) { success: function (res) {
if (res.code === 0) { if (res.code === 0) {
@ -387,7 +387,7 @@
// 加载分类信息 // 加载分类信息
that.loadCategoryInfo = function (id) { that.loadCategoryInfo = function (id) {
$.get('/admin/articles/cateedit?id=' + id, function (res) { $.get('/admin/article/cateedit?id=' + id, function (res) {
if (res.code === 0) { if (res.code === 0) {
that.showCategoryForm(0, res.data); that.showCategoryForm(0, res.data);
} }
@ -413,7 +413,7 @@
$select.empty().append('<option value="0">顶级分类</option>'); $select.empty().append('<option value="0">顶级分类</option>');
// 获取所有分类作为父级选项 // 获取所有分类作为父级选项
$.ajax({ $.ajax({
url: '/admin/articles/articlecate', url: '/admin/article/articlecate',
type: 'POST', type: 'POST',
async: false, async: false,
success: function (res) { success: function (res) {
@ -472,7 +472,7 @@
// 监听表单提交 // 监听表单提交
form.on('submit(saveCategory)', function (data) { form.on('submit(saveCategory)', function (data) {
var url = data.field.id ? '/admin/articles/cateedit' : '/admin/articles/cateadd'; var url = data.field.id ? '/admin/article/cateedit' : '/admin/article/cateadd';
$.post(url, data.field, function (res) { $.post(url, data.field, function (res) {
if (res.code === 0) { if (res.code === 0) {
layer.msg(res.msg, { icon: 1 }); layer.msg(res.msg, { icon: 1 });
@ -490,7 +490,7 @@
if (!id) return; if (!id) return;
layer.confirm('确定要删除该分类吗?', function (index) { layer.confirm('确定要删除该分类吗?', function (index) {
$.post('/admin/articles/catedel', { id: id }, function (res) { $.post('/admin/article/catedel', { id: id }, function (res) {
if (res.code === 0) { if (res.code === 0) {
layer.msg(res.msg, { icon: 1 }); layer.msg(res.msg, { icon: 1 });
that.initCategoryList(); that.initCategoryList();

View File

@ -87,7 +87,7 @@
// 初始化表格 // 初始化表格
table.render({ table.render({
elem: '#articleTable', elem: '#articleTable',
url: '/admin/articles/articlelist', url: '/admin/article/articlelist',
method: 'post', method: 'post',
cols: [[ cols: [[
{ field: 'id', title: 'ID', align: 'center', width: 80 }, { field: 'id', title: 'ID', align: 'center', width: 80 },
@ -174,18 +174,18 @@
} }
function add() { function add() {
window.location.href = '/admin/articles/add'; window.location.href = '/admin/article/add';
} }
function edit(id) { function edit(id) {
window.location.href = '/admin/articles/edit?id=' + id; window.location.href = '/admin/article/edit?id=' + id;
} }
function del(id) { function del(id) {
layer.confirm('确定要删除该文章吗?', { layer.confirm('确定要删除该文章吗?', {
btn: ['确定', '取消'] btn: ['确定', '取消']
}, function () { }, function () {
$.post('/admin/articles/delete', { id: id }, function (res) { $.post('/admin/article/delete', { id: id }, function (res) {
if (res.code == 0) { if (res.code == 0) {
layer.msg(res.msg, { icon: 1 }); layer.msg(res.msg, { icon: 1 });
setTimeout(function () { setTimeout(function () {

View File

@ -3,12 +3,14 @@
* 文章控制器 * 文章控制器
*/ */
namespace app\index\controller; namespace app\index\controller;
use app\index\controller\Base; use app\index\controller\BaseController;
use think\facade\Db; use think\facade\Db;
use think\facade\View; use think\facade\View;
use think\facade\Request; use think\facade\Request;
use app\index\model\Articles\Articles;
use app\index\model\Articles\ArticlesCategory;
class Article extends Base class ArticlesController extends BaseController
{ {
// 文章列表页 // 文章列表页
public function list() public function list()
@ -27,8 +29,7 @@ class Article extends Base
} }
// 获取文章列表 // 获取文章列表
$articles = Db::table('yz_article') $articles = Articles::where($where)
->where($where)
->order('id DESC') ->order('id DESC')
->paginate([ ->paginate([
'list_rows' => 10, 'list_rows' => 10,
@ -38,16 +39,14 @@ class Article extends Base
// 获取分类信息 // 获取分类信息
$category = null; $category = null;
if ($cateId > 0) { if ($cateId > 0) {
$category = Db::table('yz_article_category') $category = ArticlesCategory::where('id', $cateId)
->where('id', $cateId)
->where('delete_time', null) ->where('delete_time', null)
->where('status', 3) ->where('status', 3)
->find(); ->find();
} }
// 获取所有分类 // 获取所有分类
$categories = Db::table('yz_article_category') $categories = ArticlesCategory::where('delete_time', null)
->where('delete_time', null)
->where('status', 3) ->where('status', 3)
->select() ->select()
->toArray(); ->toArray();
@ -66,36 +65,32 @@ class Article extends Base
public function detail() public function detail()
{ {
$id = Request::param('id/d', 0); $id = Request::param('id/d', 0);
$article = Db::table('yz_article')->where('id', $id)->find(); $article = Articles::where('id', $id)->find();
if (!$article) { if (!$article) {
return json(['code' => 0, 'msg' => '文章不存在或已被删除']); return json(['code' => 0, 'msg' => '文章不存在或已被删除']);
} }
// 获取分类名称 // 获取分类名称
$cateName = Db::table('yz_article_category') $cateName = ArticlesCategory::where('id', $article['cate'])
->where('id', $article['cate'])
->value('name'); ->value('name');
// 获取上一篇和下一篇文章 // 获取上一篇和下一篇文章
$prevArticle = Db::table('yz_article') $prevArticle = Articles::where('id', '<', $id)
->where('id', '<', $id)
->where('delete_time', null) ->where('delete_time', null)
->where('status', '<>', 3) ->where('status', '<>', 3)
->order('id DESC') ->order('id DESC')
->find(); ->find();
$nextArticle = Db::table('yz_article') $nextArticle = Articles::where('id', '>', $id)
->where('id', '>', $id)
->where('delete_time', null) ->where('delete_time', null)
->where('status', '<>', 3) ->where('status', '<>', 3)
->order('id ASC') ->order('id ASC')
->find(); ->find();
// 获取相关文章(同分类的其他文章) // 获取相关文章(同分类的其他文章)
$relatedArticles = Db::table('yz_article') $relatedArticles = Articles::alias('a')
->alias('a') ->join('articles_category c', 'a.cate = c.id')
->join('yz_article_category c', 'a.cate = c.id')
->where('a.cate', $article['cate']) ->where('a.cate', $article['cate'])
->where('a.id', '<>', $id) ->where('a.id', '<>', $id)
->where('a.delete_time', null) ->where('a.delete_time', null)
@ -148,8 +143,7 @@ class Article extends Base
$id = Request::param('id/d', 0); $id = Request::param('id/d', 0);
// 更新点赞数 // 更新点赞数
$result = Db::table('yz_article') $result = Articles::where('id', $id)
->where('id', $id)
->where('delete_time', null) ->where('delete_time', null)
->inc('likes', 1) ->inc('likes', 1)
->update(); ->update();
@ -177,8 +171,7 @@ class Article extends Base
} }
// 检查文章是否存在 // 检查文章是否存在
$article = Db::table('yz_article') $article = Articles::where('id', $articleId)
->where('id', $articleId)
->where('delete_time', null) ->where('delete_time', null)
->where('status', 3) ->where('status', 3)
->find(); ->find();
@ -228,8 +221,7 @@ class Article extends Base
// 获取总访问量 // 获取总访问量
$totalViews = Db::table('yz_article') $totalViews = Articles::where('id', $id)
->where('id', $id)
->value('views'); ->value('views');
return json([ return json([
@ -256,16 +248,16 @@ class Article extends Base
try { try {
// 更新访问次数 // 更新访问次数
$article = Db::table('yz_article')->where('id', $id)->find(); $article = Articles::where('id', $id)->find();
if (!$article) { if (!$article) {
return json(['code' => 0, 'msg' => '文章不存在']); return json(['code' => 0, 'msg' => '文章不存在']);
} }
// 更新访问次数 // 更新访问次数
Db::table('yz_article')->where('id', $id)->inc('views')->update(); Articles::where('id', $id)->inc('views')->update();
// 获取更新后的访问次数 // 获取更新后的访问次数
$newViews = Db::table('yz_article')->where('id', $id)->value('views'); $newViews = Articles::where('id', $id)->value('views');
return json(['code' => 1, 'msg' => '更新成功', 'data' => ['views' => $newViews]]); return json(['code' => 1, 'msg' => '更新成功', 'data' => ['views' => $newViews]]);
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@ -0,0 +1,139 @@
<?php
declare (strict_types = 1);
namespace app\index\controller;
use think\App;
use think\facade\View;
use think\facade\Request;
use think\facade\Config;
/**
* 前台控制器基础类
*/
abstract class BaseController
{
/**
* Request实例
* @var \think\Request
*/
protected $request;
/**
* 应用实例
* @var \think\App
*/
protected $app;
/**
* 构造方法
* @access public
* @param App $app 应用对象
*/
public function __construct(App $app)
{
$this->app = $app;
$this->request = $this->app->request;
// 控制器初始化
$this->initialize();
}
/**
* 初始化
*/
protected function initialize()
{
// 设置通用变量
View::assign([
'site_name' => '网站名称',
'site_description' => '网站描述',
'site_keywords' => '网站关键词',
'config' => [
'admin_name' => Config::get('site.name', '云泽科技'),
'admin_phone' => Config::get('site.phone', '400-123-4567'),
'admin_email' => Config::get('site.email', 'admin@example.com'),
'admin_wechat' => Config::get('site.wechat_qrcode', '/static/images/wechat_qrcode.jpg'),
'logo' => Config::get('site.logo', '/static/images/logo.png'),
'logo1' => Config::get('site.logo1', '/static/images/logo1.png'),
'admin_route' => Config::get('site.admin_route', '/admin/')
]
]);
}
/**
* 获取控制器名称移除Controller后缀
* @return string
*/
public function getControllerName()
{
$className = get_class($this);
$className = substr($className, strrpos($className, '\\') + 1);
return str_replace('Controller', '', $className);
}
/**
* 渲染模板输出
* @param string $template 模板文件
* @param array $vars 模板变量
* @return string
*/
protected function fetch($template = '', $vars = [])
{
return View::fetch($template, $vars);
}
/**
* 操作成功跳转
* @param string $msg 提示信息
* @param string $url 跳转地址
* @param mixed $data 返回数据
* @param integer $wait 跳转等待时间
* @return void
*/
protected function success($msg = '', $url = null, $data = '', $wait = 3)
{
if (Request::isAjax()) {
return json([
'code' => 1,
'msg' => $msg,
'data' => $data,
'url' => $url
]);
}
return View::fetch('common/success', [
'msg' => $msg,
'url' => $url,
'data' => $data,
'wait' => $wait
]);
}
/**
* 操作失败跳转
* @param string $msg 提示信息
* @param string $url 跳转地址
* @param mixed $data 返回数据
* @param integer $wait 跳转等待时间
* @return void
*/
protected function error($msg = '', $url = null, $data = '', $wait = 3)
{
if (Request::isAjax()) {
return json([
'code' => 0,
'msg' => $msg,
'data' => $data,
'url' => $url
]);
}
return View::fetch('common/error', [
'msg' => $msg,
'url' => $url,
'data' => $data,
'wait' => $wait
]);
}
}

View File

@ -3,19 +3,19 @@
* 后台管理系统-首页 * 后台管理系统-首页
*/ */
namespace app\index\controller; namespace app\index\controller;
use app\index\controller\Base; use app\index\controller\BaseController;
use think\facade\Db; use think\facade\Db;
use think\facade\View; use think\facade\View;
use think\facade\Env; use think\facade\Env;
use think\facade\Config; use think\facade\Config;
use app\index\model\Banner; use app\index\model\Banner;
use app\index\model\ResourcesCategory; use app\index\model\Resources\ResourcesCategory;
use app\index\model\ArticlesCategory; use app\index\model\Articles\ArticlesCategory;
use app\index\model\Resources; use app\index\model\Resources\Resources;
use app\index\model\Articles; use app\index\model\Articles\Articles;
class Index extends Base class IndexController extends BaseController
{ {
/** /**
* 首页 * 首页

View File

@ -3,15 +3,15 @@
* 程序下载控制器 * 程序下载控制器
*/ */
namespace app\index\controller; namespace app\index\controller;
use app\index\controller\Base; use app\index\controller\BaseController;
use think\facade\Db; use think\facade\Db;
use think\facade\View; use think\facade\View;
use think\facade\Request; use think\facade\Request;
use app\index\model\Resources; use app\index\model\Resources\Resources;
use app\index\model\ResourcesCategory; use app\index\model\Resources\ResourcesCategory;
use app\index\model\Attachments; use app\index\model\Attachments;
class Program extends Base class ProgramController extends BaseController
{ {
// 程序列表页 // 程序列表页
public function list() public function list()

View File

@ -0,0 +1,8 @@
<?php
namespace app\index\model\Articles;
use think\Model;
class Articles extends Model
{
}

View File

@ -0,0 +1,8 @@
<?php
namespace app\index\model\Articles;
use think\Model;
class ArticlesCategory extends Model
{
}

View File

@ -1,5 +1,5 @@
<?php <?php
namespace app\index\model; namespace app\index\model\Resources;
use think\Model; use think\Model;

View File

@ -1,5 +1,5 @@
<?php <?php
namespace app\index\model; namespace app\index\model\Resources;
use think\Model; use think\Model;

View File

@ -21,7 +21,7 @@ return [
// 是否强制使用路由 // 是否强制使用路由
'url_route_must' => false, 'url_route_must' => false,
// 合并路由规则 // 合并路由规则
'route_rule_merge' => false, 'route_rule_merge' => true,
// 路由是否完全匹配 // 路由是否完全匹配
'route_complete_match' => false, 'route_complete_match' => false,
// 使用注解路由 // 使用注解路由
@ -68,7 +68,7 @@ return [
// 空控制器名 // 空控制器名
'empty_controller' => 'Error', 'empty_controller' => 'Error',
// 是否使用控制器后缀 // 是否使用控制器后缀
'controller_suffix' => false, 'controller_suffix' => true,
// 访问控制器层名称 // 访问控制器层名称
'controller_layer' => 'controller', 'controller_layer' => 'controller',
// 默认控制器名 // 默认控制器名

27
config/site.php Normal file
View File

@ -0,0 +1,27 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
return [
// 站点名称
'name' => '云泽科技',
// 联系电话
'phone' => '188-1152-3967',
// 联系邮箱
'email' => '357099073@qq.com',
// 微信二维码
'wechat_qrcode' => '/static/images/wechat_qrcode.jpg',
// 网站Logo
'logo' => '/static/images/logo.png',
// 网站Logo深色
'logo1' => '/static/images/logo1.png',
// 后台路由前缀
'admin_route' => '/admin/'
];

View File

@ -0,0 +1,24 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class CreateArticleCategoryTable extends Migrator
{
public function change()
{
$table = $this->table('yz_article_category', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_unicode_ci']);
$table
->addColumn('name', 'string', ['limit' => 50, 'null' => false, 'comment' => '分类名称'])
->addColumn('cid', 'integer', ['signed' => true, 'null' => false, 'default' => 0, 'comment' => '父级ID'])
->addColumn('image', 'string', ['limit' => 255, 'null' => true, 'comment' => '分类图片'])
->addColumn('sort', 'integer', ['signed' => true, 'null' => false, 'default' => 0, 'comment' => '排序'])
->addColumn('status', 'integer', ['signed' => true, 'null' => false, 'default' => 1, 'comment' => '状态1=正常2=禁用'])
->addColumn('create_time', 'integer', ['signed' => true, 'null' => false, 'default' => 0, 'comment' => '创建时间'])
->addColumn('update_time', 'integer', ['signed' => true, 'null' => false, 'default' => 0, 'comment' => '更新时间'])
->addColumn('delete_time', 'integer', ['signed' => true, 'null' => true, 'comment' => '删除时间'])
->addIndex(['cid'], ['name' => 'idx_cid'])
->addIndex(['status'], ['name' => 'idx_status'])
->create();
}
}

View File

@ -1,11 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\facade\Route;

View File

@ -181,7 +181,7 @@
// 初始化表格 // 初始化表格
table.render({ table.render({
elem: '#articleTable', elem: '#articleTable',
url: '/admin/articles/articlelist', url: '/admin/article/articlelist',
method: 'post', method: 'post',
cols: [[ cols: [[
{ field: 'id', title: 'ID', align: 'center', width: 80 }, { field: 'id', title: 'ID', align: 'center', width: 80 },
@ -268,18 +268,18 @@
} }
function add() { function add() {
window.location.href = '/admin/articles/add'; window.location.href = '/admin/article/add';
} }
function edit(id) { function edit(id) {
window.location.href = '/admin/articles/edit?id=' + id; window.location.href = '/admin/article/edit?id=' + id;
} }
function del(id) { function del(id) {
layer.confirm('确定要删除该文章吗?', { layer.confirm('确定要删除该文章吗?', {
btn: ['确定', '取消'] btn: ['确定', '取消']
}, function () { }, function () {
$.post('/admin/articles/delete', { id: id }, function (res) { $.post('/admin/article/delete', { id: id }, function (res) {
if (res.code == 0) { if (res.code == 0) {
layer.msg(res.msg, { icon: 1 }); layer.msg(res.msg, { icon: 1 });
setTimeout(function () { setTimeout(function () {

View File

@ -416,7 +416,7 @@
// 初始化分类列表 // 初始化分类列表
that.initCategoryList = function () { that.initCategoryList = function () {
$.ajax({ $.ajax({
url: '/admin/articles/articlecate', url: '/admin/article/articlecate',
type: 'POST', type: 'POST',
success: function (res) { success: function (res) {
if (res.code === 0) { if (res.code === 0) {
@ -481,7 +481,7 @@
// 加载分类信息 // 加载分类信息
that.loadCategoryInfo = function (id) { that.loadCategoryInfo = function (id) {
$.get('/admin/articles/cateedit?id=' + id, function (res) { $.get('/admin/article/cateedit?id=' + id, function (res) {
if (res.code === 0) { if (res.code === 0) {
that.showCategoryForm(0, res.data); that.showCategoryForm(0, res.data);
} }
@ -507,7 +507,7 @@
$select.empty().append('<option value="0">顶级分类</option>'); $select.empty().append('<option value="0">顶级分类</option>');
// 获取所有分类作为父级选项 // 获取所有分类作为父级选项
$.ajax({ $.ajax({
url: '/admin/articles/articlecate', url: '/admin/article/articlecate',
type: 'POST', type: 'POST',
async: false, async: false,
success: function (res) { success: function (res) {
@ -566,7 +566,7 @@
// 监听表单提交 // 监听表单提交
form.on('submit(saveCategory)', function (data) { form.on('submit(saveCategory)', function (data) {
var url = data.field.id ? '/admin/articles/cateedit' : '/admin/articles/cateadd'; var url = data.field.id ? '/admin/article/cateedit' : '/admin/article/cateadd';
$.post(url, data.field, function (res) { $.post(url, data.field, function (res) {
if (res.code === 0) { if (res.code === 0) {
layer.msg(res.msg, { icon: 1 }); layer.msg(res.msg, { icon: 1 });
@ -584,7 +584,7 @@
if (!id) return; if (!id) return;
layer.confirm('确定要删除该分类吗?', function (index) { layer.confirm('确定要删除该分类吗?', function (index) {
$.post('/admin/articles/catedel', { id: id }, function (res) { $.post('/admin/article/catedel', { id: id }, function (res) {
if (res.code === 0) { if (res.code === 0) {
layer.msg(res.msg, { icon: 1 }); layer.msg(res.msg, { icon: 1 });
that.initCategoryList(); that.initCategoryList();

View File

@ -1,4 +1,4 @@
<?php /*a:2:{s:67:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\article\articlelist.php";i:1747385257;s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\header.php";i:1746849526;}*/ ?> <?php /*a:2:{s:67:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\article\articlelist.php";i:1747642386;s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\header.php";i:1746849526;}*/ ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>

View File

@ -1,4 +1,4 @@
<?php /*a:2:{s:67:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\article\articlecate.php";i:1747387836;s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\header.php";i:1746849526;}*/ ?> <?php /*a:2:{s:67:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\article\articlecate.php";i:1747642386;s:61:"E:\Demos\DemoOwns\PHP\yunzer\app\admin\view\public\header.php";i:1746849526;}*/ ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
<?php /*a:4:{s:59:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\index\index.php";i:1746865108;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\header.php";i:1747445574;s:62:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\main.php";i:1747445574;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\footer.php";i:1747616057;}*/ ?> <?php /*a:4:{s:59:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\index\index.php";i:1746865108;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\header.php";i:1747445574;s:62:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\main.php";i:1747646542;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\footer.php";i:1747617266;}*/ ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@ -799,7 +799,7 @@
}); });
return ` return `
<div class="opencourse product-item" onclick="window.open('/index/article/detail?id=${article.id || ''}', '_blank')"> <div class="opencourse product-item" onclick="window.open('/index/articles/detail?id=${article.id || ''}', '_blank')">
<div class="video"> <div class="video">
<img src="${article.image || ''}" alt="" class="cover"> <img src="${article.image || ''}" alt="" class="cover">
</div> </div>
@ -1019,7 +1019,7 @@
</div> </div>
<div class="tongji"> <div class="tongji">
<script id="LA-DATA-WIDGET" crossorigin="anonymous" charset="UTF-8" <script id="LA-DATA-WIDGET" crossorigin="anonymous" charset="UTF-8"
src="https://v6-widget.51.la/v6/KoyzaWWEcLvPzkQn/quote.js?theme=0&f=12"></script> src="https://v6-widget.51.la/v6/KoyzaWWEcLvPzkQn/quote.js?theme=#1690FF,#FFFFFF,#999999,#FFFFFF,#FFFFFF,#1690FF,12&f=12"></script>
</div> </div>
</section> </section>