all(); $page_index=$info['page_index']; $page_size=$info['page_size']; $search_name=$info['search_name']; $activity_id=$info['activity_id']; $re=GiftUserImg::where('img_type',1)->where('type',0)->where('activity_id',$activity_id); if ($search_name){ $uid=User::where('mobile','like',"%$search_name%")->orwhere('nickname','like',"%$search_name%")->pluck('id'); $re->whereIn('user_id',$uid); } $auth_id=Auth::user()->role_id; if ($auth_id==23){ $id=Warea::where('admin_id',Auth::user()->id)->value('id'); $ids=User::where('warea_id',$id)->pluck('id'); $re->whereIn('user_id',$ids); } $count=$re->count(); $data=$re->with(['user'=>function($q){ $q->select('id','nickname','remark_name','headimgurl','mobile','level','warea_id')->with(['warea']); }])->orderByDesc('id')->take($page_size)->skip(($page_index-1)*$page_size)->get(); $datas=[]; foreach ($data as $k=>$v){ $remar=User::where('id',$v->user_id)->with(['agent'])->first(); if ($remar){ $v->up_name=$remar->agent->remark_name; $v->up_phone=$remar->agent->mobile; }else{ $v->up_name=''; $v->up_phone=''; } $datas[$k]=$v; } return $this->success_list($datas,'',$count); } public function GetUserList_b(Request $request){ $info=$request->all(); $page_index=$info['page_index']; $page_size=$info['page_size']; $search_name=$info['search_name']; $activity_id=$info['activity_id']; $re=GiftUserImg::where('img_type',1)->where('type',2)->where('activity_id',$activity_id); if ($search_name){ $uid=User::where('mobile','like',"%$search_name%")->orwhere('nickname','like',"%$search_name%")->pluck('id'); $re->whereIn('user_id',$uid); } $auth_id=Auth::user()->role_id; if ($auth_id==23){ $id=Warea::where('admin_id',Auth::user()->id)->value('id'); $ids=User::where('warea_id',$id)->pluck('id'); $re->whereIn('user_id',$ids); } $count=$re->count(); $data=$re->with(['user'=>function($q){ $q->select('id','nickname','remark_name','headimgurl','mobile','level','warea_id')->with(['warea']); }])->orderByDesc('id')->take($page_size)->skip(($page_index-1)*$page_size)->get(); $datas=[]; foreach ($data as $k=>$v){ $remar=User::where('id',$v->user_id)->with(['agent'])->first(); if ($remar){ $v->up_name=$remar->agent->remark_name; $v->up_phone=$remar->agent->mobile; }else{ $v->up_name=''; $v->up_phone=''; } $datas[$k]=$v; } return $this->success_list($datas,'',$count); } public function GetImgStatus(Request $request){ $activity_id=$request->activity_id; $re=GiftUserImg::where('activity_id',$activity_id)->where('type',0)->where('is_main',1)->where('img_type',0)->first(); $res=GiftUserImg::where('activity_id',$activity_id)->where('type',0)->where('is_main',0)->where('img_type',0)->first(); if (!$res || !$re){ return $this->success(['status'=>false]); } return $this->success(['status'=>true,'main_img'=>$re->url,'img'=>$res->url]); } public function GetImgStatus_b(Request $request){ $activity_id=$request->activity_id; $re=GiftUserImg::where('activity_id',$activity_id)->where('type',2)->where('is_main',1)->where('img_type',0)->first(); $res=GiftUserImg::where('activity_id',$activity_id)->where('type',2)->where('is_main',0)->where('img_type',0)->first(); if (!$res || !$re){ return $this->success(['status'=>false]); } return $this->success(['status'=>true,'main_img'=>$re->url,'img'=>$res->url]); } public function GetImgStatusB(Request $request){ $activity_id=$request->activity_id; $re=GiftUserImg::where('activity_id',$activity_id)->where('type',1)->where('is_main',1)->where('img_type',0)->first(); $res=GiftUserImg::where('activity_id',$activity_id)->where('type',1)->where('is_main',0)->where('img_type',0)->first(); if (!$res || !$re){ return $this->success(['status'=>false]); } return $this->success(['status'=>true,'main_img'=>$re->url,'img'=>$res->url]); } public function GetImgStatusB_d(Request $request){ $activity_id=$request->activity_id; $re=GiftUserImg::where('activity_id',$activity_id)->where('type',3)->where('is_main',1)->where('img_type',0)->first(); $res=GiftUserImg::where('activity_id',$activity_id)->where('type',3)->where('is_main',0)->where('img_type',0)->first(); if (!$res || !$re){ return $this->success(['status'=>false]); } return $this->success(['status'=>true,'main_img'=>$re->url,'img'=>$res->url]); } //上传图片 public function uploadImage(Request $request){ $file= $request->file('file'); $path_url='activity_img/user_img'; $upload= new UploadFilesHandler(); $result= $upload->save($file, $path_url, null, 'image'); if($result){ return $this->success($result['path']); } return $this->error(); // $path = $request->file('file')->store('/public/userImg'); // $url = Storage::url($path); // if($url){ // return $this->success($url); // } // return $this->error(); } public function AddUpdateImg(Request $request){ $auth_id=Auth::user()->role_id; if ($auth_id==23){ return $this->error(50214,'你没有权限'); } $main_img=$request->main_url; $img=$request->input('url'); $activity_id=$request->activity_id; $re=GiftUserImg::where('activity_id',$activity_id)->where('type',0)->where('is_main',1)->where('img_type',0)->first(); $res=GiftUserImg::where('activity_id',$activity_id)->where('type',0)->where('is_main',0)->where('img_type',0)->first(); if (!$re){ $re=new GiftUserImg(); $re->type=0; $re->is_main=1; $re->img_type=0; $re->url=$main_img; $re->activity_id=$activity_id; $re->save(); }else{ $re->url=$main_img; $re->save(); } if (!$res){ $res=new GiftUserImg(); $res->type=0; $res->is_main=0; $res->img_type=0; $res->url=$img; $res->activity_id=$activity_id; $res->save(); }else{ $res->url=$img; $res->save(); } return $this->success([]); } public function AddUpdateImg_b(Request $request){ $auth_id=Auth::user()->role_id; if ($auth_id==23){ return $this->error(50214,'你没有权限'); } $main_img=$request->main_url; $img=$request->input('url'); $activity_id=$request->activity_id; $re=GiftUserImg::where('activity_id',$activity_id)->where('type',2)->where('is_main',1)->where('img_type',0)->first(); $res=GiftUserImg::where('activity_id',$activity_id)->where('type',2)->where('is_main',0)->where('img_type',0)->first(); if (!$re){ $re=new GiftUserImg(); $re->type=2; $re->is_main=1; $re->img_type=0; $re->url=$main_img; $re->activity_id=$activity_id; $re->save(); }else{ $re->url=$main_img; $re->save(); } if (!$res){ $res=new GiftUserImg(); $res->type=2; $res->is_main=0; $res->img_type=0; $res->url=$img; $res->activity_id=$activity_id; $res->save(); }else{ $res->url=$img; $res->save(); } return $this->success([]); } public function AddUpdateImgB(Request $request){ $main_img=$request->main_url; $img=$request->input('url'); $activity_id=$request->activity_id; $re=GiftUserImg::where('activity_id',$activity_id)->where('type',1)->where('is_main',1)->where('img_type',0)->first(); $res=GiftUserImg::where('activity_id',$activity_id)->where('type',1)->where('is_main',0)->where('img_type',0)->first(); if (!$re){ $re=new GiftUserImg(); $re->type=1; $re->is_main=1; $re->img_type=0; $re->url=$main_img; $re->activity_id=$activity_id; $re->save(); }else{ $re->url=$main_img; $re->save(); } if (!$res){ $res=new GiftUserImg(); $res->type=1; $res->is_main=0; $res->img_type=0; $res->url=$img; $res->activity_id=$activity_id; $res->save(); }else{ $res->url=$img; $res->save(); } return $this->success([]); } public function AddUpdateImgB_d(Request $request){ $main_img=$request->main_url; $img=$request->input('url'); $activity_id=$request->activity_id; $re=GiftUserImg::where('activity_id',$activity_id)->where('type',3)->where('is_main',1)->where('img_type',0)->first(); $res=GiftUserImg::where('activity_id',$activity_id)->where('type',3)->where('is_main',0)->where('img_type',0)->first(); if (!$re){ $re=new GiftUserImg(); $re->type=3; $re->is_main=1; $re->img_type=0; $re->url=$main_img; $re->activity_id=$activity_id; $re->save(); }else{ $re->url=$main_img; $re->save(); } if (!$res){ $res=new GiftUserImg(); $res->type=3; $res->is_main=0; $res->img_type=0; $res->url=$img; $res->activity_id=$activity_id; $res->save(); }else{ $res->url=$img; $res->save(); } return $this->success([]); } public function GetUserInfo(Request $request){ $user=User::where('mobile',$request->mobile)->first(); $activity_id=$request->input('activity_id',1); $activity=Activity::find($activity_id); if (!$user){ return $this->error(500214,'系统中不存在这个手机号'); } $activity_id=Activity::where('is_ing',1)->value('id'); $users=GiftUserImg::where('user_id',$user->id)->where('type',0)->where('activity_id',$activity_id)->first(); if ($users){ return $this->error(563214,'该用户已经存在!'); } if ($user->level!=2){ return $this->error(50214,'只有销售经理能获得A礼包'); } $data['nickname']=$user->remark_name; $data['user_id']=$user->id; $data['url']=''; $data['mobile']=$request->mobile; $re=GiftUserImg::where('user_id',$user->id)->where('type',0)->where('img_type',0)->orderByDesc('id')->limit(1)->first(); if ($re){ $data['url']=$re->user_img; } $res=Ordertest::where('order_test.is_deleted',0) ->whereBetween('order_test.created_at',[$activity->start_time,$activity->end_time]) ->where('order_test.good_user_id',$user->id) ->join('address','address.id','order_test.address_id') ->select('order_num','address.*')->get(); $data['order_info']=$res; return $this->success($data); } public function GetUserInfo_b(Request $request){ $user=User::where('mobile',$request->mobile)->first(); $activity_id=$request->input('activity_id',17); $activity=Activity::find($activity_id); if (!$user){ return $this->error(500214,'系统中不存在这个手机号'); } $activity_id=Activity::where('is_ing',1)->value('id'); $users=GiftUserImg::where('user_id',$user->id)->where('type',2)->where('activity_id',$activity_id)->first(); if ($users){ return $this->error(563214,'该用户已经存在!'); } if ($user->level!=2){ return $this->error(50214,'只有销售经理能获得A礼包'); } $data['nickname']=$user->remark_name; $data['user_id']=$user->id; $data['url']=''; $data['mobile']=$request->mobile; $re=GiftUserImg::where('user_id',$user->id)->where('type',2)->where('img_type',0)->orderByDesc('id')->limit(1)->first(); if ($re){ $data['url']=$re->user_img; } $res=Ordertest::where('order_test.is_deleted',0) ->whereBetween('order_test.created_at',[$activity->start_time,$activity->end_time]) ->where('order_test.good_user_id',$user->id) ->join('address','address.id','order_test.address_id') ->select('order_num','address.*')->get(); $data['order_info']=$res; return $this->success($data); } public function GetUserInfos(Request $request){ $activity_id=$request->input('activity_id',15); $activity=Activity::find($activity_id); $user_id=$request->input('user_id'); $res=Ordertest::where('order_test.is_deleted',0) ->whereBetween('order_test.created_at',[$activity->start_time,$activity->end_time]) ->where('order_test.good_user_id',$user_id) ->join('address','address.id','order_test.address_id') ->select('order_num','address.*')->get(); $data['order_info']=$res; return $this->success($data); } public function AddUserImgInfo(Request $request){ $info=$request->all(); $user_id=$info['user_id']; $user_img=$info['user_img']; $activity_id=$info['activity_id']; $nickname=$info['nickname']; $pro=$request->input('province'); $city=$request->input('city'); $area=$request->input('area'); $address=$request->input('address'); $phone=$request->input('phone'); $name=$request->input('car_name'); if ($user_id){ $user=GiftUserImg::where('user_id',$user_id)->where('activity_id',$activity_id)->first(); if ($user){ return $this->error(563214,'该用户已经存在!'); } }else{ $users=User::where('mobile',$phone)->first(); $user_id=$users->id; $user=GiftUserImg::where('user_id',$users->id)->where('activity_id',$activity_id)->first(); if ($user){ return $this->error(563214,'该用户已经存在!'); } } $re=GiftUserImg::where('activity_id',$activity_id)->where('type',0)->where('is_main',1)->where('img_type',0)->first(); $img=GiftUserImg::where('activity_id',$activity_id)->where('type',0)->where('is_main',0)->where('img_type',0)->first(); if (!$re || !$img){ return $this->error(500214,'请先上传模板图'); } $res=new GiftUserImg(); $res->type=0; $res->user_id=$user_id; $res->activity_id=$activity_id; $res->nickname=$nickname; $res->user_img=$user_img; $res->img_type=1; $user_url=$this->CreateImg($user_id,$re->url,$user_img,$nickname,$img->url); $res->url=$user_url; $res->city=$city; $res->area=$area; $res->address=$address; $res->phone=$phone; $res->car_name=$name; $res->province=$pro; $res->save(); return $this->success([]); } /*增加大礼包A-b的信息**/ public function AddUserImgInfo_b(Request $request){ $info=$request->all(); $user_id=$info['user_id']; $user_img=$info['user_img']; $activity_id=$info['activity_id']; $nickname=$info['nickname']; $pro=$request->input('province'); $city=$request->input('city'); $area=$request->input('area'); $address=$request->input('address'); $phone=$request->input('phone'); $name=$request->input('car_name'); if ($user_id){ $user=GiftUserImg::where('user_id',$user_id)->where('activity_id',$activity_id)->first(); if ($user){ return $this->error(563214,'该用户已经存在!'); } }else{ $users=User::where('mobile',$phone)->first(); $user_id=$users->id; $user=GiftUserImg::where('user_id',$users->id)->where('activity_id',$activity_id)->first(); if ($user){ return $this->error(563214,'该用户已经存在!'); } } $re=GiftUserImg::where('activity_id',$activity_id)->where('type',2)->where('is_main',1)->where('img_type',0)->first(); $img=GiftUserImg::where('activity_id',$activity_id)->where('type',2)->where('is_main',0)->where('img_type',0)->first(); if (!$re || !$img){ return $this->error(500214,'请先上传模板图'); } $res=new GiftUserImg(); $res->type=2; $res->user_id=$user_id; $res->activity_id=$activity_id; $res->nickname=$nickname; $res->user_img=$user_img; $res->img_type=1; $user_url=$this->CreateImg($user_id,$re->url,$user_img,$nickname,$img->url); $res->url=$user_url; $res->city=$city; $res->area=$area; $res->address=$address; $res->phone=$phone; $res->car_name=$name; $res->province=$pro; $res->save(); return $this->success([]); } public function CreateImg($id,$main_url,$user_img,$nickname,$img_url){ $imageDealHandler=new ImageDealHandler(); $image=Image::make($main_url); $avatar=$imageDealHandler->circleImg($user_img); $avatar=Image::make($avatar); $avatar->resize(630,630); $img=Image::make($img_url); $image->insert($avatar,'',230,273); $image->insert($img); if (mb_strlen($nickname)==1){ $y=600; $n=1; }elseif (mb_strlen($nickname)==2){ $y=550; $n=2; }elseif (mb_strlen($nickname)==3){ $y=500; $n=3; }elseif (mb_strlen($nickname)==4){ $y=450; $n=4; }else{ $y=450; $n=0; } for ($i=0;$i<$n;$i++){ $image->text(mb_substr($nickname,$i,1), 100,$y+$i*100 , function ($font) { $font->file(public_path() . '/ziti/ht.otf'); $font->size(90); $font->color('fff'); $font->angle(0); }); } $image->encode('data-url'); $upload= new UploadFilesHandler(); $dirname= 'activity_img/create_img/'. date("Ymd"); $result= $upload->save($image, $dirname, $id, 'image'); return $result['path']; $folder_name = "uploads/UserImg/" . date("Ym/d", time()); $upload_path = 'public/'.$folder_name; // 获取文件的后缀名,因图片从剪贴板里黏贴时后缀名为空,所以此处确保后缀一直存在 $extension = 'png'; // 拼接文件名,加前缀是为了增加辨析度,前缀可以是相关数据模型的 ID // 值如:1_1493521050_7BVc9v9ujP.png $filename = $id.'_'.str_random(10) .'.'. $extension; // File::isDirectory($upload_path) or File::makeDirectory($upload_path, 077, true, true); if (!file_exists(public_path($upload_path))) { mkdir(public_path($upload_path), 0777, true); } // 将图片移动到我们的目标存储路径中 $image->save(public_path().'/'.$upload_path . '/' . $filename); $url=env('APP_URL').'/'.$upload_path.'/'.$filename; return $url; } /*更新信息**/ public function UpdateUserImgInfo(Request $request){ $id=$request->input('id'); $nickname=$request->input('nickname'); $user_id=$request->input('user_id'); $pro=$request->input('province'); $city=$request->input('city'); $area=$request->input('area'); $address=$request->input('address'); $phone=$request->input('phone'); $name=$request->input('car_name'); $user_img=$request->input('user_img'); $url=$request->input('url'); $re=GiftUserImg::find($id); $re->nickname=$nickname; $re->user_id=$user_id; $re->user_img=$user_img; $re->url=$url; $re->city=$city; $re->area=$area; $re->address=$address; $re->phone=$phone; $re->car_name=$name; $re->province=$pro; $re->save(); return $this->success([]); } /*更新信息**/ public function UpdateUserImgInfoB(Request $request){ $id=$request->input('gift_id'); $user_img=$request->input('user_img',''); $url=$request->input('url',''); if(!$id){ return $this->error(50231,'暂未生成'); }else{ $re=GiftUserImg::find($id); } $re->user_img=$user_img; $re->url=$url; $re->save(); return $this->success([]); } /*重新生成**/ public function AgainCreateImg(Request $request){ $id=$request->input('id'); $activity_id=$request->input('activity_id'); $re=GiftUserImg::find($id); $res=GiftUserImg::where('activity_id',$activity_id)->where('type',0)->where('is_main',1)->where('img_type',0)->first(); $img=GiftUserImg::where('activity_id',$activity_id)->where('type',0)->where('is_main',0)->where('img_type',0)->first(); $user_url=$this->CreateImg($re->user_id,$res->url,$re->user_img,$re->nickname,$img->url); $re->url=$user_url; $re->save(); return $this->success([]); } /*大礼包A-b的重新生成**/ public function AgainCreateImg_b(Request $request){ $id=$request->input('id'); $activity_id=$request->input('activity_id'); $re=GiftUserImg::find($id); $res=GiftUserImg::where('activity_id',$activity_id)->where('type',2)->where('is_main',1)->where('img_type',0)->first(); $img=GiftUserImg::where('activity_id',$activity_id)->where('type',2)->where('is_main',0)->where('img_type',0)->first(); $user_url=$this->CreateImg($re->user_id,$res->url,$re->user_img,$re->nickname,$img->url); $re->url=$user_url; $re->save(); return $this->success([]); } public function AgainCreateImgB(Request $request){ $id=$request->input('gift_id'); $activity_id=$request->input('activity_id'); $re=GiftUserImg::find($id); $res=GiftUserImg::where('activity_id',$activity_id)->where('type',1)->where('is_main',1)->where('img_type',0)->first(); $img=GiftUserImg::where('activity_id',$activity_id)->where('type',1)->where('is_main',0)->where('img_type',0)->first(); $user_url=$this->CreateImgB($re->user_id,$res->url,$re->user_img,$img->url); $re->url=$user_url; $re->img_type=1; $re->save(); return $this->success([]); } /*大礼包B-d 的重新生成**/ public function AgainCreateImgB_d(Request $request){ $id=$request->input('gift_id'); $activity_id=$request->input('activity_id'); $re=GiftUserImg::find($id); $res=GiftUserImg::where('activity_id',$activity_id)->where('type',3)->where('is_main',1)->where('img_type',0)->first(); $img=GiftUserImg::where('activity_id',$activity_id)->where('type',3)->where('is_main',0)->where('img_type',0)->first(); $user_url=$this->CreateImgB($re->user_id,$res->url,$re->user_img,$img->url); $re->url=$user_url; $re->img_type=1; $re->save(); return $this->success([]); } /**大礼包B的生成**/ public function CreateImgB($id,$main_url,$user_img,$imgurl){ $image=Image::make($main_url); $avatar=Image::make($user_img); $w=$avatar->getWidth(); $avatar->crop($w,900,0,0); $img=Image::make($imgurl); $image->insert($avatar,'top-left',0,0); $image->insert($img); $folder_name = "uploads/UserImgB/" . date("Ym/d", time()); $upload_path = 'public/'.$folder_name; // 获取文件的后缀名,因图片从剪贴板里黏贴时后缀名为空,所以此处确保后缀一直存在 $extension = 'png'; // 拼接文件名,加前缀是为了增加辨析度,前缀可以是相关数据模型的 ID // 值如:1_1493521050_7BVc9v9ujP.png $filename = $id.'_'.str_random(10) .'.'. $extension; // File::isDirectory($upload_path) or File::makeDirectory($upload_path, 077, true, true); if (!file_exists(public_path($upload_path))) { mkdir(public_path($upload_path), 0777, true); } // 将图片移动到我们的目标存储路径中 $image->save(public_path().'/'.$upload_path . '/' . $filename); $url=env('APP_URL').'/'.$upload_path.'/'.$filename; return $url; } public function GetUser(){ $user=User::whereIn('id',[75229,78958,82720,82758,82889,84232,86359,86535,86649,86945,88911,89432,91216,91794,93892,95488,97723])->select('nickname','mobile','level')->get(); return $this->success($user); } public function GetCrownInfo(Request $request){ $page_index=$request->input('page_index'); $page_size=$request->input('page_size'); $search_name=$request->input('search_name'); $activity_id=$request->activity_id; $re=User::whereNull('deleted_at')->where('level',3); if ($search_name){ $uid=User::where('mobile','like',"%$search_name%")->orwhere('nickname','like',"%$search_name%")->pluck('id'); $re->whereIn('id',$uid); } $auth_id=Auth::user()->role_id; if ($auth_id==23){ $id=Warea::where('admin_id',Auth::user()->id)->value('id'); $re->where('warea_id',$id); } $count=$re->count(); $data=$re->select('remark_name as nickname','mobile','headimgurl','realname','id') ->with(['GetGiftImg'=>function($q)use($activity_id){ $q->where('activity_id',$activity_id)->where('type',1)->select('user_img','user_id','id'); }]); $data=$data->take($page_size)->skip(($page_index-1)*$page_size)->get(); return $this->success_list($data,'',$count); } /*更新信息**/ public function UpdateCrownImgInfo(Request $request){ $id=$request->input('id'); $activity_id=$request->input('activity_id'); $user_img=$request->input('user_img',''); $re=GiftUserImg::where('user_id',$id)->where('activity_id',$activity_id)->first(); if (!$re){ $re=new GiftUserImg(); $re->user_id=$id; $re->activity_id=$activity_id; } $re->user_img=$user_img; $re->type=1; $re->save(); return $this->success([]); } /*删除大礼包A**/ public function DeleteUserImg(Request $request){ $id=$request->input('id'); GiftUserImg::where('id',$id)->delete(); return $this->success([]); } public function ExportAddress(Request $request){ $info=$request->all(); $search_name=$info['search_name']; $activity_id=$info['activity_id']; $re=GiftUserImg::where('img_type',1)->where('type',0)->where('activity_id',$activity_id); if ($search_name){ $uid=User::where('mobile','like',"%$search_name%")->orwhere('nickname','like',"%$search_name%")->pluck('id'); $re->whereIn('user_id',$uid); } $auth_id=Auth::user()->role_id; if ($auth_id==23){ $id=Warea::where('admin_id',Auth::user()->id)->value('id'); $ids=User::where('warea_id',$id)->pluck('id'); $re->whereIn('user_id',$ids); } $re=$re->get(); $data=[]; foreach ($re as $k=>$v){ $remar=User::where('id',$v->user_id)->with(['agent'])->first(); if ($remar){ $v->up_name=$remar->agent->remark_name; $v->up_phone=$remar->agent->mobile; }else{ $v->up_name=''; $v->up_phone=''; } $data[$k]=$v; } return $this->success_list($data); } public function ExportAddress_b(Request $request){ $info=$request->all(); $search_name=$info['search_name']; $activity_id=$info['activity_id']; $re=GiftUserImg::where('img_type',1)->where('type',2)->where('activity_id',$activity_id); if ($search_name){ $uid=User::where('mobile','like',"%$search_name%")->orwhere('nickname','like',"%$search_name%")->pluck('id'); $re->whereIn('user_id',$uid); } $auth_id=Auth::user()->role_id; if ($auth_id==23){ $id=Warea::where('admin_id',Auth::user()->id)->value('id'); $ids=User::where('warea_id',$id)->pluck('id'); $re->whereIn('user_id',$ids); } $re=$re->get(); $data=[]; foreach ($re as $k=>$v){ $remar=User::where('id',$v->user_id)->with(['agent'])->first(); if ($remar){ $v->up_name=$remar->agent->remark_name; $v->up_phone=$remar->agent->mobile; }else{ $v->up_name=''; $v->up_phone=''; } $data[$k]=$v; } return $this->success_list($data); } public function UpdateAddress(){ $activity=Activity::find(15); $data=GiftUserImg::where('activiity_id',15)->where('type',0)->whereNull('provinice')->get(); foreach ($data as $k=>$v){ $res=Ordertest::where('order_test.is_deleted',0) ->whereBetween('order_test.created_at',[$activity->start_time,$activity->end_time]) ->where('order_test.good_user_id',$v->user_id) ->join('address','address.id','order_test.address_id') ->select('order_num','address.*')->get()->toArray(); if (isset($res[0])){ $arr=$res[0]; GiftUserImg::where('id',$v->id)->update([ 'city'=>$arr['city'], 'area'=>$arr['town'], 'address'=>$arr['address'], 'phone'=>$arr['mobile'], 'car_name'=>$arr['username'], 'province'=>$arr['province'], ]); } } } /**AB大礼包的统计**/ public function BigGiftInfo(Request $request){ $type=$request->input('type'); $activity_id=$request->input('activity_id'); $arr=GiftUserImg::where('gift_user_img.type',0)->where('gift_user_img.img_type',1)->where('activity_id',$activity_id) ->join('users','users.id','=','gift_user_img.user_id') ->leftjoin('warea','warea.id','=','users.warea_id') ->groupBy('users.warea_id') ->select('warea.name',\DB::raw('count(*) as total'))->orderByDesc('total')->pluck('total','name'); $arr2=GiftUserImg::where('gift_user_img.type',2)->where('gift_user_img.img_type',1)->where('activity_id',$activity_id) ->join('users','users.id','=','gift_user_img.user_id') ->join('warea','warea.id','=','users.warea_id') ->groupBy('users.warea_id') ->select('warea.name',\DB::raw('count(*) as total'))->orderByDesc('total')->pluck('total','name'); $data=[]; foreach ($arr as $k=>$v){ $data[$k]['A']=$v; $data[$k]['B']=isset($arr2[$k])?$arr2[$k]:0; } return $this->success($data); } public function CrownBigGiftInfo(Request $request){ $activity_id=$request->input('activity_id'); $data=User::whereNull('deleted_at')->where('level',3)->get(); $re=[]; foreach ($data as $k=>$v){ $ids=User::where('agent_id',$v->id)->whereIn('cert_status',[3,6])->pluck('id')->toArray(); $idss=User::whereIn('agent_id',$ids)->whereIn('cert_status',[3,6])->pluck('id')->toArray(); $id_all=array_merge($ids,$idss); $count=count($id_all); $count1=GiftUserImg::whereIn('user_id',$id_all)->where('type',0)->where('activity_id',$activity_id)->where('img_type',1)->count(); $count2=GiftUserImg::whereIn('user_id',$id_all)->where('type',2)->where('activity_id',$activity_id)->where('img_type',1)->count(); $re[$k]['B']=$count2; $re[$k]['A']=$count1; $re[$k]['count']=$count1+$count2; $re[$k]['nickname']=$v->remark_name=null?$v->nickname:$v->remark_name; } $last_ages = array_column($re,'count'); array_multisort($last_ages ,SORT_DESC,$re); return $this->success($re); } }