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
d5dd03d6
Commit
d5dd03d6
authored
Jun 13, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
用户管理
parent
42c32953
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
352 additions
and
6 deletions
+352
-6
MemberController.php
api/controllers/MemberController.php
+1
-3
MemberController.php
backend/controllers/MemberController.php
+103
-0
edit.php
backend/views/member/edit.php
+104
-0
index.php
backend/views/member/index.php
+81
-0
Member.php
common/models/pwallet/Member.php
+63
-3
No files found.
api/controllers/MemberController.php
View file @
d5dd03d6
...
...
@@ -28,9 +28,7 @@ class MemberController extends BaseController
//加密password
//加盐
try
{
$member
->
salt
=
Yii
::
$app
->
security
->
generateRandomString
();
$member
->
password
=
Yii
::
$app
->
security
->
generatePasswordHash
(
$member
->
password
.
$member
->
salt
);
$member
->
save
();
$member
->
addOne
();
return
[
'code'
=>
0
,
'msg'
=>
'succeed'
];
}
catch
(
\Exception
$exception
)
{
throw
$exception
;
...
...
backend/controllers/MemberController.php
0 → 100644
View file @
d5dd03d6
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-12
* Time: 下午5:50
*/
namespace
backend\controllers
;
use
Yii
;
use
common\models\pwallet\Member
;
class
MemberController
extends
BaseController
{
public
function
actionIndex
()
{
$req
=
Yii
::
$app
->
request
;
$response
=
Yii
::
$app
->
response
;
if
(
$req
->
isAjax
)
{
$page
=
$req
->
get
(
'page'
,
0
);
$limit
=
$req
->
get
(
'limit'
,
10
);
$register_at
=
$req
->
get
(
'register_at'
,
null
);
$type
=
$req
->
get
(
'type'
,
0
);
$condition
=
$req
->
get
(
'condition'
,
''
);
$where
=
[];
if
(
!
empty
(
$condition
))
{
$where
[]
=
[
'OR'
,
[
'='
,
'uid'
,
$condition
],
[
'='
,
'phone'
,
$condition
],
[
'='
,
'email'
,
$condition
],
[
'='
,
'realname'
,
$condition
],
[
'='
,
'nickname'
,
$condition
],
[
'='
,
'username'
,
$condition
],
];
if
(
$type
)
{
//todo 推客查找
//先获取推客uid
$recommenders
=
Member
::
getList
(
1
,
999
,
$where
);
if
(
$recommenders
[
'code'
]
==
0
)
{
$recommenders
=
$recommenders
[
'data'
];
$ids
=
[];
foreach
(
$recommenders
as
$recommender
)
{
$ids
[]
=
$recommender
[
'uid'
];
}
unset
(
$where
);
$where
=
[];
$where
[]
=
[
'in'
,
'recommend_id'
,
$ids
];
}
}
}
if
(
$register_at
!=
null
&&
!
empty
(
$register_at
))
{
list
(
$s
,
$e
)
=
explode
(
'~'
,
str_replace
(
' '
,
''
,
$register_at
));
$where
[]
=
[
'between'
,
'register_at'
,
$s
,
$e
];
}
$data
=
Member
::
getList
(
$page
,
$limit
,
$where
);
$response
->
format
=
'json'
;
$response
->
data
=
$data
;
$response
->
send
();
}
return
$this
->
render
(
'index'
);
}
public
function
actionEdit
()
{
$req
=
Yii
::
$app
->
request
;
if
(
$req
->
isPost
)
{
//TODO 保存信息
$id
=
$req
->
post
(
'uid'
,
0
);
if
(
$id
)
{
$memeber
=
Member
::
findOne
([
'uid'
=>
$id
]);
if
(
$memeber
)
{
$memeber
->
scenario
=
Member
::
SCENARIO_UPDATE
;
if
(
$memeber
->
load
(
$req
->
post
())
&&
$memeber
->
validate
())
{
try
{
$memeber
->
updateOne
();
$this
->
success
(
'修改成功'
,
'/admin/member/index'
);
}
catch
(
\Exception
$exception
)
{
}
}
if
(
$memeber
->
hasErrors
())
{
$errors
=
$memeber
->
errors
;
foreach
(
$errors
as
$error
)
{
$this
->
error
(
$error
[
0
],
$req
->
getReferrer
());
}
}
}
}
}
$id
=
$req
->
get
(
'id'
,
0
);
if
(
$id
)
{
$memeber
=
Member
::
findOne
([
'uid'
=>
$id
]);
if
(
$memeber
)
{
return
$this
->
render
(
'edit'
,
[
'model'
=>
$memeber
]);
}
}
$this
->
error
(
'用户不存在'
,
'/admin/member/index'
);
}
}
\ No newline at end of file
backend/views/member/edit.php
0 → 100644
View file @
d5dd03d6
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-13
* Time: 下午2:05
*/
/**
* @var $model \common\models\pwallet\Member
*/
?>
<h4>
修改用户信息
</h4>
<div
class=
"layui-row"
>
<div
class=
"layui-col-md8"
>
<form
class=
"layui-form"
method=
"post"
>
<input
type=
"hidden"
name=
"_csrf"
value=
"
<?=
Yii
::
$app
->
request
->
getCsrfToken
()
?>
"
>
<input
type=
"hidden"
name=
"uid"
value=
"
<?=
$model
->
uid
?>
"
>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
style=
"width: 150px;margin-bottom: 0"
>
用户名
</label>
<div
class=
"layui-input-inline"
>
<input
name=
"username"
class=
"layui-input"
value=
"
<?=
$model
->
username
?>
"
>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
style=
"width: 150px;margin-bottom: 0"
>
真实姓名
</label>
<div
class=
"layui-input-inline"
>
<input
name=
"realname"
class=
"layui-input"
value=
"
<?=
$model
->
realname
?>
"
>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
style=
"width: 150px;margin-bottom: 0"
>
昵称
</label>
<div
class=
"layui-input-inline"
>
<input
name=
"nickname"
class=
"layui-input"
value=
"
<?=
$model
->
nickname
?>
"
>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
style=
"width: 150px;margin-bottom: 0"
>
手机
</label>
<div
class=
"layui-input-inline"
>
<input
name=
"phone"
class=
"layui-input"
value=
"
<?=
$model
->
phone
?>
"
>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
style=
"width: 150px;margin-bottom: 0"
>
邮箱
</label>
<div
class=
"layui-input-inline"
>
<input
name=
"email"
class=
"layui-input"
value=
"
<?=
$model
->
email
?>
"
>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
style=
"width: 150px;margin-bottom: 0"
>
资产总值
</label>
<div
class=
"layui-input-inline"
>
<input
name=
"capital"
class=
"layui-input"
value=
"
<?=
$model
->
capital
?>
"
>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
style=
"width: 150px;margin-bottom: 0"
>
注册时间
</label>
<div
class=
"layui-input-inline"
>
<input
name=
"register_at"
class=
"layui-input"
value=
"
<?=
$model
->
register_at
?>
"
id=
"date1"
>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
style=
"width: 150px;margin-bottom: 0"
>
推荐人UID
</label>
<div
class=
"layui-input-inline"
>
<input
name=
"recommend_id"
class=
"layui-input"
value=
"
<?=
$model
->
recommend_id
?>
"
>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
style=
"width: 150px;margin-bottom: 0"
>
推荐人数
</label>
<div
class=
"layui-input-inline"
>
<input
name=
"recommend_number"
class=
"layui-input"
value=
"
<?=
$model
->
recommend_number
?>
"
>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
style=
"width: 150px;margin-bottom: 0"
>
托管账户地址
</label>
<div
class=
"layui-input-inline"
>
<input
name=
"account_address"
class=
"layui-input"
value=
"
<?=
$model
->
account_address
?>
"
>
</div>
</div>
<div
class=
"layui-form-item"
>
<button
class=
"layui-btn"
>
保存
</button>
</div>
</form>
</div>
</div>
<script>
var
laydate
=
layui
.
laydate
;
laydate
.
render
({
elem
:
"#date1"
,
type
:
"datetime"
,
format
:
'yyyy-MM-dd HH:mm:ss'
});
</script>
\ No newline at end of file
backend/views/member/index.php
0 → 100644
View file @
d5dd03d6
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-12
* Time: 下午5:52
*/
?>
<h4>
用户管理
</h4>
<div
class=
"layui-row"
>
<form
class=
"layui-form"
>
<div
class=
"layui-inline"
>
<label
class=
"layui-form-label"
style=
"width: 100px; margin-bottom: 0"
>
注册日期
</label>
<div
class=
"layui-input-inline"
>
<input
name=
"register_at"
class=
"layui-input"
type=
"text"
id=
"date1"
>
</div>
</div>
<div
class=
"layui-inline"
>
<div
class=
"layui-input-inline"
>
<select
name=
"type"
>
<option
value=
"0"
>
查找单个用户
</option>
<option
value=
"1"
>
通过推客查找
</option>
</select>
</div>
</div>
<div
class=
"layui-inline"
>
<input
type=
"text"
name=
"condition"
class=
"layui-input"
placeholder=
"UID/姓名/手机/邮箱"
>
</div>
<div
class=
"layui-inline"
>
<button
class=
"layui-btn"
lay-submit
lay-filter=
"submit1"
>
查询
</button>
<button
class=
"layui-btn"
type=
"reset"
>
清除
</button>
</div>
</form>
</div>
<div
class=
"layui-row"
>
<div
class=
"layui-col-md12"
>
<table
class=
"layui-table"
id=
"table1"
></table>
</div>
</div>
<script>
var
laydate
=
layui
.
laydate
;
var
form
=
layui
.
form
;
var
table
=
layui
.
table
;
laydate
.
render
({
elem
:
"#date1"
,
range
:
'~'
,
});
form
.
render
();
table
.
render
({
elem
:
"#table1"
,
url
:
'/admin/member/index'
,
page
:
1
,
cols
:
[[
{
field
:
'uid'
,
title
:
"UID"
},
{
field
:
'realname'
,
title
:
"姓名"
},
{
field
:
'nickname'
,
title
:
"昵称"
},
{
field
:
'phone'
,
title
:
"手机"
},
{
field
:
'email'
,
title
:
"邮箱"
},
{
field
:
'capital'
,
title
:
"资产总值"
},
{
field
:
'register_at'
,
title
:
"注册时间"
},
{
field
:
'recommend_id'
,
title
:
"推客UID"
},
{
field
:
'recommend_number'
,
title
:
"推介人数"
},
{
field
:
'account_address'
,
title
:
"托管账户地址"
},
{
title
:
"操作"
,
templet
:
"#operationTpl"
},
]]
});
form
.
on
(
'submit(submit1)'
,
function
(
data
)
{
table
.
reload
(
'table1'
,
{
where
:
data
.
field
,
page
:
{
curr
:
1
},
});
return
false
;
});
</script>
<script
type=
"text/html"
id=
"operationTpl"
>
<
a
href
=
"/admin/member/edit?id={{d.uid}}"
>
<
button
class
=
"layui-btn layui-btn-sm"
>
编辑
<
/button
>
<
/a
>
</script>
\ No newline at end of file
common/models/pwallet/Member.php
View file @
d5dd03d6
...
...
@@ -8,6 +8,7 @@
namespace
common\models\pwallet
;
use
common\base\Exception
;
use
Yii
;
use
common\core\BaseActiveRecord
;
...
...
@@ -30,7 +31,8 @@ use common\core\BaseActiveRecord;
*/
class
Member
extends
BaseActiveRecord
{
const
SCENARIO_ADD
=
'add'
;
const
SCENARIO_ADD
=
'add'
;
const
SCENARIO_UPDATE
=
'update'
;
/**
* @return null|object|\yii\db\Connection
...
...
@@ -57,15 +59,30 @@ class Member extends BaseActiveRecord
[[
'capital'
],
'number'
],
[[
'account_address'
],
'string'
],
[[
'username'
],
'usernameExistsValidate'
],
[[
'username'
],
'usernameExistsValidate'
,
'on'
=>
self
::
SCENARIO_ADD
],
[[
'username'
,
'password'
,
'register_at'
],
'required'
,
'on'
=>
self
::
SCENARIO_ADD
],
[[
'uid'
,
'username'
],
'required'
,
'on'
=>
self
::
SCENARIO_UPDATE
],
];
}
public
function
scenarios
()
{
return
[
self
::
SCENARIO_ADD
=>
[
self
::
SCENARIO_ADD
=>
[
'username'
,
'password'
,
'realname'
,
'nickname'
,
'phone'
,
'email'
,
'capital'
,
'register_at'
,
'recommend_id'
,
'recommend_number'
,
'account_address'
],
self
::
SCENARIO_UPDATE
=>
[
'uid'
,
'username'
,
'password'
,
'realname'
,
...
...
@@ -110,4 +127,46 @@ class Member extends BaseActiveRecord
$this
->
addError
(
$attribute
,
'Username Exists!'
);
}
}
/**
* 添加一个新用户
* @throws \Exception
*/
public
function
addOne
()
{
$this
->
salt
=
Yii
::
$app
->
security
->
generateRandomString
();
$this
->
password
=
Yii
::
$app
->
security
->
generatePasswordHash
(
$this
->
password
.
$this
->
salt
);
if
(
$this
->
recommend_id
)
{
$recommend
=
self
::
findOne
([
'uid'
=>
$this
->
recommend_id
]);
if
(
$recommend
)
{
$recommend
->
recommend_number
+=
1
;
$recommend
->
save
(
false
);
}
else
{
$this
->
recommend_id
=
''
;
}
}
$this
->
save
(
false
);
}
public
function
updateOne
()
{
$old
=
self
::
findOne
([
'uid'
=>
$this
->
uid
]);
if
(
$this
->
recommend_id
)
{
//更新推介人数
if
(
$old
->
recommend_id
&&
$old
->
recommend_id
!=
$this
->
recommend_id
)
{
$recommend
=
self
::
findOne
([
'uid'
=>
$old
->
recommend_id
]);
if
(
$recommend
)
{
$recommend
->
recommend_number
-=
1
;
$recommend
->
save
(
false
);
}
}
$recommend
=
self
::
findOne
([
'uid'
=>
$this
->
recommend_id
]);
if
(
$recommend
)
{
$recommend
->
recommend_number
+=
1
;
$recommend
->
save
(
false
);
}
}
$this
->
save
(
false
);
}
}
\ 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