Commit 915e5bdd by 李洋

消息模板改版 包括列表页 和 新增/编辑页

parent 4260a4a7
......@@ -371,4 +371,13 @@ class MessageApiController extends Controller
->where('cls_id',$data['sel_msg_tpl_cls'])->get();
$this->Export(0, 'success',objectToArray($sub_tpl_info));
}
private function delTpl($request){
$in_data = $request->input();
$res = DB::connection('message')->table('lie_msg_tpl')->where('tpl_id',$in_data['tpl_id'])->update(['status'=>1]);
if ($res && $res !== false){
$this->Export(0, 'success');
}
}
}
\ No newline at end of file
......@@ -176,7 +176,6 @@ class MessageController extends Controller
// 消息模板列表
private function templatelist(Request $request, $id, $viewid)
{
Csrf($request);
//获取权限
$perms_arr = ['template_check','template_create','template_edit'];
$res_perm = $this->getUserPerms($request,$perms_arr);
......@@ -184,70 +183,56 @@ class MessageController extends Controller
$template_create = $res_perm['template_create'];
$template_edit = $res_perm['template_edit'];
// $template_check = $template_create = $template_edit =true;
//搜索
$search_desc = $request->input('search_desc');
$search_channel = $request->input('search_channel');
$search_keyword = $request->input('search_keyword');
$conditions = $request->input();
$info = [];
$db = DB::connection('message');
if (!empty($conditions['page']) && !empty($conditions['limit'])){
$info = $db->table('lie_msg_tpl as mt')->select('mt.tpl_id','mt.channels','mt.description','mt.ex_str','mtc.cls_name','mtsc.sub_cls_name','mtsc.sub_cls_id','mtsc.cls_id')
->leftjoin('lie_msg_tpl_sub_classify as mtsc','mtsc.sub_cls_id','=','mt.sub_cls_id')
->leftjoin('lie_msg_tpl_classify as mtc','mtc.cls_id','=','mtsc.cls_id')
->where(function($query) use($conditions){
if (!empty($conditions['msg_key'])){
$query->where('mt.description','like','%'.$conditions['msg_key'].'%');
}
if (!empty($conditions['msg_channel'])){
$query->where('mt.channels','like','%'.$conditions['msg_channel'].'%');
}
if (!empty($conditions['msg_tpl_cls'])){
$query->where('mtsc.cls_id',$conditions['msg_tpl_cls']);
}
if (!empty($conditions['msg_tpl_sub_cls'])){
$query->where('mtsc.sub_cls_id',$conditions['msg_tpl_sub_cls']);
}
})
->where('status',0)
->where('source_type',1)
->orderby('tpl_id','desc')
->paginate($conditions['limit'],['*'],'page',$conditions['page'])->toArray();
$cnt = DB::connection('message');
//自动发送模板数据
//1.首次进页面无搜索条件
if($search_desc==null && $search_channel==null && $search_keyword == null)
{
$info = $cnt->table('lie_msg_tpl')->where("status",'0')->where('source_type','1')->orderBy('tpl_id','desc')->paginate(20);
$search_channel = 0;
$search_desc = '';
}else//2.有搜索条件
{
//渠道里没有0,所以如果没选,将此条件剔除掉
if(0==$search_channel)
{
$info = $cnt->table('lie_msg_tpl')->where('source_type','1')->where("status",'0')->where('ex_str','like',"%$search_desc%")->where('description','like',"%$search_keyword%")->orderBy('tpl_id','desc')->paginate(20);
}else
{
$info = $cnt->table('lie_msg_tpl')->where('source_type','1')->where("status",'0')->where('channels','like',"%$search_channel%")->where('description','like',"%$search_keyword%")->where('ex_str','like',"%$search_desc%")->orderBy('tpl_id','desc')->paginate(20);
foreach ($info['data'] as &$item){
$item = objectToArray($item);
$item['cls_name'] = !empty($item['cls_name'])?$item['cls_name']:'' ;
$item['sub_cls_name'] = !empty($item['sub_cls_name'])?$item['sub_cls_name']:'' ;
$item['show_channels_str'] = $this->changeNumberStrToChineseStr(['站内信','短信','邮箱','微信通知','钉钉消息'],$item['channels']);
}
unset($item);
return json_encode(['code'=>0,'count'=>$info['total'],'msg'=>'success','data'=>$info['data']]);
}
//构建model
foreach ($info as $tpl)
{
//将消息渠道从 数字字符串转化为汉字字符串 用于用户展示
$tpl->show_channels_str = $this->changeNumberStrToChineseStr(['站内信','短信','邮箱','微信通知','钉钉消息'],$tpl->channels);
//取出渠道站内信和邮件title 放到info中
$inner_title = $cnt->table('lie_msg_channel_tpl')->select('title')
->where('tpl_id',$tpl->tpl_id)->where('channel_type',1)->first();
$email_title = $cnt->table('lie_msg_channel_tpl')->select('title')
->where('tpl_id',$tpl->tpl_id)->where('channel_type',3)->first();
$tpl->title = '-';
if(!empty($inner_title->title))
{
$tpl->title = $inner_title->title;
}else if(!empty($email_title->title))
{
$tpl->title = $email_title->title;
}
//消息模板分类
$clses = [];
$cls = $db->table('lie_msg_tpl_classify')->select('cls_id','cls_name')->get();
foreach ($cls as &$c){
$c = objectToArray($c);
$clses[$c['cls_id']] = $c['cls_name'];
}
$msg_channels=[
'全部',
'站内信',
'短信',
'邮件',
'微信通知',
'钉钉通知'
];
unset($c);
$data=[
'title'=>'asd',
'id'=>$id,
'info'=>$info,
'msg_channels'=>$msg_channels,
'search_desc'=>$search_desc,
'search_channel'=>$search_channel,
'search_keyword'=>$search_keyword,
'clses'=>$clses,
'template_check'=>$template_check,
'template_create'=>$template_create,
......
......@@ -56,6 +56,6 @@ return [
2 => '活动',
3 => '新闻',
4 => '其他'
]
],
];
\ No newline at end of file
//指定条件搜索
$('#search-btn').click(function () {
var search_desc = $('#search-desc').val();
var search_keyword = $('#search-keyword').val();
var search_channel = $('#choose-tpl option:selected').val();
window.location.href="/message/templatelist?search_desc="+search_desc+"&search_channel="+search_channel + "&search_keyword=" + search_keyword;
})
\ No newline at end of file
layui.use(['jquery','element', 'layer', 'form','table','laypage','laydate'], function(){
var $ = layui.$;
var element = layui.element;
var layer = layui.layer;
var form = layui.form;
var table = layui.table;
//监听模板分类选择 并刷新二级分类数据
form.on('select(msg_tpl_cls)', function(data){
var sel_msg_tpl_cls = data.value;
$.ajax({
url: "/msgapi/getSubTplCls",
dataType: 'json',
data: {
sel_msg_tpl_cls: sel_msg_tpl_cls
},
success: function (result) {
var optionstring = "";
$.each(result.data, function(i,item){
optionstring += "<option value=" + item.sub_cls_id + ">" + item.sub_cls_name + "</option>";
});
$("#msg_tpl_sub_cls").html('<option value=""></option>' + optionstring);
form.render('select');
}
});
});
//监听表单提交按钮
form.on('submit(search)', function(data){
//根据搜索条件 重载表单
msg_tpl_table.reload({
where: data.field,//设定异步数据接口的额外参数,任意设
page: {
curr: 1 //重新从第 1 页开始
}
});
return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。
});
//数据表格渲染
var msg_tpl_table = table.render({
elem: '#table',
url: '/message/templatelist',
page: true,
limit: 20,
id:'table',
cols: [[ //表头
{field: 'tpl_id', title: '模板编号',align:'center'},
{field: 'description', title: '关键字',align:'center'},
{field: 'cls_name', title: '模板分类',align:'center'},
{field: 'sub_cls_name', title: '模板二级分类',align:'center'},
{field: 'show_channels_str', title: '消息渠道',align:'center'},
{field: 'ex_str', title: '消息描述',align:'center'},
{title: '操作', fixed: 'right', width:150, align:'center', toolbar: '#bar'}
]]
});
//监听工具条
table.on('tool(table)', function(obj){ //注:tool是工具条事件名,test是table原始容器的属性 lay-filter="对应的值"
var data = obj.data; //获得当前行数据
var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值)
var tr = obj.tr; //获得当前行 tr 的DOM对象
if(layEvent === 'edit'){ //编辑
window.location.href='addtemplate?tpl_id='+data.tpl_id;
} else if(layEvent === 'del'){ //删除
delTpl(data.tpl_id);
}
});
$('#reload_table').on('click',function () {
table.reload('table',{
// where: {activity_id:$('#activity_id').val()},//设定异步数据接口的额外参数,任意设
page: {
curr: 1 //重新从第 1 页开始
}
});
});
form.render();
});
function delTpl(tpl_id){
$.ajax({
url: "/msgapi/delTpl",
dataType: 'json',
data: {
tpl_id: tpl_id
},
success: function (resp) {
if(!resp){
Prompt('网络异常,请重试', 5);
return false;
}
if(resp.errcode==0){
Prompt(resp.errmsg, 1);
location.reload();
}else{
Prompt(resp.errmsg, 5);
return false;
}
},
error:function(jqXHR, textStatus, errorThrown){
Prompt("网络异常,请重试",5);
}
});
}
\ No newline at end of file
......@@ -20,7 +20,7 @@
@endif
<div class="row">
<div class="col-lg-12">
<iframe src="http://{{ Config::get('website.data') }}/message/{{ $id }}" style="height: 100%;overflow: auto" id="iframe"></iframe>
<iframe src="http://{{ Config::get('website.data') }}/message/{{ $id }}" style="height: 100%;overflow: auto;width: 98%;" id="iframe"></iframe>
</div>
</div>
</div>
......
<style>
.p-l{
margin: 20px;
background-color: rgba(255, 249, 242, 0.02);
height: auto;
}
.p-l label{
margin-left: 30px;
.filter-label-left{
margin-left: 40px;
margin-top: 20px;
width: 150px;
}
.div-b{
.filter-select{
margin-top: 20px;
width: 150px;
}
</style>
@if($template_check)
<div class="gray-bg">
<div class="wrapper wrapper-content">
<div class="row">
<div class="col-lg-12">
<div class="ibox float-e-margins">
<div class="ibox-title">
<div class="form-inline p-l">
<form method="get" action="/message/templatelist">
<div style="text-align: center" class="div-b">
@if($template_create)
<a class="btn btn-primary btn-sm" href="/message/addtemplate" style="float: left; margin-left: 30px">新增消息模板</a>
@endif
<label>消息关键词(开发使用):</label>
<input type="text" class="form-control" id="search-keyword" placeholder="请输入消息关键词" value="{{ $search_keyword }}">
<label>消息描述:</label>
<input type="text" class="form-control" id="search-desc" placeholder="请输入消息描述" value="{{ $search_desc }}">
<label>消息渠道:</label>
<select class="form-control" name="inner-choose-type" id="choose-tpl">
@for($i=0;$i<count($msg_channels);$i++)
<option value="{{ $i }}" @if($i==$search_channel) selected @endif>{{ $msg_channels[$i] }}</option>
@endfor
</select>
<input class="btn btn-primary btn-sm" id="search-btn" style="float: right; margin-right: 60px" value="搜索"/>
</div>
</form>
</div>
</div>
@if(count($info)>0)
<div class="ibox-content">
<div class="dataTables_wrapper form-inline dt-bootstrap">
<div class="row">
<div class="col-sm-12">
<table class="table table-striped table-bordered table-hover">
<thead>
<tr role="row">
<th style="width:100px;" class="text-center">模板编号</th>
<th style="width:100px;" class="text-center">模板标题</th>
<th style="width:100px;" class="text-center">关键字</th>
<th style="width:150px;" class="text-center">消息描述</th>
<th style="width:100px;" class="text-center">消息渠道</th>
<th style="width:100px;" class="text-center">操作</th>
</tr>
</thead>
<tbody>
@for($i=0;$i<count($info);$i++)
<tr role="row" style="text-align: center">
<td>{{ $info[$i]->tpl_id }}</td>
<td>{{ $info[$i]->title }}</td>
<td>{{ $info[$i]->description }}</td>
<td>{{ $info[$i]->ex_str }}</td>
<td>{{ $info[$i]->show_channels_str }}</td>
@if($template_edit)
<td>
<a href="{{url('message/addtemplate')}}?tpl_id={{$info[$i]->tpl_id}}" class="btn btn-xs btn-outline btn-primary">编辑</a>
<a onclick="deletemlate({{$info[$i]->tpl_id}})" href="#" class="btn btn-xs btn-outline btn-primary">删除</a>
</td>
@endif
</tr>
@endfor
</tbody>
</table>
{{--{!! $info->links() !!}--}}
{{$info->appends([
'search_desc'=>$search_desc,
'search_channel'=>$search_channel,
'search_keyword'=>$search_keyword,
])->links() }}
</div>
</div>
<div class="row" id="my_list_paginate"></div>
</div>
</div>
@else
<div style="text-align: center">
<label>很抱歉,暂无数据</label>
</div>
@endif
<form class="layui-form" action="">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label filter-label-left">消息关键字:</label>
<div class="layui-input-inline" style="width: 200px; margin-top: 20px;">
<input type="text" name="msg_key" autocomplete="off" class="layui-input" style="width: 200px;"/>
</div>
<label class="layui-form-label filter-label-left">消息渠道:</label>
<div class="layui-input-inline filter-select">
<select name="msg_channel" lay-filter="msg_channel" id="msg_channel">
<option value="">请选择</option>
@foreach(Config('msgconfig.msg_channels') as $k=>$v)
<option value="{{$k}}">{{$v}}</option>
@endforeach
</select>
</div>
</div>
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label filter-label-left">消息模板分类:</label>
<div class="layui-input-inline filter-select">
<select name="msg_tpl_cls" lay-filter="msg_tpl_cls" id="msg_tpl_cls">
<option value="">请选择</option>
@foreach($clses as $k=>$v)
<option value="{{$k}}">{{$v}}</option>
@endforeach
</select>
</div>
<label class="layui-form-label filter-label-left">消息模板二级分类:</label>
<div class="layui-input-inline filter-select">
<select name="msg_tpl_sub_cls" lay-filter="msg_tpl_sub_cls" id="msg_tpl_sub_cls">
<option value="">请选择</option>
</select>
</div>
<div class="layui-input-inline" style="float:right;margin-top: 20px;">
<button class="layui-btn" lay-submit lay-filter="search" data-type="reload">查询</button>
</div>
</div>
</div>
</form>
{{--<button id="reload_table" hidden></button>--}}
<table class="layui-hide" id="table" lay-filter="table"></table>
<script type="text/html" id="bar">
@if($template_edit)
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
@endif
</script>
@else
<div style="text-align: center">
<label style="margin-top: 30px">对不起,您没有权限查看此页面</label>
......@@ -114,26 +87,5 @@
</div>
</div>
@endif
<script src="/js/Message/layer/layer.js"></script>
<script>
var deletemplateurl = '{{url('msgapi/deletetemplate')}}';
function deletemlate(id){
layer.confirm('确定删除?', {
btn: ['确定','取消'] //按钮
}, function(){
$.post(deletemplateurl,{'id':id},function(res){
if(res.errcode == 0){
layer.msg('删除成功', {icon: 1});
window.location.reload();
}else{
layer.msg('删除失败', {icon: 1});
}
},'json');
}, function(){
});
}
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment