xiaogang 4 年 前
コミット
37b2e968b3

+ 10 - 0
app/Exceptions/AuthException.php

xqd
@@ -0,0 +1,10 @@
+<?php
+
+namespace App\Exceptions;
+
+use Exception;
+
+class AuthException extends Exception
+{
+    //
+}

+ 3 - 0
app/Http/Controllers/Api/HomeController.php

xqd xqd
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api;
 
 
 use App\Enums\ApiEnum;
+use App\Exceptions\AuthException;
 use App\Http\Params\UserCommentParam;
 use App\Http\Params\UserLikeParam;
 use App\Models\UserPhotoDestroy;
@@ -93,6 +94,8 @@ class HomeController extends Controller
             $res = $this->homeService->user_detail($request->user_id);
         }catch (\Exception $exception){
             return $this->response->errorForbidden($exception->getMessage());
+        }catch (AuthException $exception){
+            return $this->response->errorUnauthorized($exception->getMessage());
         }
         return response()->json($res);
     }

+ 9 - 0
app/Services/HomeService.php

xqd xqd
@@ -5,6 +5,7 @@ namespace App\Services;
 
 
 use App\Enums\ApiEnum;
+use App\Exceptions\AuthException;
 use App\Http\Params\UserCommentParam;
 use App\Http\Params\UserLikeParam;
 use App\Models\User;
@@ -59,6 +60,14 @@ class HomeService
     //用户详情
     public function user_detail($user_id){
         $user = auth('api')->user();
+
+        //判断逛一逛用户和非会员用户
+        if(!$user){
+            throw new AuthException("请先登录");
+        }
+
+
+
         $is_like = 0;
         $is_comment = 0;