<?php
|
|
namespace app\admin\command;
|
use think\console\Command;
|
use think\console\Input;
|
use think\console\Output;
|
use app\admin\model\Banner as ModelBanner;
|
use fast\Http;
|
|
/**
|
* 轮播图采集
|
*/
|
class Banner extends Command
|
{
|
protected $model = null;
|
|
protected function configure()
|
{
|
$this->setName('banner')->setDescription('采集轮播图数据');
|
}
|
|
protected function execute(Input $input, Output $output)
|
{
|
$url = "https://ljxhapi.ffquan.cn/home/conf?app_id=1";
|
$Http = new Http();
|
$result = $Http->get($url);
|
if(!empty($result)){
|
$ModelBanner = new ModelBanner();
|
$ModelBanner->where(['sourceType'=>1])->delete();
|
$result = json_decode($result, true);
|
if($result['code'] == 0 && isset($result['data']['ads']['banner_ad']) && !empty($result['data']['ads']['banner_ad'])){
|
$list = $result['data']['ads']['banner_ad'];
|
$data = [];
|
foreach($list as $item){
|
$tmp_data = [
|
'name' => $item['ad_name'],
|
'image' => $item['image_url'],
|
'type' => 1,
|
'colour' => $item['background_color'],
|
'parameter_json' => [
|
"appId" => "",
|
"route" => "",
|
"url" => "",
|
"cmark" => "version_update",
|
"activityId" => "",
|
"goodsId" => "",
|
"goods_platform" => "",
|
"template_id" => "",
|
"jtk_act_id" => ""
|
],
|
'status' => 1,
|
"sourceType" => 1,
|
'start_time' => time(),
|
'end_time' => time() + 86400 *7,
|
'create_time' => time()
|
];
|
if($item['jump']['jump_type'] == 'taobao'){
|
$tmp_data['url_type'] = 2;
|
$tmp_data['parameter_json']['activityId'] = $item['jump']['jump_value']['activity_id'];
|
}else if($item['jump']['jump_type'] == 'jd'){
|
$tmp_data['url_type'] = 7;
|
$tmp_data['parameter_json']['url'] = $item['jump']['jump_value']['activity_link'];
|
}else{
|
continue;
|
}
|
array_push($data,$tmp_data);
|
}
|
if(!empty($data)){
|
$ModelBanner->saveAll($data);
|
}
|
}
|
}
|
$output->info("采集成功");
|
}
|
|
|
}
|