|
@@ -0,0 +1,68 @@
|
|
|
+<?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 PostYesterday extends Command
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * The name and signature of the console command.
|
|
|
+ *
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $signature = 'post:yesterday';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 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("开始统计昨日内容");
|
|
|
+
|
|
|
+ $postData = $this->postData
|
|
|
+ ->where('created_at', '>=', Carbon::now()->startOfDay()->toDateTimeString())
|
|
|
+ ->select(DB::raw('count(*) as count'), DB::raw('sum(create_bean) as bean'))
|
|
|
+ ->first();
|
|
|
+ Log::info('统计昨日内容'.json_encode($postData));
|
|
|
+ Log::debug('统计昨日内容'.json_encode($postData));
|
|
|
+
|
|
|
+ Redis::set('yesterday_post_count', $postData->count);
|
|
|
+ Redis::set('yesterday_post_create_bean', $postData->bean);
|
|
|
+
|
|
|
+ $this->line("统计昨日内容结束");
|
|
|
+
|
|
|
+ }
|
|
|
+}
|