瀏覽代碼

用户信息和黑名单移除

zhangxiaobin 1 年之前
父節點
當前提交
6c9db1a661
共有 1 個文件被更改,包括 15 次插入4 次删除
  1. 15 4
      application/api/controller/Usercenter.php

+ 15 - 4
application/api/controller/Usercenter.php

@@ -86,7 +86,10 @@ class UserCenter extends Common
             $party = \app\common\model\Party::where('id',$livingUserPartyId)->field('id,room_type')->find();
             $userInfo['party_info'] = ['party_id' => $party['id'], 'room_type' => $party['room_type']];
         }
-
+        $blackWhere['user_id'] = $this->auth->id;
+        $blackList = model('UserBlacklist')->where($blackWhere)->select();
+        $blackIds = !empty($blackList) ? array_column($blackList,'black_user_id') : [];
+        $userInfo['is_black'] = in_array($user_id,$blackIds) ? 1 : 0;
         //访客记录
         $visit_data = [
             'user_id' => $this->auth->id,
@@ -728,14 +731,22 @@ class UserCenter extends Common
      */
     public function removeUserBlack() {
         $id = $this->request->request('id'); // 黑名单ID
-        if (!$id) {
+        $userId = $this->request->request('user_id'); // 用户ID
+        if (!$id && !$userId) {
             $this->error(__('Invalid parameters'));
         }
 
         $userblacklistModel = new \app\common\model\UserBlacklist();
         $where = [];
-        $where["id"] = $id;
-        $res = $userblacklistModel->where($where)->delete();
+        $id && $where["id"] = $id;
+        if ($userId) {
+            $where['user_id'] = $this->auth->id;
+            $where['black_user_id'] = $userId;
+        }
+        $res = false;
+        if (!empty($where)) {
+            $res = $userblacklistModel->where($where)->delete();
+        }
         if($res) {
             $this->success("移除成功!",$res);
         } else {