更新代码
This commit is contained in:
parent
1587524031
commit
7bd072add9
@ -3,16 +3,25 @@
|
||||
* 后台管理系统-文章管理
|
||||
*/
|
||||
namespace app\admin\controller;
|
||||
use app\admin\controller\Base;
|
||||
use app\admin\model\Article\Article;
|
||||
use app\admin\model\Article\ArticleCategory;
|
||||
use app\admin\model\Article\Articles;
|
||||
use app\admin\model\Article\ArticlesCategory;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
use think\facade\Request;
|
||||
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()
|
||||
{
|
||||
@ -23,13 +32,13 @@ class Articles extends Base
|
||||
$title = input('post.title');
|
||||
$author = input('post.author');
|
||||
|
||||
$query = Article::where('delete_time', null)
|
||||
$query = Articles::where('delete_time', null)
|
||||
->where('status', '<>', 3);
|
||||
|
||||
// 分类筛选
|
||||
if (!empty($category)) {
|
||||
// 先获取分类ID
|
||||
$cateInfo = ArticleCategory::where('name', $category)
|
||||
$cateInfo = ArticlesCategory::where('name', $category)
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->find();
|
||||
@ -58,7 +67,7 @@ class Articles extends Base
|
||||
->select()
|
||||
->each(function ($item) {
|
||||
// 获取分类信息
|
||||
$cateInfo = ArticleCategory::where('id', $item['cate'])
|
||||
$cateInfo = ArticlesCategory::where('id', $item['cate'])
|
||||
->field('name, image')
|
||||
->find();
|
||||
|
||||
@ -85,7 +94,7 @@ class Articles extends Base
|
||||
]);
|
||||
} else {
|
||||
// 获取所有分类并构建父子结构
|
||||
$allCategories = ArticleCategory::where('delete_time', null)
|
||||
$allCategories = ArticlesCategory::where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->order('sort asc, id asc')
|
||||
->select()
|
||||
@ -127,7 +136,7 @@ class Articles extends Base
|
||||
'create_time' => time()
|
||||
];
|
||||
|
||||
$insert = Article::insert($data);
|
||||
$insert = Articles::insert($data);
|
||||
if (empty($insert)) {
|
||||
Log::record('添加文章', 0, '添加文章失败', '文章管理');
|
||||
return json(['code' => 1, 'msg' => '添加失败', 'data' => []]);
|
||||
@ -135,7 +144,7 @@ class Articles extends Base
|
||||
Log::record('添加文章', 1, '', '文章管理');
|
||||
return json(['code' => 0, 'msg' => '添加成功', 'data' => []]);
|
||||
} else {
|
||||
$lists = Article::order('id DESC')
|
||||
$lists = Articles::order('id DESC')
|
||||
->select()
|
||||
->each(function ($item, $key) {
|
||||
$item['create_time'] = time();
|
||||
@ -164,7 +173,7 @@ class Articles extends Base
|
||||
'update_time' => time()
|
||||
];
|
||||
|
||||
$update = Article::where('id', $id)->update($data);
|
||||
$update = Articles::where('id', $id)->update($data);
|
||||
if ($update === false) {
|
||||
Log::record('编辑文章', 0, '编辑文章失败', '文章管理');
|
||||
return json(['code' => 1, 'msg' => '更新失败', 'data' => []]);
|
||||
@ -173,12 +182,12 @@ class Articles extends Base
|
||||
return json(['code' => 0, 'msg' => '更新成功', 'data' => []]);
|
||||
} else {
|
||||
$id = input('get.id');
|
||||
$info = Article::where('id', $id)->find();
|
||||
$info = Articles::where('id', $id)->find();
|
||||
if ($info === null) {
|
||||
return json(['code' => 1, 'msg' => '文章不存在', 'data' => []]);
|
||||
}
|
||||
|
||||
$cates = ArticleCategory::where('delete_time', null)
|
||||
$cates = ArticlesCategory::where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->order('sort asc, id asc')
|
||||
->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']))) : '';
|
||||
|
||||
$currentCate = ArticleCategory::where('id', $info['cate'])
|
||||
$currentCate = ArticlesCategory::where('id', $info['cate'])
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->find();
|
||||
@ -207,7 +216,7 @@ class Articles extends Base
|
||||
$data = [
|
||||
'delete_time' => time(),
|
||||
];
|
||||
$delete = Article::where('id', $id)->update($data);
|
||||
$delete = Articles::where('id', $id)->update($data);
|
||||
if ($delete === false) {
|
||||
Log::record('删除文章', 0, '删除文章失败', '文章管理');
|
||||
return json(['code' => 1, 'msg' => '删除失败', 'data' => []]);
|
||||
@ -220,7 +229,7 @@ class Articles extends Base
|
||||
public function articlecate()
|
||||
{
|
||||
if (Request::isPost()) {
|
||||
$lists = ArticleCategory::where('delete_time', null)
|
||||
$lists = ArticlesCategory::where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->order('sort asc, id asc')
|
||||
->select()
|
||||
@ -262,7 +271,7 @@ class Articles extends Base
|
||||
public function getcate()
|
||||
{
|
||||
// 获取所有分类
|
||||
$lists = ArticleCategory::where('delete_time', null)
|
||||
$lists = ArticlesCategory::where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->order('sort asc, id asc')
|
||||
->select()
|
||||
@ -304,7 +313,7 @@ class Articles extends Base
|
||||
'create_time' => time()
|
||||
];
|
||||
|
||||
$insert = ArticleCategory::insert($data);
|
||||
$insert = ArticlesCategory::insert($data);
|
||||
if (empty($insert)) {
|
||||
Log::record('添加文章分类', 0, '添加文章分类失败', '文章分类');
|
||||
return json(['code' => 1, 'msg' => '添加失败', 'data' => []]);
|
||||
@ -313,7 +322,7 @@ class Articles extends Base
|
||||
return json(['code' => 0, 'msg' => '添加成功', 'data' => []]);
|
||||
} else {
|
||||
// 获取所有可选的父级分类
|
||||
$parentCategories = ArticleCategory::where('delete_time', null)
|
||||
$parentCategories = ArticlesCategory::where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->where('cid', 0)
|
||||
->field('id, name')
|
||||
@ -344,7 +353,7 @@ class Articles extends Base
|
||||
'update_time' => time()
|
||||
];
|
||||
|
||||
$update = ArticleCategory::where('id', $data['id'])
|
||||
$update = ArticlesCategory::where('id', $data['id'])
|
||||
->update($data);
|
||||
|
||||
if ($update === false) {
|
||||
@ -355,10 +364,10 @@ class Articles extends Base
|
||||
return json(['code' => 0, 'msg' => '更新成功', 'data' => []]);
|
||||
} else {
|
||||
$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('id', '<>', $id) // 排除自己
|
||||
->where(function ($query) use ($id) {
|
||||
@ -397,7 +406,7 @@ class Articles extends Base
|
||||
$id = input('post.id');
|
||||
|
||||
// 检查是否有子分类
|
||||
$hasChildren = ArticleCategory::where('cid', $id)
|
||||
$hasChildren = ArticlesCategory::where('cid', $id)
|
||||
->where('delete_time', null)
|
||||
->find();
|
||||
|
||||
@ -406,7 +415,7 @@ class Articles extends Base
|
||||
return json(['code' => 1, 'msg' => '该分类下有子分类,无法删除', 'data' => []]);
|
||||
}
|
||||
|
||||
$delete = ArticleCategory::where('id', $id)
|
||||
$delete = ArticlesCategory::where('id', $id)
|
||||
->update(['delete_time' => time()]);
|
||||
|
||||
if ($delete === false) {
|
||||
@ -419,7 +428,7 @@ class Articles extends Base
|
||||
|
||||
//统计文章数量
|
||||
public function counts() {
|
||||
$total = Article::where('delete_time', null)
|
||||
$total = Articles::where('delete_time', null)
|
||||
->where('status', '<>', 3)
|
||||
->count();
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app;
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\App;
|
||||
use think\exception\ValidateException;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
* 后台控制器基础类
|
||||
*/
|
||||
abstract class BaseController
|
||||
abstract class BaseController extends Base
|
||||
{
|
||||
/**
|
||||
* Request实例
|
||||
@ -43,16 +43,54 @@ abstract class BaseController
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->app = $app;
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,7 @@
|
||||
* 后台管理系统-资源管理
|
||||
*/
|
||||
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\ResourceCategory;
|
||||
use think\facade\View;
|
||||
@ -12,7 +12,7 @@ use think\facade\Db;
|
||||
use app\admin\controller\Log;
|
||||
use think\App;
|
||||
|
||||
class Resources extends Base
|
||||
class Resources extends BaseController
|
||||
{
|
||||
// 资源列表
|
||||
public function lists()
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
namespace app\admin\model\Article;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class Article extends Model
|
||||
{
|
||||
// 设置当前模型对应的数据表名称(不含前缀)
|
||||
protected $name = 'article';
|
||||
|
||||
// 设置主键
|
||||
protected $pk = 'id';
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
namespace app\admin\model\Article;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class ArticleCategory extends Model
|
||||
{
|
||||
// 设置当前模型对应的数据表名称(不含前缀)
|
||||
protected $name = 'article_category';
|
||||
|
||||
// 设置主键
|
||||
protected $pk = 'id';
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace app\index\model;
|
||||
namespace app\admin\model\Article;
|
||||
|
||||
use think\Model;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace app\index\model;
|
||||
namespace app\admin\model\Article;
|
||||
|
||||
use think\Model;
|
||||
|
||||
@ -322,7 +322,7 @@
|
||||
// 初始化分类列表
|
||||
that.initCategoryList = function () {
|
||||
$.ajax({
|
||||
url: '/admin/articles/articlecate',
|
||||
url: '/admin/article/articlecate',
|
||||
type: 'POST',
|
||||
success: function (res) {
|
||||
if (res.code === 0) {
|
||||
@ -387,7 +387,7 @@
|
||||
|
||||
// 加载分类信息
|
||||
that.loadCategoryInfo = function (id) {
|
||||
$.get('/admin/articles/cateedit?id=' + id, function (res) {
|
||||
$.get('/admin/article/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/articles/articlecate',
|
||||
url: '/admin/article/articlecate',
|
||||
type: 'POST',
|
||||
async: false,
|
||||
success: function (res) {
|
||||
@ -472,7 +472,7 @@
|
||||
|
||||
// 监听表单提交
|
||||
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) {
|
||||
if (res.code === 0) {
|
||||
layer.msg(res.msg, { icon: 1 });
|
||||
@ -490,7 +490,7 @@
|
||||
if (!id) return;
|
||||
|
||||
layer.confirm('确定要删除该分类吗?', function (index) {
|
||||
$.post('/admin/articles/catedel', { id: id }, function (res) {
|
||||
$.post('/admin/article/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/articles/articlelist',
|
||||
url: '/admin/article/articlelist',
|
||||
method: 'post',
|
||||
cols: [[
|
||||
{ field: 'id', title: 'ID', align: 'center', width: 80 },
|
||||
@ -174,18 +174,18 @@
|
||||
}
|
||||
|
||||
function add() {
|
||||
window.location.href = '/admin/articles/add';
|
||||
window.location.href = '/admin/article/add';
|
||||
}
|
||||
|
||||
function edit(id) {
|
||||
window.location.href = '/admin/articles/edit?id=' + id;
|
||||
window.location.href = '/admin/article/edit?id=' + id;
|
||||
}
|
||||
|
||||
function del(id) {
|
||||
layer.confirm('确定要删除该文章吗?', {
|
||||
btn: ['确定', '取消']
|
||||
}, function () {
|
||||
$.post('/admin/articles/delete', { id: id }, function (res) {
|
||||
$.post('/admin/article/delete', { id: id }, function (res) {
|
||||
if (res.code == 0) {
|
||||
layer.msg(res.msg, { icon: 1 });
|
||||
setTimeout(function () {
|
||||
@ -3,12 +3,14 @@
|
||||
* 文章控制器
|
||||
*/
|
||||
namespace app\index\controller;
|
||||
use app\index\controller\Base;
|
||||
use app\index\controller\BaseController;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
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()
|
||||
@ -27,8 +29,7 @@ class Article extends Base
|
||||
}
|
||||
|
||||
// 获取文章列表
|
||||
$articles = Db::table('yz_article')
|
||||
->where($where)
|
||||
$articles = Articles::where($where)
|
||||
->order('id DESC')
|
||||
->paginate([
|
||||
'list_rows' => 10,
|
||||
@ -38,16 +39,14 @@ class Article extends Base
|
||||
// 获取分类信息
|
||||
$category = null;
|
||||
if ($cateId > 0) {
|
||||
$category = Db::table('yz_article_category')
|
||||
->where('id', $cateId)
|
||||
$category = ArticlesCategory::where('id', $cateId)
|
||||
->where('delete_time', null)
|
||||
->where('status', 3)
|
||||
->find();
|
||||
}
|
||||
|
||||
// 获取所有分类
|
||||
$categories = Db::table('yz_article_category')
|
||||
->where('delete_time', null)
|
||||
$categories = ArticlesCategory::where('delete_time', null)
|
||||
->where('status', 3)
|
||||
->select()
|
||||
->toArray();
|
||||
@ -66,36 +65,32 @@ class Article extends Base
|
||||
public function detail()
|
||||
{
|
||||
$id = Request::param('id/d', 0);
|
||||
$article = Db::table('yz_article')->where('id', $id)->find();
|
||||
$article = Articles::where('id', $id)->find();
|
||||
|
||||
if (!$article) {
|
||||
return json(['code' => 0, 'msg' => '文章不存在或已被删除']);
|
||||
}
|
||||
|
||||
// 获取分类名称
|
||||
$cateName = Db::table('yz_article_category')
|
||||
->where('id', $article['cate'])
|
||||
$cateName = ArticlesCategory::where('id', $article['cate'])
|
||||
->value('name');
|
||||
|
||||
// 获取上一篇和下一篇文章
|
||||
$prevArticle = Db::table('yz_article')
|
||||
->where('id', '<', $id)
|
||||
$prevArticle = Articles::where('id', '<', $id)
|
||||
->where('delete_time', null)
|
||||
->where('status', '<>', 3)
|
||||
->order('id DESC')
|
||||
->find();
|
||||
|
||||
$nextArticle = Db::table('yz_article')
|
||||
->where('id', '>', $id)
|
||||
$nextArticle = Articles::where('id', '>', $id)
|
||||
->where('delete_time', null)
|
||||
->where('status', '<>', 3)
|
||||
->order('id ASC')
|
||||
->find();
|
||||
|
||||
// 获取相关文章(同分类的其他文章)
|
||||
$relatedArticles = Db::table('yz_article')
|
||||
->alias('a')
|
||||
->join('yz_article_category c', 'a.cate = c.id')
|
||||
$relatedArticles = Articles::alias('a')
|
||||
->join('articles_category c', 'a.cate = c.id')
|
||||
->where('a.cate', $article['cate'])
|
||||
->where('a.id', '<>', $id)
|
||||
->where('a.delete_time', null)
|
||||
@ -148,8 +143,7 @@ class Article extends Base
|
||||
$id = Request::param('id/d', 0);
|
||||
|
||||
// 更新点赞数
|
||||
$result = Db::table('yz_article')
|
||||
->where('id', $id)
|
||||
$result = Articles::where('id', $id)
|
||||
->where('delete_time', null)
|
||||
->inc('likes', 1)
|
||||
->update();
|
||||
@ -177,8 +171,7 @@ class Article extends Base
|
||||
}
|
||||
|
||||
// 检查文章是否存在
|
||||
$article = Db::table('yz_article')
|
||||
->where('id', $articleId)
|
||||
$article = Articles::where('id', $articleId)
|
||||
->where('delete_time', null)
|
||||
->where('status', 3)
|
||||
->find();
|
||||
@ -228,8 +221,7 @@ class Article extends Base
|
||||
|
||||
|
||||
// 获取总访问量
|
||||
$totalViews = Db::table('yz_article')
|
||||
->where('id', $id)
|
||||
$totalViews = Articles::where('id', $id)
|
||||
->value('views');
|
||||
|
||||
return json([
|
||||
@ -256,16 +248,16 @@ class Article extends Base
|
||||
|
||||
try {
|
||||
// 更新访问次数
|
||||
$article = Db::table('yz_article')->where('id', $id)->find();
|
||||
$article = Articles::where('id', $id)->find();
|
||||
if (!$article) {
|
||||
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]]);
|
||||
} catch (\Exception $e) {
|
||||
139
app/index/controller/BaseController.php
Normal file
139
app/index/controller/BaseController.php
Normal 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
|
||||
]);
|
||||
}
|
||||
}
|
||||
@ -3,19 +3,19 @@
|
||||
* 后台管理系统-首页
|
||||
*/
|
||||
namespace app\index\controller;
|
||||
use app\index\controller\Base;
|
||||
use app\index\controller\BaseController;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
use think\facade\Env;
|
||||
use think\facade\Config;
|
||||
use app\index\model\Banner;
|
||||
use app\index\model\ResourcesCategory;
|
||||
use app\index\model\ArticlesCategory;
|
||||
use app\index\model\Resources;
|
||||
use app\index\model\Articles;
|
||||
use app\index\model\Resources\ResourcesCategory;
|
||||
use app\index\model\Articles\ArticlesCategory;
|
||||
use app\index\model\Resources\Resources;
|
||||
use app\index\model\Articles\Articles;
|
||||
|
||||
|
||||
class Index extends Base
|
||||
class IndexController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 首页
|
||||
@ -3,15 +3,15 @@
|
||||
* 程序下载控制器
|
||||
*/
|
||||
namespace app\index\controller;
|
||||
use app\index\controller\Base;
|
||||
use app\index\controller\BaseController;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
use think\facade\Request;
|
||||
use app\index\model\Resources;
|
||||
use app\index\model\ResourcesCategory;
|
||||
use app\index\model\Resources\Resources;
|
||||
use app\index\model\Resources\ResourcesCategory;
|
||||
use app\index\model\Attachments;
|
||||
|
||||
class Program extends Base
|
||||
class ProgramController extends BaseController
|
||||
{
|
||||
// 程序列表页
|
||||
public function list()
|
||||
8
app/index/model/Articles/Articles.php
Normal file
8
app/index/model/Articles/Articles.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace app\index\model\Articles;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class Articles extends Model
|
||||
{
|
||||
}
|
||||
8
app/index/model/Articles/ArticlesCategory.php
Normal file
8
app/index/model/Articles/ArticlesCategory.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace app\index\model\Articles;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class ArticlesCategory extends Model
|
||||
{
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace app\index\model;
|
||||
namespace app\index\model\Resources;
|
||||
|
||||
use think\Model;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace app\index\model;
|
||||
namespace app\index\model\Resources;
|
||||
|
||||
use think\Model;
|
||||
|
||||
@ -21,7 +21,7 @@ return [
|
||||
// 是否强制使用路由
|
||||
'url_route_must' => false,
|
||||
// 合并路由规则
|
||||
'route_rule_merge' => false,
|
||||
'route_rule_merge' => true,
|
||||
// 路由是否完全匹配
|
||||
'route_complete_match' => false,
|
||||
// 使用注解路由
|
||||
@ -68,7 +68,7 @@ return [
|
||||
// 空控制器名
|
||||
'empty_controller' => 'Error',
|
||||
// 是否使用控制器后缀
|
||||
'controller_suffix' => false,
|
||||
'controller_suffix' => true,
|
||||
// 访问控制器层名称
|
||||
'controller_layer' => 'controller',
|
||||
// 默认控制器名
|
||||
|
||||
27
config/site.php
Normal file
27
config/site.php
Normal 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/'
|
||||
];
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
@ -181,7 +181,7 @@
|
||||
// 初始化表格
|
||||
table.render({
|
||||
elem: '#articleTable',
|
||||
url: '/admin/articles/articlelist',
|
||||
url: '/admin/article/articlelist',
|
||||
method: 'post',
|
||||
cols: [[
|
||||
{ field: 'id', title: 'ID', align: 'center', width: 80 },
|
||||
@ -268,18 +268,18 @@
|
||||
}
|
||||
|
||||
function add() {
|
||||
window.location.href = '/admin/articles/add';
|
||||
window.location.href = '/admin/article/add';
|
||||
}
|
||||
|
||||
function edit(id) {
|
||||
window.location.href = '/admin/articles/edit?id=' + id;
|
||||
window.location.href = '/admin/article/edit?id=' + id;
|
||||
}
|
||||
|
||||
function del(id) {
|
||||
layer.confirm('确定要删除该文章吗?', {
|
||||
btn: ['确定', '取消']
|
||||
}, function () {
|
||||
$.post('/admin/articles/delete', { id: id }, function (res) {
|
||||
$.post('/admin/article/delete', { id: id }, function (res) {
|
||||
if (res.code == 0) {
|
||||
layer.msg(res.msg, { icon: 1 });
|
||||
setTimeout(function () {
|
||||
|
||||
@ -416,7 +416,7 @@
|
||||
// 初始化分类列表
|
||||
that.initCategoryList = function () {
|
||||
$.ajax({
|
||||
url: '/admin/articles/articlecate',
|
||||
url: '/admin/article/articlecate',
|
||||
type: 'POST',
|
||||
success: function (res) {
|
||||
if (res.code === 0) {
|
||||
@ -481,7 +481,7 @@
|
||||
|
||||
// 加载分类信息
|
||||
that.loadCategoryInfo = function (id) {
|
||||
$.get('/admin/articles/cateedit?id=' + id, function (res) {
|
||||
$.get('/admin/article/cateedit?id=' + id, function (res) {
|
||||
if (res.code === 0) {
|
||||
that.showCategoryForm(0, res.data);
|
||||
}
|
||||
@ -507,7 +507,7 @@
|
||||
$select.empty().append('<option value="0">顶级分类</option>');
|
||||
// 获取所有分类作为父级选项
|
||||
$.ajax({
|
||||
url: '/admin/articles/articlecate',
|
||||
url: '/admin/article/articlecate',
|
||||
type: 'POST',
|
||||
async: false,
|
||||
success: function (res) {
|
||||
@ -566,7 +566,7 @@
|
||||
|
||||
// 监听表单提交
|
||||
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) {
|
||||
if (res.code === 0) {
|
||||
layer.msg(res.msg, { icon: 1 });
|
||||
@ -584,7 +584,7 @@
|
||||
if (!id) return;
|
||||
|
||||
layer.confirm('确定要删除该分类吗?', function (index) {
|
||||
$.post('/admin/articles/catedel', { id: id }, function (res) {
|
||||
$.post('/admin/article/catedel', { id: id }, function (res) {
|
||||
if (res.code === 0) {
|
||||
layer.msg(res.msg, { icon: 1 });
|
||||
that.initCategoryList();
|
||||
|
||||
@ -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>
|
||||
<html>
|
||||
<head>
|
||||
|
||||
@ -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>
|
||||
<html>
|
||||
<head>
|
||||
|
||||
1119
runtime/index/temp/745a6917c29d4d1aec94c5bc5dbce0b2.php
Normal file
1119
runtime/index/temp/745a6917c29d4d1aec94c5bc5dbce0b2.php
Normal file
File diff suppressed because it is too large
Load Diff
@ -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>
|
||||
<html>
|
||||
|
||||
@ -799,7 +799,7 @@
|
||||
});
|
||||
|
||||
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">
|
||||
<img src="${article.image || ''}" alt="" class="cover">
|
||||
</div>
|
||||
@ -1019,7 +1019,7 @@
|
||||
</div>
|
||||
<div class="tongji">
|
||||
<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>
|
||||
</section>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user