Commit cdab42c9 authored by rlgy's avatar rlgy

推介币种

parent 0ea1024d
......@@ -86,7 +86,12 @@ class CoinController extends BaseController
*/
public function actionGetRecList()
{
//todo 推介币种列表
$request = Yii::$app->request;
$page = $request->post('page', 1);
$limit = $request->post('limit', 999);
$condition = [['recommend' => '1']];
$data = CoinBusiness::getApiList($page, $limit, $condition);
Yii::$app->response->data = $data;
}
/**
......
......@@ -11,8 +11,6 @@ namespace backend\controllers;
use Yii;
use common\models\pwallet\Coin;
use backend\models\coin\CoinForm;
use yii\base\InvalidConfigException;
use yii\db\Exception;
use yii\web\UploadedFile;
use yii\validators\ImageValidator;
use common\business\CoinBusiness;
......@@ -31,14 +29,19 @@ class CoinController extends BaseController
$page = $request->get('page', 1);
$limit = $request->get('limit', 10);
$name = $request->get('name', null);
$platform = $request->get('platform', null);
$platform = $request->get('platform', 'all');
$recommend = $request->get('recommend', 'all');
$condition = [];
if ($name) {
$condition[] = ['like', 'name', $name];
}
if ($platform) {
if ($platform != 'all') {
$condition[] = ['platform' => $platform];
}
if ($recommend != 'all') {
$recommend = $recommend ? 1 : 0;
$condition[] = ['recommend' => $recommend];
}
$data = CoinBusiness::getList($page, $limit, $condition);
$data['code'] = 0;
//ajax return
......@@ -131,9 +134,7 @@ class CoinController extends BaseController
return ['code' => 0, 'data' => ['src' => $src]];
}
}
} catch (InvalidConfigException $e) {
} catch (Exception $exception) {
} catch (\Exception $exception) {
return ['code' => $exception->getCode(), 'msg' => $exception->getMessage()];
}
}
......
......@@ -57,6 +57,15 @@
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">推介该币种</label>
<div class="layui-input-block">
<select name="recommend">
<option value="0"></option>
<option value="1"></option>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">区块查询</label>
<div class="layui-input-block">
<input type="text" class="layui-input" value="" name="area_search">
......@@ -127,4 +136,7 @@
}
});
//form render
var form = layui.form;
form.render();
</script>
......@@ -19,7 +19,7 @@
<button class="layui-btn layui-btn-default" id="add">添加币种</button>
</a>
</div>
<div class="layui-col-md6">
<div class="layui-col-md8">
<form class="layui-form" method="get" action="">
<div class="layui-inline">
<label class="layui-form-label" style="margin-bottom: 0; width: 100px;">币种名称</label>
......@@ -31,12 +31,22 @@
<label class="layui-form-label" style="margin-bottom: 0; width: 100px;">平台</label>
<div class="layui-input-inline">
<select name="platform">
<option>all</option>
<option value="all">全部</option>
<option value="ethereum">eth</option>
</select>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label" style="margin-bottom: 0; width: 100px;">推介币种</label>
<div class="layui-input-inline">
<select name="recommend">
<option value="all">全部</option>
<option value="0"></option>
<option value="1"></option>
</select>
</div>
</div>
<div class="layui-inline">
<button class="layui-btn" lay-submit lay-filter="form1">搜索</button>
</div>
</form>
......@@ -74,6 +84,7 @@
},
{field: 'price', title: '众筹价格'},
{field: 'release', title: '发行时间'},
{field: 'recommend', title: '推介该币种', templet: "#recommendTpl"},
{field: 'id', title: '操作', templet: '#operationTpl'}
]]
})
......@@ -132,3 +143,10 @@
<script type="text/html" id="exchangeTpl">
{{d.exchange.count}}
</script>
<script type="text/html" id="recommendTpl">
{{# if(d.recommend==0){ }}
{{# }else{ }}
{{# } }}
</script>
\ No newline at end of file
......@@ -52,7 +52,7 @@ class CoinBusiness
if ($rows['count'] > 0) {
$datas = $rows['data'];
foreach ($datas as $key => $value) {
//获取交易所信息
//获取行情信息
$rows['data'][$key]['quotation'] = CoinService::quotation($value['sid']);
}
}
......
......@@ -44,7 +44,7 @@ class Coin extends BaseActiveRecord
{
$query = self::find();
foreach ($condition as $item) {
$query = $query->andFilterWhere($item);
$query = $query->andWhere($item);
}
$count = $query->count();
$data = $query->offset(($page - 1) * 10)->limit($limit)->asArray()->all();
......
......@@ -13,6 +13,10 @@ use common\core\BaseActiveRecord;
class MinerFee extends BaseActiveRecord
{
/**
* @return null|object|\yii\db\Connection
* @throws \yii\base\InvalidConfigException
*/
public static function getDb()
{
return Yii::$app->get('db_pwallet');
......
......@@ -8,10 +8,8 @@
namespace common\service;
use common\base\Exception;
use Yii;
use common\helpers\Curl;
use yii\base\ErrorException;
/**
* 币种服务类
......@@ -49,7 +47,7 @@ class CoinService
$result = array_unique($matchs[1]);
Yii::$app->cache->set($key, $result, 180);//set caching
return ['count' => count($result), 'data' => $result];
} catch (Exception $exception) {
} catch (\Exception $exception) {
return ['count' => 0, 'data' => []];
}
}
......@@ -64,6 +62,15 @@ class CoinService
*/
public static function quotation($sid = 'eos')
{
//使用缓存
$key = [
__CLASS__,
__METHOD__,
'coin',//表名
$sid,//sid
];
$result = Yii::$app->cache->get($key);
if ($result === false) {
$url = Yii::$app->params['feixiaohao_domain'] . Yii::$app->params['feixiaohao_page']['currencies'] . $sid . '/';
$ch = new Curl();
try {
......@@ -96,7 +103,8 @@ class CoinService
$result['low'] = $matchs[1][1];
//美元 btc
preg_match_all('/<div class=sub><span>(.*?)<\/span>(.*?)<span>(.*?)<\/span><\/div>/is', $content, $matchs,
preg_match_all('/<div class=sub><span>(.*?)<\/span>(.*?)<span>(.*?)<\/span><\/div>/is', $content,
$matchs,
PREG_SET_ORDER);
$result['dollar'] = $matchs[0][1];
$result['btc'] = $matchs[0][3];
......@@ -118,9 +126,12 @@ class CoinService
$result = array_map(function ($value) {
return trim($value);
}, $result);
Yii::$app->cache->set($key, $result, 60);//set cache
return $result;
} catch (Exception $exception) {
} catch (\Exception $exception) {
return false;
}
}
return $result;
}
}
\ 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