Commit fb0edddd authored by rlgy's avatar rlgy

添加矿工费 平台改用dropdown选择

parent 0b89476d
......@@ -9,6 +9,10 @@
/**
* @var $model backend\models\coin\CoinForm;
*/
use common\models\pwallet\Coin;
$platforms = Coin::getPlatformList();
?>
<style>
.layui-form-label {
......@@ -23,7 +27,13 @@
<div class="layui-form-item">
<label class="layui-form-label">平台</label>
<div class="layui-input-block">
<input class="layui-input" name="platform" value="<?= $model->platform ?>" lay-verify="required">
<select name="platform">
<?php foreach ($platforms as $platform): ?>
<option value="<?= $platform ?>" <?php if ($model->platform == $platform) {
echo "selected";
} ?>><?= $platform ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
......@@ -51,3 +61,6 @@
</form>
</div>
</div>
<script>
layui.form.render();
</script>
\ No newline at end of file
......@@ -29,13 +29,13 @@ class CoinBusiness
public static function getList($page = 1, $limit = 10, $condition = [])
{
$rows = Coin::getList($page, $limit, $condition);
if ($rows['count'] > 0) {
$datas = $rows['data'];
foreach ($datas as $key => $value) {
//获取交易所信息
$rows['data'][$key]['exchange'] = CoinService::exchange($value['sid']);
}
}
// if ($rows['count'] > 0) {
// $datas = $rows['data'];
// foreach ($datas as $key => $value) {
// //获取交易所信息
// $rows['data'][$key]['exchange'] = CoinService::exchange($value['sid']);
// }
// }
return $rows;
}
......
......@@ -34,7 +34,7 @@ class CoinService
$name,//sid
];
$result = Yii::$app->cache->get($key);
if ($result === false) {
if ($result === false || YII_ENV_DEV) {
$url = Yii::$app->params['feixiaohao_domain'] . Yii::$app->params['feixiaohao_page']['coinmarket'] . $name . '/';
$ch = new Curl();
try {
......@@ -42,9 +42,28 @@ class CoinService
preg_match_all("/<div class=boxContain><table class=table3 id=markets>(.*)?<\/table>/is", $content,
$matchs);
$content = $matchs[1][0];
preg_match_all('/alt=(.*?)>/is', $content, $matchs);
preg_match_all('/<a href="(.*?)"(.*?)alt=(.*?)>/is', $content, $matchs);
//匹配到了
$result = array_unique($matchs[1]);
//保存匹配数据
$count = count($matchs[1]);
$result = [];
$r = [];
for ($i = 0; $i < $count; $i++) {
if (!in_array($matchs[3][$i], $r)) {
$r[] = $matchs[3][$i];
//爬取正确的官网
if (strpos($matchs[1][$i], '/exchange') === false) {
$matchs[1][$i] .= 'https:';
} else {
$url = 'https://www.feixiaohao.com' . $matchs[1][$i];
$content = $ch->get($url, true);
preg_match_all('/官网地址:<a(.*?)>(.*?)<\/a><\/span>/', $content, $matchs2);
$matchs[1][$i] = $matchs2[2][0];
}
$result[] = ['url' => $matchs[1][$i], 'name' => $matchs[3][$i]];
}
}
unset($content, $i, $r, $url, $matchs2);
Yii::$app->cache->set($key, $result, 180);//set caching
return ['count' => count($result), 'data' => $result];
} catch (\Exception $exception) {
......@@ -55,6 +74,15 @@ class CoinService
}
/**
* 爬取交易所数量
* @param string $sid
* @return integer|bool
*/
public static function exchange_count($sid = 'eos')
{
}
/**
* 爬取币种的实时行情,默认eos
*
* @param string $sid
......
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