V2boardCache.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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\Models\Server;
  7. use App\Models\ServerLog;
  8. use App\Utils\Helper;
  9. use Cache;
  10. class V2boardCache extends Command
  11. {
  12. /**
  13. * The name and signature of the console command.
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'v2board:cache';
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = '缓存任务';
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33. /**
  34. * Execute the console command.
  35. *
  36. * @return mixed
  37. */
  38. public function handle()
  39. {
  40. $this->setMonthIncome();
  41. $this->setMonthRegisterTotal();
  42. }
  43. private function setMonthIncome()
  44. {
  45. Cache::put(
  46. 'month_income',
  47. Order::where('created_at', '>=', strtotime(date('Y-m-1')))
  48. ->where('created_at', '<', time())
  49. ->where('status', '3')
  50. ->sum('total_amount')
  51. );
  52. }
  53. private function setMonthRegisterTotal()
  54. {
  55. Cache::put(
  56. 'month_register_total',
  57. User::where('created_at', '>=', strtotime(date('Y-m-1')))
  58. ->where('created_at', '<', time())
  59. ->count()
  60. );
  61. }
  62. }