findByPk(Yii::app()->user->_id); if (!$model) { Helper::error('信息未找到'); } $authIds = DB::getScalerWithCriteria('role', DbCriteria::simpleCompare(['id' => $model->role_id])->setSelect('auth_ids')); $authIds = $authIds ? explode(',', $authIds) : []; $authIds = array_map(function ($item) { return (int)$item; }, $authIds); Helper::ok([ 'id' => $model->id, 'username' => $model->username, 'auth_ids' => $authIds, 'buttons' => [], 'avatar' => Helper::getImageUrl($model->avatar), 'email' => $model->email, 'phone' => $model->phone, 'descr' => $model->descr, ]); } public function actionRoleList() { $name = Helper::getPostString('name'); $name = $name ? '%' . $name : null; $cri = DbCriteria::simpleCompareWithPage(['name' => $name])->setSelect('id, name, auth_ids, descr, create_date, show_ids'); $data = DB::getListWithCriteria('role', $cri); if (!empty($data['records'])) { $data['records'] = array_map(function ($item) { $item['auth_ids'] = $item['auth_ids'] ? explode(',', $item['auth_ids']) : []; $item['auth_ids'] = array_map(function ($aid) { return (int)$aid; }, $item['auth_ids']); $item['show_ids'] = $item['show_ids'] ? explode(',', $item['show_ids']) : []; $item['show_ids'] = array_map(function ($aid) { return (int)$aid; }, $item['show_ids']); return $item; }, $data['records']); } Helper::ok($data); } /** * 角色下拉列表获取 * @return void */ public function actionGetRoleSelect() { $cri = DbCriteria::simpleCompare([])->setSelect('id, name'); $data = DB::getListWithCriteria('role', $cri); Helper::ok($data['records']??[]); } public function actionUserList() { $name = Helper::getPostString('name'); $name = $name ? '%' . $name : null; $filters = [ 'username' => $name, 'u.id' => '!=1', 'u.status' => '1', 'role_id' => Helper::getPostInt('role_id')?:null, 'phone' => Helper::getPostString('phone')?:null, ]; $cri = DbCriteria::simpleCompareWithPage($filters) ->setAlias('u') ->setDebugUntil('234', '-1') ->setSelect('u.id, u.username, r.name as role_name, u.status, u.sex, u.phone, u.create_date, u.avatar, u.update_date') ->setJoin('left join wx_role r on u.role_id = r.id'); $data = DB::getListWithCriteria('useradmin', $cri); if (!empty($data['records'])) { $data['records'] = array_map(function ($item) { $item['avatar'] = Helper::getImageUrl($item['avatar']); return $item; }, $data['records']); } Helper::ok($data); } public function actionSaveRoleAuth() { $id = Helper::getPostInt('id'); $leaf_ids = Helper::getArrParam($_POST, 'leaf_ids', 'array_int', []); $half_Leaf_ids = Helper::getArrParam($_POST, 'half_Leaf_ids', 'array_int', []); if ($id < 0 || !$leaf_ids) { return Helper::error('参数错误'); } $info = [ 'auth_ids' => implode(',', Helper::concatArray($half_Leaf_ids, $leaf_ids)), 'show_ids' => $leaf_ids ? implode(',', $leaf_ids) : '', ]; DB::updateById('role', $info, $id); Helper::ok(); } public function actionEditUser() { $id = Helper::getPostInt('id'); $username = Helper::getPostString('username'); $password = Helper::getPostString('password'); $phone = Helper::getPostString('phone'); $sex = Helper::getPostInt('sex'); $role_id = Helper::getPostInt('role_id'); // username不能为空和重复 if (!$username) { Helper::error('用户名不能为空'); } $cri = DbCriteria::simpleCompare(['username' => $username])->setSelect('id'); if ($id > 0) { $cri->addCondition('id!=' . $id); } if ($fid = DB::getScalerWithCriteria('useradmin', $cri)) { Helper::error('用户名已存在 ' . $fid); } $info = [ 'username' => $username, 'phone' => $phone, 'sex' => $sex, ]; if (!$id) { // 新增用户 if (!$password) { Helper::error('密码不能为空'); } if (!$role_id) { Helper::error('请选择角色'); } $info['password'] = md5($password); $info['role_id'] = $role_id; DB::addData('useradmin', $info); } else { DB::updateById('useradmin', $info, $id); } Helper::ok(); } public function actionDeleteUser() { $id = Helper::getPostInt('id'); if ($id < 1) { Helper::error('参数错误'); } DB::updateById('useradmin', ['status' => 0], $id); Helper::ok(); } public function actionDeleteRole() { $id = Helper::getPostInt('id'); if ($id < 1) { Helper::error('参数错误'); } DB::deleteById('role', $id); Helper::ok(); } public function actionEditRole() { $id = Helper::getPostInt('id'); $name = Helper::getPostString('name'); $descr = Helper::getPostString('descr'); if (!$name) { Helper::error('角色名称不能为空'); } if ($id) { DB::updateById('role', ['name' => $name, 'descr' => $descr], $id); } else { DB::addData('role', ['name' => $name, 'descr' => $descr]); } Helper::ok(); } public function actionCheckpwd(){ $pass = $_POST['pass']; $new_passwd = trim($_POST['new_passwd']); $confir_passwd = trim($_POST['confir_passwd']); if( !$pass ) { $arr = array('status'=>'failed','code'=>0); } if( !$new_passwd ) { $arr = array('status'=>'failed','code'=>1); } if( !$confir_passwd ) { $arr = array('status'=>'failed','code'=>2); } if( $new_passwd != $confir_passwd ) { $arr = array('status'=>'failed','code'=>4); $this->response($arr); } $id = Yii::app()->user->_id; $userAdminModel = Useradmin::model()->findByPk($id); if( md5($pass) != $userAdminModel->password ) { $arr = array('status'=>'failed','code'=>5); $this->response($arr); } $userAdminModel->password = md5($new_passwd); $userAdminModel->verifypassword = md5($new_passwd); if($userAdminModel->save()) { Yii::app()->user->logout(); $this->response(array('status'=>'success')); } } }