作者 何书鹏
1 个管道 的构建 通过 耗费 1 秒

社区管理员代码调整

@@ -63,23 +63,23 @@ class HouseAdmin extends Api @@ -63,23 +63,23 @@ 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 - $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 - } 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 } 83 }
84 $info->visible(['id','house_id','is_direct','nickname','avatar','house'])->toArray(); 84 $info->visible(['id','house_id','is_direct','nickname','avatar','house'])->toArray();
85 }else{ 85 }else{
@@ -119,36 +119,36 @@ class HouseAdmin extends Api @@ -119,36 +119,36 @@ class HouseAdmin extends Api
119 $user = $this->auth->getUser(); 119 $user = $this->auth->getUser();
120 $keyword = $this->request->param('keyword'); 120 $keyword = $this->request->param('keyword');
121 $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 - // 关键字  
148 if(!empty($keyword)){ 122 if(!empty($keyword)){
149 - $where['name'] = ['like',"%$keyword%"]; 123 + $where['h.name'] = ['like',"%$keyword%"];
150 } 124 }
151 - $list = House::where($where)->field('id,name')->select(); 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 + // // 关键字
  148 + // if(!empty($keyword)){
  149 + // $where['name'] = ['like',"%$keyword%"];
  150 + // }
  151 + // $list = House::where($where)->field('id,name')->select();
152 $this->success('success',$list); 152 $this->success('success',$list);
153 } 153 }
154 154
@@ -178,10 +178,10 @@ class HouseAdmin extends Api @@ -178,10 +178,10 @@ class HouseAdmin extends Api
178 empty($house_id) && $this->error('缺少必要参数'); 178 empty($house_id) && $this->error('缺少必要参数');
179 $info = HouseAdminModel::where(['user_id'=>$this->auth->id,'house_id'=>$house_id])->field('id,nickname,avatar,mobile') 179 $info = HouseAdminModel::where(['user_id'=>$this->auth->id,'house_id'=>$house_id])->field('id,nickname,avatar,mobile')
180 ->find(); 180 ->find();
181 - if(!$info){  
182 - $admin_user_id = House::where('id',$house_id)->value('admin_user_id');  
183 - $info = HouseAdminModel::where(['id'=>$admin_user_id,'user_id'=>$this->auth->id])->field('id,nickname,avatar,mobile')->find();  
184 - } 181 + // if(!$info){
  182 + // $admin_user_id = House::where('id',$house_id)->value('admin_user_id');
  183 + // $info = HouseAdminModel::where(['id'=>$admin_user_id,'user_id'=>$this->auth->id])->field('id,nickname,avatar,mobile')->find();
  184 + // }
185 $info['avatar'] = cdnurl($info['avatar'],true); 185 $info['avatar'] = cdnurl($info['avatar'],true);
186 $this->success('success',$info); 186 $this->success('success',$info);
187 } 187 }
@@ -200,10 +200,10 @@ class HouseAdmin extends Api @@ -200,10 +200,10 @@ class HouseAdmin extends Api
200 200
201 empty($house_id) && $this->error('缺少必要参数'); 201 empty($house_id) && $this->error('缺少必要参数');
202 $admin = HouseAdminModel::get(['user_id'=>$this->auth->id,'house_id'=>$house_id]); 202 $admin = HouseAdminModel::get(['user_id'=>$this->auth->id,'house_id'=>$house_id]);
203 - if(!$admin){  
204 - $house = House::get($house_id);  
205 - $admin = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);  
206 - } 203 + // if(!$admin){
  204 + // $house = House::get($house_id);
  205 + // $admin = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);
  206 + // }
