Commit 698f7366 authored by shajiaiming's avatar shajiaiming

Merge branch 'master' into feature/ucenter

parents a7152986 dce20133
...@@ -126,10 +126,12 @@ class CoinDogController extends BaseController ...@@ -126,10 +126,12 @@ class CoinDogController extends BaseController
public function actionArticleBanner() public function actionArticleBanner()
{ {
$type = Yii::$app->request->get('type', 1);
$data = Article::find() $data = Article::find()
->select('id, image_url ,title, url') ->select('id, image_url ,title, url')
->limit(5) ->where(['type' => $type])
->orderBy('update_at desc') ->orderBy('update_at desc')
->limit(5)
->asArray() ->asArray()
->all(); ->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
<?php
namespace api\controllers;
use Yii;
use api\base\BaseController;
use common\models\psources\CoinPlatform;
class IssueChainController extends BaseController
{
/**
* 可发行链列表
* @return array
*/
public function actionIndex()
{
$data = null;
$header = Yii::$app->request->headers;
$platform_id = $header['FZM-PLATFORM-ID'] ?? null;
if (empty($platform_id)) {
$msg = '缺少必要的参数';
$code = -1;
goto doEnd;
}
if (1 == $platform_id) {
$chain_model = CoinPlatform::find()->all();
} else {
$chain_model = CoinPlatform::find()->where(['id' => $platform_id])->all();
}
if (false == $chain_model) {
$msg = '不存在的链';
$code = -1;
goto doEnd;
}
foreach ($chain_model as &$val) {
$val->chain_name = isset($val->chain->platform) ? $val->chain->platform : '';
$val->issue_charge = (float)sprintf("%0.3f", $val->issue_charge);
$val->charge_unit = isset($val->gas->coin_name) ? $val->gas->coin_name : '';
unset($val->download_url);
unset($val->introduce);
unset($val->create_time);
unset($val->update_time);
}
$msg = 'ok';
$code = 0;
$data = is_array($chain_model) ? $chain_model : [$chain_model];
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
/**
* 人工审核状态
* @return array
*/
public function actionManualReviewStatus()
{
$status = 0;
$manual_review = Yii::$app->redis->get('issue_chain_manual_review');
if (false == $manual_review || 'open' == $manual_review) {
$status = 1;
}
return ['code' => 0, 'data' => $status];
}
}
\ No newline at end of file
This diff is collapsed.
...@@ -14,19 +14,19 @@ use common\service\exchange\ExchangeBuilderFactory; ...@@ -14,19 +14,19 @@ use common\service\exchange\ExchangeBuilderFactory;
class TickerController extends BaseController class TickerController extends BaseController
{ {
protected $basic_coin = ['ETH', 'BTC', 'USDT', 'BTY']; protected $basic_coin = ['ETH', 'BTC', 'USDT', 'BTY', 'CNYT'];
protected $basic_price = []; protected $basic_price = [];
public function actionIndex() public function actionIndex()
{ {
$page = Yii::$app->request->get('page', 1); $page = Yii::$app->request->get('page', 1);
$device_code = Yii::$app->request->get('device_code', ''); $device_code = Yii::$app->request->get('device_code', '');
$platform_id = Yii::$app->request->get('device_code', 0); $platform_id = Yii::$app->request->get('platform_id', 0);
$exchange = Yii::$app->request->get('exchange', 'zhaobi'); $exchange = Yii::$app->request->get('exchange', 'zhaobi');
$data_value = Yii::$app->request->get('data_value', ''); $data_value = Yii::$app->request->get('data_value', '');
$sort_value = Yii::$app->request->get('sort_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)) { if (!in_array($exchange, $exchange_arr)) {
$msg = '不存在的交易平台'; $msg = '不存在的交易平台';
...@@ -76,6 +76,7 @@ class TickerController extends BaseController ...@@ -76,6 +76,7 @@ class TickerController extends BaseController
"btc,btc", "btc,btc",
"usdt,ethereum", "usdt,ethereum",
"bty,bty", "bty,bty",
"cnyt,bitnasdaqchain"
] ]
]; ];
$params = json_encode($data); $params = json_encode($data);
...@@ -103,7 +104,7 @@ class TickerController extends BaseController ...@@ -103,7 +104,7 @@ class TickerController extends BaseController
$msg = '参数错误'; $msg = '参数错误';
goto doEnd; goto doEnd;
} }
$model = CoinOptional::find()->where(['device_code' => $device_code, 'symbol' => $symbol, 'platform_id' => (int)$platform_id])->one(); $model = CoinOptional::find()->where(['device_code' => $device_code, 'symbol' => $symbol, 'platform' => $platform, 'platform_id' => (int)$platform_id])->one();
if ($model) { if ($model) {
$msg = '数据已存在!'; $msg = '数据已存在!';
goto doEnd; goto doEnd;
...@@ -164,18 +165,23 @@ class TickerController extends BaseController ...@@ -164,18 +165,23 @@ class TickerController extends BaseController
$exchange = 'Binance'; $exchange = 'Binance';
} else if ('zhaobi' == $val['platform']) { } else if ('zhaobi' == $val['platform']) {
$exchange = 'Zhaobi'; $exchange = 'Zhaobi';
} else if ('bitnasdaq' == strtolower($val['platform'])) {
$exchange = 'Bitnasdaq';
} else { } else {
} }
$symbol = explode('/', $val['symbol']); $symbol = explode('/', $val['symbol']);
$tag_first = $symbol[0]; $tag_first = $currency = $symbol[0];
$tag_second = $symbol[1]; $tag_second = $symbol[1];
if ('BCH' == strtoupper($tag_first)) {
$tag_first = 'BCC';
}
$exchange = ExchangeFactory::createExchange($exchange); $exchange = ExchangeFactory::createExchange($exchange);
$quotation = $exchange->getTicker(strtolower($tag_first), strtolower($tag_second)); $quotation = $exchange->getTicker(strtolower($tag_first), strtolower($tag_second));
if (empty($quotation)) continue; if (empty($quotation)) continue;
$temp['symbol'] = $val['symbol']; $temp['symbol'] = $val['symbol'];
$temp['currency'] = strtoupper($tag_first); $temp['currency'] = strtoupper($currency);
$temp['base_currency'] = strtoupper($tag_second); $temp['base_currency'] = strtoupper($tag_second);
$temp['close'] = rtrim(sprintf('%.8f', floatval($quotation['last'])), '0'); $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_usd'] = rtrim(sprintf('%.6f', floatval($quotation['last'] * $this->basic_price[$tag_second]['usd'])), '0');
...@@ -199,6 +205,10 @@ class TickerController extends BaseController ...@@ -199,6 +205,10 @@ class TickerController extends BaseController
$temp['platform_zh'] = '币安'; $temp['platform_zh'] = '币安';
$temp['platform_us'] = 'binance'; $temp['platform_us'] = 'binance';
} }
if ('BITNASDAQ' == strtoupper($val['platform'])) {
$temp['platform_zh'] = '比特纳斯达克';
$temp['platform_us'] = 'bitnasdaq';
}
array_push($ticker, $temp); array_push($ticker, $temp);
} }
if (!empty($condition)) { if (!empty($condition)) {
...@@ -273,10 +283,47 @@ class TickerController extends BaseController ...@@ -273,10 +283,47 @@ class TickerController extends BaseController
public function actionHotTicker() public function actionHotTicker()
{ {
$builder = ExchangeBuilderFactory::create('huobi'); $platform_id = Yii::$app->request->get('platform_id', 0);
$result = $builder->getHotTicker(); if (9 == $platform_id) {
$code = $result['code']; $datas = [
$data = $result['ticker']; [
'exchange' => 'huobi',
'symbol' => [
'btcusdt',
'ethusdt'
],
],[
'exchange' => 'dag',
'symbol' => [
'dagusdt'
],
]
];
} else {
$datas = [
[
'exchange' => 'huobi',
'symbol' => [
'btcusdt',
'ethusdt'
]
],[
'exchange' => 'zhaobi',
'symbol' => [
'btyusdt'
]
]
];
}
$ticker = [];
foreach ($datas as $data) {
$builder = ExchangeBuilderFactory::create($data['exchange']);
$result = $builder->getHotTicker($data['symbol']);
if (0 != $result['code']) continue;
$ticker = array_merge($ticker, $result['ticker']);
}
$code = 0;
$data = $ticker;
$msg = 'success'; $msg = 'success';
doEnd : doEnd :
......
...@@ -4,6 +4,7 @@ namespace api\controllers; ...@@ -4,6 +4,7 @@ namespace api\controllers;
use api\base\BaseController; use api\base\BaseController;
use common\models\psources\CoinAirDropTrade; use common\models\psources\CoinAirDropTrade;
use common\models\psources\CoinIssueTransfer;
use common\models\psources\CoinPlatform; use common\models\psources\CoinPlatform;
use common\service\chain33\Chain33Service; use common\service\chain33\Chain33Service;
use Yii; use Yii;
...@@ -16,7 +17,7 @@ class WalletController extends BaseController ...@@ -16,7 +17,7 @@ class WalletController extends BaseController
$code = 0; $code = 0;
$msg = 'success'; $msg = 'success';
$platform_id = Yii::$app->request->get('platform_id', ''); $platform_id = Yii::$app->request->get('platform_id', '');
if(empty($platform_id)){ if (empty($platform_id)) {
$msg = '参数不能为空'; $msg = '参数不能为空';
$code = -1; $code = -1;
$data = null; $data = null;
...@@ -24,7 +25,7 @@ class WalletController extends BaseController ...@@ -24,7 +25,7 @@ class WalletController extends BaseController
} }
$data = CoinPlatform::find()->select("name, download_url, introduce")->where(['id' => $platform_id])->asArray()->one(); $data = CoinPlatform::find()->select("name, download_url, introduce")->where(['id' => $platform_id])->asArray()->one();
if(empty($data)){ if (empty($data)) {
$msg = '数据不存在'; $msg = '数据不存在';
$data = null; $data = null;
$code = -1; $code = -1;
...@@ -39,8 +40,8 @@ class WalletController extends BaseController ...@@ -39,8 +40,8 @@ class WalletController extends BaseController
public function actionGameTradeUpdate() public function actionGameTradeUpdate()
{ {
$coinAirDropTrade = CoinAirDropTrade::find()->where(['attach' => 2 ,'msg' => '0'])->limit(30)->all(); $coinAirDropTrade = CoinAirDropTrade::find()->where(['attach' => 2, 'msg' => '0'])->limit(30)->all();
foreach ($coinAirDropTrade as $val){ foreach ($coinAirDropTrade as $val) {
$fee = 100000; $fee = 100000;
$amount = 1 * 1e8; $amount = 1 * 1e8;
$execer = 'coins'; $execer = 'coins';
...@@ -48,7 +49,7 @@ class WalletController extends BaseController ...@@ -48,7 +49,7 @@ class WalletController extends BaseController
$service = new Chain33Service(); $service = new Chain33Service();
$createRawTransaction = $service->createRawTransaction($val->coins_address, $amount, $fee, $note, $execer); $createRawTransaction = $service->createRawTransaction($val->coins_address, $amount, $fee, $note, $execer);
if(0 != $createRawTransaction['code']){ if (0 != $createRawTransaction['code']) {
continue; continue;
} }
...@@ -57,13 +58,13 @@ class WalletController extends BaseController ...@@ -57,13 +58,13 @@ class WalletController extends BaseController
$expire = '1m'; $expire = '1m';
$signRawTx = $service->signRawTx($privkey, $txHex, $expire); $signRawTx = $service->signRawTx($privkey, $txHex, $expire);
if(0 != $signRawTx['code']){ if (0 != $signRawTx['code']) {
continue; continue;
} }
$sign_str = $signRawTx['result']; $sign_str = $signRawTx['result'];
$result = $service->sendTransaction($sign_str); $result = $service->sendTransaction($sign_str);
if(0 != $result['code']){ if (0 != $result['code']) {
continue; continue;
} }
$currentModel = CoinAirDropTrade::findOne($val->id); $currentModel = CoinAirDropTrade::findOne($val->id);
...@@ -77,23 +78,59 @@ class WalletController extends BaseController ...@@ -77,23 +78,59 @@ class WalletController extends BaseController
public function actionGetBalance() public function actionGetBalance()
{ {
$coinAirDropTrade = CoinAirDropTrade::find()->where(['balance' => 0])->limit(60)->all(); $code = 0;
$address = []; $msg = 'success';
foreach ($coinAirDropTrade as $val){ $platform_id = Yii::$app->request->get('platform_id', '');
$address[] = $val->coins_address; $token = Yii::$app->request->get('address', '');
if (empty($platform_id) || empty($token)) {
$msg = '参数不能为空';
$code = -1;
$data = null;
goto doEnd;
} }
$service = new Chain33Service(); $node = Yii::$app->params['chain_parallel']['primary'];
$service = new Chain33Service($node);
$address[] = $token;
$execer = 'coins'; $execer = 'coins';
$result = $service->getBalance($address, $execer); $result = $service->getBalance($address, $execer);
if(0 == $result['code']){ if (0 !== $result['code']) {
$result_balance = $result['result']; $msg = '当前发币人数过多,请客官稍后再试';
foreach ($result_balance as $val){ $code = -1;
$coinAirDropTrade = CoinAirDropTrade::find()->where(['coins_address' => $val['addr']])->one(); $data = null;
if(empty($coinAirDropTrade)) continue; goto doEnd;
$coinAirDropTrade->balance = $val['balance'];
$coinAirDropTrade->save();
} }
$data = $result['result'];
doEnd :
return ['code' => $code, 'data' => $data, 'msg' => $msg];
} }
return ['code' => 1, 'msg' => 'ok'];
public function actionTransfer()
{
$code = -1;
$request = Yii::$app->request;
$post = $request->post();
if (!$request->isPost) {
$msg = '请求错误!';
goto doEnd;
}
$txhex = isset($post['txhex']) ? $post['txhex'] : '';
$issue_coin_id = isset($post['issue_coin_id']) ? $post['issue_coin_id'] : 0;
if (false == $txhex || false == $issue_coin_id) {
$msg = '参数错误!';
goto doEnd;
}
$model = new CoinIssueTransfer();
$data['txhex'] = $txhex;
$data['issue_coin_id'] = (int)$issue_coin_id;
$model->load($data, '');
$model->save();
$code = 0;
$msg = 'success';
doEnd :
return ['code' => $code, 'msg' => $msg];
} }
} }
\ No newline at end of file
<?php
namespace backend\assets\coinSupportedCoin;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/coin-supported-coin';
public $js = [
'index.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
<?php
namespace backend\controllers;
use common\models\psources\CoinSupportedCoin;
use Yii;
class CoinSupportedCoinController extends BaseController
{
public function actionList()
{
$platform_id = Yii::$app->request->get('id');
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$page = $request->get('page', 1);
$limit = $request->get('limit', 10);
$id = $request->get('id', '');
$where = [];
if ($id) {
$where[] = ['platform_id' => $id];
}
$data = CoinSupportedCoin::getList($page, $limit, $where);
$data['code'] = 0;
Yii::$app->response->format = 'json';
return $data;
}
return $this->render('index', ['platform_id' => $platform_id]);
}
public function actionAdd()
{
$this->layout = false;
$model = new CoinSupportedCoin();
$model->setScenario(CoinSupportedCoin::SCENARIOS_CREATE);
if (Yii::$app->request->isPost) {
Yii::$app->response->format = 'json';
$data = Yii::$app->request->post();
if ($model->load($data, '') && $model->save()) {
return ['code' => 0, 'msg' => 'succeed'];
}
$error = $model->errors;
if ($error) {
return ['code' => -1, 'msg' => current($model->firstErrors)];
}
}
$platform_id = Yii::$app->request->get('platform_id');
return $this->render('add', ['model' => $model, 'platform_id' => $platform_id]);
}
public function actionDelete()
{
Yii::$app->response->format = 'json';
$id = Yii::$app->request->get('id', 0);
if ($id) {
$model = CoinSupportedCoin::findOne(['id' => $id]);
if ($model) {
try {
$model->delete();
return ['code' => 0, 'msg' => 'succeed'];
} catch (\Throwable $t) {
return ['code' => $t->getCode(), 'msg' => $t->getMessage()];
}
}
}
return ['code' => -1, 'msg' => '删除失败'];
}
}
\ No newline at end of file
...@@ -10,6 +10,7 @@ namespace backend\controllers; ...@@ -10,6 +10,7 @@ namespace backend\controllers;
use backend\models\coin\CoinPlatformForm; use backend\models\coin\CoinPlatformForm;
use common\models\psources\CoinPlatform; use common\models\psources\CoinPlatform;
use common\models\psources\CoinPlatformWithHold;
use Yii; use Yii;
...@@ -39,6 +40,7 @@ class WalletController extends BaseController ...@@ -39,6 +40,7 @@ class WalletController extends BaseController
{ {
$model = new CoinPlatformForm(); $model = new CoinPlatformForm();
$model->scenario = 'add'; $model->scenario = 'add';
$platform_withhold = CoinPlatformWithHold::find()->select('id, platform')->orderBy('platform')->asArray()->all();
if (Yii::$app->request->isPost) { if (Yii::$app->request->isPost) {
$data = Yii::$app->request->post(); $data = Yii::$app->request->post();
if ($model->load($data, '') && $model->validate()) { if ($model->load($data, '') && $model->validate()) {
...@@ -60,7 +62,8 @@ class WalletController extends BaseController ...@@ -60,7 +62,8 @@ class WalletController extends BaseController
} }
$this->error($errors, Yii::$app->request->getReferrer()); $this->error($errors, Yii::$app->request->getReferrer());
} }
return $this->render('add', ['model' => $model]);
return $this->render('add', ['model' => $model, 'platform_withhold' => $platform_withhold]);
} }
public function actionEdit() public function actionEdit()
...@@ -90,9 +93,10 @@ class WalletController extends BaseController ...@@ -90,9 +93,10 @@ class WalletController extends BaseController
} elseif (Yii::$app->request->isGet) { } elseif (Yii::$app->request->isGet) {
$id = Yii::$app->request->get('id', null); $id = Yii::$app->request->get('id', null);
if ($id) { if ($id) {
$platform_withhold = CoinPlatformWithHold::find()->select('id, platform')->orderBy('platform')->asArray()->all();
$coin = CoinPlatform::findOne(['id' => $id]); $coin = CoinPlatform::findOne(['id' => $id]);
$this->layout = false; $this->layout = false;
return $this->render('edit', ['model' => $coin]); return $this->render('edit', ['model' => $coin, 'platform_withhold' => $platform_withhold]);
} }
} }
} }
......
...@@ -14,6 +14,7 @@ class CoinPlatformForm extends Model ...@@ -14,6 +14,7 @@ class CoinPlatformForm extends Model
{ {
public $id; public $id;
public $name; public $name;
public $chain_id;
public $download_url; public $download_url;
public $introduce; public $introduce;
...@@ -27,6 +28,7 @@ class CoinPlatformForm extends Model ...@@ -27,6 +28,7 @@ class CoinPlatformForm extends Model
return [ return [
[['name'], 'required', 'on' => 'add'], [['name'], 'required', 'on' => 'add'],
[['id', 'name'], 'required', 'on' => 'update'], [['id', 'name'], 'required', 'on' => 'update'],
[['chain_id', 'download_url', 'introduce'], 'safe']
]; ];
} }
...@@ -34,6 +36,7 @@ class CoinPlatformForm extends Model ...@@ -34,6 +36,7 @@ class CoinPlatformForm extends Model
{ {
return [ return [
'id' => 'ID', 'id' => 'ID',
'chain_id' => '所属链',
'name' => '名称', 'name' => '名称',
'download_url' => '下载链接', 'download_url' => '下载链接',
'introduce' => '介绍' 'introduce' => '介绍'
...@@ -46,10 +49,16 @@ class CoinPlatformForm extends Model ...@@ -46,10 +49,16 @@ class CoinPlatformForm extends Model
'add' => [ 'add' => [
'id', 'id',
'name', 'name',
'chain_id',
'download_url',
'introduce'
], ],
'update' => [ 'update' => [
'id', 'id',
'name', 'name',
'chain_id',
'download_url',
'introduce'
], ],
]; ];
} }
......
<div style="padding: 5px 20px;">
<br>
<form id="addData">
<input name="_csrf" type="hidden" value="<?= Yii::$app->request->getCsrfToken() ?>">
<div class="input-group my-group">
<span class="input-group-addon">币种名称</span>
<input name="coin_name" type="text" class="form-control" lay-verify="required">
</div>
<input class="layui-input" name="platform_id" type="hidden" value="<?= $platform_id ?>"
lay-verify="required">
</form>
</div>
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 上午9:59
*/
use backend\assets\coinSupportedCoin\IndexAsset;
IndexAsset::register($this);
?>
<style>
.layui-table-tips-c {
padding: 0px;
}
</style>
<h4>货币列表</h4>
<div class="layui-row">
<div class="layui-col-md1">
<button class="layui-btn layui-btn-sm" lay-event="add" id="add">单笔添加</button>
</div>
</div>
<input id="platform_id" type="hidden" value="<?= $platform_id ?>">
<div class="layui-row">
<table class="layui-table" id="table1" lay-filter="table1"></table>
</div>
<script type="text/html" id="operationTpl">
<a lay-event="delete">
<button class="layui-btn layui-btn-sm layui-btn-danger"><i class="layui-icon">&#xe640;</i></button>
</a>
</script>
...@@ -23,6 +23,18 @@ ...@@ -23,6 +23,18 @@
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">所属链</label>
<div class="layui-input-block">
<select name="chain_id">
<?php foreach ($platform_withhold as $val): ?>
<option value="<?= $val['id'] ?>" <?php if ($model->chain_id == $val['id']) {
echo "selected";
} ?>><?= $val['platform'] ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">下载地址</label> <label class="layui-form-label">下载地址</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input class="layui-input" name="download_url" value="<?= $model->download_url ?>"> <input class="layui-input" name="download_url" value="<?= $model->download_url ?>">
...@@ -40,3 +52,6 @@ ...@@ -40,3 +52,6 @@
</form> </form>
</div> </div>
</div> </div>
<script>
layui.form.render();
</script>
...@@ -24,6 +24,18 @@ ...@@ -24,6 +24,18 @@
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">所属链</label>
<div class="layui-input-block">
<select name="chain_id">
<?php foreach ($platform_withhold as $val): ?>
<option value="<?= $val['id'] ?>" <?php if ($model->chain_id == $val['id']) {
echo "selected";
} ?>><?= $val['platform'] ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">下载地址</label> <label class="layui-form-label">下载地址</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input class="layui-input" name="download_url" value="<?= $model->download_url ?>"> <input class="layui-input" name="download_url" value="<?= $model->download_url ?>">
......
...@@ -42,10 +42,7 @@ IndexAsset::register($this); ...@@ -42,10 +42,7 @@ IndexAsset::register($this);
</div> </div>
<script type="text/html" id="operationTpl"> <script type="text/html" id="operationTpl">
<a lay-event="edit"> <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<button class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe642;</i></button> <a class="layui-btn layui-btn-xs" lay-event="delete">删除</a>
</a> <a class="layui-btn layui-btn-primary layui-btn-xs" href="/admin/coin-supported-coin/list?id={{d.id}}" >支持发行货币种类</a>
<a lay-event="delete">
<button class="layui-btn layui-btn-sm layui-btn-danger"><i class="layui-icon">&#xe640;</i></button>
</a>
</script> </script>
/**
* @author rlgyzhcn@qq.com
*/
var table = layui.table;
var form = layui.form;
var layer = layui.layer;
form.render();
var platform_id = $("#platform_id").val();
var tableIns = table.render({
elem: "#table1",
url: '/admin/coin-supported-coin/list?id=' + platform_id,
limit: 10,
page: 1,
loading: true,
cols: [[
{field: 'id', title: 'ID'},
{field: 'coin_name', title: '货币对'},
{field: 'create_time', title: '创建时间'},
{field: 'id', title: '操作', templet: '#operationTpl'}
]],
});
form.on('submit(form1)', function (data) {
table.reload("table1", {
where: data.field,
page: {curr: 1},
});
return false;
});
//监听单元格事件
table.on('tool(table1)', function (obj) {
var data = obj.data;
if (obj.event == 'delete') {
layer.confirm('真的要删除' + data.coin_name + '吗?', {icon: 3, title: '删除'}, function (index) {
layer.close(index);
//向服务端发送删除指令
$.get('/admin/coin-supported-coin/delete?id=' + obj.data.id, function (data, status) {
if (data.code == 0) {
obj.del(); //删除对应行(tr)的DOM结构
}
layer.msg(data.msg);
});
});
}
});
$('#add').click(function () {
//打开弹窗
$.get('/admin/coin-supported-coin/add?platform_id=' + platform_id, {}, function (str) {
var index = layer.open({
type: 1,
title: '添加数据',
id: 'add-one',
skin: 'layui-layer-lan',
area: ['320px', 'auto'],
content: str,
btn: ['确认', '取消'],
btn1: function () {
$.post('/admin/coin-supported-coin/add', $("#addData").serialize(), function (rev) {
layer.msg(rev.msg);
if (rev.code == 0) {
layer.close(index);
table.reload("table1", {});
}
});
}
});
layui.form.render();
});
return false;
});
\ No newline at end of file
...@@ -26,14 +26,14 @@ class LoginStatusAuthInterceptor extends ActionFilter ...@@ -26,14 +26,14 @@ class LoginStatusAuthInterceptor extends ActionFilter
$token_string = Yii::$app->request->headers->get('Token'); $token_string = Yii::$app->request->headers->get('Token');
if(false == $token_string){ if(false == $token_string){
$msg = 'platform auth error'; $msg = 'platform auth error';
$code = '40004'; $code = '40001';
goto doEnd; goto doEnd;
} }
$model = new Admin(); $model = new Admin();
$user = $model->loginByAccessToken($token_string,''); $user = $model->loginByAccessToken($token_string,'');
if(false == $user){ if(false == $user){
$msg = 'user auth error'; $msg = 'user auth error';
$code = '40004'; $code = '40002';
goto doEnd; goto doEnd;
} }
$user_id = $user->uid; $user_id = $user->uid;
......
...@@ -33,19 +33,21 @@ class ExchangeBusiness ...@@ -33,19 +33,21 @@ class ExchangeBusiness
4 => 'Bittrex', 4 => 'Bittrex',
5 => 'Zb', 5 => 'Zb',
6 => 'Token7', 6 => 'Token7',
7 => 'S', 7 => 'Zg',
8 => 'Zg', 8 => 'Go',
9 => 'Go', 9 => 'Zhaobi',
10 => 'Zhaobi', 10 => 'Ex',
11 => 'Gdpro', 11 => 'Zt',
12 => 'Ex', 12 => 'Tsc',
13 => 'Zt', 13 => 'Binance',
14 => 'Tsc', 14 => 'Biki',
15 => 'Binance', 15 => 'Bilaxy',
16 => 'Ceohk', 16 => 'Bitnasdaq',
17 => 'Biki', 17 => 'Dag',
18 => 'Bilaxy', 18 => 'Boc',
19 => 'Boc' //7 => 'S',//已挂
//11 => 'Gdpro',//已挂
//16 => 'Ceohk', //已挂
]; ];
/** /**
...@@ -98,7 +100,7 @@ class ExchangeBusiness ...@@ -98,7 +100,7 @@ class ExchangeBusiness
goto doEnd; goto doEnd;
} }
if (strtoupper($tag) == 'GST' || strtoupper($tag) == 'JNTK' || strtoupper($tag) == 'SPT' ||strtoupper($tag) == 'STO' || strtoupper($tag) == 'GM' || strtoupper($tag) == 'BSTC' || strtoupper($tag) == 'RYH' || strtoupper($tag) == 'CNDT' || strtoupper($tag) == 'WL' || strtoupper($tag) == 'ETS' || strtoupper($tag) == 'LIMS' || strtoupper($tag) == 'AT' || strtoupper($tag) == 'BTJ') { if (strtoupper($tag) == 'GST' || strtoupper($tag) == 'JNTK' || strtoupper($tag) == 'SPT' || strtoupper($tag) == 'STO' || strtoupper($tag) == 'GM' || strtoupper($tag) == 'BSTC' || strtoupper($tag) == 'RYH' || strtoupper($tag) == 'CNDT' || strtoupper($tag) == 'WL' || strtoupper($tag) == 'ETS' || strtoupper($tag) == 'LIMS' || strtoupper($tag) == 'AT' || strtoupper($tag) == 'BTJ') {
$quotation = [ $quotation = [
'low' => 0, 'low' => 0,
'high' => 0, 'high' => 0,
...@@ -121,6 +123,13 @@ class ExchangeBusiness ...@@ -121,6 +123,13 @@ class ExchangeBusiness
goto doEnd; goto doEnd;
} }
if (in_array(strtoupper($tag), ['DAG'])) {
$exchange = ExchangeFactory::createExchange("Dag");
$quotation = $exchange->getTicker($tag, 'USDT');
$quotation['rmb'] = (float)sprintf("%0.2f", $quotation['last']);
goto doEnd;
}
if (in_array(strtoupper($tag), ['GM', 'BSTC'])) { if (in_array(strtoupper($tag), ['GM', 'BSTC'])) {
$exchange = ExchangeFactory::createExchange("Token7"); $exchange = ExchangeFactory::createExchange("Token7");
$quotation = $exchange->getTicker($tag, 'HA'); $quotation = $exchange->getTicker($tag, 'HA');
......
<?php
namespace common\components;
use yii\base\Component;
class ErrorMessage extends Component
{
/**
* 预定义错误信息
*/
public static $errors = [
'ErrTokenNameLen' => "token名字太长",
'ErrTokenSymbolLen' => " token符号太长",
'ErrTokenTotalOverflow' => ' token 总数过大, 或是负的',
'ErrTokenSymbolUpper' => ' token symbol 需要全是大写字母',
'ErrTokenIntroLen' => ' Token介绍太长',
'ErrTokenExist' => ' Token Symbol 已经存在',
'ErrTokenNotPrecreated' => ' Token 还没有预创建',
'ErrTokenCreatedApprover' => 'Token Approver 没有权限',
'ErrTokenRevoker' => ' Token Revoker 错误 (需要创建者自己撤销)',
'ErrTokenCanotRevoked' => 'Token 不能撤销',
'ErrTokenOwner' => 'Token Owner 错误',
'ErrTokenHavePrecreated' => 'Token已经被预创建',
'ErrTokenBlacklist' => 'Token 在黑名单里',
'ErrTokenNotExist' => 'Token 不存在',
'ErrTokenSymbolExistAlready' => 'Token Symbol 已经存在'
];
/**
* 获取错误信息
*/
public static function getMessage($msg)
{
$message = isset(self::$errors[$msg]) ? self::$errors[$msg] : '未知错误';
return $message;
}
}
\ No newline at end of file
<?php
namespace common\models;
use Yii;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use yii\helpers\FileHelper;
class Tools
{
/**
* 获取随机验证码
* @return string
*/
public static function getRandomNumber($count = 6, $type = 'mixed')
{
$chars = '1234567890abcdefghijklmnopqrstuvwxyz';
switch($type) {
case 'number':
$startIndex = 0;
$endIndex = 9;
break;
case 'letter':
$startIndex = 10;
$endIndex = 35;
break;
default :
$startIndex = 0;
$endIndex = 35;
break;
}
$randomNumber = '';
for($i = 0; $i<$count; $i++) {
$randomNumber .= substr($chars, rand($startIndex, $endIndex), 1);
}
return $randomNumber;
}
/**
* 获取文件全路径
* @param type $filename
* @param type $type
* @return string
*/
public static function getFileUrl($fileName)
{
return $fileName? Url::to('@resDomain' . $fileName): '';
}
/**
* 判断当前日期是否是可用日期
* @param type $startData
* @param type $endData
*/
public static function isAvailableDate($start, $end)
{
$current = date('Y-m-d');
$start = $start?date('Y-m-d', strtotime($start)):$current;
$end = $end?date('Y-m-d', strtotime($end)):$current;
if($start <= $current && $end >= $current) {
return true;
} else {
return false;
}
}
/**
* 添加get查询数据
* @param type $values
*/
public static function addQueryParams($values)
{
Yii::$app->request->setQueryParams(\yii\helpers\ArrayHelper::merge(Yii::$app->request->get(), $values));
}
/**
* 获取post数据, 可附加额外数据
* @param array $values 附加数据,必须是数组形式
* @param string $formName 指定数据附加到特定键
*/
public static function getPost(array $values, $formName = null)
{
if(Yii::$app->request->isPost) {
$data = Yii::$app->request->post();
if($formName !== null) {
$data[$formName] = ArrayHelper::merge($data[$formName], $values);
} else {
$data = ArrayHelper::merge($data, $values);
}
return $data;
} else {
return;
}
}
/**
* 获取到下个给定时间点还有多长时间,单位 秒
* @param mixed $time 可以是一个时间字符串,也可以是时间字符串数组
* 格式为 h:m:s
* @return $duration 返回值为到下个时间点还有多长时间,以秒为单位
*/
public static function getDuration($time)
{
if(!is_array($time)) {
$time = (array)$time;
}
$seconds = [];
foreach($time as $value) {
$timeArray = explode(':', $value);
if(3 != count($timeArray)) {
return false;
}
list($hour, $minute, $second) = $timeArray;
if((int)$hour < 0 || (int)$hour > 23 || (int)$minute < 0 || (int)$minute > 59 || (int)$second < 0 || (int)$second > 59) {
return false;
}
$seconds[] = $hour * 3600 + $minute * 60 + $second;
}
sort($seconds);
$currentTimeSecond = idate('H') * 3600 + idate('i') * 60 + idate('s');
foreach($seconds as $second) {
if(($second - $currentTimeSecond) > 0) {
return $second - $currentTimeSecond;
}
}
return $seconds[0] + (24 * 3600 - $currentTimeSecond);
}
/**
* 保留小数位数,向下取数
* @param float $number //数字
* @param int $precision //精度
* 例如, roundDown(1.20058, 4) return 1.2005
*/
public static function roundDown($number, $precision)
{
$pow = pow(10, (int)$precision);
return floor($number*$pow)/$pow;
}
/**
* 获取一条错误信息
* @param type $errors
* @return type
*/
public static function getFirstError($errors,$defaultError = null)
{
if(count($errors) > 0){
foreach($errors as $error) {
return $error[0];
}
}
$defaultError = '请求数据有误';
return $defaultError;
}
/**
* 格式化数字
* @param int $num
* @return string
*/
public static function formatNumber($num)
{
return ($num/100000000 > 1) ? sprintf('%.2f', $num/100000000).'亿' : (($num/10000 > 1) ? sprintf('%.2f', $num/10000).'万' : sprintf('%.2f', $num));
}
/**
* 获取配置参数
* @param string $moduleId 模块ID
* @param mixed $keys
* @param mixed $default 默认值
*/
public static function getModuleParams($moduleId, $keys, $default = null)
{
if(is_string($keys) && isset(Yii::$app->params[$moduleId][$keys])) {
return Yii::$app->params[$moduleId][$keys];
} elseif(is_array($keys) && isset(Yii::$app->params[$moduleId])) {
$params = Yii::$app->params[$moduleId];
foreach($keys as $key) {
if(isset($params[$key])) {
$params = $params[$key];
} else {
return $default;
}
}
return $params;
}
return $default;
}
/**
* 获取上传文件目录
* @param string $moduleId 模块ID
* @param array $moduleSubDir 模块子目录
*/
public static function getUploadDir($moduleId, $moduleSubdir = null)
{
$uploadDir = '/' . $moduleId;
if(is_array($moduleSubdir)) {
foreach($moduleSubdir as $dirName) {
$uploadDir .= '/' . $dirName;
}
}
return $uploadDir;
}
/**
* 复制文件夹及子目录文件
* @param string $source
* @param string $destination
*/
public static function xCopy($source, $destination)
{
if(!is_dir($source)) {
return;
}
FileHelper::createDirectory($destination, 0755, true);
$handle = opendir($source);
while (($file = readdir($handle)) !== false) {
if ($file === '.' || $file === '..') {
continue;
}
$path = $source . DIRECTORY_SEPARATOR . $file;
if (is_dir($path)) {
static::xCopy($path, $destination . DIRECTORY_SEPARATOR . $file);
} else {
copy($path, $destination . DIRECTORY_SEPARATOR . $file);
}
}
closedir($handle);
}
/**
* 压缩文件或文件夹
* @param string $source 文件夹或文件路径
*/
public static function folderToZip($source, &$zipArchive, $exclusiveLength)
{
if (is_dir($source) || is_file($source)) {
$handle = opendir($source);
while (($file = readdir($handle)) !== false) {
if ($file === '.' || $file === '..') {
continue;
}
$path = $source . DIRECTORY_SEPARATOR . $file;
$localPath = substr($path, $exclusiveLength);
if (is_file($path)) {
$zipArchive->addFile($path, $localPath);
} elseif (is_dir($path)) {
$zipArchive->addEmptyDir($localPath);
static::folderToZip($path, $zipArchive, $exclusiveLength);
}
}
closedir($handle);
}
}
/**
* 压缩文件夹
* @param string $source
*/
public static function zipDir($source)
{
$pathinfo = pathinfo($source);
$basename = $pathinfo['basename'];
$dirname = $pathinfo['dirname'];
$zipArchive = new \ZipArchive();
$zipArchive->open($dirname . DIRECTORY_SEPARATOR . $basename . '.zip', \ZipArchive::CREATE);
$exclusiveLength = strlen($dirname) + 1;
static::folderToZip($source, $zipArchive, $exclusiveLength);
$zipArchive->close();
}
public static function unZip($source)
{
$pathinfo = pathinfo($source);
$dirname = $pathinfo['dirname'];
$zipArchive = new \ZipArchive();
$resource = $zipArchive->open($source);
if ($resource === true) {
$zipArchive->extractTo($dirname);
$zipArchive->close();
}
}
/**
* 生成全球唯一标识uuid
* @param string $source
*/
public function uuid(){
if (function_exists('com_create_guid')) {
return com_create_guid();
} else {
mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45);// "-"
$uuid = substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12);
return $uuid;
}
}
}
\ No newline at end of file
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* Date: 2018/12/18 * Date: 2018/12/18
* Time: 16:56 * Time: 16:56
*/ */
namespace common\models\psources; namespace common\models\psources;
use common\core\BaseActiveRecord; use common\core\BaseActiveRecord;
...@@ -12,6 +13,10 @@ use Yii; ...@@ -12,6 +13,10 @@ use Yii;
class CoinBannerItem extends BaseActiveRecord class CoinBannerItem extends BaseActiveRecord
{ {
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public static function getDb() public static function getDb()
{ {
return Yii::$app->get('p_sources'); return Yii::$app->get('p_sources');
...@@ -22,6 +27,26 @@ class CoinBannerItem extends BaseActiveRecord ...@@ -22,6 +27,26 @@ class CoinBannerItem extends BaseActiveRecord
return '{{coin_banner_item}}'; return '{{coin_banner_item}}';
} }
public function rules()
{
return [
[['image_url', 'platform_id'], 'required'],
['banner_url', 'default', 'value' => '#'],
[['banner_url', 'title'], 'safe'],
[['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 = []) public static function getItems($condition = [])
{ {
return self::find()->joinWith('platform')->where($condition)->asArray()->all(); return self::find()->joinWith('platform')->where($condition)->asArray()->all();
...@@ -34,6 +59,6 @@ class CoinBannerItem extends BaseActiveRecord ...@@ -34,6 +59,6 @@ class CoinBannerItem extends BaseActiveRecord
public function getPlatform() public function getPlatform()
{ {
return $this->hasOne(CoinPlatform::className(), ['id'=>'platform_id']); return $this->hasOne(CoinPlatform::className(), ['id' => 'platform_id']);
} }
} }
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
class CoinIssueChainRecord extends CommonActiveRecord
{
//定义场景
const SCENARIOS_PRE_CREATE = 'create';
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_issue_chain_record}}';
}
public function rules()
{
return [
[['pre_create_tx', 'pre_send_transaction', 'pre_query_transaction', 'finish_tx', 'finish_send_transaction', 'finish_query_transaction', 'issue_coin_id'], 'required'],
[['issue_coin_id'], 'integer'],
[['finish_tx'], 'safe']
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_PRE_CREATE => ['pre_create_tx', 'pre_send_transaction', 'pre_query_transaction', 'finish_tx', 'finish_send_transaction', 'finish_query_transaction', 'issue_coin_id'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function getCoin()
{
return $this->hasOne(CoinIssueCoin::className(), ['id' => 'issue_coin_id']);
}
public function getAdvance()
{
return $this->hasOne(CoinIssueCoin::className(), ['id' => 'issue_coin_id'])->where(['status' => CoinIssueCoin::STATUS_ADVANCE]);
}
public function getConfirm()
{
return $this->hasOne(CoinIssueCoin::className(), ['id' => 'issue_coin_id'])->where(['>', 'status', CoinIssueCoin::STATUS_CONFIRM]);
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
use yii\db\Expression;
class CoinIssueCoin extends CommonActiveRecord
{
const UN_PAY = 0;
const ALLOW_PAY = 1;
const SUCCESS_PAY = 2;
const STATUS_ADVANCE = 0; //预发行,待确认
const STATUS_PEDDING = 1; //预发行成功,待用户确认
const STATUS_CANCEL = 2; //用户点击撤消后的状态
const STATUS_CANCEL_SUCCESS = 3; //撤消成功
const STATUS_CANCEL_FAILED = 4; //撤消失败
const STATUS_CONFIRM = 5; //用户点击确认后的状态
const STATUS_ALLOW = 6; //开启人工审核,管理员后台点击通过后的状态 (未开启人工审核,跳过该状态)
const STATUS_REFUSE = 7; //开启人工审核,管理员后台点击拒绝后的状态 (未开启人工审核,跳过该状态)
const STATUS_SUCCESS = 8; //发行成功
const STATUS_FAILED = 9; //(预)发行失败
const TYPE_NO = 0; //不是增发
const TYPE_YES = 1; //是增发
const ISSUE_TOKEN = 'issue_token';
const REVOKE_TOKEN = 'revoke_token';
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
const SCENARIOS_CANCEL = 'cancel';
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_issue_coin}}';
}
public function rules()
{
return [
[['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'type', 'platform_id', 'chain_id', 'charge_unit_id', 'charge'], 'required'],
[['total', 'category', 'type', 'platform_id', 'chain_id', 'charge_unit_id'], 'integer'],
['introduction', 'string', 'length' => [1, 20]],
['symbol', 'string', 'length' => [1, 6]],
['name', 'string', 'length' => [1, 20]],
#['status', 'in', 'range' => [1, 2, 0]],
['name', 'verfiyName'],
['symbol', 'verfiySymbol'],
['total', 'verfiyAmount']
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'type', 'platform_id', 'chain_id', 'charge_unit_id', 'charge'],
self:: SCENARIOS_UPDATE => ['status'],
self:: SCENARIOS_CANCEL => ['status'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function verfiyName($attribute, $params)
{
//增发
if (CoinIssueCoin::TYPE_YES == $this->type) {
$model = CoinIssueCoin::find()->where(['name' => $this->name, 'owner' => $this->owner, 'platform_id' => $this->platform_id, 'status' => CoinIssueCoin::STATUS_SUCCESS])->orderBy('id desc')->one();
if (false == $model) {
$this->addError($attribute, '该Token币种尚未发行');
return false;
}
if (0 == $model->category) {
$this->addError($attribute, '该Token币种不可增发');
return false;
}
}
//非增发
if (CoinIssueCoin::TYPE_NO == $this->type) {
$model = CoinIssueCoin::find()->where(['name' => $this->name, 'platform_id' => $this->platform_id, 'status' => CoinIssueCoin::STATUS_SUCCESS])->orderBy('id desc')->one();
if ($model) {
$this->addError($attribute, 'Token名称已存在');
return false;
}
}
}
public function verfiySymbol($attribute, $params)
{
if (!preg_match('/^[A-Z]+$/', $this->symbol)) {
$this->addError($attribute, 'Token简称必须大写');
return false;
}
if (CoinIssueCoin::TYPE_YES == $this->type) {
$model = CoinIssueCoin::find()->where(['symbol' => $this->symbol, 'owner' => $this->owner, 'platform_id' => $this->platform_id, 'status' => CoinIssueCoin::STATUS_SUCCESS])->orderBy('id desc')->one();
if (false == $model) {
$this->addError($attribute, '该Token币种尚未发行');
return false;
}
if (0 == $model->category) {
$this->addError($attribute, '该Token币种不可增发');
return false;
}
}
if (CoinIssueCoin::TYPE_NO == $this->type) {
$model = CoinIssueCoin::find()->where(['symbol' => $this->symbol, 'platform_id' => $this->platform_id, 'status' => CoinIssueCoin::STATUS_SUCCESS])->orderBy('id desc')->one();
if ($model) {
$this->addError($attribute, 'Token名称已存在');
return false;
}
}
}
public function verfiyAmount($attribute, $params)
{
if (CoinIssueCoin::TYPE_YES == $this->type) {
if ($this->$attribute > 10) {
$this->addError($attribute, '增发发行量不能超过10亿');
return false;
}
}
$issue_record = CoinIssueCoin::find()->where(['platform_id' => $this->platform_id, 'symbol' => $this->symbol, 'status' => CoinIssueCoin::STATUS_SUCCESS])->sum('total');
$issue_record = empty($issue_record) ? 0 : $issue_record;
if ($issue_record + $this->$attribute > 900) {
$this->addError($attribute, '最大发行量900亿,目前已发行' . $issue_record . '亿');
return false;
}
}
public function attributeLabels()
{
return [
'name' => 'Token全称',
'symbol' => 'Token简称',
'total' => '发行数量',
'owner' => '接收地址',
'introduction' => 'Token简介',
'category' => '是否增发',
'chain_id' => '平行链名称',
'msg' => '失败原因',
'status' => '状态',
'charge_unit_id' => '手续费',
];
}
public function attributes()
{
return array_merge(parent::attributes(), ['issue_charge', 'charge_unit', 'url', 'chain_name']);
}
/**
* 获取状态数组
* @return array
*/
public static function getAgentStatus()
{
return [
self::STATUS_SUCCESS => '发行成功',
self::STATUS_FAIL => '发行失败',
];
}
public function getChain()
{
return $this->hasOne(CoinPlatformWithHold::className(), ['id' => 'chain_id']);
}
public function getPlatform()
{
return $this->hasOne(CoinPlatform::className(), ['id' => 'platform_id']);
}
public function getGas()
{
return $this->hasOne(CoinSupportedCoin::className(), ['id' => 'charge_unit_id']);
}
public function getTransfer()
{
return $this->hasOne(CoinIssueChainRecord::className(), ['issue_coin_id' => 'id']);
}
public function getRevoke()
{
return $this->hasOne(CoinIssueRevokeRecord::className(), ['issue_coin_id' => 'id']);
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
class CoinIssueRecord extends CommonActiveRecord
{
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_issue_record}}';
}
public function rules()
{
return [
[['platform_id', 'total'], 'required'],
[['total', 'platform_id'], 'integer'],
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['platform_id', 'total'],
self:: SCENARIOS_UPDATE => ['platform_id', 'total'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
class CoinIssueRevokeRecord extends CommonActiveRecord
{
//定义场景
const SCENARIOS_CREATE = 'create';
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coins_issue_revoke_record}}';
}
public function rules()
{
return [
[['revoke_tx', 'revoke_send_transaction', 'issue_coin_id'], 'required'],
[['issue_coin_id'], 'integer'],
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['revoke_tx', 'revoke_send_transaction', 'issue_coin_id', 'revoke_query_transaction'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function getCoin()
{
return $this->hasOne(CoinIssueCoin::className(), ['id' => 'issue_coin_id']);
}
}
\ No newline at end of file
...@@ -10,6 +10,7 @@ namespace common\models\psources; ...@@ -10,6 +10,7 @@ namespace common\models\psources;
class CoinPlatform extends BaseActiveRecord class CoinPlatform extends BaseActiveRecord
{ {
public static function tableName() public static function tableName()
{ {
return '{{%coin_platform}}'; return '{{%coin_platform}}';
...@@ -73,4 +74,19 @@ class CoinPlatform extends BaseActiveRecord ...@@ -73,4 +74,19 @@ class CoinPlatform extends BaseActiveRecord
return ['code' => $exception->getCode(), 'message' => $exception->getMessage()]; return ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
} }
} }
public function attributes()
{
return array_merge(parent::attributes(), ['chain_name', 'charge_unit']);
}
public function getChain()
{
return $this->hasOne(CoinPlatformWithHold::className(), ['id' => 'chain_id']);
}
public function getGas()
{
return $this->hasOne(CoinSupportedCoin::className(), ['id' => 'charge_unit_id']);
}
} }
<?php
namespace common\models\psources;
use Yii;
use yii\db\Expression;
class CoinSupportedCoin extends CommonActiveRecord
{
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_supported_coin}}';
}
public function rules()
{
return [
[['platform_id', 'coin_name'], 'required'],
[['platform_id'], 'integer'],
['coin_name', 'string', 'length' => [1, 50]],
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['platform_id', 'coin_name'],
self:: SCENARIOS_UPDATE => ['platform_id', 'coin_name'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function attributeLabels()
{
return [
'platform_id' => '所属钱包',
'coin_name' => '币种名称',
];
}
public static function getList($page = 1, $limit = 10, $condition = [])
{
$query = self::find();
foreach ($condition as $item) {
$query = $query->andWhere($item);
}
$count = $query->count();
$data = $query->offset(($page - 1) * 10)->limit($limit)->asArray()->all();
return ['count' => $count, 'data' => $data];
}
public function addOne($params)
{
$params = array_filter($params, function ($value) {
if (null == $value) {
return false;
}
return true;
});
$this->setAttributes($params, false);
try {
return (bool)$this->save();
} catch (\Exception $exception) {
return ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
}
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
use yii\db\ActiveRecord;
use yii\helpers\ArrayHelper;
use yii\web\Linkable;
use yii\web\Link;
class CommonActiveRecord extends ActiveRecord
{
public $cacheKeyStorage = []; //缓存key寄存器
public function toArray(array $fields = [], array $expand = [], $recursive = true)
{
$data = [];
$cachePrefix = __CLASS__;
$cache = Yii::$app->cache;
foreach ($this->resolveFields($fields, $expand) as $field => $definition) {
if (strpos($field, '.')) {
$fieldChunks = explode('.', $field);
$primaryKey = is_array($this->primaryKey) ? implode('-', $this->primaryKey) : $this->primaryKey;
$uniqueRelationCacheKey = "{$cachePrefix}_{$primaryKey}_{$fieldChunks[0]}";
$this->addCacheKeyToStorage($uniqueRelationCacheKey);
$relation = $cache->get($uniqueRelationCacheKey);
if (!$relation) {
$relation = $this->{$fieldChunks[0]};
$cache->set($uniqueRelationCacheKey, $relation);
}
if (is_array($relation)) {
foreach ($relation as $relatedField => $relatedObject) {
if (!is_object($relatedObject)) {
continue;
}
$data[$fieldChunks[0]][$relatedField][$fieldChunks[1]] = $this->getRelationField($relatedObject, $fieldChunks[1]);
}
} else {
if (!is_object($relation)) {
continue;
}
$data[$fieldChunks[0]][$fieldChunks[1]] = $this->getRelationField($relation, $fieldChunks[1]);
}
} else {
$data[$field] = is_string($definition) ? $this->$definition : call_user_func($definition, $this, $field);
}
}
$this->deleteStorageCaches();
if ($this instanceof Linkable) {
$data['_links'] = Link::serialize($this->getLinks());
}
return $recursive ? ArrayHelper::toArray($data) : $data;
}
/**
* This method also will check relations which are declared in [[extraFields()]]
* to determine which related fields can be returned.
* @inheritdoc
*/
protected function resolveFields(array $fields, array $expand)
{
$result = [];
foreach ($this->fields() as $field => $definition) {
if (is_integer($field)) {
$field = $definition;
}
if (empty($fields) || in_array($field, $fields, true)) {
$result[$field] = $definition;
}
}
if (empty($expand)) {
return $result;
}
$extraFieldsKeys = array_keys($this->extraFields());
foreach($expand as $expandedAttribute) {
if(in_array(explode('.',$expandedAttribute)[0], $this->extraFields())) {
$result[$expandedAttribute] = $expandedAttribute;
}else if(in_array($expandedAttribute, $extraFieldsKeys)) {
$result[$expandedAttribute] = $this->extraFields()[$expandedAttribute];
}
}
return $result;
}
/**
* Additional method to check the related model has specified field
*/
private function getRelationField($relatedRecord, $field)
{
if (!$relatedRecord->hasAttribute($field) && !$relatedRecord->isRelationPopulated($field)) {
throw new \yii\web\ServerErrorHttpException(sprintf(
"Related record '%s' does not have attribute '%s'",
get_class($relatedRecord), $field)
);
}
if($relatedRecord->hasAttribute($field)) {
return ArrayHelper::toArray($relatedRecord)[$field];
} else {
return $relatedRecord->{$field};
}
}
public static function quoteDbName($dbname)
{
return '`' . $dbname . '`';
}
/**
* 添加cache key到寄存器
* @param type $cacheKey
*/
public function addCacheKeyToStorage($cacheKey)
{
if(!in_array($cacheKey, $this->cacheKeyStorage)) {
$this->cacheKeyStorage[] = $cacheKey;
}
}
/**
* 删除寄存器里所有的cache
*/
public function deleteStorageCaches()
{
foreach($this->cacheKeyStorage as $cacheKey) {
Yii::$app->cache->delete($cacheKey);
}
}
}
\ No newline at end of file
<?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'],
['slogan', 'string', 'max' => 50],
[['icon'], 'url']
];
}
public function attributeLabels()
{
return [
'name' => '应用名称',
'icon' => '应用图标',
'app_url' => 'H5链接',
'slogan' => '应用宣传语',
'type' => '应用类型',
'sort' => '应用排序',
'status' => '应用状态'
];
}
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'])->where(['status' => ExploreApp::STATUS_ON])->orderBy('sort');
}
}
\ No newline at end of file
...@@ -246,6 +246,16 @@ class Chain33Service ...@@ -246,6 +246,16 @@ class Chain33Service
return $this->send($params, 'Chain33.QueryTransaction'); return $this->send($params, 'Chain33.QueryTransaction');
} }
public function query()
{
$params = [
"execer" => 'manage',
"funcName" => "GetConfigItem",
"payload" => ['data' => 'token-finisher']
];
return $this->send($params, 'Chain33.Query');
}
public function getBalance($address, $execer) public function getBalance($address, $execer)
{ {
$params = [ $params = [
...@@ -298,6 +308,29 @@ class Chain33Service ...@@ -298,6 +308,29 @@ class Chain33Service
return $this->send($params, 'Chain33.SignRawTx'); return $this->send($params, 'Chain33.SignRawTx');
} }
public function createRawTokenPreCreateTx($params)
{
return $this->send($params, 'token.CreateRawTokenPreCreateTx');
}
public function createRawTokenFinishTx($symbol, $owner)
{
$params = [
'symbol' => $symbol,
'owner' => $owner
];
return $this->send($params, 'token.CreateRawTokenFinishTx');
}
public function createRawTokenRevokeTx($symbol, $owner)
{
$params = [
'symbol' => $symbol,
'owner' => $owner
];
return $this->send($params, 'token.CreateRawTokenRevokeTx');
}
public function getBlock2MainInfo($start, $end) public function getBlock2MainInfo($start, $end)
{ {
$params = [ $params = [
......
<?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)));
}
}
}
}
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-8-7
* Time: 上午11:30
*/
namespace common\service\exchange;
use linslin\yii2\curl\Curl;
class Dag extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_dag';
protected $quotation_prefix = 'quotation_dag_';
protected $base_url = 'https://www.7xex.com/m/ticker/DAGUSDT';
public function symbolExists($tag = 'DAG', $aim = "USDT")
{
$supported = $this->redis->smembers($this->supported_symbol);
if (is_array($supported) && in_array($this->formatSymbol($tag, $aim), $supported)) {
return true;
}
return false;
}
/**
* 转化交易对为请求变量
*
* @param string $tag
* @param string $aim
* @return mixed
*/
public function formatSymbol($tag = 'DAG', $aim = 'USDT')
{
return strtoupper($tag . $aim);
}
/**
* 保存支持的交易对到redis数据库,使用crontab定时更新
*
* @return mixed|void
*/
public function setSupportedSymbol()
{
$this->redis->sadd($this->supported_symbol, 'DAGUSDT');
}
/**
* 更新交易对行情保存到redis,使用crontab定时更新
*
* @return mixed|void
*/
public function setQuotation()
{
$curl = new Curl();
$content = $curl->get($this->base_url, false);
if (is_array($content)) {
$key = $this->quotation_prefix . 'DAGUSDT';
$this->redis->hmset($key, 'low', $content['low'], 'high', $content['high'], 'last', $content['close'], 'open', $content['open'], 'vol', $content['volume']);
$this->redis->sadd($this->supported_symbol, 'DAGUSDT');
}
}
}
\ No newline at end of file
...@@ -114,6 +114,12 @@ class BinanceBuilder extends FactoryService ...@@ -114,6 +114,12 @@ class BinanceBuilder extends FactoryService
$temp = []; $temp = [];
$temp['symbol'] = strtoupper($symbol); $temp['symbol'] = strtoupper($symbol);
$temp['close'] = $close; $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['low'] = $low;
$temp['high'] = $high; $temp['high'] = $high;
$temp['open'] = $open; $temp['open'] = $open;
...@@ -124,7 +130,7 @@ class BinanceBuilder extends FactoryService ...@@ -124,7 +130,7 @@ class BinanceBuilder extends FactoryService
$this->redis_ticker->hmset($key, 'low', $low, 'high', $high, 'last', $close, 'open', $open, 'vol', $vol); $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_asc);
$this->redis_ticker->del($this->supported_symbol_close_desc); $this->redis_ticker->del($this->supported_symbol_close_desc);
foreach ($ticker_sort_close as $val) { 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', 'BTCCNYT', 'ETCCNYT', 'ETHCNYT', 'GHPCNYT', 'LTCCNYT'])) {
$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']));
}
}
}
<?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 DagBuilder extends FactoryService
{
protected $supported_symbol = 'supported_symbol_dag';
protected $quotation_prefix = 'quotation_dag_';
public function getHotTicker($symbol = [])
{
if (empty($symbol)) {
return ['code' => $this->code, 'ticker' => []];
}
$ticker = [];
foreach ($symbol as $val) {
list($low, $high, $close, $open, $vol) = $this->redis->hmget($this->quotation_prefix . strtoupper($val), 'low', 'high', 'last', 'open', 'vol');
$explode_arr = explode('usdt', $val);
$temp = [];
$temp['symbol'] = strtoupper($explode_arr[0]) . '/USDT';
$temp['currency'] = strtoupper($explode_arr[0]);
$temp['base_currency'] = 'USDT';
$temp['close'] = (float)sprintf("%0.6f", $close);
$temp['close_usd'] = (float)sprintf("%0.6f", $close * $this->basic_price['USDT']['usd']);
$temp['close_rmb'] = (float)sprintf("%0.4f", $close * $this->basic_price['USDT']['rmb']);
$temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100);
$temp['high_usd'] = (float)sprintf("%0.4f", $high * $this->basic_price['USDT']['usd']);
$temp['low_usd'] = (float)sprintf("%0.4f", $low * $this->basic_price['USDT']['usd']);
$temp['high_rmb'] = (float)sprintf("%0.4f", $high * $this->basic_price['USDT']['rmb']);
$temp['low_rmb'] = (float)sprintf("%0.4f", $low * $this->basic_price['USDT']['rmb']);
$temp['vol'] = (float)sprintf("%0.4f", $vol);
array_push($ticker, $temp);
}
if (count($ticker) > 0) {
$this->code = 0;
}
return ['code' => $this->code, 'ticker' => $ticker];
}
}
...@@ -13,7 +13,7 @@ use linslin\yii2\curl\Curl; ...@@ -13,7 +13,7 @@ use linslin\yii2\curl\Curl;
abstract class FactoryService abstract class FactoryService
{ {
protected $code = -1; protected $code = -1;
protected $basic_coin = ['ETH', 'BTC', 'USDT', 'BTY']; protected $basic_coin = ['ETH', 'BTC', 'USDT', 'BTY', 'CNYT'];
protected $basic_price = []; protected $basic_price = [];
protected $redis; protected $redis;
...@@ -31,6 +31,7 @@ abstract class FactoryService ...@@ -31,6 +31,7 @@ abstract class FactoryService
"btc,btc", "btc,btc",
"usdt,ethereum", "usdt,ethereum",
"bty,bty", "bty,bty",
"cnyt,bitnasdaqchain"
] ]
]; ];
$params = json_encode($data); $params = json_encode($data);
......
...@@ -97,8 +97,8 @@ class HuobiBuilder extends FactoryService ...@@ -97,8 +97,8 @@ class HuobiBuilder extends FactoryService
$temp['symbol'] = strtoupper($explode_arr[0]) . '/' . $coin; $temp['symbol'] = strtoupper($explode_arr[0]) . '/' . $coin;
$temp['currency'] = strtoupper($explode_arr[0]); $temp['currency'] = strtoupper($explode_arr[0]);
$temp['base_currency'] = strtoupper($coin); $temp['base_currency'] = strtoupper($coin);
$temp['close'] = rtrim(sprintf('%.8f', floatval($close)),'0'); $temp['close'] = rtrim(sprintf('%.8f', floatval($close)), '0');
$temp['close_usd'] = rtrim(sprintf('%.6f', floatval($close * $this->basic_price[$coin]['usd'])),'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['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['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['high_usd'] = (float)sprintf("%0.4f", $high * $this->basic_price[$coin]['usd']);
...@@ -135,6 +135,12 @@ class HuobiBuilder extends FactoryService ...@@ -135,6 +135,12 @@ class HuobiBuilder extends FactoryService
$temp = []; $temp = [];
$temp['symbol'] = strtoupper($symbol); $temp['symbol'] = strtoupper($symbol);
$temp['close'] = $close; $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['low'] = $low;
$temp['high'] = $high; $temp['high'] = $high;
$temp['open'] = $open; $temp['open'] = $open;
...@@ -145,7 +151,7 @@ class HuobiBuilder extends FactoryService ...@@ -145,7 +151,7 @@ class HuobiBuilder extends FactoryService
$this->redis_ticker->hmset($key, 'low', $low, 'high', $high, 'last', $close, 'open', $open, 'vol', $vol); $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_asc);
$this->redis_ticker->del($this->supported_symbol_close_desc); $this->redis_ticker->del($this->supported_symbol_close_desc);
foreach ($ticker_sort_close as $val) { foreach ($ticker_sort_close as $val) {
...@@ -162,20 +168,15 @@ class HuobiBuilder extends FactoryService ...@@ -162,20 +168,15 @@ class HuobiBuilder extends FactoryService
} }
} }
public function getHotTicker() public function getHotTicker($symbol = [])
{ {
$symbol = [ if (empty($symbol)) {
'btcusdt', return ['code' => $this->code, 'ticker' => []];
'ethusdt', }
'btyusdt'
];
$ticker = []; $ticker = [];
foreach ($symbol as $val) { foreach ($symbol as $val) {
if ('btyusdt' == $val) {
list($low, $high, $close, $open, $vol) = $this->redis->hmget('quotation_zhaobi_' . strtolower($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'); list($low, $high, $close, $open, $vol) = $this->redis->hmget($this->quotation_prefix . strtolower($val), 'low', 'high', 'last', 'open', 'vol');
}
$explode_arr = explode('usdt', $val); $explode_arr = explode('usdt', $val);
$temp = []; $temp = [];
$temp['symbol'] = strtoupper($explode_arr[0]) . '/USDT'; $temp['symbol'] = strtoupper($explode_arr[0]) . '/USDT';
......
...@@ -103,13 +103,21 @@ class ZhaobiBuilder extends FactoryService ...@@ -103,13 +103,21 @@ class ZhaobiBuilder extends FactoryService
$temp = []; $temp = [];
$temp['symbol'] = strtoupper($symbol); $temp['symbol'] = strtoupper($symbol);
$temp['close'] = number_format($close, 6, '.', ''); $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']);
}
if ('SFTCNY' == strtoupper($symbol)) {
$temp['close_rmb'] = (float)sprintf("%0.4f", $close * 1);
}
}
$temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100); $temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100);
array_push($ticker, $temp); array_push($ticker, $temp);
$key = $this->quotation_prefix . strtoupper($symbol); $key = $this->quotation_prefix . strtoupper($symbol);
$this->redis_ticker->hmset($key, 'low', $low, 'high', $high, 'last', $close, 'open', $open, 'vol', $vol); $this->redis_ticker->hmset($key, 'low', $low, 'high', $high, 'last', $close, 'open', $open, 'vol', $vol);
} }
$ticker_sort_close = Tools::arraySort($ticker, 'close_rmb');
$ticker_sort_close = Tools::arraySort($ticker, 'close');
$this->redis_ticker->del($this->supported_symbol_close_asc); $this->redis_ticker->del($this->supported_symbol_close_asc);
$this->redis_ticker->del($this->supported_symbol_close_desc); $this->redis_ticker->del($this->supported_symbol_close_desc);
foreach ($ticker_sort_close as $val) { foreach ($ticker_sort_close as $val) {
...@@ -159,13 +167,34 @@ class ZhaobiBuilder extends FactoryService ...@@ -159,13 +167,34 @@ class ZhaobiBuilder extends FactoryService
return ['code' => $this->code, 'notice' => $data]; return ['code' => $this->code, 'notice' => $data];
} }
protected function arraySort($array, $keys, $sort = SORT_DESC) public function getHotTicker($symbol = [])
{ {
$keysValue = []; if (empty($symbol)) {
foreach ($array as $k => $v) { return ['code' => $this->code, 'ticker' => []];
$keysValue[$k] = $v[$keys]; }
$ticker = [];
foreach ($symbol as $val) {
list($low, $high, $close, $open, $vol) = $this->redis->hmget($this->quotation_prefix . strtolower($val), 'low', 'high', 'last', 'open', 'vol');
$explode_arr = explode('usdt', $val);
$temp = [];
$temp['symbol'] = strtoupper($explode_arr[0]) . '/USDT';
$temp['currency'] = strtoupper($explode_arr[0]);
$temp['base_currency'] = 'USDT';
$temp['close'] = (float)sprintf("%0.6f", $close);
$temp['close_usd'] = (float)sprintf("%0.6f", $close * $this->basic_price['USDT']['usd']);
$temp['close_rmb'] = (float)sprintf("%0.4f", $close * $this->basic_price['USDT']['rmb']);
$temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100);
$temp['high_usd'] = (float)sprintf("%0.4f", $high * $this->basic_price['USDT']['usd']);
$temp['low_usd'] = (float)sprintf("%0.4f", $low * $this->basic_price['USDT']['usd']);
$temp['high_rmb'] = (float)sprintf("%0.4f", $high * $this->basic_price['USDT']['rmb']);
$temp['low_rmb'] = (float)sprintf("%0.4f", $low * $this->basic_price['USDT']['rmb']);
$temp['vol'] = (float)sprintf("%0.4f", $vol);
array_push($ticker, $temp);
}
if (count($ticker) > 0) {
$this->code = 0;
} }
array_multisort($keysValue, $sort, $array); return ['code' => $this->code, 'ticker' => $ticker];
return $array;
} }
} }
\ No newline at end of file
...@@ -207,36 +207,5 @@ class CrossChainController extends Controller ...@@ -207,36 +207,5 @@ class CrossChainController extends Controller
$this->queryTransaction($node_params, $result['result']['tx']['next']); $this->queryTransaction($node_params, $result['result']['tx']['next']);
} }
return $result; return $result;
// if (isset($result['result']['actionName']) && 'unknown' == $result['result']['actionName']) {
// if (isset($result['result']['tx']['next'])) {
// $this->queryTransaction($node_params, $result['result']['tx']['next']);
// }
// }
//
// if (isset($result['result']['receipt']['ty']) && 2 == $result['result']['receipt']['ty']){
// if (isset($result['result']['tx']['next'])) {
// $this->queryTransaction($node_params, $result['result']['tx']['next']);
// }
// }
//
// return $result;
// if (isset($result['result']['receipt']) && is_array($result['result']['receipt']['logs'])){
// foreach ($result['result']['receipt']['logs'] as $log) {
// if (isset($log['tyName']) && 'logerr' == strtolower($log['tyName'])){
// return $result;
// }
// }
// }
// static $result = [];
// $service = new Chain33Service($node_params);
// $result = $service->QueryTransaction($send_result);
// echo json_encode($result) . PHP_EOL;
// if (isset($result['result']['tx']['next'])) {
// $this->queryTransaction($node_params, $result['result']['tx']['next']);
// }
// return $result;
} }
} }
This diff is collapsed.
This diff is collapsed.
...@@ -14,7 +14,7 @@ class TickerController extends Controller ...@@ -14,7 +14,7 @@ class TickerController extends Controller
{ {
public function actionSort() public function actionSort()
{ {
$class = ['Binance', 'Huobi', 'Zhaobi']; $class = ['Binance', 'Huobi', 'Zhaobi', 'Bitnasdaq'];
foreach ($class as $val) { foreach ($class as $val) {
go(function () use ($val) { go(function () use ($val) {
\Co::sleep(0.5); \Co::sleep(0.5);
...@@ -22,6 +22,8 @@ class TickerController extends Controller ...@@ -22,6 +22,8 @@ class TickerController extends Controller
$ticker_builder->TickerSort(); $ticker_builder->TickerSort();
}); });
} }
echo date('Y-m-d H:i:s') .'排序更新成功' . PHP_EOL;
return 0;
} }
public function actionHot() public function actionHot()
......
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 common\models\psources\CoinPlatform;
use common\models\psources\CoinSupportedCoin;
use Yii;
use wallet\base\BaseController;
class IssueChainController extends BaseController
{
/**
* 可发行链列表
* @return array
*/
public function actionIndex()
{
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
if (1 == $platform_id) {
$chain_model = CoinPlatform::find()->all();
} else {
$chain_model = CoinPlatform::find()->where(['id' => $platform_id])->all();
}
if (false == $chain_model) {
$msg = '不存在的链';
$code = -1;
goto doEnd;
}
foreach ($chain_model as &$val) {
$val->chain_name = isset($val->chain->platform) ? $val->chain->platform : '';
unset($val->download_url);
unset($val->introduce);
unset($val->create_time);
unset($val->update_time);
unset($val->chain_id);
}
$msg = 'ok';
$code = 0;
$data = $chain_model;
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
/**
* 发行链信息
* @return array
*/
public function actionChainInfo()
{
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
if (empty($platform_id)) {
$msg = '缺少必要的参数';
$code = -1;
goto doEnd;
}
if (1 == $platform_id) {
$chain_model = CoinPlatform::find()->select('id, chain_id')->all();
} else {
$chain_model = CoinPlatform::find()->select('id, chain_id')->where(['id' => $platform_id])->all();
}
if (false == $chain_model) {
$msg = '不存在的链';
$code = -1;
goto doEnd;
}
foreach ($chain_model as &$val) {
$val->chain_name = isset($val->chain->platform) ? $val->chain->platform : '';
$coin_supported_coin = CoinSupportedCoin::find()->select('id, coin_name')->where(['platform_id' => $val->id])->asArray()->all();
$val->charge_unit = $coin_supported_coin;
}
$msg = 'ok';
$code = 0;
$data = is_array($chain_model) ? $chain_model : [$chain_model];
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
/**
* 设置手续费
* @param integer issue_charge
* @param integer charge_unit_id
* @param integer platform_id
* @return array
*/
public function actionSetCharge()
{
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
$result = Yii::$app->request->post();
$issue_charge = isset($result['issue_charge']) ? $result['issue_charge'] : '';
$charge_unit_id = isset($result['charge_unit_id']) ? strtoupper($result['charge_unit_id']) : '';
$id = isset($result['platform_id']) ? (int)$result['platform_id'] : 0;
if (false == $issue_charge || false == $charge_unit_id) {
$msg = '提交数据有误';
$code = -1;
goto doEnd;
}
if (1 == $platform_id) {
$platform_id = $id;
}
$chain_model = CoinPlatform::find()->where(['id' => $platform_id])->one();
if (false == $chain_model) {
$msg = '不存在的链';
$code = -1;
goto doEnd;
}
$chain_model->issue_charge = $issue_charge;
$chain_model->charge_unit_id = $charge_unit_id;
if (false == $chain_model->save()) {
$msg = '手续费设置失败';
$code = -1;
goto doEnd;
}
$msg = 'ok';
$code = 0;
doEnd :
return ['code' => $code, 'msg' => $msg];
}
/**
* 人工审核开启/关闭
* @param string manual_review
* @return array
*/
public function actionManageReview()
{
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
if (1 != $platform_id) {
$msg = '当前账户无权限操作';
$code = -1;
goto doEnd;
}
$manual_review = \Yii::$app->request->post('manual_review', '');
if (!in_array($manual_review, ['open', 'close'])) {
$msg = '参数错误';
$code = -1;
goto doEnd;
}
Yii::$app->redis->set('issue_chain_manual_review', $manual_review);
$code = 0;
$msg = 'success';
doEnd :
return ['code' => $code, 'msg' => $msg];
}
}
\ No newline at end of file
<?php
namespace wallet\controllers;
use common\models\psources\CoinIssueChainRecord;
use Yii;
use yii\data\Pagination;
use wallet\base\BaseController;
use common\models\psources\CoinIssueCoin;
class IssueCoinController extends BaseController
{
/**
* 申请列表
* @param integer page
* @param integer size
* @param integer status
* @param string owner
* @param integer chain_id
* @return array
*/
public function actionApplyList()
{
$platform_id = Yii::$app->request->getPlatformId();
$page = \Yii::$app->request->get('page', 1);
$size = \Yii::$app->request->get('size', 10);
$status = \Yii::$app->request->get('status', -1);
$owner = \Yii::$app->request->get('owner', '');
$chain_id = \Yii::$app->request->get('chain_id', '');
if (1 == $platform_id) {
$query = CoinIssueCoin::find()
->select('id, name, total, status, chain_id, charge_unit_id, charge, platform_id, owner, category, type, symbol, introduction, create_time')
->where(['in', 'status', [CoinIssueCoin::STATUS_CONFIRM, CoinIssueCoin::STATUS_ALLOW, CoinIssueCoin::STATUS_REFUSE, CoinIssueCoin::STATUS_SUCCESS, CoinIssueCoin::STATUS_FAILED]])
->orderBy('create_time desc');
} else {
$query = CoinIssueCoin::find()
->select('id, name, total, status, chain_id, charge_unit_id, charge, platform_id, owner, category, type, symbol, introduction, create_time')
->where(['platform_id' => $platform_id])
->andWhere(['in', 'status', [CoinIssueCoin::STATUS_CONFIRM, CoinIssueCoin::STATUS_ALLOW, CoinIssueCoin::STATUS_REFUSE, CoinIssueCoin::STATUS_SUCCESS, CoinIssueCoin::STATUS_FAILED]])
->orderBy('create_time desc');
}
if ($status > -1) {
$query->andWhere(['status' => $status]);
}
if (false != $owner) {
$query->andWhere(['owner' => $owner]);
}
if (false != $chain_id) {
$query->andWhere(['chain_id' => $chain_id]);
}
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $size]);
$models = $query->offset($pages->offset)
->limit($pages->limit)
->all();
foreach ($models as &$val) {
$platform = isset($val->chain->platform) ? $val->chain->platform : '';
$val->chain_name = $platform;
$val->charge_unit = isset($val->gas->coin_name) ? $val->gas->coin_name : '';
$val->url = Yii::$app->redis->hget('platform_brower_info', $platform);
$val->total = (int)$val->total * 1e8;
}
$data = [
'list' => $models,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => $size,
'currentPage' => (int)$page,
]
];
$msg = 'ok';
$code = 0;
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
/**
* 申请详情
* @param integer id
* @return array
*/
public function actionApplyDetail()
{
$id = Yii::$app->request->get('id', '');
$data = null;
if (empty($id)) {
$msg = '缺少必要的参数';
$code = -1;
goto doEnd;
}
$data = CoinIssueCoin::find()->where(['id' => $id])->one();
$platform = isset($data->chain->platform) ? $data->chain->platform : '';
$data->total = (int)$data->total * 1e8;
$data->issue_charge = rtrim(sprintf('%.3f', floatval($data->charge)), '0');
$data->charge_unit = isset($data->gas->coin_name) ? $data->gas->coin_name : '';
$data->url = Yii::$app->redis->hget('platform_brower_info', $platform);
$code = 0;
$msg = 'success';
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
/**
* 申请操作管理
* @param integer id
* @param integer status
* @param string msg
* @return array
*/
public function actionVerify()
{
$id = Yii::$app->request->post('id', '');
$status = Yii::$app->request->post('status', '');
$msg = Yii::$app->request->post('msg', '');
if (false == $id || false == $status) {
$msg = '缺少必要的参数';
$code = -1;
goto doEnd;
}
if (!in_array($status, [CoinIssueCoin::STATUS_ALLOW, CoinIssueCoin::STATUS_REFUSE])) {
$msg = '状态值错误';
$code = -1;
goto doEnd;
}
$model = CoinIssueCoin::findOne($id);
if (false == $model) {
$msg = '不存在的记录';
$code = -1;
goto doEnd;
}
$data = [
'status' => $status,
#'msg' => $msg
];
$model->setScenario(CoinIssueCoin::SCENARIOS_UPDATE);
$model->load($data, '');
if (!$model->save()) {
$msg = current($model->firstErrors);
$code = -1;
goto doEnd;
}
$record = CoinIssueChainRecord::find()->where(['issue_coin_id' => $id])->one();
$record->finish_tx = 'failed';
$record->finish_send_transaction = 'failed';
$record->finish_query_transaction = $msg;
$record->save();
$code = 0;
$msg = 'success';
doEnd :
return ['code' => $code, 'msg' => $msg];
}
}
\ 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