Commit 4260a4a7 by 李洋

添加消息模板类别

parent 80fd4cbe
......@@ -48,8 +48,6 @@ class MessageApiController extends Controller
private function addTemplate($request)
{
$data = $request->input();
// var_dump($data);die;
$insert_tpl_id = $data['tpl_id'];
//至少选择一个渠道
......@@ -59,8 +57,14 @@ class MessageApiController extends Controller
if (empty($data['description'])) {
$this->Export(11002, '请输入消息key');
}
if (empty($data['tpl_key'])) {
$this->Export(11003, '请输入模板描述');
// if (empty($data['tpl_key'])) {
// $this->Export(11003, '请输入模板描述');
// }
if (empty($data['cls_id'])){
$this->Export(11024, '请输入模板分类');
}
if (empty($data['sub_cls_id'])){
$this->Export(11025, '请输入模板二级分类');
}
$is_dumplicated = DB::connection('message')->table('lie_msg_tpl')->where('description',$data['description'])->first();
......@@ -87,11 +91,12 @@ class MessageApiController extends Controller
$tpl_model['tpl_id'] = $data['tpl_id'];
$tpl_model['channels'] = $data['channels'];
$tpl_model['description'] = $data['description'];
$tpl_model['ex_str'] = $data['tpl_key'];
// $tpl_model['ex_str'] = $data['tpl_key'];
$tpl_model['source_type'] = $data['source_type'];
$tpl_model['creater'] = $data['creater'];
$tpl_model['obj_user'] = $data['obj_user'];
$tpl_model['msg_type'] = $data['msg_type'];
$tpl_model['sub_cls_id'] = $data['sub_cls_id'];
if (empty($tpl_model['tpl_id'])) {
$tpl_model['create_time'] = time();
......@@ -356,4 +361,14 @@ class MessageApiController extends Controller
$this->Export($response['err_code'], $response['err_msg']);
}
/** 获取模板子分类
* @param $request
*/
private function getSubTplCls($request){
$data = $request->input();
$sub_tpl_info = DB::connection('message')->table('lie_msg_tpl_sub_classify')->select('sub_cls_id','sub_cls_name')
->where('cls_id',$data['sel_msg_tpl_cls'])->get();
$this->Export(0, 'success',objectToArray($sub_tpl_info));
}
}
\ No newline at end of file
......@@ -385,32 +385,39 @@ class MessageController extends Controller
// 新增编辑消息模板
private function addtemplate(Request $request, $id, $viewid)
{
Csrf($request);
$perms_arr = ['template_create'];
$res_perm = $this->getUserPerms($request,$perms_arr);
$template_create = $res_perm['template_create'];
$rq_tpl_id = $request->input('tpl_id');
$db = DB::connection('message');
//是否包含某一渠道
$isContainInner = '';
$isContainSMS = '';
$isContainEmail = '';
$isContainWechatNotify = '';
$isContainDing = '';
//渠道模板id
$inner_chn_tpl_id = '';
$sms_chn_tpl_id = '';
$email_chn_tpl_id = '';
$wechatNotify_chn_tpl_id = '';
$ding_chn_tpl_id = '';
//消息模板一级分类
$msg_tpl_cls = $db->table('lie_msg_tpl_classify')->orderby('cls_id','asc')->get();
$msg_tpl_clses = [];
foreach ($msg_tpl_cls as $k=>$v){
$msg_tpl_clses[$v->cls_id] = $v->cls_name;
}
//消息模板二级分类
$msg_tpl_sub_clses = [];
if(!empty($rq_tpl_id))
{
//通过tpl_id找到模板的渠道们 和 描述等
$info = $db->table('lie_msg_tpl')->select('tpl_id','description','channels','msg_type','creater','source_type','obj_user','ex_str')->where('tpl_id',$rq_tpl_id)->first();
$info = $db->table('lie_msg_tpl as mt')->select('mt.tpl_id','mt.description','mt.channels','mt.msg_type','mt.creater','mt.source_type','mt.obj_user','mt.ex_str','mtsc.sub_cls_id','mtsc.sub_cls_name','mtsc.cls_id','mtc.cls_name')
->leftjoin('lie_msg_tpl_sub_classify as mtsc','mt.sub_cls_id','=','mtsc.sub_cls_id')
->leftjoin('lie_msg_tpl_classify as mtc','mtc.cls_id','=','mtsc.cls_id')
->where('tpl_id',$rq_tpl_id)->first();
//获取消息模板二级分类
if (!empty($info->cls_id)){
$msg_tpl_sub_cls = $db->table('lie_msg_tpl_sub_classify')->select('sub_cls_id','sub_cls_name','cls_id')
->where('cls_id',$info->cls_id)->get();
foreach ($msg_tpl_sub_cls as $k=>$v){
$msg_tpl_sub_clses[$v->sub_cls_id] = $v->sub_cls_name;
}
}
//通过找到的 channels 去渠道模板表里 把每个channel找出来
$tpl_channels_arr = explode(',',$info->channels);
$channel_tpls = [];
......@@ -439,52 +446,21 @@ class MessageController extends Controller
$channel_tpls[$channel_type] = $channel_tpl_obj;
}
$info->channel_tpls = $channel_tpls;
//判断包含的消息渠道(用于展示消息渠道)(利用之前分割字符串得到的数组)
$isContainInner = in_array('1',$tpl_channels_arr);
$isContainSMS = in_array('2',$tpl_channels_arr);
$isContainEmail = in_array('3',$tpl_channels_arr);
$isContainWechatNotify = in_array('4',$tpl_channels_arr);
$isContainDing = in_array('5',$tpl_channels_arr);
}
if(empty($info))
{
$info = (object)null;
$info->tpl_id = '';
$info->ex_str = '';
$info->description = '';
$info->channels ='';
$info->channel_tpls = [];
$info->msg_type = '';
$info->creater = '';
}
//消息类型枚举
$msg_type = [
'请选择',
'公告',
'活动',
'新闻',
'其他'
];
$data=[
'title'=>'asd',
'id'=>$id,
'info'=>$info,
'msg_type'=>$msg_type,
'isContainInner'=>$isContainInner,
'isContainSMS'=>$isContainSMS,
'isContainEmail'=>$isContainEmail,
'isContainWechatNotify'=>$isContainWechatNotify,
'isContainDing'=>$isContainDing,
'inner_chn_tpl_id'=>$inner_chn_tpl_id,
'sms_chn_tpl_id'=>$sms_chn_tpl_id,
'email_chn_tpl_id'=>$email_chn_tpl_id,
'wechatNotify_chn_tpl_id'=>$wechatNotify_chn_tpl_id,
'ding_chn_tpl_id'=>$ding_chn_tpl_id,
'template_create' => $template_create
'info'=>!empty($info)?$info:(object)null,
'inner_chn_tpl_id'=>!empty($inner_chn_tpl_id)?$inner_chn_tpl_id:'',
'sms_chn_tpl_id'=>!empty($sms_chn_tpl_id)?$sms_chn_tpl_id:'',
'email_chn_tpl_id'=>!empty($email_chn_tpl_id)?$email_chn_tpl_id:'',
'wechatNotify_chn_tpl_id'=>!empty($wechatNotify_chn_tpl_id)?$wechatNotify_chn_tpl_id:'',
'ding_chn_tpl_id'=>!empty($ding_chn_tpl_id)?$ding_chn_tpl_id:'',
'tpl_channels_arr'=>!empty($tpl_channels_arr)?$tpl_channels_arr:[],
'template_create' => $template_create,
'msg_tpl_clses'=>$msg_tpl_clses,
'msg_tpl_sub_clses'=>$msg_tpl_sub_clses
];
return view($viewid, $data);
......
......@@ -51,4 +51,11 @@ return [
5 => '钉钉消息'
],
'msg_type' => [
1 => '公告',
2 => '活动',
3 => '新闻',
4 => '其他'
]
];
\ No newline at end of file
layui.use(['jquery','element', 'layer', 'form'], function(){
var $ = layui.$;
var element = layui.element;
var layer = layui.layer;
var form = layui.form;
//监听模板分类选择 并刷新二级分类数据
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.render();
});
$('#msg-tpl-submit').click(function()
{
//前端校验
......@@ -12,15 +40,15 @@ $('#msg-tpl-submit').click(function()
return false;
}
if(!$('#msg-tpl-desc1').val())
{
Prompt('请输入消息key', 5);
return false;
}
// if(!$('#msg-tpl-desc1').val())
// {
// Prompt('请输入消息描述', 5);
// return false;
// }
if(!$('#msg-tpl-desc').val())
{
Prompt('请输入模板描述', 5);
Prompt('请输入模板key', 5);
return false;
}
......@@ -114,6 +142,8 @@ function addTemplate()
tpl_id:$('#tpl-id').val(),
channels:getChosenMsgChannels(),
msg_type:$('#inner-tpl-type option:selected').val(),
cls_id:$('#msg_tpl_cls option:selected').val(),
sub_cls_id:$('#msg_tpl_sub_cls option:selected').val(),
source_type:1,
creater:$('#creater').val(),
tpl_key:$('#msg-tpl-desc1').val(),
......
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