diff --git a/app/controller/Admin.php b/app/controller/Admin.php index af3609b9..65058f00 100755 --- a/app/controller/Admin.php +++ b/app/controller/Admin.php @@ -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', ], ]; diff --git a/app/controller/Base.php b/app/controller/Base.php index c70cc8db..c24ca5d7 100644 --- a/app/controller/Base.php +++ b/app/controller/Base.php @@ -49,6 +49,7 @@ class Base { '__img__' => '/static/front/images', '__css__' => '/static/front/css', '__js__' => '/static/front/js', + '__plugins__' => '/static/plugins', '__public__' => '/static/front', ], ]; diff --git a/app/controller/admin/Category.php b/app/controller/admin/Category.php index 3cdf99c7..0676c081 100644 --- a/app/controller/admin/Category.php +++ b/app/controller/admin/Category.php @@ -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(); } } diff --git a/app/controller/admin/Channel.php b/app/controller/admin/Channel.php index f1256952..b2aabadb 100644 --- a/app/controller/admin/Channel.php +++ b/app/controller/admin/Channel.php @@ -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 麦当苗儿 */ 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('操作失败!'); } } } \ No newline at end of file diff --git a/app/controller/admin/Menu.php b/app/controller/admin/Menu.php index 77214504..59265d58 100644 --- a/app/controller/admin/Menu.php +++ b/app/controller/admin/Menu.php @@ -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 { diff --git a/app/http/form/template/image.html b/app/http/form/template/image.html new file mode 100644 index 00000000..ebe932ae --- /dev/null +++ b/app/http/form/template/image.html @@ -0,0 +1,47 @@ +
+
上传图片
+ {if isset($value) && $value} + + {else/} + + {/if} +
+ {if $value} + {php} + $images = get_cover($value); + {/php} +
  • +
    + + + 上传时间:{$images['create_time']} +
    +
    +
    + +
    +
  • + {/if} +
    +
    + \ No newline at end of file diff --git a/app/http/validate/admin/Channel.php b/app/http/validate/admin/Channel.php new file mode 100644 index 00000000..43014197 --- /dev/null +++ b/app/http/validate/admin/Channel.php @@ -0,0 +1,29 @@ + +// +---------------------------------------------------------------------- +namespace app\http\validate\admin; + +use think\Validate; + +/** + * 菜单验证 + */ +class Channel extends Validate{ + protected $rule = [ + 'title' => 'require', + ]; + + protected $message = [ + 'title.require' => '导航名称必须', + ]; + + protected $scene = [ + 'add' => ['title'], + 'edit' => ['title'], + ]; +} \ No newline at end of file diff --git a/app/model/Channel.php b/app/model/Channel.php index 4fbce534..eb8096c9 100644 --- a/app/model/Channel.php +++ b/app/model/Channel.php @@ -20,4 +20,9 @@ class Channel extends \think\Model { protected $auto = array('update_time', 'status' => 1); protected $insert = array('create_time'); + + protected function getStatusTextAttr($value, $data){ + $status = [0 => '禁用', 1 => '启用']; + return isset($status[$data['status']]) ? $status[$data['status']] : '禁用'; + } } \ No newline at end of file diff --git a/view/admin/category/edit.html b/view/admin/category/edit.html index 9b694df5..25a59443 100644 --- a/view/admin/category/edit.html +++ b/view/admin/category/edit.html @@ -18,36 +18,36 @@
    - -
    + +
    - -
    + +
    (名称不能为空)
    - -
    + +
    (英文字母)
    - -
    + +
    - -
    + +
    不允许 @@ -66,19 +66,19 @@
    -