xiaogang 3 anos atrás
pai
commit
ac3763aa29

+ 10 - 0
app/Exceptions/VipException.php

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

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

xqd xqd
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api;
 
 
 use App\Enums\ApiEnum;
+use App\Exceptions\VipException;
 use App\Http\Params\DynamicParam;
 use App\Http\Params\DynamicZanParam;
 use App\Http\Params\UserReportParam;
@@ -73,6 +74,8 @@ class DynamicController extends Controller
             }else{
                 throw new Exception("请求太频繁");
             }
+        }catch (VipException $exception){
+            return response()->json(['message'=>$exception->getMessage()])->setStatusCode(410);
         }catch (\Exception $exception){
             DB::rollBack();
             return $this->response->errorForbidden($exception->getMessage());

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

xqd xqd xqd
@@ -6,6 +6,7 @@ namespace App\Http\Controllers\Api;
 
 use App\Enums\ApiEnum;
 use App\Exceptions\AuthException;
+use App\Exceptions\VipException;
 use App\Http\Params\UserCommentParam;
 use App\Http\Params\UserLikeParam;
 use App\Models\UserPhotoDestroy;
@@ -94,6 +95,8 @@ class HomeController extends Controller
             $param['user_id'] = $request->user_id;
             $param['tencent_im_user_id'] = $request->tencent_im_user_id;
             $res = $this->homeService->user_detail($param);
+        }catch (VipException $exception){
+            return response()->json(['message'=>$exception->getMessage()])->setStatusCode(410);
         }catch (AuthException $exception){
             return $this->response->errorUnauthorized($exception->getMessage());
         }catch (\Exception $exception){
@@ -171,6 +174,8 @@ class HomeController extends Controller
     public function get_weixin(Request $request){
         try {
             $res = $this->homeService->get_weixin($request->user_id);
+        }catch (VipException $exception){
+            return response()->json(['message'=>$exception->getMessage()])->setStatusCode(410);
         }catch (\Exception $exception){
             return $this->response->errorForbidden($exception->getMessage());
         }

+ 2 - 1
app/Services/DynamicService.php

xqd xqd
@@ -4,6 +4,7 @@
 namespace App\Services;
 
 
+use App\Exceptions\VipException;
 use App\Http\Params\DynamicParam;
 use App\Http\Params\DynamicZanParam;
 use App\Http\Params\UserReportParam;
@@ -36,7 +37,7 @@ class DynamicService
         $user = auth('api')->user();
         //判断会员特权和普通用户
         if($user->is_vip==0){
-            throw new Exception("开通VIP即可发布动态");
+            throw new VipException("开通VIP即可发布动态");
         }else{
             $limit = UserVipLimit::query()->where('user_id',$user->id)->first();
             if($limit->dynamic>=5){

+ 3 - 2
app/Services/HomeService.php

xqd xqd xqd
@@ -6,6 +6,7 @@ namespace App\Services;
 
 use App\Enums\ApiEnum;
 use App\Exceptions\AuthException;
+use App\Exceptions\VipException;
 use App\Http\Params\UserCommentParam;
 use App\Http\Params\UserLikeParam;
 use App\Models\User;
@@ -104,7 +105,7 @@ class HomeService
             if($user->is_vip==0){
                 $limit = UserVipLimit::query()->where('user_id',$user->id)->first();
                 if($limit->user_detail>=10){
-                    throw new Exception("非VIP用户每天只能看10个人");
+                    throw new VipException("非VIP用户每天只能看10个人");
                 }else{
                     //如果当天没有看过这个人  增加记录
                     if(!DB::table('users_look')->where(['user_id'=>$user->id,'look_id'=>$user_id])->whereBetween('atime',[date('Y-m-d 00:00:00'),date('Y-m-d 23:59:59')])->first()){
@@ -253,7 +254,7 @@ class HomeService
         $user = auth('api')->user();
         //判断会员特权和普通用户
         if($user->is_vip==0){
-            throw new Exception("开通VIP即可解锁");
+            throw new VipException("开通VIP即可解锁");
         }else{
             $limit = UserVipLimit::query()->where('user_id',$user->id)->first();
             if($limit->weixin>=10){