更新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

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('操作失败!');
}
}
}