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
9d5c6fe8
Commit
9d5c6fe8
authored
Oct 13, 2018
by
ZhuChunYang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
55c1f4df
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
442 additions
and
53 deletions
+442
-53
ApplicationCategoryController.php
backend/controllers/ApplicationCategoryController.php
+18
-34
BaseController.php
backend/controllers/BaseController.php
+15
-0
ImageController.php
backend/controllers/ImageController.php
+35
-0
BaseForm.php
backend/models/BaseForm.php
+28
-0
UploadForm.php
backend/models/UploadForm.php
+94
-0
CoinApplicationCategoryForm.php
backend/models/coin/CoinApplicationCategoryForm.php
+121
-0
index.php
backend/views/application-category/index.php
+52
-17
Uploader.php
common/components/uploader/Uploader.php
+2
-0
CoinApplicationCategory.php
common/models/psources/CoinApplicationCategory.php
+40
-2
CoinImage.php
common/models/psources/CoinImage.php
+37
-0
No files found.
backend/controllers/ApplicationCategoryController.php
View file @
9d5c6fe8
...
...
@@ -8,6 +8,7 @@
namespace
backend\controllers
;
use
backend\models\coin\CoinApplicationCategoryForm
;
use
common\models\psources\CoinApplicationCategory
;
use
Yii
;
use
yii\web\UploadedFile
;
...
...
@@ -22,7 +23,7 @@ class ApplicationCategoryController extends BaseController
$request
=
Yii
::
$app
->
request
;
$page
=
$request
->
get
(
'page'
,
1
);
$limit
=
$request
->
get
(
'limit'
,
10
);
$name
=
$request
->
get
(
'name'
,
''
);
$name
=
$request
->
get
(
'
category_
name'
,
''
);
$where
=
[];
if
(
$name
){
$where
[]
=
[
'name'
=>
$name
];
...
...
@@ -30,43 +31,29 @@ class ApplicationCategoryController extends BaseController
$data
=
CoinApplicationCategory
::
getList
(
$page
,
$limit
,
$where
);
return
$data
;
}
//$items = CoinApplicationCategory::getItemsByPid(0);
return
$this
->
render
(
'index'
);
}
/**
* 添加一个application category
*/
public
function
actionAdd
()
public
function
actionAdd
AndEdit
()
{
if
(
Yii
::
$app
->
request
->
isPost
)
{
Yii
::
$app
->
response
->
format
=
'json'
;
if
(
$id
=
Yii
::
$app
->
request
->
post
(
'id'
))
{
$model
=
AppVersion
::
findOne
(
$id
);
$model
->
scenario
=
AppVersion
::
APP_UPDATE
;
}
else
{
$model
=
new
AppVersion
();
$model
->
scenario
=
AppVersion
::
APP_ADD
;
}
$post
=
array_filter
(
Yii
::
$app
->
request
->
post
(),
function
(
$item
)
{
return
$item
;
});
if
(
$model
->
load
(
$post
)
&&
$model
->
validate
())
{
if
(
!
isset
(
$post
[
'id'
]))
{
$model
->
created_at
=
date
(
'Y-m-d H:i:s'
);
}
$model
->
updated_at
=
date
(
'Y-m-d H:i:s'
);
//更新日志使用json array
if
(
isset
(
$post
[
'log'
]))
{
$log_str
=
$post
[
'log'
];
$log_arr
=
explode
(
"
\n
"
,
$log_str
);
$model
->
log
=
$log_arr
;
}
$model
->
save
(
false
);
return
[
'code'
=>
0
,
'msg'
=>
'succeed'
];
}
$errors
=
$model
->
errors
;
foreach
(
$errors
as
$error
)
{
return
[
'code'
=>
1
,
'msg'
=>
$error
[
0
]];
$fields
=
[
'id'
,
'name'
,
'sort'
,
'icon'
];
$params
=
$this
->
initParams
(
Yii
::
$app
->
request
->
post
(),
$fields
);
$application_category
=
new
CoinApplicationCategoryForm
();
if
(
$params
[
'id'
]){
//edit
$application_category
->
setScenario
(
CoinApplicationCategoryForm
::
SCENARIO_EDIT
);
$application_category
->
load
(
$params
,
''
);
return
$application_category
->
edit
();
}
else
{
$application_category
->
setScenario
(
CoinApplicationCategoryForm
::
SCENARIO_ADD
);
$application_category
->
load
(
$params
,
''
);
return
$application_category
->
add
();
}
}
}
...
...
@@ -82,11 +69,8 @@ class ApplicationCategoryController extends BaseController
$id
=
Yii
::
$app
->
request
->
get
(
'id'
);
if
(
$id
)
{
$model
=
AppVersion
::
findOne
(
$id
);
if
(
$model
)
{
$model
->
delete
();
return
[
'code'
=>
0
,
'msg'
=>
'succeed'
];
}
$application_category
=
new
CoinApplicationCategoryForm
();
return
$application_category
->
del
(
$id
);
}
return
[
'code'
=>
1
,
'msg'
=>
'failed'
];
}
...
...
backend/controllers/BaseController.php
View file @
9d5c6fe8
...
...
@@ -279,4 +279,19 @@ class BaseController extends Controller
$admins
=
array_column
(
$admins
,
'username'
,
'uid'
);
return
$admins
;
}
protected
function
initParams
(
$p
=
[],
$fields
=
[],
$isFilter
=
false
)
{
$params
=
[];
if
(
!
empty
(
$fields
))
{
foreach
(
$fields
as
$key
=>
$value
)
{
if
(
isset
(
$p
[
$value
])
&&
(
!
empty
(
$p
[
$value
])
||
$p
[
$value
]
==
0
))
{
$params
[
$value
]
=
$p
[
$value
];
}
else
{
if
(
!
$isFilter
)
$params
[
$value
]
=
null
;
}
}
}
return
$params
;
}
}
backend/controllers/ImageController.php
0 → 100644
View file @
9d5c6fe8
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/10/13
* Time: 10:53
*/
namespace
backend\controllers
;
use
backend\models\UploadForm
;
use
Yii
;
use
yii\web\UploadedFile
;
class
ImageController
extends
BaseController
{
public
function
actionUpload
()
{
Yii
::
$app
->
response
->
format
=
'json'
;
$fields
=
[
'isSave'
,
'image_type'
];
$params
=
$this
->
initParams
(
Yii
::
$app
->
request
->
post
(),
$fields
);
$uploadForm
=
new
UploadForm
();
$uploadForm
->
setScenario
(
UploadForm
::
SCENARIO_UPLOAD_IMAGE
);
$uploadForm
->
load
(
$params
,
''
);
$fielsInfo
=
UploadedFile
::
getInstanceByName
(
'file'
);
$uploadForm
->
file
=
$fielsInfo
;
return
$uploadForm
->
uploadImage
();
}
}
\ No newline at end of file
backend/models/BaseForm.php
0 → 100644
View file @
9d5c6fe8
<?php
/**
@author ZCY
*/
namespace
backend\models
;
use
Yii
;
use
yii\base\Model
;
class
BaseForm
extends
Model
{
public
static
function
getModelError
(
$model
)
{
$error
=
null
;
$errors
=
$model
->
getErrors
();
foreach
(
$errors
as
$key
=>
$value
)
{
$v
=
$value
[
0
];
$error
=
$v
;
break
;
}
return
$error
;
}
}
\ No newline at end of file
backend/models/UploadForm.php
0 → 100644
View file @
9d5c6fe8
<?php
namespace
backend\models
;
use
common\models\psources\CoinImage
;
use
Yii
;
class
UploadForm
extends
BaseForm
{
const
SCENARIO_UPLOAD_IMAGE
=
'upload_image'
;
public
$file
;
//用来保存文件
public
$isSave
;
//是否保存到本地
public
$image_type
;
//图片类型
const
IMAGE_SAVE_DIR
=
[
1
=>
"/coin/"
,
//存放logo
2
=>
"/banner/"
//存放banner
];
/**
* @inheritdoc
*/
public
function
scenarios
()
{
return
[
self
::
SCENARIO_UPLOAD_IMAGE
=>
[
'file'
,
'isSave'
,
'image_type'
],
];
}
/**
* @inheritdoc
*/
public
function
rules
()
{
return
[
[[
'file'
],
'file'
,
'skipOnEmpty'
=>
false
,
'extensions'
=>
'jpg, png, gif'
,
'on'
=>
[
self
::
SCENARIO_UPLOAD_IMAGE
]],
[
'isSave'
,
'default'
,
'value'
=>
1
],
[
'image_type'
,
'default'
,
'value'
=>
1
],
];
}
public
function
uploadImage
()
{
if
(
$this
->
validate
()){
$uploader
=
Yii
::
$app
->
uploader
;
$save_dir
=
self
::
IMAGE_SAVE_DIR
[
$this
->
image_type
];
$uploadPath
=
$uploader
->
absolute
.
$save_dir
;
// 取得上传路径
if
(
!
file_exists
(
$uploadPath
))
{
@
mkdir
(
$uploadPath
,
0777
,
true
);
}
$ext
=
$this
->
file
->
getExtension
();
// 获取文件的扩展名
$randnums
=
$this
->
getrandnums
();
// 生成一个随机数,为了重命名文件
$imageName
=
date
(
"YmdHis"
)
.
$randnums
.
'.'
.
$ext
;
// 重命名文件
$filePath
=
$uploadPath
.
$imageName
;
// 生成文件的绝对路径
$this
->
file
->
saveAs
(
$filePath
);
$base_url
=
rtrim
(
$uploader
->
baseuri
,
'/'
);
$file_url
=
$save_dir
.
$imageName
;
$image_id
=
CoinImage
::
addOneRecord
(
$base_url
,
$file_url
);
$image_src
=
rtrim
(
$uploader
->
baseuri
,
'/'
)
.
$save_dir
.
$imageName
;
$data
=
[
'image_id'
=>
$image_id
,
'image_src'
=>
$image_src
];
return
[
'code'
=>
0
,
'data'
=>
$data
];
}
else
{
$error
=
self
::
getModelError
(
$this
);
return
[
'code'
=>
1
,
'msg'
=>
$error
];
}
}
/**
* 生成随机数
* @return string 随机数
*/
protected
function
getrandnums
()
{
$arr
=
array
();
while
(
count
(
$arr
)
<
10
)
{
$arr
[]
=
rand
(
1
,
10
);
$arr
=
array_unique
(
$arr
);
}
return
implode
(
""
,
$arr
);
}
}
?>
\ No newline at end of file
backend/models/coin/CoinApplicationCategoryForm.php
0 → 100644
View file @
9d5c6fe8
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/10/12
* Time: 19:10
*/
namespace
backend\models\coin
;
use
backend\models\BaseForm
;
use
common\models\psources\CoinApplicationCategory
;
class
CoinApplicationCategoryForm
extends
BaseForm
{
const
SCENARIO_ADD
=
'add'
;
const
SCENARIO_EDIT
=
'edit'
;
public
$id
;
public
$name
;
public
$sort
;
public
$icon
;
public
$pid
;
public
function
scenarios
()
{
return
[
self
::
SCENARIO_ADD
=>
[
'name'
,
'sort'
,
'icon'
,
'pid'
],
self
::
SCENARIO_EDIT
=>
[
'id'
,
'name'
,
'sort'
,
'icon'
],
];
}
public
function
attributeLabels
()
{
return
[
'id'
=>
'ID'
,
'name'
=>
'名称'
,
'icon'
=>
'图标'
,
'sort'
=>
'排序'
,
];
}
public
function
rules
()
{
return
[
[[
'name'
],
'required'
,
'on'
=>
self
::
SCENARIO_ADD
],
[[
'id'
,
'name'
,
'sort'
],
'required'
,
'on'
=>
self
::
SCENARIO_EDIT
],
[
'sort'
,
'default'
,
'value'
=>
99
],
[
'icon'
,
'default'
,
'value'
=>
0
],
[
'name'
,
'checkName'
],
];
}
public
function
checkName
(
$attribute
,
$params
)
{
$res
=
CoinApplicationCategory
::
find
()
->
where
([
'name'
=>
$this
->
$attribute
])
->
one
();
$scenario
=
$this
->
getScenario
();
if
(
$scenario
==
self
::
SCENARIO_ADD
){
if
(
$res
){
$this
->
addError
(
$attribute
,
'应用分类名称已存在'
);
}
}
else
if
(
$scenario
==
self
::
SCENARIO_EDIT
){
if
(
$res
&&
$res
->
id
!=
$this
->
id
){
$this
->
addError
(
$attribute
,
'应用分类名称已存在'
);
}
}
}
/**
* 添加应用分类
*/
public
function
add
()
{
if
(
$this
->
validate
()){
$coin_applicate_category
=
new
CoinApplicationCategory
();
$coin_applicate_category
->
setAttributes
(
$this
->
attributes
,
false
);
$coin_applicate_category
->
save
();
return
[
'code'
=>
0
,
'msg'
=>
'应用分类添加成功!'
];
}
else
{
$error
=
self
::
getModelError
(
$this
);
return
[
'code'
=>
1
,
'msg'
=>
$error
];
}
}
/**
* 编辑应用分类
*/
public
function
edit
()
{
if
(
$this
->
validate
()){
$coin_applicate_category
=
CoinApplicationCategory
::
getCategoryById
(
$this
->
id
);
if
(
$coin_applicate_category
){
$coin_applicate_category
->
setAttributes
(
$this
->
attributes
,
false
);
$coin_applicate_category
->
save
();
return
[
'code'
=>
0
,
'msg'
=>
'应用分类修改成功!'
];
}
else
{
return
[
'code'
=>
1
,
'msg'
=>
'应用分类不存在'
];
}
}
else
{
$error
=
self
::
getModelError
(
$this
);
return
[
'code'
=>
1
,
'msg'
=>
$error
];
}
}
/**
* @param $id
* 删除应用分类
*/
public
function
del
(
$id
)
{
$coin_applicate_category
=
CoinApplicationCategory
::
getCategoryById
(
$id
);
if
(
$coin_applicate_category
){
$coin_applicate_category
->
delete
();
return
[
'code'
=>
0
,
'msg'
=>
'应用分类删除成功'
];
}
else
{
return
[
'code'
=>
1
,
'msg'
=>
'应用分类不存在'
];
}
}
}
\ No newline at end of file
backend/views/application-category/index.php
View file @
9d5c6fe8
...
...
@@ -6,7 +6,6 @@
* Time: 17:41
*/
?>
<h4>
应用分类列表
</h4>
<div
class=
"layui-row"
>
<div
class=
"layui-col-md1"
>
...
...
@@ -33,7 +32,7 @@
<!-- 添加页面 -->
<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 form_add"
action=
"javascript:void(0)"
method=
"post"
lay-filter=
"form1"
>
<form
class=
"layui-form form_add"
action=
"javascript:void(0)"
id=
"form1"
method=
"post"
lay-filter=
"form1"
>
<input
type=
"hidden"
name=
"_csrf"
value=
"
<?=
Yii
::
$app
->
request
->
getCsrfToken
()
?>
"
>
<input
type=
"hidden"
name=
"id"
value=
""
>
<div
class=
"layui-form-item layui-form-text"
>
...
...
@@ -66,11 +65,12 @@
</button>
</div>
</div>
</form>
</div>
</div>
<script
type=
"text/html"
id=
"iconTpl"
>
<
img
src
=
"{{d.icon_url}}"
style
=
"max-width: 32px; max-height: 32px;"
/>
</script>
<script
type=
"text/html"
id=
"operationTpl"
>
<
button
class
=
"layui-btn layui-btn-sm"
lay
-
event
=
"edit"
><
i
class
=
"layui-icon"
>&
#
xe642
;
<
/i></
button
>
<
button
class
=
"layui-btn layui-btn-sm layui-btn-danger"
lay
-
event
=
"del"
><
i
class
=
"layui-icon"
>&
#
xe640
;
<
/i></
button
>
...
...
@@ -92,9 +92,11 @@
field
:
'name'
,
title
:
'名称'
,
},
{
field
:
'icon'
,
title
:
'图标'
field
:
'icon_url'
,
title
:
'图标'
,
templet
:
'#iconTpl'
},
{
field
:
'sort'
,
...
...
@@ -104,8 +106,16 @@
title
:
'操作'
,
templet
:
'#operationTpl'
},
]]
{
field
:
'icon'
,
title
:
'图标'
,
hide
:
true
,
width
:
50
},
]],
});
var
form
=
layui
.
form
;
form
.
render
();
...
...
@@ -126,9 +136,10 @@
icon
:
data
.
icon
,
sort
:
data
.
sort
,
});
$
(
"#icon1"
).
attr
(
'src'
,
data
.
icon_url
);
},
btn1
:
function
()
{
$
.
get
(
'/admin/coin-recommend/add
'
,
$
(
"#form1"
).
serialize
(),
function
(
rev
)
{
$
.
post
(
'/admin/application-category/add-and-edit
'
,
$
(
"#form1"
).
serialize
(),
function
(
rev
)
{
layer
.
msg
(
rev
.
msg
);
if
(
0
==
rev
.
code
)
{
layer
.
close
(
index
);
...
...
@@ -152,10 +163,9 @@
});
}
else
if
(
'del'
===
event
)
{
var
index
=
layer
.
confirm
(
"确认删除?"
,
{
icon
:
3
,
title
:
'删除'
},
function
()
{
$
.
get
(
'/admin/
coin-recommend/del
'
,
{
id
:
data
.
id
},
function
(
rev
)
{
$
.
get
(
'/admin/
application-category/delete
'
,
{
id
:
data
.
id
},
function
(
rev
)
{
layer
.
msg
(
rev
.
msg
);
if
(
0
==
rev
.
code
)
{
// layer.close(index);
table
.
reload
(
'table1'
,{
page
:{
curr
:
1
}
});
...
...
@@ -180,19 +190,15 @@
content
:
$
(
"#_form"
),
btn
:
[
'保存'
,
'取消'
],
success
:
function
()
{
form
.
val
(
"form1"
,
{
id
:
""
,
name
:
""
,
icon
:
""
,
sort
:
""
,
});
clearForm
();
},
btn1
:
function
()
{
$
.
get
(
'/admin/coin-recommend/add
'
,
$
(
"#form1"
).
serialize
(),
function
(
rev
)
{
$
.
post
(
'/admin/application-category/add-and-edit
'
,
$
(
"#form1"
).
serialize
(),
function
(
rev
)
{
layer
.
msg
(
rev
.
msg
);
if
(
0
==
rev
.
code
)
{
layer
.
close
(
index
);
$
(
"#_form"
).
css
(
'display'
,
'none'
);
clearForm
();
table
.
reload
(
'table1'
,
{
page
:
{
curr
:
1
...
...
@@ -211,4 +217,32 @@
}
});
})
//图片上传
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='icon']"
).
val
(
res
.
data
.
image_id
);
$
(
"#icon1"
).
attr
(
'src'
,
res
.
data
.
image_src
);
}
},
error
:
function
(
res
)
{
}
});
function
clearForm
(){
form
.
val
(
"form1"
,
{
id
:
''
,
name
:
''
,
icon
:
''
,
sort
:
''
,
});
$
(
"#icon1"
).
attr
(
'src'
,
''
);
}
</script>
\ No newline at end of file
common/components/uploader/Uploader.php
View file @
9d5c6fe8
...
...
@@ -71,4 +71,6 @@ class Uploader extends Component
}
}
}
common/models/psources/CoinApplicationCategory.php
View file @
9d5c6fe8
...
...
@@ -22,6 +22,19 @@ class CoinApplicationCategory extends BaseActiveRecord
return
'{{%coin_application_category}}'
;
}
public
function
beforeSave
(
$instert
)
{
if
(
parent
::
beforeSave
(
$instert
))
{
if
(
$this
->
isNewRecord
)
{
$this
->
create_time
=
Yii
::
$app
->
formatter
->
asTimestamp
(
'now'
);
}
else
{
$this
->
update_time
=
Yii
::
$app
->
formatter
->
asTimestamp
(
'now'
);
}
return
true
;
}
else
{
return
false
;
}
}
/**
* 获取应用分类列表
*
...
...
@@ -34,12 +47,37 @@ class CoinApplicationCategory extends BaseActiveRecord
public
static
function
getList
(
$page
=
1
,
$limit
=
10
,
$condition
=
[],
$order_by
=
[
'sort'
=>
SORT_ASC
],
$select
=
[])
{
$query
=
self
::
find
();
if
(
!
empty
(
$condition
))
{
$query
=
$query
->
where
(
$condition
);
foreach
(
$condition
as
$item
)
{
$query
=
$query
->
andWhere
(
$item
);
}
$count
=
$query
->
count
();
$data
=
$query
->
offset
((
$page
-
1
)
*
10
)
->
limit
(
$limit
)
->
orderby
(
$order_by
);
$data
=
$data
->
asArray
()
->
all
();
$icon_Items
=
array_column
(
$data
,
'icon'
);
$icon_Infos
=
CoinImage
::
getItemsByIds
(
$icon_Items
);
foreach
(
$data
as
$key
=>
&
$value
){
if
(
$value
[
'icon'
]){
$value
[
'icon_url'
]
=
$icon_Infos
[
$value
[
'icon'
]][
'base_url'
]
.
$icon_Infos
[
$value
[
'icon'
]][
'file_url'
];
}
else
{
$value
[
'icon_url'
]
=
''
;
}
}
return
[
'count'
=>
$count
,
'data'
=>
$data
,
'code'
=>
0
];
}
/**
* @param $id
*/
public
static
function
getCategoryById
(
$id
)
{
return
self
::
find
()
->
where
([
'id'
=>
$id
])
->
one
();
}
public
static
function
getItemsByPid
(
$pid
)
{
$data
=
self
::
find
()
->
where
([
'pid'
=>
$pid
])
->
asArray
()
->
all
();
$items
=
array_column
(
$data
,
'name'
,
'id'
);
return
$items
;
}
}
common/models/psources/CoinImage.php
0 → 100644
View file @
9d5c6fe8
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/10/13
* Time: 14:08
*/
namespace
common\models\psources
;
use
Yii
;
class
CoinImage
extends
BaseActiveRecord
{
public
static
function
tableName
()
{
return
'coin_image'
;
}
public
static
function
addOneRecord
(
$base_url
,
$file_path
)
{
$coin_image
=
new
self
();
$coin_image
->
base_url
=
$base_url
;
$coin_image
->
file_url
=
$file_path
;
$coin_image
->
save
();
return
$coin_image
->
id
;
}
public
static
function
getItemsByIds
(
$idItems
)
{
$data
=
self
::
find
()
->
where
([
'in'
,
'id'
,
$idItems
])
->
asArray
()
->
all
();
return
array_column
(
$data
,
null
,
'id'
);
}
}
\ 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