MapCommand.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Console\Commands\Cache;
  3. use App\Models\User\UserModel;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Facades\Redis;
  6. class MapCommand extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'cache:map';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '地图数据缓存';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. $data = [
  37. 'province_count' => '34',
  38. 'city_count' => '301',
  39. 'school_count' => '1845'
  40. ];
  41. $data['card_count'] = UserModel::where('sex', 0)->count();
  42. $data['men_count'] = UserModel::where('sex', 1)->count();
  43. $data['women_count'] = UserModel::where('sex', 2)->count();
  44. Redis::set('map', json_encode($data));
  45. }
  46. }