Commit fc0928a2 by 李洋

update api

parent 6da550cc
...@@ -29,57 +29,201 @@ class MessageApiController extends Controller ...@@ -29,57 +29,201 @@ class MessageApiController extends Controller
private function addTemplate($request) private function addTemplate($request)
{ {
$data = $request->input(); $data = $request->input();
$insert_tpl_id = $data['tpl_id'];
//要保证是一个事务!
//至少选择一个渠道 //至少选择一个渠道
if(empty($data['channels'])) if(empty($data['channels']))
{ {
$this->Export(11001,'请选择渠道'); $this->Export(11001,'请勾选至少一个消息渠道');
}else{ }
if(empty($data['description']))
{
$this->Export(11002,'请输入模板描述');
}
//消息模板模型
$db=DB::connection('message')->table('lie_msg_tpl');
$tpl_model = [];
$tpl_model['tpl_id'] = $data['tpl_id'];
$tpl_model['channels'] = $data['channels'];
$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['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->insertGetId($tpl_model);
if(!$insert_tpl_id)
{
$this->Export(11020, '新增消息模板失败');
}
}else
{
$tpl_model['update_time'] = time();
$result = $db->where('tpl_id',$tpl_model['tpl_id'])->update($tpl_model);
$insert_tpl_id = $tpl_model['tpl_id'];
if(!$result)
{
$this->Export(11021, '编辑消息模板失败');
}
}
//每一个渠道模板 的验证与写数据库
$db=DB::connection('message')->table('lie_msg_channel_tpl');
//选了站内信渠道 就要选站内信类型 //选了站内信渠道 就要选站内信类型
if(strpos($data['channels'],'1')) if(strpos($data['channels'],'1')!==false)
{ {
if(empty($data['msg_type'])) if(empty($data['msg_type']))
{ {
$this->Export(11001,'请选择选择站内信类型'); $this->Export(11003,'请选择站内信类型');
} }
if(empty($data['inner_title']))
{
$this->Export(11004,'请填写站内信标题');
} }
if(empty($data['inner_content']))
{
$this->Export(11005,'请填写站内信内容');
} }
if(empty($data['op_type']))
{
$input_model = []; $this->Export(11006,'请选择点击消息操作');
$input_model['brand_id']=$data['brand_id'];
$input_model['brand_name']=$data['brand_name'];
$input_model['brand_logo']=$data['brand_logo'];
$input_model['brand_desc']=$data['brand_desc'];
$input_model['status']=$data['status'];
$input_model['main_product']=$data['main_product'];
$input_model['brand_brief']=$data['brand_brief'];
if(isset($data['brand_area']))
{
$input_model['brand_area']=$data['brand_area'];
} }
if(empty($data['url']) && $data['op_type']==2)
$db=DB::connection('spu')->table('lie_brand'); {
if(!empty($input_model['brand_id'])){ $this->Export(11007,'请填写要打开的url');
$resurt=$db->where('brand_id',$input_model['brand_id'])->update($input_model);
if(!$resurt) {
$this->Export(11011, '修改制造商失败', 'sql');
} }
$chn_tpl_model_inner = [];
}else{ $chn_tpl_model_inner['channel_tpl_id'] = $data['inner_channel_tpl_id'];
$find=DB::connection('spu')->table('lie_brand')->where('brand_name',$input_model['brand_name'])->first(); $chn_tpl_model_inner['channel_type'] = $data['inner_channel_type'];
if($find){ $chn_tpl_model_inner['title'] = $data['inner_title'];
$this->Export(11012, '当前品牌名字已经存在', 'brand_name'); $chn_tpl_model_inner['content'] = $data['inner_content'];
$chn_tpl_model_inner['op_type'] = $data['op_type'];
$chn_tpl_model_inner['tpl_id'] = $insert_tpl_id;
if($data['op_type']==2)
{
$chn_tpl_model_inner['url'] = $data['url'];
}
if(empty($chn_tpl_model_inner['channel_tpl_id']))
{
$chn_tpl_model_inner['create_time'] = time();
$chn_tpl_model_inner['update_time'] = time();
$result = $db->insert($chn_tpl_model_inner);
if(!$result)
{
$this->Export(11008, '新增消息模板失败');
}
}else
{
$chn_tpl_model_inner['update_time'] = time();
$result = $db->where('channel_tpl_id',$chn_tpl_model_inner['channel_tpl_id'])->update($chn_tpl_model_inner);
if(!$result)
{
$this->Export(11009, '编辑消息模板失败');
}
}
}
if(strpos($data['channels'],'2')!==false)
{
if(empty($data['sms_content']))
{
$this->Export(11010,'请填写短信内容');
}
$chn_tpl_model_sms = [];
$chn_tpl_model_sms['channel_tpl_id'] = $data['sms_channel_tpl_id'];
$chn_tpl_model_sms['channel_type'] = $data['sms_channel_type'];
$chn_tpl_model_sms['content'] = $data['sms_content'];
$chn_tpl_model_sms['tpl_id'] = $insert_tpl_id;
if(empty($chn_tpl_model_sms['channel_tpl_id']))
{
$chn_tpl_model_sms['create_time'] = time();
$chn_tpl_model_sms['update_time'] = time();
$result = $db->insert($chn_tpl_model_sms);
if(!$result)
{
$this->Export(11011, '新增消息模板失败');
}
}else
{
$chn_tpl_model_sms['update_time'] = time();
$result = $db->where('channel_tpl_id',$chn_tpl_model_sms['channel_tpl_id'])->update($chn_tpl_model_sms);
if(!$result)
{
$this->Export(11012, '编辑消息模板失败');
}
}
}
if(strpos($data['channels'],'3')!==false)
{
if(empty($data['email_title']))
{
$this->Export(11013,'请填写邮件标题');
}
if(empty($data['email_content']))
{
$this->Export(11014,'请填写邮件内容');
}
$chn_tpl_model_email = [];
$chn_tpl_model_email['channel_tpl_id'] = $data['email_channel_tpl_id'];
$chn_tpl_model_email['channel_type'] = $data['email_channel_type'];
$chn_tpl_model_email['title'] = $data['email_title'];
$chn_tpl_model_email['content'] = $data['email_content'];
$chn_tpl_model_email['tpl_id'] = $insert_tpl_id;
if(empty($chn_tpl_model_email['channel_tpl_id']))
{
$chn_tpl_model_email['create_time'] = time();
$chn_tpl_model_email['update_time'] = time();
$result = $db->insert($chn_tpl_model_email);
if(!$result)
{
$this->Export(11015, '新增消息模板失败');
}
}else
{
$chn_tpl_model_email['update_time'] = time();
$result = $db->where('channel_tpl_id',$chn_tpl_model_email['channel_tpl_id'])->update($chn_tpl_model_email);
if(!$result)
{
$this->Export(11016, '编辑消息模板失败');
}
}
}
if(strpos($data['channels'],'4')!==false)
{
if(empty($data['wechat_notify_title']))
{
$this->Export(11017,'请填写微信模板编号');
}
$chn_tpl_model_wechatnotify = [];
$chn_tpl_model_wechatnotify['channel_tpl_id'] = $data['wechat_notify_tpl_id'];
$chn_tpl_model_wechatnotify['channel_type'] = $data['wechat_notify_channel_type'];
$chn_tpl_model_wechatnotify['title'] = $data['wechat_notify_title'];
$chn_tpl_model_wechatnotify['tpl_id'] = $insert_tpl_id;
if(empty($chn_tpl_model_wechatnotify['channel_tpl_id']))
{
$chn_tpl_model_wechatnotify['create_time'] = time();
$chn_tpl_model_wechatnotify['update_time'] = time();
$result = $db->insert($chn_tpl_model_wechatnotify);
if(!$result)
{
$this->Export(11018, '新增消息模板失败');
}
}else
{
$chn_tpl_model_wechatnotify['update_time'] = time();
$result = $db->where('channel_tpl_id',$chn_tpl_model_wechatnotify['channel_tpl_id'])->update($chn_tpl_model_wechatnotify);
if(!$result)
{
$this->Export(11019, '编辑消息模板失败');
} }
$input_model['create_time']=time();
$resurt=$db->insert($input_model);
if(!$resurt) {
$this->Export(11013, '新增制造商失败', 'sql');
} }
} }
$this->Export(0,empty($input_model['brand_id'])? '新增成功':'修改成功'); $this->Export(0,empty($tpl_model['tpl_id'])? '新增成功':'修改成功');
} }
//编辑手动消息 //编辑手动消息
......
...@@ -395,15 +395,21 @@ class MessageController extends Controller ...@@ -395,15 +395,21 @@ class MessageController extends Controller
Csrf($request); Csrf($request);
$rq_tpl_id = $request->input('tpl_id'); $rq_tpl_id = $request->input('tpl_id');
$db = DB::connection('message'); $db = DB::connection('message');
//是否包含某一渠道
$isContainInner = ''; $isContainInner = '';
$isContainSMS = ''; $isContainSMS = '';
$isContainEmail = ''; $isContainEmail = '';
$isContainWechatNotify = ''; $isContainWechatNotify = '';
//渠道模板id
$inner_chn_tpl_id = '';
$sms_chn_tpl_id = '';
$email_chn_tpl_id = '';
$wechatNotify_chn_tpl_id = '';
if(!empty($rq_tpl_id)) if(!empty($rq_tpl_id))
{ {
//通过tpl_id找到模板的渠道们 和 描述等 //通过tpl_id找到模板的渠道们 和 描述等
$info = $db->table('lie_msg_tpl')->select('tpl_id','description','channels','msg_type')->where('tpl_id',$rq_tpl_id)->first(); $info = $db->table('lie_msg_tpl')->select('tpl_id','description','channels','msg_type','creater')->where('tpl_id',$rq_tpl_id)->first();
//通过找到的 channels 去渠道模板表里 把每个channel找出来 //通过找到的 channels 去渠道模板表里 把每个channel找出来
$tpl_channels_arr = explode(',',$info->channels); $tpl_channels_arr = explode(',',$info->channels);
...@@ -412,6 +418,20 @@ class MessageController extends Controller ...@@ -412,6 +418,20 @@ class MessageController extends Controller
{ {
$channel_tpl_obj = $db->table('lie_msg_channel_tpl')->where('tpl_id',$info->tpl_id)->where('channel_type',$channel_type)->first(); $channel_tpl_obj = $db->table('lie_msg_channel_tpl')->where('tpl_id',$info->tpl_id)->where('channel_type',$channel_type)->first();
$channel_tpls[$channel_type] = $channel_tpl_obj; $channel_tpls[$channel_type] = $channel_tpl_obj;
//将channel_tpl_id赋给正确的变量中
if($channel_type==1)
{
$inner_chn_tpl_id = $channel_tpl_obj->channel_tpl_id;
}elseif($channel_type==2)
{
$sms_chn_tpl_id = $channel_tpl_obj->channel_tpl_id;
}elseif($channel_type==3)
{
$email_chn_tpl_id = $channel_tpl_obj->channel_tpl_id;
}elseif($channel_type==4)
{
$wechatNotify_chn_tpl_id = $channel_tpl_obj->channel_tpl_id;
}
} }
$info->channel_tpls = $channel_tpls; $info->channel_tpls = $channel_tpls;
...@@ -430,6 +450,7 @@ class MessageController extends Controller ...@@ -430,6 +450,7 @@ class MessageController extends Controller
$info->channels =''; $info->channels ='';
$info->channel_tpls = []; $info->channel_tpls = [];
$info->msg_type = ''; $info->msg_type = '';
$info->creater = '';
} }
//消息类型枚举 //消息类型枚举
...@@ -450,6 +471,10 @@ class MessageController extends Controller ...@@ -450,6 +471,10 @@ class MessageController extends Controller
'isContainSMS'=>$isContainSMS, 'isContainSMS'=>$isContainSMS,
'isContainEmail'=>$isContainEmail, 'isContainEmail'=>$isContainEmail,
'isContainWechatNotify'=>$isContainWechatNotify, 'isContainWechatNotify'=>$isContainWechatNotify,
'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,
]; ];
return view($viewid, $data); return view($viewid, $data);
......
...@@ -83,31 +83,46 @@ $('#msg_tpl_submit').click(function() ...@@ -83,31 +83,46 @@ $('#msg_tpl_submit').click(function()
} }
} }
addTemplate();
// addTemplate();
}) })
function addTemplate() function addTemplate()
{ {
var ue_inner = UE.getEditor('inner-tpl-content');
var ue_email = UE.getEditor('email-tpl-content');
$.ajax({ $.ajax({
type: 'post', type: 'post',
url: '/msgapi/addTemplate', url: '/msgapi/addTemplate',
timeout : 10000, //超时时间设置,单位毫秒 timeout : 10000, //超时时间设置,单位毫秒
data: { data: {
tpl_id:$('#spu_id').val(), tpl_id:$('#tpl-id').val(),
channels:$('#class_id1').val(), channels:getChosenMsgChannels(),
msg_type:$('#class_id2').val(), msg_type:$('#inner-tpl-type option:selected').val(),
source_type:$('#class_id3').val(), source_type:1,
creater:$('#brand_id').val(), creater:$('#creater').val(),
obj_user:$('#spu_name').val(), description:$('#msg-tpl-desc').val(),
description:$("input[name='status']:checked").val(),
inner_channel_tpl_id:$('#inner-chn-tpl-id').val(),
channel_tpl_id:$('#images_l').val(), inner_channel_type:1,
channel_type:$('#images_s').val(), inner_title:$('#inner-tpl-title').val(),
title:$('#encap').val(), inner_content:ue_inner.getContent(),
content:$('#pdf').val(), op_type:$("input[name='inner-tpl-op']:checked").val(),
op_type:$('#spu_brief').val(), url:$('#inner-tpl-op-url-text').val(),
url:$("input[name='has_rohs']:checked").val(),
sms_channel_tpl_id:$('#sms-chn-tpl-id').val(),
sms_channel_type:2,
sms_content:$('#sms-tpl-content').val(),
email_channel_tpl_id:$('#email-chn-tpl-id').val(),
email_channel_type:3,
email_title:$('#email-tpl-title').val(),
email_content:ue_email.getContent(),
wechat_notify_tpl_id:$('#wechatnotify-chn-tpl-id').val(),
wechat_notify_channel_type:4,
wechat_notify_title:$('#wechat-notify_tpl_title').val(),//存放的是微信模板的id
}, },
dataType: 'json', dataType: 'json',
success: function(resp){ success: function(resp){
......
...@@ -77,8 +77,8 @@ $('#msg_tpl_submit').click(function() ...@@ -77,8 +77,8 @@ $('#msg_tpl_submit').click(function()
Prompt('请填写邮件标题', 5); Prompt('请填写邮件标题', 5);
return false; return false;
} }
var ue = UE.getEditor('email-tpl-content'); var uee = UE.getEditor('email-tpl-content');
if(!ue.getContent()) if(!uee.getContent())
{ {
Prompt('请填写邮件内容', 5); Prompt('请填写邮件内容', 5);
return false; return false;
......
...@@ -104,6 +104,9 @@ ...@@ -104,6 +104,9 @@
{{--外部统一模板描述+消息渠道提示--}} {{--外部统一模板描述+消息渠道提示--}}
<div style="margin-left: 40px;"> <div style="margin-left: 40px;">
{{--模板iD和创建人--}}
<input id="tpl-id" type="hidden" value="{{ $info->tpl_id }}">
<input id="creater" type="hidden" value="{{ $info->creater }}">
<div class="col-sm-10 form-inline" style="margin-top: 20px"> <div class="col-sm-10 form-inline" style="margin-top: 20px">
<label class="col-sm-2 control-label" id="msg-tpl-channels"><span style="color: red">*</span> 消息渠道:</label> <label class="col-sm-2 control-label" id="msg-tpl-channels"><span style="color: red">*</span> 消息渠道:</label>
<div class="col-sm-4"> <div class="col-sm-4">
...@@ -161,7 +164,7 @@ ...@@ -161,7 +164,7 @@
<div class="tab-content tabs"> <div class="tab-content tabs">
{{--站内信--}} {{--站内信--}}
<div role="tabpanel" class="tab-pane fade in active" id="innner"> <div role="tabpanel" class="tab-pane fade in active" id="innner">
<input type="hidden" id="inner-chn-tpl-id" value="{{ $inner_chn_tpl_id }}">
<div class="col-sm-10 form-inline" style="margin-top: 40px"> <div class="col-sm-10 form-inline" style="margin-top: 40px">
<label class="col-sm-2 control-label"><span style="color: red">*</span> 站内信类型:</label> <label class="col-sm-2 control-label"><span style="color: red">*</span> 站内信类型:</label>
<div class="col-sm-3"> <div class="col-sm-3">
...@@ -182,7 +185,7 @@ ...@@ -182,7 +185,7 @@
<div class="col-sm-10" style="margin-top: 20px"> <div class="col-sm-10" style="margin-top: 20px">
<label><span style="color: red">*</span>站内信内容:</label> <label><span style="color: red">*</span>站内信内容:</label>
<script type="text/plain" id="inner-tpl-content" name="inner-tpl-content">@if(!empty($info->channel_tpls['1']->content)) {{ $info->channel_tpls['1']->content }} @endif</script> <script type="text/plain" id="inner-tpl-content" name="inner-tpl-content">@if(!empty($info->channel_tpls['1']->content)) {!! $info->channel_tpls['1']->content !!} @endif</script>
<script type="text/javascript">UE.getEditor('inner-tpl-content');</script> <script type="text/javascript">UE.getEditor('inner-tpl-content');</script>
</div> </div>
...@@ -199,6 +202,7 @@ ...@@ -199,6 +202,7 @@
{{--短信--}} {{--短信--}}
<div role="tabpanel" class="tab-pane fade" id="sms"> <div role="tabpanel" class="tab-pane fade" id="sms">
<input type="hidden" id="sms-chn-tpl-id" value="{{ $sms_chn_tpl_id }}">
<div class="col-sm-10" style="margin-top: 40px"> <div class="col-sm-10" style="margin-top: 40px">
<label class="col-sm-2 control-label"><span style="color: red">*</span> 短信内容:</label> <label class="col-sm-2 control-label"><span style="color: red">*</span> 短信内容:</label>
<div class="col-sm-10"> <div class="col-sm-10">
...@@ -210,6 +214,7 @@ ...@@ -210,6 +214,7 @@
{{--邮件--}} {{--邮件--}}
<div role="tabpanel" class="tab-pane fade" id="email"> <div role="tabpanel" class="tab-pane fade" id="email">
<input type="hidden" id="email-chn-tpl-id" value="{{ $email_chn_tpl_id }}">
<div class="col-sm-10 form-inline" style="margin-top: 40px"> <div class="col-sm-10 form-inline" style="margin-top: 40px">
<label class="col-sm-2 control-label"><span style="color: red">*</span> 邮件标题:</label> <label class="col-sm-2 control-label"><span style="color: red">*</span> 邮件标题:</label>
<div class="col-sm-3"> <div class="col-sm-3">
...@@ -219,13 +224,14 @@ ...@@ -219,13 +224,14 @@
<div class="col-sm-10" style="margin-top: 20px"> <div class="col-sm-10" style="margin-top: 20px">
<label><span style="color: red">*</span>邮件内容:</label> <label><span style="color: red">*</span>邮件内容:</label>
<script type="text/plain" id="email-tpl-content" name="email-tpl-content">@if(!empty($info->channel_tpls['3']->content)) {{ $info->channel_tpls['3']->content }} @endif</script> <script type="text/plain" id="email-tpl-content" name="email-tpl-content">@if(!empty($info->channel_tpls['3']->content)) {!! $info->channel_tpls['3']->content !!} @endif</script>
<script type="text/javascript">UE.getEditor('email-tpl-content');</script> <script type="text/javascript">UE.getEditor('email-tpl-content');</script>
</div> </div>
</div> </div>
{{--微信通知--}} {{--微信通知--}}
<div role="tabpanel" class="tab-pane fade" id="wechat-notify"> <div role="tabpanel" class="tab-pane fade" id="wechat-notify">
<input type="hidden" id="wechatnotify-chn-tpl-id" value="{{ $wechatNotify_chn_tpl_id }}">
<div class="col-sm-10 form-inline" style="margin-top: 40px"> <div class="col-sm-10 form-inline" style="margin-top: 40px">
<label class="col-sm-2 control-label"><span style="color: red">*</span> 微信模板:</label> <label class="col-sm-2 control-label"><span style="color: red">*</span> 微信模板:</label>
<div class="col-sm-3"> <div class="col-sm-3">
......
...@@ -196,7 +196,7 @@ ...@@ -196,7 +196,7 @@
<div class="col-sm-10" style="margin-top: 20px"> <div class="col-sm-10" style="margin-top: 20px">
<label><span style="color: red">*</span>站内信内容:</label> <label><span style="color: red">*</span>站内信内容:</label>
<script type="text/plain" id="inner-tpl-content" name="inner-tpl-content">@if(!empty($info->channel_tpls['1']->content)) {{ $info->channel_tpls['1']->content }} @endif</script> <script type="text/plain" id="inner-tpl-content" name="inner-tpl-content">@if(!empty($info->channel_tpls['1']->content)) {!! $info->channel_tpls['1']->content !!} @endif</script>
<script type="text/javascript">UE.getEditor('inner-tpl-content');</script> <script type="text/javascript">UE.getEditor('inner-tpl-content');</script>
</div> </div>
...@@ -233,7 +233,7 @@ ...@@ -233,7 +233,7 @@
<div class="col-sm-10" style="margin-top: 20px"> <div class="col-sm-10" style="margin-top: 20px">
<label><span style="color: red">*</span>邮件内容:</label> <label><span style="color: red">*</span>邮件内容:</label>
<script type="text/plain" id="email-tpl-content" name="email-tpl-content">@if(!empty($info->channel_tpls['3']->content)) {{ $info->channel_tpls['3']->content }} @endif</script> <script type="text/plain" id="email-tpl-content" name="email-tpl-content">@if(!empty($info->channel_tpls['3']->content)) {!! $info->channel_tpls['3']->content !!} @endif</script>
<script type="text/javascript">UE.getEditor('email-tpl-content');</script> <script type="text/javascript">UE.getEditor('email-tpl-content');</script>
</div> </div>
</div> </div>
......
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