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); $re->where('op_name',Auth::user()->name); } $count=$re->count(); $data=$re->with(['user'=>function($q){ $q->select('id','nickname','remark_name','mobile','level','warea_id')->with(['warea']); }])->orderByDesc('id')->take($page_size)->skip(($page_index-1)*$page_size)->get(); $datas=[]; foreach ($data as $k=>$v){ $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){ $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,'img_info'=>$re->img_info]); } 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,'img_info'=>$re->img_info]); } public function GetImgStatusB_e(Request $request){ $activity_id=$request->activity_id; $re=GiftUserImg::where('activity_id',$activity_id)->where('type',4)->where('is_main',1)->where('img_type',0)->first(); $res=GiftUserImg::where('activity_id',$activity_id)->where('type',4)->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,'img_info'=>$re->img_info]); } //上传图片 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(); $img_info=[ 'height'=>$request->input('height'), 'color'=>$request->input('color'), 'size'=>$request->input('size'), 'left_len'=>$request->input('left_len'), ]; if (!$re){ $re=new GiftUserImg(); $re->type=1; $re->is_main=1; $re->img_type=0; $re->url=$main_img; $re->img_info=json_encode($img_info); $re->activity_id=$activity_id; $re->save(); }else{ $re->url=$main_img; $re->img_info=json_encode($img_info); $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(); $img_info=[ 'height'=>$request->input('height'), 'color'=>$request->input('color'), 'size'=>$request->input('size'), 'left_len'=>$request->input('left_len'), ]; if (!$re){ $re=new GiftUserImg(); $re->type=3; $re->is_main=1; $re->img_type=0; $re->url=$main_img; $re->img_info=json_encode($img_info); $re->activity_id=$activity_id; $re->save(); }else{ $re->url=$main_img; $re->img_info=json_encode($img_info); $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 AddUpdateImgB_e(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',4)->where('is_main',1)->where('img_type',0)->first(); $res=GiftUserImg::where('activity_id',$activity_id)->where('type',4)->where('is_main',0)->where('img_type',0)->first(); $img_info=[ 'height'=>$request->input('height'), 'color'=>$request->input('color'), 'size'=>$request->input('size'), 'left_len'=>$request->input('left_len'), ]; if (!$re){ $re=new GiftUserImg(); $re->type=4; $re->is_main=1; $re->img_type=0; $re->url=$main_img; $re->img_info=json_encode($img_info); $re->activity_id=$activity_id; $re->save(); }else{ $re->url=$main_img; $re->img_info=json_encode($img_info); $re->save(); } if (!$res){ $res=new GiftUserImg(); $res->type=4; $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){ $order_num=$request->input('mobile'); $activity_id=$request->input('activity_id',6); $activity_id=Activity::where('is_ing',1)->value('id'); $activity=Activity::find($activity_id); // $order=Order::where('order_num',$order_num)->first(); // if (!$order){ // return $this->error(500214,'不存在该订单,请核实'); // } // if ($order->is_deleted==1){ // return $this->error(500214,'该订单已删除,请核实'); // } // $re=GiftUserImg::where('o_id',$order->id)->where('type',0)->where('activity_id',$activity_id)->first(); // if ($re){ // return $this->error(500214,'该订单已经登记,请核实'); // } // $user=User::find($order->good_user_id); // $user=User::where('mobile',$request->input('mobile'))->first(); // if (!$user){ // return $this->error(500214,'不存在该用户,请核实'); // } if (!is_numeric(mb_substr($order_num,0,1))){ $order=Order::where('order_num',$order_num)->first(); if (!$order){ return $this->error(500214,'不存在该订单,请核实'); } $user=User::where('id',$order->good_user_id)->first(); $data['nickname']=$user->remark_name; $data['user_id']=$user->id; $data['url']=''; $data['mobile']=''; // $data['mobile']=$request->mobile; $res=Order::where('order.is_deleted',0) ->whereBetween('order.created_at',[$activity->start_time,$activity->end_time]) ->where('order.order_num',$order_num) // ->where('order.good_user_id',$user->id) ->join('address','address.id','order.address_id') ->select('order_num','order.id as ids','address.*')->get(); }else{ $user=User::where('mobile',$request->input('mobile'))->first(); if (!$user){ return $this->error(500214,'不存在该用户,请核实'); } $data['nickname']=$user->remark_name; $data['user_id']=$user->id; $data['url']=''; // $data['mobile']=''; $data['mobile']=$request->mobile; $res=Order::where('order.is_deleted',0) ->whereBetween('order.created_at',[$activity->start_time,$activity->end_time]) // ->where('order.order_num',$order_num) ->where('order.good_user_id',$user->id) ->join('address','address.id','order.address_id') ->select('order_num','order.id as ids','address.*')->get(); } // $res=Order::where('order.is_deleted',0) // ->whereBetween('order.created_at',[$activity->start_time,$activity->end_time]) // ->where('order.id',$order->id) // ->join('address','address.id','order.address_id') //// ->with(['get_order_detail:order_id,goods_unit,num']) // ->select('order_num','order.id as ids','address.*')->get(); Log::error($res); $add=[]; foreach ($res as $k=>$v){ $mon=0; $get_order_detail=OrderDetail::where('order_id',$v->ids)->get(); foreach ($get_order_detail as $ke=>$va){ if ($va->goods_unit=='盒'){ $mon+=$va->num*219; }else{ $mon+=$va->num*119*4; } } if ($mon>=10000){ $add[]=$v; // return $this->error(50014,'金额不满足1W',$v); } // $res[$k]->mobile=Crypt::decryptString($v->mobile_code); // $res[$k]->address=Crypt::decryptString($v->address_code); } if (count($add)==0){ return $this->error(50014,'金额不满足1W'); } $data['order_info']=$res; return $this->success($data); } public function GetUserInfo_b(Request $request){ // $user=User::where('mobile',$request->mobile)->first(); $mobiles=mb_substr($request->mobile,0,3).'****'.mb_substr($request->mobile,'-4'); $users=User::where('mobile',$mobiles)->get(); $user=[]; foreach ($users as $k=>$v){ try { $m=Crypt::decryptString($v->uuid); if ($m==$request->mobile){ $user=User::find($v->id); } }catch (\Exception $exception){ } } $activity_id=$request->input('activity_id',6); $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=Order::where('order.is_deleted',0) // ->whereBetween('order.created_at',[$activity->start_time,$activity->end_time]) // ->where('order.good_user_id',$user->id) // ->join('address','address.id','order.address_id') // ->select('order_num','address.*')->get(); $res=Order::where('order.is_deleted',0) ->whereBetween('order.created_at',[$activity->start_time,$activity->end_time]) ->where('order.good_user_id',$user->id) ->join('address','address.id','order.address_id') // ->with(['get_order_detail:order_id,goods_unit,num']) ->select('order_num','order.id as ids','address.*')->get(); Log::error($res); foreach ($res as $k=>$v){ $mon=0; $get_order_detail=OrderDetail::where('order_id',$v->ids)->get(); foreach ($get_order_detail as $ke=>$va){ if ($va->goods_unit=='套'){ $mon+=$va->num*219; }else{ $mon+=$va->num*119*4; } } if ($mon<20000){ return $this->error(50014,'金额不满足2W',$res); } $res[$k]->mobile=Crypt::decryptString($v->mobile_code); $res[$k]->address=Crypt::decryptString($v->address_code); } $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=Order::where('order.is_deleted',0) ->whereBetween('order.created_at',[$activity->start_time,$activity->end_time]) ->where('order.good_user_id',$user_id) ->join('address','address.id','order.address_id') ->with(['get_order_detail:order_id,goods_unit,num']) ->select('order_num','address.*')->get(); // foreach ($res as $k=>$v){ // $res[$k]->mobile=Crypt::decryptString($v->mobile_code); // $res[$k]->address=Crypt::decryptString($v->address_code); // } $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->op_name=Auth::user()->name; $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); }); } $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([]); } public function AgainCreateImgB_e(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',4)->where('is_main',1)->where('img_type',0)->first(); $img=GiftUserImg::where('activity_id',$activity_id)->where('type',4)->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; } /**大礼包B的生成**/ public function CreateImgBDemo(Request $request){ $user_img=$request->input('user_img'); $avatar=Image::make($user_img); $fontPath=public_path().'/ziti/syht.otf'; $textColor=$request->input('color'); $text=$request->input('text'); // $text='不忘初心'; $length = strlen($text); $height=$request->input('height'); $left_len=$request->input('left_len'); $size=$request->input('size'); // 使用 for 循环输出每个字符 for ($i = 0; $i < $length; $i++) { $avatar->text(mb_substr($text,$i,1), $left_len, $height+100*$i, function($font) use ($fontPath, $textColor,$size) { $font->file($fontPath); $font->size($size); // 文本大小 $font->color($textColor); $font->align('center'); // 文本对齐方式 $font->valign('top'); // 文本垂直对齐方式 }); } return $avatar->response('png'); $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 $this->success([$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','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->where('op_name',Auth::user()->name); } $re=$re->get(); $data=[]; foreach ($re as $k=>$v){ $v->up_phone=''; $user_id=Order::where('good_user_id',$v->user_id) ->where('created_at','>','2024-11-05 00:00:00')->value('user_id'); if ($user_id){ $user=User::where('id',$user_id)->first(); if ($user){ $v->up_phone=$user->nickname; } } // $remar=User::where('id',$v->user_id)->first(); $v->up_name=$v->op_name; $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){ $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=Order::where('order.is_deleted',0) ->whereBetween('order.created_at',[$activity->start_time,$activity->end_time]) ->where('order.good_user_id',$v->user_id) ->join('address','address.id','order.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); } public function getBAgentGiftBag(Request $request){ $input=$request->all(); $page_index = $input['page_index']; $page_size = $input['page_size']; $num = ($page_index - 1) * $page_size; $activity_id=$input['activity_id']; $search_name=$input['search_name']; $tag=$input['tag']; // $big_gift='38500'; $where=[]; $wheres=[]; $big_gift=Activity::where('id',$activity_id)->value('big_gift'); // if($activity_id>17){ $big_gift_2=ActivityLimit::where('activity_id',$activity_id)->where('title','=','大礼包B-a')->value('account'); $big_gift_3=ActivityLimit::where('activity_id',$activity_id)->where('title','=','大礼包B-b')->value('account'); // }else{ // $big_gift_2=ActivityLimit::where('activity_id',$activity_id)->where('title','=','大礼包C')->value('account'); // $big_gift_3=ActivityLimit::where('activity_id',$activity_id)->where('title','=','大礼包D')->value('account'); // } $big_gift=$big_gift_2?$big_gift_2:$big_gift; if(empty($big_gift)){ return $this->error('450001','本此活动未开放大礼包名单'); } $gift_id=$big_gift_2; $max_status=false; if ($big_gift_3){ $max_status=true; } $max=0; // if (isset($input['gift_id'])){ // $dd=ActivityLimit::where('activity_id',$activity_id)->where('title','like','%大礼包%')->where('account','>',$big_gift_2)->orderBy('account')->limit(1)->first(); // if ($dd){ // $max=$dd->account; // $max_status=true; // } // $gift_id=$input['gift_id']; // } $actice=Activity::find($activity_id); $wheres=function($query) use ($actice){ $query->whereBetween('order.created_at',[$actice->start_time,$actice->end_time]); }; $user_ids=ListTag::where('type',1)->where('activity_id',$activity_id)->pluck('user_id')->toArray(); $user=User::select('users.id','users.mobile','users.remark_name as nickname','users.realname','users.remark_name as name', DB::raw('SUM(order.money) as account'), DB::raw('SUM(order.pay_money) as pay_account'),'gift_user_img.url','gift_user_img.user_img','gift_user_img.id as gift_id') ->leftJoin('order', 'order.user_id', '=', 'users.id'); // ->leftJoin('list_tag',function ($join) use ($activity_id){ // $join->on('users.id','=','list_tag.user_id') // ->where('list_tag.activity_id',$activity_id) // ->where('list_tag.type',1); // }) // ->leftJoin('list_tag','users.id','=','list_tag.user_id') // ->where('list_tag.activity_id',$activity_id) // ->where('list_tag.type',1) if (is_numeric($tag)){ if ($tag==1){ $user->whereIn('users.id',$user_ids); }else{ $user->whereNotIn('users.id',$user_ids); } }else{ $user->leftJoin('list_tag',function ($join) use ($activity_id){ $join->on('users.id','=','list_tag.user_id') ->where('list_tag.activity_id',$activity_id) ->where('list_tag.type',1); })->orderBy('list_tag.type'); } $user->leftJoin('gift_user_img',function ($join) use ($activity_id){ $join->on('users.id','=','gift_user_img.user_id') ->where('gift_user_img.activity_id',$activity_id) // ->where('gift_user_img.img_type',1) ->where('gift_user_img.type',1); }); if ($search_name){ $wheress=function ($q)use ($search_name){ $q->where('users.name','like',"%$search_name%")->orwhere('users.nickname','like',"%$search_name%")->orwhere('users.realname','like',"%$search_name%")->orwhere('users.mobile','like',"%$search_name%"); }; $user->where($wheress); } $user->where('order.is_deleted',0) ->where($where) ->where($wheres) ->groupBy('users.id') ->having('account','>=',$gift_id) ->when($max_status,function ($q)use($big_gift_3){ $q->having('account','<',$big_gift_3); }) ->orderBy('account','desc') ->orderBy('pay_account','desc'); $count = $user->get()->count(); if($count<=0){ $this->error('450001', '暂无信息'); } $ss=clone $user; $list=$user->skip($num)->take($page_size)->get(); foreach($list as $key=>$val){ $no_pay_account=round($val->account-$val->pay_account,2); if($no_pay_account>0){ $list[$key]->no_pay_account=$no_pay_account; }else{ $list[$key]->no_pay_account=0; } if(in_array($val->id,$user_ids)){ $list[$key]->tag=1; }else{ $list[$key]->tag=0; } } $ids=$ss->get(); return $this->success_list($list,'',$count,$ids); } public function getBAgentGiftBag_d(Request $request){ $input=$request->all(); $page_index = $input['page_index']; $page_size = $input['page_size']; $num = ($page_index - 1) * $page_size; $activity_id=$input['activity_id']; $search_name=$input['search_name']; $tag=$input['tag']; // $big_gift='38500'; $where=[]; $wheres=[]; $big_gift=Activity::where('id',$activity_id)->value('big_gift'); // if($activity_id>17){ $big_gift_2=ActivityLimit::where('activity_id',$activity_id)->where('title','=','大礼包B-b')->value('account'); $big_gift_3=ActivityLimit::where('activity_id',$activity_id)->where('title','=','大礼包B-c')->value('account'); // }else{ // $big_gift_2=ActivityLimit::where('activity_id',$activity_id)->where('title','=','大礼包C')->value('account'); // $big_gift_3=ActivityLimit::where('activity_id',$activity_id)->where('title','=','大礼包D')->value('account'); // } $big_gift=$big_gift_2?$big_gift_2:$big_gift; if(empty($big_gift)){ return $this->error('450001','本此活动未开放大礼包名单'); } $gift_id=$big_gift_2; $max_status=false; if ($big_gift_3){ $max_status=true; } $max=0; // if (isset($input['gift_id'])){ // $dd=ActivityLimit::where('activity_id',$activity_id)->where('title','like','%大礼包%')->where('account','>',$big_gift_2)->orderBy('account')->limit(1)->first(); // if ($dd){ // $max=$dd->account; // $max_status=true; // } // $gift_id=$input['gift_id']; // } $actice=Activity::find($activity_id); $wheres=function($query) use ($actice){ $query->whereBetween('order.created_at',[$actice->start_time,$actice->end_time]); }; $user_ids=ListTag::where('type',1)->where('activity_id',$activity_id)->pluck('user_id')->toArray(); $user=User::select('users.id','users.mobile','users.remark_name as nickname','users.realname','users.remark_name as name', DB::raw('SUM(order.money) as account'), DB::raw('SUM(order.pay_money) as pay_account'),'gift_user_img.url','gift_user_img.user_img','gift_user_img.id as gift_id') ->leftJoin('order', 'order.user_id', '=', 'users.id'); // ->leftJoin('list_tag',function ($join) use ($activity_id){ // $join->on('users.id','=','list_tag.user_id') // ->where('list_tag.activity_id',$activity_id) // ->where('list_tag.type',1); // }) // ->leftJoin('list_tag','users.id','=','list_tag.user_id') // ->where('list_tag.activity_id',$activity_id) // ->where('list_tag.type',1) if (is_numeric($tag)){ if ($tag==1){ $user->whereIn('users.id',$user_ids); }else{ $user->whereNotIn('users.id',$user_ids); } }else{ $user->leftJoin('list_tag',function ($join) use ($activity_id){ $join->on('users.id','=','list_tag.user_id') ->where('list_tag.activity_id',$activity_id) ->where('list_tag.type',1); })->orderBy('list_tag.type'); } $user->leftJoin('gift_user_img',function ($join) use ($activity_id){ $join->on('users.id','=','gift_user_img.user_id') ->where('gift_user_img.activity_id',$activity_id) // ->where('gift_user_img.img_type',1) ->where('gift_user_img.type',3); }); if ($search_name){ $wheress=function ($q)use ($search_name){ $q->where('users.name','like',"%$search_name%")->orwhere('users.nickname','like',"%$search_name%")->orwhere('users.realname','like',"%$search_name%")->orwhere('users.mobile','like',"%$search_name%"); }; $user->where($wheress); } $user->where('order.is_deleted',0) ->where($where) ->where($wheres) ->groupBy('users.id') ->having('account','>=',$gift_id) ->when($max_status,function ($q)use($big_gift_3){ $q->having('account','<',$big_gift_3); }) ->orderBy('account','desc') ->orderBy('pay_account','desc'); $count = $user->get()->count(); if($count<=0){ $this->error('450001', '暂无信息'); } $ss=clone $user; $list=$user->skip($num)->take($page_size)->get(); foreach($list as $key=>$val){ $no_pay_account=round($val->account-$val->pay_account,2); if($no_pay_account>0){ $list[$key]->no_pay_account=$no_pay_account; }else{ $list[$key]->no_pay_account=0; } if(in_array($val->id,$user_ids)){ $list[$key]->tag=1; }else{ $list[$key]->tag=0; } } $ids=$ss->get(); return $this->success_list($list,'',$count,$ids); } public function exportList(Request $request){ $input=$request->all(); $type=$input['type']; $activity_id=$input['activity_id']; $search_name=$input['search_name']; $tag=$input['tag']; $where=[]; $wheres=[]; $max_status=false; $max=0; if($type==1){ $big_gift=Activity::where('id',$activity_id)->value('big_gift'); $big_gift_2=ActivityLimit::where('activity_id',$activity_id)->where('title','大礼包B-c')->value('account'); $big_gift=$big_gift_2?$big_gift_2:$big_gift; if(empty($big_gift)){ return $this->error('450001','本此活动未开放大礼包名单'); } }elseif($type==2){ $honor_wall=Activity::where('id',$activity_id)->value('honor_wall'); $honor_wall_2=ActivityLimit::where('activity_id',$activity_id)->where('title','荣誉墙')->value('account'); $honor_wall=$honor_wall_2?$honor_wall_2:$honor_wall; if(empty($honor_wall)){ return $this->error('450001','本此活动未开放荣誉墙名单'); } }else{ $travel=ActivityLimit::where('activity_id',$activity_id)->where('title','旅游')->value('account'); if(empty($travel)){ return $this->error('450001','本此活动未开放旅游名单'); } } $actice=Activity::find($activity_id); $wheres=function($query) use ($actice){ $query->whereBetween('order.created_at',[$actice->start_time,$actice->end_time]); }; if($type==1){ // $money=Activity::where('id',$activity_id)->value('big_gift'); $big_gift_2=ActivityLimit::where('activity_id',$activity_id)->where('title','大礼包B-a')->min('account'); $money=$big_gift_2; $max_status=false; $max=0; // if (isset($input['gift_id'])){ $dd=ActivityLimit::where('activity_id',$activity_id)->where('title','大礼包B-d')->where('account','>',$big_gift_2)->orderBy('account')->limit(1)->first(); if ($dd){ $max=$dd->account; $max_status=true; } // $money=$input['gift_id']; // } }elseif($type==2){ $money = Activity::where('id', $activity_id)->value('honor_wall'); $honor_wall_2 = ActivityLimit::where('activity_id', $activity_id)->where('title', '荣誉墙')->value('account'); $money = $honor_wall_2 ? $honor_wall_2 : $money; } else { $money=ActivityLimit::where('activity_id',$activity_id)->where('title','旅游')->value('account'); } $user_ids=ListTag::where('type',$type)->where('activity_id',$activity_id)->pluck('user_id')->toArray(); $list=User::select('users.id','users.nickname','users.remark_name','users.realname','users.mobile', DB::raw('SUM(order.money) as account'), DB::raw('SUM(order.pay_money) as pay_account'),'gift_user_img.province','gift_user_img.city','gift_user_img.area','gift_user_img.address','gift_user_img.phone','gift_user_img.car_name') ->leftJoin('order', 'order.user_id', '=', 'users.id'); if (is_numeric($tag)){ if ($tag==1){ $list->whereIn('users.id',$user_ids); }else{ $list->whereNotIn('users.id',$user_ids); } }else{ $list->leftJoin('list_tag',function ($join) use ($activity_id){ $join->on('users.id','=','list_tag.user_id') ->where('list_tag.activity_id',$activity_id) ->where('list_tag.type',1); })->orderBy('list_tag.type'); } if ($search_name){ $wheress=function ($q)use ($search_name){ $q->where('users.name','like',"$search_name")->orwhere('users.nickname','like',"$search_name")->orwhere('users.realname','like',"$search_name")->orwhere('users.mobile','like',"$search_name"); }; $list->where($wheress); }; // ->leftJoin('list_tag',function ($join) use ($type,$activity_id){ // $join->on('users.id','=','list_tag.user_id') // ->where('list_tag.activity_id',$activity_id) // ->where('list_tag.type',$type); // }) $list->where('order.is_deleted',0) ->where($where) ->where($wheres) ->leftJoin('gift_user_img',function ($join) use ($activity_id){ $join->on('users.id','=','gift_user_img.user_id') ->where('gift_user_img.type',1) ->where('gift_user_img.img_type',1) ->whereNotNull('gift_user_img.province') ->orderByDesc('gift_user_img.id')->limit(1); }) ->groupBy('users.id') ->having('account','>=',$money) ->when($max_status,function ($q)use ($max){ $q->having('account','<',$max); }) ->orderBy('account','desc') ->orderBy('pay_account','desc'); $count=$list->get()->count(); if($count<=0){ $this->error('450001', '暂无信息'); } $list=$list->get(); $ll=[]; foreach($list as $key=>$val){ $ll[$key]['备注昵称']=$val->remark_name; $ll[$key]['客户姓名']=$val->realname; $ll[$key]['订货金额']=$val->account; $ll[$key]['已付款金额']=$val->pay_account; $no_pay_account=round($val->account-$val->pay_account,2); if($no_pay_account>0){ $ll[$key]['未付款金额']=$no_pay_account; }else{ $ll[$key]['未付款金额']=0; } if(in_array($val->id,$user_ids)){ $ll[$key]['标记']='已标记'; }else{ $ll[$key]['标记']='未标记'; } $ll[$key]['收货人']=$val->car_name==null?$val->realname:$val->car_name; $ll[$key]['电话']=$val->phone==null?$val->mobile:$val->phone; $ll[$key]['省份']=$val->province; $ll[$key]['城市']=$val->city; $ll[$key]['地区']=$val->area; $ll[$key]['详细地址']=$val->address; } return $this->success($ll); } /* * 导出活动大礼包D * */ public function exportList_d(Request $request){ $input=$request->all(); $type=$input['type']; $activity_id=$input['activity_id']; $search_name=$input['search_name']; $tag=$input['tag']; $where=[]; $wheres=[]; $max_status=false; $max=0; if($type==1){ $big_gift=Activity::where('id',$activity_id)->value('big_gift'); $big_gift_2=ActivityLimit::where('activity_id',$activity_id)->where('title','大礼包D')->value('account'); $big_gift=$big_gift_2?$big_gift_2:$big_gift; if(empty($big_gift)){ return $this->error('450001','本此活动未开放大礼包名单'); } }elseif($type==2){ $honor_wall=Activity::where('id',$activity_id)->value('honor_wall'); $honor_wall_2=ActivityLimit::where('activity_id',$activity_id)->where('title','荣誉墙')->value('account'); $honor_wall=$honor_wall_2?$honor_wall_2:$honor_wall; if(empty($honor_wall)){ return $this->error('450001','本此活动未开放荣誉墙名单'); } }else{ $travel=ActivityLimit::where('activity_id',$activity_id)->where('title','旅游')->value('account'); if(empty($travel)){ return $this->error('450001','本此活动未开放旅游名单'); } } $actice=Activity::find($activity_id); $wheres=function($query) use ($actice){ $query->whereBetween('order.created_at',[$actice->start_time,$actice->end_time]); }; if($type==1){ // $money=Activity::where('id',$activity_id)->value('big_gift'); $big_gift_2=ActivityLimit::where('activity_id',$activity_id)->where('title','大礼包D')->value('account'); $money=$big_gift_2; $max_status=false; $max=0; // if (isset($input['gift_id'])){ $dd=ActivityLimit::where('activity_id',$activity_id)->where('title','like','%大礼包%')->where('account','>',$big_gift_2)->orderBy('account')->limit(1)->first(); if ($dd){ $max=$dd->account; $max_status=true; } // $money=$input['gift_id']; // } }elseif($type==2){ $money = Activity::where('id', $activity_id)->value('honor_wall'); $honor_wall_2 = ActivityLimit::where('activity_id', $activity_id)->where('title', '荣誉墙')->value('account'); $money = $honor_wall_2 ? $honor_wall_2 : $money; } else { $money=ActivityLimit::where('activity_id',$activity_id)->where('title','旅游')->value('account'); } $user_ids=ListTag::where('type',$type)->where('activity_id',$activity_id)->pluck('user_id')->toArray(); $list=User::select('users.id','users.nickname','users.remark_name','users.realname', DB::raw('SUM(order.money) as account'), DB::raw('SUM(order.pay_money) as pay_account')) ->leftJoin('order', 'order.user_id', '=', 'users.id'); if (is_numeric($tag)){ if ($tag==1){ $list->whereIn('users.id',$user_ids); }else{ $list->whereNotIn('users.id',$user_ids); } }else{ $list->leftJoin('list_tag',function ($join) use ($activity_id){ $join->on('users.id','=','list_tag.user_id') ->where('list_tag.activity_id',$activity_id) ->where('list_tag.type',1); })->orderBy('list_tag.type'); } if ($search_name){ $wheress=function ($q)use ($search_name){ $q->where('users.name','like',"$search_name")->orwhere('users.nickname','like',"$search_name")->orwhere('users.realname','like',"$search_name")->orwhere('users.mobile','like',"$search_name"); }; $list->where($wheress); }; // ->leftJoin('list_tag',function ($join) use ($type,$activity_id){ // $join->on('users.id','=','list_tag.user_id') // ->where('list_tag.activity_id',$activity_id) // ->where('list_tag.type',$type); // }) $list->where('order.is_deleted',0) ->where($where) ->where($wheres) ->groupBy('users.id') ->having('account','>=',$money) ->when($max_status,function ($q)use ($max){ $q->having('account','<',$max); }) ->orderBy('account','desc') ->orderBy('pay_account','desc'); $count=$list->get()->count(); if($count<=0){ $this->error('450001', '暂无信息'); } $list=$list->get(); $ll=[]; foreach($list as $key=>$val){ $ll[$key]['备注昵称']=$val->remark_name; $ll[$key]['客户姓名']=$val->realname; $ll[$key]['订货金额']=$val->account; $ll[$key]['已付款金额']=$val->pay_account; $no_pay_account=round($val->account-$val->pay_account,2); if($no_pay_account>0){ $ll[$key]['未付款金额']=$no_pay_account; }else{ $ll[$key]['未付款金额']=0; } if(in_array($val->id,$user_ids)){ $ll[$key]['标记']='已标记'; }else{ $ll[$key]['标记']='未标记'; } } return $this->success($ll); } }