Commit 9d735913 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/log-operation' into develop

parents dcf72a7d 737186b3
......@@ -10,7 +10,7 @@ namespace api\controllers;
use Yii;
use api\base\BaseController;
use common\models\pwallet\Article;
use common\models\pwallet\News;
class ArticleController extends BaseController
{
......@@ -50,7 +50,7 @@ class ArticleController extends BaseController
if (isset($post['update_at'])) {
$condition[] = ['>=', 'update_at', $post['update_at']];
}
$data = Article::getList($page, $limit, $condition);
$data = News::getList($page, $limit, $condition);
return $data;
}
......
......@@ -3,7 +3,7 @@
namespace api\controllers;
use backend\models\coin\ArticleForm;
use common\models\pwallet\Article;
use common\models\pwallet\News;
use common\service\bishijie\BishijieService;
use linslin\yii2\curl\Curl;
use Yii;
......@@ -127,7 +127,7 @@ class CoinDogController extends BaseController
public function actionArticleBanner()
{
$type = Yii::$app->request->get('type', 1);
$data = Article::find()
$data = News::find()
->select('id, image_url ,title, url')
->where(['type' => $type])
->orderBy('update_at desc')
......
......@@ -28,7 +28,7 @@ class TickerController extends BaseController
$data_value = Yii::$app->request->get('data_value', '');
$sort_value = Yii::$app->request->get('sort_value', '');
$exchange_arr = ['huobi', 'binance', 'zhaobi', 'bitnasdaq'];
$exchange_arr = ['huobi', 'binance', 'zhaobi', 'bitnasdaq', 'jingwang'];
if (!in_array($exchange, $exchange_arr)) {
$msg = '不存在的交易平台';
......@@ -43,6 +43,9 @@ class TickerController extends BaseController
'sort_value' => $sort_value
];
}
if ('jingwang' == $exchange) {
$exchange = 'jinwang';
}
$builder = ExchangeBuilderFactory::create($exchange);
$result = $builder->getTickerFromCache($page, $condition);
$code = $result['code'];
......
......@@ -11,7 +11,7 @@ namespace backend\controllers;
use backend\models\coin\ArticleForm;
use backend\models\coin\NoticeForm;
use Yii;
use common\models\pwallet\Article;
use common\models\pwallet\News;
use common\models\pwallet\Notice;
use common\models\pwallet\Feedback;
use yii\db\Exception;
......@@ -37,7 +37,7 @@ class SourceController extends BaseController
if ($status != 'all') {
$condition[] = ['status' => $status];
}
$results = Article::getList($page, $limit, $condition);
$results = News::getList($page, $limit, $condition);
Yii::$app->response->format = 'json';
Yii::$app->response->data = $results;
Yii::$app->response->send();
......@@ -56,7 +56,7 @@ class SourceController extends BaseController
if (Yii::$app->request->isPost) {
$request = Yii::$app->request;
if ($model->load($request->post()) && $model->validate()) {
$article = new Article();
$article = new News();
$res = $article->addOne($request->post());
if ($res === true) {
$this->success('添加成功', '/admin/source/article');
......@@ -85,7 +85,7 @@ class SourceController extends BaseController
$model->scenario = 'edit';
$id = Yii::$app->request->get('id', null);
if ($id) {
$article = Article::findOne(['id' => $id]);
$article = News::findOne(['id' => $id]);
if ($article) {
if (Yii::$app->request->isPost) {
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
......@@ -118,7 +118,7 @@ class SourceController extends BaseController
{
$id = Yii::$app->request->get('id', null);
if ($id) {
$article = Article::findOne(['id' => $id]);
$article = News::findOne(['id' => $id]);
if ($article) {
try {
$article->delete();
......
......@@ -25,31 +25,42 @@ class OperationLogInterceptor extends ActionFilter
// if (!isset(Yii::$app->params['handleTableAndDesc']['handleTableAndDesc'][$handerClass][$handlerAction][$method])) {
// return false;
// }
if ('asset' == $handerClass) {
$uri = Yii::$app->request->post('uri', '');
if (isset(Yii::$app->params['handleTableAndDesc']['handleTableAndDesc'][$handerClass][$handlerAction][$uri])) {
$params = [
'ip' => Yii::$app->request->userIP,
'operation' => '操作',
'business' => Yii::$app->params['handleTableAndDesc']['handleTableAndDesc'][$handerClass][$handlerAction][$uri] ?? $handerClass . '-' . $handlerAction,
'table' => 'asset'
];
}
} else {
switch ($method) {
case "get":
$operation = '查询';
break;
case 'post':
$operation = '增加';
break;
case 'put':
$operation = '更新';
break;
case 'delete':
$operation = '删除';
break;
default:
$operation = '未知';
}
switch ($method) {
case "get":
$operation = '查询';
break;
case 'post':
$operation = '增加';
break;
case 'put':
$operation = '更新';
break;
case 'delete':
$operation = '删除';
break;
default:
$operation = '未知';
$params = [
'ip' => Yii::$app->request->userIP,
'operation' => $operation,
'business' => Yii::$app->params['handleTableAndDesc']['handleTableAndDesc'][$handerClass][$handlerAction][$method] ?? $handerClass . '-' . $handlerAction,
'table' => Yii::$app->params['handleTableAndDesc']['handleTableAndDesc'][$handerClass][$handlerAction]['table'] ?? '未知'
];
}
$params = [
'ip' => Yii::$app->request->userIP,
'operation' => $operation,
'business' => Yii::$app->params['handleTableAndDesc']['handleTableAndDesc'][$handerClass][$handlerAction][$method] ?? $handerClass . '-' . $handlerAction,
'table' => Yii::$app->params['handleTableAndDesc']['handleTableAndDesc'][$handerClass][$handlerAction]['table'] ?? '未知'
];
$token_string = Yii::$app->request->headers->get('Token');
$curl = new Curl();
......
......@@ -46,7 +46,7 @@ class ExchangeBusiness
17 => 'Coinka',
18 => 'Isummit',
19 => 'Boc',
20 => 'Jinwang'
//1 => 'Hadax', //不需要
//2 => 'Bitfinex', //不需要
......@@ -127,10 +127,10 @@ class ExchangeBusiness
if (strtoupper($tag) == 'POKE') {
$quotation = [
'low' => 0.15,
'high' => 0.15,
'last' => 0.15,
'rmb' => 0.15,
'low' => 0.1587,
'high' => 0.1587,
'last' => 0.1587,
'rmb' => 0.1587,
];
goto doEnd;
}
......
......@@ -87,7 +87,7 @@ class Article extends BaseActiveRecord
unset($params['id']);
} else {
$article = $this;
$params = array_merge($params, ['create_at' => date('Y-m-d H:i:s')]);
$params = array_merge($params, ['create_at' => date('Y-m-d H:i:s')]);
}
$params = array_merge($params, ['update_at' => date('Y-m-d H:i:s', time())]);
if (!isset($params['status'])) {
......
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-4
* Time: 上午9:53
*/
namespace common\models\pwallet;
use common\base\Exception;
use common\core\BaseActiveRecord;
use Yii;
class News extends BaseActiveRecord
{
public static function getDb()
{
return Yii::$app->get('db_pwallet');
}
public static function tableName()
{
return '{{%news}}';
}
/**
* 获取文章列表
* @param int $page
* @param int $limit
* @param array $condition
* @return array
*/
public static function getList($page = 1, $limit = 10, $condition = [])
{
$query = self::find();
foreach ($condition as $item) {
$query = $query->andWhere($item);
}
$count = $query->count();
if ($count) {
$data = $query->offset(($page - 1) * $limit)->limit($limit)->asArray()->all();
return ['code' => 0, 'count' => $count, 'data' => $data];
}
return ['code' => 1, 'msg' => '数据为空'];
}
/**
* 添加文章
* @param $params
* @return bool|array
*/
public function addOne($params)
{
return $this->realWrite($params);
}
/**
* 更新文章
* @param $params
* @return bool|array
*/
public function updateOne($params)
{
return $this->realWrite($params);
}
/**
* 实际操作数据方法
*/
private function realWrite($params)
{
if (!is_array($params)) {
$params = [$params];
}
$params = array_filter($params, function ($value, $key) {
if (ctype_digit($key) || empty($value)) {
return false;
}
return true;
}, ARRAY_FILTER_USE_BOTH);
if (isset($params['id'])) {
$article = self::findOne($params['id']);
if ($article === null) {
return ['code' => 1, 'msg' => '文章不存在'];
}
unset($params['id']);
} else {
$article = $this;
$params = array_merge($params, ['create_at' => date('Y-m-d H:i:s')]);
}
$params = array_merge($params, ['update_at' => date('Y-m-d H:i:s', time())]);
if (!isset($params['status'])) {
$params['status'] = 0;
}
$article->setAttributes($params, false);
try {
return (bool)$article->save();
} catch (Exception $exception) {
return ['code' => $exception->getCode(), 'msg' => $exception->getMessage()];
}
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-8-7
* Time: 上午11:30
*/
namespace common\service\exchange;
use linslin\yii2\curl\Curl;
class Jinwang extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_jinwang';
protected $quotation_prefix = 'quotation_jinwang_';
protected $base_url = 'http://www.jinwangin.com/exapi/api/klinevtwo/message';
public function symbolExists($tag = 'TG', $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 = 'TG', $aim = 'USDT')
{
return strtoupper($tag . $aim);
}
/**
* 保存支持的交易对到redis数据库,使用crontab定时更新
*
* @return mixed|void
*/
public function setSupportedSymbol()
{
}
/**
* 更新交易对行情保存到redis,使用crontab定时更新
*
* @return mixed|void
*/
public function setQuotation()
{
$curl = new Curl();
$resp = $curl->get($this->base_url, false);
if (is_array($resp)) {
if (isset($resp['marketDetail'])) {
foreach ($resp['marketDetail'] as $symbol => $item) {
$key = $this->quotation_prefix . strtolower($symbol);
$this->redis->hmset($key, 'low', $item[0]["payload"]['priceLow'], 'high', $item[0]["payload"]['priceHigh'], 'last', $item[0]["payload"]['priceLast'], 'open', $item[0]["payload"]['priceOpen'], 'vol', $item[0]["payload"]['totalAmount']);
if (!$this->redis->sismember($this->supported_symbol, strtoupper($symbol))) {
$this->redis->sadd($this->supported_symbol, strtoupper($symbol));
}
}
}
}
}
}
\ No newline at end of file
<?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 JinwangBuilder extends FactoryService
{
protected $base_url = 'http://www.jinwangin.com';
protected $supported_symbol = 'supported_symbol_jinwang';
protected $supported_symbol_list = 'supported_symbol_jinwang_list';
protected $supported_symbol_close_asc = 'supported_symbol_close_asc_jinwang';
protected $supported_symbol_close_desc = 'supported_symbol_close_desc_jinwang';
protected $supported_symbol_change_asc = 'supported_symbol_change_asc_jinwang';
protected $supported_symbol_change_desc = 'supported_symbol_change_desc_jinwang';
protected $quotation_prefix = 'quotation_jinwang_';
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), ['LTC_USDT', 'BTC_USDT', 'EOS_USDT', 'TG_USDT', 'TPC_USDT', 'ETH_USDT'])) {
$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['currency'] = strtoupper(str_replace('_', '', $explode_arr[0]));
$temp['symbol'] = $temp['currency'] . '/' . $coin;
$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'] = 'Diamond coin';
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']));
}
}
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 . 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;
}
return ['code' => $this->code, 'ticker' => $ticker];
}
}
......@@ -4,61 +4,48 @@ namespace console\controllers;
use Yii;
use yii\console\Controller;
use linslin\yii2\curl\Curl;
use common\components\Tools;
use common\models\pwallet\Article;
use common\service\bishijie\BishijieService;
class ArticleController extends Controller
{
public function actionIndex()
{
$coindog = Yii::$app->params['coindog'];
$page = 1;
$size = 20;
$accessKey = $coindog['accessKey'];
$secretKey = $coindog['secretKey'];
$httpParams = array(
'access_key' => $accessKey,
'date' => time()
);
$bishijie = Yii::$app->params['bishijie'];
$appid = $bishijie['Appid'];
$appSecret = $bishijie['AppSecret'];
$bishijie_service = new BishijieService($appid, $appSecret);
$resp = $bishijie_service->getArticleList($page, $size);
$signParams = array_merge($httpParams, array('secret_key' => $secretKey));
ksort($signParams);
$signString = http_build_query($signParams);
$httpParams = [
'sign' => strtolower(md5($signString)),
];
$url = $coindog['live'] . '?' . http_build_query($httpParams);
$curl = new Curl();
$resp = $curl->get($url, false);
if (!isset($resp['list'])) {
return 0;
}
$create_time = Article::find()->where(['platform_id' => -1])->max('create_time');
$list = $resp['list'][0]['lives'];
if ($create_time >= $list[0]['created_at']) {
$list = $resp['list'];
if ($create_time >= $list[0]['issue_time']) {
return 0;
}
$list = Tools::arraySort($list, 'created_at', SORT_ASC);
$list = Tools::arraySort($list, 'issue_time', SORT_ASC);
$article = new Article();
foreach ($list as &$item) {
go(function () use ($item, $article, $create_time) {
\Co::sleep(0.5);
if ($item['created_at'] > $create_time) {
preg_match_all("/\【(.+?)\】/", $item['content'], $match);
$title = $match[1][0];
$content = str_replace('【' . $title . '】', '', $item['content']);
if ($item['issue_time'] > $create_time) {
$article->setIsNewRecord(true);
$article->title = $title;
$article->content = $content;
$article->title = $item['title'];
$article->source = $item['source'];
$article->content = $item['id'];
$article->logo_pic = $item['promulgator']['logo_pic'];
$article->img_url = $item['img_url'];
$article->platform_id = -1;
$article->create_time = $item['created_at'];
$article->create_time = $item['issue_time'];
$article->save() && $article->id = 0;;
}
});
......
<?php
namespace console\controllers;
use Yii;
use yii\console\Controller;
use linslin\yii2\curl\Curl;
use common\components\Tools;
use common\models\pwallet\News;
class NewsController extends Controller
{
public function actionIndex()
{
$coindog = Yii::$app->params['coindog'];
$accessKey = $coindog['accessKey'];
$secretKey = $coindog['secretKey'];
$httpParams = array(
'access_key' => $accessKey,
'date' => time()
);
$signParams = array_merge($httpParams, array('secret_key' => $secretKey));
ksort($signParams);
$signString = http_build_query($signParams);
$httpParams = [
'sign' => strtolower(md5($signString)),
];
$url = $coindog['live'] . '?' . http_build_query($httpParams);
$curl = new Curl();
$resp = $curl->get($url, false);
if (!isset($resp['list'])) {
return 0;
}
$create_time = News::find()->where(['platform_id' => -1])->max('create_time');
$list = $resp['list'][0]['lives'];
if ($create_time >= $list[0]['created_at']) {
return 0;
}
$list = Tools::arraySort($list, 'created_at', SORT_ASC);
$article = new News();
foreach ($list as &$item) {
go(function () use ($item, $article, $create_time) {
\Co::sleep(0.5);
if ($item['created_at'] > $create_time) {
preg_match_all("/\【(.+?)\】/", $item['content'], $match);
$title = $match[1][0];
$content = str_replace('【' . $title . '】', '', $item['content']);
$article->setIsNewRecord(true);
$article->title = $title;
$article->content = $content;
$article->platform_id = -1;
$article->create_time = $item['created_at'];
$article->save() && $article->id = 0;;
}
});
}
return 0;
}
}
......@@ -14,7 +14,7 @@ class TickerController extends Controller
{
public function actionSort()
{
$class = ['Binance', 'Huobi', 'Zhaobi', 'Bitnasdaq'];
$class = ['Binance', 'Huobi', 'Zhaobi', 'Bitnasdaq', 'Jinwang'];
foreach ($class as $val) {
go(function () use ($val) {
\Co::sleep(0.5);
......
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