xielin hace 5 años
padre
commit
855b68f97f
Se han modificado 2 ficheros con 80 adiciones y 3 borrados
  1. 71 0
      app/Console/Commands/YesterdayGreatPost.php
  2. 9 3
      app/Console/Kernel.php

+ 71 - 0
app/Console/Commands/YesterdayGreatPost.php

@@ -0,0 +1,71 @@
+<?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);
+
+    }
+}

+ 9 - 3
app/Console/Kernel.php

@@ -17,6 +17,7 @@ use App\Console\Commands\UpdateReplyCount;
 use App\Console\Commands\UpdateTopicData;
 use App\Console\Commands\UpdateTopicUseCount;
 use App\Console\Commands\VirusAdd;
+use App\Console\Commands\YesterdayGreatPost;
 use Illuminate\Console\Scheduling\Schedule;
 use Laravel\Lumen\Console\Kernel as ConsoleKernel;
 
@@ -42,18 +43,19 @@ class Kernel extends ConsoleKernel
         UpdateTopicData::class,
         TopicUseCount::class,
         CommunityMemberStatistics::class,
-        MusicImport::class
+        MusicImport::class,
+        YesterdayGreatPost::class
     ];
 
     /**
      * Define the application's command schedule.
      *
-     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
+     * @param  \Illuminate\Console\Scheduling\Schedule $schedule
      * @return void
      */
     protected function schedule(Schedule $schedule)
     {
-        $path = storage_path('logs/'.date('Y-m-d').'-schedule.log');
+        $path = storage_path('logs/' . date('Y-m-d') . '-schedule.log');
 
         $schedule->command('download:download')
             ->everyMinute()
@@ -69,6 +71,10 @@ class Kernel extends ConsoleKernel
         $schedule->command('member:statistics')
             ->dailyAt('00:05')
             ->withoutOverlapping()->appendOutputTo($path);
+        //统计前一天最佳内容
+        $schedule->command('post:yesterday-great')
+            ->dailyAt('00:30')
+            ->withoutOverlapping()->appendOutputTo($path);
         //内容生成U米
         $schedule->command('post:create_bean')
             ->everyFiveMinutes()