xiaogang 3 years ago
parent
commit
8c9c44e527
2 changed files with 26 additions and 0 deletions
  1. 10 0
      app/Http/Controllers/Api/HomeController.php
  2. 16 0
      app/Services/HomeService.php

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

xqd
@@ -207,4 +207,14 @@ class HomeController extends Controller
         return response()->json(['message'=>'已销毁']);
     }
 
+    //拉黑用户
+    public function lahei(Request $request){
+        try {
+            $param['user_id'] = $request->user_id;
+            $this->homeService->lahei($param);
+        }catch (\Exception $exception){
+            return $this->response->errorForbidden($exception->getMessage());
+        }
+        return response()->json(['message'=>'已拉黑']);
+    }
 }

+ 16 - 0
app/Services/HomeService.php

xqd xqd
@@ -9,6 +9,7 @@ use App\Exceptions\AuthException;
 use App\Http\Params\UserCommentParam;
 use App\Http\Params\UserLikeParam;
 use App\Models\User;
+use App\Models\UserBlacklistModel;
 use App\Models\UserComment;
 use App\Models\UserInfoModel;
 use App\Models\UserLikeModel;
@@ -263,4 +264,19 @@ class HomeService
         $weixin = UserInfoModel::query()->where('user_id',$user_id)->value('weixin');
         return $weixin;
     }
+
+    //拉黑用户
+    public function lahei($param){
+        $user = auth('api')->user();
+        if(empty($param['user_id'])){
+            throw new Exception("参数错误");
+        }
+        if(UserBlacklistModel::query()->where(['user_id'=>$user->id,'black_id'=>$param['user_id']])->first()){
+            throw new Exception("该用户已被拉黑");
+        }
+
+        UserBlacklistModel::query()->create(['user_id'=>$user->id,'black_id'=>$param['user_id'],'atime'=>date("Y-m-d H:i:s")]);
+
+        return true;
+    }
 }