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

社区管理员代码调整

... ... @@ -63,23 +63,23 @@ 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();
$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 = 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{
... ... @@ -119,36 +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['name'] = ['like',"%$keyword%"];
$where['h.name'] = ['like',"%$keyword%"];
}
$list = House::where($where)->field('id,name')->select();
// 查出该管理员已绑定的小区
$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['name'] = ['like',"%$keyword%"];
// }
// $list = House::where($where)->field('id,name')->select();
$this->success('success',$list);
}
... ... @@ -178,10 +178,10 @@ class HouseAdmin extends Api
empty($house_id) && $this->error('缺少必要参数');
$info = HouseAdminModel::where(['user_id'=>$this->auth->id,'house_id'=>$house_id])->field('id,nickname,avatar,mobile')
->find();
if(!$info){
$admin_user_id = House::where('id',$house_id)->value('admin_user_id');
$info = HouseAdminModel::where(['id'=>$admin_user_id,'user_id'=>$this->auth->id])->field('id,nickname,avatar,mobile')->find();
}
// if(!$info){
// $admin_user_id = House::where('id',$house_id)->value('admin_user_id');
// $info = HouseAdminModel::where(['id'=>$admin_user_id,'user_id'=>$this->auth->id])->field('id,nickname,avatar,mobile')->find();
// }
$info['avatar'] = cdnurl($info['avatar'],true);
$this->success('success',$info);
}
... ... @@ -200,10 +200,10 @@ class HouseAdmin extends Api
empty($house_id) && $this->error('缺少必要参数');
$admin = HouseAdminModel::get(['user_id'=>$this->auth->id,'house_id'=>$house_id]);
if(!$admin){
$house = House::get($house_id);
$admin = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);
}
// if(!$admin){
// $house = House::get($house_id);
// $admin = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);
// }
empty($admin) && $this->error('您不是该小区的管理员');
$admin->nickname = $nickname;
... ... @@ -230,10 +230,10 @@ class HouseAdmin extends Api
$this->error('手机号格式不正确');
}
$admin = HouseAdminModel::get(['user_id'=>$this->auth->id,'house_id'=>$house_id]);
if(!$admin){
$house = House::get($house_id);
$admin = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);
}
// if(!$admin){
// $house = House::get($house_id);
// $admin = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);
// }
empty($admin) && $this->error('您不是该小区的管理员');
// 检查手机号是否存在
$mobile_exists = HouseAdminModel::where('mobile',$mobile)
... ... @@ -451,10 +451,10 @@ class HouseAdmin extends Api
empty($post['title']) && $this->error('请填写公告标题');
empty($post['content']) && $this->error('请填写公告内容');
$admin = HouseAdminModel::get(['user_id'=>$this->auth->id,'house_id'=>$post['house_id']]);
if(!$admin){
$house = House::get($post['house_id']);
$admin = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);
}
// if(!$admin){
// $house = House::get($post['house_id']);
// $admin = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);
// }
empty($admin) && $this->error('您不是该小区的管理员');
$count = HouseBoard::whereTime('createtime', 'week')
->where('house_id',$post['house_id'])
... ... @@ -523,10 +523,10 @@ class HouseAdmin extends Api
$this->error('缺少必要参数');
}
$admin = HouseAdminModel::get(['user_id'=>$this->auth->id,'house_id'=>$house_id]);
if(!$admin){
$house = House::get($house_id);
$admin = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);
}
// if(!$admin){
// $house = House::get($house_id);
// $admin = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);
// }
empty($admin) && $this->error('您不是该小区的管理员');
$info = HouseBoard::get(['house_id'=>$house_id,'id'=>$house_board_id]);
empty($info) && $this->error('公告信息不存在');
... ... @@ -873,11 +873,11 @@ class HouseAdmin extends Api
$user = $user_model->field('id,nickname,avatar')->where('id',$v['user_id'])->find();
}else{
$user = HouseAdminModel::where(['user_id'=>$this->auth->id,'house_id'=>$msg['object_id']])->field('id,nickname,avatar')->find();
// 多管理员
if(!$user){
$house = House::get($msg['object_id']);
$user = HouseAdminModel::where(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id])->field('id,nickname,avatar')->find();
}
// // 多管理员
// if(!$user){
// $house = House::get($msg['object_id']);
// $user = HouseAdminModel::where(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id])->field('id,nickname,avatar')->find();
// }
}
$user['avatar'] = cdnurl($user['avatar'],true);
$v['user'] = $user;
... ...
... ... @@ -335,12 +335,12 @@ class HouseBoard extends Api
if(empty($house_id)){
$this->error('缺少必要参数');
}
$admin_user_id = Db::name('house')->where('id',$house_id)->value('admin_user_id');
// $admin_user_id = Db::name('house')->where('id',$house_id)->value('admin_user_id');
$data = Db::name('house_admin')
->alias('a')
->join('user b','a.user_id = b.id')
->where('a.house_id',$house_id)
->whereOr('a.id',$admin_user_id)
// ->whereOr('a.id',$admin_user_id)
->field('a.user_id,b.avatar,b.nickname')
->order('a.is_direct')
->select();
... ... @@ -492,10 +492,11 @@ class HouseBoard extends Api
$house_admin = Db::name('house_admin')->where('user_id',$wuye_user_id)->where('house_id',$house_id)->find();
if(empty($house_admin)){
// 多管理员
$house = Db::name('house')->where('id',$house_id)->find();
$house_admin = Db::name('house_admin')->where(['id'=>$house['admin_user_id'],'user_id'=>$wuye_user_id])->find();
empty($house_admin) && $this->error('参数有误,社区与管理员id不匹配');
// // 多管理员
// $house = Db::name('house')->where('id',$house_id)->find();
// $house_admin = Db::name('house_admin')->where(['id'=>$house['admin_user_id'],'user_id'=>$wuye_user_id])->find();
// empty($house_admin) && $this->error('参数有误,社区与管理员id不匹配');
$this->error('参数有误,社区与管理员id不匹配');
}
$where = [
'where' => [
... ...
... ... @@ -190,9 +190,10 @@ class User extends Api
if($info) {
$user['identity'] = 1;
} else {
// 社区管理员管理多个小区
$info = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);
$user['identity'] = $info ? 1 : 0;
// // 社区管理员管理多个小区
// $info = HouseAdminModel::get(['id'=>$house['admin_user_id'],'user_id'=>$this->auth->id]);
// $user['identity'] = $info ? 1 : 0;
$user['identity'] = 0;
}
$this->success('成功', array_merge($user,$data));
}
... ...