123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930 |
- <?php
- namespace app\admin\controller\base\user;
- use app\admin\extend\enroll\UserRoleHandle;
- use Cassandra\Uuid;
- use daorui\platform\platformAuth;
- use think\Db;
- use app\admin\controller\Base;
- use app\admin\validate\base\user\User as UserValidate;
- use app\common\model\base\user\User as UserModel;
- use app\common\model\base\user\Token;
- use app\common\model\base\user\UserRole;
- use app\common\model\base\org\OrgRole;
- use app\common\model\base\org\Org;
- use app\common\model\base\menu\Menu;
- use think\facade\Cache;
- use app\common\model\base\msg\Sms as smsModel;
- class User extends Base
- {
- protected $userModel = null;
- protected $tokenModel = null;
- protected $orgRoleModel = null;
- protected $orgModel = null;
- protected $userRoleModel = null;
- protected $loginByName = false;
- protected $maxtrynum = 0;
- protected $noNeedLogin = [
- 'register', 'login', 'captcha', 'getSmsCode',
- 'checkLogin', 'logout', 'getQrcode', 'getTemplate', 'getFileRows', 'resetPwdByCode', 'ssologin', 'checkPwdComplexity',
- 'BatchCreateUser', 'BatchPower', 'resetPwdAll', 'exportNoChangePwd', 'resetPwd', 'socialLogin', 'accountLogin',
- ];
- protected $noNeedAuth = ['userInfo', 'getUserInfo', 'getList', 'getRouterList', 'socialLogin', 'accountLogin'];
- protected $noNeedValidate = ['doEdit'];
-
- public function initialize()
- {
- parent::initialize();
- $this->userModel = new UserModel;
- $this->tokenModel = new Token;
- $this->orgRoleModel = new OrgRole;
- $this->orgModel = new Org;
- $this->userRoleModel = new UserRole;
- $this->maxtrynum = sysconfig('account.PwdMaxTry');
- }
-
- private function createWhere()
- {
- $data = $this->request->param();
- $keyword = $data['keyword'] ?? '';
- $status = $data['status'] ?? 0;
- $roleCode = $data['roleCode'] ?? '';
- $org_id = $data['org_id'] ?? 0;
- $ids = $data['ids'] ?? [];
- $where = [];
- $whereOr = [];
-
- if (!empty($ids)) {
- $where[] = ['user_id', 'IN', $ids];
- } else {
-
- if (!empty($org_id) && $org_id > 0) {
- $org_ids = $this->orgModel->getChildrenIds($org_id, true);
- $ids = $this->userRoleModel->where('org_id', 'IN', $org_ids)->column('user_id');
- $where[] = ['user_id', 'IN', $ids];
- }
-
- if (!empty($roleCode)) {
- $ids = $this->userRoleModel->where('role_code', 'LIKE', "%$roleCode%")->column('user_id');
- $where[] = ['user_id', 'IN', $ids];
- }
-
- if (!empty($status)) {
- $where[] = ['status', '=', $status];
- }
-
- if (!empty($keyword)) {
- $where[] = ["username|nickname|phone|idcard|name", "LIKE", "%$keyword%"];
- }
- }
- return ['where' => $where, 'whereOr' => $whereOr];
- }
-
- public function getList($pageNo = 1, $pageSize = 10)
- {
- $data = $this->request->param();
- $whereAry = $this->createWhere();
- $where = $whereAry['where'];
- $whereOr = $whereAry['whereOr'];
- $list = $this->userModel->where($where)->whereOr($whereOr)->with(['roles'])->append(['sex_txt', 'status_txt', 'is_ensure_txt'])->paginate(['page' => $pageNo, 'list_rows' => $pageSize]);
- $total = $list->total();
- $list = FieldConverList($list->items());
- return pageRes(1, "获取成功", $total, $list, $where);
- }
-
- public function login($username = '', $password = '', $code = '', $login_role = 'SUPERADMIN', $login_org = 1)
- {
- try {
-
- if (!IsMobileAccess() && !parent::captcha_check($code)) {
- return Result(2, "验证码错误", $code);
- }
- $res = (new platformAuth())->interfaceRequest('accountLogin', ['username' => $username, 'password' => $password]);
- if (!$res['code']) return Result(2, $res['msg']);
- $fetchUser = $res['data'];
- $user = UserModel::where('uuid', $fetchUser['uuid'])->find();
- if (!$user->is_developer) {
- UserRoleHandle::handleRole($user->user_id);
- $userRole = UserRole::where('user_id', $user->user_id)->find();
- if ($userRole) {
- $login_org = $userRole['org_id'] ?? $login_org;
- $login_role = $this->orgRoleModel->where('role_id', $userRole['role_id'])->value('code');
- }
- }
- $token = $this->tokenModel->updatetoken($user->user_id, $login_org, $login_role);
- $log = slog(1, $user->username . "使用帐号密码登录成功");
- return Result(1, '登录成功', ['token' => $token, 'user_id' => $user->user_id, 'user' => $this->tokenModel->tokenUser($token), 'log' => $log]);
- } catch (\Exception $e) {
- return res(2, '系统繁忙', $e->getFile() . '第' . $e->getLine() . '行:' . $e->getMessage(), $e->getTrace());
- }
- }
-
- private function accountLogin($username, $password, $login_org, $login_role)
- {
- $where = [];
- try {
-
- $where[] = ['username|phone|idcard', '=', $username];
- $user = $this->userModel->where($where)->find();
- if (empty($user)) {
- return Result(0, '帐号或密码错误');
- }
-
- if (!CheckEncrypt($user->salt, $password, $user->password)) {
-
- $user->inc('trynum', 1)->update();
-
- $Surplus = $this->maxtrynum - $user->trynum;
- if ($user->trynum > $this->maxtrynum) {
- $user->save(['status' => 2]);
- slog(1, $user->username . "登录失败次数超过限制,账户已被禁用");
- return Result(0, '帐号或密码错误');
- }
- return Result(0, '帐号或密码错误,您还有' . $Surplus . '次机会。');
- }
-
- if ($user->status == 2) {
- return Result(0, '此帐号已被禁用');
- }
-
- $PwdComplexity = UserModel::checkPwdComplexity($password);
- $complexity = $PwdComplexity['code'] == 1 ? 0 : 1;
-
- if ($complexity == 0) {
- if (trim($password) == trim(sysconfig('account.default_pwd'))) {
- $complexity = 1;
- }
- }
- if (!$user->is_developer) {
- $userRole = UserRole::where('user_id', $user->user_id)->find();
- if ($userRole) {
- $login_org = $userRole['org_id'] ?? $login_org;
- $login_role = $this->orgRoleModel->where('role_id', $userRole['role_id'])->value('code');
- }
- }
-
- $userRole = $this->userRoleModel->where('user_id', $user->user_id)->where('org_id', $login_org)->where('role_code', $login_role)->find();
- if (empty($userRole)) {
- return Result(0, "此账号未绑定对应角色");
- }
- $user->trynum = 0;
- $user->complexity = $complexity;
- $user->save();
- $token = $this->tokenModel->updatetoken($user->user_id, $userRole['org_id'], $login_role);
- $log = slog(1, $user->username . "使用帐号密码登录成功");
- return Result(1, '登录成功', ['token' => $token, 'user_id' => $user->user_id, 'user' => $this->tokenModel->tokenUser($token), 'log' => $log]);
- } catch (\Exception $e) {
- return Result(0, "登录失败", $e->getFile() . "第" . $e->getLine() . "行:" . $e->getMessage(), $e->getTrace());
- }
- }
-
- public function socialLogin()
- {
- $data = $this->request->param();
- if (empty($data['uuid'])) return res(0, '缺少参数');
- $uuid = $data['uuid'];
- $user = UserModel::where('uuid', $uuid)->find();
- if (empty($user)) {
-
- $user = $this->userModel->create_user($data);
- UserRole::create(['user_id' => $user['user_id'], 'role_id' => $data['role_id'], 'org_id' => $data['org_id'], 'role_code' => $data['role_code']]);
- $token = $this->tokenModel->updatetoken($user->user_id, $data['org_id'], $data['role_code']);
- } else {
-
- $user->replace()->save($data);
-
- $token = $this->tokenModel->updatetoken($user->user_id, $data['org_id'], $data['role_code']);
- }
- return Result(1, '登录成功', ['token' => $token, 'user_id' => $user->user_id, 'user' => $this->tokenModel->tokenUser($token)]);
- }
-
- public function getUserInfo($user_id = 0)
- {
- if ($user_id) {
- $res = $this->userModel->where('user_id', $user_id)->hidden(['password', 'salt'])->append(['roles'])->find();
- $res->avatar_base64 = file2base64(public_path() . $res->avatar);
- } else {
- $tokenUser = $this->userinfo;
- $user_id = $this->userinfo['user_id'];
- if (empty($tokenUser)) {
- return res(2, "TOKEN验证失败");
- } else {
- $res = $tokenUser;
- $res['avatar'] = !empty($res['avatar']) ? $res['avatar'] : sysconfig('account.default_avatar');
- $res['avatar_base64'] = file2base64(public_path() . $res['avatar']);
- }
- }
-
- $res['permissions'] = \app\common\model\base\user\User::getUserRole($user_id, 'auth', $this->token) ?? [];
- return res(1, "获取成功", $res ?? []);
- }
-
- public function doEdit()
- {
- $data = $this->request->param();
- $user_id = !empty($data['user_id']) ? $data['user_id'] : 0;
- $scene = !empty($user_id) ? 'edit' : 'add';
- $data['avatar'] = !empty($data['avatar']) ? $data['avatar'] : sysconfig('account.default_avatar');
-
- $check = validate(UserValidate::class)->scene($scene)->check($data);
- if (true !== $check) {
- return res(2, $check);
- }
-
- if (!empty($user_id)) {
-
- $phoneUsed = $this->userModel->where('phone', $data['phone'])->where('user_id', '<>', $user_id)->value('user_id');
- if (!empty($phoneUsed) && $phoneUsed != $user_id) {
- return res(2, "手机号已注册");
- }
-
- $accountUsed = $this->userModel->where('username', $data['username'])->where('user_id', '<>', $user_id)->value('user_id');
- if (!empty($accountUsed) && $accountUsed != $user_id) {
- return res(2, "账号已被使用");
- }
- if (isset($data['password'])) {
- unset($data['password']);
- }
- if (isset($data['salt'])) {
- unset($data['salt']);
- }
- $data['name'] = !empty($data['name']) ? $data['name'] : $data['nickname'];
- $info = $this->userModel->where('user_id', $user_id)->find();
- $params = [
- 'user' => [
- 'uuid' => $info['uuid'],
- 'name' => $data['name'],
- 'phone' => $data['phone'],
- 'sex' => $data['sex'],
- ],
- ];
- $res = (new platformAuth())->interfaceRequest('createAccount', $params);
- if (!$res['code']) return res(2, $res['msg']);
- $info->data($data, true);
- $info->save();
-
- $token = $this->token;
- if ($this->userinfo['user_id'] == $user_id) {
- Token::updateTokenUser($this->token);
- }
- }
- else {
-
- $data['create_uid'] = $this->userinfo['user_id'];
-
- $data['uuid'] = Uuid::uuid4()->toString();
-
- $phoneUsed = $this->userModel->where('phone', $data['phone'])->value('user_id');
- if (!empty($phoneUsed)) {
- return res(2, "手机号已注册");
- }
- $res = $this->userModel->create_user($data);
- if (is_string($res)) {
- return res(2, $res);
- }
- }
-
- if (1 == sysconfig('account.sync_corp')) {
-
- $developIds = $this->orgModel->where('org_type_code', 'in', ['SYSTEM', 'EXTERNAL'])->column('org_id');
- if (!in_array($data['org_id'], $developIds)) {
- $this->userModel->createCorpUser($user_id);
- }
- }
- if (empty($user_id)) {
- slog(1, "创建了用户" . $data['name']);
- } else {
- slog(1, '修改了用户' . $data['name']);
- }
- cache('USERLIST', null);
- return res(1, "保存成功", $data);
- }
-
- public function logout()
- {
- $token = $this->token;
- slog(1, "退出了系统");
- $this->tokenModel->losetoken($token);
- return Res(1, "成功退出");
- }
-
- public function resetPwd($user_id = '')
- {
- if (empty($user_id)) {
- return res(2, "参数错误");
- }
- $info = $this->userModel->where('user_id', $user_id)->find();
- $res = $this->userModel->resetPwd($user_id);
- if ($res) {
- slog(1, "重置了" . $info->username . "的密码");
- return res(1, "操作成功,密码已被重置为默认密码");
- } else {
- slog(2, "重置" . $info->username . "的密码失败");
- return res(2, "操作失败");
- }
- }
-
- public function changePwd($oldPwd = '', $newPwd = '', $renewPwd = '')
- {
-
- $PwdComplexity = UserModel::checkPwdComplexity($newPwd);
- if ($PwdComplexity['code'] == 2) {
- return json($PwdComplexity);
- }
- $userInfo = UserModel::find($this->userinfo['user_id']);
- if (empty($oldPwd) || empty($newPwd)) {
- return res(2, '原密码和新密码都不能为空');
- } elseif (empty($renewPwd)) {
- return res(2, '确认密码不能为空');
- } elseif ($newPwd != $renewPwd) {
- return res(2, "确认密码与新密码不一致");
- } elseif (strlen($newPwd) < 6) {
- return res(2, '密码不能少于6个字符');
- }
- $params = [
- 'user' => [
- 'uuid' => $userInfo->uuid,
- 'password' => $oldPwd,
- 'newPwd' => $renewPwd,
- ],
- ];
- $res = (new platformAuth())->interfaceRequest('createAccount', $params);
- if (!$res['code']) return res(2, $res['msg']);
- return res(1, "密码修改成功");
- }
-
- public function resetPwdByCode(string $mobile, string $newPassword, string $rePassword, string $code)
- {
- $mobile = trim($mobile);
- $newPassword = trim($newPassword);
- $rePassword = trim($rePassword);
- $code = trim($code);
- $PwdComplexity = UserModel::checkPwdComplexity($newPassword);
- if ($PwdComplexity['code'] == 2) {
- return json($PwdComplexity);
- }
- if (empty($mobile) || empty($newPassword) || empty($rePassword) || empty($code)) {
- return res(2, "重设密码失败");
- }
- if (trim($newPassword) != trim($rePassword)) {
- return res(2, "两次密码输入不一致");
- }
- if (!smsModel::check($mobile, $code)) {
- return res(2, "验证码错误或失效");
- }
- $userList = $this->userModel->where('phone', $mobile)->select();
- foreach ($userList as $userInfo) {
- $res = $this->userModel->resetPwd($userInfo->user_id, $newPassword);
- slog(1, "修改了" . $userInfo->username . "的密码");
- if ($res) {
- wssend($userInfo->user_id, 'changepwd', "您的帐号密码已修改,请重新登录!");
- }
- }
- return res(1, "操作成功,手机号为$mobile 的所有帐号密码都已修改");
- }
-
- public function changeMobile()
- {
- $data = $this->request->param();
- $in = ['phone' => $data['phone']];
- if ($this->userinfo['username'] == $this->userinfo['mobile']) {
- $in['username'] = $data['phone'];
- }
- $this->userModel->where('user_id', $this->userinfo['user_id'])->save($in);
- return res(1, "操作成功");
- }
-
- public function doDelete($ids)
- {
- $where = [];
- if (!is_array($ids)) {
- $ids = explode(',', $ids);
- }
- $where[] = ['user_id', 'IN', $ids];
- if (in_array($this->userinfo['user_id'], $ids)) {
- return res(2, '无法删除自己');
- }
- $list = $this->userModel->where($where)->select();
- try {
- UserModel::startTrans();
- foreach ($list as $item) {
- if ($item->role_code == $this->userinfo['role_code']) {
- UserModel::rollback();
- return res(2, "无法删除同级账号");
- }
- $result = $this->userModel->deleteUser($item->user_id);
- $item->delete();
- slog(1, "删除了用户" . $item->username);
- }
- cache('USERLIST', null);
- UserModel::commit();
- return res(1, "删除成功");
- } catch (\Exception $e) {
- UserModel::rollback();
- return res(2, "删除失败", $e->getMessage());
- }
- }
-
- public function changeStatus($ids = [], $status = 0)
- {
- $where = [];
- if (empty($ids)) {
- return res(2, "参数错误");
- }
- if (is_string($ids)) {
- $ids = explode(',', $ids);
- } elseif (is_int($ids)) {
- $ids = [$ids];
- }
- $where[] = ['user_id', 'IN', $ids];
- if (empty($status)) {
- UserModel::where($where)->update(['status' => Db::raw('ABS(3 * `status` - 5)')]);
- } else {
- UserModel::where($where)->update(['status' => $status]);
- }
-
- $userList = UserModel::where($where)->where('status', 2)->select();
- foreach ($userList as $item) {
- slog(1, "封禁了用户" . $item->username);
- }
-
- $userList = UserModel::where($where)->where('status', 1)->select();
- foreach ($userList as $info) {
- slog(1, "激活了用户" . $info->username);
- $info->trynum = 0;
- $info->save();
- }
- return res(1, "操作成功");
- }
-
- public function checkLogin($token = "")
- {
- $res = $this->checkToken($token);
- return res($res['code'], $res['msg']);
- }
-
- public function clearCache()
- {
- if (!$this->userinfo['is_developer']) {
- return res(2, "没有权限");
- }
- Cache::clear();
- return res(1, "清除成功");
- }
-
- public function getQrcode($user_id = 0)
- {
- $info = $this->userModel->where('user_id', $user_id)->find();
- if (empty($info)) {
- return res(2, "用户不存在");
- }
- $basepath = "qrcode" . DS . "user" . DS;
- $savepath = public_path() . $basepath;
- $filename = "user_" . $user_id . '.png';
- $fullpath = $savepath . $filename;
- if (!is_file($fullpath)) {
- $data = $this->createQrcode($user_id, $info->name);
- } else {
- $data = [
- 'filename' => $filename,
- 'savepath' => DS . $basepath . $filename,
- 'url' => WEBURL . DS . $basepath . $filename,
- ];
- }
- return res(1, "获取成功", $data);
- }
-
- public function createQrcode($user_id, $name = '')
- {
- $basepath = "qrcode" . DS . "user" . DS;
- $savepath = public_path() . $basepath;
- $filename = "user_" . $user_id . '.png';
- $fullpath = $savepath . $filename;
- if (!is_dir($savepath)) {
- mkdir($savepath, 0777, true);
- }
-
- include_once(root_path() . '/extend/phpqrcode/qrcode.php');
- $qrcode = CreateQRCode(WEBURL . '/index.php/index/pilot.user/info?user_id=' . $user_id, '400', $name, '', true, $fullpath);
-
- $data = [
- 'filename' => $filename,
- 'savepath' => DS . $basepath . $filename,
- 'url' => WEBURL . DS . $basepath . $filename,
- ];
- return $data;
- }
-
- public function captcha()
- {
- $content = parent::captcha();
- return response($content, 200, ['Content-Length' => strlen($content)])->contentType('image/png');
- }
-
- public function doExport()
- {
- $where = $this->createWhere();
- $list = $this->userModel->where($where)->with(['org'])->select();
- $rows = [];
- $header = array_values($this->importField);
- $rows[0] = $header;
- foreach ($list as $key => $item) {
- $index = $key + 1;
- foreach ($this->importField as $k => $v) {
- if ($k == 'role_id') {
- $rows[$index][] = $item['role']['name'];
- } elseif ($k == 'org_id') {
- $rows[$index][] = $item['org']['pathName'];
- } elseif ($k == 'sex') {
- $rows[$index][] = $item['sex_txt'];
- } else {
- $rows[$index][] = isset($item[$k . '_txt']) ? $item[$k . '_txt'] : $item[$k];
- }
- }
- }
-
- $basepath = "uploads" . DS . "download" . DS . date('Ymd');
- $savepath = public_path() . $basepath;
- if (!is_dir($savepath)) {
- mkdir($savepath, 0777, true);
- }
-
- require_once root_path() . "extend/excel/Excel.php";
- $filename = time() . GetRandStr() . ".xls";
- $fullpath = $savepath . DS . $filename;
- ArrayToXls($rows, $fullpath);
-
- $returnpath = WEBURL . DS . $basepath . DS . $filename;
- slog(1, "导出了用户列表");
- return res(1, "获取成功", ['url' => $returnpath, 'name' => $filename]);
- }
-
- protected $importField = [
- 'org_id' => '所属组织',
- 'name' => '姓名',
- 'sex' => '性别',
- 'phone' => '手机号',
- 'role_id' => '角色',
- 'fax' => '传真',
- 'username' => '帐号',
- 'remark' => '备注',
- ];
-
- public function saveSignImg($sign_img = '')
- {
- if (empty($sign_img)) {
- return res(2, "签名图片未上传");
- }
- if (strpos($sign_img, WEBURL)) {
- $sign_img = $sign_img;
- $old = public_path() . $this->userinfo['sign_img'];
- $new = public_path() . $sign_img;
- } else {
- $sign_img = str_replace(WEBURL, '', $sign_img);
- $old = public_path() . $this->userinfo['sign_img'];
- $new = public_path() . $sign_img;
- }
- if (is_file($new)) {
- $this->userinfo['sign_img'] = $sign_img;
- $this->userModel->replace()->save($this->userinfo);
- }
- if (is_file($old)) {
- unlink($old);
- }
- return res(1, "保存成功");
- }
-
- public function checkPwdComplexity(string $pwd = '')
- {
- $res = UserModel::checkPwdComplexity($pwd);
- return json($res);
- }
-
- public function getRouterList()
- {
- $fields = [
- 'menu_id',
- 'pid',
- 'name',
- 'title',
- 'path',
- 'component',
- 'redirect',
- 'icon',
- 'is_root',
- 'is_parent',
- 'affix',
- 'status',
- 'parent_path',
- 'sort',
- 'hidden',
- 'noKeepAlive',
- 'tabHidden',
- ];
- $where = [];
- $where[] = ['status', '=', 1];
- $whereOr = [];
- $whereOr[] = ['name', 'IN', ['Root', 'index', 'UserCenter', 'Homepage', 'Workbench', 'System']];
- if (!$this->userinfo['is_developer']) {
- $userInfo = $this->userinfo;
- $role_id = $userInfo['role_id'];
- $menu_ids = UserModel::getMenuIds($role_id);
- $where[] = ['menu_id', 'IN', $menu_ids];
- }
- $list = Menu::where($where)->whereOr($whereOr)->field($fields)->order('sort')->select()->toArray();
- foreach ($list as &$row) {
- $row['meta'] = [];
- $row['meta']['title'] = $row['title'];
- unset($row['title']);
- $row['meta']['icon'] = $row['icon'];
- unset($row['icon']);
- if (isset($row['hidden'])) {
- $row['meta']['hidden'] = $row['hidden'] == 1;
- unset($row['hidden']);
- }
- if (!empty($row['affix'])) {
- $row['meta']['affix'] = $row['affix'] == 1;
- unset($row['affix']);
- }
- if (!empty($row['dot'])) {
- $row['meta']['dot'] = $row['dot'] == 1;
- unset($row['dot']);
- }
- if (!empty($row['tabHidden'])) {
- $row['meta']['tabHidden'] = $row['tabHidden'] == 1;
- unset($row['tabHidden']);
- }
- if (!empty($row['noKeepAlive'])) {
- $row['meta']['noKeepAlive'] = $row['noKeepAlive'] == 1;
- unset($row['noKeepAlive']);
- }
- if (false !== strpos($row['path'], 'http')) {
- $row['meta']['target'] = '_blank';
- }
- }
- $list = array2tree($list, 'pid', 'menu_id');
- return res(1, '获取成功', $list);
- }
-
- public function getUserRole($user_id = 0)
- {
- if (empty($user_id)) {
- $user_id = $this->userinfo['user_id'];
- }
- UserRoleHandle::handleRole($user_id);
- $list = $this->userRoleModel->where('user_id', $user_id)->select();
- return res(1, '获取成功', $list);
- }
-
- public function changeOrg()
- {
- $org_id = input('org_id/d', "");
- $role_code = input('role_code/s', "");
- $userinfo = $this->userinfo;
- $token = $this->tokenModel->updatetoken($userinfo['user_id'], $org_id, $role_code);
- return res(1, '变更成功', $token);
- }
- }
|