207 empty($admin) && $this->error('您不是该小区的管理员'); 207 empty($admin) && $this->error('您不是该小区的管理员');
208 208
209 $admin->nickname = $nickname; 209 $admin->nickname = $nickname;
@@ -230,10 +230,10 @@ class HouseAdmin extends Api @@ -230,10 +230,10 @@ class HouseAdmin extends Api
230 $this->error('手机号格式不正确'); 230 $this->error('手机号格式不正确');
231 } 231 }
232 $admin = HouseAdminModel::get(['user_id'=>$this->auth->id,'house_id'=>$house_id]); 232 $admin = HouseAdminModel::get(['user_id'=>$this->auth->id,'house_id'=>$house_id]);
233 - if(!$admin){  
234 - $house = House::get($house_id);  
235 - $admin = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);  
236 - } 233 + // if(!$admin){
  234 + // $house = House::get($house_id);
  235 + // $admin = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);
  236 + // }
237 empty($admin) && $this->error('您不是该小区的管理员'); 237 empty($admin) && $this->error('您不是该小区的管理员');
238 // 检查手机号是否存在 238 // 检查手机号是否存在
239 $mobile_exists = HouseAdminModel::where('mobile',$mobile) 239 $mobile_exists = HouseAdminModel::where('mobile',$mobile)
@@ -451,10 +451,10 @@ class HouseAdmin extends Api @@ -451,10 +451,10 @@ class HouseAdmin extends Api
451 empty($post['title']) && $this->error('请填写公告标题'); 451 empty($post['title']) && $this->error('请填写公告标题');
452 empty($post['content']) && $this->error('请填写公告内容'); 452 empty($post['content']) && $this->error('请填写公告内容');
453 $admin = HouseAdminModel::get(['user_id'=>$this->auth->id,'house_id'=>$post['house_id']]); 453 $admin = HouseAdminModel::get(['user_id'=>$this->auth->id,'house_id'=>$post['house_id']]);
454 - if(!$admin){  
455 - $house = House::get($post['house_id']);  
456 - $admin = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);  
457 - } 454 + // if(!$admin){
  455 + // $house = House::get($post['house_id']);
  456 + // $admin = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);
  457 + // }
458 empty($admin) && $this->error('您不是该小区的管理员'); 458 empty($admin) && $this->error('您不是该小区的管理员');
459 $count = HouseBoard::whereTime('createtime', 'week') 459 $count = HouseBoard::whereTime('createtime', 'week')
460 ->where('house_id',$post['house_id']) 460 ->where('house_id',$post['house_id'])
@@ -523,10 +523,10 @@ class HouseAdmin extends Api @@ -523,10 +523,10 @@ class HouseAdmin extends Api
523 $this->error('缺少必要参数'); 523 $this->error('缺少必要参数');
524 } 524 }
525 $admin = HouseAdminModel::get(['user_id'=>$this->auth->id,'house_id'=>$house_id]); 525 $admin = HouseAdminModel::get(['user_id'=>$this->auth->id,'house_id'=>$house_id]);
526 - if(!$admin){  
527 - $house = House::get($house_id);  
528 - $admin = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);  
529 - } 526 + // if(!$admin){
  527 + // $house = House::get($house_id);
  528 + // $admin = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);
  529 + // }
530 empty($admin) && $this->error('您不是该小区的管理员'); 530 empty($admin) && $this->error('您不是该小区的管理员');
531 $info = HouseBoard::get(['house_id'=>$house_id,'id'=>$house_board_id]); 531 $info = HouseBoard::get(['house_id'=>$house_id,'id'=>$house_board_id]);
532 empty($info) && $this->error('公告信息不存在'); 532 empty($info) && $this->error('公告信息不存在');
@@ -873,11 +873,11 @@ class HouseAdmin extends Api @@ -873,11 +873,11 @@ class HouseAdmin extends Api
873 $user = $user_model->field('id,nickname,avatar')->where('id',$v['user_id'])->find(); 873 $user = $user_model->field('id,nickname,avatar')->where('id',$v['user_id'])->find();
874 }else{ 874 }else{
875 $user = HouseAdminModel::where(['user_id'=>$this->auth->id,'house_id'=>$msg['object_id']])->field('id,nickname,avatar')->find(); 875 $user = HouseAdminModel::where(['user_id'=>$this->auth->id,'house_id'=>$msg['object_id']])->field('id,nickname,avatar')->find();
876 - // 多管理员  
877 - if(!$user){  
878 - $house = House::get($msg['object_id']);  
879 - $user = HouseAdminModel::where(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id])->field('id,nickname,avatar')->find();  
880 - } 876 + // // 多管理员
  877 + // if(!$user){
  878 + // $house = House::get($msg['object_id']);
  879 + // $user = HouseAdminModel::where(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id])->field('id,nickname,avatar')->find();
  880 + // }
