=2 && $cachehas('user')->orderBy('id')->skip(($cache-1)*$num)->take($num)->get(); $wareas=DwbsWarea::pluck('name','id'); $store_user_ids=Store::orderBy('id')->skip(($cache-1)*$num)->take($num)->pluck('user_id'); $warea_user_ids=DwbsUser::withTrashed()->whereIn('id',$store_user_ids)->pluck('warea_id','id'); if(!Cache::has('gift_orders')){ $gift_orders=GiftOrders::where('type',0)->groupBy('store_id') ->select('store_id',DB::raw('sum(num*bonus) as integral'))->pluck('integral','store_id')->toArray(); Cache::add('gift_orders', $gift_orders, 60); } Cache::remember('wareas',Carbon::now()->addHours(2),function (){ return DwbsWarea::pluck('name','id'); }); foreach($store as $key=>$val){ $second=mt_rand(2880,7200); if(!Cache::has('warea-'.$val->user->id)){ $warea_id=array_key_exists($val->user_id,$warea_user_ids)?$warea_user_ids[$val->user_id]:null; Cache::put('warea-'.$val->user->id, array_key_exists($warea_id,$wareas)?$wareas[$warea_id]:null, $second); } if(!empty($val->user) && $val->user->level==2){ if(!Cache::has('company-'.$val->user->id)){ $company=DwbsUser::withTrashed()->where('id',$val->user->agent_id)->value('nickname'); Cache::add('company-'.$val->user->id, $company, $second); } } if(!empty($val->user) && $val->user->level==1){ if(!Cache::has('company-'.$val->user->id)){ $agent=DwbsUser::withTrashed()->with('agent:id,nickname')->where('id',$val->user->agent_id)->first(); if($agent->level==3){ $company=$agent->nickname; }else{ $company=$agent->agent->nickname; } Cache::put('company-'.$val->user->id, $company, $second); } } if(!empty($val->user) && $val->user->level==3){ if(!Cache::has('company-'.$val->user->id)){ $company=$val->user->nickname; Cache::add('company-'.$val->user->id, $company, $second); } } } Log::info('even结束缓存代理信息'); } }