259 lines
6.5 KiB
PHP
259 lines
6.5 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | 小说系统 [ WE CAN DO IT JUST THINK IT ]
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\admin\controller;
|
||
use app\common\controller\Admin;
|
||
|
||
class Message extends Admin {
|
||
|
||
public function _initialize() {
|
||
parent::_initialize();
|
||
}
|
||
|
||
/**
|
||
* 内容列表
|
||
* @return [html] [页面内容]
|
||
* @author netlife <40150501@qq.com>
|
||
*/
|
||
public function index() {
|
||
$keyword = input('keyword');
|
||
$map['content'] = array("LIKE", "%$keyword%");
|
||
$list = db('MessageCenter')->where($map)->order('id DESC')->paginate(20);
|
||
$this->assign('keyword', $keyword);
|
||
$this->assign('list', $list);
|
||
$this->assign('page', $list->render());
|
||
$this->setMeta("消息列表");
|
||
return $this->fetch();
|
||
}
|
||
|
||
/**
|
||
* 内容添加
|
||
* @author netlife <40150501@qq.com>
|
||
*/
|
||
public function add() {
|
||
if (IS_POST) {
|
||
|
||
$this->param['send_type'] =1;
|
||
$this->param['status'] =1;
|
||
$this->param['created_at'] =time();
|
||
$this->param['updated_at'] =time();
|
||
$result = db('MessageCenter')->insert($this->param);
|
||
if ($result) {
|
||
|
||
return $this->success("添加成功!", url('admin/message/index'));
|
||
} else {
|
||
return $this->error($this->model->getError(), url('admin/message/add'));
|
||
}
|
||
} else {
|
||
$template = 'message/edit';
|
||
$this->setMeta("添加消息");
|
||
return $this->fetch($template);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 内容修改
|
||
* @author netlife <40150501@qq.com>
|
||
*/
|
||
public function edit($id) {
|
||
if (IS_POST) {
|
||
$result = db('MessageCenter')->update($this->param, array('id'=> $id));
|
||
if ($result !== false) {
|
||
return $this->success("更新成功!", url('admin/message/index'));
|
||
} else {
|
||
return $this->error($this->model->getError(), url('admin/message/edit', array('id' => $id)));
|
||
}
|
||
} else {
|
||
if (!$id) {
|
||
return $this->error("非法操作!");
|
||
}
|
||
$info = db('MessageCenter')->find($id);
|
||
|
||
$data = array(
|
||
'info' => $info
|
||
);
|
||
$template = 'message/edit';
|
||
$this->assign($data);
|
||
$this->setMeta("编辑");
|
||
return $this->fetch($template);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* 内容删除
|
||
* @author netlife <40150501@qq.com>
|
||
*/
|
||
public function del() {
|
||
$id = $this->getArrayParam('id');
|
||
if (empty($id)) {
|
||
return $this->error("非法操作!");
|
||
}
|
||
|
||
$map['id'] = array('IN', $id);
|
||
$result = db('MessageCenter')->where($map)->delete();
|
||
|
||
if (false !== $result) {
|
||
//记录行为
|
||
action_log('delete_content', 'content', $result, session('user_auth.uid'));
|
||
return $this->success("删除成功!");
|
||
} else {
|
||
return $this->error("删除失败!");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 设置状态
|
||
* @author netlife <40150501@qq.com>
|
||
*/
|
||
public function status($id, $status) {
|
||
$map['id'] = $id;
|
||
$result = db('MessageCenter')->where($map)->setField('status', $status);
|
||
if (false !== $result) {
|
||
return $this->success("操作成功!");
|
||
} else {
|
||
return $this->error("操作失败!!");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 设置置顶
|
||
* @author netlife <40150501@qq.com>
|
||
*/
|
||
public function settop($id, $is_top) {
|
||
$map['id'] = $id;
|
||
$result = $this->model->where($map)->setField('is_top', $is_top);
|
||
if (false !== $result) {
|
||
return $this->success("操作成功!");
|
||
} else {
|
||
return $this->error("操作失败!!");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取字段信息
|
||
* @return array 字段数组
|
||
* @author netlife <40150501@qq.com>
|
||
*/
|
||
protected function getField() {
|
||
$field_group = parse_config_attr($this->modelInfo['attribute_group']);
|
||
|
||
$map['model_id'] = $this->modelInfo['id'];
|
||
if ($this->request->action() == 'add') {
|
||
$map['is_show'] = array('in', array('1', '2'));
|
||
} elseif ($this->request->action() == 'edit') {
|
||
$map['is_show'] = array('in', array('1', '3'));
|
||
}
|
||
|
||
//获得数组的第一条数组
|
||
$rows = model('Attribute')->getFieldlist($map, 'id');
|
||
if (!empty($rows)) {
|
||
foreach ($rows as $key => $value) {
|
||
$list[$value['group_id']][] = $value;
|
||
}
|
||
foreach ($field_group as $key => $value) {
|
||
$fields[$value] = isset($list[$key]) ? $list[$key] : array();
|
||
}
|
||
}else{
|
||
$fields = array();
|
||
}
|
||
return $fields;
|
||
}
|
||
|
||
/**
|
||
* 创建搜索
|
||
* @return [array] [查询条件]
|
||
*/
|
||
protected function buildMap($search_key) {
|
||
$map = array();
|
||
$data = $this->request->param();
|
||
foreach ($data as $key => $value) {
|
||
if ($value) {
|
||
if ($key == 'keyword') {
|
||
$map[$search_key] = array("LIKE", "%$value%");
|
||
} elseif ($key == 'category') {
|
||
$map['category_id'] = $value;
|
||
} elseif ($key == 'create_time') {
|
||
$map['create_time'] = array('BETWEEN', array(strtotime($value[0]), strtotime($value[1])));
|
||
} else {
|
||
$map[$key] = $value;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (isset($map['page'])) {
|
||
unset($map['page']);
|
||
}
|
||
if (isset($map['model_id'])) {
|
||
unset($map['model_id']);
|
||
}
|
||
$this->assign($data);
|
||
return $map;
|
||
}
|
||
|
||
/**
|
||
* 检测需要动态判断的文档类目有关的权限
|
||
*
|
||
* @return boolean|null
|
||
* 返回true则表示当前访问有权限
|
||
* 返回false则表示当前访问无权限
|
||
* 返回null,则会进入checkRule根据节点授权判断权限
|
||
*
|
||
* @author 朱亚杰 <xcoolcc@gmail.com>
|
||
*/
|
||
protected function checkDynamic() {
|
||
$model_id = $this->request->param('model_id');
|
||
if (IS_ROOT) {
|
||
return true; //管理员允许访问任何页面
|
||
}
|
||
$models = model('AuthGroup')->getAuthModels(session('user_auth.uid'));
|
||
if (!$model_id) {
|
||
return false;
|
||
} elseif (in_array($model_id, $models)) {
|
||
//返回null继续判断操作权限
|
||
return null;
|
||
} else {
|
||
return false; //无权限
|
||
}
|
||
return false;
|
||
}
|
||
|
||
public function faceback() {
|
||
$keyword = input('keyword');
|
||
$map['content'] = array("LIKE", "%$keyword%");
|
||
$list = db('FecebackInfo')->where($map)->order('id DESC')->paginate(20);
|
||
$this->assign('keyword', $keyword);
|
||
$this->assign('list', $list);
|
||
$this->assign('page', $list->render());
|
||
$this->setMeta("意见反馈列表");
|
||
return $this->fetch();
|
||
}
|
||
|
||
public function editfaceback($name = null, $value = null, $pk = null) {
|
||
if ($name && ($value != null || $value != '') && $pk) {
|
||
db('FecebackInfo')->where(array('id' => $pk))->setField($name, $value);
|
||
}
|
||
}
|
||
|
||
|
||
public function feedbackdel() {
|
||
$id = $this->getArrayParam('id');
|
||
if (empty($id)) {
|
||
return $this->error("非法操作!");
|
||
}
|
||
|
||
$map['id'] = array('IN', $id);
|
||
$result = db('FecebackInfo')->where($map)->delete();
|
||
|
||
if (false !== $result) {
|
||
//记录行为
|
||
action_log('delete_content', 'content', $result, session('user_auth.uid'));
|
||
return $this->success("删除成功!");
|
||
} else {
|
||
return $this->error("删除失败!");
|
||
}
|
||
}
|
||
} |