新增当前栏目位置|新增从栏目生成导航(升级需数据库增加字段)

This commit is contained in:
K先森
2017-11-21 13:42:28 +08:00
parent 5b26ddd7e7
commit 2a945ea10b
6 changed files with 206 additions and 4 deletions

View File

@@ -248,4 +248,42 @@ class Category extends Admin {
return $this->error("设置失败!");
}
}
public function add_channel() {
if (IS_POST) {
$Channel = model('Channel');
$data = $this->request->param();
if ($data) {
$id = $Channel->save($data);
if ($id) {
$map['id'] = array('IN', $data['mid']);
$result = db('Category')->where($map)->setField('ismenu',$Channel->id);
return $this->success('生成成功',url('index'));
//记录行为
action_log('update_channel', 'channel', $id, session('user_auth.uid'));
} else {
return $this->error('生成失败');
}
} else {
$this->error($Channel->getError());
}
} else {
$data = $this->request->param();
$modelname = db('Model')->where( array('id' => $data['model_id']) )->field('id,name')->find();
$data['url'] = $modelname['name'].'/list/'.$data['mid'];
$pid = input('pid', 0);
//获取父导航
if (!empty($pid)) {
$parent = db('Channel')->where(array('id' => $pid))->field('title')->find();
$this->assign('parent', $parent);
}
$pnav = db('Channel')->where(array('pid' => '0'))->select();
$this->assign('pnav', $pnav);
$this->assign('pid', $pid);
$this->assign('info', $data);
$this->assign('data',null );
$this->setMeta('生成导航');
return $this->fetch('edit_channel');
}
}
}

View File

