userCon = $userCon; $this->orderCon = $orderCon; $this->momentService = $momentService; } /** * app版本 * @param Request $request [description] * @return [type] [description] */ public function appVersion(Request $request) { $ios_log = AppLog::where('type', 0)->orderBy('id', 'desc')->first(); $and_log = AppLog::where('type', 1)->orderBy('id', 'desc')->first(); //是否强制更新 $forced_updating = 0; if(!empty($ios_log)){ if($ios_log->is_forced && $ios_log->start_time < date('Y-m-d H:i:s')){ $forced_updating = 1; } } $and_forced_updating = 0; if(!empty($and_log)){ if ($and_log->is_forced && $and_log->start_time < date('Y-m-d H:i:s')) { $and_forced_updating = 1; } } //是否检查更新 $check_updating = 0; if(!empty($ios_log)){ if($ios_log->is_check_forced && $ios_log->start_time < date('Y-m-d H:i:s')){ $check_updating = 1; } } $and_check_updating = 0; if(!empty($and_log)){ if ($and_log->is_check_forced && $and_log->start_time < date('Y-m-d H:i:s')) { $and_check_updating = 1; } } $data = [ 'api_version'=>'1.0.0',//api接口版本 'app_version' => !empty($ios_log->next_version) ? $ios_log->next_version :'1.3.0',//iosapp版本 'and_app_version' => !empty($and_log->next_version) ? $and_log->next_version :'1.3.0',//安卓app版本 'and_app_code'=>!empty($and_log->and_app_code) ? $and_log->and_app_code :15, //安卓 'forced_updating'=>$forced_updating, //ios是否强制更新 'and_forced_updating'=>$and_forced_updating,//安卓是否强制更新 'check_updating'=>$check_updating, //ios是否检查更新 'and_check_updating'=>$and_check_updating,//安卓是否检查更新 'content'=> !empty($ios_log->point) ? $ios_log->point : "更新内容\n1.优化动态\n2.优化登录",//ios更新内容 'and_content'=> !empty($and_log->point) ? $and_log->point : "更新内容\n1.优化动态\n2.优化资料编辑",//安卓更新内容 'and_download_url' => !empty($and_log->apk) ? $and_log->apk : 'https://image.ufutx.com/apk/FullLink.apk', ]; return $this->success('ok', $data); } public function servicerIds(Request $request) { $servicer_ids = UserInfo::where('is_service_client', 1)->pluck('user_id')->toArray(); return $this->success('ok', compact('servicer_ids')); } public function getPhoto(Request $request) { if(!$request->has('user_id')) return $this->failure('请求参数缺失。'); $user_id = $request->user_id; $user = new User(); $photo = $user->userAvatar($user_id); return $this->success('ok', compact('photo')); } public function androidDownloadUrl(Request $request) { $download_url = 'https://image.ufutx.com/apk/FullLink.apk'; return $this->success('ok', compact('download_url')); } /**P * 个人中心 * @param Request $request [description] * @return [type] [description] */ public function personalCenter(Request $request) { try { $user_id = auth()->id(); $user = User::where('id', $user_id)->select('id','name', 'nickname', 'photo', 'app_avatar','industry','industry_sub', 'type', 'is_approved','is_real_approved', 'is_educate_approved','approve_time', 'hidden', 'sex', 'belief', 'is_photo_audited', 'live_match_maker','rank_id', 'hidden')->first(); $user->is_approved = $user->is_approved == 0?((ApproveHistory::where('user_id', $user_id)->where('type', 'name')->where('status', 0)->exists())?2:0):1; $deadline = RankHistory::where('user_id', $user_id)->where('rank_id', $user->rank_id)->orderBy('deadline', 'desc')->value('deadline'); //会员到期时间 $user->deadline = $deadline; //是否是超级会员 $user->isSuperRank = $user->isSuperRank(); //好友数 $user->friendCount = $user->friendCount(); //粉丝数 $user->fans_count = $user->followers()->count()?:0; //关注数 $user->follow_count = $user->followings()->count()?:0; //访客数 // $user->preview_count = $user->userPreview()->whereNotNull('preview_time')->whereHas('previewUser', function($sql){ // })->count()?:0; $result = UserPreviewHistory::whereHas('previewUser', function($sql) use($user){ if ($user->type == 'single') { $sql->where('sex', '<>', $user->sex)->where('type', 'single')->where('hidden_profile', '<>', 'ALLSEX'); } })->where('user_id', $user->id)->where('is_hidden', 0)->groupBy('preview_user_id') ->get()->toArray(); $user->preview_count = count($result)?:0; //是否完善资料 $profile_data = User::APPCOMPLETEINFO; $result = $this->userCon->profileIntegrity($user->profileCourtship,$user,explode(',', $profile_data)); $bili = $result['count'] / $result['total_count']; $user->isCompleteInfo = number_format($bili,2) == 1?1:0; //是否绑定微信 $user->bind_wechat = $user->wechat?($user->wechat->app_openid?1:0):0; //头像 $user->photo = $user->userAvatar(); $introductionVerifyResultCode__key = $this->userCon->KYE_IVRC . $user->id; $ideal_mateVerifyResultCode_key = $this->userCon->KYE_IMVRC . $user->id; $interest_hobbyVerifyResultCode_key = $this->userCon->KYE_IMPHO . $user->id; //个人介绍 $user->introduction_verifyResultCode = $this->userCon->geTextVerifyCode($introductionVerifyResultCode__key,$user->profileCourtship->introduction); //择偶标准 $user->ideal_mate_verifyResultCode = $this->userCon->geTextVerifyCode($ideal_mateVerifyResultCode_key,$user->profileCourtship->ideal_mate); //兴趣爱好 $user->interest_hobby_verifyResultCode = $this->userCon->geTextVerifyCode($interest_hobbyVerifyResultCode_key,$user->profileCourtship->interest_hobby); //是否被标记 $user->tag_status = WrongInfoHistories::where('user_id',$user->id)->where('type','tag')->where('status',1)->count(); unset($user->wechat, $user->profileCourtship); return $this->success('ok', $user); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取个人中心信息失败,请稍后再试'); } } /** * 关注列表 * @param Request $request [description] * @return [type] [description] */ public function followings(Request $request) { try { $user = auth()->user(); $followings = $user->followings()->orderBy('followables.created_at', 'desc')->paginate(); foreach ($followings as $following) { // dd($following); $rd_user_key = User::cacheUserKey($following->id); if (Cache::has($rd_user_key)) { $rd_user = Cache::get($rd_user_key); }else{ $following->cacheUser(); $rd_user = Cache::get($rd_user_key); } $birthday = $rd_user->profileCourtship?$rd_user->profileCourtship->birthday:null; $following->age = \CommonUtilsService::getAge($birthday); $following->isSuperRank = $rd_user->is_super_rank; $following->photo = $rd_user->userAvatar(); unset($following->uid, $following->is_new, $following->name, $following->face_score, $following->card_num, $following->circle_avatar, $following->mobile, $following->email, $following->location_longitude, $following->location_latitude, $following->temp_member, $following->industry, $following->industry_sub,$following->from_user_id,$following->from_openid,$following->from_official_openid, $following->from_platform,$following->friend_count,$following->my_qrcode,$following->my_qrcode_rect,$following->my_share_rect,$following->my_share,$following->home_share,$following->is_admin,$following->approve_time,$following->is_real_approved,$following->approve_date,$following->hidden,$following->is_audited,$following->is_photo_audited,$following->system_info,$following->identification_photos,$following->scene,$following->last_visit,$following->tag_num,$following->negative_score,$following->info_complete_score,$following->is_update_score,$following->is_subscribe,$following->mark,$following->created_at,$following->updated_at,$following->deleted_at); $following->created_at = $following->pivot->created_at; unset($following->pivot); } return $this->success('ok', $followings); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取关注列表失败,请稍后再试'); } } /** * 好友列表 * @param Request $request [description] * @return [type] [description] */ public function friends(Request $request) { try { $user = auth()->user(); $linkings = Linking::with('user:id,nickname,photo,app_avatar,rank_id,is_approved,sex', 'userLink:id,nickname,photo,app_avatar,rank_id,is_approved,sex')->where(function($sql){ $sql->where('user_id', auth()->id())->orWhere('user_linking_id', auth()->id()); })->whereHas('user', function($sql){ // $sql->where('hidden_profile', 'NONE')/*->where('type', 'single')*/; })->whereHas('userLink', function($sql){ // $sql->where('hidden_profile', 'NONE')/*->where('type', 'single')*/; }); $keyword = $request->keyword; if($keyword || ($keyword == 0 && $keyword != null) ){ $linkings = $linkings->whereHas('user', function($query) use ($keyword,$user) { $query->where('nickname', 'like', '%'.$keyword.'%'); $query->orWhere('id',$user->id); }); $linkings = $linkings->whereHas('userLink', function($query) use ($keyword,$user) { $query->where('nickname', 'like', '%'.$keyword.'%'); $query->orWhere('id',$user->id); }); } $linkings = $linkings->orderBy('created_at', 'desc')->paginate(); foreach ($linkings as $linking) { if ($linking->user_id != auth()->id()) { $linking->nickname = $linking->user->nickname; $linking->id = $linking->user->id; $linking->is_approved = $linking->user->is_approved; $linking->isSuperRank = $linking->user->isSuperRank()?1:0; $linking->sex = $linking->user->sex; $linking->photo = $linking->user->userAvatar(); }else{ $linking->nickname = $linking->userLink->nickname; $linking->id = $linking->userLink->id; $linking->is_approved = $linking->userLink->is_approved; $linking->isSuperRank = $linking->userLink->isSuperRank()?1:0; $linking->sex = $linking->userLink->sex; $linking->photo = $linking->userLink->userAvatar(); } $profile_courtship = ProfileCourtship::where('user_id', $linking->id)->select('user_id', 'birthday', 'city', 'stature')->first(); if ($profile_courtship) { $linking->age = \CommonUtilsService::getAge($profile_courtship->birthday); } $linking->profile_courtship = $profile_courtship; unset($linking->user, $linking->userLink, $linking->user_linking_id,$linking->user_id); } return $this->success('ok', $linkings); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取好友列表信息失败,请稍后再试'); } } /**获取群聊和好友的列表 */ public function myGroupFriendsChat(Request $request){ $userinfo = $this->getMyUserinfo(); if(!$userinfo){ return $this->fail('请登录后访问',2); } $keyword = $request->keyword; $type = $request->input('type'); $groupChatList = $this->userCon->getMyGroupChat($userinfo,$keyword,15); $friendChatList = $this->userCon->getMyFriends($userinfo,$keyword,$type,15); return $this->success('ok', ['groupChatList'=>$groupChatList,'friendChatList'=>$friendChatList]); } /** * 粉丝列表 * @param Request $request [description] * @return [type] [description] */ public function fans(Request $request) { try { $user = auth()->user(); $followings = $user->followers()->orderBY('followables.created_at', 'desc')->paginate(); foreach ($followings as $following) { $rd_user_key = User::cacheUserKey($following->id); if (Cache::has($rd_user_key)) { $rd_user = Cache::get($rd_user_key); }else{ $following->cacheUser(); $rd_user = Cache::get($rd_user_key); } $birthday = $rd_user->profileCourtship?$rd_user->profileCourtship->birthday:null; $following->city = $rd_user->profileCourtship?$rd_user->profileCourtship->city:null; $following->age = \CommonUtilsService::getAge($birthday); $following->birthday = $birthday; $following->isSuperRank = $rd_user->is_super_rank; $following->photo = $rd_user->userAvatar(); Notice::where('type','follow')->where('user_id',$user->id)->where('status',0)->update(['status'=>1]); unset($following->uid, $following->is_new, $following->name, $following->face_score, $following->card_num, $following->circle_avatar, $following->mobile, $following->email, $following->location_longitude, $following->location_latitude, $following->temp_member, $following->industry, $following->industry_sub,$following->from_user_id,$following->from_openid,$following->from_official_openid, $following->from_platform,$following->friend_count,$following->my_qrcode,$following->my_qrcode_rect,$following->my_share_rect,$following->my_share,$following->home_share,$following->is_admin,$following->approve_time,$following->is_real_approved,$following->approve_date,$following->hidden,$following->is_audited,$following->is_photo_audited,$following->system_info,$following->identification_photos,$following->scene,$following->last_visit,$following->tag_num,$following->negative_score,$following->info_complete_score,$following->is_update_score,$following->is_subscribe,$following->mark,$following->created_at,$following->updated_at,$following->deleted_at); $following->created_at = $following->pivot->created_at; unset($following->pivot); } notice::where('user_id',$user->id)->where('type','follow')->update(['status'=>1]); return $this->success('ok', $followings); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取关注列表失败,请稍后再试'); } } /** * 访客记录 * @param Request $request [description] * @return [type] [description] */ public function previews(Request $request) { $user = auth()->user(); $linkings = UserPreviewHistory::with('previewUser:id,nickname,name,photo,circle_avatar,app_avatar,sex,type,hidden_profile') ->with('profileCourtship:province,city,birthday,user_id,stature') ->with('profileMarriage:province,city,birthday,user_id') ->whereHas('previewUser', function($sql) use($user){ if ($user->type == 'single') { $sql->where('sex', '<>', $user->sex)->where('type', 'single'); } })->where('user_id', $user->id)->where('is_hidden', 0) ->select(DB::raw('max(id) as some_id, id, user_id, preview_user_id,is_hidden, max(created_at) as created_at')) ->orderBY('some_id', 'desc') ->groupBy('preview_user_id'); $linkings = $linkings->whereHas('previewUser', function ($sql) { $sql->where('hidden_profile', '!=','ALLSEX'); }); $keyword = $request->input('keyword'); if ($keyword) { $keyword = trim($keyword); $linkings = $linkings->whereHas('user', function ($sql) use ($keyword) { $sql->where('name', 'like', '%' . $keyword . '%'); }); } $linkings = $linkings->paginate(); foreach ($linkings as $linking) { $linking->nickname = $linking->previewUser->nickname; $linking->id = $linking->previewUser->id; $linking->is_approved = $linking->previewUser->is_approved; $linking->isSuperRank = $linking->previewUser->isSuperRank()?1:0; $linking->sex = $linking->previewUser->sex; $profile_courtship = $linking->previewUser->profileCourtship; $linking->age = \CommonUtilsService::getAge($profile_courtship?$profile_courtship->birthday:null); $linking->profile_courtship = $profile_courtship; $linking->photo = $linking->previewUser->userAvatar(); unset($linking->previewUser,$linking->user_id,$linking->previewe_user_id,$linking->status); } UserPreview::where('user_id', $user->id)->where('status', 0)->update(['status' => 1]); return $this->success('ok', $linkings); } //刪除访客记录 public function deletePreviewHistory(Request $request){ try { $mine = auth()->user(); $user_id = $request->user_id; UserPreview::where('preview_user_id',$user_id)->where('user_id',$mine->id)->delete(); return $this->success('ok'); } catch (\Exception $e) { $this->getError($e); return $this->failure('操作失败,请稍后再试'); } } /** * 搜索相关用户 好友、关注、粉丝、访客 * @param Request $request [description] * @return [type] [description] */ public function searchFriends(Request $request) { $user = auth()->user(); $keyword = $request->input('keyword'); //好友搜索 list($friends, $friend_count) = $this->getSearchFriends($user, $keyword, 10); //关注 list($followings, $following_count) = $this->getSearchFollowings($user, $keyword, 10); //粉丝 list($followers, $follower_count) = $this->getSearchFollowers($user, $keyword, 10); //访客 list($previews, $preview_count) = $this->getSearchPreviews($user, $keyword, 10); $num_arr = [ 'friend_count'=>$friend_count, 'following_count' => $following_count, 'follower_count' => $follower_count, 'preview_count' => $preview_count, ]; return $this->success('ok', compact('friends', 'followings', 'followers', 'previews', 'num_arr')); } public function getSearchFriends($user, $keyword, $limit=0) { $ids = Linking::where('user_id', $user->id)->pluck('user_linking_id'); $other_ids = Linking::where('user_linking_id', $user->id)->pluck('user_id'); $friends_query = User::where(function($sql) use($ids, $other_ids){ $sql->whereIn('id', $ids)->orWhereIn('id', $other_ids); })/*->where('type', 'single')*/->where('hidden_profile', 'NONE'); if($keyword || ($keyword == 0 && $keyword != null) ){ $friends_query = $friends_query->where('nickname', 'like', '%'.$keyword.'%'); } $friends = $friends_query->select('id', 'photo', 'app_avatar', 'nickname')->limit(3)->get(); foreach ($friends as $friend) { $friend->photo = $friend->userAvatar(); } $friend_count = $friends_query->count()?:0; return [$friends, $friend_count]; } public function getSearchFollowings($user, $keyword, $limit=0) { $followings_query = $user->followings()/*->where('type', 'single')*/->where('hidden_profile', 'NONE'); if($keyword){ $followings_query = $followings_query->where('nickname', 'like', '%'.$keyword.'%');; } if ($limit) { $followings = $followings_query->limit($limit)->get(); $following_count = $followings_query->count()?:0; }else{ $followings = $followings_query->paginate(); $following_count = 0; } foreach ($followings as $following) { unset($following->uid, $following->is_new, $following->name, $following->face_score, $following->card_num, $following->circle_avatar, $following->mobile, $following->email, $following->location_longitude, $following->location_latitude, $following->temp_member, $following->industry, $following->industry_sub,$following->from_user_id,$following->from_openid,$following->from_official_openid, $following->from_platform,$following->friend_count,$following->my_qrcode,$following->my_qrcode_rect,$following->my_share_rect,$following->my_share,$following->home_share,$following->is_admin,$following->approve_time,$following->is_real_approved,$following->approve_date,$following->hidden,$following->is_audited,$following->is_photo_audited,$following->system_info,$following->identification_photos,$following->scene,$following->last_visit,$following->tag_num,$following->negative_score,$following->info_complete_score,$following->is_update_score,$following->is_subscribe,$following->mark,$following->created_at,$following->updated_at,$following->deleted_at,$following->sex,$following->age,$following->rank_id,$following->type,$following->is_approved,$following->hidden_profile,$following->belief); unset($following->pivot); } return [$followings, $following_count]; } public function getSearchFollowers($user, $keyword, $limit=0) { $followers_query = $user->followers()/*->where('type', 'single')*/->where('hidden_profile', 'NONE'); if($keyword){ $followers_query = $followers_query->where('nickname', 'like', '%'.$keyword.'%'); } if ($limit) { $followings = $followers_query->limit($limit)->get(); $follower_count = $followers_query->count()?:0; }else{ $followings = $followers_query->paginate(); $follower_count = 0; } foreach ($followings as $following) { unset($following->uid, $following->is_new, $following->name, $following->face_score, $following->card_num, $following->circle_avatar, $following->mobile, $following->email, $following->location_longitude, $following->location_latitude, $following->temp_member, $following->industry, $following->industry_sub,$following->from_user_id,$following->from_openid,$following->from_official_openid, $following->from_platform,$following->friend_count,$following->my_qrcode,$following->my_qrcode_rect,$following->my_share_rect,$following->my_share,$following->home_share,$following->is_admin,$following->approve_time,$following->is_real_approved,$following->approve_date,$following->hidden,$following->is_audited,$following->is_photo_audited,$following->system_info,$following->identification_photos,$following->scene,$following->last_visit,$following->tag_num,$following->negative_score,$following->info_complete_score,$following->is_update_score,$following->is_subscribe,$following->mark,$following->created_at,$following->updated_at,$following->deleted_at,$following->sex,$following->age,$following->rank_id,$following->type,$following->is_approved,$following->hidden_profile,$following->belief); unset($following->pivot); } return [$followings, $follower_count]; } public function getSearchPreviews($user, $keyword, $limit=0) { $previews_query = $user->userPreview()->with('previewUser:id,nickname,photo,app_avatar')->whereHas('previewUser', function($sql) use($keyword) { $sql = $sql->where('hidden_profile', 'NONE')/*->where('type', 'single')*/->where('nickname', 'like', '%'.$keyword.'%'); if($keyword){ $sql = $sql->where('nickname', 'like', '%'.$keyword.'%'); } }); if ($limit) { //访客记录 $previews = $previews_query->select('id', 'user_id', 'preview_user_id')->limit($limit)->get(); $preview_count = $previews_query->count()?:0; }else{ $previews = $previews_query->select('id', 'user_id', 'preview_user_id')->paginate(); $preview_count = 0; } foreach ($previews as $preview) { $preview->id = $preview->preview_user_id; $preview->nickname = $preview->previewUser->nickname; $preview->photo = $preview->previewUser->userAvatar(); unset($preview->previewUser, $preview->user_id, $preview->preview_user_id); } return [$previews, $preview_count]; } /** * 认证 * @param Request $request [description] * @return [type] [description] */ public function approve(Request $request) { \DB::beginTransaction(); try { $user = auth()->user(); $blacklist = [42805, 42802, 42801]; if (in_array($user->id, $blacklist)) { return $this->failure('请进入人工认证,上传手持身份证照!'); } $name = $request->input('name'); if (empty($name)) { return $this->failure('请输入真实姓名'); } $card_num = $request->input('card_num'); if (empty($card_num)) { return $this->failure('请输入身份证号'); } if (empty($user->approve_time)) { return $this->failure('无自动认证资格,请通过人工认证'); } //是否身份已经验证过 $history = User::where('id', '<>', $user->id)->where('card_num', $card_num)->exists(); if ($history) { return $this->failure('此身份证已经实名验证过,请使用真实信息!'); } if ($user->name != $name) { $user->name = $name; } if ($user->card_num != $card_num) { $user->card_num = $card_num; } $user->save(); $result = \AliyunService::aliCheckInfoV2($user->id, $name, $card_num); $result = json_decode($result); if (empty($result)) { return $this->failure('服务错误,请重试'); } $user->decrement('approve_time', 1); if ($result->code == 200) { $bizCode = $result->value->bizCode; if ($bizCode == 0) { //添加身份证号 if ($user->card_num && $user->is_approved == 1) { return $this->failure('已认证'); } //认证状态 $user->is_approved = 1; //认证时间 $user->approve_date = date('Y-m-d H:i:s'); $user->save(); //增加认证记录 $history = ApproveHistory::where('user_id', $user->id)->first(); if (empty($history)) { ApproveHistory::create([ 'user_id'=>$user->id, 'type'=>'name', 'status'=>1, 'ways' => 1, 'from_platform'=>$request->from_platform, ]); }else{ $history->status = 1; $history->save(); } //更新出生年月日 $user->cardBirthdayToProfile('app'); \DB::commit(); return $this->success('ok'); }else{ \DB::rollback(); return $this->failure($result->message); } }else { \DB::commit(); $message = explode(':', $result->message); if (is_array($message) && count($message)) { if ($message[1] == '参数非法') { $error = '信息不匹配'; return $this->failure($error); }elseif ($message[1] != '参数非法') { return $this->failure($message[1]); } } return $this->failure($result->message); } } catch (\Exception $e) { \DB::rollback(); $this->getError($e); return $this->failure('认证失败,请稍后再试'); } } /** * 活体检测 * @param Request $request [description] * @return [type] [description] */ public function realApprove(Request $request) { try { //检测参数 $result = $this->checkRealApproveParam(); if (empty($result)) throw new \Exception("参数错误", 1); if (is_array($result) && $result['code']) return $this->failure($result['msg'], ['error_type'=>$result['error_type']]); //活体检测 $im_service = new IMService(); $result = $im_service->checkBioassay($request->card_num, $request->name, $request->token); if (empty($result)) throw new \Exception("活体检测失败", 1); if ($result->code != 200) throw new \Exception($result->msg, $result->code); //记录认证信息 if ($result->result) { $this->userCon->addLiveperson($result->result); } if ($result->result && $result->result->reasonType != 1) return $this->failure($this->getBioassay($result), ['error_type'=>1]); \DB::beginTransaction(); //更新实人认证信息 $body_log = auth()->user()->updateApproveInfo('body', 1); //更新实名认证信息 $name_log = auth()->user()->updateApproveInfo('name', 1); //同步生日 auth()->user()->cardBirthdayToProfile('app'); //是否已赠送 $log = auth()->user()->coinLogs()->where(['type'=>'RECSYSTEM', 'remark'=>'真人认证'])->first(); if (empty($log)) { //赠送福币 +10 不可提现 auth()->user()->updateCoinInfo('add', 10, 'other'); auth()->user()->addCoinLog("RECSYSTEM", 0, 10, '真人认证'); $message = "您的真人认证已通过后台审核,系统赠送您10个福币作为奖励,请注意查收!"; $body = ['msg'=>$message]; $im_service = new IMService(env('IM_APP_KEY'), env('IM_APP_SECRET')); $result = $im_service->sendMsg(1, 0,auth()->id(),$type=0,$body); if (empty($result)) throw new \Exception("修改认证信息失败", 1); } //分享人福币赠送 if ($body_log->from_user_id) { $share_user = User::find($body_log->from_user_id); if ($share_user) { $log = $share_user->coinLogs()->where(['type'=>'RECSYSTEM', 'type_id'=>$body_log->user_id, 'remark'=>'邀请好友认证'])->first(); if (empty($log)) { $share_user->addCoinLog("RECSYSTEM", $body_log->user_id, 50, '邀请好友认证'); } } } \DB::commit(); auth()->user()->updateCacheUser('is_approved'); auth()->user()->updateCacheUser('is_real_approved'); return $this->success('ok'); } catch (\Exception $e) { \DB::rollback(); $this->getError($e); return $this->failure('真人认证失败,请稍后再试', ['error_type'=>1]); } } /** * 活体检测 * @param Request $request [description] * @return [type] [description] */ public function realApproveV2(Request $request) { try { //检测参数 $result = $this->checkRealApproveParamV2(); if (empty($result)) throw new \Exception("参数错误", 1); if(is_array($result)){ return $this->success('认证失败', $result); } if (is_array($result) && $result['code']) return $this->failure($result['msg'], ['error_type'=>$result['error_type']]); //活体检测 $im_service = new IMService(); $result = $im_service->checkBioassay($request->card_num, $request->name, $request->token); if (empty($result)) throw new \Exception("活体检测失败", 1); if ($result->code != 200){ $data = [ 'type' => 1, 'message' => $result->msg ]; return $this->success('认证失败', $data); } // throw new \Exception($result->msg, $result->code); //记录认证信息 if ($result->result) { $this->userCon->addLiveperson($result->result); } if ($result->result && $result->result->reasonType != 1){ $data = UserService::getData($result->result->reasonType); return $this->success('认证失败', $data); } \DB::beginTransaction(); //更新实人认证信息 $body_log = auth()->user()->updateApproveInfo('body', 1); //更新实名认证信息 $name_log = auth()->user()->updateApproveInfo('name', 1); //同步生日 auth()->user()->cardBirthdayToProfile('app'); //是否已赠送 $log = auth()->user()->coinLogs()->where(['type'=>'RECSYSTEM', 'remark'=>'真人认证'])->first(); if (empty($log)) { //赠送福币 +10 不可提现 auth()->user()->updateCoinInfo('add', 10, 'other'); auth()->user()->addCoinLog("RECSYSTEM", 0, 10, '真人认证'); $message = "您的真人认证已通过后台审核,系统赠送您10个福币作为奖励,请注意查收!"; $body = ['msg'=>$message]; $im_service = new IMService(env('IM_APP_KEY'), env('IM_APP_SECRET')); $result = $im_service->sendMsg(1, 0,auth()->id(),$type=0,$body); if (empty($result)) throw new \Exception("修改认证信息失败", 1); } //分享人福币赠送 if ($body_log->from_user_id) { $share_user = User::find($body_log->from_user_id); if ($share_user) { $log = $share_user->coinLogs()->where(['type'=>'RECSYSTEM', 'type_id'=>$body_log->user_id, 'remark'=>'邀请好友认证'])->first(); if (empty($log)) { $share_user->addCoinLog("RECSYSTEM", $body_log->user_id, 50, '邀请好友认证'); } } } \DB::commit(); auth()->user()->updateCacheUser('is_approved'); auth()->user()->updateCacheUser('is_real_approved'); $data = [ 'type' => 0, 'message' => '认证检测通过' ]; return $this->success('ok', $data); } catch (\Exception $e) { \DB::rollback(); $this->getError($e); $data = [ 'type' => 1, 'message' => '认证失败,系统繁忙,稍后重试' ]; return $this->success('认证失败', $data); } } public function getBioassay($result) { try { $msg = ''; switch ($result->result->reasonType) { case 2: $msg = '姓名身份证号一致,人脸比对非同一人'; break; case 3: $msg = '姓名身份证号不一致'; break; case 4: $msg = '活体不通过'; break; case 5: $msg = '活体检测超时或出现异常'; break; case 6: $msg = '查无此身份证'; break; case 7: $msg = '库中无此身份证照片'; break; case 8: $msg = '人像照过大'; break; case 9: $msg = '公安接口超时或出现异常'; break; } return $msg; } catch (\Exception $e) { $this->getError($e); return false; } } public function checkRealApproveParam() { try { $name = request()->input('name'); $card_num = request()->input('card_num'); $token = request()->input('token'); if (empty($name) || empty($card_num) || empty($token)) throw new \Exception("缺少参数", 1); //判断用户信息已经被其他账号认证 $user = User::where('card_num', $card_num)->where('is_real_approved', 1)->where('id', '<>', auth()->id())->first(); if ($user) { $mobile = substr_replace($user->mobile, '****', 3,4); return ['code'=>1, 'msg'=>"认证失败,身份信息已在其他账号".PHP_EOL.$mobile."认证", 'error_type'=>0]; } //是否满十八岁 $result = \CommonUtilsService::checkCardBirhday($card_num); if ($result['error'] != 2) return ['code'=>1, 'msg'=>'认证失败,身份证号码格式错误', 'error_type'=>1]; $age = \CommonUtilsService::getAge($result['tdate']); if ($age < 18) return ['code'=>1, 'msg'=>'认证失败,身份信息小于18岁', 'error_type'=>1]; return true; } catch (\Exception $e) { $this->getError($e); return false; } } public function checkRealApproveParamV2() { try { $name = request()->input('name'); $card_num = request()->input('card_num'); $token = request()->input('token'); if (empty($name) || empty($card_num) || empty($token)) throw new \Exception("缺少参数", 1); //判断用户信息已经被其他账号认证 $user = User::where('card_num', (string)$card_num)->where('is_real_approved', 1)->where('id', '<>', auth()->id())->first(); if (!empty($user)) { $mobile = substr_replace($user->mobile, '****', 3,4); $data = [ 'type' => 1, 'message' => "认证失败,身份信息已在其他账号".PHP_EOL.$mobile."认证" ]; return $data; } //是否满十八岁 $result = \CommonUtilsService::checkCardBirhday($card_num); if ($result['error'] != 2){ $data = [ 'type' => 1, 'message' => "认证失败,身份证号码格式错误" ]; return $data; } $age = \CommonUtilsService::getAge($result['tdate']); if ($age < 18){ $data = [ 'type' => 1, 'message' => "认证失败,身份信息小于18岁" ]; return $data; } return true; } catch (\Exception $e) { $this->getError($e); return false; } } /** * 人工认证 */ public function manualApprove(Request $request) { try { $user = auth()->user(); if ($user->is_real_approved == 1) return $this->failure("已通过真人认证"); $photos = $request->input('photos', []); if (empty(count($photos)) && is_array($photos)) { return $this->failure('请上传手持身份证照!'); } $user->identification_photos = json_encode($photos); $user->save(); //创建审核记录 // $h = ApproveHistory::where('user_id', $user->id)->where('type', 'name')->where('status', 0)->first(); // if ($h && $user->identification_photos) { // return $this->failure('认证信息正在审核中,请等待后台人员审核'); // } ApproveHistory::updateOrCreate(['user_id' => $user->id,'type'=>'body'],['status' => 0,'ways' => 1,'from_user_id'=>$request->from_user_id,]); ApproveHistory::updateOrCreate(['user_id' => $user->id,'type'=>'name'],['status' => 0,'ways' => 1,'from_user_id'=>$request->from_user_id,]); return $this->success('ok'); } catch (\Exception $e) { $this->getError($e); return $this->failure('人工认证申请失败,请稍后再试'); } } /** * 认证信息 * @param Request $request [description] * @return [type] [description] */ public function approveInfo(Request $request) { try { $user_id = auth()->id(); $user = User::where('id', $user_id)->select('id', 'name', 'card_num', 'is_approved', 'is_real_approved', 'approve_time','is_educate_approved', 'identification_photos')->first(); if ($user->card_num && mb_strlen($user->card_num)) { $user->card_num = substr_replace($user->card_num, '********',-8,8); }else{ $user->card_num = '********'; } $user->card = $user->card_num; if ($user->name && mb_strlen($user->name)) { $str = mb_substr($user->name, 1 ); $re = ''; for ($i=0; $i name = str_replace($str, $re, $user->name); } //理由 $user->reason = ''; $result = ApproveHistory::where('user_id', $user_id)->where('type', 'body')->where('ways', 1)->where('status',-1)->first(); if($result) $user->reason = '失败原因:'.$result->reason; $user->approve_date = null; //客服电话 $user->service_mobile = '18922809346'; //身份证照片 if(!empty($user->identification_photos)){ $user->identification_photos = json_decode($user->identification_photos); } return $this->success('ok', $user); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取认证信息失败,请稍后再试'); } } /** * 我的活动 * @param Request $request [description] * @return [type] [description] */ public function userActivities(Request $request) { try { $user_id = auth()->id(); $activities = DB::table('activities as a') ->rightJoin('activity_members as m', 'a.id', '=','m.activity_id') ->where('m.user_id', $user_id) ->select('a.id as id','theme', 'poster', 'city', 'address','dist', 'start_time', 'end_time', 'class_id', 'fee','user_id', 'm.created_at',DB::raw("'fulllin_activity' as activity_type"),'is_online'); $merchant_user = MerchantUser::where('user_id',$user_id)->first(); if(!$merchant_user) { $activities = $activities->orderBy('created_at','desc')->paginate(); } else { $type_ids = DB::table('tourist_orders') ->join('community_activities','tourist_orders.type_id','community_activities.id') ->where('community_activities.class','one')->whereIn('channel',[1,2]) ->where('tourist_orders.type','community')->where('account_id',$merchant_user->id)->whereIn('pay_status',[1,4]) ->pluck('tourist_orders.type_id'); //,'tourist_orders.type','type_id',DB::raw("'business_order' as order_type"),'tourist_orders.price','tourist_orders.pay_type','pay_status','trade_no','desc as goods','tourist_orders.created_at' $community_activities = DB::table('community_activities')->whereIn('id',$type_ids) ->select('id','title as theme',"pic as poster", "address as city",'address', DB::raw("'' as dist"),'start_time','end_time', DB::raw("'0' as class_id"), DB::raw("'price' as fee"),'anchor_id as user_id','created_at',DB::raw("'business_activity' as activity_type"),'location as is_online'); $query = $activities->union($community_activities); $sql = $query->toSql(); $activities = DB::table(DB::raw("($sql) as a"))->mergeBindings($query) ->orderBy('created_at','desc')->paginate(); } foreach ($activities as $activity) { $activity->class_name = ActivityClass::where('id', $activity->class_id)->value('title'); if($activity->activity_type == 'business_activity' && $activity->is_online == 0) { $activity->city = '线上活动'; } } return $this->success('ok', $activities); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取我的活动列表失败,请稍后再试'); } } /** * 我的订单列表 * @param Request $request [description] * @return [type] [description] */ public function userOrders(Request $request) { try { $user_id = auth()->id(); $type = $request->input('type', 'rank'); $orders = Order::where('user_id', $user_id)->where('pay_status', 'PAID'); if ($type === 'rank') { $orders = $orders->whereIn('type', ['rank', 'single_service']); $orders = $orders->select('id', 'goods', 'price', 'created_at', 'type','trade_no')->orderBy('id', 'desc')->paginate(); }elseif ($type === 'activity') { $merchant_user = MerchantUser::where('user_id',$user_id)->first(); if(!$merchant_user) { $orders = DB::table('orders')->where('user_id', $user_id)->where('type', 'activity')->where('pay_status', 'PAID') ->select('id','type','type_id',DB::raw("'fulllin_order' as order_type"),'price','pay_type','pay_status','trade_no','goods','created_at') ->orderBy('created_at','desc')->paginate(); } else { $business_order = DB::table('tourist_orders') ->join('community_activities','tourist_orders.type_id','community_activities.id') ->where('community_activities.class','one')->whereIn('tourist_orders.channel',[1,2]) ->where('tourist_orders.type','community')->where('account_id',$merchant_user->id)->whereIn('pay_status',[1,4]) ->select('tourist_orders.id','tourist_orders.type','type_id',DB::raw("'business_order' as order_type"),'tourist_orders.price','tourist_orders.pay_type','pay_status','trade_no','desc as goods','tourist_orders.created_at'); $order = DB::table('orders')->where('user_id', $user_id)->where('type', 'activity')->where('pay_status', 'PAID') ->select('id','type','type_id',DB::raw("'fulllin_order' as order_type"),'price','pay_type','pay_status','trade_no','goods','created_at'); $query = $business_order->union($order); $sql = $query->toSql(); $orders = DB::table(DB::raw("($sql) as a"))->mergeBindings($query) ->orderBy('created_at','desc')->paginate(); } //$orders = $orders->where('type', 'activity'); } return $this->success('ok', $orders); } catch (\Exception $e) { $this->getError($e); return $this->failure('服务器休息中,请稍后再试'); } } /** * 订单详情 * @param Request $request [description] * @param Order $order [description] * @return [type] [description] */ public function userOrder(Request $request, $order_id) { try { $order = Order::where('id', $order_id)->where('user_id', auth()->id())->select('id', 'goods', 'price', 'type', 'pay_status', 'pay_type', 'created_at', 'trade_no')->first(); if (empty($order)) { $merchant_user = MerchantUser::where('user_id',auth()->id())->first(); $order = TouristOrder::where('id', $order_id)->where('account_id',$merchant_user->id)->first(); if(empty($order)) throw new \Exception("订单不存在", 1); $show_pay_type = '免费'; if($order['pay_type'] == 'wechat'){ $show_pay_type = '微信支付'; }else if($order['pay_type'] == 'alipay'){ $show_pay_type = '支付宝支付'; }else if($order['pay_type'] == 'ios'){ $show_pay_type = 'IOS支付'; }else if($order['pay_type'] == 'h5'){ $show_pay_type = 'H5支付'; } $order['pay_type'] = $show_pay_type; $activity = CommunityActivity::find($order->type_id); $order['type'] = $activity->class == 'one' ? '活动订单':'社群订单';//$this->orderCon->orderTypeCodeSwitchChinese($order['type']); if($order->type=='course') $order->goods = $order->course->title??$order->goods; $order->used_coin = 0 ; //花费福币50个,抵扣金额5.00元 if($order->remark){ $start = strpos($order->remark,'币')/3+1; $end = strpos($order->remark,'个')-8; $len = $end- $start; if($start&&$end&&$len){ $order->used_coin = intval(mb_substr($order->remark, $start,$len,'utf-8')); } } return $this->success('ok', $order); } //是否使用福气 $order->use_score = $order->pay_order?($order->pay_order->score?'使用':'未使用'):'未使用'; //会员类型 switch ($order->type) { case 'rank': $order->type = '会员开通'; break; case 'single_service': $order->type = '会员套餐'; break; case 'activity': $order->type = '活动报名'; break; case 'course': $order->type = '购买课程'; break; default: $order->type = '其他'; break; } //支付类型 switch ($order->pay_type) { case 'alipay': $order->pay_type = '支付宝支付'; break; case 'wechat': $order->pay_type = '微信支付'; break; case 'free': $order->pay_type = '免费'; break; default: $order->pay_type = '其他'; break; } //支付状态 switch ($order->pay_status) { case 'UNPAID': $order->pay_status = '未支付'; break; case 'PAID': $order->pay_status = '支付成功'; break; case 'CANCLE': $order->pay_status = '已取消'; break; default: $order->pay_status = '其他'; break; } return $this->success('ok', $order); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取订单详情失败,请稍后再试'); } } /** * 我的社群动态 * @param Request $request [description] * @return [type] [description] */ public function userCommunityMoment(Request $request) { try { $user = auth()->user(); $moments = \DB::table('community_moments as m')->leftJoin('users as u', 'm.user_id', '=', 'u.id')->where('m.user_id',auth()->id())->whereNull('m.deleted_at')->leftJoin('community_topics as t', 't.id', '=', 'm.topic_id')->leftJoin('communities as c', 'c.id', '=', 'm.community_id')->select('m.id as id', 'nickname', 'photo', 'app_avatar', 'm.user_id as user_id', 't.name as topic_name', 'm.content as content', 'photos', 'c.title as community_title', 'm.created_at as created_at')->paginate(); foreach ($moments as $moment) { $moment->photos = json_decode($moment->photos); $community_moment = CommunityMoment::find($moment->id); $moment->photo = $moment->app_avatar?:$moment->photo; //是否点赞 $moment->is_llker = $community_moment->isLikedBy($user)?1:0;; //是否收藏 $moment->is_favorite = $user->hasFavorited($community_moment)?1:0; //点赞数 $moment->momentLikerCount = $community_moment->likers()->get()->count()?:0; //收藏数 $moment->favoriteCount = $community_moment->favoriters()->get()->count()?:0; //评论数 $moment->momentCommentCount = $community_moment->totalCommentsCount(); } return $this->success('ok', $moments); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取我发布的动态列表失败,请稍后再试'); } } /** * 我的分享 * @param Request $request [description] * @return [type] [description] */ public function userInvites(Request $request) { $user = auth()->user(); $user_id = $user->id; $openid = $user->wechat?$user->wechat->openid:null; $users = User::where(function($sql) use($user_id, $openid){ $sql = $sql->where('from_user_id', $user_id); if ($openid) { $sql->orWhere('from_openid', $openid); } })/*->where('type', 'single')*/->where('hidden_profile', 'NONE'); $keyword = $request->input('keyword'); if ($keyword) { $users = $users->where('nickname', 'like', '%'.$keyword.'%'); } $users = $users->select('id', 'nickname', 'photo', 'app_avatar', 'sex', 'created_at')->paginate(); foreach ($users as $user) { $user->age = \CommonUtilsService::getAge($user->profileCourtship?$user->profileCourtship->birthday:null); unset($user->profileCourtship); $user->isSuperRank = $user->isSuperRank(); $user->photo = $user->userAvatar(); } return $this->success('ok', $users); } /** * 隐身 * @param Request $request [description] * @return [type] [description] */ public function hidden(Request $request) { try { $user = auth()->user(); $is_super_rank = $user->isSuperRank($user->id); if(!$is_super_rank){ return $this->failure('非会员不能设置隐身'); } if ($user->hidden) { $user->hidden = 0; }else { $user->hidden = 1; } $hidden = $user->hidden; $user->save(); return $this->success('ok', compact('hidden')); } catch (\Exception $e) { $this->getError($e); return $this->failure('隐身设置失败,请稍后再试'); } } /** * 关闭资料 * @param Request $request [description] * @return [type] [description] */ public function hiddenProfile(Request $request) { try { $user = auth()->user(); if ($user->hidden_profile == 'NONE') { $user->hidden_profile = 'ALLSEX'; // 增加备注记录 CloseProfileHistory::updateOrCreate(['user_id'=>$user->id],['operator'=>0,'reason'=>$request->input('content')]); $type = 'ALLSEX'; $else_type = 'NONE'; }elseif ($user->hidden_profile == 'ALLSEX') { $user->hidden_profile = 'NONE'; $type = 'NONE'; $else_type = 'ALLSEX'; } $user->save(); AreaUser::where('user_id', $user->id)->delete(); //增加修改记录 $old_data['hidden_profile'] = $else_type; $new_data['hidden_profile'] = $type; ProfileChangeHistory::create([ 'user_id'=>$user->id, 'owner_user_id'=>$user->id, 'new_content'=>json_encode($new_data), 'old_content'=>json_encode($old_data) ]); return $this->success('ok'); } catch (\Exception $e) { $this->getError($e); return $this->failure('关闭资料失败,请稍候再试'); } } public function hiddenProfileOptions(Request $request) { $options = [ ['key'=>'key1', 'value'=>'已经在福恋找到伴侣了'], ['key'=>'key2', 'value'=>'通过其他方式找到伴侣了'], ['key'=>'key3', 'value'=>'被婚托,酒托骚扰'], ['key'=>'key4', 'value'=>'人少,看来看去就那么几个'], ['key'=>'key5', 'value'=>'想要找的意中人太少'], ['key'=>'key6', 'value'=>'其他原因'], ]; return $this->success('ok', compact('options')); } /** * 黑名单列表 * @param Request $request [description] * @return [type] [description] */ public function blacklist(Request $request) { try { $user = auth()->user(); $keyword = $request->input('keyword'); $list = $user->linkBlackList()->with('otherUser:id,nickname,photo,app_avatar,sex,is_approved'); if ($keyword) { $list = $list->whereHas('otherUser', function($sql) use($keyword){ $sql->where('nickname', 'like', '%'.$keyword.'%'); }); } $list = $list->paginate(); foreach ($list as $li) { if (empty($li->otherUser)) continue; $li->nickname = $li->otherUser->nickname; $li->photo = $li->otherUser->photo; $li->id = $li->otherUser->id; $li->is_approved = $li->otherUser->is_approved; $li->isSuperRank = $li->otherUser->isSuperRank()?1:0; $li->sex = $li->otherUser->sex; $profile_courtship = ProfileCourtship::where('user_id', $li->other_user_id)->select('user_id', 'birthday', 'city', 'stature')->first(); if ($profile_courtship) { $li->age = \CommonUtilsService::getAge($profile_courtship->birthday); }else{ $li->age = 0; } $li->profile_courtship = $profile_courtship; $li->photo = $li->otherUser->userAvatar(); unset($li->otherUser, $li->user_id, $li->other_user_id, $li->updated_at, $li->deleted_at); } return $this->success('ok', $list); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取黑名单信息失败,请稍后再试'); } } /** * 删除黑名单 * @param Request $request [description] * @param [type] $id [description] * @return [type] [description] */ public function deleteBlackList(Request $request, $id) { try { LinkingBlacklist::where('user_id', auth()->id())->where('other_user_id', $id)->delete(); return $this->success('ok'); } catch (\Exception $e) { $this->getError($e); return $this->failure('删除黑名单失败,请稍后再试'); } } /** * 我的收藏 * @param Request $request [description] * @return [type] [description] */ public function favorites(Request $request) { try { $user = auth()->user(); $type = $request->input('type', 'activity'); if ($type == 'activity') { $favorites = $user->favorites(Activity::class)->where('is_hidden', 0)->paginate(); foreach ($favorites as $favorite) { $favorite->class_name = $favorite->class?$favorite->class->title:null; unset($favorite->pivot, $favorite->host, $favorite->detail, $favorite->detail_path, $favorite->detail_pic, $favorite->content, $favorite->is_top, $favorite->show_member_num,$favorite->province, $favorite->address, $favorite->qrcode, $favorite->vote_qrcode, $favorite->sign_in_qrcode,$favorite->location_latitude, $favorite->location_longitude, $favorite->is_deadline, $favorite->is_cancel, $favorite->click_num, $favorite->is_hidden, $favorite->created_at, $favorite->deleted_at, $favorite->updated_at, $favorite->class_id, $favorite->class); } }elseif ($type == 'community_moment') { $favorites = $user->favorites(CommunityMoment::class)->where('is_show', 1)->paginate(); foreach ($favorites as $favorite) { $favorite->user_id = $user->id; $favorite->nickname = $user->nickname; $favorite->photo = $user->app_avatar?:$user->photo; $favorite->photos = json_decode($favorite->photos); $favorite->topic_name = $favorite->topic()->value("name"); $favorite->community_title = $favorite->community()->value('title'); //是否点赞 $favorite->is_llker = $favorite->isLikedBy($user)?1:0; //是否收藏 $favorite->is_favorite = $user->hasFavorited($favorite)?1:0; //点赞数 $favorite->momentLikerCount = $favorite->likers()->get()->count()?:0; //收藏数 $favorite->favoriteCount = $favorite->favoriters()->get()->count()?:0; //评论数 $favorite->momentCommentCount = $favorite->totalCommentsCount(); unset($favorite->pivot, $favorite->community_id, $favorite->is_show, $favorite->created_at, $favorite->deleted_at, $favorite->updated_at, $favorite->topic_id); } } return $this->success('ok', $favorites); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取收藏列表失败,请稍后再试'); } } /** * 会员列表 * @param Request $request [description] * @return [type] [description] */ public function ranks(Request $request) { try { $rank = Rank::with(['subRanks' => function($sql){ if (auth()->user()->mobile != '15872844805'){ $sql->where('is_show_app', 1); } }])->where('name', '超级会员')->select('id','name', 'explain', 'app_feature')->first(); if (!empty($rank)) { $rank->explain = json_decode($rank->explain); $rank->feature = json_decode($rank->app_feature); foreach ($rank->subRanks as $subRank) { if (request()->header('client-os') == "IOS") { $subRank->discount_price = $subRank->ios_price; $subRank->pic = $subRank->ios_pic; } } $rank->carousel_feature = [ 'https://images.ufutx.com/202012/03/877232dcc84c1ddda634dc04ec2339f0.png', 'https://images.ufutx.com/202012/03/e23467fd983a0c4d547fdfcc586602d6.png', 'https://images.ufutx.com/202012/03/da26cb16c92a1f9daefaa5d591914ae2.png', 'https://images.ufutx.com/202012/03/46913f2ffd527ff5bdf7f03c89b8e5e3.png', 'https://images.ufutx.com/202012/03/b3ab31f133268f34e721fe1d3d414b90.png', 'https://images.ufutx.com/202012/03/b1b3c5be08182155260d21d01ec2d94d.png' ]; unset($rank->app_feature); } $user = auth()->user(); $dateline = RankHistory::where('user_id', $user->id)->where('rank_id', $user->rank_id)->orderBy('id', 'desc')->value('deadline'); return $this->success('ok', compact('dateline', 'rank')); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取超级会员信息失败,请稍后再试'); } } /** * 会员套餐 * @param Request $request [description] * @return [type] [description] */ public function singleServices(Request $request) { try { $user = auth()->user(); $dateline = RankHistory::where('user_id', $user->id)->where('rank_id', $user->rank_id)->orderBy('id', 'desc')->value('deadline'); $services = SingleService::with('rank:id,feature')->where('is_show_app',1)->orderBy('price', 'asc')->select('id', 'title', 'price', 'discount_price', 'pic','rank_id', 'discount_desc', 'feature','discount_desc_type')->get(); foreach ($services as $service) { if ($service->discount_desc_type == 'json') { $service->feature = json_decode($service->feature); $service->discount_desc = json_decode($service->discount_desc); unset($service->rank); }else{ $service->feature = json_decode($service->feature); $service->discount_desc = explode('****',$service->discount_desc); // $service->discount_desc = json_decode($service->discount_desc); unset($service->rank); } } return $this->success('ok', compact('dateline', 'services')); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取会员套餐信息失败,请稍后再试'); } } /** * [buyRank description] * @param Request $request [description] * @return [type] [description] */ public function buyRank(Request $request) { \DB::beginTransaction(); try { $user = auth()->user(); //购买的会员等级 $sub_rank_id = $request->input('sub_rank_id'); if ($sub_rank_id < 10) { return $this->failure('支付失败,请稍后再试'); } $sub_rank = SubRank::find($sub_rank_id); if (empty($sub_rank)) { return $this->failure('没有该会员'); } if ($sub_rank->ios_price <= 1 && $user->mobile != '15872844805'){ return $this->failure('测试会员暂不支持购买'); } $use_score = $request->input('use_score', 0); if ($use_score) return $this->failure('暂支持使用福气支付'); $rank = Rank::find($sub_rank->rank_id); $goods = '购买'.$sub_rank->month.'个月'.$rank->name.'VIP'; $os = $request->header('client-os'); if ($os == 'IOS') { $price = $sub_rank->ios_price; }else{ $price = $sub_rank->discount_price; } $order_pay = $this->orderCon->makeAppOrder($request, $price, 'rank', $sub_rank_id, $goods, $linkmen=[], $detail='购买会员'); if (empty($order_pay)) { throw new \Exception("订单生成失败", 1); } \DB::commit(); return $this->success('ok', $order_pay); } catch (\Exception $e) { \DB::rollBack(); $this->getError($e); return $this->failure('支付失败,请稍后再试'); } } /** * 购买会员套餐 * @param Request $request [description] * @return [type] [description] */ public function buySingleService(Request $request, SingleService $single_service) { \DB::beginTransaction(); try { $user = auth()->user(); $goods = $single_service->title; $order_pay = $this->orderCon->makeAppOrder($request, $single_service->discount_price, 'single_service', $single_service->id, $goods, $linkmen=[], $detail='购买会员套餐'); if (empty($order_pay)) { throw new \Exception("订单生成失败", 1); } \DB::commit(); //购买成功 发送短信通知 // $m = Message::create([ // 'phone' => $user->mobile, // 'message' => '', // 'confirmed' => 1, // 'code' => '购买服务套餐', // 'ip' => request() ? request()->ip() : '127.0.0.1', // ]); // $message = '您已成功购买【'.$single_service->title.'】服务套餐,福恋工作人员将尽快联系您为您服务,请耐心等待。如有问题,请联系:18922809346'; // $m->message = $message; // $m->save(); // Messenger::sendSMS($user->mobile, $message); return $this->success('ok', $order_pay); } catch (\Exception $e) { \DB::rollBack(); $this->getError($e); return $this->failure('支付失败,请稍后再试'); } } /** * 签到提醒 */ public function sign_notice(Request $request) { $user = auth()->user(); $UserInfo = UserInfo::where('user_id',$user->id)->first(); if($UserInfo){ $UserInfo->sign_notice = $UserInfo->sign_notice?0:1; }else{ $UserInfo = new userInfo; $UserInfo->user_id = $user->id; $UserInfo->sign_notice = 1; } $UserInfo->save(); return $this->success('ok',$UserInfo); } /** * 问题反馈 * @param Request $request [description] * @return [type] [description] */ public function feedback(Request $request) { try { $this->userCon->feedback($request, auth()->id()); return $this->success('ok'); } catch (\Exception $e) { $this->getError($e); return $this->failure('问题反馈失败,请稍后再试'); } } /** * 用户信息 * @param Request $request [description] * @return [type] [description] */ public function userInfo(Request $request, $user_id=0) { try { $login_user = null; if ($user_id == 0){ $login_user = $this->getMyUserinfo(); if(!$login_user){ return $this->fail('请登录后访问',2); } $user_id = $login_user->id; } //是否在黑名单 $is_black = LinkingBlacklist::where('user_id', $user_id)->where('other_user_id', $login_user->id)->count(); if($is_black) return $this->failure('您已被对方拉入黑名单'); $profile_data = User::APPCOMPLETEINFO; $user = User::where('id', $user_id)->select('id','name', 'nickname', 'photo', 'app_avatar','industry','industry_sub', 'type', 'is_approved','hidden_profile','is_real_approved', 'is_educate_approved','approve_time', 'hidden', 'sex', 'belief', 'is_photo_audited','rank_id','mobile')->first(); // $user->is_approved = $user->is_approved == 0?((ApproveHistory::where('user_id', $user_id)->where('type', 'name')->where('status', 0)->exists())?2:0):1; $user->photo = $user->userAvatar(); $profile = $user->profileCourtship()->select('user_id', 'birthday','state','province','city','resident_province','resident_city','stature','weight','degree','graduate_school','educate_photo','introduction','ideal_mate','interest_label','income','wechat_id', 'belief','edc_type','chsi_code', 'sex','mate_conditon')->first(); if (!empty($profile)) { $profile->interest_label = json_decode($profile->interest_label)?:[]; $user->age = \CommonUtilsService::getAge($profile->birthday); $profile->mate_conditon = json_decode($profile->mate_conditon,true); //不正常身高年龄 if($profile->stature < 100 && $profile->stature){ $profile->stature = $user->sex == 1 ? 170 : 160; } if($profile->weight < 30 && $profile->weight){ $profile->weight = $user->sex == 1 ? 170 : 160; } } $user->profile_photo = $user->profilePhoto()->select('id','photo')->limit(9)->orderBy('id', 'desc')->get(); $user->profile = $profile; //今日打招呼次数 $time = date('Y-m-d 00:00:00'); $user->request_num = LinkingRequest::where('user_linking_id',$user->id)->whereBetween('created_at', [$time,now()])->count(); //今日购买打招呼次数 $user->pay_num = CoinLog::where('user_id',$user->id)->where('type','friend_request')->where('type_id',0)->whereBetween('created_at', [$time,now()])->count(); //剩余次数 $user->surplus_num = 3+$user->pay_num-$user->request_num; if($user->surplus_num<0)$user->surplus_num=0; $result = $this->userCon->profileIntegrity($user->profileCourtship,$user,explode(',', $profile_data)); $bili = $result['count'] / $result['total_count']; $user->info_pro = number_format($bili,2); //临时会员 $user->temp_status = $this->userTempStatus($user, $bili); //超级会员 $user->isSuperRank = $user->isSuperRank(); $user->is_hidden = $user->hidden; $user->fans_count = $user->followers()->count()?:0; //访客数 $user->preview_count = $user->userPreview()->whereNotNull('preview_time')->whereHas('previewUser', function($sql){ })->count()?:0; //动态 $user->moment_count = $user->moments()->where('is_audited', 1)->where('is_show', 1)->count(); $moments = Moment::where(function($query){ $query->where('photos', '!=', '[]')->orWhereNotNull('aliyun_video_id'); })->where('user_id', $user->id)->orderBy('id', 'desc')->limit(6)->get(); $new_photos = []; // return $this->success('ok', $moments); foreach ($moments as $moment){ if(!empty($moment->photos)){ $moment_photo = json_decode($moment->photos); if(!empty($moment_photo)){ foreach ($moment_photo as $value){ array_push($new_photos, $value); } } } if(!empty($moment->aliyun_video_id)){ $rd_moment_key = Moment::cacheMoemntKey($moment->id); if (Cache::has($rd_moment_key)) { $rd_moment = Cache::get($rd_moment_key); if(!empty($rd_moment->cover_url)){ $new_photos[] = $rd_moment->cover_url; } }else{ $result = \AliyunService::getPlayInfo($moment->aliyun_video_id); if(!empty($result['VideoBase']['CoverURL'])){ $new_photos[] = $result['VideoBase']['CoverURL']; } } } } $user->moment = array_slice($new_photos, 0, 4); //礼物榜 $user->gift_icons = $user->giftIcons(); //是否完善 $result = UserService::isCompleteProfileV4($user, 'app'); $user->self_info_level = 0; if ($result) { $user->self_info_level = $result['level']; } //注册基本资料 $user->complete_base_info = $user->isCompletedProfile("app_register_info"); //其他基本资料 $user->complete_other_info = $user->isCompletedProfile('app_other_info'); //头像是否审核 $user->is_photo_audited; //学历是否认证 $user->is_educate_approved; //是否设置破冰问题 $user->has_friend_question = $user->userFriendQuestion?1:0; $user->friend_question = ($user->has_friend_question)?$user->friendQuestion():''; //是否动态管理员 $user->is_moment_admin = RoleUser::where('role_id', 21)->where('user_id', $user->id)->count() ? 1 : 0; unset($user->profileCourtship, $user->userFriendQuestion); //分享链接 $user->share_url = config('app.url').'/h5/#/downloadApp?from_user_id='.$user->id.'&app_url=user_info'; //是否申请过专区推荐 $is_audited = AreaUser::where('user_id', $user->id)->where('area_id', 1)->orderBy('id', 'desc')->value('is_audited'); $user->has_apply_area = $is_audited === null ? 2: $is_audited; $banned_state = 0; $blacklist = SystemBlacklist::where('user_id', $user->id)->first(); if ($blacklist) { $date = date('Y-m-d H:i:s'); if($blacklist->end_time >= $date && $blacklist->start_time <= $date){ $banned_state = 1; } } //是否是客服 $user->service_man = UserInfo::where('user_id',$user_id)->where('is_service_client',1)->exists()?1:0; $user->banned_state = $banned_state; $user->frozen_state = $this->userCon->getUserFrozenState($user->id); $user->profile->belief = $profile->belief ? : $user->belief; return $this->success('ok', $user); } catch (\Exception $e) { $this->getError($e); return $this->failure('用户信息获取失败,请稍后再试'); } } //解冻用户 public function unfrozenUsers(Request $request,$user_id){ try { $info = WrongInfoHistories::where('user_id',$user_id)->where('type','frozen')->first(); $user = User::find($user_id); $user->can_be_found = 1; $info->delete(); $user->save(); return $this->success('ok'); } catch (\Exception $e) { $this->getError($e); return $this->failure('解锁失败,请稍后再试'); } } //增加认证 public function addApprove(Request $request) { $mobile = $request->mobile; $reason = $request->reason??'人工认证'; $type = $request->type; //is_real_approved,is_approved if($type=='is_real_approved'){ $Approve = 'body'; }elseif($type=='is_approved'){ $Approve = 'name'; } $user_id = User::where('mobile', $mobile)->value('id'); User::where('id', $user_id)->update([$type=>1]); ApproveHistory::where('type',$Approve)->updateOrCreate(['user_id'=>$user_id],[ 'type'=>$Approve, 'ways'=>1, 'status'=>1, 'reason'=>$reason, ]); return $this->success('ok'); } /** * 基本资料 * @param Request $request [description] * @return [type] [description] */ public function baseUserInfo(Request $request) { try { $user = auth()->user(); if (empty($profile)) { $this->userCon->updateAppProfile($request, $user); } //是否完善 $result = UserService::isCompleteProfileV4($user, 'app'); $self_info_level = 0; if ($result) { $self_info_level = $result['level']; } $profile = $user->profileCourtship ? $user->profileCourtship : $user->profileMarriage; //今日打招呼次数 $time = date('Y-m-d 00:00:00'); // $request_num = LinkingRequest::where('user_id',$user->id)->whereBetween('created_at', [$time,now()])->count(); $user_info = [ 'app_avatar' => $user->app_avatar, 'nickname' => $user->nickname, 'sex'=> $user->sex, 'type'=>$user->type, 'birthday'=>$profile->birthday, 'stature'=>$profile->stature, 'province' => $profile->province, 'city' => $profile->city, 'belief' => $profile->belief, // 'request_num'=>$request_num, 'introduction'=> $profile->introduction, 'self_info_level'=>$self_info_level ]; return $this->success('ok', $user_info); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取基本信息失败,请稍后再试'); } } public function userTempStatus($user, $bili) { //未完善资料 if ($bili < 1) { $status = 0; }else{ //判断是否领取临时会员 $result = TempMember::where('user_id', $user->id)->first(); if (empty($result)) { $status = 0; }elseif ($result->status == 0) { $status = 1; }elseif ($result->status) { $status = 2; } } return $status; } /** * 修改资料 * @param Request $request [description] * @return [type] [description] */ public function updateUserInfo(Request $request) { try { $user = auth()->user(); $result = $this->userCon->updateAppProfile($request, $user); $introductionVerifyResultCode__key = $this->userCon->KYE_IVRC . $user->id; $ideal_mateVerifyResultCode_key = $this->userCon->KYE_IMVRC . $user->id; $interest_hobbyVerifyResultCode_key = $this->userCon->KYE_IMPHO . $user->id; Cache::forget($introductionVerifyResultCode__key); Cache::forget($ideal_mateVerifyResultCode_key); Cache::forget($interest_hobbyVerifyResultCode_key); if (is_array($result) && $result['code']) return $this->failure($result['msg']); return $this->success('ok'); } catch (\Exception $e) { \DB::rollBack(); $this->getError($e); return $this->failure('修改资料失败,请重试'); } } /** * 兴趣爱好标签 * @param Request $request [description] * @return [type] [description] */ public function interestLabels(Request $request) { //系统 $system_labels = InterestLabel::whereNull('user_id')->select('name')->get(); //自定义 $custom_labels = InterestLabel::where('user_id', auth()->id())->select('id','name')->orderBy('id', 'desc')->get(); //选中得 $select_labels = json_decode(auth()->user()->profileCourtship->interest_label); $select_labels = $select_labels ?$select_labels:array(); return $this->success('ok', compact('system_labels', 'custom_labels','select_labels')); } /** * 创建标签 * @param Request $request [description] * @return [type] [description] */ public function storeInterestLabel(Request $request) { try { $name = $request->input('name'); if (empty($name) || mb_strlen($name) > 8) { return $this->failure('请按照规则创建标签'); } $result = InterestLabel::where(function($sql){ $sql->where('user_id',auth()->id())->orWhereNull('user_id'); })->where('name', $name)->exists(); if ($result) { return $this->failure('标签已经存在'); } $label = InterestLabel::firstOrCreate([ 'user_id'=>auth()->id(), 'name'=>$name ]); return $this->success('ok', $label); } catch (\Exception $e) { $this->getError($e); return $this->failure('创建标签失败,请稍后再试'); } } /** * 删除标签 * @param Request $request [description] * @param InterestLabel $interest_label [description] * @return [type] [description] */ public function deleteInterestLabel(Request $request, InterestLabel $interest_label) { try { if ($interest_label->user_id != auth()->id()) { throw new \Exception("请选择自己自定义标签", 1); } $interest_label->delete(); return $this->success('ok'); } catch (\Exception $e) { $this->getError($e); return $this->failure('删除标签失败,请稍后再试'); } } /** * 修改用户兴趣爱好 * @param Request $request [description] * @return [type] [description] */ public function updateUserInterestLabel(Request $request) { try { \DB::beginTransaction(); $user_id = auth()->id(); $labels = $request->input('labels', []); sort($labels); if (empty(count($labels))) { return $this->failure('请选择标签'); } $old_data = ProfileCourtship::where('user_id', $user_id)->value('interest_label'); $profile = ProfileCourtship::where('user_id', auth()->id())->first(); if (json_encode($labels) != $profile->interest_label) { $profile->interest_label = json_encode($labels); $profile->save(); } //修改完善分数 $user = auth()->user(); $result = $this->userCon->profileIntegrity($profile, $user, explode(',', User::APPCOMPLETEINFO)); $user->info_complete_score = $result['count']; $user->save(); //更新缓存 $user->cacheUser(); //获取临时会员 $bili = $user->type == 'sinlge'?$result['count'] / $result['total_count']:0; // if ($bili == 1) { // $user->getTempRank(); // } $new_data = ProfileCourtship::where('user_id', $user_id)->value('interest_label'); ProfileChangeHistory::create([ 'user_id'=>auth()->id(), 'owner_user_id'=>$user_id, 'new_content'=>json_encode(['interest_label' => json_decode($new_data)]), 'old_content'=>json_encode(['interest_label' => json_decode($old_data)]) ]); \DB::commit(); return $this->success('ok'); } catch (\Exception $e) { \DB::rollback(); $this->getError($e); return $this->failure('更新用户兴趣爱好失败,请稍后再试'); } } /** * 获取临时会员 * @return [type] [description] */ public function getTempRank() { $result = auth()->user()->getTempRank(); if (is_array($result) && $result['code']) return $this->failure($result['msg']); return $this->success('ok'); } public function userInfoOptions(Request $request) { //年龄 $sex_arr = [ ['key'=>'男','value'=>1], ['key'=>'女','value'=>2] ]; //身高 $stature_arr = []; for ($i=139; $i < 202; $i++) { if ($i === 139) { $key = $i.'cm以下'; $arr = ['key'=> $key, 'value'=>$i]; $stature_arr[] = $arr; continue; }elseif ($i === 201) { $key = $i.'cm以上'; $arr = ['key'=> $key, 'value'=>$i]; $stature_arr[] = $arr; continue; } $arr =['key'=> $i.'cm', 'value'=>$i]; $stature_arr[] = $arr; } $weight_arr = []; for ($i=39; $i < 132; $i++) { if ($i === 39) { $key = $i.'kg以下'; $arr = ['key'=> $key, 'value'=>$i]; $weight_arr[] = $arr; continue; }elseif ($i === 131) { $key = $i.'kg以上'; $arr = ['key'=> $key, 'value'=>$i]; $weight_arr[] = $arr; continue; } $arr =['key'=> $i.'kg', 'value'=>$i]; $weight_arr[] = $arr; } $address_arr = Address::where('name', '<>', '不限')->orderBy('codeId', 'asc')->select('codeId', 'name', 'parentId')->get()->toArray(); $address_arr = $this->addressSort($address_arr); $state_arr = ['从未结婚','离异','丧偶', '已婚']; $degree_arr = ['小学','初中', '高中','中专','大专','本科','硕士','博士','其他']; $income_arr = ['5~10w', '10~15w', '15~20w', '15~30w', '30~50w', '50~100w', '100~500w', '500w以上']; $belief_arr = ['基督教','佛教', '伊斯兰教','其他']; //行业 list($__sort, $__detail) = $this->industryJsonData(); $industry_arr =[]; foreach($__sort as $key => $item){ $industry_arr[] =[ 'title' => $item, 'items' => $__detail[$key] ]; } //单身状态 $type_arr = [ ['key'=>'single', 'value'=>'目前单身'], ['key'=>'marriage', 'value'=>'已有对象'] ]; return $this->success('ok', compact('sex_arr', 'stature_arr', 'weight_arr','address_arr', 'state_arr', 'degree_arr', 'income_arr', 'belief_arr', 'industry_arr', 'type_arr')); } /** * 修改头像 * @param Request $request [description] * @return [type] [description] */ public function updateUserPhoto(Request $request) { try { $user = auth()->user(); $photo = $request->input('photo'); if (empty($photo)) { return $this->failure('请上传头像'); } //内容安全-图片 $result = \CommonUtilsService::imageContentCecurity([$photo]); if ($result && $result['result']) { return $this->failure('图片'.$result['result'].',请换一张照片'); } //人脸识别 $result = $this->userCon->faceDelectBaiDu($photo); $res = $this->userCon->checkPhotoResult($result); if (empty($res)) throw new \Exception("图片分析失败", 1); if (is_array($res) && $res['code']) { //增加错误头像记录 ErrorPhoto::firstOrCreate(['user_id'=>$user->id, 'photo'=>$photo, 'error_msg'=>$res['msg']]); if ($res['msg'] == "pic not has face") return $this->failure('图片上传失败,可能未获取到人脸,请换一张照片'); if ($res['msg'] == "image download fail") return $this->failure('图片解析失败,请重新上传'); return $this->failure($res['msg']); } if ($request->input('photo') && $request->photo != $user->photo) { // $face_list = $result->result->face_list; $user->photo = $request->photo; // $user->face_score = $face_list[0]->beauty; $user->circle_avatar = null; $user->my_share = null; $user->home_share = null; $user->is_audited = 0; $user->is_photo_audited = 0; // $user->is_photo_audited = 1; $user->app_avatar = $request->photo; $user->save(); // //创建百度图片信息 // $this->userCon->addImageInfo($user, $user->photo, $face_list[0]); // $user->updateCacheUser('photo'); // $user->updateCacheUser('app_avatar'); // //对比照片相似度 // FaceMatchJob::dispatch($user->id)->onQueue('love'); // //同步IM头像 // $birthday = $user->profileCourtship?$user->profileCourtship->birthday:null; // $im_service = new IMService(env('IM_APP_KEY'), env('IM_APP_SECRET')); // $result = $im_service->updateUinfo($user->id,$user->nickname, $user->app_avatar,$sign='',$user->email,$birthday,$user->mobile,$user->sex); } return $this->success('OK', $result); } catch (\Exception $e) { $this->getError($e); return $this->failure('头像上传失败,请稍后再试'); } } /** * 上传生活照 * @param Request $request [description] * @return [type] [description] */ public function uploadProfilePhoto(Request $request) { $user_id = auth()->id(); $photos = $request->input('photos', []); $result = \CommonUtilsService::imageContentCecurity($photos); if ($result && isset($result['result']) && $result['result']) { return $this->failure('图片'.$result['result'].',请换一张照片'); } $data = []; $old_data['profile_photos'] = ProfilePhoto::where('user_id', $user_id)->pluck('photo'); if (count($photos)) { foreach ($photos as $photo) { if (empty($photo)) { continue; } $photo_obj = new ProfilePhoto(); $photo_obj->photo = $photo; $photo_obj->user_id = auth()->id(); $photo_obj->dateline = date('Y-m-d'); $photo_obj->save(); $data[] = $photo_obj; } } $new_data['profile_photos'] = ProfilePhoto::where('user_id', $user_id)->pluck('photo'); ProfileChangeHistory::create([ 'user_id'=>auth()->id(), 'owner_user_id'=>$user_id, 'new_content'=>json_encode($new_data), 'old_content'=>json_encode($old_data) ]); return $this->success('ok', $data); } public function deleteProfilePhoto(Request $request, $profile_photo) { $result = ProfilePhoto::where('id', $profile_photo)->delete(); return $this->success('ok'); } public function getUserAsset($user) { $asset = $user->userAsset(); if (empty($asset)) { $asset = $user->asset()->create([ 'viewer_id'=>0, 'cash'=>0, 'share_cash'=>0, 'blocked_cash'=>0, ]); } return $asset; } /** * 钱包 * @param Request $request [description] * @return [type] [description] */ public function userAsset(Request $request) { try { $user = auth()->user(); $asset = $this->getUserAsset($user); $asset->sum_cash = bcadd($asset->cash, $asset->share_cash, 2); $asset->total_cash = $asset->sum_cash * 100; //是否绑定微信 $asset->bind_wechat = $user->wechat?($user->wechat->app_openid?1:0):0; //轮播 $logs = AssetLog::where('type', 3)->with('user:id,nickname,photo', 'viewer:id,nickname,avatar')->select('id', 'viewer_id', 'user_id', 'num', 'type', 'is_hooked','created_at')->orderBy('id', 'desc')->limit(5)->get(); foreach ($logs as $log) { if (empty($log->user)) { $viewer = $log->viewer; $nickname = $viewer?$viewer->nickname:null; $photo = $viewer?$viewer->avatar:null; }else{ $nickname = $log->user->nickname; $photo = $log->user->photo; } $log->nickname = $nickname; $log->photo = $photo; unset($log->user, $log->viewer); } return $this->success('ok', compact('asset', 'logs')); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取钱包信息失败,请稍后再试'); } } public function userCoin(Request $request) { try { $user = auth()->user(); $coin = $user->coinInfo(); // if ($coin->is_safe != 1) { // $text = '近期,我公司发现部分用户利用平台系统漏洞,通过注册虚假用户获取平台发放的新用户注册奖励,以谋取不当利益,严重违反相关法律规定。针对此种行为,我公司已经向有权机关进行报案,并积极配合有权机关打击此类违法行为。特此声明!'; // return $this->fail($text,9); // } //获取用户总福币 $total_coin = CoinLog::where('user_id',$user->id) ->where('type','RECSYSTEM') ->where(function ($query){ $query/*->where('remark', 'like','%邀请好友%')*/ ->Where('remark', 'like','%城市群主服务%') ->orWhere('remark', 'like','%奖励%') ->orWhere('remark', 'like','%刘勇芳%') ->orWhere('remark', 'like','%钉钉%') ->orWhere("remark", 'like', '%促进消费%'); })->sum('coin'); //已提现 $cash = CoinWithdrawLog::where('user_id',$user->id)->where(function ($query){ $query->where('remark', 'like','%邀请好友%'); })->wherein('status',[0,1])->wherein('is_hooked',[0,1])->sum('value'); //获取活动获得的总福币 $coin->can_remain_amount = $total_coin - $cash??0; $coin->remain_amount = $coin->remain_amount+$coin->amount_from_other; //福币转换费率 $coin->rate = 0; //福币和人民币比例 $coin->rmb_rate = 10; //最低额度 $coin->minimum_amout=100; $coin->is_real_approved=$user->is_real_approved; //提现记录 $logs = CoinWithdrawLog::with('user:id,nickname,app_avatar,photo')->where('status',1)->where('is_hooked',1)->limit(5)->orderBy('id', 'desc')->get(); return $this->success('ok', compact('coin', 'logs')); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取钱包信息失败,请稍后再试'); } } /** * 福币绑定支付宝账号 * @param Request $request [description] * @return [type] [description] */ public function coinBindAlipayAccount(Request $request) { try { $alipay_account = $request->input('alipay_account'); $alipay_real_name = $request->input('alipay_real_name'); if (empty($alipay_account) || empty($alipay_real_name)) return $this->failure('绑定账号失败'); $user = auth()->user(); $coin = $user->coinInfo(); $coin->alipay_account = $alipay_account; $coin->alipay_real_name = $alipay_real_name; $coin->save(); return $this->success('ok'); } catch (\Exception $e) { $this->getError($e); return $this->failure('绑定账号失败,请稍后再试'); } } /** * 收益记录 * @param Request $request [description] * @return [type] [description] */ public function assetIncomeLogs(Request $request) { try { $user = auth()->user(); $asset = $user->userAsset(); $logs = AssetLog::where('user_id',$asset->user_id)->whereIn('type', [1,2,4,5])->where('is_hooked',1)->select('id', 'user_id', 'num', 'type', 'is_hooked', 'created_at')->orderBy('id', 'desc')->paginate(); foreach ($logs as $log) { switch ($log->type) { case 1: $log->type_name = '收益-打赏'; break; case 2: $log->type_name = '收益-分享新用户'; break; case 4: $log->type_name = '收益-分享用户消费'; case 5: $log->type_name = '收益-后台赠送'; break; default: $log->type_name = '收益'; break; } $log->num = $log->num * 100; } return $this->success('ok', $logs); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取收益记录失败,请稍后再试'); } } /** * 提现记录 */ public function assetWithdrawLogs(Request $request) { try { $user = auth()->user(); $asset = $user->userAsset(); $logs = AssetLog::where('user_id',$asset->user_id)->where('type', 3)->select('id', 'user_id', 'num', 'type', 'is_hooked','created_at')->orderBy('id', 'desc')->paginate(); foreach ($logs as $log) { $log->type_name = $log->is_hooked?'微信-提现成功':'微信-提现审核中'; $log->num = $log->num * 100; } return $this->success('ok', $logs); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取收益提现失败,请稍后再试'); } } /** * 消费记录 */ public function assetConsumeLogs(Request $request) { try { $user = auth()->user(); $asset = $user->userAsset(); $logs = AssetLog::where('user_id',$asset->user_id)->where('type', 6)->select('id', 'user_id', 'num', 'type', 'is_hooked', 'created_at')->orderBy('id', 'desc')->paginate(); foreach ($logs as $log) { $log->type_name = '消费'; $log->num = $log->num * 100; } return $this->success('ok', $logs); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取收益提现失败,请稍后再试'); } } /** * 提现 * @param Request $request [description] * @return [type] [description] */ public function assetWithdraw(Request $request) { try { $score = $request->input('score'); if (empty($score)) { return $this->failure('提现失败,没有金额'); } //钱包 $user = auth()->user(); $asset = $this->getUserAsset($user); //剩余金额 $remain_cash = bcadd($asset->cash, $asset->share_cash, 2); //判断金额是否足够 if ($remain_cash < $score) { return $this->failure('提现失败,余额不足'); } \DB::beginTransaction(); //修改余额 if ($asset->share_cash >= $score) { $asset->decrement('share_cash', $score); }else{ $cash = bcsub($score, $asset->share_cash); $asset->decrement('share_cash', $asset->share_cash); $asset->decrement('cash', $cash); } //创建提现记录 $log = new AssetLog; $log->user_id = $user->id; $log->num = $score; $log->real_num = $score; $log->type = 3; $log->is_hooked = 0; $log->account = 1; $log->score = bcadd($asset->cash, $asset->share_cash, 2); $log->save(); \DB::commit(); return $this->success('ok'); } catch (\Exception $e) { \DB::rollback(); $this->getError($e); return $this->failure('提现失败,请稍后再试'); } } /** * 给用户写上标签 */ public function post_user_label(Request $request) { $user = auth()->user(); $other_user_id = $request->other_user_id; $labels = $request['labels']; $labels = json_encode($labels); $start = Carbon::today(); $end = Carbon::tomorrow(); //当前用户是否打开夸夸我功能 $info = UserInfo::where('user_id',$request->user_id)->first(); if($info && $info->label_notice == 0) return $this->failure('对方已关闭夸夸功能'); $exist = LabelHistory::where('user_id',$user->id)->where('labeled_user_id',$other_user_id)->wherebetween('created_at',[$start,$end])->count(); if($exist) return $this->failure('今天你已经夸过Ta了,明天再夸吧~'); if($labels){ $LabelHistory = new LabelHistory; $LabelHistory->user_id = $user->id; $LabelHistory->labeled_user_id = $other_user_id; $LabelHistory->content = $labels; $LabelHistory->save(); } $url = $this->getMiniUrl($request->other_user_id); $url = \CommonUtilsService::shortUrl($url); $message = '刚刚有人夸夸了你,点击链接(' . $url['url'] . ')快来看看吧'; $send_user = User::where('id', $other_user_id)->first(); //关闭资料 介绍人不发 if($send_user->hidden_profile != 'ALLSEX' || $send_user->type != 'single'){ //是否系统设置不通知 $log = UserMessageSetting::where(['user_id'=>$send_user->id, 'type'=>'label'])->first(); if (empty($log)) $this->sentMessage($send_user->mobile,$message); } $key = 'get_user_label_app'.$other_user_id; cache::forget($key); $LabelHistory->content = implode(' ',$request['labels']); $LabelHistory->avatar = $LabelHistory->user->avatar; unset($LabelHistory->user); return $this->success('评价成功~',$LabelHistory); } // 获取用户标签 public function get_user_label(Request $request) { $key = 'get_user_label_app'.$request->user_id; //当前用户是否打开夸夸我功能 $info = UserInfo::where('user_id',$request->user_id)->first(); if($info && $info->label_notice == 0) return $this->success('ok',[]); $result = cache::remember($key,5,function () use($request){ $user_id = $request->user_id; $result = LabelHistory::select('user_id','labeled_user_id','content')->where('labeled_user_id', $user_id)->orderBy('id','desc')->get(); foreach ($result as $key => $value) { $value->avatar = $value->user->avatar??null; $content = json_decode($value->content,true); $value->content = implode(' ',$content); unset($value->user); } return $result; }); return $this->success('ok',$result); } // 获取小程序地址 public function getMiniUrl($id) { $app = \WechatService::app()->access_token; $token = $app->getToken(true); $data = []; $data['jump_wxa']['path'] = '/pages/home/information'; $data['jump_wxa']['query'] = 'id=' . $id; $data = json_encode($data); $wechaturl = 'https://api.weixin.qq.com/wxa/generatescheme?access_token=' . $token['access_token']; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($curl, CURLOPT_URL, $wechaturl); // curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); if (1 == strpos("$" . $wechaturl, "https://")) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); $result = curl_exec($curl); $result = json_decode($result, true); $jump_url = $result['openlink']; $path = env('APP_URL').'/h5/#/jump_url?url='.$jump_url; return $path; } /** * 记录手机信息 * @return [type] [description] */ public function storeDeviceInfo(Request $request) { try { $device_idfa = $request->header('device-idfa'); $client_os = $request->header('client-os'); $device_imei = $request->header('device-imei'); $device_model = $request->header("device-model"); if (empty($device_idfa) && empty($client_os) && empty($device_imei) && empty($device_model)) return $this->failure('参数错误'); $back_log = null; $quick_back_log = null; if ($client_os == 'IOS') { $info = DeviceInfo::where(['device_idfa'=> $device_idfa])->first(); //查询积分墙 $back_log = BackActivation::where('idfa', $device_idfa)->first(); $imeiMD5 = null; }else{ $info = DeviceInfo::where(['device_imei'=> $device_imei])->first(); //查询快手 $imeiMD5 = md5($device_imei); $quick_back_log = QuickBackActivation::where('imei', $imeiMD5)->first(); } if (empty($info)) { //生成记录 $info = new DeviceInfo; $info->device_idfa = $device_idfa; $info->client_os = $client_os; $info->device_imei = $device_imei; $info->device_model = $device_model; $info->imei_md5 = $imeiMD5; $info->save(); AdBackActivation::dispatch($back_log)->onQueue('love'); $arr = [ 'event_type'=>1, 'quick_back_log'=>$quick_back_log, ]; AdQuickBackActivation::dispatch($arr)->onQueue('love'); } return $this->success('ok', $info); } catch (\Exception $e) { $this->getError($e); return $this->failure('存储手机信息失败'); } } public function userMoments(Request $request) { try { $result = $this->momentService->userMoments(auth()->id()); if (empty($result)) throw new \Exception("用户动态列表失败", 1); return $this->success('ok', $result); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取用户动态列表失败,请稍后再试'); } } /** * 提现福币 * @param Request $request [description] * @return [type] [description] */ public function userWithdrawCoin(Request $request) { try { //检查 return $this->failure('提现福币失败,请稍后再试'); $result = $this->userCon->checkWithdrawCoin(); if (empty($result)) throw new \Exception("检查提现失败", 1); if (is_array($result) && $result['code']) return $this->failure($result['msg']); //生成提现记录,等待后台审核 $result = $this->userCon->withdrawCoin(); if (empty($result)) throw new \Exception("提现失败", 1); return $this->success('ok', '提现申请成功'); } catch (\Exception $e) { $this->getError($e); return $this->failure('提现福币失败,请稍后再试'); } } /** * 福币提现记录 * @param Request $request [description] * @return [type] [description] */ public function userWithdrawCoinLogs(Request $request) { try { $user = auth()->user(); $logs = $user->coinWithdrawLogs()->orderBy('id', 'desc')->paginate(); return $this->success('ok', $logs); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取福币提现记录失败,请稍后再试'); } } public function userAlipayBindInfo(Request $request) { $result = \AlipayService::infoStr(); return $this->success('ok', $result); } //双通道分享记录 public function shareTrace(Request $request) { $data['resume_page'] = $request->input('resume_page'); $data['params_data'] = $request->input('params_data'); $data['channel'] = $request->input('channel'); $data['device_model'] = $request->header('device-model'); $data['device_idfa'] = $request->header('device-idfa'); $data['device_imei'] = $request->header('unique-device'); $client = $request->header('client-os'); if ($data['params_data']) { if ($client == "IOS") { $trace = ShareTrace::where('device_idfa', $data['device_idfa'])->first(); }else{ $trace = ShareTrace::where('device_imei', $data['device_imei'])->first(); } if ($trace) { $trace->update($data); }else{ ShareTrace::create($data); } } return $this->success('ok'); } /** * 设置破冰问题 * @param Request $request [description] */ public function setFriendQuestion(Request $request) { try { $user = auth()->user(); if (empty($request->input('question_id')) && empty($request->input('content'))) return $this->failure('请选择破冰内容'); if (empty($request->input('question_id')) && $request->input('content')) { //检测问题合规 $result = \CommonUtilsService::textContentCecurity([$request->input('content')]); if ($result && $result['result']) { return $this->failure('您填写的内容【'.$result['context']."】:".$result['result'].",请重新输入"); } //创建问题 $question = $user->friendQuestions()->firstOrCreate([ 'title'=>$request->input('content'), ]); $request->question_id = $question->id; } //查看破冰问题 $user_question = $user->userFriendQuestion; //设置破冰问题 if (empty($user_question)) { $user_question = $user->userFriendQuestion()->create([ 'friend_question_id'=>$request->question_id, ]); }else{ $user->userFriendQuestion()->update([ 'friend_question_id'=>$request->question_id, ]); $user_question->friend_question_id = (int)$request->question_id; } return $this->success('ok', $user_question); } catch (\Exception $e) { $this->getError($e); return $this->failure('设置破冰问题失败,请稍后再试'); } } /** * 破冰问题列表(随机三个) * @param Request $request [description] * @return [type] [description] */ public function friendQuestions(Request $request) { try { $ids = FriendQuestion::where(function($sql){ $sql->whereNull('user_id')->orWhere('user_id', auth()->id()); })->pluck('id')->toArray(); $result = array_rand($ids,3); $sub_ids = []; foreach ($result as $re) { $sub_ids[] = $ids[$re]; } $questions = FriendQuestion::whereIn('id', $sub_ids)->orderBy('id', 'desc')->get(); return $this->success('ok', $questions); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取破冰问题失败,请稍后再试'); } } /** * 增加打招呼次数 */ public function sayHello(Request $request) { $user = auth()->user(); try { $result = $user->updateCoinInfo('sub', 10); if (empty($result)) return $this->failure('修改福币信息失败~'); CoinLog::create([ 'user_id' => $user->id, 'type' => 'friend_request', 'type_id' => 0, 'coin' => 10, 'remark' => '购买打招呼次数', 'is_hooked' => 1 ]); \DB::commit(); return $this->success('购买成功'); } catch (\Exception $e) { \DB::rollback(); $this->getError($e); return $this->failure('购买失败。'); } } /** * 绑定微信 * @param Request $request [description] * @return [type] [description] */ public function bindWechat(Request $request) { try { //传入微信信息 $openid = $request->input('openid'); if (empty($openid)) throw new \Exception('绑定微信失败,缺少微信信息', 1); //判断该微信号是否已绑定其他账号 $log = Wechat::where('app_openid', $openid)->where('user_id', '<>', auth()->id())->first(); if ($log) return $this->failure('绑定失败,该微信号已经绑定其他福恋账号'); $unionid = $request->input('unionid'); //获取wechat信息 $wechat = auth()->user()->wechat; if (empty($wechat)) { $wechat = auth()->user()->wechat()->create([ 'app_openid'=>$openid, 'unionid'=>request()->input('unionid'), 'avatar'=>$request->input('headimgurl'), 'nickname'=>$request->input('nickname'), 'country'=>$request->input('country'), 'province'=>$request->input('province'), 'city'=>$request->input('city'), 'gender'=>$request->input('sex'), ]); }else{ $wechat->app_openid = $openid; $wechat->unionid = $wechat->unionid?:$unionid; $wechat->save(); } return $this->success('ok'); } catch (\Exception $e) { $this->getError($e); return $this->failure('绑定微信失败,请稍后再试'); } } /** * 网易用户信息 * @return [type] [description] */ public function wyUserInfo(Request $request) { $accids = $request->accids; $im = new IMService(); $result = $im->getUinfos($accids); return $this->success($result); } //分区用户 public function areaUser(Request $request){ $area_id = $request->input('area_id', 1); $area_users = AreaUser::with(['user:id,circle_avatar,photo,app_avatar,nickname,name,sex', 'user.profileCourtship'])->whereHas('user', function ($query){ $query->where('type', 'single')->where('hidden_profile', 'NONE'); })->where('area_id', $area_id)->where('is_audited', 1)->where('is_show', 1)->orderBy('sort', 'asc')->orderBy('id','desc'); $area_users = $area_users->paginate(16); foreach ($area_users as $area_user){ $area_user->user->birthday = ''; if($area_user->user->profileCourtship){ $area_user->user->birthday = $area_user->user->profileCourtship->birthday; $area_user->user->age = !empty($area_user->user->profileCourtship->birthday) ? \CommonUtilsService::getAge($area_user->user->profileCourtship->birthday) : 0; $area_user->user->city = !empty($area_user->user->profileCourtship->city) ? $area_user->user->profileCourtship->city: ''; } unset($area_user->user->profileCourtship); } return $this->success('ok', $area_users); } //处理群主无法加好友问题 public function group(Request $request) { //获取所有群的群主 $ids = Team::pluck('owner','id'); $num = 0; foreach ($ids as $key => $value) { UserTeam::where('user_id',$value)->where('team_id',$key)->update(['type'=>1]); $num++; } return '已经更新了'.$num.'个群组'; } /** 我的访问 */ public function myPreviewHistroies(Request $request){ $user = auth()->user(); $user_id = $user->id; $linkings = UserPreview:: with('otherpreviewUser:id,nickname,photo,app_avatar,age,is_approved,sex,rank_id', 'otherpreviewUser.profileCourtship:user_id,birthday,city,stature') ->whereHas('otherpreviewUser', function($sql) { $sql->where('hidden_profile', 'NONE');/*->where('type', 'single')*/; })->whereNotNull('preview_time') ->where('preview_user_id', $user_id) ->orderBY('preview_time', 'desc') ->paginate(); foreach ($linkings as $linking) { $linking->nickname = $linking->otherpreviewUser->nickname; $linking->id = $linking->otherpreviewUser->id; $linking->is_approved = $linking->otherpreviewUser->is_approved; $linking->isSuperRank = $linking->otherpreviewUser->isSuperRank()?1:0; $linking->sex = $linking->otherpreviewUser->sex; $profile_courtship = $linking->otherpreviewUser->profileCourtship; $linking->age = \CommonUtilsService::getAge($profile_courtship?$profile_courtship->birthday:null); $linking->profile_courtship = $profile_courtship; $linking->photo = $linking->otherpreviewUser->userAvatar(); unset($linking->otherpreviewUser,$linking->user_id,$linking->previewe_user_id,$linking->status); } UserPreview::whereHas('user', function($sql){ $sql->where('hidden_profile', '<>', 'ALLSEX'); })->where('user_id', $user->id)->where('preview_user_id', '<>',$user->id)->where('status', 0)->update(['status'=>1]); return $this->success('ok', $linkings); } //用户注销账号 public function closeAccount(Request $request){ $user_id = auth()->user()->id; //账号 try { $user = auth()->user(); $user->hidden_profile = 'ALLSEX'; $user->save(); // UserHiddenHistory::where('user_id', $user->id)->firstOrCreate(['user_id']) return $this->success('ok'); DB::beginTransaction(); ApproveHistory::where('user_id',$user_id)->delete(); User::where('id', $user_id)->update([ 'name'=>null, 'nickname'=>null, 'age'=>0, 'card_num'=>null, 'app_avatar'=>null, 'circle_avatar'=>null, 'is_approved'=>0, 'is_real_approved'=>0, 'is_educate_approved'=>0, 'industry'=>null, 'industry_sub'=>null, 'deleted_at'=>date('Y-m-d H:i:s') ]); //微信信息 Wechat::where('user_id', $user_id)->delete(); ProfileCourtship::where('user_id', $user_id)->delete(); ProfileMarriage::where('user_id', $user_id)->delete(); //群组 UserGroup::where('user_id', $user_id)->delete(); //提示 Notice::where('user_id', $user_id)->orWhere('send_user_id', $user_id)->delete(); //联系人 MessageLinkman::where('user_id', $user_id)->orWhere('other_user_id', $user_id)->delete(); //聊天记录 ChatMessage::where('user_id', $user_id)->orWhere('other_user_id', $user_id)->delete(); //匹配 MatchingRate::where('user_id', $user_id)->orWhere('other_user_id', $user_id)->delete(); //加好友请求 LinkingRequest::where('user_id', $user_id)->orWhere('user_linking_id', $user_id)->delete(); //访问记录 UserPreviewHistory::where('user_id', $user_id)->orWhere('user_id', $user_id)->forceDelete(); //h5用户 Viewer::where('user_id', $user_id)->update(['user_id'=>0,'mobile'=>'']); $linkings = Linking::where('user_id', $user_id)->orWhere('user_linking_id', $user_id)->get(); foreach ($linkings as $linking) { if ($linking->user_id != $user_id) { User::where('id', $linking->user_id)->decrement('friend_count', 1); }else{ User::where('id', $linking->user_linking_id)->decrement('friend_count', 1); } } //好友 Linking::where('user_id', $user_id)->orWhere('user_linking_id', $user_id)->delete(); ProfilePhoto::where('user_id',$user_id)->delete(); //加好友问题回答 FriendQuestionAnswer::where('user_id' ,$user_id)->delete(); //微信通知id FormId::where('user_id', $user_id)->delete(); //关注 Followable::where('user_id', $user_id)->orWhere('Followable_id', $user_id)->delete(); //操作记录 Dynamic::where('user_id', $user_id)->delete(); //举报记录 ComplaintHistory::where('user_id', $user_id)->orWhere('complaint_id', $user_id)->delete(); //文章记录 ArticleHistory::where('user_id', $user_id)->delete(); //红娘 Matchmaker::where('user_id', $user_id)->delete(); //盟爱 GoodMatch::where('user_id', $user_id)->delete(); //客戶 MatchmakerClient::where('client_user_id', $user_id)->delete(); //浏览记录 UserPreview::where('user_id', $user_id)->delete(); //征婚推荐 CommunityStar::where('user_id', $user_id)->delete(); //增加操作记录 AdminLog::create([ 'path'=> $request->path(), 'method'=>$request->method(), 'user_id'=>$user_id, 'param'=>json_encode(['用户注销账号']), 'model'=>null, 'model_id'=>0, ]); DB::commit(); return $this->success('delete ok'); } catch (\Exception $e) { DB::rollBack(); $this->getError($e); return $this->failure('服务器休息,请稍后再试'); } } }