Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
token
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wallet
token
Commits
73749bb9
Commit
73749bb9
authored
Oct 17, 2018
by
ZhuChunYang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
79f8ca6d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
243 additions
and
6 deletions
+243
-6
ApplicationController.php
backend/controllers/ApplicationController.php
+34
-3
CoinApplicationForm.php
backend/models/coin/CoinApplicationForm.php
+41
-0
image-index.php
backend/views/application/image-index.php
+152
-0
list.php
backend/views/application/list.php
+0
-3
CoinImage.php
common/models/psources/CoinImage.php
+16
-0
No files found.
backend/controllers/ApplicationController.php
View file @
73749bb9
...
@@ -137,15 +137,18 @@ class ApplicationController extends BaseController
...
@@ -137,15 +137,18 @@ class ApplicationController extends BaseController
if
(
Yii
::
$app
->
request
->
isAjax
){
if
(
Yii
::
$app
->
request
->
isAjax
){
$id
=
Yii
::
$app
->
request
->
get
(
'id'
);
$id
=
Yii
::
$app
->
request
->
get
(
'id'
);
Yii
::
$app
->
response
->
format
=
'json'
;
Yii
::
$app
->
response
->
format
=
'json'
;
$request
=
Yii
::
$app
->
request
;
$applicate
=
CoinApplication
::
getApplicate
(
$id
);
$data
=
[];
if
(
$applicate
){
$data
=
CoinImage
::
getItemsByImageIds
(
$applicate
->
image_ids
);
}
else
{
$data
=
[
'code'
=>
0
,
'data'
=>
[]];
}
return
$data
;
return
$data
;
}
else
{
}
else
{
$id
=
Yii
::
$app
->
request
->
get
(
'id'
);
$id
=
Yii
::
$app
->
request
->
get
(
'id'
);
if
(
$id
){
if
(
$id
){
$applicate
=
CoinApplication
::
getApplicate
(
$id
);
$applicate
=
CoinApplication
::
getApplicate
(
$id
);
if
(
$applicate
){
if
(
$applicate
){
$this
->
layout
=
false
;
return
$this
->
render
(
'image-index'
,[
'applicate'
=>
$applicate
]);
return
$this
->
render
(
'image-index'
,[
'applicate'
=>
$applicate
]);
}
else
{
}
else
{
$this
->
error
(
'id参数不合法'
,
Yii
::
$app
->
request
->
getReferrer
());
$this
->
error
(
'id参数不合法'
,
Yii
::
$app
->
request
->
getReferrer
());
...
@@ -157,4 +160,31 @@ class ApplicationController extends BaseController
...
@@ -157,4 +160,31 @@ class ApplicationController extends BaseController
}
}
}
}
public
function
actionAddImage
()
{
if
(
Yii
::
$app
->
request
->
isPost
){
Yii
::
$app
->
response
->
format
=
'json'
;
$id
=
Yii
::
$app
->
request
->
post
(
'applicate_id'
,
0
);
$image_id
=
Yii
::
$app
->
request
->
post
(
'image'
,
0
);
if
(
$id
&&
$image_id
){
$coin_applicate_form
=
new
CoinApplicationForm
();
return
$coin_applicate_form
->
addImage
(
$id
,
$image_id
);
}
else
{
return
[
'code'
=>
1
,
'msg'
=>
'图片添加失败'
];
}
}
}
public
function
actionDeleteImage
()
{
Yii
::
$app
->
response
->
format
=
'json'
;
$id
=
Yii
::
$app
->
request
->
get
(
'id'
);
$applicate_id
=
Yii
::
$app
->
request
->
get
(
'applicate_id'
);
if
(
$id
&&
$applicate_id
)
{
$coin_applicateion_form
=
new
CoinApplicationForm
();
return
$coin_applicateion_form
->
delImage
(
$id
,
$applicate_id
);
}
return
[
'code'
=>
1
,
'msg'
=>
'failed'
];
}
}
}
\ No newline at end of file
backend/models/coin/CoinApplicationForm.php
View file @
73749bb9
...
@@ -190,5 +190,45 @@ class CoinApplicationForm extends BaseForm
...
@@ -190,5 +190,45 @@ class CoinApplicationForm extends BaseForm
}
}
}
}
public
function
addImage
(
$id
,
$image_id
)
{
$coin_applicate
=
CoinApplication
::
getApplicate
(
$id
);
if
(
$coin_applicate
){
$image_ids
=
$coin_applicate
->
image_ids
;
if
(
$image_ids
){
$image_items
=
explode
(
','
,
$image_ids
);
array_push
(
$image_items
,
$image_id
);
$image_ids
=
implode
(
","
,
$image_items
);
}
else
{
$image_ids
=
$image_id
;
}
$coin_applicate
->
image_ids
=
$image_ids
;
$coin_applicate
->
save
();
return
[
'code'
=>
0
,
'msg'
=>
'图片添加成功'
];
}
else
{
return
[
'code'
=>
1
,
'msg'
=>
'应用不存在'
];
}
}
public
function
delImage
(
$image_id
,
$id
)
{
$coin_applicate
=
CoinApplication
::
getApplicate
(
$id
);
if
(
$coin_applicate
){
$image_ids
=
$coin_applicate
->
image_ids
;
$image_items
=
explode
(
','
,
$image_ids
);
$image_items
=
array_diff
(
$image_items
,[
$image_id
]);
if
(
$image_items
){
$image_ids
=
implode
(
","
,
$image_items
);
}
else
{
$image_ids
=
''
;
}
$coin_applicate
->
image_ids
=
$image_ids
;
$coin_applicate
->
save
();
return
[
'code'
=>
0
,
'msg'
=>
'图片删除成功'
];
}
else
{
return
[
'code'
=>
1
,
'msg'
=>
'应用不存在'
];
}
}
}
}
\ No newline at end of file
backend/views/application/image-index.php
View file @
73749bb9
...
@@ -5,3 +5,154 @@
...
@@ -5,3 +5,154 @@
* Date: 2018/10/17
* Date: 2018/10/17
* Time: 16:27
* Time: 16:27
*/
*/
?>
<style>
.layui-form-label
{
width
:
100px
;
}
</style>
<h4>
所属应用---
<?=
$applicate
->
name
?>
</h4>
<div
class=
"layui-row"
style=
"padding: 5px;"
>
<div
class=
"layui-col-md1"
>
<button
class=
"layui-btn layui-btn-default"
id=
"add"
>
添加应用图片
</button>
</div>
</div>
<div
class=
"layui-col-md10"
>
<table
class=
"layui-table"
id=
"table1"
lay-filter=
"table1"
></table>
</div>
<div
class=
"layui-row add"
style=
"display: none;padding: 5px;"
id=
"_form"
>
<div
class=
"layui-col-xs6 layui-col-sm6 layui-col-md11"
>
<form
class=
"layui-form"
action=
"javascript:void(0)"
id=
"form1"
method=
"post"
lay-filter=
"form1"
>
<input
type=
"hidden"
name=
"_csrf"
value=
"
<?=
Yii
::
$app
->
request
->
getCsrfToken
()
?>
"
>
<input
id=
"applicate_id"
name=
"applicate_id"
type=
"hidden"
value=
"
<?=
$applicate
->
id
?>
"
>
<div
class=
"layui-form-item"
>
<div
class=
"layui-inline"
>
<label
class=
"layui-form-label"
>
图标
</label>
<div
class=
"layui-input-block"
>
<img
src=
""
style=
"margin-top: 11px; max-width: 32px; max-height: 32px"
id=
"image1"
>
</div>
<input
type=
"hidden"
name=
"image"
value=
""
>
</div>
<div
class=
"layui-inline"
style=
"margin-left: 50px;"
>
<button
type=
"button"
class=
"layui-btn"
id=
"upload1"
style=
""
>
<i
class=
"layui-icon"
>

