CacheStoresWareaInfo.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\DwbsAdmin;
  4. use App\Models\DwbsUser;
  5. use App\Models\DwbsWarea;
  6. use App\Models\OrderDetail;
  7. use App\Models\Store;
  8. use App\Models\User;
  9. use Carbon\Carbon;
  10. use Illuminate\Console\Command;
  11. use Illuminate\Support\Facades\Cache;
  12. use Illuminate\Support\Facades\Log;
  13. use Illuminate\Support\Facades\DB;
  14. class CacheStoresWareaInfo extends Command
  15. {
  16. /**
  17. * The name and signature of the console command.
  18. *
  19. * @var string
  20. */
  21. protected $signature = 'cache_stores_warea_info';
  22. /**
  23. * The console command description.
  24. *
  25. * @var string
  26. */
  27. protected $description = '缓存店铺战区信息';
  28. /**
  29. * Create a new command instance.
  30. *
  31. * @return void
  32. */
  33. public function __construct()
  34. {
  35. parent::__construct();
  36. }
  37. /**
  38. * Execute the console command.
  39. *
  40. * @return mixed
  41. */
  42. public function handle()
  43. {
  44. Log::info('开始缓存店铺战区信息'.microtime());
  45. $user_ids=Store::pluck('user_id');
  46. Cache::put('user_ids',$user_ids,mt_rand(600,1800));
  47. $store_user_ids=Store::pluck('user_id', 'id')->toArray();
  48. Cache::put('store_user_ids',$store_user_ids,mt_rand(600,1800));
  49. $wareas=DwbsWarea::pluck('name', 'id');
  50. Cache::put('wareas',$wareas,mt_rand(1800,3600),mt_rand(600,1800));
  51. $warea_user_ids=DwbsUser::withTrashed()->whereIn('id', $user_ids)->pluck('warea_id', 'id');
  52. Cache::put('warea_user_ids',$warea_user_ids,mt_rand(600,1800));
  53. $level_user=DwbsUser::whereIn('id', $user_ids)->pluck('level', 'id');
  54. Cache::put('level_user',$level_user,mt_rand(600,1800));
  55. Log::info('结束缓存店铺战区信息'.microtime());
  56. }
  57. }