更新channel模块

This commit is contained in:
2020-03-26 22:12:31 +08:00
parent 8cd53f9366
commit 336f5af8ad
12 changed files with 209 additions and 124 deletions
+1
View File
@@ -23,6 +23,7 @@ class Admin extends Base {
'__img__' => '/static/admin/images',
'__css__' => '/static/admin/css',
'__js__' => '/static/admin/js',
'__plugins__' => '/static/plugins',
'__public__' => '/static/admin',
],
];
+1
View File
@@ -49,6 +49,7 @@ class Base {
'__img__' => '/static/front/images',
'__css__' => '/static/front/css',
'__js__' => '/static/front/js',
'__plugins__' => '/static/plugins',
'__public__' => '/static/front',
],
];
+25 -22
View File
@@ -50,19 +50,20 @@ class Category extends Admin {
'module_id' => isset($param['module_id']) ? $param['module_id'] : 0,
'model_list' => []
];
// $this->assign('tree', $list);
// $this->assign('model_list', $model_list);
// $this->assign('model_id', $model_id);
// $this->setMeta('栏目列表');
return $this->fetch();
}
/**
* @title 编辑字段
*/
public function editable($name = null, $value = null, $pk = null) {
if ($name && ($value != null || $value != '') && $pk) {
db('Category')->where(array('id' => $pk))->setField($name, $value);
public function editable() {
$name = $this->request->param('name', '');
$value = $this->request->param('value', '');
$pk = $this->request->param('pk', '');
if ($name && $value && $pk) {
$save[$name] = $value;
CategoryM::update($save, ['id' => $pk]);
}
}
@@ -83,24 +84,26 @@ class Category extends Admin {
return $this->error(empty($error) ? '未知错误!' : $error);
}
} else {
$cate = '';
if ($pid) {
/* 获取上级分类信息 */
$cate = db('Category')->find($pid);
if (!($cate && 1 == $cate['status'])) {
return $this->error('指定的上级分类不存在或被禁用!');
}
}
$subsql = db('Attribute')->where('name', 'category_id')->fetchSql(true)->column('model_id');
$model_list = model('Model')->where('id IN ('. $subsql.')')->select();
$cate = [];
// if ($pid) {
// /* 获取上级分类信息 */
// $cate = db('Category')->find($pid);
// if (!($cate && 1 == $cate['status'])) {
// return $this->error('指定的上级分类不存在或被禁用!');
// }
// }
// $subsql = db('Attribute')->where('name', 'category_id')->fetchSql(true)->column('model_id');
// $model_list = model('Model')->where('id IN ('. $subsql.')')->select();
$model_list = [];
/* 获取分类信息 */
$info = $id ? db('Category')->find($id) : '';
$info = $id ? CategoryM::find($id) : [];
$this->assign('info', $info);
$this->assign('model_list', $model_list);
$this->assign('category', $cate);
$this->setMeta('编辑分类');
$this->data = [
'info' => $info,
'model_list' => $model_list,
'category' => $cate
];
return $this->fetch();
}
}
+44 -45
View File
@@ -24,12 +24,11 @@ class Channel extends Admin {
*/
public function index(ChannelM $channel, $type = 0) {
/* 获取频道列表 */
//$map = array('status' => array('gt', -1), 'pid'=>$pid);
$map = array('status' => array('gt', -1));
$map[] = ['status', '>', -1];
if ($type) {
$map['type'] = $type;
}
$list = $channel->where($map)->order('sort asc,id asc')->column('*', 'id');
$list = $channel->where($map)->order('sort asc,id asc')->select()->append(['status_text'])->toArray();
if (!empty($list)) {
$tree = new Tree();
@@ -60,11 +59,9 @@ class Channel extends Admin {
if ($this->request->isPost()) {
$data = $this->request->post();
if ($data) {
$id = ChannelM::save($data);
$id = ChannelM::create($data);
if ($id) {
return $this->success('新增成功', url('index'));
//记录行为
action_log('update_channel', 'channel', $id, session('user_auth.uid'));
return $this->success('新增成功', url('/admin/channel/index'));
} else {
return $this->error('新增失败');
}
@@ -72,16 +69,17 @@ class Channel extends Admin {
$this->error('新增失败');
}
} else {
$pid = input('pid', 0);
$pid = $this->request->param('pid', 0);
//获取父导航
$parent = "";
if (!empty($pid)) {
$parent = ChannelM::where(array('id' => $pid))->field('title')->find();
$this->assign('parent', $parent);
$parent = ChannelM::where(array('id' => $pid))->value('title');
}
$pnav = ChannelM::where(array('pid' => '0'))->select();
$this->data = [
'parent' => $parent,
'pnav' => $pnav,
'pid' => $pid,
'info' => ['pid' => $pid]
@@ -95,40 +93,39 @@ class Channel extends Admin {
*/
public function edit($id = 0) {
if ($this->request->isPost()) {
$Channel = model('Channel');
$data = $this->request->post();
if ($data) {
if (false !== $Channel->save($data, array('id' => $data['id']))) {
//记录行为
action_log('update_channel', 'channel', $data['id'], session('user_auth.uid'));
return $this->success('编辑成功', url('index'));
$result = ChannelM::update($data, ['id' => $data['id']]);
if (false !== $result) {
return $this->success('编辑成功', url('/admin/channel/index'));
} else {
return $this->error('编辑失败');
}
} else {
return $this->error($Channel->getError());
return $this->error('非法操作!');
}
} else {
$info = array();
$pid = $this->request->param('pid', 0);
/* 获取数据 */
$info = db('Channel')->find($id);
$info = ChannelM::find($id);
if (false === $info) {
return $this->error('获取配置信息错误');
}
$pid = input('pid', 0);
//获取父导航
$parent = "";
if (!empty($pid)) {
$parent = db('Channel')->where(array('id' => $pid))->field('title')->find();
$this->assign('parent', $parent);
$parent = ChannelM::where(array('id' => $pid))->value('title');
}
$pnav = db('Channel')->where(array('pid' => '0'))->select();
$this->assign('pnav', $pnav);
$this->assign('pid', $pid);
$this->assign('info', $info);
$this->setMeta('编辑导航');
$pnav = ChannelM::where(array('pid' => '0'))->select();
$this->data = [
'parent' => $parent,
'pnav' => $pnav,
'pid' => $pid,
'info' => $info
];
return $this->fetch();
}
}
@@ -137,19 +134,20 @@ class Channel extends Admin {
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function del() {
$id = $this->getArrayParam('id');
$id = $this->request->param('id', '');
if (empty($id)) {
$map = [];
if (!$id) {
return $this->error('请选择要操作的数据!');
}
if (is_array($id)) {
$map[] = ['id', 'IN', $id];
}else{
$map[] = ['id', '=', $id];
}
$map = array('id' => array('in', $id));
if (db('Channel')->where($map)->delete()) {
//删除category中的ismenu字段记录
$map = array('ismenu' => array('in', $id));
db('Category')->where($map)->setField('ismenu', 0);
//记录行为
action_log('update_channel', 'channel', $id, session('user_auth.uid'));
$result = ChannelM::where($map)->delete();
if (false !== $result) {
return $this->success('删除成功');
} else {
return $this->error('删除失败!');
@@ -197,19 +195,20 @@ class Channel extends Admin {
* @title 设置状态
*/
public function setStatus() {
$id = array_unique((array) input('ids', 0));
$status = input('status', '0', 'trim');
if (empty($id)) {
return $this->error('请选择要操作的数据!');
$id = $this->request->param('id', 0);
$status = $this->request->param('status', 0);
$map = [];
if (is_array($id)) {
$map[] = ['id', 'IN', $id];
}else{
$map[] = ['id', '=', $id];
}
$map = array('id' => array('in', $id));
$result = db('Channel')->where($map)->update(array('status' => $status));
if ($result) {
return $this->success("操作成功!");
$result = ChannelM::update(['status'=> $status], $map);
if ($result !== false) {
return $this->success('操作成功!');
} else {
return $this->error("操作失败!");
return $this->error('操作失败!');
}
}
}
+2 -2
View File
@@ -144,8 +144,8 @@ class Menu extends Admin {
$map[] = ['id', '=', $id];
}
if (MenuM::where($map)->delete()) {
$result = MenuM::where($map)->delete()
if (false !== $result) {
Cache::pull('admin_menu_list');
return $this->success('删除成功');
} else {