后台内容模块功能完善
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
namespace app\controller\admin;
|
||||
|
||||
use app\model\AdPlace;
|
||||
use app\model\Ad as AdModel;
|
||||
|
||||
/**
|
||||
* @title 广告管理
|
||||
@@ -36,26 +37,19 @@ class Ad extends Base {
|
||||
* @title 广告位添加
|
||||
*/
|
||||
public function add() {
|
||||
$place = model('AdPlace');
|
||||
if ($this->request->isPost()) {
|
||||
$result = $place->change();
|
||||
if (!empty($_POST['name'])) {
|
||||
$result = $place->change();
|
||||
if ($result) {
|
||||
return $this->success("添加成功!");
|
||||
} else {
|
||||
return $this->error($place->getError());
|
||||
}
|
||||
$data = $this->request->post();
|
||||
$result = AdPlace::create($data);
|
||||
if (false !== $result) {
|
||||
return $this->success("添加成功!");
|
||||
} else {
|
||||
return $this->error("标识不能为空!");
|
||||
return $this->error('添加失败!');
|
||||
}
|
||||
} else {
|
||||
$data = array(
|
||||
'keyList' => $place->keyList,
|
||||
$this->data = array(
|
||||
'keyList' => AdPlace::$keyList,
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta("添加广告位");
|
||||
return $this->fetch('public/edit');
|
||||
return $this->fetch('admin/public/edit');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,26 +57,24 @@ class Ad extends Base {
|
||||
* @title 广告位编辑
|
||||
*/
|
||||
public function edit($id = null) {
|
||||
$place = model('AdPlace');
|
||||
if ($this->request->isPost()) {
|
||||
$result = $place->change();
|
||||
$data = $this->request->post();
|
||||
$result = AdPlace::update($data, ['id' => $data['id']]);
|
||||
if ($result) {
|
||||
return $this->success("修改成功!", url('admin/ad/index'));
|
||||
return $this->success("修改成功!", url('/admin/ad/index'));
|
||||
} else {
|
||||
return $this->error($this->adplace->getError());
|
||||
return $this->error('修改失败!');
|
||||
}
|
||||
} else {
|
||||
$info = db('AdPlace')->where(array('id' => $id))->find();
|
||||
$info = AdPlace::find($id);
|
||||
if (!$info) {
|
||||
return $this->error("非法操作!");
|
||||
}
|
||||
$data = array(
|
||||
$this->data = array(
|
||||
'info' => $info,
|
||||
'keyList' => $place->keyList,
|
||||
'keyList' => AdPlace::$keyList,
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta("编辑广告位");
|
||||
return $this->fetch('public/edit');
|
||||
return $this->fetch('admin/public/edit');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,19 +100,15 @@ class Ad extends Base {
|
||||
* @title 广告列表
|
||||
*/
|
||||
public function lists($id = null) {
|
||||
$map['place_id'] = $id;
|
||||
$map[] = ['place_id', '=', $id];
|
||||
$order = "id desc";
|
||||
|
||||
$list = db('Ad')->where($map)->order($order)->paginate(10, false, array(
|
||||
'query' => $this->request->param(),
|
||||
));
|
||||
$data = array(
|
||||
$list = AdModel::where($map)->order($order)->paginate($this->request->pageConfig);
|
||||
$this->data = array(
|
||||
'id' => $id,
|
||||
'list' => $list,
|
||||
'page' => $list->render(),
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta("广告管理");
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
@@ -128,23 +116,22 @@ class Ad extends Base {
|
||||
* @title 添加广告
|
||||
*/
|
||||
public function addad($id) {
|
||||
$ad = model('ad');
|
||||
if ($this->request->isPost()) {
|
||||
$result = $ad->change();
|
||||
$data = $this->request->post();
|
||||
|
||||
$result = AdModel::create($data);
|
||||
if ($result) {
|
||||
return $this->success("添加成功!", url('admin/ad/lists', array('id' => $this->request->param('place_id'))));
|
||||
return $this->success("添加成功!", url('/admin/ad/lists', ['id' => $data['place_id']]));
|
||||
} else {
|
||||
return $this->error($ad->getError());
|
||||
return $this->error('添加失败!');
|
||||
}
|
||||
} else {
|
||||
$info['place_id'] = $id;
|
||||
$data = array(
|
||||
$this->data = array(
|
||||
'info' => $info,
|
||||
'keyList' => $ad->keyList,
|
||||
'keyList' => AdModel::$keyList,
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta("添加广告位");
|
||||
return $this->fetch('public/edit');
|
||||
return $this->fetch('admin/public/edit');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,26 +139,25 @@ class Ad extends Base {
|
||||
* @title 编辑广告
|
||||
*/
|
||||
public function editad($id = null) {
|
||||
$ad = model('ad');
|
||||
if ($this->request->isPost()) {
|
||||
$result = $ad->change();
|
||||
$data = $this->request->post();
|
||||
|
||||
$result = AdModel::update($data, ['id' => $data['id']]);
|
||||
if ($result) {
|
||||
return $this->success("修改成功!", url('admin/ad/lists', array('id' => $this->request->param('place_id'))));
|
||||
return $this->success("修改成功!", url('/admin/ad/lists', ['id' => $data['place_id']]));
|
||||
} else {
|
||||
return $this->error($ad->getError());
|
||||
return $this->error('修改失败!');
|
||||
}
|
||||
} else {
|
||||
$info = db('ad')->where(array('id' => $id))->find();
|
||||
$info = AdModel::find($id);
|
||||
if (!$info) {
|
||||
return $this->error("非法操作!");
|
||||
}
|
||||
$data = array(
|
||||
$this->data = array(
|
||||
'info' => $info,
|
||||
'keyList' => $ad->keyList,
|
||||
'keyList' => AdModel::$keyList,
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta("编辑广告位");
|
||||
return $this->fetch('public/edit');
|
||||
return $this->fetch('admin/public/edit');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,13 +40,13 @@ class Client extends Base {
|
||||
|
||||
$result = ClientM::create($data);
|
||||
if (false !== $result) {
|
||||
return $this->success('成功添加', url('client/index'));
|
||||
return $this->success('成功添加', url('/admin/client/index'));
|
||||
} else {
|
||||
return $this->error('添加失败!');
|
||||
}
|
||||
} else {
|
||||
$info['appid'] = rand_string(10, 1); //八位数字appid
|
||||
$info['appsecret'] = rand_string(32); //32位数字加字母秘钥
|
||||
$info['appid'] = time(); //八位数字appid
|
||||
$info['appsecret'] = \xin\helper\Str::random(32); //32位数字加字母秘钥
|
||||
|
||||
$this->data = array(
|
||||
'info' => $info,
|
||||
@@ -64,12 +64,12 @@ class Client extends Base {
|
||||
|
||||
$result = ClientM::update($data, ['id' => $this->request->param('id')]);
|
||||
if (false !== $result) {
|
||||
return $this->success('修改添加', url('client/index'));
|
||||
return $this->success('修改添加', url('/admin/client/index'));
|
||||
} else {
|
||||
return $this->error($this->model->getError());
|
||||
}
|
||||
} else {
|
||||
$info = $ClientM::where('id', $request->param('id'))->find();
|
||||
$info = ClientM::where('id', $this->request->param('id'))->find();
|
||||
|
||||
$this->data = array(
|
||||
'info' => $info,
|
||||
@@ -81,7 +81,24 @@ class Client extends Base {
|
||||
/**
|
||||
* @title 删除客户端
|
||||
*/
|
||||
public function del(\think\Request $request) {
|
||||
public function del() {
|
||||
$id = $this->request->param('id', '');
|
||||
|
||||
$map = [];
|
||||
if (!$id) {
|
||||
return $this->error('请选择要操作的数据!');
|
||||
}
|
||||
if (is_array($id)) {
|
||||
$map[] = ['id', 'IN', $id];
|
||||
}else{
|
||||
$map[] = ['id', '=', $id];
|
||||
}
|
||||
|
||||
$result = ClientM::where($map)->delete();
|
||||
if (false !== $result) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->error('删除失败!');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测需要动态判断的文档类目有关的权限
|
||||
*
|
||||
|
||||
@@ -36,27 +36,23 @@ class Link extends Base {
|
||||
* @title 添加链接
|
||||
*/
|
||||
public function add() {
|
||||
$link = model('Link');
|
||||
if ($this->request->isPost()) {
|
||||
$data = input('post.');
|
||||
$data = $this->request->post();
|
||||
if ($data) {
|
||||
unset($data['id']);
|
||||
$result = $link->save($data);
|
||||
$result = LinkM::create($data);
|
||||
if ($result) {
|
||||
return $this->success("添加成功!", url('Link/index'));
|
||||
return $this->success("添加成功!", url('/admin/link/index'));
|
||||
} else {
|
||||
return $this->error($link->getError());
|
||||
return $this->error('添加失败!');
|
||||
}
|
||||
} else {
|
||||
return $this->error($link->getError());
|
||||
return $this->error('未提交数据');
|
||||
}
|
||||
} else {
|
||||
$data = array(
|
||||
'keyList' => $link->keyList,
|
||||
$this->data = array(
|
||||
'keyList' => LinkM::$keyList,
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta("添加友链");
|
||||
return $this->fetch('public/edit');
|
||||
return $this->fetch('admin/public/edit');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,31 +60,27 @@ class Link extends Base {
|
||||
* @title 修改链接
|
||||
*/
|
||||
public function edit() {
|
||||
$link = model('Link');
|
||||
$id = input('id', '', 'trim,intval');
|
||||
$id = $this->request->param('id');
|
||||
if ($this->request->isPost()) {
|
||||
$data = input('post.');
|
||||
$data = $this->request->post();
|
||||
if ($data) {
|
||||
$result = $link->save($data, array('id' => $data['id']));
|
||||
if ($result) {
|
||||
return $this->success("修改成功!", url('Link/index'));
|
||||
$result = LinkM::update($data, array('id' => $data['id']));
|
||||
if (false !== $result) {
|
||||
return $this->success("修改成功!", url('/admin/link/index'));
|
||||
} else {
|
||||
return $this->error("修改失败!");
|
||||
}
|
||||
} else {
|
||||
return $this->error($link->getError());
|
||||
return $this->error('未提交数据');
|
||||
}
|
||||
} else {
|
||||
$map = array('id' => $id);
|
||||
$info = db('Link')->where($map)->find();
|
||||
$info = LinkM::find($id);
|
||||
|
||||
$data = array(
|
||||
'keyList' => $link->keyList,
|
||||
$this->data = array(
|
||||
'keyList' => LinkM::$keyList,
|
||||
'info' => $info,
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta("编辑友链");
|
||||
return $this->fetch('public/edit');
|
||||
return $this->fetch('admin/public/edit');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,18 +88,23 @@ class Link extends Base {
|
||||
* @title 删除链接
|
||||
*/
|
||||
public function delete() {
|
||||
$id = $this->getArrayParam('id');
|
||||
if (empty($id)) {
|
||||
return $this->error('非法操作!');
|
||||
}
|
||||
$link = db('Link');
|
||||
$id = $this->request->param('id', '');
|
||||
|
||||
$map = array('id' => array('IN', $id));
|
||||
$result = $link->where($map)->delete();
|
||||
if ($result) {
|
||||
return $this->success("删除成功!");
|
||||
$map = [];
|
||||
if (!$id) {
|
||||
return $this->error('请选择要操作的数据!');
|
||||
}
|
||||
if (is_array($id)) {
|
||||
$map[] = ['id', 'IN', $id];
|
||||
}else{
|
||||
$map[] = ['id', '=', $id];
|
||||
}
|
||||
|
||||
$result = LinkM::where($map)->delete();
|
||||
if (false !== $result) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->error("删除失败!");
|
||||
return $this->error('删除失败!');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user