input('isNoPage',false); $limit = $param['limit'] ?? 20; $nickname = $param['nickname'] ?? ''; $name = $param['name'] ?? ''; $mobile = $param['mobile'] ?? ''; $id = $param['id'] ?? ''; $unit = isset($param['unit'])?$param['unit']:''; $where = []; if (!empty($nickname)) { $where[] = ['nickname', 'like', '%' . $nickname . '%']; } if (!empty($name)) { $where[] = ['name', 'like', '%' . $name . '%']; } if (!empty($mobile)) { $where[] = ['mobile', 'like', '%' . $mobile . '%']; } if (!empty($id)){ $where[] = ['id','like', '%'.$id.'%']; } if($unit) { $org_ids = getOrgSelfAndChildrenIdsById($unit); $uids = (new AdminOrgUser)->whereIN('org_id', $org_ids)->pluck('user_id')->toArray(); $where[] = ['id','in', $uids]; } $adminUserModel = new AdminUser(); if($isNoPage){ $list = $adminUserModel->getAllList($where, ['*'], ['id' => 'asc'], ['role','userOrgs']); }else{ $list = $adminUserModel->getPaginateList($where, ['*'], ['id' => 'asc'], ['role','userOrgs'], $limit); foreach ($list['data'] as $key => $item) { if ($item['role_id'] == 0) { $list['data'][$key]['role_name'] = '超级管理员'; } } } return dataReturn(0, 'success', $list); } /** * 添加管理员 * @param $param */ public function addAdmin($param) { if (isset($param['file'])) { unset($param['file']); } $validate = new AdminUserValidate(); if (!$validate->check($param)) { throw new ApiException($validate->getError(), -1); } $adminUserModel = new AdminUser(); $has = $adminUserModel->checkUnique([ 'name' => $param['name'] ]); if (!empty($has)) { throw new ApiException('该管理员已经存在', -1); } $param['password'] = makePassword($param['password']); $param['salt'] = config('shop.salt'); $param['create_time'] = now(); $param['update_time'] = now(); $param['id'] = time(); $adminUserModel->insertOne($param); return dataReturn(0, '添加成功'); } /** * 编辑管理员 * @param $param * @return array|\think\response\Json */ public function editAdmin($param) { if (isset($param['file'])) { unset($param['file']); } $validate = new AdminUserValidate(); if (!$validate->scene('edit')->check($param)) { throw new ApiException($validate->getError(), -1); } if (!empty($param['password'])) { $param['password'] = makePassword($param['password']); $param['salt'] = config('shop.salt'); } else { unset($param['password']); } $adminUserModel = new AdminUser(); $where[] = ['name', '=', $param['name']]; $where[] = ['id', '<>', $param['id']]; $has = $adminUserModel->checkUnique($where); if (!empty($has)) { throw new ApiException('该管理员已经存在', -1); } $adminUserModel->updateById($param, $param['id']); return dataReturn(0, '编辑成功'); } }