2023-03-16 22:40:15 +08:00
|
|
|
|
<?php
|
2023-05-05 11:58:42 +08:00
|
|
|
|
/*
|
2023-03-16 22:42:05 +08:00
|
|
|
|
* @Program: TaoLer 2023/3/14
|
|
|
|
|
* @FilePath: app\admin\controller\content\Cate.php
|
2023-05-05 11:58:42 +08:00
|
|
|
|
* @Description: Cate 分类菜单
|
2023-03-16 22:42:05 +08:00
|
|
|
|
* @LastEditTime: 2023-03-14 15:40:53
|
|
|
|
|
* @Author: Taoker <317927823@qq.com>
|
|
|
|
|
* @Copyright (c) 2020~2023 https://www.aieok.com All rights reserved.
|
|
|
|
|
*/
|
2023-03-16 22:40:15 +08:00
|
|
|
|
|
|
|
|
|
namespace app\admin\controller\content;
|
|
|
|
|
|
|
|
|
|
use app\common\controller\AdminController;
|
2023-05-05 11:58:42 +08:00
|
|
|
|
use think\App;
|
2023-03-16 22:40:15 +08:00
|
|
|
|
use think\facade\View;
|
|
|
|
|
use think\facade\Request;
|
|
|
|
|
use think\facade\Db;
|
|
|
|
|
use taoler\com\Files;
|
|
|
|
|
use app\common\lib\Msgres;
|
2023-03-16 22:42:05 +08:00
|
|
|
|
use app\common\model\Cate as CateModel;
|
|
|
|
|
|
|
|
|
|
|
2023-03-16 22:40:15 +08:00
|
|
|
|
|
|
|
|
|
class Cate extends AdminController
|
|
|
|
|
{
|
2023-05-05 11:58:42 +08:00
|
|
|
|
protected $model;
|
|
|
|
|
|
|
|
|
|
public function __construct(App $app)
|
|
|
|
|
{
|
|
|
|
|
parent::__construct($app);
|
|
|
|
|
$this->model = new CateModel();
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-16 22:40:15 +08:00
|
|
|
|
/**
|
|
|
|
|
* 浏览
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
|
|
|
|
return View::fetch();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//帖子分类
|
|
|
|
|
public function list()
|
|
|
|
|
{
|
2023-05-05 11:58:42 +08:00
|
|
|
|
return $this->model->getList();
|
2023-03-16 22:40:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-05 11:58:42 +08:00
|
|
|
|
//添加和编辑帖子分类 废弃
|
|
|
|
|
public function addEdit()
|
2023-03-16 22:40:15 +08:00
|
|
|
|
{
|
|
|
|
|
$addOrEdit = !is_null(input('id'));//true是编辑false新增
|
2023-05-05 11:58:42 +08:00
|
|
|
|
$msg = $addOrEdit ? lang('edit') : lang('add');
|
2023-03-16 22:40:15 +08:00
|
|
|
|
if(Request::isAjax()) {
|
|
|
|
|
$data = Request::param();
|
2023-05-05 11:58:42 +08:00
|
|
|
|
if(isset($data['id']) && $data['pid'] == $data['id']) return json(['code'=>-1,'msg'=> $msg.'不能作为自己的子类']);
|
2023-03-16 22:40:15 +08:00
|
|
|
|
$list = Db::name('cate')->cache('catename')->save($data);
|
|
|
|
|
if($list){
|
2023-05-05 11:58:42 +08:00
|
|
|
|
return json(['code'=>0,'msg'=> $msg.'成功']);
|
2023-03-16 22:40:15 +08:00
|
|
|
|
}
|
2023-05-05 11:58:42 +08:00
|
|
|
|
return json(['code'=>-1,'msg'=> $msg.'失败']);
|
2023-03-16 22:40:15 +08:00
|
|
|
|
}
|
|
|
|
|
//详情模板
|
2023-05-05 11:58:42 +08:00
|
|
|
|
$template = $this->getIndexTpl();
|
2023-03-16 22:40:15 +08:00
|
|
|
|
// 如果是新增,pid=0,detpl默认第一个子模块,如果是编辑,查询出cate
|
2023-05-05 11:58:42 +08:00
|
|
|
|
$cate = $addOrEdit ? $this->model->getCateInfoById((int) input('id')) : '';
|
|
|
|
|
$view = $addOrEdit ? 'edit' : 'add';
|
|
|
|
|
|
|
|
|
|
View::assign([
|
|
|
|
|
'template' => $template,
|
|
|
|
|
'cate' => $cate
|
|
|
|
|
]);
|
|
|
|
|
return View::fetch($view);
|
2023-03-16 22:40:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//删除帖子分类
|
|
|
|
|
public function delete()
|
|
|
|
|
{
|
2023-05-05 11:58:42 +08:00
|
|
|
|
$result = $this->model->del(input('id'));
|
|
|
|
|
if($result == 1){
|
|
|
|
|
return json(['code'=>0,'msg'=>'删除分类成功']);
|
|
|
|
|
}
|
|
|
|
|
return json(['code'=>-1,'msg' => $result]);
|
2023-03-16 22:40:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-05 11:58:42 +08:00
|
|
|
|
// 动态审核
|
|
|
|
|
public function check()
|
2023-03-16 22:40:15 +08:00
|
|
|
|
{
|
2023-05-05 11:58:42 +08:00
|
|
|
|
$param = Request::only(['id','name','value']);
|
|
|
|
|
$data = ['id'=>$param['id'],$param['name']=>$param['value']];
|
|
|
|
|
//获取状态
|
|
|
|
|
$res = Db::name('cate')->save($data);
|
|
|
|
|
if($res){
|
|
|
|
|
return json(['code'=>0,'msg'=>'设置成功','icon'=>6]);
|
|
|
|
|
}
|
|
|
|
|
return json(['code'=>-1,'msg'=>'设置失败']);
|
2023-03-16 22:40:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-05 11:58:42 +08:00
|
|
|
|
/**
|
|
|
|
|
* index/view/article下模板文件
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
protected function getIndexTpl() :array
|
|
|
|
|
{
|
|
|
|
|
$sys = $this->getSystem();
|
|
|
|
|
return Files::getDirName('../view/'.$sys['template'].'/index/article/');
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-16 22:40:15 +08:00
|
|
|
|
|
|
|
|
|
}
|