Commit 53037b1d authored by rlgy's avatar rlgy

init

parent 537d7ee7
...@@ -51,13 +51,13 @@ class CoinController extends BaseController ...@@ -51,13 +51,13 @@ class CoinController extends BaseController
$condition = [['recommend' => '1']]; $condition = [['recommend' => '1']];
$result = ExchangeBusiness::getApiListForIndex($page, $limit, $condition); $result = ExchangeBusiness::getApiListForIndex($page, $limit, $condition);
if ($result) { if ($result) {
$chains = array_unique(array_column($result['data'], 'chain')); $chains = array_unique(array_column($result['data'], 'chain'));
$chain_quotation=[]; $chain_quotation = [];
foreach ($chains as $key => $value) { foreach ($chains as $key => $value) {
$chain_quotation[$value]=ExchangeBusiness::getquatation($value); $chain_quotation[$value] = ExchangeBusiness::getquatation($value);
} }
foreach ($result['data'] as $key => &$value) { foreach ($result['data'] as $key => &$value) {
$value['chain_quotation']=$chain_quotation[$value['chain']]; $value['chain_quotation'] = $chain_quotation[$value['chain']];
} }
return $result; return $result;
} }
...@@ -97,13 +97,13 @@ class CoinController extends BaseController ...@@ -97,13 +97,13 @@ class CoinController extends BaseController
$condition = [['in', 'name', $names]]; $condition = [['in', 'name', $names]];
$result = ExchangeBusiness::getApiListForIndex(1, 999, $condition); $result = ExchangeBusiness::getApiListForIndex(1, 999, $condition);
if ($result) { if ($result) {
$chains = array_unique(array_column($result['data'], 'chain')); $chains = array_unique(array_column($result['data'], 'chain'));
$chain_quotation=[]; $chain_quotation = [];
foreach ($chains as $key => $value) { foreach ($chains as $key => $value) {
$chain_quotation[$value]=ExchangeBusiness::getquatation($value); $chain_quotation[$value] = ExchangeBusiness::getquatation($value);
} }
foreach ($result['data'] as $key => &$value) { foreach ($result['data'] as $key => &$value) {
$value['chain_quotation']=$chain_quotation[$value['chain']]; $value['chain_quotation'] = $chain_quotation[$value['chain']];
} }
return $result; return $result;
} }
...@@ -119,20 +119,25 @@ class CoinController extends BaseController ...@@ -119,20 +119,25 @@ class CoinController extends BaseController
$name = $request->post('name', ''); $name = $request->post('name', '');
$page = $request->post('page', 1); $page = $request->post('page', 1);
$limit = $request->post('limit', 10); $limit = $request->post('limit', 10);
if ($name) {
$condition = [['!=', 'chain', 'other'], ['or', ['like', 'name', $name], ['like', 'nickname', $name]]]; $condition = [['!=', 'chain', 'other']];
$result = ExchangeBusiness::SearchByName($page, $limit, $condition); if (!empty($name)) {
if ($result) { $condition[] = ['or', ['like', 'name', $name], ['like', 'nickname', $name]];
$chains = array_unique(array_column($result,'chain')); }
$chain_quotation=[]; $result = ExchangeBusiness::SearchByName($page, $limit, $condition);
foreach ($chains as $key => $value) {
$chain_quotation[$value]=ExchangeBusiness::getquatation($value); $total = $result['total'];
} $result = $result['data'];
foreach ($result as $key => $value) { if ($result) {
$result[$key]['chain_quotation']=$chain_quotation[$value['chain']]; $chains = array_unique(array_column($result, 'chain'));
} $chain_quotation = [];
return $result; foreach ($chains as $key => $value) {
$chain_quotation[$value] = ExchangeBusiness::getquatation($value);
}
foreach ($result as $key => $value) {
$result[$key]['chain_quotation'] = $chain_quotation[$value['chain']];
} }
return ['code' => 0, 'count' => $total, 'data' => $result];
} }
} }
......
...@@ -121,7 +121,8 @@ class ExchangeBusiness ...@@ -121,7 +121,8 @@ class ExchangeBusiness
*/ */
public static function getApiListForIndex($page = 1, $limit = 999, $condition = []) public static function getApiListForIndex($page = 1, $limit = 999, $condition = [])
{ {
$rows = Coin::getSelectList($page, $limit, ['id', 'sid', 'icon', 'name', 'nickname', 'platform', 'chain'], $condition); $rows = Coin::getSelectList($page, $limit, ['id', 'sid', 'icon', 'name', 'nickname', 'platform', 'chain'],
$condition);
$count = 0; $count = 0;
if (!empty($rows) && is_array($rows) && array_key_exists('count', $rows)) { if (!empty($rows) && is_array($rows) && array_key_exists('count', $rows)) {
$count = $rows['count']; $count = $rows['count'];
...@@ -166,13 +167,15 @@ class ExchangeBusiness ...@@ -166,13 +167,15 @@ class ExchangeBusiness
*/ */
public static function SearchByName($page = 1, $limit = 10, $condition = []) public static function SearchByName($page = 1, $limit = 10, $condition = [])
{ {
$rows = Coin::getSelectList($page, $limit, ['id', 'sid', 'icon', 'name', 'nickname', 'platform', 'chain'], $condition); $rows = Coin::getSelectList($page, $limit, ['id', 'sid', 'icon', 'name', 'nickname', 'platform', 'chain'],
$condition);
if ($rows['count'] > 0) { if ($rows['count'] > 0) {
$rows = $rows['data']; $total = $rows['count'];
$rows = $rows['data'];
foreach ($rows as $key => $row) { foreach ($rows as $key => $row) {
$rows[$key]['sid'] = ucfirst($rows[$key]['sid']); $rows[$key]['sid'] = ucfirst($rows[$key]['sid']);
} }
return $rows; return ['total' => $total, 'data' => $rows];
} }
return []; return [];
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment