105 lines
2.7 KiB
PHP
Executable File
105 lines
2.7 KiB
PHP
Executable File
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
|
// +----------------------------------------------------------------------
|
|
namespace app\controller\admin;
|
|
|
|
use app\controller\Admin;
|
|
use app\Model\Category as CategoryModel;
|
|
|
|
class Category extends Admin{
|
|
|
|
/**
|
|
* @title 栏目列表
|
|
*/
|
|
public function index(CategoryModel $category){
|
|
if($this->request->isAjax()){
|
|
$tree = $this->request->param('tree', 0);
|
|
$map = array();
|
|
|
|
$res = $category->where($map)->order('sort asc, id asc')->select();
|
|
|
|
$list = $res->toArray();
|
|
if($tree){
|
|
if (!empty($list)) {
|
|
$tree = new \com\Tree();
|
|
$list = $tree->toFormatTree($list);
|
|
}
|
|
}
|
|
$this->data['data'] = $list;
|
|
return $this->data;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @title 添加栏目
|
|
*/
|
|
public function add(CategoryModel $category){
|
|
if ($this->request->isPost()) {
|
|
$data = $this->request->post();
|
|
$result = $category->save($data);
|
|
if (false !== $result) {
|
|
return $this->success('成功添加', url('/admin/category/index'));
|
|
}else{
|
|
return $this->error($this->model->getError());
|
|
}
|
|
}else{
|
|
$info['appid'] = rand_string(10, 1); //八位数字appid
|
|
$info['appsecret'] = rand_string(32); //32位数字加字母秘钥
|
|
$this->data['data'] = array(
|
|
'info' => $info
|
|
);
|
|
|
|
return $this->data;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @title 编辑栏目
|
|
*/
|
|
public function edit(CategoryModel $category){
|
|
if ($this->request->isPost()) {
|
|
$data = $this->request->post();
|
|
if (!isset($data['id']) || !$data['id']) {
|
|
return $this->error('非法操作!');
|
|
}
|
|
|
|
$result = $category->exists(true)->save($data);
|
|
if (false !== $result) {
|
|
return $this->success('修改成功', url('/admin/category/index'));
|
|
}else{
|
|
return $this->error($this->model->getError());
|
|
}
|
|
}else{
|
|
$info = $category->where('id', $this->request->param('id'))->find();
|
|
$this->data['template'] = "add";
|
|
$this->data['data'] = array(
|
|
'info' => $info
|
|
);
|
|
return $this->data;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @title 删除栏目
|
|
*/
|
|
public function del(CategoryModel $category){
|
|
$ids = $this->request->param('ids', 0);
|
|
if(!$ids){
|
|
return $this->error('非法操作!');
|
|
}else{
|
|
$ids = \explode(",", $ids);
|
|
}
|
|
$result = $category->where('id', 'IN', $ids)->delete();
|
|
|
|
if(false !== $result){
|
|
return $this->success('删除成功!');
|
|
}else{
|
|
return $this->error('删除失败!');
|
|
}
|
|
}
|
|
} |