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
85cec1b1
Commit
85cec1b1
authored
Mar 10, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/optimize' into develop
parents
673ae21f
5119bbc5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
27 deletions
+61
-27
RecommendCoinController.php
api/controllers/RecommendCoinController.php
+61
-27
No files found.
api/controllers/RecommendCoinController.php
View file @
85cec1b1
...
...
@@ -10,7 +10,7 @@ use common\models\psources\WalletRecommendCategory;
class
RecommendCoinController
extends
BaseController
{
public
function
action
Index
()
public
function
action
Top
()
{
$platform_id
=
$this
->
platform_id
;
if
(
false
==
$platform_id
)
{
...
...
@@ -19,21 +19,14 @@ class RecommendCoinController extends BaseController
goto
doEnd
;
}
$type
=
Yii
::
$app
->
request
->
get
(
'type'
,
1
);
$is_top
=
Yii
::
$app
->
request
->
get
(
'is_top'
,
''
);
if
(
false
==
$is_top
)
{
$recommend_category
=
WalletRecommendCategory
::
find
()
->
select
(
'id, name'
)
->
where
([
'wallet_type'
=>
(
int
)
$type
,
'platform_id'
=>
(
int
)
$platform_id
])
->
andWhere
([
'>'
,
'sort'
,
1
])
->
orderBy
(
'sort'
)
->
asArray
()
->
all
();
}
else
{
$recommend_category
=
WalletRecommendCategory
::
find
()
->
select
(
'id, name'
)
->
where
([
'wallet_type'
=>
(
int
)
$type
,
'platform_id'
=>
(
int
)
$platform_id
,
'sort'
=>
1
])
->
orderBy
(
'sort'
)
->
limit
(
1
)
->
asArray
()
->
all
();
}
$recommend_category
=
WalletRecommendCategory
::
find
()
->
select
(
'id, name'
)
->
where
([
'wallet_type'
=>
(
int
)
$type
,
'platform_id'
=>
(
int
)
$platform_id
])
->
orderBy
(
'sort'
)
->
limit
(
1
)
->
asArray
()
->
all
();
if
(
empty
(
$recommend_category
))
{
goto
doEnd
;
}
$ticker
=
[
'low'
=>
0
,
'high'
=>
0
,
'last'
=>
0
,
'open'
=>
0
,
'vol'
=>
0
,
'rmb'
=>
0
,
'usd'
=>
0
];
foreach
(
$recommend_category
as
&
$category
)
{
$name
=
json_decode
(
$category
[
'name'
],
true
);
$category
[
'name'
]
=
isset
(
$name
[
$this
->
lang
])
?
$name
[
$this
->
lang
]
:
''
;
...
...
@@ -56,24 +49,65 @@ class RecommendCoinController extends BaseController
$category
[
'items'
]
=
$items
;
}
if
(
!
empty
(
$is_top
))
{
$result
=
$recommend_category
[
0
][
'items'
];
//获取行情信息
$coin_names
=
array_column
(
$result
,
'name'
);
$coin_names
=
array_merge
(
$coin_names
,
array_column
(
$result
,
'chain'
));
$coin_quotations
=
ExchangeBusiness
::
getQuatationByNames
(
$coin_names
);
$result
=
$recommend_category
[
0
][
'items'
];
//获取行情信息
$coin_names
=
array_column
(
$result
,
'name'
);
$coin_names
=
array_merge
(
$coin_names
,
array_column
(
$result
,
'chain'
));
$coin_quotations
=
ExchangeBusiness
::
getQuatationByNames
(
$coin_names
);
$ticker
=
[
'low'
=>
0
,
'high'
=>
0
,
'last'
=>
0
,
'open'
=>
0
,
'vol'
=>
0
,
'rmb'
=>
0
,
'usd'
=>
0
];
foreach
(
$result
as
$key
=>
&
$val
)
{
$val
[
'chain_quotation'
]
=
isset
(
$coin_quotations
[
strtoupper
(
$val
[
'chain'
])])
?
$coin_quotations
[
strtoupper
(
$val
[
'chain'
])]
:
[];
$result
[
$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
;
}
$ticker
=
[
'low'
=>
0
,
'high'
=>
0
,
'last'
=>
0
,
'open'
=>
0
,
'vol'
=>
0
,
'rmb'
=>
0
,
'usd'
=>
0
];
foreach
(
$result
as
$key
=>
&
$val
)
{
$val
[
'chain_quotation'
]
=
isset
(
$coin_quotations
[
strtoupper
(
$val
[
'chain'
])])
?
$coin_quotations
[
strtoupper
(
$val
[
'chain'
])]
:
[];
$result
[
$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
;
}
$this
->
data
=
$result
;
doEnd
:
return
[
'code'
=>
$this
->
code
,
'data'
=>
$this
->
data
,
'msg'
=>
$this
->
msg
];
}
public
function
actionIndex
()
{
$platform_id
=
$this
->
platform_id
;
if
(
false
==
$platform_id
)
{
$this
->
code
=
-
1
;
$this
->
msg
=
'参数错误'
;
goto
doEnd
;
}
$type
=
Yii
::
$app
->
request
->
get
(
'type'
,
1
);
$this
->
data
=
$result
;
$recommend_category
=
WalletRecommendCategory
::
find
()
->
select
(
'id, name'
)
->
where
([
'wallet_type'
=>
(
int
)
$type
,
'platform_id'
=>
(
int
)
$platform_id
])
->
andWhere
([
'>'
,
'sort'
,
1
])
->
orderBy
(
'sort'
)
->
asArray
()
->
all
();
if
(
empty
(
$recommend_category
))
{
goto
doEnd
;
}
foreach
(
$recommend_category
as
&
$category
)
{
$name
=
json_decode
(
$category
[
'name'
],
true
);
$category
[
'name'
]
=
isset
(
$name
[
$this
->
lang
])
?
$name
[
$this
->
lang
]
:
''
;
$recommend_coin
=
WalletRecommendCoin
::
find
()
->
where
([
'category_id'
=>
$category
[
'id'
]])
->
all
();
$items
=
[];
foreach
(
$recommend_coin
as
$coin
)
{
$temp
[
'icon'
]
=
$coin
->
coin
[
'icon'
];
$temp
[
'name'
]
=
$coin
->
coin
[
'name'
];
$temp
[
'platform'
]
=
$coin
->
coin
[
'platform'
];
$temp
[
'chain'
]
=
$coin
->
coin
[
'chain'
];
$temp
[
'treaty'
]
=
$coin
->
coin
[
'treaty'
];
$temp
[
'exchange_id'
]
=
$coin
->
coin
[
'exchange_id'
];
$nickname
=
json_decode
(
$coin
->
coin
[
'nickname'
],
true
);
$temp
[
'nickname'
]
=
isset
(
$nickname
[
$this
->
lang
])
?
$nickname
[
$this
->
lang
]
:
''
;
$introduce
=
json_decode
(
$coin
->
coin
[
'introduce'
],
true
);
$temp
[
'introduce'
]
=
isset
(
$introduce
[
$this
->
lang
])
?
$introduce
[
$this
->
lang
]
:
''
;
array_push
(
$items
,
$temp
);
}
$category
[
'items'
]
=
$items
;
}
$this
->
data
=
$recommend_category
;
doEnd
:
...
...
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