SystemCache.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\User;
  5. use App\Utils\Helper;
  6. use App\Models\Order;
  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. 'getMonthIncome',
  44. Order::where('created_at', '>', strtotime(date('Y-m-1')))
  45. ->where('created_at', '>', time())
  46. ->where('status', '3')
  47. ->where('callback_no', '!=', NULL)
  48. ->sum('total_amount')
  49. );
  50. }
  51. private function setMonthRegisterTotal() {
  52. Redis::set(
  53. 'getMonthRegisterTotal',
  54. User::where('created_at', '>', strtotime(date('Y-m-1')))
  55. ->where('created_at', '>', time())
  56. ->count()
  57. );
  58. }
  59. }