CacheStoresAdmin.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\Store;
  7. use App\Models\User;
  8. use Carbon\Carbon;
  9. use Illuminate\Console\Command;
  10. use Illuminate\Support\Facades\Cache;
  11. use Illuminate\Support\Facades\Log;
  12. use Illuminate\Support\Facades\DB;
  13. class CacheStoresAdmin extends Command
  14. {
  15. /**
  16. * The name and signature of the console command.
  17. *
  18. * @var string
  19. */
  20. protected $signature = 'cache_stores_admin';
  21. /**
  22. * The console command description.
  23. *
  24. * @var string
  25. */
  26. protected $description = '缓存政委店铺信息';
  27. /**
  28. * Create a new command instance.
  29. *
  30. * @return void
  31. */
  32. public function __construct()
  33. {
  34. parent::__construct();
  35. }
  36. /**
  37. * Execute the console command.
  38. *
  39. * @return mixed
  40. */
  41. public function handle()
  42. {
  43. Log::info('开始缓存政委店铺信息'.microtime());
  44. $admins=DwbsAdmin::where('role_id',23)->get();
  45. foreach($admins as $key=>$val){
  46. $second=mt_rand(600,1800);
  47. $warea_ids = DwbsWarea::where('admin_id', $val->id)->pluck('id');
  48. $agent_ids = DwbsUser::whereIn('warea_id', $warea_ids)->pluck('id');
  49. $store_admin= Store::whereIn('user_id', $agent_ids)->pluck('id')->toArray();
  50. Cache::put('stores_admin_'.$val->id,$store_admin,$second);
  51. }
  52. foreach([1,2,3] as $key=>$val){
  53. $second=mt_rand(600,1800);
  54. $agent_ids = Store::where('status', 0)->where('is_apply', 3)->pluck('user_id');
  55. $user_ids = DwbsUser::where('level', $val)->whereIn('id',$agent_ids)->pluck('id');
  56. $level = Store::whereIn('user_id', $user_ids)->pluck('id')->toArray();
  57. Cache::put('level-'.$val,$level,$second);
  58. }
  59. Log::info('结束缓存政委店铺信息'.microtime());
  60. }
  61. }