更新channel模块
This commit is contained in:
@@ -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',
|
||||
],
|
||||
];
|
||||
|
||||
@@ -49,6 +49,7 @@ class Base {
|
||||
'__img__' => '/static/front/images',
|
||||
'__css__' => '/static/front/css',
|
||||
'__js__' => '/static/front/js',
|
||||
'__plugins__' => '/static/plugins',
|
||||
'__public__' => '/static/front',
|
||||
],
|
||||
];
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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('操作失败!');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<div class="picker-box">
|
||||
<div id="picker_{$name}" class="picker_button">上传图片</div>
|
||||
{if isset($value) && $value}
|
||||
<input type="hidden" name="{$name}" id="field_{$name}" value="{$value}">
|
||||
{else/}
|
||||
<input type="hidden" name="{$name}" id="field_{$name}" value="">
|
||||
{/if}
|
||||
<div id="fileList_{$name}" class="upload-file-list-info" style="width:280px;">
|
||||
{if $value}
|
||||
{php}
|
||||
$images = get_cover($value);
|
||||
{/php}
|
||||
<li class="affix-list-item" id="WU_FILE_0">
|
||||
<div class="upload-file-info">
|
||||
<span class="webuploader-pick-file-close" data-queued-id="WU_FILE_0" data-id="{$value}" data-fileurl="{$images['path']}"><i class="close"></i></span>
|
||||
<span class="fname"></span>
|
||||
<span class="fsize">上传时间:{$images['create_time']}</span>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="filebox image">
|
||||
<img src="{:config('base_url')}{$images['path']}" class="img-responsive">
|
||||
</div>
|
||||
</li>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
uploadsize = 2;
|
||||
$(function(){
|
||||
$("#picker_{$name}").SentUploader({
|
||||
compress:false,
|
||||
fileNumLimit:1,
|
||||
uploadEvents: {
|
||||
uploadComplete:function(file){}
|
||||
},
|
||||
listName : 'fileList_{$name}',
|
||||
hiddenName: 'field_{$name}',
|
||||
hiddenValType:1,
|
||||
fileSingleSizeLimit:uploadsize*1024*1024,
|
||||
closeX:true
|
||||
},
|
||||
{
|
||||
fileType: 'service',
|
||||
filename : 'images',
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
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'],
|
||||
];
|
||||
}
|
||||
@@ -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']] : '禁用';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user