1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/6/12
- * Time: 16:32
- */
- namespace App\Console\Commands;
- use App\Models\PostData;
- use Illuminate\Console\Command;
- use Illuminate\Support\Carbon;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Redis;
- class YesterdayGreatPost extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'post:yesterday-great';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '昨日最佳内容';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct(PostData $postData)
- {
- parent::__construct();
- $this->postData = $postData;
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $this->line(date('Y-m-d H:i:s')."开始统计昨日最佳内容");
- $postData = $this->postData
- ->where('created_at', '>=', Carbon::yesterday()->startOfDay()->toDateTimeString())
- ->where('created_at', '<=', Carbon::yesterday()->endOfDay()->toDateTimeString())
- ->get()->toArray();
- $postId = 0;
- $postScore = 0;
- foreach ($postData as $post) {
- $score = $post->pv + $post->collect_count + $post->share_count + $post->comment_count;
- if($score>$postScore){
- $postId = $post->post_id;
- }
- }
- Redis::set('yesterday_great_post', $postId);
- $this->line(date('Y-m-d H:i:s')."统计昨日最佳内容结束".$postId);
- }
- }
|