PostYesterday.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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::now()->startOfDay()->toDateTimeString())
  49. ->select(DB::raw('count(*) as count'), DB::raw('sum(create_bean) as bean'))
  50. ->first();
  51. Log::info('统计昨日内容'.json_encode($postData));
  52. Log::debug('统计昨日内容'.json_encode($postData));
  53. Redis::set('yesterday_post_count', $postData->count);
  54. Redis::set('yesterday_post_create_bean', $postData->bean);
  55. $this->line("统计昨日内容结束");
  56. }
  57. }