<?php
|
|
namespace app\admin\command;
|
use think\console\Command;
|
use think\console\Input;
|
use think\console\Output;
|
use app\api\logic\taoke\device\Haodanku as LogicHaodanku;
|
use app\common\model\TalentInfo as ModelTalentInfo;
|
|
/**
|
* 达人说数据采集
|
*/
|
class TalentInfo extends Command
|
{
|
protected $model = null;
|
|
protected function configure()
|
{
|
$this->setName('talentinfo')->setDescription('采集达人说数据');
|
}
|
|
protected function execute(Input $input, Output $output)
|
{
|
$LogicHaodanku = new LogicHaodanku();
|
$ModelTalentInfo = new ModelTalentInfo();
|
$res = $LogicHaodanku->getTalentInfo(0);
|
if(!empty($res)){
|
$clickdata = $res['clickdata'];
|
if(empty($clickdata)) return false;
|
$topIds = empty($res['topdata']) ? [] : array_column($res['topdata'],'id');
|
$newIds = empty($res['newdata']) ? [] : array_column($res['newdata'],'id');
|
$save_data = [];
|
foreach($clickdata as $key => $item){
|
$t_class = 3;
|
if(!empty($topIds) && in_array($item['id'],$topIds)) $t_class = 1;
|
if(!empty($newIds) && in_array($item['id'],$newIds)) $t_class = 2;
|
$save_data[] = [
|
'tid' => $item['id'],
|
'name' => $item['name'],
|
'short_title' => $item['shorttitle'],
|
'image' => $item['image'],
|
't_class' => $t_class,
|
'app_image' => $item['app_image'],
|
'article' => $item['article'],
|
'label' => $item['label'],
|
'tk_item_id' => $item['tk_item_id'],
|
'article_banner' => $item['article_banner'],
|
'high_quality' => $item['highquality'],
|
'read_times' => $item['readtimes'],
|
'talent_name' => $item['talent_name'],
|
'head_img' => isset($item['head_img']) ? $item['head_img'] : '',
|
'talentcat' => $item['talentcat'],
|
'item_num' =>isset($item['itemnum']) ? $item['itemnum'] : '',
|
'type' => 0,
|
'follow_times' => isset($item['followtimes']) ? $item['followtimes'] : '',
|
'addtime' => time(),
|
'create_time' => time()
|
];
|
}
|
if(empty($save_data))return false;
|
$ModelTalentInfo->where(['id'=>['>',0]])->delete();//清空表
|
$ModelTalentInfo->saveAll($save_data); //插入新数据
|
$output->info("采集成功");
|
}
|
}
|
|
|
}
|