正在显示
2 个修改的文件
包含
49 行增加
和
16 行删除
@@ -63,12 +63,24 @@ class HouseAdmin extends Api | @@ -63,12 +63,24 @@ class HouseAdmin extends Api | ||
63 | $info = HouseAdminModel::get(['user_id'=>$user_id,'house_id'=>$house_id],['house']); | 63 | $info = HouseAdminModel::get(['user_id'=>$user_id,'house_id'=>$house_id],['house']); |
64 | // empty($info) && $this->error('您不是该小区的管理员'); | 64 | // empty($info) && $this->error('您不是该小区的管理员'); |
65 | if(empty($info)) { | 65 | if(empty($info)) { |
66 | - $info = HouseAdminModel::with(['house']) | ||
67 | - ->where(['user_id'=>$user_id]) | ||
68 | - ->order(['is_direct'=>'asc','createtime'=>'asc']) | ||
69 | - ->field('id,house_id,is_direct,nickname,avatar') | ||
70 | - ->find(); | ||
71 | - }; | 66 | +// $info = HouseAdminModel::with(['house']) |
67 | +// ->where(['user_id'=>$user_id]) | ||
68 | +// ->order(['is_direct'=>'asc','createtime'=>'asc']) | ||
69 | +// ->field('id,house_id,is_direct,nickname,avatar') | ||
70 | +// ->find(); | ||
71 | + $house = House::get($house_id); | ||
72 | + $info = HouseAdminModel::get($house['admin_user_id']); | ||
73 | + if($info){ | ||
74 | + $info['house_id'] = $house_id; | ||
75 | + $info['house'] = $house; | ||
76 | + }else{ | ||
77 | + $info = HouseAdminModel::with(['house']) | ||
78 | + ->where(['user_id'=>$user_id]) | ||
79 | + ->order(['is_direct'=>'asc','createtime'=>'asc']) | ||
80 | + ->field('id,house_id,is_direct,nickname,avatar') | ||
81 | + ->find(); | ||
82 | + } | ||
83 | + } | ||
72 | $info->visible(['id','house_id','is_direct','nickname','avatar','house'])->toArray(); | 84 | $info->visible(['id','house_id','is_direct','nickname','avatar','house'])->toArray(); |
73 | }else{ | 85 | }else{ |
74 | $info = HouseAdminModel::with(['house']) | 86 | $info = HouseAdminModel::with(['house']) |
@@ -107,17 +119,36 @@ class HouseAdmin extends Api | @@ -107,17 +119,36 @@ class HouseAdmin extends Api | ||
107 | $user = $this->auth->getUser(); | 119 | $user = $this->auth->getUser(); |
108 | $keyword = $this->request->param('keyword'); | 120 | $keyword = $this->request->param('keyword'); |
109 | $where = []; | 121 | $where = []; |
122 | +// if(!empty($keyword)){ | ||
123 | +// $where['h.name'] = ['like',"%$keyword%"]; | ||
124 | +// } | ||
125 | +// // 查出该管理员已绑定的小区 | ||
126 | +// $list = HouseAdminModel::alias('ha') | ||
127 | +// ->join('house h','h.id = ha.house_id') | ||
128 | +// ->where('ha.user_id',$user['id']) | ||
129 | +// ->where($where) | ||
130 | +// ->field("h.id,h.name") | ||
131 | +// ->order('ha.is_direct') | ||
132 | +// ->select(); | ||
133 | + // 社区管理员管理多个小区 | ||
134 | + $house_ids = []; | ||
135 | + $house_list = HouseAdminModel::where('user_id',$user['id'])->field('id,house_id')->select(); | ||
136 | + if(count($house_list) > 0){ | ||
137 | + $house_ids = array_merge($house_ids,array_column($house_list,'house_id')); | ||
138 | + $house_admin_ids = array_column($house_list,'id'); | ||
139 | + if($house_admin_ids){ | ||
140 | + $house_ids = array_merge($house_ids,House::where('admin_user_id','in',$house_admin_ids)->column('id')); | ||
141 | + } | ||
142 | + } | ||
143 | + $house_ids = array_filter(array_unique($house_ids)); | ||
144 | + if ($house_ids) { | ||
145 | + $where['id'] = ['in',$house_ids]; | ||
146 | + } | ||
147 | + // 关键字 | ||
110 | if(!empty($keyword)){ | 148 | if(!empty($keyword)){ |
111 | - $where['h.name'] = ['like',"%$keyword%"]; | 149 | + $where['name'] = ['like',"%$keyword%"]; |
112 | } | 150 | } |
113 | - // 查出该管理员已绑定的小区 | ||
114 | - $list = HouseAdminModel::alias('ha') | ||
115 | - ->join('house h','h.id = ha.house_id') | ||
116 | - ->where('ha.user_id',$user['id']) | ||
117 | - ->where($where) | ||
118 | - ->field("h.id,h.name") | ||
119 | - ->order('ha.is_direct') | ||
120 | - ->select(); | 151 | + $list = House::where($where)->field('id,name')->select(); |
121 | $this->success('success',$list); | 152 | $this->success('success',$list); |
122 | } | 153 | } |
123 | 154 |
@@ -190,7 +190,9 @@ class User extends Api | @@ -190,7 +190,9 @@ class User extends Api | ||
190 | if($info) { | 190 | if($info) { |
191 | $user['identity'] = 1; | 191 | $user['identity'] = 1; |
192 | } else { | 192 | } else { |
193 | - $user['identity'] = 0; | 193 | + // 社区管理员管理多个小区 |
194 | + $info = HouseAdminModel::get($house['admin_user_id']); | ||
195 | + $user['identity'] = $info ? 1 : 0; | ||
194 | } | 196 | } |
195 | $this->success('成功', array_merge($user,$data)); | 197 | $this->success('成功', array_merge($user,$data)); |
196 | } | 198 | } |
-
请 注册 或 登录 后发表评论