后台内容模块功能完善
This commit is contained in:
@@ -19,11 +19,13 @@ use app\model\Attribute;
|
||||
class Content extends Base {
|
||||
|
||||
public $modelInfo = [];
|
||||
public $model = null;
|
||||
|
||||
public function initialize() {
|
||||
parent::initialize();
|
||||
$this->getContentMenu();
|
||||
$this->modelInfo = Model::where('name', $this->request->param('name'))->find()->append(['grid_list'])->toArray();
|
||||
$this->modelInfo = Model::where('name', $this->request->param('name'))->find()->append(['grid_list', 'attr_group'])->toArray();
|
||||
$this->model = Db::name($this->modelInfo['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,12 +35,12 @@ class Content extends Base {
|
||||
*/
|
||||
public function index() {
|
||||
if ($this->modelInfo['list_grid'] == '') {
|
||||
return $this->error("列表定义不正确!", url('admin/model/edit', array('id' => $this->modelInfo['id'])));
|
||||
return $this->error("列表定义不正确!", url('/admin/model/edit', array('id' => $this->modelInfo['id'])));
|
||||
}
|
||||
$order = "id desc";
|
||||
$map = [];
|
||||
|
||||
$list = Db::name($this->modelInfo['name'])->where($map)->order($order)->paginate($this->modelInfo['list_row'], false, array(
|
||||
$list = $this->model->where($map)->order($order)->paginate($this->modelInfo['list_row'], false, array(
|
||||
'query' => $this->request->param(),
|
||||
));
|
||||
|
||||
@@ -63,11 +65,11 @@ class Content extends Base {
|
||||
*/
|
||||
public function add() {
|
||||
if ($this->request->isPost()) {
|
||||
$result = $this->model->save($this->request->param());
|
||||
$result = $this->model->save($this->request->post());
|
||||
if ($result) {
|
||||
return $this->success("添加成功!", url('admin/content/index', array('model_id' => $this->modelInfo['id'])));
|
||||
return $this->success("添加成功!", url('/admin/'.$this->modelInfo['name'].'/index'));
|
||||
} else {
|
||||
return $this->error($this->model->getError(), url('admin/content/add', array('model_id' => $this->modelInfo['id'])));
|
||||
return $this->error('添加失败!');
|
||||
}
|
||||
} else {
|
||||
$info = [
|
||||
@@ -76,13 +78,13 @@ class Content extends Base {
|
||||
];
|
||||
$this->data = [
|
||||
'info' => $info,
|
||||
'fieldGroup' => $this->getField($this->modelInfo),
|
||||
'fieldGroup' => Attribute::getField($this->modelInfo),
|
||||
];
|
||||
|
||||
if ($this->modelInfo['template_add']) {
|
||||
$template = 'content/' . $this->modelInfo['template_add'];
|
||||
$template = 'admin/content/' . $this->modelInfo['template_add'];
|
||||
} else {
|
||||
$template = 'public/edit';
|
||||
$template = 'admin/public/edit';
|
||||
}
|
||||
return $this->fetch($template);
|
||||
}
|
||||
@@ -94,13 +96,11 @@ class Content extends Base {
|
||||
*/
|
||||
public function edit($id) {
|
||||
if ($this->request->isPost()) {
|
||||
$result = $this->model->save($this->request->param(), array('id' => $id));
|
||||
$result = $this->model->save($this->request->post());
|
||||
if ($result !== false) {
|
||||
//记录行为
|
||||
action_log('update_content', 'content', $result, session('auth_user.uid'));
|
||||
return $this->success("更新成功!", url('admin/content/index', array('model_id' => $this->modelInfo['id'])));
|
||||
return $this->success("更新成功!", url('/admin/'.$this->modelInfo['name'].'/index'));
|
||||
} else {
|
||||
return $this->error($this->model->getError(), url('admin/content/edit', array('model_id' => $this->modelInfo['id'], 'id' => $id)));
|
||||
return $this->error('修改失败!');
|
||||
}
|
||||
} else {
|
||||
if (!$id) {
|
||||
@@ -108,20 +108,18 @@ class Content extends Base {
|
||||
}
|
||||
$info = $this->model->find($id);
|
||||
if (!$info) {
|
||||
return $this->error($this->model->getError());
|
||||
return $this->error('无此数据!');
|
||||
}
|
||||
$info['model_id'] = $this->modelInfo['id'];
|
||||
$data = array(
|
||||
$this->data = array(
|
||||
'info' => $info,
|
||||
'fieldGroup' => $this->getField($this->modelInfo),
|
||||
'fieldGroup' => Attribute::getField($this->modelInfo, 'edit'),
|
||||
);
|
||||
if ($this->modelInfo['template_edit']) {
|
||||
$template = 'content/' . $this->modelInfo['template_edit'];
|
||||
$template = 'admin/content/' . $this->modelInfo['template_edit'];
|
||||
} else {
|
||||
$template = 'public/edit';
|
||||
$template = 'admin/public/edit';
|
||||
}
|
||||
$this->assign($data);
|
||||
$this->setMeta("编辑" . $this->modelInfo['title']);
|
||||
return $this->fetch($template);
|
||||
}
|
||||
}
|
||||
@@ -131,18 +129,21 @@ class Content extends Base {
|
||||
* @author molong <ycgpp@126.com>
|
||||
*/
|
||||
public function del() {
|
||||
$param = $this->request->param();
|
||||
$id = $param['id'];
|
||||
if (empty($id)) {
|
||||
return $this->error("非法操作!");
|
||||
$id = $this->request->param('id', '');
|
||||
|
||||
$map = [];
|
||||
if (!$id) {
|
||||
return $this->error('请选择要操作的数据!');
|
||||
}
|
||||
if (is_array($id)) {
|
||||
$map[] = ['id', 'IN', $id];
|
||||
}else{
|
||||
$map[] = ['id', '=', $id];
|
||||
}
|
||||
|
||||
$map['id'] = array('IN', $id);
|
||||
$result = $this->model->where($map)->delete();
|
||||
|
||||
if (false !== $result) {
|
||||
//记录行为
|
||||
action_log('delete_content', 'content', $result, session('auth_user.uid'));
|
||||
return $this->success("删除成功!");
|
||||
} else {
|
||||
return $this->error("删除失败!");
|
||||
@@ -153,9 +154,14 @@ class Content extends Base {
|
||||
* @title 设置状态
|
||||
* @author molong <ycgpp@126.com>
|
||||
*/
|
||||
public function status($id, $status) {
|
||||
$map['id'] = $id;
|
||||
$result = $this->model->where($map)->setField('status', $status);
|
||||
public function status() {
|
||||
$id = $this->request->param('id', '');
|
||||
$status = $this->request->param('status', 1);
|
||||
if (!$id) {
|
||||
return $this->error('请选择要操作的数据!');
|
||||
}
|
||||
|
||||
$result = $this->model->where('id', $id)->update(['status' => $status]);
|
||||
if (false !== $result) {
|
||||
return $this->success("操作成功!");
|
||||
} else {
|
||||
@@ -167,9 +173,14 @@ class Content extends Base {
|
||||
* @title 设置置顶
|
||||
* @author molong <ycgpp@126.com>
|
||||
*/
|
||||
public function settop($id, $is_top) {
|
||||
$map['id'] = $id;
|
||||
$result = $this->model->where($map)->setField('is_top', $is_top);
|
||||
public function settop() {
|
||||
$id = $this->request->param('id', '');
|
||||
$is_top = $this->request->param('is_top', 1);
|
||||
if (!$id) {
|
||||
return $this->error('请选择要操作的数据!');
|
||||
}
|
||||
|
||||
$result = $this->model->where('id', $id)->update(['is_top' => $is_top]);
|
||||
if (false !== $result) {
|
||||
return $this->success("操作成功!");
|
||||
} else {
|
||||
@@ -177,66 +188,6 @@ class Content extends Base {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 获取字段信息
|
||||
* @return array 字段数组
|
||||
* @author molong <ycgpp@126.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 = 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 创建搜索
|
||||
* @return [array] [查询条件]
|
||||
*/
|
||||
protected function buildMap() {
|
||||
$map = array();
|
||||
$data = $this->request->param();
|
||||
foreach ($data as $key => $value) {
|
||||
if ($value) {
|
||||
if ($key == 'keyword') {
|
||||
$map['title'] = 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测需要动态判断的文档类目有关的权限
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user