2023-01-31 16:39:11 +08:00

88 lines
2.4 KiB
PHP

<?php
declare (strict_types = 1);
namespace app\admin\controller\nk;
use app\admin\BaseController;
use think\facade\Db;
use think\facade\View;
class Category extends BaseController
{
public function __construct()
{
$this->adminInfo = get_login_admin();
// 类型
$map[] = ['pid','=','0'];
$map[] = ['status','=','normal'];
$this->type = Db::table('fa_category')->where($map)->field('id,type,name')->select();
}
public function index()
{
if (request()->isAjax()) {
$list = Db::table('fa_category')->order('weigh asc,id asc')->select()->toArray();
foreach ($list as $k =>$v){
if($v['status'] == 'normal'){
$list[$k]['status'] = '正常';
}else{
$list[$k]['status'] = '禁用';
}
}
return to_assign(0, '', $list);
} else {
return view();
}
}
//添加
public function add()
{
$param = get_params();
if (request()->isAjax()) {
return to_assign();
} else {
$id = isset($param['id']) ? $param['id'] : 0;
$pid = isset($param['pid']) ? $param['pid'] : 0;
if($id>0){
$detail = Db::name('fa_category')->where('id',$id)->find();
View::assign('detail', $detail);
}
View::assign('id', $id);
View::assign('pid', $pid);
View::assign('type', $this->type);
return view();
}
}
//删除
public function delete()
{
$id = get_params("id");
$count = Db::name('AdminRule')->where(["pid" => $id])->count();
if ($count > 0) {
return to_assign(1, "该节点下还有子节点,无法删除");
}
if (Db::name('AdminRule')->delete($id) !== false) {
clear_cache('adminRules');
add_log('delete', $id, []);
return to_assign(0, "删除节点成功");
} else {
return to_assign(1, "删除失败");
}
}
public function getbytype(){
$type = get_params("type");
$where['type'] = $type;
$where['status'] = 'normal';
$list = Db::table('fa_category')->where($where)->order('weigh asc,id asc')->select();
return to_assign(0, '', $list);
}
}