46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Middleware;
|
||
|
|
|
||
|
|
use Closure;
|
||
|
|
use Route;
|
||
|
|
use App\Models\User;
|
||
|
|
class LimitUnApprove
|
||
|
|
{
|
||
|
|
|
||
|
|
public function handle($request, Closure $next)
|
||
|
|
{
|
||
|
|
$user = auth()->user();
|
||
|
|
if (empty($user)) return $next($request);
|
||
|
|
//是否认证
|
||
|
|
if ($user->is_real_approved == 1) return $next($request);
|
||
|
|
//当前路由
|
||
|
|
$route_name = Route::currentRouteName();
|
||
|
|
//关注
|
||
|
|
if ($route_name == 'follow_user') {
|
||
|
|
$other_user = User::find($request->id);
|
||
|
|
//是否是取消关注
|
||
|
|
if ($user->isFollowing($other_user)) return $next($request);
|
||
|
|
//关注次数
|
||
|
|
if ($user->followings->count() >= 5) return $this->failure("关注人数上限,请先完善真人认证");
|
||
|
|
}
|
||
|
|
// //发消息
|
||
|
|
// if ($route_name == 'send_chat_message' && $user->is_real_approved != 1) return $this->failure('发送消息失败,请先完善真人认证');
|
||
|
|
|
||
|
|
return $next($request);
|
||
|
|
}
|
||
|
|
|
||
|
|
//接口返回失败
|
||
|
|
public function failure($msg, $data=[], $jsonp=false){
|
||
|
|
$result = [
|
||
|
|
'code'=> 1,
|
||
|
|
'message'=> $msg,
|
||
|
|
'data'=> $data,
|
||
|
|
];
|
||
|
|
if($jsonp){
|
||
|
|
return Response()->jsonp('callback', $result);
|
||
|
|
}else{
|
||
|
|
return Response()->json($result);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|