114 lines
2.9 KiB
PHP
Executable File
114 lines
2.9 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\Channel as ChannelModel;
|
|
|
|
class Channel extends Admin{
|
|
/**
|
|
* @title 频道列表
|
|
*/
|
|
public function index(ChannelModel $channel){
|
|
if($this->request->isAjax()){
|
|
$tree = $this->request->param('tree', 0);
|
|
$type = $this->request->param('type', 0);
|
|
$map = array();
|
|
|
|
if($type){
|
|
$map['type'] = $type;
|
|
}
|
|
|
|
$res = $channel->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;
|
|
}else{
|
|
$this->data['data'] = array(
|
|
'type' => $this->request->param('type', 0),
|
|
);
|
|
return $this->data;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @title 添加频道
|
|
*/
|
|
public function add(ChannelModel $channel){
|
|
if ($this->request->isPost()) {
|
|
$data = $this->request->post();
|
|
$result = $channel->save($data);
|
|
if (false !== $result) {
|
|
return $this->success('成功添加', url('/admin/channel/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(ChannelModel $channel){
|
|
if ($this->request->isPost()) {
|
|
$data = $this->request->post();
|
|
if (!isset($data['id']) || !$data['id']) {
|
|
return $this->error('非法操作!');
|
|
}
|
|
|
|
$result = $channel->exists(true)->save($data);
|
|
if (false !== $result) {
|
|
return $this->success('修改成功', url('/admin/channel/index'));
|
|
}else{
|
|
return $this->error($this->model->getError());
|
|
}
|
|
}else{
|
|
$info = $channel->where('id', $this->request->param('id'))->find();
|
|
$this->data['template'] = "add";
|
|
$this->data['data'] = array(
|
|
'info' => $info
|
|
);
|
|
return $this->data;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @title 删除频道
|
|
*/
|
|
public function del(ChannelModel $channel){
|
|
$ids = $this->request->param('ids', 0);
|
|
if(!$ids){
|
|
return $this->error('非法操作!');
|
|
}else{
|
|
$ids = \explode(",", $ids);
|
|
}
|
|
$result = $channel->where('id', 'IN', $ids)->delete();
|
|
|
|
if(false !== $result){
|
|
return $this->success('删除成功!');
|
|
}else{
|
|
return $this->error('删除失败!');
|
|
}
|
|
}
|
|
} |