Commit cbd6f4d0 authored by shajiaiming's avatar shajiaiming

fix

parent f4c21ec8
......@@ -35,7 +35,7 @@ class CoinController extends BaseController
public function actionGetCoinById()
{
$request = Yii::$app->request;
$id = $request->post('id', 0);
$id = $request->post('id', 0);
if ($id) {
$ret = CoinBusiness::getCoinAllById($id);
if ($ret) {
......@@ -55,9 +55,9 @@ class CoinController extends BaseController
*/
public function actionGetRecList()
{
$request = Yii::$app->request;
$page = $request->post('page', 1);
$limit = $request->post('limit', 999);
$request = Yii::$app->request;
$page = $request->post('page', 1);
$limit = $request->post('limit', 999);
$platform_id = $request->post('platform_id', 2);//默认币钱包
if ($platform_id == 1) {
$platform_id = 3;
......@@ -73,7 +73,7 @@ class CoinController extends BaseController
$condition['recommend'] = $recommend;
}
$select = ['id', 'sid', 'icon', 'name', 'nickname', 'platform', 'chain'];
$datas = CoinRecommend::getList($page, $limit, $condition, [], $select);
$datas = CoinRecommend::getList($page, $limit, $condition, [], $select);
//获取详细信息
$coin_recommends = &$datas['data'];
if (!empty($coin_recommends)) {
......@@ -81,8 +81,8 @@ class CoinController extends BaseController
//获取币种信息
$coin_infos = Coin::getCoinInfoByIds($coin_ids, $select, 'id');
//获取行情信息
$coin_names = array_column($coin_infos, 'name');
$coin_names = array_merge($coin_names, array_column($coin_infos, 'chain'));
$coin_names = array_column($coin_infos, 'name');
$coin_names = array_merge($coin_names, array_column($coin_infos, 'chain'));
$coin_quotations = ExchangeBusiness::getQuatationByNames($coin_names);
if ($coin_infos) {
......@@ -93,19 +93,19 @@ class CoinController extends BaseController
$value[$item] = $coin_infos[$value['cid']][$item];
if ($value['platform_id'] != 2) {
//国盾币不需要行情
$value['low'] = $coin_quotations[$temp_key]['low'];
$value['low'] = $coin_quotations[$temp_key]['low'];
$value['high'] = $coin_quotations[$temp_key]['high'];
$value['last'] = $coin_quotations[$temp_key]['last'];
$value['rmb'] = $coin_quotations[$temp_key]['rmb'];
$value['rmb'] = $coin_quotations[$temp_key]['rmb'];
} else {
$value['low'] = 0;
$value['low'] = 0;
$value['high'] = 0;
$value['last'] = 0;
$value['rmb'] = 0;
$value['rmb'] = 0;
}
}
$value['id'] = $value['cid'];
$value['sid'] = ucfirst($value['sid']);
$value['id'] = $value['cid'];
$value['sid'] = ucfirst($value['sid']);
$value['chain_quotation'] = $coin_quotations[$coin_infos[$value['cid']]['chain']];
unset($value['create_time'], $value['update_time'], $value['cid']);
}
......@@ -120,9 +120,9 @@ class CoinController extends BaseController
*/
public function actionGetNewRecList()
{
$request = Yii::$app->request;
$page = $request->post('page', 1);
$limit = $request->post('limit', 999);
$request = Yii::$app->request;
$page = $request->post('page', 1);
$limit = $request->post('limit', 999);
$platform_id = $request->post('platform_id', 1);//默认币钱包
$recommend = $request->post('recommend', '');
......@@ -132,20 +132,20 @@ class CoinController extends BaseController
}
$select = ['id', 'sid', 'icon', 'name', 'nickname', 'platform', 'chain', 'treaty'];
$order_by = ['sort' => SORT_ASC];
$datas = CoinRecommend::getList($page, $limit, $condition, $order_by, $select);
$datas = CoinRecommend::getList($page, $limit, $condition, $order_by, $select);
//获取详细信息
$coin_recommends = &$datas['data'];
if (!empty($coin_recommends)) {
$coin_ids = array_column($coin_recommends, 'cid');
//获取币种信息
$coin_infos = Coin::getCoinInfoByIds($coin_ids, $select, 'id');
foreach ($coin_infos as $key => &$val){
foreach ($coin_infos as $key => &$val) {
$nickname = json_decode($val['nickname'], true);
$val['nickname'] = $nickname[$this->lang];
}
//获取行情信息
$coin_names = array_column($coin_infos, 'name');
$coin_names = array_merge($coin_names, array_column($coin_infos, 'chain'));
$coin_names = array_column($coin_infos, 'name');
$coin_names = array_merge($coin_names, array_column($coin_infos, 'chain'));
$coin_quotations = ExchangeBusiness::getQuatationByNames($coin_names);
if ($coin_infos) {
......@@ -156,21 +156,21 @@ class CoinController extends BaseController
$value[$item] = $coin_infos[$value['cid']][$item];
if ($value['platform_id'] != 2) {
//国盾币不需要行情
$value['low'] = $coin_quotations[$temp_key]['low'];
$value['low'] = $coin_quotations[$temp_key]['low'];
$value['high'] = $coin_quotations[$temp_key]['high'];
$value['last'] = $coin_quotations[$temp_key]['last'];
$value['rmb'] = $coin_quotations[$temp_key]['rmb'];
$value['usd'] = $coin_quotations[$temp_key]['usd'] ?? 0;
$value['rmb'] = $coin_quotations[$temp_key]['rmb'];
$value['usd'] = $coin_quotations[$temp_key]['usd'] ?? 0;
} else {
$value['low'] = 0;
$value['low'] = 0;
$value['high'] = 0;
$value['last'] = 0;
$value['rmb'] = 0;
$value['usd'] = 0;
$value['rmb'] = 0;
$value['usd'] = 0;
}
}
$value['id'] = $value['cid'];
$value['sid'] = ucfirst($value['sid']);
$value['id'] = $value['cid'];
$value['sid'] = ucfirst($value['sid']);
$value['chain_quotation'] = $coin_quotations[$coin_infos[$value['cid']]['chain']];
$value['chain_rmb'] = isset($coin_quotations[$coin_infos[$value['cid']]['chain']]['rmb']) ? $coin_quotations[$coin_infos[$value['cid']]['chain']]['rmb'] : 0;
$value['chain_usd'] = isset($coin_quotations[$coin_infos[$value['cid']]['chain']]['usd']) ? $coin_quotations[$coin_infos[$value['cid']]['chain']]['usd'] : 0;
......@@ -179,7 +179,7 @@ class CoinController extends BaseController
unset($key, $value);
}
}
if(!$datas['data']){
if (!$datas['data']) {
$datas['data'] = null;
}
return $datas;
......@@ -195,20 +195,20 @@ class CoinController extends BaseController
public function actionGetMinerFeeByName()
{
$names = Yii::$app->request->post('name');
$coin = Coin::findOne(['name' => $names]);
$coin = Coin::findOne(['name' => $names]);
if ($coin) {
$chain = $coin->chain;
$miner_fee = MinerFee::find()->where(['platform' => $chain,'type' => 1])->one();
if(!$miner_fee){
throw new Exception('8', '旷工费未设置');
}
$chain = $coin->chain;
$miner_fee = MinerFee::find()->where(['platform' => $chain, 'type' => 1])->one();
if (!$miner_fee) {
throw new Exception('8', '旷工费未设置');
}
} else {
//如果coin为null,$coin->minerFee会抛出Trying to get property 'minerFee' of non-object",code=>8
throw new Exception('8', '币种不存在');
}
$result = (array)$miner_fee->getAttributes();
$result['min'] = number_format($result['min'],6);
$result['max'] = number_format($result['max'],6);
$result = (array)$miner_fee->getAttributes();
$result['min'] = number_format($result['min'], 6);
$result['max'] = number_format($result['max'], 6);
return $result;
}
......@@ -217,28 +217,28 @@ class CoinController extends BaseController
*/
public function actionCoinIndex()
{
$names = Yii::$app->request->post('names');
$names = Yii::$app->request->post('names');
$platforms = [];
$newNames = [];
if(!$names){
return ['code' => 0,'data' => []];
if (!$names) {
return ['code' => 0, 'data' => []];
}
foreach($names as $item){
$item_array = explode(',',$item);
foreach ($names as $item) {
$item_array = explode(',', $item);
$newNames [] = $item_array[0];
if(isset($item_array[1])){
if(!in_array($item_array[1],$platforms)){
if (isset($item_array[1])) {
if (!in_array($item_array[1], $platforms)) {
$platforms [] = $item_array[1];
}
}
}
$condition = [['in', 'name', $newNames]];
if($platforms){
if ($platforms) {
$condition[] = ['in', 'platform', $platforms];
}
$result = ExchangeBusiness::getApiListForIndex(1, 999, $condition);
$result = ExchangeBusiness::getApiListForIndex(1, 999, $condition);
if ($result) {
$chains = array_unique(array_column($result['data'], 'chain'));
$chains = array_unique(array_column($result['data'], 'chain'));
$chain_quotation = [];
foreach ($chains as $key => $value) {
$chain_quotation[$value] = ExchangeBusiness::getquatation($value);
......@@ -261,23 +261,23 @@ class CoinController extends BaseController
*/
public function actionSearchCoinByName()
{
$request = Yii::$app->request;
$name = $request->post('name', '');
$page = $request->post('page', 1);
$limit = $request->post('limit', 10);
$request = Yii::$app->request;
$name = $request->post('name', '');
$page = $request->post('page', 1);
$limit = $request->post('limit', 10);
$platform_ids = $request->post('platform_id', null);
$condition = [['in', 'chain', ['ETH','DCR','BTC','BTY']]];
$condition = [['in', 'chain', ['ETH', 'DCR', 'BTC', 'BTY']]];
if (!empty($name)) {
$condition[] = ['or',['address' => $name],['or', ['like', 'name', $name], ['like', 'nickname', $name]]];
$condition[] = ['or', ['address' => $name], ['or', ['like', 'name', $name], ['like', 'nickname', $name]]];
}
if ($platform_ids) {
/* $platform_id_arr = explode(',', $platform_ids);
$condition_arr = ['OR'];
foreach ($platform_id_arr as $key => $value) {
array_push($condition_arr, ['=', 'platform_id', $value]);
}
$condition[] = $condition_arr;*/
/* $platform_id_arr = explode(',', $platform_ids);
$condition_arr = ['OR'];
foreach ($platform_id_arr as $key => $value) {
array_push($condition_arr, ['=', 'platform_id', $value]);
}
$condition[] = $condition_arr;*/
$condition[] = ['>', "find_in_set($platform_ids, platform_id)", 0];
}
......@@ -285,10 +285,10 @@ class CoinController extends BaseController
if (empty($result)) {
return ['code' => 0, 'count' => 0, 'data' => []];
}
$total = $result['total'];
$total = $result['total'];
$result = $result['data'];
if ($result) {
$chains = array_unique(array_column($result, 'chain'));
$chains = array_unique(array_column($result, 'chain'));
$chain_quotation = [];
foreach ($chains as $key => $value) {
$chain_quotation[$value] = ExchangeBusiness::getquatation($value);
......@@ -314,8 +314,8 @@ class CoinController extends BaseController
public function actionTransaction()
{
$request = Yii::$app->request;
$name = $request->post('name', '');
$txhash = $request->post('txhash', '');
$name = $request->post('name', '');
$txhash = $request->post('txhash', '');
if ($name && $txhash) {
return BrowerBusiness::getTransStatus($name, $txhash);
}
......@@ -329,12 +329,12 @@ class CoinController extends BaseController
public function actionGetBrowerByPlatform()
{
$request = Yii::$app->request;
$platform = $request->post('platform', '');
if($platform){
$brower_url = Yii::$app->redis->hget('platform_brower_info',$platform);
return ['code' => 0,'data' => $brower_url];
}else{
return ['code' => 1,'data' => [],'msg' => '平台参数不能为空'];
$platform = $request->post('platform', '');
if ($platform) {
$brower_url = Yii::$app->redis->hget('platform_brower_info', $platform);
return ['code' => 0, 'data' => $brower_url];
} else {
return ['code' => 1, 'data' => [], 'msg' => '平台参数不能为空'];
}
}
......@@ -344,14 +344,27 @@ class CoinController extends BaseController
public function actionGetWithHold()
{
$request = Yii::$app->request;
$platform = $request->get('platform', '');
if($platform){
$platform = $request->get('platform', '');
$coin_name = $request->get('coinname', '');
if ($platform && $coin_name) {
$platform_with_hold = CoinPlatformWithHold::getRecord($platform);
if($platform_with_hold){
$coin_info = Coin::find()->select('treaty')->where(['name' => strtoupper($coin_name)])->asArray()->one();
if ($platform_with_hold) {
$des = Yii::$app->des;
$platform_with_hold['private_key'] = $des->encrypt($platform_with_hold['private_key']);
return ['code' => 0,'data' => $platform_with_hold];
}else{
if(1 == $coin_info['treaty']){
$platform_with_hold['exer'] = 'user.p.'. $platform .'.token';
$platform_with_hold['tokensymbol'] = $platform;
$platform_with_hold['fee'] = 0;
} else {
$platform_with_hold['exer'] = 'user.p.'. $platform .'.coins';
$platform_with_hold['tokensymbol'] = $platform .'.coins';
$platform_with_hold['fee'] = (float)sprintf("%0.4f", (double)$platform_with_hold['fee']);
}
$platform_with_hold['bty_fee'] = (float)sprintf("%0.4f", (double)Yii::$app->params['bty_fee']);;
return ['code' => 0, 'data' => $platform_with_hold];
} else {
$data = [
'id' => 0,
'platform' => '',
......@@ -361,8 +374,8 @@ class CoinController extends BaseController
];
return ['code' => 0, 'data' => $data];
}
}else{
return ['code' => 1,'data' => [],'msg' => '平台参数不能为空'];
} else {
return ['code' => 1, 'data' => [], 'msg' => '平台参数或币种名称不能为空'];
}
}
}
......@@ -6,7 +6,6 @@
* Time: 17:37
*/
namespace common\models\psources;
use Yii;
class CoinPlatformWithHold extends BaseActiveRecord
{
......
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