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
123482d1
Commit
123482d1
authored
Jun 19, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API规范
parent
a4cf284f
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
478 additions
and
15 deletions
+478
-15
BaseResponse.php
api/base/BaseResponse.php
+1
-0
CoinController.php
api/controllers/CoinController.php
+14
-8
CoinBusiness.php
common/business/CoinBusiness.php
+38
-6
Coin.php
common/models/pwallet/Coin.php
+1
-1
Coin.php
common/service/coin/Coin.php
+227
-0
CoinBTYService.php
common/service/coin/CoinBTYService.php
+150
-0
CoinFactory.php
common/service/coin/CoinFactory.php
+25
-0
CoinInterface.php
common/service/coin/CoinInterface.php
+22
-0
CoinService.php
common/service/coin/CoinService.php
+0
-0
No files found.
api/base/BaseResponse.php
View file @
123482d1
...
...
@@ -26,6 +26,7 @@ class BaseResponse extends Response
$return
[
'msg'
]
=
'数据为空'
;
}
else
{
$return
[
'code'
]
=
0
;
$return
[
'count'
]
=
count
(
$data
);
$return
[
'data'
]
=
$data
;
}
\Yii
::
$app
->
response
->
data
=
$return
;
...
...
api/controllers/CoinController.php
View file @
123482d1
...
...
@@ -84,6 +84,10 @@ class CoinController extends BaseController
Yii
::
$app
->
response
->
data
=
$data
;
}
/**
* 单币种按照id查询
* @return array|null|\yii\db\ActiveRecord
*/
public
function
actionGetCoinById
()
{
$request
=
Yii
::
$app
->
request
;
...
...
@@ -103,8 +107,7 @@ class CoinController extends BaseController
$page
=
$request
->
post
(
'page'
,
1
);
$limit
=
$request
->
post
(
'limit'
,
999
);
$condition
=
[[
'recommend'
=>
'1'
]];
$data
=
CoinBusiness
::
getApiList
(
$page
,
$limit
,
$condition
);
Yii
::
$app
->
response
->
data
=
$data
;
return
CoinBusiness
::
getApiList
(
$page
,
$limit
,
$condition
);
}
/**
...
...
@@ -120,13 +123,13 @@ class CoinController extends BaseController
if
(
$coin
)
{
$miner_fee
=
$coin
->
minerFee
;
if
(
empty
(
$miner_fee
))
{
return
[
'code'
=>
1
,
'msg'
=>
'数据为空'
];
return
[];
}
}
else
{
//如果coin为null,$coin->minerFee会抛出Trying to get property 'minerFee' of non-object",code=>8
throw
new
Exception
(
'8'
,
'币种不存在'
);
}
return
[
'code'
=>
0
,
'data'
=>
$miner_fee
];
return
[
$miner_fee
];
}
...
...
@@ -137,9 +140,13 @@ class CoinController extends BaseController
{
$names
=
Yii
::
$app
->
request
->
post
(
'names'
);
$condition
=
[[
'in'
,
'name'
,
$names
]];
Yii
::
$app
->
response
->
data
=
CoinBusiness
::
getApiListForIndex
(
$condition
);
return
CoinBusiness
::
getApiListForIndex
(
$condition
);
}
/**
* 按照名称搜索币种
* @return array
*/
public
function
actionSearchCoinByName
()
{
$request
=
Yii
::
$app
->
request
;
...
...
@@ -148,9 +155,7 @@ class CoinController extends BaseController
$limit
=
$request
->
post
(
'limit'
,
10
);
if
(
$name
)
{
$condition
=
[[
'or'
,
[
'like'
,
'name'
,
$name
],
[
'like'
,
'nickname'
,
$name
]]];
$row
=
Coin
::
getSelectList
(
$page
,
$limit
,
[
'id'
,
'sid'
,
'icon'
,
'name'
,
'nickname'
,
'chain'
],
$condition
);
return
$row
;
return
CoinBusiness
::
SearchByName
(
$page
,
$limit
,
$condition
);
}
}
}
\ No newline at end of file
common/business/CoinBusiness.php
View file @
123482d1
...
...
@@ -9,6 +9,7 @@
namespace
common\business
;
use
common\models\pwallet\Coin
;
use
common\service\coin\CoinFactory
;
use
common\service\CoinService
;
/**
...
...
@@ -70,20 +71,21 @@ class CoinBusiness
{
$rows
=
Coin
::
getList
(
$page
,
$limit
,
$condition
);
if
(
$rows
[
'count'
]
>
0
)
{
$
data
s
=
$rows
[
'data'
];
foreach
(
$
data
s
as
$key
=>
$value
)
{
$
row
s
=
$rows
[
'data'
];
foreach
(
$
row
s
as
$key
=>
$value
)
{
//获取行情信息
if
(
strtoupper
(
$value
[
'name'
])
==
'BTY'
)
{
$rows
[
'data'
][
$key
][
'quotation'
]
=
CoinService
::
quotationBTY
();
$rows
[
$key
][
'quotation'
]
=
CoinService
::
quotationBTY
();
continue
;
}
$rows
[
'data'
][
$key
][
'quotation'
]
=
CoinService
::
quotation
(
$value
[
'sid'
]);
$rows
[
$key
][
'quotation'
]
=
CoinService
::
quotation
(
$value
[
'sid'
]);
}
}
return
$rows
;
}
/**
* 根据name返回币种信息
* @param array $condition 需要的币种sid列表
* @return array
*/
...
...
@@ -93,7 +95,31 @@ class CoinBusiness
if
(
$rows
[
'count'
]
>
0
)
{
$rows
=
$rows
[
'data'
];
foreach
(
$rows
as
$key
=>
$row
)
{
$coinServer
=
new
CoinService
(
$row
[
'id'
],
$row
[
'sid'
]);
$coinServer
=
CoinFactory
::
createCoin
(
$row
[
'name'
],
$row
[
'id'
],
$row
[
'sid'
]);
$rows
[
$key
][
'sid'
]
=
ucfirst
(
$rows
[
$key
][
'sid'
]);
$rows
[
$key
][
'rmb'
]
=
$coinServer
->
getPrice
();
$rows
[
$key
][
'usd'
]
=
$coinServer
->
getDollar
();
$coinServer
->
__destruct
();
}
return
$rows
;
}
return
[];
}
/**
* 根据名称搜索
* @param int $page
* @param int $limit
* @param array $condition
* @return array|\yii\db\ActiveRecord|\yii\db\ActiveRecord[]
*/
public
static
function
SearchByName
(
$page
=
1
,
$limit
=
10
,
$condition
=
[])
{
$rows
=
Coin
::
getSelectList
(
$page
,
$limit
,
[
'id'
,
'sid'
,
'icon'
,
'name'
,
'nickname'
,
'chain'
],
$condition
);
if
(
$rows
[
'count'
]
>
0
)
{
$rows
=
$rows
[
'data'
];
foreach
(
$rows
as
$key
=>
$row
)
{
$coinServer
=
CoinFactory
::
createCoin
(
$row
[
'name'
],
$row
[
'id'
],
$row
[
'sid'
]);
$rows
[
$key
][
'sid'
]
=
ucfirst
(
$rows
[
$key
][
'sid'
]);
$rows
[
$key
][
'rmb'
]
=
$coinServer
->
getPrice
();
$rows
[
$key
][
'usd'
]
=
$coinServer
->
getDollar
();
...
...
@@ -106,6 +132,7 @@ class CoinBusiness
/**
* 获取币种的所有信息
* @return array
*/
public
static
function
getCoinAllById
(
$id
)
{
...
...
@@ -113,9 +140,13 @@ class CoinBusiness
if
(
$row
)
{
//TODO 获取行情
$row
[
'quotation'
]
=
CoinService
::
quotation
(
$row
[
'sid'
]);
//行情BTY
if
(
strtoupper
(
$row
[
'name'
])
==
'BTY'
)
{
$row
[
'quotation'
]
=
CoinService
::
quotationBTY
();
}
//TODO 获取交易所详情
$row
[
'exchange'
]
=
CoinService
::
exchange
(
$row
[
'sid'
]);
}
return
$row
?
$row
:
[];
return
$row
?
[
$row
]
:
[];
}
}
\ No newline at end of file
common/models/pwallet/Coin.php
View file @
123482d1
...
...
@@ -69,7 +69,7 @@ class Coin extends BaseActiveRecord
$query
=
$query
->
andWhere
(
$item
);
}
$count
=
$query
->
count
();
$data
=
$query
->
select
(
$columns
)
->
offset
((
$page
-
1
)
*
10
)
->
limit
(
$limit
)
->
asArray
()
->
all
();
$data
=
$query
->
select
(
$columns
)
->
offset
((
$page
-
1
)
*
$limit
)
->
limit
(
$limit
)
->
asArray
()
->
all
();
return
[
'count'
=>
$count
,
'data'
=>
$data
];
}
...
...
common/service/coin/Coin.php
0 → 100644
View file @
123482d1
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-19
* Time: 下午2:25
*/
namespace
common\service\coin
;
abstract
class
Coin
{
//行情信息
protected
$price
;
//价格
protected
$dollar
;
//价格美元
protected
$btc
;
//价格btc
protected
$high
;
//最高价
protected
$low
;
//最低价
protected
$change
;
//涨幅(跌幅)
protected
$rank
;
//流通市值排名
protected
$circulate_value_rmb
;
//流通市值人民币
protected
$circulate_value_usd
;
//流通市值美元
protected
$circulate_value_btc
;
//流通市值btc
protected
$publish_count
;
//发行总量
protected
$circulate_count
;
//流通总量
protected
$content
;
//行情html数据
public
$id
;
//币种id
public
$sid
;
//币种sid
public
$cache_key_prifx
=
'quotation_coin_'
;
/**
* @return mixed
*/
public
function
getPrice
()
{
return
$this
->
price
;
}
/**
* @param mixed $price
*/
public
function
setPrice
(
$price
)
{
$this
->
price
=
$price
;
}
/**
* @return mixed
*/
public
function
getDollar
()
{
return
$this
->
dollar
;
}
/**
* @param mixed $dollar
*/
public
function
setDollar
(
$dollar
)
{
$this
->
dollar
=
$dollar
;
}
/**
* @return mixed
*/
public
function
getBtc
()
{
return
$this
->
btc
;
}
/**
* @param mixed $btc
*/
public
function
setBtc
(
$btc
)
{
$this
->
btc
=
$btc
;
}
/**
* @return mixed
*/
public
function
getHigh
()
{
return
$this
->
high
;
}
/**
* @param mixed $high
*/
public
function
setHigh
(
$high
)
{
$this
->
high
=
$high
;
}
/**
* @return mixed
*/
public
function
getLow
()
{
return
$this
->
low
;
}
/**
* @param mixed $low
*/
public
function
setLow
(
$low
)
{
$this
->
low
=
$low
;
}
/**
* @return mixed
*/
public
function
getChange
()
{
return
$this
->
change
;
}
/**
* @param mixed $change
*/
public
function
setChange
(
$change
)
{
$this
->
change
=
$change
;
}
/**
* @return mixed
*/
public
function
getRank
()
{
return
$this
->
rank
;
}
/**
* @param mixed $rank
*/
public
function
setRank
(
$rank
)
{
$this
->
rank
=
$rank
;
}
/**
* @return mixed
*/
public
function
getCirculateValueRmb
()
{
return
$this
->
circulate_value_rmb
;
}
/**
* @param mixed $circulate_value_rmb
*/
public
function
setCirculateValueRmb
(
$circulate_value_rmb
)
{
$this
->
circulate_value_rmb
=
$circulate_value_rmb
;
}
/**
* @return mixed
*/
public
function
getCirculateValueUsd
()
{
return
$this
->
circulate_value_usd
;
}
/**
* @param mixed $circulate_value_usd
*/
public
function
setCirculateValueUsd
(
$circulate_value_usd
)
{
$this
->
circulate_value_usd
=
$circulate_value_usd
;
}
/**
* @return mixed
*/
public
function
getCirculateValueBtc
()
{
return
$this
->
circulate_value_btc
;
}
/**
* @param mixed $circulate_value_btc
*/
public
function
setCirculateValueBtc
(
$circulate_value_btc
)
{
$this
->
circulate_value_btc
=
$circulate_value_btc
;
}
/**
* @return mixed
*/
public
function
getPublishCount
()
{
return
$this
->
publish_count
;
}
/**
* @param mixed $publish_count
*/
public
function
setPublishCount
(
$publish_count
)
{
$this
->
publish_count
=
$publish_count
;
}
/**
* @return mixed
*/
public
function
getCirculateCount
()
{
return
$this
->
circulate_count
;
}
/**
* @param mixed $circulate_count
*/
public
function
setCirculateCount
(
$circulate_count
)
{
$this
->
circulate_count
=
$circulate_count
;
}
}
\ No newline at end of file
common/service/coin/CoinBTYService.php
0 → 100644
View file @
123482d1
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-19
* Time: 下午2:20
*/
namespace
common\service\coin
;
class
CoinBTYService
extends
Coin
implements
CoinInterface
{
public
function
__construct
(
$id
,
$sid
)
{
}
public
function
init
()
{
// TODO: Implement init() method.
}
public
function
__destruct
()
{
// TODO: Implement __destruct() method.
}
public
function
getPrice
()
{
return
parent
::
getPrice
();
// TODO: Change the autogenerated stub
}
public
function
setPrice
(
$price
)
{
parent
::
setPrice
(
$price
);
// TODO: Change the autogenerated stub
}
public
function
getDollar
()
{
return
parent
::
getDollar
();
// TODO: Change the autogenerated stub
}
public
function
setDollar
(
$dollar
)
{
parent
::
setDollar
(
$dollar
);
// TODO: Change the autogenerated stub
}
public
function
getBtc
()
{
return
parent
::
getBtc
();
// TODO: Change the autogenerated stub
}
public
function
setBtc
(
$btc
)
{
parent
::
setBtc
(
$btc
);
// TODO: Change the autogenerated stub
}
public
function
getHigh
()
{
return
parent
::
getHigh
();
// TODO: Change the autogenerated stub
}
public
function
setHigh
(
$high
)
{
parent
::
setHigh
(
$high
);
// TODO: Change the autogenerated stub
}
public
function
getLow
()
{
return
parent
::
getLow
();
// TODO: Change the autogenerated stub
}
public
function
setLow
(
$low
)
{
parent
::
setLow
(
$low
);
// TODO: Change the autogenerated stub
}
public
function
getChange
()
{
return
parent
::
getChange
();
// TODO: Change the autogenerated stub
}
public
function
setChange
(
$change
)
{
parent
::
setChange
(
$change
);
// TODO: Change the autogenerated stub
}
public
function
getRank
()
{
return
parent
::
getRank
();
// TODO: Change the autogenerated stub
}
public
function
setRank
(
$rank
)
{
parent
::
setRank
(
$rank
);
// TODO: Change the autogenerated stub
}
public
function
getCirculateValueRmb
()
{
return
parent
::
getCirculateValueRmb
();
// TODO: Change the autogenerated stub
}
public
function
setCirculateValueRmb
(
$circulate_value_rmb
)
{
parent
::
setCirculateValueRmb
(
$circulate_value_rmb
);
// TODO: Change the autogenerated stub
}
public
function
getCirculateValueUsd
()
{
return
parent
::
getCirculateValueUsd
();
// TODO: Change the autogenerated stub
}
public
function
setCirculateValueUsd
(
$circulate_value_usd
)
{
parent
::
setCirculateValueUsd
(
$circulate_value_usd
);
// TODO: Change the autogenerated stub
}
public
function
getCirculateValueBtc
()
{
return
parent
::
getCirculateValueBtc
();
// TODO: Change the autogenerated stub
}
public
function
setCirculateValueBtc
(
$circulate_value_btc
)
{
parent
::
setCirculateValueBtc
(
$circulate_value_btc
);
// TODO: Change the autogenerated stub
}
public
function
getPublishCount
()
{
return
parent
::
getPublishCount
();
// TODO: Change the autogenerated stub
}
public
function
setPublishCount
(
$publish_count
)
{
parent
::
setPublishCount
(
$publish_count
);
// TODO: Change the autogenerated stub
}
public
function
getCirculateCount
()
{
return
parent
::
getCirculateCount
();
// TODO: Change the autogenerated stub
}
public
function
setCirculateCount
(
$circulate_count
)
{
parent
::
setCirculateCount
(
$circulate_count
);
// TODO: Change the autogenerated stub
}
}
\ No newline at end of file
common/service/coin/CoinFactory.php
0 → 100644
View file @
123482d1
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-19
* Time: 下午1:56
*/
namespace
common\service\coin
;
class
CoinFactory
{
public
static
function
createCoin
(
$coinName
=
''
,
$id
,
$sid
)
{
$coinName
=
strtoupper
(
$coinName
);
$className
=
__NAMESPACE__
.
'\Coin'
.
$coinName
.
'Service'
;
if
(
class_exists
(
$className
))
{
return
new
$className
(
$id
,
$sid
);
}
else
{
return
new
CoinService
(
$id
,
$sid
);
}
}
}
\ No newline at end of file
common/service/coin/CoinInterface.php
0 → 100644
View file @
123482d1
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-19
* Time: 下午2:12
*/
namespace
common\service\coin
;
interface
CoinInterface
{
//币种实例化接口
public
function
__construct
(
$id
,
$sid
);
//币种初始化
public
function
init
();
//币种销毁
public
function
__destruct
();
}
\ No newline at end of file
common/service/coin/CoinService.php
0 → 100644
View file @
123482d1
This diff is collapsed.
Click to expand it.
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