Commit 9de92d26 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/optimize' into 'master'

fix See merge request !498
parents 1344840e 9fb3eb2d
......@@ -250,7 +250,7 @@ class CoinController extends BaseController
foreach ($chains as $key => $value) {
$chain_quotation[$value] = ExchangeBusiness::getquatation($value);
}
$last[] = 1;
$last[] = $rate[] = 1;
$currency = CoinCurrency::find()->where(['pj_id' => $this->currency_id])->one();
if (false != $currency) {
if (1111 == $this->currency_id) {
......@@ -259,11 +259,12 @@ class CoinController extends BaseController
if (Yii::$app->redis->hkeys('quotation_go_CNY_USD')) {
$last[0] = 1 / Yii::$app->redis->hmget('quotation_go_CNY_USD', 'last')[0];
} else {
$last = Yii::$app->redis_currency->hmget('quotation_boc_' . 'CNY_' . $currency->symbol, 'last');
$last = Yii::$app->redis_currency->hmget('quotation_currency_' . 'USD_' . $currency->symbol, 'last');
}
} else {
$last = Yii::$app->redis_currency->hmget('quotation_boc_' . 'CNY_' . $currency->symbol, 'last');
$last = Yii::$app->redis_currency->hmget('quotation_currency_' . 'USD_' . $currency->symbol, 'last');
}
$rate = Yii::$app->redis_currency->hmget('quotation_currency_' . 'CNY_' . $currency->symbol, 'last');
}
foreach ($result['data'] as $key => &$value) {
......@@ -275,8 +276,8 @@ class CoinController extends BaseController
$value['chain_quotation'] = $chain_quotation[$value['chain']] ?: null;
$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;
$value['chain_country_rate'] = (float)sprintf("%0.4f", $last[0] * $value['chain_rmb']);
$value['country_rate'] = (false == $currency) ? $value['rmb'] : (float)sprintf("%0.4f", $last[0] * $value['rmb']);
$value['chain_country_rate'] = (float)sprintf("%0.4f", $rate[0] * $value['chain_rmb']);
$value['country_rate'] = (false == $currency) ? $value['rmb'] : (float)sprintf("%0.4f", $last[0] * $value['last']);
}
return $result;
}
......
......@@ -432,7 +432,7 @@ class TickerController extends BaseController
if (1111 == $val->currency->pj_id) {
$rate = (string)1;
} else {
list($rate) = Yii::$app->redis_currency->hmget('quotation_boc_' . 'CNY_' . $val->currency->symbol, 'last');
list($rate) = Yii::$app->redis_currency->hmget('quotation_currency_' . 'CNY_' . $val->currency->symbol, 'last');
}
$val->pj_id = $val->currency->pj_id;
$val->pj_name = $val->currency->pj_name;
......
......@@ -79,14 +79,11 @@ class WalletCoinController extends BaseController
$chains_symbols = array_keys(array_flip($chains) + array_flip($symbol));
$coin_quotations = ExchangeBusiness::getQuatationByNames($chains_symbols);
$last[] = 1;
$last[] = $rate[] = 1;
$currency = CoinCurrency::find()->where(['pj_id' => $this->currency_id])->one();
if (false != $currency) {
if (1111 == $this->currency_id) {
$last[] = 1;
} else {
$last = Yii::$app->redis_currency->hmget('quotation_boc_' . 'CNY_' . $currency->symbol, 'last');
}
$rate = Yii::$app->redis_currency->hmget('quotation_currency_' . 'CNY_' . $currency->symbol, 'last');
$last = Yii::$app->redis_currency->hmget('quotation_currency_' . 'USD_' . $currency->symbol, 'last');
}
$ticker = ['low' => 0, 'high' => 0, 'last' => 0, 'open' => 0, 'vol' => 0, 'rmb' => 0, 'usd' => 0];
......@@ -100,8 +97,8 @@ class WalletCoinController extends BaseController
$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']);
$val['country_rate'] = (false == $currency) ? $val['rmb'] : (float)sprintf("%0.4f", $last[0] * $val['rmb']);
$val['chain_country_rate'] = (float)sprintf("%0.4f", $rate[0] * $val['chain_rmb']);
$val['country_rate'] = (false == $currency) ? $val['rmb'] : (float)sprintf("%0.4f", $last[0] * $val['last']);
unset($val['chain_quotation']);
}
......
......@@ -38,38 +38,43 @@ class TickerController extends Controller
{
$ticker_builder = ExchangeFactory::createExchange($exchange);
$ticker_builder->setQuotation();
echo date('Y-m-d H:i:s') . $exchange. '更新成功' . PHP_EOL;
echo date('Y-m-d H:i:s') . $exchange . '更新成功' . PHP_EOL;
return 0;
}
public function actionCurrency()
{
$currency_model = CoinSupportedCurrency::find()->groupBy('currency_id')->all();
$curl = new Curl();
$curl->setHeaders([
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0',
'Host' => 'cc-api.oanda.com',
'Origin' => 'https://www.oanda.com',
'Sec-Fetch-Dest' => 'empty',
'Sec-Fetch-Mode' => 'cors',
'Sec-Fetch-Site' => 'same-site',
'TE' => 'trailers'
]);
$currency_model = CoinSupportedCurrency::find()->groupBy('currency_id')->all();
$start_date = date("Y-m-d", strtotime("-1 day"));
$end_data = date("Y-m-d");
foreach ($currency_model as $val) {
if (1111 == $val->currency->pj_id) continue;
go(function () use ($val, $curl) {
\Co::sleep(0.5);
$response = $curl->setPostParams([
'erectDate' => '',
'nothing' => '',
'pjname' => $val->currency->pj_name
])->post('https://srh.bankofchina.com/search/whpj/search_cn.jsp');
$url = 'https://cc-api.oanda.com/cc-api/v1/currencies?base=USD&quote=' . $val->currency->symbol . '&data_type=general_currency_pair&start_date=' . $start_date . '&end_date=' . $end_data;
$content = $curl->get($url, false);
if (is_array($content) && isset($content['response'])) {
$key = 'quotation_currency_' . 'USD_' . $val->currency->symbol;
Yii::$app->redis_currency->hmset($key, 'low', $content['response'][0]['low_ask'], 'high', $content['response'][0]['high_ask'], 'last', $content['response'][0]['average_ask'], 'open', $content['response'][0]['average_ask']);
Yii::$app->redis_currency->sadd('supported_symbol_currency', $content['response'][0]['base_currency'] . '_' . $content['response'][0]['quote_currency']);
}
$response = iconv('UTF-8', 'GBK//TRANSLIT', $response);
$html = HtmlDomParser::str_get_html($response);
$div = ($html->find('div.BOC_main'));
if ($div->find('td')) {
foreach ($div->find('td') as $key => $e) {
if ($key == 5) {
$key = 'quotation_boc_' . 'CNY_' . $val->currency->symbol;
$currency = rtrim(sprintf('%.6f', 1 / (str_replace("
", "", $e->innertext) / 100)), '0');
Yii::$app->redis_currency->hmset($key, 'low', $currency, 'high', $currency, 'last', $currency, 'open', $currency);
}
}
}
});
$url = 'https://cc-api.oanda.com/cc-api/v1/currencies?base=CNY&quote=' . $val->currency->symbol . '&data_type=general_currency_pair&start_date=' . $start_date . '&end_date=' . $end_data;
$content = $curl->get($url, false);
if (is_array($content) && isset($content['response'])) {
$key = 'quotation_currency_' . 'CNY_' . $val->currency->symbol;
Yii::$app->redis_currency->hmset($key, 'low', $content['response'][0]['low_ask'], 'high', $content['response'][0]['high_ask'], 'last', $content['response'][0]['average_ask'], 'open', $content['response'][0]['average_ask']);
Yii::$app->redis_currency->sadd('supported_symbol_currency', $content['response'][0]['base_currency'] . '_' . $content['response'][0]['quote_currency']);
}
}
echo date('Y-m-d H:i:s') . '计价货币更新成功' . PHP_EOL;
return 0;
}
......
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