Commit 1ba6191d authored by shajiaiming's avatar shajiaiming

Merge branch 'master' into feature/issue_coin

parents 9f918352 f891431f
......@@ -126,10 +126,12 @@ class CoinDogController extends BaseController
public function actionArticleBanner()
{
$type = Yii::$app->request->get('type', 1);
$data = Article::find()
->select('id, image_url ,title, url')
->limit(5)
->where(['type' => $type])
->orderBy('update_at desc')
->limit(5)
->asArray()
->all();
......
<?php
namespace api\controllers;
use Yii;
use api\base\BaseController;
use common\models\psources\ExploreApp;
use common\models\psources\CoinBannerItem;
use common\models\psources\ExploreAppCategory;
class ExploreController extends BaseController
{
public function actionIndex()
{
$header = Yii::$app->request->headers;
$platform_id = $header['FZM-PLATFORM-ID'] ?? null;
$data = null;
if (false == $platform_id) {
$msg = '参数错误';
$code = -1;
goto doEnd;
}
$app_category_model = ExploreAppCategory::find()->where(['platform_id' => $platform_id, 'status' => ExploreAppCategory::STATUS_ON])->orderBy('sort')->all();
if (false == $app_category_model) {
$msg = 'success';
$code = 0;
goto doEnd;
}
foreach ($app_category_model as $key => $val) {
unset($val->apps);
$val->name = $val->name[$this->lang];
$apps_model = ExploreApp::find()->select('id, name, icon, type, app_url, slogan')
->where(['app_category_id' => (int)$val->id, 'status' => ExploreApp::STATUS_ON])
->orderBy('sort')
->limit($val->limit)
->all();
if (empty($apps_model)) {
unset($app_category_model[$key]);
continue;
}
foreach ($apps_model as &$app) {
$app->name = $app->name[$this->lang];
}
$val->apps = $apps_model;
unset($val->sort);
unset($val->limit);
unset($val->platform_id);
}
foreach ($app_category_model as $val) {
$data[] = $val;
}
$msg = 'success';
$code = 0;
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionCategory()
{
$header = Yii::$app->request->headers;
$platform_id = $header['FZM-PLATFORM-ID'] ?? null;
$category_id = Yii::$app->request->get('id', 0);
if (false == $platform_id || false == $category_id) {
$msg = '参数错误';
$code = -1;
$data = null;
goto doEnd;
}
$app_category_model = ExploreAppCategory::find()->where(['id' => (int)$category_id, 'platform_id' => $platform_id])->all();
if (false == $app_category_model) {
$msg = 'success';
$code = 0;
$data = null;
goto doEnd;
}
foreach ($app_category_model as &$val) {
foreach ($val->applications as $app) {
$app->name = $app->name[$this->lang];
}
$val->name = $val->name[$this->lang];
$val->apps = $val->applications;
unset($val->id);
unset($val->sort);
unset($val->style);
unset($val->limit);
unset($val->platform_id);
}
$data = $app_category_model;
$msg = 'success';
$code = 0;
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionSearch()
{
$header = Yii::$app->request->headers;
$platform_id = $header['FZM-PLATFORM-ID'] ?? null;
$ids = Yii::$app->request->get('ids', '');
if (false == $platform_id || false == $ids) {
$msg = '参数错误';
$code = -1;
$data = null;
goto doEnd;
}
$id_arr = explode(',', $ids);
$order = "FIELD(`id`,$ids)";
$apps_model = ExploreApp::find()->select('id, name, icon, type, app_url, slogan')
->where(['status' => ExploreApp::STATUS_ON])
->andWhere(['in', 'id', $id_arr])
->orderBy([$order => true])
->limit(4)
->all();
if (false == $apps_model) {
$msg = 'success';
$code = 0;
$data = null;
goto doEnd;
}
foreach ($apps_model as &$app) {
$app->name = $app->name[$this->lang];
}
$data = $apps_model;
$msg = 'success';
$code = 0;
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionBanner()
{
$msg = 'ok';
$code = 0;
$header = Yii::$app->request->headers;
$platform_id = $header['FZM-PLATFORM-ID'] ?? null;
if (false == $platform_id) {
$msg = '参数错误';
$code = -1;
$data = null;
goto doEnd;
}
$coin_banner = CoinBannerItem::find()->select('banner_url, image_url, title')->where(['platform_id' => $platform_id])->asArray()->all();
$data = $coin_banner;
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
namespace api\controllers;
use common\components\Tools;
use Yii;
use yii\data\Pagination;
use linslin\yii2\curl\Curl;
......@@ -22,10 +23,10 @@ class TickerController extends BaseController
$device_code = Yii::$app->request->get('device_code', '');
$platform_id = Yii::$app->request->get('device_code', 0);
$exchange = Yii::$app->request->get('exchange', 'zhaobi');
$data_value = Yii::$app->request->get('data-value', '');
$sort_value = Yii::$app->request->get('sort-value', '');
$data_value = Yii::$app->request->get('data_value', '');
$sort_value = Yii::$app->request->get('sort_value', '');
$exchange_arr = ['huobi', 'binance', 'okex', 'zhaobi'];
$exchange_arr = ['huobi', 'binance', 'zhaobi', 'bitnasdaq'];
if (!in_array($exchange, $exchange_arr)) {
$msg = '不存在的交易平台';
......@@ -127,11 +128,22 @@ class TickerController extends BaseController
$msg = '参数错误';
goto doEnd;
}
$data_value = Yii::$app->request->get('data_value', '');
$sort_value = Yii::$app->request->get('sort_value', '');
$condition = [];
if (false != $data_value && false != $sort_value) {
$condition = [
'data_value' => $data_value,
'sort_value' => $sort_value
];
}
$temp = [];
$query = CoinOptional::find()->select('symbol, platform')
$data = CoinOptional::find()->select('symbol, platform')
->where(['device_code' => $device_code, 'platform_id' => (int)$platform_id])
->orderBy('update_time desc');
$data = $query->offset(($page - 1) * 50)->limit(50)->asArray()->all();
->orderBy('update_time desc')
->asArray()
->all();
if (false == $data) {
$msg = 'success';
$code = 0;
......@@ -156,17 +168,19 @@ class TickerController extends BaseController
}
$symbol = explode('/', $val['symbol']);
$tag_first = $symbol[0];
$tag_first = $currency = $symbol[0];
$tag_second = $symbol[1];
if ('BCH' == strtoupper($tag_first)){
$tag_first = 'BCC';
}
$exchange = ExchangeFactory::createExchange($exchange);
$quotation = $exchange->getTicker(strtolower($tag_first), strtolower($tag_second));
if (empty($quotation)) continue;
$temp['symbol'] = $val['symbol'];
$temp['currency'] = strtoupper($tag_first);
$temp['currency'] = strtoupper($currency);
$temp['base_currency'] = strtoupper($tag_second);
$temp['close'] = number_format($quotation['last'], 6, '.', '');
$temp['close_usd'] = (float)sprintf("%0.6f", $quotation['last'] * $this->basic_price[$tag_second]['usd']);
$temp['close'] = rtrim(sprintf('%.8f', floatval($quotation['last'])), '0');
$temp['close_usd'] = rtrim(sprintf('%.6f', floatval($quotation['last'] * $this->basic_price[$tag_second]['usd'])), '0');
$temp['close_rmb'] = (float)sprintf("%0.4f", $quotation['last'] * $this->basic_price[$tag_second]['rmb']);
$temp['change'] = (0 == $quotation['open']) ? 0 : (float)sprintf("%0.2f", ($quotation['last'] - $quotation['open']) / $quotation['open'] * 100);
$temp['high_usd'] = (float)sprintf("%0.4f", $quotation['high'] * $this->basic_price[$tag_second]['usd']);
......@@ -189,7 +203,24 @@ class TickerController extends BaseController
}
array_push($ticker, $temp);
}
if (!empty($condition)) {
if ('price' == $condition['data_value']) {
if ('price_asc' == $condition['sort_value']) {
$ticker = Tools::arraySort($ticker, 'close', SORT_ASC);
}
if ('price_desc' == $condition['sort_value']) {
$ticker = Tools::arraySort($ticker, 'close', SORT_DESC);
}
}
if ('change' == $condition['data_value']) {
if ('change_asc' == $condition['sort_value']) {
$ticker = Tools::arraySort($ticker, 'change', SORT_ASC);
}
if ('change_desc' == $condition['sort_value']) {
$ticker = Tools::arraySort($ticker, 'change', SORT_DESC);
}
}
}
}
$data = [
......
......@@ -45,7 +45,9 @@ class ExchangeBusiness
16 => 'Ceohk',
17 => 'Biki',
18 => 'Bilaxy',
19 => 'Boc'
19 => 'Bitnasdaq',
20 => 'Boc'
];
/**
......
......@@ -12,6 +12,10 @@ use Yii;
class CoinBannerItem extends BaseActiveRecord
{
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public static function getDb()
{
return Yii::$app->get('p_sources');
......@@ -22,6 +26,25 @@ class CoinBannerItem extends BaseActiveRecord
return '{{coin_banner_item}}';
}
public function rules()
{
return [
[['image_url', 'platform_id'], 'required'],
[['banner_url', 'title'], 'safe'],
[['banner_url', 'image_url'], 'url']
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['image_url', 'banner_url', 'title', 'platform_id'],
self:: SCENARIOS_UPDATE => ['id', 'image_url', 'banner_url', 'title', 'platform_id'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public static function getItems($condition = [])
{
return self::find()->joinWith('platform')->where($condition)->asArray()->all();
......
<?php
namespace common\models\psources;
use Yii;
use yii\db\Expression;
use common\core\BaseActiveRecord;
use yii\behaviors\TimestampBehavior;
class ExploreApp extends BaseActiveRecord
{
const STATUS_ON = 1; //激活
const STATUS_OFF = 0; //未激活
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{explore_app}}';
}
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public function rules()
{
return [
[['name', 'icon', 'app_url', 'slogan', 'type', 'sort', 'status', 'platform_id', 'app_category_id'], 'required'],
[['type', 'sort', 'status', 'platform_id', 'app_category_id'], 'integer'],
[['icon'], 'url']
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['name', 'icon', 'app_url', 'slogan', 'type', 'sort', 'status', 'platform_id', 'app_category_id'],
self:: SCENARIOS_UPDATE => ['id', 'name', 'icon', 'app_url', 'slogan', 'type', 'sort', 'status', 'platform_id', 'app_category_id'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function getAppCategory()
{
return $this->hasOne(ExploreAppCategory::className(), ['id' => 'app_category_id']);
}
public static function getCasesStatus()
{
return [
self::STATUS_ON => '激活',
self::STATUS_OFF => '未激活',
];
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
use common\core\BaseActiveRecord;
class ExploreAppCategory extends BaseActiveRecord
{
const STATUS_ON = 1; //激活
const STATUS_OFF = 0; //未激活
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{explore_app_category}}';
}
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public function rules()
{
return [
[['name', 'sort', 'limit', 'style', 'platform_id', 'status'], 'required'],
];
}
public function attributes()
{
return array_merge(parent::attributes(), ['apps']);
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['name', 'sort', 'limit', 'style', 'platform_id', 'status'],
self:: SCENARIOS_UPDATE => ['name', 'sort', 'limit', 'style', 'platform_id', 'status'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function attributeLabels()
{
return [
'name' => '应用分类名称',
'sort' => '应用分类排序',
'limit' => '该分类下首页可显示的应用数量',
'style' => '应用分类展示样式',
'status' => '应用分类状态'
];
}
public function getApplications()
{
return $this->hasMany(ExploreApp::className(), ['app_category_id' => 'id'])->select(['id', 'name', 'icon', 'app_url', 'slogan', 'type'])->orderBy('sort');
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-26
* Time: 下午7:21
*/
namespace common\service\exchange;
use Yii;
use linslin\yii2\curl\Curl;
class Bitnasdaq extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_bitnasdaq';
protected $quotation_prefix = 'quotation_bitnasdaq_';
protected $base_url = 'https://www.bitnasdaq.com/';
public function formatSymbol($tag = 'BTC', $aim = 'USDT')
{
return strtolower(trim($tag) . trim($aim));
}
public function setSupportedSymbol()
{
$curl = new Curl();
$api = $this->base_url . '/api/v1/ticker/24hr';
$res = $curl->get($api, false);//json
if (is_array($res)) {
foreach ($res as $item) {
$this->redis->sadd($this->supported_symbol, strtolower($item['symbol']));
}
}
}
public function setQuotation()
{
$curl = new Curl();
$api = $this->base_url . '/app/tradeMarket/coinPrice';
$res = $curl->get($api, false);
if (is_array($res) && isset($res['obj'])) {
$data = $res['obj'];
foreach ($data as $key => $item) {
$low = isset($item['minPrice']) ? $item['minPrice'] : 0;
$high = isset($item['maxPrice']) ? $item['maxPrice'] : 0;
$last = isset($item['currentExchangPrice']) ? $item['currentExchangPrice'] : 0;
$open = isset($item['openPrice']) ? $item['openPrice'] : 0;
$vol = isset($item['transactionSum']) ? $item['transactionSum'] : 0;
$cache_key = strtolower($this->quotation_prefix . str_replace('_', '', $key));
$this->redis->hmset($cache_key, 'low', $low, 'high', $high, 'last', $last, 'open', $open, 'vol', $vol);
$this->redis->sadd($this->supported_symbol, strtoupper(str_replace('_', '', $key)));
}
}
}
}
......@@ -44,18 +44,18 @@ class BinanceBuilder extends FactoryService
}
if (false != $condition) {
if ('price' == $condition['data_value']) {
if ('price-asc' == $condition['sort_value']) {
if ('price_asc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_close_asc, $this->start, $this->end);
}
if ('price-desc' == $condition['sort_value']) {
if ('price_desc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_close_desc, $this->start, $this->end);
}
}
if ('change' == $condition['data_value']) {
if ('change-asc' == $condition['sort_value']) {
if ('change_asc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_change_asc, $this->start, $this->end);
}
if ('change-desc' == $condition['sort_value']) {
if ('change_desc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_change_desc, $this->start, $this->end);
}
}
......@@ -114,6 +114,12 @@ class BinanceBuilder extends FactoryService
$temp = [];
$temp['symbol'] = strtoupper($symbol);
$temp['close'] = $close;
foreach ($this->basic_coin as $k => $coin) {
$explode_arr = explode(strtoupper($coin), strtoupper($symbol));
if (2 == count($explode_arr) && empty($explode_arr[1])) {
$temp['close_rmb'] = (float)sprintf("%0.4f", $close * $this->basic_price[$coin]['rmb']);
}
}
$temp['low'] = $low;
$temp['high'] = $high;
$temp['open'] = $open;
......@@ -124,7 +130,7 @@ class BinanceBuilder extends FactoryService
$this->redis_ticker->hmset($key, 'low', $low, 'high', $high, 'last', $close, 'open', $open, 'vol', $vol);
}
$ticker_sort_close = Tools::arraySort($ticker, 'close');
$ticker_sort_close = Tools::arraySort($ticker, 'close_rmb');
$this->redis_ticker->del($this->supported_symbol_close_asc);
$this->redis_ticker->del($this->supported_symbol_close_desc);
foreach ($ticker_sort_close as $val) {
......
<?php
/**
* Created by PhpStorm.
* User: jiaming
* Date: 2019/8/15
* Time: 10:10
*/
namespace common\service\exchange\factory;
use common\components\Tools;
use linslin\yii2\curl\Curl;
class BitnasdaqBuilder extends FactoryService
{
protected $base_url = 'https://www.bitnasdaq.com';
protected $supported_symbol = 'supported_symbol_bitnasdaq';
protected $supported_symbol_list = 'supported_symbol_bitnasdaq_list';
protected $supported_symbol_close_asc = 'supported_symbol_close_asc_bitnasdaq';
protected $supported_symbol_close_desc = 'supported_symbol_close_desc_bitnasdaq';
protected $supported_symbol_change_asc = 'supported_symbol_change_asc_bitnasdaq';
protected $supported_symbol_change_desc = 'supported_symbol_change_desc_bitnasdaq';
protected $quotation_prefix = 'quotation_bitnasdaq_';
public function getTickerFromCache($page = 1, $condition = [])
{
$size = 0;
for ($i = 0; $i < $page; $i++) {
$size += 50;
$this->end = $size;
}
$this->start = $this->end - 50;
$this->end = $this->end - 1;
$keys = $this->redis->smembers($this->supported_symbol);
if (false == $this->redis->exists($this->supported_symbol_list)) {
foreach ($keys as $val) {
if (in_array(strtoupper($val), ['BNCUSDT','BTCUSDT','CNYTUSDT','ETCUSDT','ETHUSDT','GHPUSDT','LTCUSDT'])) {
$this->redis->lpush($this->supported_symbol_list, strtoupper($val));
}
}
}
if (false != $condition) {
if ('price' == $condition['data_value']) {
if ('price_asc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_close_asc, $this->start, $this->end);
}
if ('price_desc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_close_desc, $this->start, $this->end);
}
}
if ('change' == $condition['data_value']) {
if ('change_asc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_change_asc, $this->start, $this->end);
}
if ('change_desc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_change_desc, $this->start, $this->end);
}
}
} else {
$keys = $this->redis->lrange($this->supported_symbol_list, $this->start, $this->end);
}
$ticker = [];
foreach ($keys as $val) {
foreach ($this->basic_coin as $k => $coin) {
$explode_arr = explode(strtoupper($coin), strtoupper($val));
if (2 == count($explode_arr) && empty($explode_arr[1])) {
if (false != $condition) {
list($low, $high, $close, $open, $vol) = $this->redis_ticker->hmget($this->quotation_prefix . strtoupper($val), 'low', 'high', 'last', 'open', 'vol');
} else {
list($low, $high, $close, $open, $vol) = $this->redis->hmget($this->quotation_prefix . strtolower($val), 'low', 'high', 'last', 'open', 'vol');
}
$temp = [];
$temp['symbol'] = strtoupper($explode_arr[0]) . '/' . $coin;
$temp['currency'] = strtoupper($explode_arr[0]);
$temp['base_currency'] = strtoupper($coin);
$temp['close'] = rtrim(sprintf('%.8f', floatval($close)),'0');
$temp['close_usd'] = rtrim(sprintf('%.6f', floatval($close * $this->basic_price[$coin]['usd'])),'0');
$temp['close_rmb'] = (float)sprintf("%0.4f", $close * $this->basic_price[$coin]['rmb']);
$temp['change'] = (false == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100);
$temp['high_usd'] = (float)sprintf("%0.4f", $high * $this->basic_price[$coin]['usd']);
$temp['low_usd'] = (float)sprintf("%0.4f", $low * $this->basic_price[$coin]['usd']);
$temp['high_rmb'] = (float)sprintf("%0.4f", $high * $this->basic_price[$coin]['rmb']);
$temp['low_rmb'] = (float)sprintf("%0.4f", $low * $this->basic_price[$coin]['rmb']);
$temp['vol'] = (float)sprintf("%0.4f", $vol);
$temp['optional'] = false;
$temp['platform_zh'] = '比特纳斯达克';
$temp['platform_us'] = 'BitNasdaq';
array_push($ticker, $temp);
}
}
}
$this->code = 0;
$data = [
'ticker' => $ticker,
'page' => [
'pageSize' => 50,
'currentPage' => (int)$page,
]
];
return ['code' => $this->code, 'data' => $data];
}
public function TickerSort()
{
$len = $this->redis->llen($this->supported_symbol_list);
$ticker = [];
for ($i = 0; $i < $len; $i++) {
$symbol = $this->redis->lindex($this->supported_symbol_list, $i);
list($close, $open, $low, $high, $vol) = $this->redis->hmget($this->quotation_prefix . strtolower($symbol), 'last', 'open', 'low', 'high', 'vol');
if ('0.00000000' == $close) continue;
$temp = [];
$temp['symbol'] = strtoupper($symbol);
$temp['close'] = $close;
foreach ($this->basic_coin as $k => $coin) {
$explode_arr = explode(strtoupper($coin), strtoupper($symbol));
if (2 == count($explode_arr) && empty($explode_arr[1])) {
$temp['close_rmb'] = (float)sprintf("%0.4f", $close * $this->basic_price[$coin]['rmb']);
}
}
$temp['low'] = $low;
$temp['high'] = $high;
$temp['open'] = $open;
$temp['vol'] = $vol;
$temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100);
array_push($ticker, $temp);
$key = $this->quotation_prefix . strtoupper($symbol);
$this->redis_ticker->hmset($key, 'low', $low, 'high', $high, 'last', $close, 'open', $open, 'vol', $vol);
}
$ticker_sort_close = Tools::arraySort($ticker, 'close_rmb');
$this->redis_ticker->del($this->supported_symbol_close_asc);
$this->redis_ticker->del($this->supported_symbol_close_desc);
foreach ($ticker_sort_close as $val) {
$this->redis_ticker->lpush($this->supported_symbol_close_asc, strtoupper($val['symbol']));
$this->redis_ticker->rpush($this->supported_symbol_close_desc, strtoupper($val['symbol']));
}
$ticker_change_close = Tools::arraySort($ticker, 'change');
$this->redis_ticker->del($this->supported_symbol_change_asc);
$this->redis_ticker->del($this->supported_symbol_change_desc);
foreach ($ticker_change_close as $val) {
$this->redis_ticker->lpush($this->supported_symbol_change_asc, strtoupper($val['symbol']));
$this->redis_ticker->rpush($this->supported_symbol_change_desc, strtoupper($val['symbol']));
}
}
}
......@@ -30,7 +30,7 @@ abstract class FactoryService
"eth,ethereum",
"btc,btc",
"usdt,ethereum",
"bty,bty",
"bty,bty"
]
];
$params = json_encode($data);
......
......@@ -64,18 +64,18 @@ class HuobiBuilder extends FactoryService
}
if (false != $condition) {
if ('price' == $condition['data_value']) {
if ('price-asc' == $condition['sort_value']) {
if ('price_asc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_close_asc, $this->start, $this->end);
}
if ('price-desc' == $condition['sort_value']) {
if ('price_desc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_close_desc, $this->start, $this->end);
}
}
if ('change' == $condition['data_value']) {
if ('change-asc' == $condition['sort_value']) {
if ('change_asc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_change_asc, $this->start, $this->end);
}
if ('change-desc' == $condition['sort_value']) {
if ('change_desc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_change_desc, $this->start, $this->end);
}
}
......@@ -135,6 +135,12 @@ class HuobiBuilder extends FactoryService
$temp = [];
$temp['symbol'] = strtoupper($symbol);
$temp['close'] = $close;
foreach ($this->basic_coin as $k => $coin) {
$explode_arr = explode(strtoupper($coin), strtoupper($symbol));
if (2 == count($explode_arr) && empty($explode_arr[1])) {
$temp['close_rmb'] = (float)sprintf("%0.4f", $close * $this->basic_price[$coin]['rmb']);
}
}
$temp['low'] = $low;
$temp['high'] = $high;
$temp['open'] = $open;
......@@ -145,7 +151,7 @@ class HuobiBuilder extends FactoryService
$this->redis_ticker->hmset($key, 'low', $low, 'high', $high, 'last', $close, 'open', $open, 'vol', $vol);
}
$ticker_sort_close = Tools::arraySort($ticker, 'close');
$ticker_sort_close = Tools::arraySort($ticker, 'close_rmb');
$this->redis_ticker->del($this->supported_symbol_close_asc);
$this->redis_ticker->del($this->supported_symbol_close_desc);
foreach ($ticker_sort_close as $val) {
......
......@@ -28,18 +28,18 @@ class ZhaobiBuilder extends FactoryService
$this->end = 50;
if (false != $condition) {
if ('price' == $condition['data_value']) {
if ('price-asc' == $condition['sort_value']) {
if ('price_asc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_close_asc, $this->start, $this->end);
}
if ('price-desc' == $condition['sort_value']) {
if ('price_desc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_close_desc, $this->start, $this->end);
}
}
if ('change' == $condition['data_value']) {
if ('change-asc' == $condition['sort_value']) {
if ('change_asc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_change_asc, $this->start, $this->end);
}
if ('change-desc' == $condition['sort_value']) {
if ('change_desc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_change_desc, $this->start, $this->end);
}
}
......@@ -103,13 +103,19 @@ class ZhaobiBuilder extends FactoryService
$temp = [];
$temp['symbol'] = strtoupper($symbol);
$temp['close'] = number_format($close, 6, '.', '');
foreach ($this->basic_coin as $k => $coin) {
$explode_arr = explode(strtoupper($coin), strtoupper($symbol));
if (2 == count($explode_arr) && empty($explode_arr[1])) {
$temp['close_rmb'] = (float)sprintf("%0.4f", $close * $this->basic_price[$coin]['rmb']);
}
}
$temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100);
array_push($ticker, $temp);
$key = $this->quotation_prefix . strtoupper($symbol);
$this->redis_ticker->hmset($key, 'low', $low, 'high', $high, 'last', $close, 'open', $open, 'vol', $vol);
}
$ticker_sort_close = Tools::arraySort($ticker, 'close');
$ticker_sort_close = Tools::arraySort($ticker, 'close_rmb');
$this->redis_ticker->del($this->supported_symbol_close_asc);
$this->redis_ticker->del($this->supported_symbol_close_desc);
foreach ($ticker_sort_close as $val) {
......
......@@ -14,7 +14,7 @@ class TickerController extends Controller
{
public function actionSort()
{
$class = ['Binance', 'Huobi', 'Zhaobi'];
$class = ['Binance', 'Huobi', 'Zhaobi', 'Bitnasdaq'];
foreach ($class as $val) {
go(function () use ($val) {
\Co::sleep(0.5);
......
This diff is collapsed.
<?php
namespace wallet\controllers;
use Yii;
use yii\data\Pagination;
use wallet\base\BaseController;
use common\models\psources\CoinBannerItem;
class ExploreBannerController extends BaseController
{
public function actionIndex()
{
$msg = 'ok';
$code = 0;
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
$page = Yii::$app->request->get('page', 1);
if (Yii::$app->request->isGet) {
$query = CoinBannerItem::find()
->select('id, banner_url, image_url, title')
->where(['platform_id' => $platform_id])
->asArray();
$banner_model = $query->offset(($page - 1) * 10)->limit(10)->asArray()->all();
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => '10']);
$data = [
'list' => $banner_model,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => 10,
'currentPage' => $page,
]
];
goto doEnd;
}
if (Yii::$app->request->isPost) {
$model = new CoinBannerItem();
$model->setScenario(CoinBannerItem::SCENARIOS_CREATE);
$params = Yii::$app->request->post();
$params['platform_id'] = $platform_id;
if ($model->load($params, '') && $model->save()) {
goto doEnd;
}
$msg = $model->errors;
$code = -1;
goto doEnd;
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionUpdate()
{
$msg = 'ok';
$code = 0;
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
if (Yii::$app->request->isGet) {
$id = Yii::$app->request->get('id');
$data = CoinBannerItem::find()->select('id, banner_url, image_url, title')->where(['platform_id' => $platform_id, 'id' => $id])->asArray()->one();
goto doEnd;
}
if (Yii::$app->request->isPut) {
$params = Yii::$app->request->post();
$id = isset($params['id']) ? $params['id'] : null;
if (false == $id) {
$msg = '参数错误';
$code = -1;
goto doEnd;
}
$model = CoinBannerItem::findOne($id);
$model->setScenario(CoinBannerItem::SCENARIOS_UPDATE);
unset($params['id']);
if ($model->load($params, '') && $model->save()) {
goto doEnd;
}
$msg = $model->errors;
$code = -1;
goto doEnd;
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionRemove()
{
$msg = 'ok';
$code = 0;
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
$id = Yii::$app->request->get('id');
if (false == $id) {
$msg = '参数错误';
$code = -1;
goto doEnd;
}
if (Yii::$app->request->isDelete) {
$model = CoinBannerItem::find()->where(['id' => $id, 'platform_id' => $platform_id])->one();
if (false == $model || !$model->delete()) {
$msg = '删除失败';
$code = -1;
goto doEnd;
}
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
}
\ No newline at end of file
<?php
namespace wallet\controllers;
use Yii;
use OSS\OssClient;
use yii\web\UploadedFile;
use wallet\base\BaseController;
class OssController extends BaseController
{
protected $accessKeyId = "LTAI4FxZ787zpBmjLmr6yMwA";
protected $accessKeySecret = "5OMu030RFIE2KP3fNJrhVRTlVqBLaE";
protected $endpoint = "http://oss-cn-shanghai.aliyuncs.com";
protected $bucket = "bqbwallet";
public function actionUpload()
{
$data = [];
$type = Yii::$app->request->post('type', '');
$uploaded_file = UploadedFile::getInstanceByName('file');
if (false == $uploaded_file || false == $type) {
$msg = '参数错误';
$code = -1;
goto doEnd;
}
$object = md5(date('Y-m-d H:i:s') . $uploaded_file->tempName) . '.' . $uploaded_file->extension;
$filePath = $uploaded_file->tempName;
$ossClient = new OssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint);
$result = $ossClient->uploadFile($this->bucket, 'upload/' . (empty($type) ? '' : $type . '/') . $object, $filePath);
if (!isset($result["info"]['url'])) {
$msg = '上传失败';
$code = -1;
goto doEnd;
}
$code = 0;
$msg = 'ok';
$data = $result["info"]['url'];
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
}
\ No newline at end of file
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