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
5af5a281
Commit
5af5a281
authored
Nov 13, 2018
by
ZhuChunYang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
125b33b8
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
349 additions
and
1 deletion
+349
-1
ApplicationCategoryController.php
backend/controllers/ApplicationCategoryController.php
+58
-0
CoinApplicationCategoryForm.php
backend/models/coin/CoinApplicationCategoryForm.php
+59
-0
banner-index.php
backend/views/application-category/banner-index.php
+177
-0
index.php
backend/views/application-category/index.php
+3
-1
CoinBanner.php
common/models/psources/CoinBanner.php
+52
-0
No files found.
backend/controllers/ApplicationCategoryController.php
View file @
5af5a281
...
...
@@ -10,6 +10,7 @@ namespace backend\controllers;
use
backend\models\coin\CoinApplicationCategoryForm
;
use
common\models\psources\CoinApplicationCategory
;
use
common\models\psources\CoinBanner
;
use
Yii
;
...
...
@@ -94,4 +95,60 @@ class ApplicationCategoryController extends BaseController
}
}
public
function
actionBannerIndex
()
{
if
(
Yii
::
$app
->
request
->
isAjax
){
$id
=
Yii
::
$app
->
request
->
get
(
'id'
);
Yii
::
$app
->
response
->
format
=
'json'
;
$applicate_category
=
CoinApplicationCategory
::
getCategoryById
(
$id
);
if
(
$applicate_category
){
$data
=
CoinBanner
::
getBannerInfoByIds
(
$applicate_category
->
h5_banner
);
}
else
{
$data
=
[
'code'
=>
0
,
'data'
=>
[]];
}
return
$data
;
}
else
{
$id
=
Yii
::
$app
->
request
->
get
(
'id'
);
if
(
$id
){
$applicate_category
=
CoinApplicationCategory
::
getCategoryById
(
$id
);
if
(
$applicate_category
){
return
$this
->
render
(
'banner-index'
,[
'applicate_category'
=>
$applicate_category
]);
}
else
{
$this
->
error
(
'id参数不合法'
,
Yii
::
$app
->
request
->
getReferrer
());
}
}
else
{
$this
->
error
(
'id参数不能为空'
,
Yii
::
$app
->
request
->
getReferrer
());
}
}
}
public
function
actionAddBanner
()
{
if
(
Yii
::
$app
->
request
->
isPost
){
Yii
::
$app
->
response
->
format
=
'json'
;
$id
=
Yii
::
$app
->
request
->
post
(
'applicate_category_id'
,
0
);
$image_id
=
Yii
::
$app
->
request
->
post
(
'image'
,
0
);
$banner_url
=
Yii
::
$app
->
request
->
post
(
'banner_url'
,
0
);
if
(
$id
&&
$image_id
){
$coin_applicate_category_form
=
new
CoinApplicationCategoryForm
();
return
$coin_applicate_category_form
->
addBanner
(
$id
,
$image_id
,
$banner_url
);
}
else
{
return
[
'code'
=>
1
,
'msg'
=>
'banner添加失败'
];
}
}
}
public
function
actionDeleteBanner
()
{
Yii
::
$app
->
response
->
format
=
'json'
;
$id
=
Yii
::
$app
->
request
->
get
(
'id'
);
$applicate_category_id
=
Yii
::
$app
->
request
->
get
(
'applicate_category_id'
);
if
(
$id
&&
$applicate_category_id
)
{
$coin_applicateion_category_form
=
new
CoinApplicationCategoryForm
();
return
$coin_applicateion_category_form
->
delBanner
(
$id
,
$applicate_category_id
);
}
return
[
'code'
=>
1
,
'msg'
=>
'failed'
];
}
}
\ No newline at end of file
backend/models/coin/CoinApplicationCategoryForm.php
View file @
5af5a281
...
...
@@ -12,6 +12,7 @@ use backend\models\BaseForm;
use
common\models\psources\CoinAppCate
;
use
common\models\psources\CoinApplicateRecommend
;
use
common\models\psources\CoinApplicationCategory
;
use
common\models\psources\CoinBanner
;
class
CoinApplicationCategoryForm
extends
BaseForm
{
...
...
@@ -133,4 +134,61 @@ class CoinApplicationCategoryForm extends BaseForm
}
}
public
function
addBanner
(
$id
,
$image_id
,
$banner_url
)
{
$coin_applicate_category
=
CoinApplicationCategory
::
getCategoryById
(
$id
);
if
(
$coin_applicate_category
){
$tr
=
CoinApplicationCategory
::
getDb
()
->
beginTransaction
();
$coin_banner
=
new
CoinBanner
();
$coin_banner
->
image_id
=
$image_id
;
$coin_banner
->
banner_url
=
$banner_url
;
if
(
$coin_banner
->
save
()){
$banner_id
=
$coin_banner
->
id
;
$banner_ids
=
$coin_applicate_category
->
h5_banner
;
if
(
$banner_ids
){
$banner_items
=
explode
(
','
,
$banner_ids
);
array_push
(
$banner_items
,
$banner_id
);
$banner_ids
=
implode
(
","
,
$banner_items
);
}
else
{
$banner_ids
=
$banner_id
;
}
$coin_applicate_category
->
h5_banner
=
$banner_ids
;
$coin_applicate_category
->
save
();
$tr
->
commit
();
return
[
'code'
=>
0
,
'msg'
=>
'banner添加成功'
];
}
else
{
return
[
'code'
=>
0
,
'msg'
=>
'banner添加失败'
];
}
}
else
{
return
[
'code'
=>
1
,
'msg'
=>
'应用分类不存在'
];
}
}
public
function
delBanner
(
$banner_id
,
$id
)
{
$coin_applicate_category
=
CoinApplicationCategory
::
getCategoryById
(
$id
);
if
(
$coin_applicate_category
){
$tr
=
CoinApplicationCategory
::
getDb
()
->
beginTransaction
();
$banner
=
CoinBanner
::
getBannerById
(
$banner_id
);
if
(
$banner
->
delete
()){
$banner_ids
=
$coin_applicate_category
->
h5_banner
;
$banner_items
=
explode
(
','
,
$banner_ids
);
$banner_items
=
array_diff
(
$banner_items
,[
$banner_id
]);
if
(
$banner_items
){
$banner_ids
=
implode
(
","
,
$banner_items
);
}
else
{
$banner_ids
=
''
;
}
$coin_applicate_category
->
h5_banner
=
$banner_ids
;
$coin_applicate_category
->
save
();
$tr
->
commit
();
return
[
'code'
=>
0
,
'msg'
=>
'banner删除成功'
];
}
else
{
return
[
'code'
=>
0
,
'msg'
=>
'banner删除失败'
];
}
}
else
{
return
[
'code'
=>
1
,
'msg'
=>
'应用分类不存在'
];
}
}
}
\ No newline at end of file
backend/views/application-category/banner-index.php
0 → 100644
View file @
5af5a281
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/11/13
* Time: 11:52
*/
?>
<style>
.layui-form-label
{
width
:
100px
;
}
</style>
<h4>
所属分类---
<?=
$applicate_category
->
name
?>
</h4>
<div
class=
"layui-row"
style=
"padding: 5px;"
>
<div
class=
"layui-tab layui-tab-card"
>
<ul
class=
"layui-tab-title"
>
<li
class=
"layui-this"
>
H5 Banner
</li>
</ul>
<div
class=
"layui-tab-content"
>
<div
class=
"layui-tab-item layui-show"
>
<button
class=
"layui-btn layui-btn-default add_banner"
>
添加H5 banner
</button>
<table
class=
"layui-table"
id=
"table1"
lay-filter=
"table1"
></table>
</div>
</div>
</div>
</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_category_id"
name=
"applicate_category_id"
type=
"hidden"
value=
"
<?=
$applicate_category
->
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>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
>
banner跳转地址
</label>
<div
class=
"layui-input-block"
>
<input
type=
"text"
class=
"layui-input"
name=
"banner_url"
value=
""
>
</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_category_id
=
$
(
"#applicate_category_id"
).
val
();
table
.
render
({
elem
:
'#table1'
,
url
:
'/admin/application-category/banner-index?id='
+
applicate_category_id
,
cols
:
[[
{
field
:
'id'
,
title
:
'banner编号'
,
width
:
200
},
{
field
:
'image_url'
,
title
:
'图片链接'
,
templet
:
function
(
d
){
return
"<a href='"
+
d
.
image_url
+
"' target='_blank'>"
+
d
.
image_url
+
"</a>"
;
}
},
{
field
:
'banner_url'
,
title
:
'banner跳转链接'
,
templet
:
function
(
d
){
return
"<a href='"
+
d
.
banner_url
+
"' target='_blank'>"
+
d
.
banner_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-category/delete-banner'
,
{
id
:
data
.
id
,
applicate_category_id
:
applicate_category_id
},
function
(
rev
)
{
layer
.
msg
(
rev
.
msg
);
if
(
0
==
rev
.
code
)
{
table
.
reload
(
'table1'
);
}
});
});
}
});
$
(
'.add_banner'
).
click
(
function
()
{
var
index
=
layer
.
open
({
title
:
'添加图片'
,
area
:
'800px'
,
type
:
1
,
content
:
$
(
"#_form"
),
btn
:
[
'保存'
,
'取消'
],
success
:
function
()
{
clearForm
();
},
btn1
:
function
()
{
$
.
post
(
'/admin/application-category/add-banner'
,
$
(
"#form1"
).
serialize
(),
function
(
rev
)
{
layer
.
msg
(
rev
.
msg
);
if
(
0
==
rev
.
code
)
{
layer
.
close
(
index
);
$
(
"#_form"
).
css
(
'display'
,
'none'
);
table
.
reload
(
'table1'
);
}
});
},
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'
,
before
:
function
(
input
){
var
data
=
{};
data
.
_csrf
=
$_csrf
;
data
.
image_type
=
5
;
this
.
data
=
data
;
},
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'
,
''
);
$
(
"input[name='banner_url']"
).
val
(
''
);
}
</script>
\ No newline at end of file
backend/views/application-category/index.php
View file @
5af5a281
...
...
@@ -107,6 +107,7 @@
<
a
class
=
"layui-btn layui-btn-xs"
lay
-
event
=
"edit"
>
编辑
<
/a>
<
a
class
=
"layui-btn layui-btn-danger layui-btn-xs"
lay
-
event
=
"del"
>
删除
<
/a>
<
a
class
=
"layui-btn layui-btn-primary layui-btn-xs"
href
=
"/admin/application/list?id={{d.id}}"
>
应用列表
<
/a>
<
a
class
=
"layui-btn layui-btn-normal layui-btn-xs"
href
=
"/admin/application-category/banner-index?id={{d.id}}"
>
banner
图管理
<
/a>
</script>
<script
type=
"text/html"
id=
"recommendTpl"
>
<
input
type
=
"checkbox"
name
=
"isrecommend"
value
=
"{{d.id}}"
lay
-
skin
=
"switch"
lay
-
text
=
"是|否"
lay
-
filter
=
"recommendDemo"
{{
d
.
isrecommend
==
1
?
'checked'
:
''
}}
>
...
...
@@ -151,7 +152,8 @@
},
{
title
:
'操作'
,
templet
:
'#operationTpl'
templet
:
'#operationTpl'
,
width
:
300
},
{
title
:
'首页推荐'
,
...
...
common/models/psources/CoinBanner.php
0 → 100644
View file @
5af5a281
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/11/13
* Time: 14:29
*/
namespace
common\models\psources
;
use
common\core\BaseActiveRecord
;
use
Yii
;
class
CoinBanner
extends
BaseActiveRecord
{
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'p_sources'
);
}
public
static
function
tableName
()
{
return
'{{coin_banner}}'
;
}
public
static
function
getBannerInfoByIds
(
$banner_ids
)
{
if
(
$banner_ids
)
{
if
(
is_array
(
$banner_ids
)){
$idItems
=
$banner_ids
;
}
else
{
$idItems
=
explode
(
','
,
$banner_ids
);
}
$data
=
self
::
find
()
->
where
([
'in'
,
'id'
,
$idItems
])
->
asArray
()
->
all
();
$image_id_items
=
array_column
(
$data
,
'image_id'
);
$image_info
=
CoinImage
::
getItemsByIds
(
$image_id_items
);
foreach
(
$data
as
&
$value
){
$value
[
'image_url'
]
=
$image_info
[
$value
[
'image_id'
]][
'base_url'
]
.
$image_info
[
$value
[
'image_id'
]][
'file_url'
];
}
return
[
'code'
=>
0
,
'data'
=>
$data
];
}
else
{
return
[
'code'
=>
0
,
'data'
=>
[]];
}
}
public
static
function
getBannerById
(
$id
)
{
return
self
::
find
()
->
where
([
'id'
=>
$id
])
->
one
();
}
}
\ 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