0) { $datas = $rows['data']; foreach ($datas as $key => $value) { //获取交易所信息 $coin = CoinFactory::createCoin($value['name'], $value['id'], $value['sid']); $rows['data'][$key]['exchange'] = $coin->exchange_count(); $coin->__destruct(); } } return $rows; } /** * 返回交易所列表 * * @param $id * @return array */ public static function getExchangeListById($id = 0) { if ($id) { $coin = Coin::findOne(['id' => $id]); if ($coin) { $model = CoinFactory::createCoin($coin->name, $coin->id, $coin->sid); $datas = $model->exchange(); $model->__destruct(); if ($datas['count'] > 0) { return $datas['data']; } } } return []; } /** * api获取行情列表 * @param int $page * @param int $limit * @param array $condition * @return array */ public static function getApiList($page = 1, $limit = 10, $condition = []) { $rows = Coin::getList($page, $limit, $condition); if ($rows['count'] > 0) { $rows = $rows['data']; foreach ($rows as $key => $value) { $coin = CoinFactory::createCoin($value['name'], $value['id'], $value['sid']); $rows[$key]['quotation'] = $coin->quotation(); $coin->__destruct(); } } return $rows; } /** * 根据name返回币种信息 * @param array $condition 需要的币种sid列表 * @return array */ public static function getApiListForIndex($condition = []) { $rows = Coin::getSelectList(1, 999, ['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(); $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(); $coinServer->__destruct(); } return $rows; } return []; } /** * 获取币种的所有信息 * @param integer $id * @return array */ public static function getCoinAllById($id) { $row = Coin::find()->where(['id' => $id])->asArray()->One(); if ($row) { $coin = CoinFactory::createCoin($row['name'], $row['id'], $row['sid']); $row['quotation'] = $coin->quotation(); $row['exchange'] = $coin->exchange(); $coin->__destruct(); } return $row ? [$row] : []; } }