SystemCache.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\User;
  5. use App\Models\Order;
  6. use App\Utils\Helper;
  7. use Illuminate\Support\Facades\Redis;
  8. class SystemCache extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'system:cache';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = '系统缓存任务';
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. $this->setMonthIncome();
  39. $this->setMonthRegisterTotal();
  40. }
  41. private function setMonthIncome() {
  42. Redis::set(
  43. 'month_income',
  44. Order::where('created_at', '>=', strtotime(date('Y-m-1')))
  45. ->where('created_at', '<', time())
  46. ->where('status', '3')
  47. ->sum('total_amount')
  48. );
  49. }
  50. private function setMonthRegisterTotal() {
  51. Redis::set(
  52. 'month_register_total',
  53. User::where('created_at', '>=', strtotime(date('Y-m-1')))
  54. ->where('created_at', '<', time())
  55. ->count()
  56. );
  57. }
  58. }