@@ -140,6 +140,9 @@ class Channel extends Admin {
$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'));
return $this->success('删除成功');

View File

@@ -0,0 +1,114 @@
{extend name="public/base"/}
{block name="body"}
<!-- datepicker end -->
<div class="main-box clearfix">
<header class="main-box-header clearfix">
<div class="pull-left">
<h2>
生成到导航
</h2>
</div>
</header>
<div class="main-box-body clearfix">
<form method="post" class="form form-horizontal">
<div class="form-group">
<label class="col-lg-2 control-label">导航标题</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="title" value="{$info.title|default=''}">
<span class="help-block">(用于显示的文字)</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">当前标识</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="active" value="{$info.active|default=''}">
<span class="help-block">(当前标识)</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">导航连接</label>
<div class="col-lg-8">
<input type="text" class="form-control" name="url" value="{$info.url|default=''}">
<span class="help-block">用于调转的URL支持带http://的URL或U函数参数格式</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">导航类型</label>
<div class="col-lg-8">
<select name="type" id="type" class="form-control" style="width:auto;">
{volist name=":config('nav_type_list')" id="item"}
<option value="{$key}" {if isset($info['type']) && $info['type'] == $key}selected{/if}>{$item}</option>
{/volist}
</select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">父导航</label>
<div class="col-lg-5">
<select name="pid" class="form-control" style="width:auto;">
<option value="0">--一级导航--</option>
{volist name=":parse_field_bind('Channel',$data['pid'],'')" id="item"}
{if condition="$item['id'] neq $data['id']"}
<option value="{$item['id']}" {if condition="$pid eq $item['id']"}selected{/if}>{$item['title_show']}</option>
{/if}
{/volist}
</select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">新窗口打开</label>
<div class="col-lg-2">
<select name="target" class="form-control" style="width:auto;">
<option value="0" ></option>
<option value="1" {eq name="data.target" value="1"}selected{/eq}></option>
</select>
<span class="help-block">(是否新窗口打开链接)</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">图标</label>
<div class="col-lg-2">
<input type="text" class="form-control" name="icon" value="{$info.icon|default=''}">
<span class="help-block">输入图标英文</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">优先级</label>
<div class="col-lg-2">
<input type="text" class="form-control" name="sort" value="{$info.sort|default='1'}">
<span class="help-block">(导航显示顺序)</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">文字颜色</label>
<div class="col-lg-2">
<input type="text" class="form-control" name="color" value="{$info['color']|default=''}">
<span class="help-block">右上角的标志点颜色支持各类css表示方式</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">标志点颜色</label>
<div class="col-lg-2">
<input type="text" class="form-control" name="band_color" value="{$info['band_color']|default=''}">
<span class="help-block">右上角的标志点颜色支持各类css表示方式</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">标志点文字</label>
<div class="col-lg-3">
<input type="text" class="form-control" name="band_text" value="{$info['band_text']|default=''}">
<span class="help-block">(右上角的标志点文字,不要太长,没有自动隐藏)</span>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<input type="hidden" name="id" value="{$data.id|default=''}">
<button class="btn btn-success submit-btn ajax-post" type="submit" target-form="form-horizontal">确 定</button>
<button class="btn btn-danger btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
</div>
</div>
</form>
</div>
</div>
{/block}

View File

@@ -35,6 +35,7 @@
<th width="120">排序</th>
<th width="120">发布</th>
<th width="120">状态</th>
<th width="120">生成导航</th>
<th>操作</th>
</tr>
</thead>
@@ -59,6 +60,13 @@
<span class="label label-danger">禁用</span>
{/if}
</td>
<td>
{if $list['ismenu']}
<a href="{:url('admin/channel/del?id='.$list['ismenu'])}" class="ajax-get"><span class="label label-primary">已生成</span></a>
{else/}
<a href="{:url('add_channel?title='.$list['title'].'&model_id='.$list['model_id'].'&active='.$list['name'].'&mid='.$list['id'])}" ><span class="label label-danger">未生成</span></a>
{/if}
</td>
<td>
<a title="编辑" href="{:url('edit?id='.$list['id'].'&pid='.$list['pid'])}">编辑</a>
{if $list['status']}

View File

@@ -988,6 +988,44 @@ function get_category_child($id) {
return array_unique($ids);
}
/**
* 栏目文章当前位置
* @param integer $id 当前栏目ID
* @param string $ext 文章标题
* @return here 当前栏目树
* @author K先森 <77413254@qq.com>
**/
function get_category_pos($id,$ext=''){
$cat = db('Category');
$here = '<a href="/">首页</a>';
$uplevels = $cat->field("id,title,pid,model_id")->where("id=$id")->find();
if(empty($uplevels)){
return '栏目不存在';
}
if($uplevels['pid'] != 0)
$here .= get_category_uplevels($uplevels['pid']);
$modelid = $uplevels['model_id'];
$modelname = db('Model')->field("name")->where("id = $modelid")->find();
$links = url('index/content/lists?model='.$modelname['name'],array('id'=>$uplevels['id']));
$here .= ' &gt;&gt; <a href="'.$links.'">'.$uplevels['title']."</a>";
if($ext != '') $here .= ' &gt;&gt; '.$ext;
return $here;
}
function get_category_uplevels($id){
$cat = db('Category');
$here = '';
$uplevels = $cat->field("id,title,pid,model_id")->where("id=$id")->find();
$modelid = $uplevels['model_id'];
$modelname = db('Model')->field("name")->where("id = $modelid")->find();
$links = url('index/content/lists?model='.$modelname['name'],array('id'=>$uplevels['id']));
$here .= ' &gt;&gt; <a href="'.$links.'">'.$uplevels['title']."</a>";
if($uplevels['pid'] != 0){
$here = get_category_uplevels($uplevels['pid']).$here;
}
return $here;
}
function send_email($to, $subject, $message) {
$config = array(
'protocol' => 'smtp',

View File

@@ -337,6 +337,7 @@ CREATE TABLE `sent_category` (
`pid` int(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '上级分类ID',
`model_id` int(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '绑定模型ID',
`sort` int(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '排序(同级有效)',
`ismenu` int(100) UNSIGNED NOT NULL DEFAULT '0' COMMENT '生成导航返回的ID',
`list_row` tinyint(3) UNSIGNED NOT NULL DEFAULT '10' COMMENT '列表每页行数',
`meta_title` varchar(50) NOT NULL DEFAULT '' COMMENT 'SEO的网页标题',
`keywords` varchar(255) NOT NULL DEFAULT '' COMMENT '关键字',
@@ -366,10 +367,10 @@ CREATE TABLE `sent_category` (
-- 转存表中的数据 `sent_category`
--
INSERT INTO `sent_category` (`id`, `name`, `title`, `pid`, `sort`, `list_row`, `meta_title`, `keywords`, `description`, `template_index`, `template_lists`, `template_detail`, `template_edit`, `model`, `model_sub`, `type`, `link_id`, `allow_publish`, `display`, `reply`, `check`, `reply_model`, `extend`, `create_time`, `update_time`, `status`, `icon`, `groups`) VALUES
(1, 'news', '新闻动态', 0, 0, 10, '', '', '', '', '', '', '', '', '2', '2,1', 0, 0, 1, 0, 0, '1', 'null', 1379474947, 1463561497, 1, 0, ''),
(2, 'company_news', '国内新闻', 1, 1, 10, '', '', '', '', '', '', '', '2,3', '2', '2,1,3', 0, 1, 1, 0, 1, '1', '', 1379475028, 1386839751, 1, 0, ''),
(3, '', '国外新闻', 1, 2, 10, '', '', '', '', '', '', '', '', '', '', 0, 1, 1, 0, 0, '', '', 0, 0, 1, 0, '');
INSERT INTO `sent_category` (`id`, `name`, `title`, `pid`, `ismenu`, `sort`, `list_row`, `meta_title`, `keywords`, `description`, `template_index`, `template_lists`, `template_detail`, `template_edit`, `model`, `model_sub`, `type`, `link_id`, `allow_publish`, `display`, `reply`, `check`, `reply_model`, `extend`, `create_time`, `update_time`, `status`, `icon`, `groups`) VALUES
(1, 'news', '新闻动态', 0, 1, 0, 10, '', '', '', '', '', '', '', '', '2', '2,1', 0, 0, 1, 0, 0, '1', 'null', 1379474947, 1463561497, 1, 0, ''),
(2, 'company_news', '国内新闻', 1, 0, 1, 10, '', '', '', '', '', '', '', '2,3', '2', '2,1,3', 0, 1, 1, 0, 1, '1', '', 1379475028, 1386839751, 1, 0, ''),
(3, '', '国外新闻', 1, 0, 2, 10, '', '', '', '', '', '', '', '', '', '', 0, 1, 1, 0, 0, '', '', 0, 0, 1, 0, '');
-- --------------------------------------------------------