</i>
上传新图片
</button>
</div>
</div>
</form>
</div>
</div>
<script
type=
"text/html"
id=
"operationTpl"
>
<
a
class
=
"layui-btn layui-btn-danger layui-btn-xs"
lay
-
event
=
"del"
>
删除
<
/a>
</script>
<script
type=
"text/javascript"
>
var
form
=
layui
.
form
;
form
.
render
();
var
table
=
layui
.
table
;
var
applicate_id
=
$
(
"#applicate_id"
).
val
();
table
.
render
({
elem
:
'#table1'
,
url
:
'/admin/application/image-index?id='
+
applicate_id
,
cols
:
[[
{
field
:
'id'
,
title
:
'图片ID'
},
{
field
:
'image_url'
,
title
:
'图片链接'
,
templet
:
function
(
d
){
return
"<a href='"
+
d
.
image_url
+
"' target='_blank'>"
+
d
.
image_url
+
"</a>"
;
}
},
{
title
:
'操作'
,
templet
:
'#operationTpl'
,
width
:
300
},
]],
});
table
.
on
(
'tool(table1)'
,
function
(
obj
)
{
var
data
=
obj
.
data
;
var
event
=
obj
.
event
;
if
(
event
===
'del'
)
{
var
index
=
layer
.
confirm
(
"确认删除?"
,
{
icon
:
3
,
title
:
'删除'
},
function
()
{
$
.
get
(
'/admin/application/delete-image'
,
{
id
:
data
.
id
,
applicate_id
:
applicate_id
},
function
(
rev
)
{
layer
.
msg
(
rev
.
msg
);
if
(
0
==
rev
.
code
)
{
table
.
reload
(
'table1'
,{
page
:{
curr
:
1
}
});
}
});
});
}
});
$
(
'#add'
).
click
(
function
()
{
var
index
=
layer
.
open
({
title
:
'添加图片'
,
area
:
'800px'
,
type
:
1
,
content
:
$
(
"#_form"
),
btn
:
[
'保存'
,
'取消'
],
success
:
function
()
{
clearForm
();
},
btn1
:
function
()
{
$
.
post
(
'/admin/application/add-image'
,
$
(
"#form1"
).
serialize
(),
function
(
rev
)
{
layer
.
msg
(
rev
.
msg
);
if
(
0
==
rev
.
code
)
{
layer
.
close
(
index
);
$
(
"#_form"
).
css
(
'display'
,
'none'
);
table
.
reload
(
'table1'
,
{
page
:
{
curr
:
1
}
});
}
});
},
btn2
:
function
()
{
layer
.
close
(
index
);
clearForm
();
$
(
"#_form"
).
css
(
'display'
,
'none'
);
},
cancel
:
function
()
{
layer
.
close
(
index
);
clearForm
();
$
(
"#_form"
).
css
(
'display'
,
'none'
);
}
});
})
//图片上传
var
uploader
=
layui
.
upload
;
$_csrf
=
$
(
"input[name='_csrf']"
).
val
();
uploader
.
render
({
elem
:
"#upload1"
,
url
:
'/admin/image/upload'
,
data
:
{
_csrf
:
$_csrf
},
done
:
function
(
res
)
{
if
(
res
.
code
==
0
){
$
(
"input[name='image']"
).
val
(
res
.
data
.
image_id
);
$
(
"#image1"
).
attr
(
'src'
,
res
.
data
.
image_src
);
}
},
error
:
function
(
res
)
{
}
});
function
clearForm
(){
form
.
val
(
"form1"
,
{
image
:
''
,
});
$
(
"#image1"
).
attr
(
'src'
,
''
);
}
</script>
\ No newline at end of file
backend/views/application/list.php
View file @
73749bb9
...
@@ -222,6 +222,4 @@
...
@@ -222,6 +222,4 @@
});
});
}
}
});
});
</script>
</script>
\ No newline at end of file
common/models/psources/CoinImage.php
View file @
73749bb9
...
@@ -38,4 +38,19 @@ class CoinImage extends BaseActiveRecord
...
@@ -38,4 +38,19 @@ class CoinImage extends BaseActiveRecord
return
self
::
find
()
->
where
([
'id'
=>
$id
])
->
asArray
()
->
one
();
return
self
::
find
()
->
where
([
'id'
=>
$id
])
->
asArray
()
->
one
();
}
}
public
static
function
getItemsByImageIds
(
$image_ids
)
{
if
(
$image_ids
){
$idItems
=
explode
(
','
,
$image_ids
);
$data
=
self
::
find
()
->
where
([
'in'
,
'id'
,
$idItems
])
->
asArray
()
->
all
();
foreach
(
$data
as
&
$value
){
$value
[
'image_url'
]
=
$value
[
'base_url'
]
.
$value
[
'file_url'
];
}
return
[
'code'
=>
0
,
'data'
=>
$data
];
}
else
{
return
[
'code'
=>
0
,
'data'
=>
[]];
}
}
}
}
\ No newline at end of file
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