14days laravel
<?php namespace App\Console\Commands\Mining; use App\Console\Commands\Core\BaseCommand;
use App\Repository\Core\ScriptStatusRepo;
use App\Repository\Mining\MoversTopKRepo;
use App\Repository\Mining\MoversTopKMinersRepo; use Illuminate\Support\Facades\DB;
use App\Core\Common\Helpers\MiningHelper; /**
* Listing分析脚本
* @auth ives
* @since 20170606 0.0.1
*/
class GetTopKAsins extends BaseCommand
{
/**
* The name and signature of the console command.
* DATA_CENTER_MANAGE_SYSTEM
* @var string
*/
protected $signature = 'movers {country}'; /**
* The console command description.
*
* @var string
*/
protected $description = '获取爬虫采集的飙升榜 参数:国家码'; /**
* @var
*/
public $country; /**
* @var
*/
public $createDatas; /**
* @var ScriptStatusRepo
*/
public $statHandler; /**
* @var 暂时略过的 listid>1000 的数据,后续分析
*/
public $listidThan1000Arr = []; /**
* Create a new command instance.
*
* @return void
*/ //當前爬蟲飆升榜最大主鍵
public $moversTopKRepoMaxId; public function __construct(
MoversTopKRepo $moversTopKRepo
, MoversTopKMinersRepo $moversTopKMinersRepo
)
{
parent::__construct();
$this->moversTopKRepo = $moversTopKRepo;
$this->moversTopKMinersRepo = $moversTopKMinersRepo;
} public function handle()
{
$this->info('start 获取爬虫采集的飙升榜'); $country = $this->argument('country');
$countrys = MiningHelper::getCountrys();
if (!in_array($country, $countrys)) {
$this->error($country . ' is not country code');
exit();
}
$this->country = $country;
//任务名称
//支持多国家同时运行
$this->statHandler = new ScriptStatusRepo('GetTopKAsins_' . $country . ''); //开启任务
$endPoint = $this->start(); //TODO 需结合脚本自身和爬虫脚本执行频率修改
//从panew.amazon_keyword_* 表中取 1000 条记录 分块处理
//一次選3000
$step = 3000;
$id_range = $this->moversTopKRepoMaxId - $step;
$db_getMoversTopK = $this->moversTopKRepo->getMoversTopK($id_range);
foreach ($db_getMoversTopK as $k => $asinArr) {
$this->mainFun($asinArr);
} //结束任务
$this->finish();
} public function start()
{
//任务已存在则不执行
if (!$this->statHandler->scriptExist()) {
$this->info('任务已存在则不执行script exist..');
exit();
}
$statHandler = $this->statHandler;
$endPoint = $statHandler->getEndPoint(); $this->info('上次執行后,分析至amazon_movers_' . $this->country . '的主鍵=' . $endPoint);
$maxId = $this->moversTopKRepo->getMoversTopKMaxId();
$maxId = $maxId[0]['maxId'];
$this->moversTopKRepoMaxId = $maxId;
if ($maxId <= $endPoint) {
$this->info('當前amazon_movers_' . $this->country . '最大主鍵--maxId=' . $maxId . '無新數據待分析');
exit();
} else {
$this->info('已經校驗當前amazon_movers_' . $this->country . '最大主鍵--maxId=' . $maxId . '---開始分析---'); } //开启
$statHandler->scriptStart($endPoint);
return $endPoint; } public function finish()
{
$statHandler = $this->statHandler;
$statHandler->freshEndPoint($this->moversTopKRepoMaxId);
$statHandler->scriptEnd(2);
$this->error('更新脚本狀態表endPoint=' . $this->moversTopKRepoMaxId . ':本次完成分許,正常結束--script finished!');
} public function mainFun($asinArr)
{ foreach ($asinArr as $k => $v) {
$$k = $v;
} //sales_rank_now > 1000 pass
if ($asinArr['sales_rank_now'] > 1000) {
$this->info('sales_rank_now=' . $asinArr['sales_rank_now'] . '---排名大于1000');
return;
} $if_existed = $this->moversTopKMinersRepo->chkAsinExisted($asinArr['asin']);
if ($if_existed) {
$this->info('miner_movers_shakers_' . $this->country . '中存在asin=' . $asinArr['asin'] . ':跳过');
return;
} else {
$this->info('miner_movers_shakers_' . $this->country . '中不存在asin=' . $asinArr['asin'] . ':继续'); } $data['asin'] = $asin;
$data['img'] = $pic_url;
$data['first_inrank'] = $add_time;
$data['first_rapidly'] = $sales_rank_ago;
$data['created_at'] = date('Y-m-d H:i:s');
$data['updated_at'] = date('Y-m-d');
$data['price'] = $price;
$data['bsr1'] = $sales_rank_now;
$data['bsr1path'] = $cate_id;
$data['reviews'] = $review_counts;
// 首次
$data['status'] = 1;
$data['is_top1000'] = 1;
$data['day_span'] = 14;
$data['top_count'] = 1;
$data['is_steady'] = 0; $data['end_date'] = date("Y-m-d", strtotime("+14 Days"));
$data_add_quote = array();
foreach ($data as $k => $v) {
$data_add_quote[$k] = '`' . $v . '`';
}
// $data = $data_add_quote;
$table = 'miner_movers_shakers_' . $this->country;
try { DB::connection('mining_db')
->table($table)
->insert($data);
$this->info('对' . $table . '新增asin=' . $asin);
} catch (Exception $exception) {
$this->info('db异常停止:' . $exception);
$this->statHandler->scriptEnd(3);
} //对listing采集表collect_listing_asins以asin+country为条件添加或者更新
$table_collect_listing_asins = 'collect_listing_asins';
try {
$data = array();
$data['asin'] = $asin;
$data['country'] = $this->country; $res = DB::connection('mining_db')
->table($table_collect_listing_asins)
->select('id', 'pass_at')
->where('country', '=', $this->country)
->where('asin', '=', $asin)
->where('status', '=', 1)
->orderBy('id', 'desc')
->limit(1)
->first();
$str_info = $table_collect_listing_asins . 'asin=' . $asin . '+country=' . $this->country . '+sataus=1--';
if (empty($res)) {
$this->info('查询' . $str_info . '无数据' . ':新增');
$data['is_fresh'] = 1;
$data['status'] = 1;
$data['updated_at'] = date('Y-m-d H:i:s');
$data['pass_at'] = date("Y-m-d", strtotime("+14 Days"));
//TODO
DB::connection('mining_db')
->table($table_collect_listing_asins)
->insert($data);
} else { $id = $res->id;
$pass_at = $res->pass_at; $this->info('查询' . $str_info . '有数据' . ':检查是否更新');
$diff = strtotime($pass_at) - strtotime("+14 Days");
$data_update = array();
$data_update['pass_at'] = date("Y-m-d", strtotime("+14 Days")); if ($diff < 0) {
$this->info('----需更新');
DB::connection('mining_db')
->table($table_collect_listing_asins)
->where('id', '=', $id)
->update($data_update);
} else {
$this->info('----不需更新');
}
} } catch (Exception $exception) {
$this->info('db异常停止:' . $exception);
$this->statHandler->scriptEnd(3);
} } }
$diff = strtotime($pass_at) - strtotime("+14 Days");
$data_update = array();
$data_update['pass_at'] = date("Y-m-d", strtotime("+14 Days"));
14days laravel的更多相关文章
- TODO:Laravel增加验证码
TODO:Laravel增加验证码1. 先聊聊验证码是什么,有什么作用?验证码(CAPTCHA)是"Completely Automated Public Turing test to te ...
- TODO:Laravel 内置简单登录
TODO:Laravel 内置简单登录 1. 激活Laravel的Auth系统Laravel 利用 PHP 的新特性 trait 内置了非常完善好用的简单用户登录注册功能,适合一些不需要复杂用户权限管 ...
- TODO:Laravel 使用blade标签布局页面
TODO:Laravel 使用blade标签布局页面 本文主要介绍Laravel的标签使用,统一布局页面.主要用到到标签有@yield,@ stack,@extends,@section,@stop, ...
- TODO:搭建Laravel VueJS SemanticUI
TODO:搭建Laravel VueJS SemanticUI Laravel是一套简洁.优雅的PHP开发框架(PHP Web Framework).可以让你从面条一样杂乱的代码中解脱出来:它可以帮你 ...
- Bringing Whoops Back to Laravel 5
You might be missing the "prettier" Whoops error handler from Laravel 4. If so, here's how ...
- 在 Laravel 中使用图片处理库 Integration/Image
系统需求 PHP >= 5.3 Fileinfo Extension GD Library (>=2.0) … or … Imagick PHP extension (>=6.5.7 ...
- Laravel Composer and ServiceProvider
Composer and: 创建自定义类库时,按命名空间把文件夹结构组织好 composer.json>autoload>classmap>psr-4 composer dump-a ...
- Laravel 5.x 请求的生命周期(附源码)
Laravel最早接触是刚开始实习的时候,那时通过网上的学习资料很快便上手,开发模块接口.后来没有什么深入和总结,但是当我刚开始学Laravel的时候,我对Laravel最大的认识就是,框架除了路由. ...
- Laravel 5.3 登录注册底层实现详解
每个控制器都使用 trait 来引入它们需要的方法 */ 用于处理用户登录认证 用于处理新用户注册 包含重置密码逻辑 用于处理重置密码邮件链接 认证需要的视图 包含了应用的基础布局文件 ...
随机推荐
- idea 2017 快捷键
Ctrl+Shift + Enter,语句完成 “!”,否定完成,输入表达式时按 “!”键 Ctrl+E,最近的文件 Ctrl+Shift+E,最近更改的文件 Shift+Click,可以关闭文件 C ...
- SQL语句创建函数
----先create,再alter alter function fuc (@userid int,@strWhere varchar(max),@strWhere2 varchar(max) ) ...
- 关于Vue的理解以及与React框架的对比
1.Vue的理解 概念: Vue是一套用于构建用户界面的渐进式框架: Vue的核心库只关注视图层: 是一个数据驱动的MVVM框架: 特性: 确实轻量:体积比较小: 数据绑定简单.方便: 有一些简单的内 ...
- 20190903 On Java8 第十七章 文件
第十七章 文件 在Java7中对 文件的操作 引入了巨大的改进.这些新元素被放在 java.nio.file 包下面,过去人们通常把nio中的n理解为new即新的io,现在更应该当成是non-bloc ...
- java 历年版本特征(简化)
无论是学习任何新知识,我都是从历史的角度着手,这让我对这些新知识是如何孕育出来的,有一个很好的理解 只从java 5-8,之后我也开始转nodejs了,感谢java伴随的这几年 Java5的新特性 ...
- ListView鼠标拖
private Point Position = new Point(0, 0); private void treeFileView_ItemDrag(object sender, ItemDrag ...
- vue框架中实现今天昨天前天最近时间
点击下拉出几个选项,根据日期不同来过滤数据.看图--(忽略小梨子,这是日常练手页面) (element ui) 点击today-当天日期 点击last three days 点击custom,并且实现 ...
- 确定Git与GitHub连接起来
1.准备工作 1)下载Git 2)注册GitHub 3)将Git与GitHub链接起来 1.获取ssh密匙 2.GitHub里 找到settings 填入密匙 2.正式开始 1)确定Git与GitHu ...
- oracle学习笔记(四) DML数据控制语言和TCL 事务控制语言
DML 数据管理语言 Data manage language insert, update, delete以及select语句,不过,有人也把select单独出来,作为DQL 数据查询语言 data ...
- Dubbo源码学习总结系列三 dubbo-cluster集群模块
Dubbo集群模块的目的是将集群Invokers构造一个透明的Invoker对象,其中包含了容错机制.负载均衡.目录服务(服务地址集合).路由机制等,为RPC层提供高可用.高并发.自动发现.可治理的S ...