PostYesterday.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/6/12
  6. * Time: 16:32
  7. */
  8. namespace App\Console\Commands;
  9. use App\Models\PostData;
  10. use Illuminate\Console\Command;
  11. use Illuminate\Support\Carbon;
  12. use Illuminate\Support\Facades\DB;
  13. use Illuminate\Support\Facades\Log;
  14. use Illuminate\Support\Facades\Redis;
  15. class PostYesterday extends Command
  16. {
  17. /**
  18. * The name and signature of the console command.
  19. *
  20. * @var string
  21. */
  22. protected $signature = 'post:yesterday';
  23. /**
  24. * The console command description.
  25. *
  26. * @var string
  27. */
  28. protected $description = '昨日内容统计';
  29. /**
  30. * Create a new command instance.
  31. *
  32. * @return void
  33. */
  34. public function __construct(PostData $postData)
  35. {
  36. parent::__construct();
  37. $this->postData = $postData;
  38. }
  39. /**
  40. * Execute the console command.
  41. *
  42. * @return mixed
  43. */
  44. public function handle()
  45. {
  46. $this->line("开始统计昨日内容");
  47. $postData = $this->postData
  48. ->where('created_at', '>=', Carbon::yesterday()->startOfDay()->toDateTimeString())
  49. ->where('created_at', '<=', Carbon::yesterday()->endOfDay()->toDateTimeString())
  50. ->select(DB::raw('count(*) as count'), DB::raw('sum(create_bean) as bean'))
  51. ->first();
  52. Log::info('统计昨日内容'.json_encode($postData));
  53. Log::debug('统计昨日内容'.json_encode($postData));
  54. Redis::set('yesterday_post_count', $postData->count);
  55. Redis::set('yesterday_post_create_bean', $postData->bean);
  56. $this->line("统计昨日内容结束");
  57. }
  58. }