Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
李洋
/
消息系统
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9438ddbd
authored
Apr 18, 2019
by
李洋
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
添加 新增/编辑 消息模板分类功能
parent
21e6707a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
287 additions
and
4 deletions
app/Http/Controllers/MessageApiController.php
app/Http/Controllers/MessageController.php
public/js/Message/addclassify.js
public/js/Message/templatelist.js
resources/views/message/addclassify.blade.php
resources/views/message/templatelist.blade.php
app/Http/Controllers/MessageApiController.php
View file @
9438ddbd
...
...
@@ -372,7 +372,7 @@ class MessageApiController extends Controller
$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
]);
...
...
@@ -380,4 +380,79 @@ class MessageApiController extends Controller
$this
->
Export
(
0
,
'success'
);
}
}
//编辑分类
private
function
editClassify
(
$request
){
$in_data
=
$request
->
input
(
'field'
);
//验证数据合理性
$this
->
verifyClassifyData
(
$in_data
);
//去字符串空格
if
(
!
empty
(
$in_data
)){
foreach
(
$in_data
as
&
$d
){
$d
=
trim
(
$d
);
}
unset
(
$d
);
}
//数据库操作
$db
=
DB
::
connection
(
'message'
);
if
(
1
==
$in_data
[
'edit_type'
]){
if
(
!
empty
(
$in_data
[
'add_classify'
])){
$res
=
$db
->
table
(
'lie_msg_tpl_classify'
)
->
insertGetId
([
'cls_name'
=>
$in_data
[
'add_classify'
]]);
if
(
!
$res
){
$this
->
Export
(
11100
,
'新增分类失败'
);
}
}
if
(
!
empty
(
$in_data
[
'add_sub_classify'
])
&&
!
empty
(
$in_data
[
'sel_add_classify'
])){
$res
=
$db
->
table
(
'lie_msg_tpl_sub_classify'
)
->
insertGetId
([
'cls_id'
=>
$in_data
[
'sel_add_classify'
],
'sub_cls_name'
=>
$in_data
[
'add_sub_classify'
]
]);
if
(
!
$res
){
$this
->
Export
(
11101
,
'新增子分类失败'
);
}
}
}
else
{
if
(
!
empty
(
$in_data
[
'sel_edit_classify_1st'
])
&&
!
empty
(
$in_data
[
'edit_classify'
])){
$res
=
$db
->
table
(
'lie_msg_tpl_classify'
)
->
where
(
'cls_id'
,
$in_data
[
'sel_edit_classify_1st'
])
->
update
([
'cls_name'
=>
$in_data
[
'edit_classify'
]]);
if
(
!
$res
&&
0
!==
$res
){
$this
->
Export
(
11102
,
'更新分类失败'
);
}
}
if
(
!
empty
(
$in_data
[
'sel_edit_classify_2nd'
])
&&
!
empty
(
$in_data
[
'sel_edit_sub_classify'
])
&&
!
empty
(
$in_data
[
'edit_sub_classify'
])){
$res
=
$db
->
table
(
'lie_msg_tpl_sub_classify'
)
->
where
(
'sub_cls_id'
,
$in_data
[
'sel_edit_sub_classify'
])
->
where
(
'cls_id'
,
$in_data
[
'sel_edit_classify_2nd'
])
->
update
([
'sub_cls_name'
=>
$in_data
[
'edit_sub_classify'
]]);
if
(
!
$res
&&
0
!==
$res
){
$this
->
Export
(
11103
,
'更新子分类失败'
);
}
}
}
$this
->
Export
(
0
,
'操作成功'
);
}
//验证修改分类数据的合理性
private
function
verifyClassifyData
(
$in_data
){
if
(
1
==
$in_data
[
'edit_type'
]){
if
(
empty
(
$in_data
[
'add_classify'
])
&&
empty
(
$in_data
[
'add_sub_classify'
])){
$this
->
Export
(
11104
,
'请填写要添加的分类或子分类'
);
}
if
(
!
empty
(
$in_data
[
'add_sub_classify'
])
&&
empty
(
$in_data
[
'sel_add_classify'
])){
$this
->
Export
(
11105
,
'请选择要添加的子分类的上级分类'
);
}
}
else
{
if
(
empty
(
$in_data
[
'edit_classify'
])
&&
empty
(
$in_data
[
'edit_sub_classify'
])){
$this
->
Export
(
11106
,
'请填写要编辑的分类或子分类'
);
}
if
(
!
empty
(
$in_data
[
'edit_classify'
])
&&
empty
(
$in_data
[
'sel_edit_classify_1st'
])){
$this
->
Export
(
11107
,
'请选择要编辑的分类'
);
}
if
(
!
empty
(
$in_data
[
'edit_sub_classify'
])
&&
(
empty
(
$in_data
[
'sel_edit_classify_2nd'
])
||
empty
(
$in_data
[
'sel_edit_sub_classify'
]))){
$this
->
Export
(
11108
,
'请选择要编辑的子分类及其上级分类'
);
}
}
}
}
\ No newline at end of file
app/Http/Controllers/MessageController.php
View file @
9438ddbd
...
...
@@ -588,7 +588,25 @@ class MessageController extends Controller
return
view
(
$viewid
,
$data
);
}
//添加分类
private
function
addclassify
(
Request
$request
,
$id
,
$viewId
){
$info
=
[];
$db
=
DB
::
connection
(
'message'
);
$infos
=
$db
->
table
(
'lie_msg_tpl_classify'
)
->
select
(
'cls_id'
,
'cls_name'
)
->
get
();
if
(
!
empty
(
$infos
)){
foreach
(
$infos
as
&
$in
){
$in
=
objectToArray
(
$in
);
$info
[
$in
[
'cls_id'
]]
=
$in
[
'cls_name'
];
}
unset
(
$in
);
}
$data
=
[
'title'
=>
'asd'
,
'id'
=>
$id
,
'info'
=>
$info
];
return
view
(
$viewId
,
$data
);
}
//--------------------------------------------inner methods-----------------------------------------
...
...
public/js/Message/addclassify.js
0 → 100644
View file @
9438ddbd
layui
.
use
(
'form'
,
function
(){
var
form
=
layui
.
form
;
//类型选择
form
.
on
(
'radio(edit_type)'
,
function
(
data
)
{
showOrHide
(
data
.
value
);
});
// form.on('select(sel_add_classify)', function (data) {
// console.log(data.value);
// });
// form.on('select(sel_edit_classify)', function (data) {
// console.log(data.value);
// });
// form.on('select(sel_edit_sub_classify)', function (data) {
// console.log(data.value);
// });
//监听模板分类选择 并刷新二级分类数据
form
.
on
(
'select(sel_edit_classify_2nd)'
,
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>"
;
});
$
(
"#sel_edit_sub_classify"
).
html
(
'<option value=""></option>'
+
optionstring
);
form
.
render
(
'select'
);
}
});
});
//监听表单提交按钮
form
.
on
(
'submit(submit)'
,
function
(
data
){
editClassify
(
data
.
field
);
});
form
.
render
();
});
function
showOrHide
(
type
){
if
(
'1'
===
type
){
$
(
'#add_classify_div'
).
show
();
$
(
'#add_sub_classify_div'
).
show
();
$
(
'#edit_classify_div'
).
hide
();
$
(
'#edit_sub_classify_div'
).
hide
();
}
else
{
$
(
'#add_classify_div'
).
hide
();
$
(
'#add_sub_classify_div'
).
hide
();
$
(
'#edit_classify_div'
).
show
();
$
(
'#edit_sub_classify_div'
).
show
();
}
}
function
editClassify
(
field
){
$
.
ajax
({
url
:
"/msgapi/editClassify"
,
dataType
:
'json'
,
data
:
{
field
:
field
},
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
public/js/Message/templatelist.js
View file @
9438ddbd
...
...
@@ -106,4 +106,4 @@ function delTpl(tpl_id){
Prompt
(
"网络异常,请重试"
,
5
);
}
});
}
\ No newline at end of file
}
resources/views/message/addclassify.blade.php
0 → 100644
View file @
9438ddbd
<style>
label
{
box-sizing
:
content-box
;
}
.number-input
{
width
:
60px
;
}
.top-20
{
margin-top
:
30px
;
}
</style>
<div
class=
"layui-form"
>
<div
class=
"layui-form-item top-20"
>
<label
class=
"layui-form-label"
>
编辑类型:
</label>
<div
class=
"layui-input-block"
>
<input
type=
"radio"
name=
"edit_type"
lay-filter=
"edit_type"
value=
"1"
title=
"新增分类"
checked=
""
>
<input
type=
"radio"
name=
"edit_type"
lay-filter=
"edit_type"
value=
"2"
title=
"编辑分类"
>
</div>
</div>
<div
class=
"layui-form-item top-20"
id=
"add_classify_div"
>
<label
class=
"layui-form-label"
>
添加分类:
</label>
<div
class=
"layui-input-inline"
style=
"width: 200px;"
>
<input
type=
"text"
name=
"add_classify"
id=
"add_classify"
placeholder=
"请输入分类名称"
autocomplete=
"off"
class=
"layui-input"
>
</div>
</div>
<div
class=
"layui-form-item top-20"
id=
"add_sub_classify_div"
>
<label
class=
"layui-form-label"
>
添加子分类:
</label>
<div
class=
"layui-input-inline"
style=
"width: 150px"
>
<select
name=
"sel_add_classify"
lay-filter=
"sel_add_classify"
id=
"sel_add_classify"
>
<option
value=
""
>
请选择一级分类
</option>
@if(!empty($info))
@foreach($info as $k=>$v)
<option
value=
"{{ $k }}"
>
{{ $v }}
</option>
@endforeach
@endif
</select>
</div>
<div
class=
"layui-input-inline"
style=
"width: 200px;"
>
<input
type=
"text"
name=
"add_sub_classify"
id=
"add_sub_classify"
placeholder=
"请输入子分类名称"
autocomplete=
"off"
class=
"layui-input"
>
</div>
</div>
<div
class=
"layui-form-item top-20"
id=
"edit_classify_div"
hidden
>
<label
class=
"layui-form-label"
>
编辑分类:
</label>
<div
class=
"layui-input-inline"
style=
"width: 150px"
>
<select
name=
"sel_edit_classify_1st"
lay-filter=
"sel_edit_classify_1st"
id=
"sel_edit_classify_1st"
>
<option
value=
""
>
请选择一级分类
</option>
@if(!empty($info))
@foreach($info as $k=>$v)
<option
value=
"{{ $k }}"
>
{{ $v }}
</option>
@endforeach
@endif
</select>
</div>
<div
class=
"layui-input-inline"
style=
"width: 200px;"
>
<input
type=
"text"
name=
"edit_classify"
id=
"edit_classify"
placeholder=
"请输入分类名称"
autocomplete=
"off"
class=
"layui-input"
>
</div>
</div>
<div
class=
"layui-form-item top-20"
id=
"edit_sub_classify_div"
hidden
>
<label
class=
"layui-form-label"
>
编辑子分类:
</label>
<div
class=
"layui-input-inline"
style=
"width: 150px"
>
<select
name=
"sel_edit_classify_2nd"
lay-filter=
"sel_edit_classify_2nd"
id=
"sel_edit_classify_2nd"
>
<option
value=
""
>
请选择一级分类
</option>
@if(!empty($info))
@foreach($info as $k=>$v)
<option
value=
"{{ $k }}"
>
{{ $v }}
</option>
@endforeach
@endif
</select>
</div>
<div
class=
"layui-input-inline"
style=
"width: 150px"
>
<select
name=
"sel_edit_sub_classify"
lay-filter=
"sel_edit_sub_classify"
id=
"sel_edit_sub_classify"
>
<option
value=
""
>
请选择子分类
</option>
</select>
</div>
<div
class=
"layui-input-inline"
style=
"width: 200px;"
>
<input
type=
"text"
name=
"edit_sub_classify"
id=
"edit_sub_classify"
placeholder=
"请输入子分类名称"
autocomplete=
"off"
class=
"layui-input"
>
</div>
</div>
<div>
<div
class=
"layui-input-inline"
style=
"margin-top: 20px; margin-left: 200px;"
>
<button
class=
"layui-btn"
lay-submit
lay-filter=
"submit"
data-type=
"*"
>
提交
</button>
</div>
</div>
</div>
resources/views/message/templatelist.blade.php
View file @
9438ddbd
...
...
@@ -63,6 +63,8 @@
</div>
</form>
<a
class=
"layui-btn"
id=
"add_classify"
href=
"/message/addclassify"
>
添加模板分类
</a>
{{--
<button
id=
"reload_table"
hidden
></button>
--}}
<table
class=
"layui-hide"
id=
"table"
lay-filter=
"table"
></table>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment