<?php namespace App\Console\Commands; use App\Models\DwbsAdmin; use App\Models\DwbsUser; use App\Models\DwbsWarea; use App\Models\Store; use App\Models\User; use Carbon\Carbon; use Illuminate\Console\Command; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\DB; class CacheStoresAdmin extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'cache_stores_admin'; /** * The console command description. * * @var string */ protected $description = '缓存政委店铺信息'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { Log::info('开始缓存政委店铺信息'.microtime()); $admins=DwbsAdmin::where('role_id',23)->get(); foreach($admins as $key=>$val){ $second=mt_rand(600,1800); $warea_ids = DwbsWarea::where('admin_id', $val->id)->pluck('id'); $agent_ids = DwbsUser::whereIn('warea_id', $warea_ids)->pluck('id'); $store_admin= Store::whereIn('user_id', $agent_ids)->pluck('id')->toArray(); Cache::put('stores_admin_'.$val->id,$store_admin,$second); } foreach([1,2,3] as $key=>$val){ $second=mt_rand(600,1800); $agent_ids = Store::where('status', 0)->where('is_apply', 3)->pluck('user_id'); $user_ids = DwbsUser::where('level', $val)->whereIn('id',$agent_ids)->pluck('id'); $level = Store::whereIn('user_id', $user_ids)->pluck('id')->toArray(); Cache::put('level-'.$val,$level,$second); } Log::info('结束缓存政委店铺信息'.microtime()); } }