Commit b64c07c7 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/optimize' into 'master'

Feature/optimize See merge request !489
parents 2f5433fd c17a2092
...@@ -2,50 +2,53 @@ ...@@ -2,50 +2,53 @@
namespace console\controllers; namespace console\controllers;
use common\models\pwallet\Article;
use Yii; use Yii;
use yii\console\Controller; use yii\console\Controller;
use common\components\Tools; use common\components\Tools;
use common\models\pwallet\Article; use linslin\yii2\curl\Curl;
use common\service\bishijie\BishijieService;
class ArticleController extends Controller class ArticleController extends Controller
{ {
public function actionIndex() public function actionIndex()
{ {
$page = 1; $coindog = Yii::$app->params['coindog'];
$size = 20; $httpParams = array(
'access_key' => $coindog['accessKey'],
$bishijie = Yii::$app->params['bishijie']; 'date' => time()
$appid = $bishijie['Appid']; );
$appSecret = $bishijie['AppSecret'];
$bishijie_service = new BishijieService($appid, $appSecret); $signParams = array_merge($httpParams, array('secret_key' => $coindog['secretKey']));
$resp = $bishijie_service->getArticleList($page, $size);
ksort($signParams);
if (!isset($resp['list'])) { $signString = http_build_query($signParams);
$httpParams['sign'] = strtolower(md5($signString));
$url = $coindog['article'] . '?' . http_build_query($httpParams);
$curl = new Curl();
$resp = $curl->get($url, false);
if (empty($resp)) {
return 0; return 0;
} }
$create_time = Article::find()->where(['platform_id' => -1])->max('create_time'); $max_create_time = Article::find()->where(['platform_id' => -1])->max('create_time');
if ($max_create_time >= strtotime($resp[0]['published_time'])) {
$list = $resp['list'];
if ($create_time >= $list[0]['issue_time']) {
return 0; return 0;
} }
$list = Tools::arraySort($list, 'issue_time', SORT_ASC); $list = Tools::arraySort($resp, 'id', SORT_ASC);
$article = new Article(); $article = new Article();
foreach ($list as &$item) { foreach ($list as &$item) {
go(function () use ($item, $article, $create_time) { go(function () use ($item, $article, $max_create_time) {
\Co::sleep(0.5); \Co::sleep(0.5);
if ($item['issue_time'] > $create_time) { if (strtotime($item['published_time']) > $max_create_time) {
$article->setIsNewRecord(true); $article->setIsNewRecord(true);
$article->title = $item['title']; $article->title = $item['title'];
$article->source = $item['source']; $article->content = $item['content'];
$article->content = $item['id']; $article->logo_pic = $item['thumbnail'];
$article->logo_pic = $item['promulgator']['logo_pic']; $article->img_url = $item['thumbnail'];
$article->img_url = $item['img_url']; $article->source = $item['resource'];
$article->platform_id = -1; $article->platform_id = -1;
$article->create_time = $item['issue_time']; $article->create_time = strtotime($item['published_time']);
$article->save() && $article->id = 0;; $article->save() && $article->id = 0;;
} }
}); });
......
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