middleware('auth'); $this->userCon = $userCon; } public function index(){ return view('home'); } /** * 首页 */ public function home(Request $request) { $mine = auth()->user(); $sex = $mine->sex == 1? 2:1; $blacklist_user_ids = Blacklist::where('user_id', $mine->id)->pluck('other_user_id'); $users = User::whereNotNull('photo')->with('profileCourtship')->where('type', 'single')->where('sex', $sex)->where('belief', $mine->belief)->whereNotIn('id', $blacklist_user_ids); $keyword = $request->input('keyword'); if ($keyword) { $keyword = trim($keyword); $users = $users->where('name', 'like', '%'.$keyword.'%'); } $users = $users->orderBy('is_approved', 'desc')->orderBy('id', 'desc')->paginate(); foreach ($users as $user) { $age = "未知"; if (!empty($user->profileCourtship) && !empty($user->profileCourtship->birthday)) { $age = $this->getAge($user->profileCourtship->birthday); $age = $age.'岁'; } $user->age = $age; } return $this->success('ok', $users); } /** * 生成社群海报 */ public function createPoster(Request $request){ if(!$request->has('type')){ $this->failure('请输入查找类型'); } //查找群组分享海报 $path = env('APP_URL').'/mobile/#'; if($request->type == 1){ $community_group = CommunityGroup::select('title', 'share_poster', 'logo')->where('id', $request->id)->first(); $path .= 'communityClass/'.$request->id; $pic = $community_group->share_poster; //没有分享海报就往数据插入一张 if(empty($community_group)){ return $this->failure('社群ID或者分类输入错误'); } if(empty($community_group->share_poster)){ $qrcode = $this->getUrlqrcode($path); $pic = $this->assembly($community_group->logo, $community_group->title, $qrcode); CommunityGroup::where('id', $request->id)->update(['share_poster'=>$pic]); } }else{ $community = Community::select('title', 'share_poster', 'logo')->where('id', $request->id)->first(); $path .= 'communityDetail/'.$request->id; //没有分享海报就往数据插入一张 if(empty($community)){ return $this->failure('社群ID或者分类输入错误'); } $pic = $community->share_poster; if(empty($community->share_poster)){ $qrcode = $this->getUrlqrcode($path); $pic = $this->assembly($community->logo, $community->title, $qrcode); Community::where('id', $request->id)->update(['share_poster'=>$pic]); } } return $this->success('ok', $pic); } public function assembly($logo, $title, $qrcode){ //原始海报 $poster = public_path()."/imgs/back.png"; $new_image = $this->imageAddImage($poster, $qrcode, 170, 170, 48, 100, 'bottom-right'); $new_image = $this->imageAddImage($new_image, $logo, 183, 183, 292, 110, 'top-left'); $new_image = $this->textAddImage($new_image, $title,50, 375, 331, '#001100', 'center'); $time = time(); $file_path = storage_path()."/qrcode/".$time."poster.png"; $new_image->save($file_path); $pic = ''; if(file_exists($file_path)){ $pic = $this->uploadFile($file_path); try{ unlink($file_path); }catch(Exception $e) { return $this->failure($e->getMessage()); exit(); } } return $pic; } /** 常见问题 */ public function faq(Request $request){ $list = QuestionType::where('is_show', 1) ->with(['commonProblems'=>function($q){ $q->orderBy('sort', 'desc')->select('type_id','question as title','answer as value'); }]) ->orderBy('sort', 'desc') ->get(); $dataList = array(); foreach($list as $key=>$l){ $dataList[]=array( 'activeName'=>'activeName'.($key+1), 'title'=>$l->name, 'pic'=>$l->icon, 'main'=>$l->commonProblems, ); } return $this->success('ok', $dataList); } }