197 lines
8.8 KiB
PHP
197 lines
8.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use App\Models\ProfileCourtship;
|
|
use App\Models\ProfileMarriage;
|
|
use App\Models\TempMember;
|
|
use App\Models\UserPreviewHistory;
|
|
use App\Models\RankHistory;
|
|
use App\Models\User;
|
|
use App\Utils\Http;
|
|
use App\Models\LinkingRequest;
|
|
use App\Services\UserService;
|
|
use App\Repositories\Eloquent\SmsRepository as Sms;
|
|
|
|
class CheckProfile
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \Closure $next
|
|
* @return mixed
|
|
*/
|
|
public function handle($request, Closure $next)
|
|
{
|
|
// if ($request->input('versions') == config('app.versions')) {
|
|
return $next($request);
|
|
// }
|
|
$user = auth()->user();
|
|
if (empty($user)) {
|
|
$user = $this->authCheck();
|
|
}
|
|
if ($user) {
|
|
if ($request->id && $user->id == $request->id && $request->route()->getName() === 'other_user_infor') {
|
|
return $next($request);
|
|
}
|
|
if ($request->route()->getName() === 'other_user_infor') {
|
|
if (is_numeric($request->id)) {
|
|
$other_user = User::where('id', $request->id)->firstOrFail();
|
|
if ($other_user->hidden_profile == 'ALLSEX') {
|
|
return $this->fail('profile', 3, 'pages/map/mapList', '查找Ta人', '该用户暂时关闭了资料!');
|
|
}
|
|
}else{
|
|
return $this->fail('profile', 3, 'pages/map/mapList', '查找其Ta', '用户不存在');
|
|
}
|
|
|
|
}
|
|
if ($user->type == 'single') {
|
|
$profile = ProfileCourtship::where('user_id', $user->id)->first();
|
|
//资料未完成
|
|
if (empty($profile)) {
|
|
// return $this->fail('profile', 3);
|
|
return $this->fail('profile', 3, 'pages/users/unmarriV2', '完善资料', '你的个人资料未完善,需要完善一下哦!');
|
|
}
|
|
//临时会员
|
|
$temp_member = TempMember::where('user_id', $user->id)->first();
|
|
if (empty($temp_member)) {
|
|
$is_temp_member = 0;
|
|
}else{
|
|
if ($temp_member->status == 1) {
|
|
$is_temp_member = 0;
|
|
}else{
|
|
$is_temp_member = 1;
|
|
}
|
|
}
|
|
|
|
if ($is_temp_member == 0) {//不是临时会员
|
|
//是否完成资料
|
|
$result = UserService::isCompleteProfile($user->id);
|
|
if (!$result) {
|
|
// return $this->fail('profile', 3);
|
|
return $this->fail('profile', 3, 'pages/users/unmarriV2', '完善资料', '你的个人资料未完善,需要完善一下哦!');
|
|
}
|
|
//没有认证
|
|
if (!$user->is_approved && $request->route()->getName() === 'other_user_infor') {
|
|
// return $this->fail('approve', 3);
|
|
return $this->fail('approve', 3, 'pages/users/realName', '前去认证', '你还未实名认证,先去认证一下吧!');
|
|
}
|
|
}else{//会员
|
|
// 浏览人数
|
|
$preview_count = UserService::previewCount($user->id, date('Y-m-d 0:0:0'), date('Y-m-d H:i:s'));
|
|
if ($preview_count >= 7 ) {
|
|
return $this->fail('当天查看次数受限,请升级更高会员,扩充权限', 3, 'pages/users/upgradeVIP', '升级VIP', '您的会员权限不能查看其它省份用户,请升级更高会员,扩充权限');
|
|
}
|
|
// 是否完善资料
|
|
$result = UserService::isCompleteProfile($user->id);
|
|
if (!$result) {
|
|
// return $this->fail('profile', $user);
|
|
return $this->fail('profile', 3, 'pages/users/unmarriV2', '完善资料', '你的个人资料未完善,需要完善一下哦!');
|
|
}
|
|
}
|
|
$history = RankHistory::where('user_id', $user->id)->where('rank_id', 1)->orderBy('deadline', 'desc')->first();
|
|
//会员查看对应地区的用户
|
|
//市级->全省
|
|
//黄金->全国
|
|
//钻石->全球
|
|
if ($request->route()->getName() === 'other_user_infor') {//add_friend_request other_user_infor
|
|
|
|
//会员权限
|
|
$other_user = User::where('id', $request->id)->first();
|
|
if (!empty($other_user)) {
|
|
$result = $user->isFriend($other_user);
|
|
if ($result) {
|
|
return $next($request);
|
|
}
|
|
if ($other_user->type === 'single') {
|
|
$other_profile = ProfileCourtship::where('user_id', $other_user->id)->first();
|
|
if (!empty($other_profile)) {
|
|
if ($user->rank_id == 1 && !empty($history) && !empty($history->deadline) && !empty($other_profile->city)) {
|
|
if (/*$province != $profile->province &&*/ $profile->province != $other_profile->province && $profile->province != $other_profile->city && $profile->city != $other_profile->province) {
|
|
return $this->fail('您的会员权限不能查看其它省份用户,请升级更高会员,扩充权限', 3, 'pages/users/upgradeVIP', '升级VIP', '您的会员权限不能查看其它省份用户,请升级更高会员,扩充权限');
|
|
|
|
}
|
|
}elseif ($user->rank_id === 2 && !empty($other_profile->country)) {
|
|
// if ($profile->country != $other_profile->country && $country != $profile->country) {
|
|
// return $this->fail('您的会员权限不能查看其它国家的信息,请充值更高会员,扩充权限。', $user,1);
|
|
// }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}else{
|
|
$profile = ProfileMarriage::where('user_id', $user->id)->first();
|
|
//未完善资料
|
|
$result = UserService::isCompleteProfile($user->id);
|
|
if (empty($profile) || !$result) {
|
|
// return $this->fail('profile', $user);
|
|
return $this->fail('profile', 3, 'pages/users/intro', '完善资料', '你的个人资料未完善,需要完善一下哦!');
|
|
}
|
|
//每天申请添加七位好友
|
|
if ($request->route()->getName() === 'add_friend_request') {
|
|
$start_time = date('Y-m-d', time());
|
|
$count = LinkingRequest::where('user_linking_id', $user->id)->where('created_at', '>', $start_time)->count();
|
|
if ($count >= 7) {
|
|
return $this->fail('profile', 3, 'pages/home/information?id='.$request->id, '返回', '介绍人每天只允许申请添加七位好友!');
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
|
|
/**
|
|
* 经纬度转地址
|
|
* @param [type] $local_latitude [description]
|
|
* @param [type] $local_longitude [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public function getAddress($local_latitude, $local_longitude)
|
|
{
|
|
$localtion = $local_latitude.','.$local_longitude;
|
|
$location = '23.13955,113.2829';
|
|
$url = "https://apis.map.qq.com/ws/geocoder/v1/?location=".$localtion.'&key=P43BZ-QSDCP-BMHDP-V3BTR-3EL45-KOFJL';
|
|
$result = json_decode(Http::http($url, [], 'GET'), true);
|
|
if ($result['status'] == 0) {
|
|
$address_component = $result['result']['address_component'];
|
|
}else{
|
|
return false;
|
|
}
|
|
|
|
return $address_component;
|
|
}
|
|
|
|
public function fail($msg, $code = 5, $path='', $operate='', $notice='')
|
|
{
|
|
$result = [
|
|
'code'=> $code,
|
|
'path'=> $path,
|
|
'message'=> $msg,
|
|
'operate'=> $operate,
|
|
'notice'=> $notice,
|
|
];
|
|
|
|
return Response()->json($result);
|
|
|
|
}
|
|
|
|
public function authCheck()
|
|
{
|
|
$guards = config('auth.guards');
|
|
$result = false;
|
|
foreach($guards as $key=>$guard){
|
|
if(\Auth::guard($key)->check()){
|
|
$result = \Auth::guard($key)->user();
|
|
continue;
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
}
|