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
ad9a621e
Commit
ad9a621e
authored
Jan 14, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
币种接口
parent
333d9ec7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
127 additions
and
20 deletions
+127
-20
RecommendCoinController.php
api/controllers/RecommendCoinController.php
+7
-1
WalletCoinController.php
api/controllers/WalletCoinController.php
+120
-19
No files found.
api/controllers/RecommendCoinController.php
View file @
ad9a621e
...
...
@@ -9,10 +9,16 @@ use common\models\psources\RecommendCoin;
class
RecommendCoinController
extends
BaseController
{
/**
* 获取推荐币种
* @param integer recommend 1首页推介,2次页推介
* @return array
*/
public
function
actionIndex
()
{
$recommend
=
Yii
::
$app
->
request
->
post
(
'recommend'
,
0
);
$platform_id
=
Yii
::
$app
->
request
->
post
(
'platform_id'
,
0
);
$header
=
Yii
::
$app
->
request
->
headers
;
$platform_id
=
$header
[
'FZM-PLATFORM-ID'
]
??
null
;
if
(
false
==
$recommend
||
false
==
$platform_id
)
{
$this
->
code
=
-
1
;
$this
->
msg
=
'参数错误'
;
...
...
api/controllers/WalletCoinController.php
View file @
ad9a621e
...
...
@@ -2,15 +2,19 @@
namespace
api\controllers
;
use
common\models\psources\Coin
;
use
common\models\psources\CoinCurrency
;
use
Yii
;
use
api\base\BaseController
;
use
common\business\ExchangeBusiness
;
use
common\models\psources\RecommendCoin
;
use
common\models\psources\WalletCoin
;
use
common\models\psources\CoinCurrency
;
class
WalletCoinController
extends
BaseController
{
/**
* 币种列表
* @param array names
* @return array
*/
public
function
actionIndex
()
{
$header
=
Yii
::
$app
->
request
->
headers
;
...
...
@@ -34,28 +38,27 @@ class WalletCoinController extends BaseController
$condition
[]
=
$val
;
}
}
$this
->
data
=
[];
if
(
count
(
$condition
[
0
])
>
1
)
{
foreach
(
$condition
as
$val
)
{
if
(
'null'
==
$val
[
1
]
||
'coin'
==
$val
[
1
])
{
$this
->
data
[]
=
Coin
::
find
()
->
select
(
'id,sid,icon,name,optional_name,nickname,introduce,platform,chain,address as contract_address,treaty'
)
->
where
([
'name'
=>
$val
[
0
]])
if
(
is_array
(
$val
))
{
$model
=
WalletCoin
::
find
()
->
select
(
'id,sid,icon,name,nickname,introduce,platform,chain,address as contract_address,treaty'
)
->
where
([
'name'
=>
$val
[
0
],
'platform_id'
=>
(
int
)
$platform_id
])
->
andWhere
([
'platform'
=>
$val
[
1
]])
->
asArray
()
->
one
();
continue
;
}
$this
->
data
[]
=
Coin
::
find
()
->
select
(
'id,sid,icon,name,optional_name,nickname,introduce,platform,chain,address as contract_address,treaty'
)
->
where
([
'name'
=>
$val
[
0
]])
->
andWhere
([
'platform'
=>
$val
[
1
]])
if
(
is_string
(
$val
))
{
$model
=
WalletCoin
::
find
()
->
select
(
'id,sid,icon,name,nickname,introduce,platform,chain,address as contract_address,treaty'
)
->
where
([
'name'
=>
$val
,
'platform_id'
=>
(
int
)
$platform_id
])
->
asArray
()
->
one
();
}
}
else
{
$this
->
data
=
Coin
::
find
()
->
select
(
'id,sid,icon,name,optional_name,nickname,introduce,platform,chain,address as contract_address,treaty'
)
->
where
([
'in'
,
'name'
,
$condition
])
->
asArray
()
->
all
();
if
(
!
empty
(
$model
))
{
$this
->
data
=
array_merge
(
$this
->
data
,
[
$model
]);
}
}
if
(
empty
(
$this
->
data
))
{
goto
doEnd
;
}
...
...
@@ -65,8 +68,6 @@ class WalletCoinController extends BaseController
$chains_symbols
=
array_keys
(
array_flip
(
$chains
)
+
array_flip
(
$symbol
));
$coin_quotations
=
ExchangeBusiness
::
getQuatationByNames
(
$chains_symbols
);
$last
[]
=
1
;
$currency
=
CoinCurrency
::
find
()
->
where
([
'pj_id'
=>
$this
->
currency_id
])
->
one
();
if
(
false
!=
$currency
)
{
...
...
@@ -86,7 +87,6 @@ class WalletCoinController extends BaseController
$val
[
'introduce'
]
=
isset
(
$introduce
[
$this
->
lang
])
?
$introduce
[
$this
->
lang
]
:
''
;
$this
->
data
[
$key
]
=
array_merge
(
$val
,
isset
(
$coin_quotations
[
strtoupper
(
$val
[
'name'
])])
?
$coin_quotations
[
strtoupper
(
$val
[
'name'
])]
:
$ticker
);
$val
[
'chain_rmb'
]
=
isset
(
$val
[
'chain_quotation'
][
'rmb'
])
?
$val
[
'chain_quotation'
][
'rmb'
]
:
0
;
$val
[
'chain_usd'
]
=
isset
(
$val
[
'chain_quotation'
][
'usd'
])
?
$val
[
'chain_quotation'
][
'usd'
]
:
0
;
$val
[
'chain_country_rate'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$last
[
0
]
*
$val
[
'chain_rmb'
]);
...
...
@@ -96,4 +96,104 @@ class WalletCoinController extends BaseController
doEnd
:
return
[
'code'
=>
$this
->
code
,
'data'
=>
$this
->
data
,
'msg'
=>
$this
->
msg
];
}
/**
* 币种搜索
* @param string chain
* @param string keyword
* @return array
*/
public
function
actionSearch
()
{
$params
=
Yii
::
$app
->
request
->
post
();
$chain
=
isset
(
$params
[
'chain'
])
?
$params
[
'chain'
]
:
''
;
$keyword
=
isset
(
$params
[
'keyword'
])
?
$params
[
'keyword'
]
:
''
;
$header
=
Yii
::
$app
->
request
->
headers
;
$platform_id
=
$header
[
'FZM-PLATFORM-ID'
]
??
null
;
if
(
false
==
$platform_id
)
{
$this
->
code
=
-
1
;
$this
->
msg
=
'参数错误'
;
goto
doEnd
;
}
$page
=
empty
(
$params
[
'page'
])
?
1
:
$params
[
'page'
];
$limit
=
empty
(
$params
[
'limit'
])
?
10
:
$params
[
'limit'
];
$query
=
WalletCoin
::
find
()
->
select
(
'id, sid, icon, name, nickname, platform, chain, address as contract_address, treaty'
)
->
where
([
'>'
,
"find_in_set(
$platform_id
, platform_id)"
,
0
])
->
orderBy
(
'id'
);
if
(
false
!=
$chain
)
{
$query
->
andWhere
([
'chain'
=>
$chain
]);
}
if
(
false
!=
$keyword
)
{
$query
->
andWhere
([
'or'
,
[
'like'
,
'address'
,
$keyword
],
[
'like'
,
'name'
,
$keyword
]]);
}
$this
->
data
=
$query
->
offset
((
$page
-
1
)
*
$limit
)
->
limit
(
$limit
)
->
asArray
()
->
all
();
if
(
false
!=
$this
->
data
)
{
$chains
=
array_unique
(
array_column
(
$this
->
data
,
'chain'
));
$chain_quotation
=
[];
foreach
(
$chains
as
$key
=>
$value
)
{
$chain_quotation
[
$value
]
=
ExchangeBusiness
::
getquatation
(
$value
);
}
foreach
(
$this
->
data
as
$key
=>
$value
)
{
$this
->
data
[
$key
][
'chain_quotation'
]
=
$chain_quotation
[
$value
[
'chain'
]]
?:
null
;
}
foreach
(
$this
->
data
as
$key
=>
&
$value
)
{
$nickname
=
json_decode
(
$value
[
'nickname'
],
true
);
$value
[
'nickname'
]
=
isset
(
$nickname
[
$this
->
lang
])
?
$nickname
[
$this
->
lang
]
:
''
;
$value
[
'chain_rmb'
]
=
isset
(
$value
[
'chain_quotation'
][
'rmb'
])
?
$value
[
'chain_quotation'
][
'rmb'
]
:
0
;
$value
[
'chain_usd'
]
=
isset
(
$value
[
'chain_quotation'
][
'usd'
])
?
$value
[
'chain_quotation'
][
'usd'
]
:
0
;
}
}
doEnd
:
return
[
'code'
=>
$this
->
code
,
'data'
=>
$this
->
data
,
'msg'
=>
$this
->
msg
];
}
/**
* 获取币种简介
* @param integer id
* @return array
*/
public
function
actionGetCoinById
()
{
$params
=
Yii
::
$app
->
request
->
post
();
$id
=
isset
(
$params
[
'id'
])
?
$params
[
'id'
]
:
0
;
$header
=
Yii
::
$app
->
request
->
headers
;
$platform_id
=
$header
[
'FZM-PLATFORM-ID'
]
??
null
;
if
(
false
==
$platform_id
||
false
==
$id
)
{
$this
->
code
=
-
1
;
$this
->
msg
=
'参数错误'
;
goto
doEnd
;
}
$this
->
data
=
WalletCoin
::
find
()
->
where
([
'id'
=>
$id
,
'platform_id'
=>
$platform_id
])
->
asArray
()
->
one
();
if
(
empty
(
$this
->
data
))
{
goto
doEnd
;
}
$quotation
=
ExchangeBusiness
::
getquatation
(
$this
->
data
[
'name'
]);
if
(
$quotation
)
{
$tikerdata
[
'price'
]
=
$quotation
[
'rmb'
];
$tikerdata
[
'dollar'
]
=
$quotation
[
'usd'
];
}
else
{
$tikerdata
[
'price'
]
=
0
;
$tikerdata
[
'dollar'
]
=
0
;
}
$this
->
data
[
'quotation'
]
=
$tikerdata
;
$this
->
data
[
'quotation'
][
'publish_count'
]
=
$this
->
data
[
'publish_count'
];
$this
->
data
[
'quotation'
][
'circulate_count'
]
=
$this
->
data
[
'circulate_count'
];
$nickname
=
json_decode
(
$this
->
data
[
'nickname'
],
true
);
$this
->
data
[
'nickname'
]
=
isset
(
$nickname
[
$this
->
lang
])
?
$nickname
[
$this
->
lang
]
:
''
;
$introduce
=
json_decode
(
$this
->
data
[
'introduce'
],
true
);
$this
->
data
[
'introduce'
]
=
isset
(
$introduce
[
$this
->
lang
])
?
$introduce
[
$this
->
lang
]
:
''
;
doEnd
:
return
[
'code'
=>
$this
->
code
,
'data'
=>
$this
->
data
,
'msg'
=>
$this
->
msg
];
}
}
\ 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