zhaojs
2023-07-31 0de015249a3abe05031eb4f5d988e8eb7ef83c87
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?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("采集成功");
        }
    }
 
    
}