statisticsUserService = $statisticsUserService; $this->authService = $authService; } public function index() { $lists = $this->statisticsUserService->getList(); $return_data = [ 'list' => $lists ]; return view('statistics.app.user.list', $return_data); } public function add(Request $request) { if (auth('web-statistics')->user()->username != 'admin') { return response()->json(array('status'=>0, 'error'=>'没有权限添加管理员,请联系超级管理员!')); } if ($request->method() == 'POST') { $username = $request->input('username', ''); $password = $request->input('password', ''); if (!$username || !$password) { return response()->json(array('status'=>0, 'error'=>'参数错误!')); } //判断用户名是否存在 if ($adminInfo = $this->statisticsUserService->getUserInfo(array('username'=>$username))) { return response()->json(array('status'=>0, 'error'=>'用户名已存在!')); } $insert_data = array( 'username' => $username, 'password' => bcrypt($password), 'name' => $username ); if ($this->statisticsUserService->createUserInfo($insert_data)) { return response()->json(array('status'=>1, 'html'=>'添加成功!')); } else { return response()->json(array('status'=>0, 'error'=>'添加失败!')); } } else { return view('statistics.app.user.add'); } } public function updatePassword(Request $request) { if ($request->method() == 'POST') { $password_old = $request->input('password_old', ''); $password = $request->input('password', ''); if (!$password_old) { return response()->json(array('status'=>0, 'error'=>'请填写原密码!')); } if (!$password) { return response()->json(array('status'=>0, 'error'=>'请填写新密码!')); } //检测旧密码是否正确 $pwd_rst = $this->authService->checkUser(auth('web-statistics')->user()->username, $password_old); if (!$pwd_rst) { return response()->json(array('status'=>0, 'error'=>'原密码错误!')); } $rst = $this->statisticsUserService->updateUserInfo(['password'=>bcrypt($password)], ['id'=>auth('web-statistics')->user()->id]); if ($rst) { return response()->json(array('status'=>1, 'html'=>'修改成功!')); } else { return response()->json(array('status'=>0, 'error'=>'修改失败!')); } } return view('statistics.app.user.update_password'); } public function edit(Request $request) { if (auth('web-statistics')->user()->username != 'admin') { return response()->json(array('status'=>0, 'error'=>'没有权限修改管理员信息,请联系超级管理员!')); } $uid = $request->input('uid', ''); if (!$uid) { return response()->json(array('status'=>0, 'error'=>'请选择用户!')); } $adminInfo = $this->statisticsUserService->getUserInfo(array('id'=>$uid)); if (!$adminInfo) { $return_data = array('status'=>0, 'error'=>'用户不存在,请重新选择!'); } else { $html_data = array( 'username' => $adminInfo->username, 'uid' => $uid ); $html = view('statistics.app.user.update_user', $html_data)->render(); $return_data = array('status'=>1, 'html'=>$html); } return response()->json($return_data); } public function updateByAdminPassword(Request $request) { $uid = $request->input('id', ''); $password = $request->input('password', ''); if (!$uid || !$password) { return response()->json(array('status'=>0, 'error'=>'参数错误!')); } $rst = $this->statisticsUserService->updateUserInfo(['password'=>bcrypt($password)], ['id'=>$uid]); if ($rst) { return response()->json(array('status'=>1, 'html'=>'修改成功!')); } else { return response()->json(array('status'=>0, 'error'=>'修改失败!')); } } public function delete(Request $request) { $id = $request->input('id', ''); if (!$id) { return response()->json(array('status'=>0, 'error'=>'请选择删除项!')); } if ($this->statisticsUserService->deleteUserInfo(['id'=>$id])) { return response()->json(array('status'=>1, 'html'=>'删除成功!')); } return response()->json(array('status'=>0, 'error'=>'删除失败!')); } }