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
42c32953
Commit
42c32953
authored
Jun 13, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加用户api
parent
f45601a2
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
194 additions
and
7 deletions
+194
-7
MemberController.php
api/controllers/MemberController.php
+47
-0
BaseActiveRecord.php
common/core/BaseActiveRecord.php
+18
-0
Member.php
common/models/pwallet/Member.php
+114
-0
CoinService.php
common/service/CoinService.php
+15
-7
No files found.
api/controllers/MemberController.php
0 → 100644
View file @
42c32953
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-13
* Time: 上午10:41
*/
namespace
api\controllers
;
use
Yii
;
use
api\base\BaseController
;
use
common\models\pwallet\Member
;
class
MemberController
extends
BaseController
{
/**
* @return array
* @throws \Exception
*/
public
function
actionAddOne
()
{
$post
=
Yii
::
$app
->
request
->
post
();
$member
=
new
Member
();
$member
->
scenario
=
Member
::
SCENARIO_ADD
;
$post
[
'register_at'
]
=
date
(
'Y-m-d H:i:s'
);
if
(
$member
->
load
(
$post
)
&&
$member
->
validate
())
{
//加密password
//加盐
try
{
$member
->
salt
=
Yii
::
$app
->
security
->
generateRandomString
();
$member
->
password
=
Yii
::
$app
->
security
->
generatePasswordHash
(
$member
->
password
.
$member
->
salt
);
$member
->
save
();
return
[
'code'
=>
0
,
'msg'
=>
'succeed'
];
}
catch
(
\Exception
$exception
)
{
throw
$exception
;
}
}
if
(
$member
->
hasErrors
())
{
$errors
=
$member
->
errors
;
foreach
(
$errors
as
$error
)
{
throw
new
\Exception
(
$error
[
0
],
1
);
}
}
}
}
\ No newline at end of file
common/core/BaseActiveRecord.php
View file @
42c32953
...
@@ -7,4 +7,22 @@ namespace common\core;
...
@@ -7,4 +7,22 @@ namespace common\core;
*/
*/
class
BaseActiveRecord
extends
\yii\db\ActiveRecord
class
BaseActiveRecord
extends
\yii\db\ActiveRecord
{
{
public
static
function
getList
(
$page
=
1
,
$limit
=
10
,
$condition
=
[])
{
$query
=
self
::
find
();
foreach
(
$condition
as
$item
)
{
$query
=
$query
->
andWhere
(
$item
);
}
$count
=
$query
->
count
();
$data
=
$query
->
offset
((
$page
-
1
)
*
10
)
->
limit
(
$limit
)
->
asArray
()
->
all
();
// $sql = $query->createCommand()->getSql();
$data
=
[
'count'
=>
$count
,
'data'
=>
$data
];
if
(
$count
>
0
)
{
$data
[
'code'
]
=
0
;
}
else
{
$data
[
'code'
]
=
1
;
$data
[
'msg'
]
=
'数据为空'
;
}
return
$data
;
}
}
}
common/models/pwallet/Member.php
0 → 100644
View file @
42c32953
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-13
* Time: 上午9:50
*/
namespace
common\models\pwallet
;
use
Yii
;
use
common\core\BaseActiveRecord
;
/**
* Class Member
* @property integer $uid
* @property string $username
* @property string $password
* @property string $salt
* @property string $realname
* @property string $nickname
* @property string $phone
* @property string $email
* @property double $capital
* @property string $register_at
* @property integer $recommend_id
* @property integer $recommend_number
* @property string $account_address
* @package common\models\pwallet
*/
class
Member
extends
BaseActiveRecord
{
const
SCENARIO_ADD
=
'add'
;
/**
* @return null|object|\yii\db\Connection
* @throws \yii\base\InvalidConfigException
*/
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'db_pwallet'
);
}
public
function
formName
()
{
return
''
;
}
public
function
rules
()
{
return
[
[[
'uid'
,
'recommend_id'
,
'recommend_number'
],
'integer'
],
[[
'username'
,
'realname'
,
'nickname'
],
'string'
,
'min'
=>
0
,
'max'
=>
64
],
[[
'phone'
],
'string'
,
'max'
=>
16
],
[[
'password'
,
'email'
],
'string'
,
'max'
=>
255
],
[[
'register_at'
],
'date'
,
'type'
=>
'datetime'
,
'format'
=>
'php:Y-m-d H:i:s'
],
[[
'capital'
],
'number'
],
[[
'account_address'
],
'string'
],
[[
'username'
],
'usernameExistsValidate'
],
[[
'username'
,
'password'
,
'register_at'
],
'required'
,
'on'
=>
self
::
SCENARIO_ADD
],
];
}
public
function
scenarios
()
{
return
[
self
::
SCENARIO_ADD
=>
[
'username'
,
'password'
,
'realname'
,
'nickname'
,
'phone'
,
'email'
,
'capital'
,
'register_at'
,
'recommend_id'
,
'recommend_number'
,
'account_address'
],
];
}
public
function
attributeLabels
()
{
return
[
'uid'
=>
'用户ID'
,
'username'
=>
'用户名'
,
'password'
=>
'密码'
,
'realname'
=>
'真实姓名'
,
'nickname'
=>
'昵称'
,
'phone'
=>
'电话号码'
,
'email'
=>
'邮箱'
,
'capital'
=>
'资产'
,
'register_at'
=>
'注册时间'
,
'recommend_id'
=>
'推介人ID'
,
'recommend_number'
=>
'推介人数'
,
'account_address'
=>
'托管账户地址'
,
];
}
public
static
function
usernameExists
(
$username
)
{
return
(
bool
)
self
::
findOne
([
'username'
=>
$username
]);
}
public
function
usernameExistsValidate
(
$attribute
,
$params
)
{
if
(
self
::
usernameExists
(
$this
->
$attribute
))
{
$this
->
addError
(
$attribute
,
'Username Exists!'
);
}
}
}
\ No newline at end of file
common/service/CoinService.php
View file @
42c32953
...
@@ -155,19 +155,26 @@ class CoinService
...
@@ -155,19 +155,26 @@ class CoinService
'circulate_count'
=>
''
,
//流通总量
'circulate_count'
=>
''
,
//流通总量
];
];
$ch
=
curl_init
(
'https://
api2.mytoken.org/currency/currencydetail?com_id=bty_CNY&market_id=1303&market_name=cmc&symbol=BTY&anchor=CNY×tamp=1528775656509&code=c368f591b57e93011cb9c853555a9126&v=1.4.0&platform=m&language=zh_CN&
'
);
$ch
=
curl_init
(
'https://
kdata.zhaobi.com:4062/kdata?datafile=db&c=BTYUSDT&p=H1&action=init&count=24&ind=volumes&out=json
'
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$ch
,
CURLOPT_HEADER
,
0
);
curl_setopt
(
$ch
,
CURLOPT_HEADER
,
0
);
$content
=
curl_exec
(
$ch
);
$content
=
curl_exec
(
$ch
);
$content
=
json_decode
(
$content
,
true
);
$content
=
json_decode
(
$content
,
true
);
if
(
$content
[
'code'
]
==
0
)
{
$content
=
$content
[
'main'
][
'y'
];
$content
=
$content
[
'data'
];
$result
[
'rank'
]
=
'第'
.
$content
[
'rank'
]
.
'名'
;
$result
[
'price'
]
=
$content
[
'price_display'
];
$min
=
10e9
;
$result
[
'dollar'
]
=
sprintf
(
"$%0.6f"
,
$content
[
'price_usd'
]);
$max
=
0
;
$result
[
'change'
]
=
sprintf
(
"%0.6f%%"
,
$content
[
'percent_change_display'
]);
foreach
(
$content
as
$item
)
{
for
(
$i
=
0
;
$i
<
4
;
$i
++
)
{
$min
=
min
(
$min
,
$item
[
$i
]);
$max
=
max
(
$max
,
$item
[
$i
]);
}
}
}
$change
=
(
$content
[
23
][
3
]
-
$content
[
0
][
0
])
/
$content
[
0
][
0
]
*
100
;
$result
[
'dollar'
]
=
$content
[
23
][
3
];
$result
[
'low'
]
=
$min
;
$result
[
'high'
]
=
$max
;
$result
[
'change'
]
=
sprintf
(
"%0.2f%%"
,
$change
);
return
$result
;
return
$result
;
}
}
}
}
\ 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