Commit 964b032b by 李洋

1111

parent b151a00e
......@@ -30,6 +30,7 @@ class MessageApiController extends Controller
private function addTemplate($request)
{
$data = $request->input();
// var_dump($data);die;
$insert_tpl_id = $data['tpl_id'];
......@@ -59,9 +60,7 @@ class MessageApiController extends Controller
//添加事务 保证 数据库多条修改时 原子操作
DB::beginTransaction();
try {
DB::connection('message')->transaction(function() use($data) {
//消息模板模型
$tpl_model = [];
$tpl_model['tpl_id'] = $data['tpl_id'];
......@@ -69,13 +68,14 @@ class MessageApiController extends Controller
$tpl_model['description'] = $data['description'];
$tpl_model['source_type'] = $data['source_type'];
$tpl_model['creater'] = $data['creater'];
// $tpl_model['obj_user'] = $data['obj_user'];
$tpl_model['obj_user'] = $data['obj_user'];
$tpl_model['msg_type'] = $data['msg_type'];
if (empty($tpl_model['tpl_id'])) {
$tpl_model['create_time'] = time();
$tpl_model['update_time'] = time();
$insert_tpl_id = DB::connection('message')->table('lie_msg_tpl')->insertGetId($tpl_model);
// var_dump($insert_tpl_id);die;
if (!$insert_tpl_id) {
$this->Export(11020, '新增消息模板失败');
}
......@@ -130,12 +130,10 @@ class MessageApiController extends Controller
$this->Export(11009, '编辑消息模板失败');
}
}
}else{
if(!empty($data['inner_channel_tpl_id']))
{
$delete_result = DB::connection('message')->table('lie_msg_channel_tpl')->where('channel_tpl_id',$data['inner_channel_tpl_id'])->delete();
if(!$delete_result)
{
} else {
if (!empty($data['inner_channel_tpl_id'])) {
$delete_result = DB::connection('message')->table('lie_msg_channel_tpl')->where('channel_tpl_id', $data['inner_channel_tpl_id'])->delete();
if (!$delete_result) {
$this->Export(11009, '编辑消息模板失败');
}
}
......@@ -164,12 +162,10 @@ class MessageApiController extends Controller
$this->Export(11012, '编辑消息模板失败');
}
}
}else{
if(!empty($data['sms_channel_tpl_id']))
{
$delete_result = DB::connection('message')->table('lie_msg_channel_tpl')->where('channel_tpl_id',$data['sms_channel_tpl_id'])->delete();
if(!$delete_result)
{
} else {
if (!empty($data['sms_channel_tpl_id'])) {
$delete_result = DB::connection('message')->table('lie_msg_channel_tpl')->where('channel_tpl_id', $data['sms_channel_tpl_id'])->delete();
if (!$delete_result) {
$this->Export(11012, '编辑消息模板失败');
}
}
......@@ -201,12 +197,10 @@ class MessageApiController extends Controller
$this->Export(11016, '编辑消息模板失败', $result);
}
}
}else{
if(!empty($data['email_channel_tpl_id']))
{
$delete_result = DB::connection('message')->table('lie_msg_channel_tpl')->where('channel_tpl_id',$data['email_channel_tpl_id'])->delete();
if(!$delete_result)
{
} else {
if (!empty($data['email_channel_tpl_id'])) {
$delete_result = DB::connection('message')->table('lie_msg_channel_tpl')->where('channel_tpl_id', $data['email_channel_tpl_id'])->delete();
if (!$delete_result) {
$this->Export(11016, '编辑消息模板失败');
}
}
......@@ -223,7 +217,7 @@ class MessageApiController extends Controller
$chn_tpl_model_wechatnotify['url'] = $data['wechat_notify_url'];
$wechat_head = $data['wechat_notify_head'];
$wechat_tail = $data['wechat_notify_tail'];
$wechat_content = json_encode(array('wechat_tpl_head'=>$wechat_head,'wechat_tpl_tail'=>$wechat_tail));
$wechat_content = json_encode(array('wechat_tpl_head' => $wechat_head, 'wechat_tpl_tail' => $wechat_tail));
$chn_tpl_model_wechatnotify['content'] = $wechat_content;
if (empty($chn_tpl_model_wechatnotify['channel_tpl_id'])) {
$chn_tpl_model_wechatnotify['create_time'] = time();
......@@ -239,20 +233,47 @@ class MessageApiController extends Controller
$this->Export(11019, '编辑消息模板失败');
}
}
}else{
if(!empty($data['wechat_notify_tpl_id']))
{
$delete_result = DB::connection('message')->table('lie_msg_channel_tpl')->where('channel_tpl_id',$data['wechat_notify_tpl_id'])->delete();
if(!$delete_result)
{
} else {
if (!empty($data['wechat_notify_tpl_id'])) {
$delete_result = DB::connection('message')->table('lie_msg_channel_tpl')->where('channel_tpl_id', $data['wechat_notify_tpl_id'])->delete();
if (!$delete_result) {
$this->Export(11019, '编辑消息模板失败');
}
}
}
DB::commit();
}catch (\Exception $e){
DB::rollBack();
}
if (strpos($data['channels'], '5') !== false) {
if (empty($data['ding_content'])) {
$this->Export(11020, '请填写钉钉消息内容');
}
$chn_tpl_model_ding = [];
$chn_tpl_model_ding['channel_tpl_id'] = $data['ding_channel_tpl_id'];
$chn_tpl_model_ding['channel_type'] = $data['ding_channel_type'];
$chn_tpl_model_ding['content'] = $data['ding_content'];
$chn_tpl_model_ding['tpl_id'] = $insert_tpl_id;
if (empty($chn_tpl_model_ding['channel_tpl_id'])) {
$chn_tpl_model_ding['create_time'] = time();
$chn_tpl_model_ding['update_time'] = time();
$result = DB::connection('message')->table('lie_msg_channel_tpl')->insert($chn_tpl_model_ding);
if (!$result) {
$this->Export(11021, '新增消息模板失败');
}
} else {
$chn_tpl_model_ding['update_time'] = time();
$result = DB::connection('message')->table('lie_msg_channel_tpl')->where('channel_tpl_id', $chn_tpl_model_ding['channel_tpl_id'])->update($chn_tpl_model_ding);
if (!$result) {
$this->Export(11022, '编辑消息模板失败');
}
}
} else {
if (!empty($data['ding_channel_tpl_id'])) {
$delete_result = DB::connection('message')->table('lie_msg_channel_tpl')->where('channel_tpl_id', $data['ding_channel_tpl_id'])->delete();
if (!$delete_result) {
$this->Export(11023, '编辑消息模板失败');
}
}
}
});
$this->Export(0, empty($tpl_model['tpl_id']) ? '新增成功' : '修改成功');
}
......
......@@ -461,16 +461,18 @@ class MessageController extends Controller
$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 = '';
if(!empty($rq_tpl_id))
{
//通过tpl_id找到模板的渠道们 和 描述等
$info = $db->table('lie_msg_tpl')->select('tpl_id','description','channels','msg_type','creater')->where('tpl_id',$rq_tpl_id)->first();
$info = $db->table('lie_msg_tpl')->select('tpl_id','description','channels','msg_type','creater','source_type','obj_user')->where('tpl_id',$rq_tpl_id)->first();
//通过找到的 channels 去渠道模板表里 把每个channel找出来
$tpl_channels_arr = explode(',',$info->channels);
......@@ -494,6 +496,8 @@ class MessageController extends Controller
$wechatNotify_chn_tpl_id = $channel_tpl_obj->channel_tpl_id;
//将head 和 tail从content中解析出来
$channel_tpl_obj->content = json_decode($channel_tpl_obj->content,true);
}else{
$ding_chn_tpl_id = $channel_tpl_obj->channel_tpl_id;
}
$channel_tpls[$channel_type] = $channel_tpl_obj;
}
......@@ -504,6 +508,7 @@ class MessageController extends Controller
$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))
......@@ -535,10 +540,12 @@ class MessageController extends Controller
'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
];
......
......@@ -83,6 +83,16 @@ $('#msg-tpl-submit').click(function()
}
}
//短信
if($("input[id='chk-channels-ding']").is(':checked'))
{
if(!$("#ding-tpl-content").val())
{
Prompt('请填写钉钉消息内容', 5);
return false;
}
}
addTemplate();
})
......@@ -101,6 +111,7 @@ function addTemplate()
source_type:1,
creater:$('#creater').val(),
description:$('#msg-tpl-desc').val(),
obj_user:$('#msg-specified-users-text').val(),
inner_channel_tpl_id:$('#inner-chn-tpl-id').val(),
inner_channel_type:1,
......@@ -125,6 +136,10 @@ function addTemplate()
wechat_notify_tail:$('#wechat-notify-tpl-tail').val(),
wechat_notify_url:$('#wechat-notify-tpl-url').val(),
ding_channel_tpl_id:$('#ding-chn-tpl-id').val(),
ding_channel_type:5,
ding_content:$('#ding-tpl-content').val(),
},
dataType: 'json',
success: function(resp){
......@@ -148,6 +163,11 @@ function addTemplate()
});
}
//监听钉钉消息内容
$('#ding-tpl-content').bind('input propertychange', function() {
$('#ding-content-length').html($(this).val().length+'/'+'256');
});
//监听短信内容,计算短信条数
$('#sms-tpl-content').bind('input propertychange', function() {
$('#sms-content-length').html('预计' + Math.ceil($(this).val().length/70) + '条短信');
......
......@@ -115,6 +115,7 @@
<input type="checkbox" name="chk-channels" id="chk-channels-sms" value="2" @if(!empty($isContainSMS)) checked @endif/><label>短息</label>
<input type="checkbox" name="chk-channels" id="chk-channels-email" value="3" @if(!empty($isContainEmail)) checked @endif/><label>邮箱</label>
<input type="checkbox" name="chk-channels" id="chk-channels-wechat-notify" value="4" @if(!empty($isContainWechatNotify)) checked @endif/><label>微信通知</label>
<input type="checkbox" name="chk-channels" id="chk-channels-ding" value="4" @if(!empty($isContainDing)) checked @endif/><label>钉钉通知</label>
</div>
</div>
......@@ -159,6 +160,12 @@
<span>微信通知</span>
</a>
</li>
<li role="presentation">
<a href="#ding" aria-controls="ding" role="tab" data-toggle="tab">
<i class="layui-icon">&#xe63a;</i>
<span>钉钉通知</span>
</a>
</li>
</ul>
</div>
......@@ -267,12 +274,36 @@
</div>
</div>
{{--钉钉消息--}}
<div role="tabpanel" class="tab-pane fade" id="ding">
<input type="hidden" id="ding-chn-tpl-id" value="{{ $ding_chn_tpl_id }}">
<div class="col-sm-10" style="margin-top: 40px">
<label class="col-sm-2 control-label"><span style="color: red">*</span> 钉钉消息内容:</label>
<div class="col-sm-10">
<textarea rows="2" cols="10" id="ding-tpl-content" class="form-control" placeholder="请输入钉钉消息内容">@if(!empty($info->channel_tpls['5'])) {{ $info->channel_tpls['5']->content }} @endif</textarea>
<label id="ding-content-length"></label>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{{--外部统一提交按钮--}}
{{--外部统一提交按钮及推送内部人员名单--}}
{{--用户范围(全局)--}}
<div class="col-sm-10 form-inline" style="margin-top: 20px;margin-left: 40px">
<label class="col-sm-2 control-label"> 内部用户名单:</label>
<div class="col-sm-8">
<textarea rows="2" cols="100" id="msg-specified-users-text" name="msg-specified-users-text" class="form-control" placeholder="请输入内部用户名单,如不需要推送内部用户可不填">{{ $info->obj_user or '' }}</textarea>
可输入多个目标用户,多个用户用','隔开
<div>
<label style="color: red">注:此名单只用于推送内部用户,推送外部用户请去手动发送消息</label>
</div>
</div>
</div>
<div class="col-sm-10" style="margin-top: 40px">
<div align="center">
<button class="btn btn-primary" id="msg-tpl-submit">提交</button>
......
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