Commit ff1bf2cd by 李洋

修复更新模板问题

parent fc0928a2
Showing with 61 additions and 100 deletions
......@@ -30,19 +30,17 @@ class MessageApiController extends Controller
{
$data = $request->input();
$insert_tpl_id = $data['tpl_id'];
//要保证是一个事务!
//至少选择一个渠道
if(empty($data['channels']))
{
$this->Export(11001,'请勾选至少一个消息渠道');
if (empty($data['channels'])) {
$this->Export(11001, '请勾选至少一个消息渠道');
}
if(empty($data['description']))
{
$this->Export(11002,'请输入模板描述');
if (empty($data['description'])) {
$this->Export(11002, '请输入模板描述');
}
//消息模板模型
$db=DB::connection('message')->table('lie_msg_tpl');
$db = DB::connection('message')->table('lie_msg_tpl');
$tpl_model = [];
$tpl_model['tpl_id'] = $data['tpl_id'];
$tpl_model['channels'] = $data['channels'];
......@@ -51,51 +49,40 @@ class MessageApiController extends Controller
$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']))
{
//添加事务
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)
{
if (!$insert_tpl_id) {
$this->Export(11020, '新增消息模板失败');
}
}else
{
} else {
$tpl_model['update_time'] = time();
$result = $db->where('tpl_id',$tpl_model['tpl_id'])->update($tpl_model);
$result = $db->where('tpl_id', $tpl_model['tpl_id'])->update($tpl_model);
$insert_tpl_id = $tpl_model['tpl_id'];
if(!$result)
{
if (!$result) {
$this->Export(11021, '编辑消息模板失败');
}
}
//每一个渠道模板 的验证与写数据库
$db=DB::connection('message')->table('lie_msg_channel_tpl');
//选了站内信渠道 就要选站内信类型
if(strpos($data['channels'],'1')!==false)
{
if(empty($data['msg_type']))
{
$this->Export(11003,'请选择站内信类型');
if (strpos($data['channels'], '1') !== false) {
if (empty($data['msg_type'])) {
$this->Export(11003, '请选择站内信类型');
}
if(empty($data['inner_title']))
{
$this->Export(11004,'请填写站内信标题');
if (empty($data['inner_title'])) {
$this->Export(11004, '请填写站内信标题');
}
if(empty($data['inner_content']))
{
$this->Export(11005,'请填写站内信内容');
if (empty($data['inner_content'])) {
$this->Export(11005, '请填写站内信内容');
}
if(empty($data['op_type']))
{
$this->Export(11006,'请选择点击消息操作');
if (empty($data['op_type'])) {
$this->Export(11006, '请选择点击消息操作');
}
if(empty($data['url']) && $data['op_type']==2)
{
$this->Export(11007,'请填写要打开的url');
if (empty($data['url']) && $data['op_type'] == 2) {
$this->Export(11007, '请填写要打开的url');
}
$chn_tpl_model_inner = [];
$chn_tpl_model_inner['channel_tpl_id'] = $data['inner_channel_tpl_id'];
......@@ -104,68 +91,54 @@ class MessageApiController extends Controller
$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)
{
if ($data['op_type'] == 2) {
$chn_tpl_model_inner['url'] = $data['url'];
}
if(empty($chn_tpl_model_inner['channel_tpl_id']))
{
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)
{
$result = DB::connection('message')->table('lie_msg_channel_tpl')->insert($chn_tpl_model_inner);
if (!$result) {
$this->Export(11008, '新增消息模板失败');
}
}else
{
} 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)
{
$result = DB::connection('message')->table('lie_msg_channel_tpl')->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,'请填写短信内容');
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']))
{
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)
{
$result = DB::connection('message')->table('lie_msg_channel_tpl')->insert($chn_tpl_model_sms);
if (!$result) {
$this->Export(11011, '新增消息模板失败');
}
}else
{
} 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)
{
$result = DB::connection('message')->table('lie_msg_channel_tpl')->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 (strpos($data['channels'], '3') !== false) {
if (empty($data['email_title'])) {
$this->Export(11013, '请填写邮件标题');
}
if(empty($data['email_content']))
{
$this->Export(11014,'请填写邮件内容');
if (empty($data['email_content'])) {
$this->Export(11014, '请填写邮件内容');
}
$chn_tpl_model_email = [];
$chn_tpl_model_email['channel_tpl_id'] = $data['email_channel_tpl_id'];
......@@ -173,58 +146,46 @@ class MessageApiController extends Controller
$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']))
{
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)
{
$result = DB::connection('message')->table('lie_msg_channel_tpl')->insert($chn_tpl_model_email);
if (!$result) {
$this->Export(11015, '新增消息模板失败');
}
}else
{
} 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, '编辑消息模板失败');
$result = DB::connection('message')->table('lie_msg_channel_tpl')->where('channel_tpl_id', $chn_tpl_model_email['channel_tpl_id'])->update($chn_tpl_model_email);
if (!$result) {
$this->Export(11016, '编辑消息模板失败',$result);
}
}
}
if(strpos($data['channels'],'4')!==false)
{
if(empty($data['wechat_notify_title']))
{
$this->Export(11017,'请填写微信模板编号');
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']))
{
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)
{
$result = DB::connection('message')->table('lie_msg_channel_tpl')->insert($chn_tpl_model_wechatnotify);
if (!$result) {
$this->Export(11018, '新增消息模板失败');
}
}else
{
} 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)
{
$result = DB::connection('message')->table('lie_msg_channel_tpl')->where('channel_tpl_id', $chn_tpl_model_wechatnotify['channel_tpl_id'])->update($chn_tpl_model_wechatnotify);
if (!$result) {
$this->Export(11019, '编辑消息模板失败');
}
}
}
$this->Export(0,empty($tpl_model['tpl_id'])? '新增成功':'修改成功');
$this->Export(0, empty($tpl_model['tpl_id']) ? '新增成功' : '修改成功');
}
//编辑手动消息
//发送手动消息
......
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