| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- <?php
- // +----------------------------------------------------------------------
- // | saiadmin [ saiadmin快速开发框架 ]
- // +----------------------------------------------------------------------
- // | Author: sai <1430792918@qq.com>
- // +----------------------------------------------------------------------
- namespace plugin\saiadmin\app\controller\system;
- use plugin\saiadmin\app\cache\UserAuthCache;
- use plugin\saiadmin\basic\BaseController;
- use plugin\saiadmin\app\cache\UserInfoCache;
- use plugin\saiadmin\app\logic\system\SystemUserLogic;
- use plugin\saiadmin\app\validate\system\SystemUserValidate;
- use support\Request;
- use support\Response;
- /**
- * 用户信息控制器
- */
- class SystemUserController extends BaseController
- {
- /**
- * 构造
- */
- public function __construct()
- {
- $this->logic = new SystemUserLogic();
- $this->validate = new SystemUserValidate;
- parent::__construct();
- }
- /**
- * 数据列表
- * @param Request $request
- * @return Response
- */
- public function index(Request $request) : Response
- {
- $where = $request->more([
- ['username', ''],
- ['phone', ''],
- ['email', ''],
- ['status', ''],
- ['dept_id', ''],
- ['create_time', ''],
- ]);
- $query = $this->logic->search($where);
- $query->auth([
- 'id' => $this->adminId,
- 'dept' => $this->adminInfo['deptList']
- ]);
- $query->field([
- 'sa_system_user.id' => 'id',
- 'sa_system_user.nickname' => 'nickname',
- 'sa_system_user.username' => 'username',
- 'sa_system_user.phone' => 'phone',
- 'sa_system_user.email' => 'email',
- 'sa_system_user.status' => 'status',
- 'sa_system_user.dept_id' => 'dept_id',
- 'sa_system_user.create_time' => 'create_time',
- 'sa_system_dept.name' => 'dept_name',
- 'GROUP_CONCAT(sa_system_user_role.role_id)' => 'role_id',
- 'GROUP_CONCAT(sa_system_role.name)' => 'role_name',
- 'sa_system_user.ad_permission' => 'ad_permission',
- 'sa_system_user.normal_game_list' => 'normal_game_list'
- ]);
- $query->leftJoin('sa_system_user_role', 'sa_system_user.id = sa_system_user_role.user_id');
- $query->leftJoin('sa_system_dept', 'sa_system_user.dept_id = sa_system_dept.id');
- $query->leftJoin('sa_system_role', 'sa_system_user_role.role_id = sa_system_role.id');
- $query->group('sa_system_user.id');
-
- $data = $this->logic->getList($query);
-
- return $this->success($data);
- }
- /**
- * 修改状态
- * @param Request $request
- * @return Response
- */
- public function changeStatus(Request $request) : Response
- {
- $id = $request->input('id', '');
- $status = $request->input('status', 1);
- $model = $this->logic->findOrEmpty($id);
- if ($model->isEmpty()) {
- return $this->fail('未查找到信息');
- }
- $result = $model->save(['status' => $status]);
- if ($result) {
- $this->afterChange('changeStatus', $model);
- return $this->success('操作成功');
- } else {
- return $this->fail('操作失败');
- }
- }
- /**
- * 更新资料
- * @param Request $request
- * @return Response
- */
- public function updateInfo(Request $request) : Response
- {
- $data = $request->post();
- unset($data['deptList']);
- unset($data['postList']);
- unset($data['roleList']);
- $result = $this->logic->update($data, ['id' => $this->adminId], ['nickname', 'phone', 'signed', 'email', 'avatar', 'backend_setting']);
- if ($result) {
- $userInfoCache = new UserInfoCache($this->adminId);
- $userInfoCache->clearUserInfo();
- $userAuthCache = new UserAuthCache($this->adminId);
- $userAuthCache->clearUserCache();
- return $this->success('操作成功');
- } else {
- return $this->fail('操作失败');
- }
- }
- /**
- * 修改密码
- * @param Request $request
- * @return Response
- */
- public function modifyPassword(Request $request) : Response
- {
- $oldPassword = $request->input('oldPassword');
- $newPassword = $request->input('newPassword');
- $this->logic->modifyPassword($this->adminId, $oldPassword, $newPassword);
- $userInfoCache = new UserInfoCache($this->adminId);
- $userInfoCache->clearUserInfo();
- $userAuthCache = new UserAuthCache($this->adminId);
- $userAuthCache->clearUserCache();
- return $this->success('修改成功');
- }
- /**
- * 清理用户缓存
- * @param Request $request
- * @return Response
- */
- public function clearCache(Request $request) : Response
- {
- $id = $request->post('id', '');
- $userInfoCache = new UserInfoCache($id);
- $userInfoCache->clearUserInfo();
- $userAuthCache = new UserAuthCache($id);
- $userAuthCache->clearUserCache();
- return $this->success('操作成功');
- }
- /**
- * 重置密码
- * @param Request $request
- * @return Response
- */
- public function initUserPassword(Request $request) : Response
- {
- $id = $request->post('id', '');
- if ($id == 1) {
- return $this->fail('超级管理员不允许重置密码');
- }
- $data = ['password' => password_hash('sai123456', PASSWORD_DEFAULT)];
- $this->logic->authEdit($id, $data);
- $userInfoCache = new UserInfoCache($id);
- $userInfoCache->clearUserInfo();
- $userAuthCache = new UserAuthCache($id);
- $userAuthCache->clearUserCache();
- return $this->success('操作成功');
- }
- /**
- * 设置首页
- * @param Request $request
- * @return Response
- */
- public function setHomePage(Request $request) : Response
- {
- $id = $request->post('id', '');
- $dashboard = $request->post('dashboard', '');
- $data = ['dashboard' => $dashboard];
- $this->logic->authEdit($id, $data);
- $userInfoCache = new UserInfoCache($id);
- $userInfoCache->clearUserInfo();
- $userAuthCache = new UserAuthCache($id);
- $userAuthCache->clearUserCache();
- return $this->success('操作成功');
- }
- /**
- * 设置用户权限
- * @param Request $request
- * @return Response
- */
- public function setUserPermission(Request $request) : Response
- {
- $id = $request->post('id');
- $game_list = $request->post('game_list');
- $normal_game_list = $request->post('normal_game_list');
- $ad_permission = $request->post('ad_permission');
- $data = [];
- if ($game_list) {
- $data['game_list'] = $game_list;
- }
- if ($normal_game_list) {
- $data['normal_game_list'] = $normal_game_list;
- }
- if($ad_permission!==null){
- $data['ad_permission'] = $ad_permission;
- }
-
- $this->logic->authEdit($id, $data);
- $userInfoCache = new UserInfoCache($id);
- $userInfoCache->clearUserInfo();
- $userAuthCache = new UserAuthCache($id);
- $userAuthCache->clearUserCache();
- return $this->success('操作成功');
- }
- }
|