881 } 881 }
882 $user['avatar'] = cdnurl($user['avatar'],true); 882 $user['avatar'] = cdnurl($user['avatar'],true);
883 $v['user'] = $user; 883 $v['user'] = $user;
@@ -335,12 +335,12 @@ class HouseBoard extends Api @@ -335,12 +335,12 @@ class HouseBoard extends Api
335 if(empty($house_id)){ 335 if(empty($house_id)){
336 $this->error('缺少必要参数'); 336 $this->error('缺少必要参数');
337 } 337 }
338 - $admin_user_id = Db::name('house')->where('id',$house_id)->value('admin_user_id'); 338 + // $admin_user_id = Db::name('house')->where('id',$house_id)->value('admin_user_id');
339 $data = Db::name('house_admin') 339 $data = Db::name('house_admin')
340 ->alias('a') 340 ->alias('a')
341 ->join('user b','a.user_id = b.id') 341 ->join('user b','a.user_id = b.id')
342 ->where('a.house_id',$house_id) 342 ->where('a.house_id',$house_id)
343 - ->whereOr('a.id',$admin_user_id) 343 + // ->whereOr('a.id',$admin_user_id)
344 ->field('a.user_id,b.avatar,b.nickname') 344 ->field('a.user_id,b.avatar,b.nickname')
345 ->order('a.is_direct') 345 ->order('a.is_direct')
346 ->select(); 346 ->select();
@@ -492,10 +492,11 @@ class HouseBoard extends Api @@ -492,10 +492,11 @@ class HouseBoard extends Api
492 492
493 $house_admin = Db::name('house_admin')->where('user_id',$wuye_user_id)->where('house_id',$house_id)->find(); 493 $house_admin = Db::name('house_admin')->where('user_id',$wuye_user_id)->where('house_id',$house_id)->find();
494 if(empty($house_admin)){ 494 if(empty($house_admin)){
495 - // 多管理员  
496 - $house = Db::name('house')->where('id',$house_id)->find();  
497 - $house_admin = Db::name('house_admin')->where(['id'=>$house['admin_user_id'],'user_id'=>$wuye_user_id])->find();  
498 - empty($house_admin) && $this->error('参数有误,社区与管理员id不匹配'); 495 + // // 多管理员
  496 + // $house = Db::name('house')->where('id',$house_id)->find();
  497 + // $house_admin = Db::name('house_admin')->where(['id'=>$house['admin_user_id'],'user_id'=>$wuye_user_id])->find();
  498 + // empty($house_admin) && $this->error('参数有误,社区与管理员id不匹配');
  499 + $this->error('参数有误,社区与管理员id不匹配');
499 } 500 }
500 $where = [ 501 $where = [
501 'where' => [ 502 'where' => [
@@ -190,9 +190,10 @@ class User extends Api @@ -190,9 +190,10 @@ class User extends Api
190 if($info) { 190 if($info) {
191 $user['identity'] = 1; 191 $user['identity'] = 1;
192 } else { 192 } else {
193 - // 社区管理员管理多个小区  
194 - $info = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);  
195 - $user['identity'] = $info ? 1 : 0; 193 + // // 社区管理员管理多个小区
  194 + // $info = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);
  195 + // $user['identity'] = $info ? 1 : 0;
  196 + $user['identity'] = 0;
196 } 197 }
197 $this->success('成功', array_merge($user,$data)); 198 $this->success('成功', array_merge($user,$data));
198 } 199 }