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

合并分支 'heshupeng' 到 'master'

社区管理员管理多个小区



查看合并请求 !405
... ... @@ -63,12 +63,24 @@ class HouseAdmin extends Api
$info = HouseAdminModel::get(['user_id'=>$user_id,'house_id'=>$house_id],['house']);
// empty($info) && $this->error('您不是该小区的管理员');
if(empty($info)) {
$info = HouseAdminModel::with(['house'])
->where(['user_id'=>$user_id])
->order(['is_direct'=>'asc','createtime'=>'asc'])
->field('id,house_id,is_direct,nickname,avatar')
->find();
};
// $info = HouseAdminModel::with(['house'])
// ->where(['user_id'=>$user_id])
// ->order(['is_direct'=>'asc','createtime'=>'asc'])
// ->field('id,house_id,is_direct,nickname,avatar')
// ->find();
$house = House::get($house_id);
$info = HouseAdminModel::get($house['admin_user_id']);
if($info){
$info['house_id'] = $house_id;
$info['house'] = $house;
}else{
$info = HouseAdminModel::with(['house'])
->where(['user_id'=>$user_id])
->order(['is_direct'=>'asc','createtime'=>'asc'])
->field('id,house_id,is_direct,nickname,avatar')
->find();
}
}
$info->visible(['id','house_id','is_direct','nickname','avatar','house'])->toArray();
}else{
$info = HouseAdminModel::with(['house'])
... ... @@ -107,17 +119,36 @@ class HouseAdmin extends Api
$user = $this->auth->getUser();
$keyword = $this->request->param('keyword');
$where = [];
// if(!empty($keyword)){
// $where['h.name'] = ['like',"%$keyword%"];
// }
// // 查出该管理员已绑定的小区
// $list = HouseAdminModel::alias('ha')
// ->join('house h','h.id = ha.house_id')
// ->where('ha.user_id',$user['id'])
// ->where($where)
// ->field("h.id,h.name")
// ->order('ha.is_direct')
// ->select();
// 社区管理员管理多个小区
$house_ids = [];
$house_list = HouseAdminModel::where('user_id',$user['id'])->field('id,house_id')->select();
if(count($house_list) > 0){
$house_ids = array_merge($house_ids,array_column($house_list,'house_id'));
$house_admin_ids = array_column($house_list,'id');
if($house_admin_ids){
$house_ids = array_merge($house_ids,House::where('admin_user_id','in',$house_admin_ids)->column('id'));
}
}
$house_ids = array_filter(array_unique($house_ids));
if ($house_ids) {
$where['id'] = ['in',$house_ids];
}
// 关键字
if(!empty($keyword)){
$where['h.name'] = ['like',"%$keyword%"];
$where['name'] = ['like',"%$keyword%"];
}
// 查出该管理员已绑定的小区
$list = HouseAdminModel::alias('ha')
->join('house h','h.id = ha.house_id')
->where('ha.user_id',$user['id'])
->where($where)
->field("h.id,h.name")
->order('ha.is_direct')
->select();
$list = House::where($where)->field('id,name')->select();
$this->success('success',$list);
}
... ...
... ... @@ -190,7 +190,9 @@ class User extends Api
if($info) {
$user['identity'] = 1;
} else {
$user['identity'] = 0;
// 社区管理员管理多个小区
$info = HouseAdminModel::get($house['admin_user_id']);
$user['identity'] = $info ? 1 : 0;
}
$this->success('成功', array_merge($user,$data));
}
... ...