User.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\Base;
  4. use app\hander\HelpHander;
  5. use think\Db;
  6. class User extends Base
  7. {
  8. public function logout(){
  9. model('Token')->logout($this->userId);
  10. HelpHander::success([],'退出登录成功');
  11. }
  12. // 获取登录后信息
  13. public function userInfo(){
  14. $ret = model('User')->userinfo($this->userId,0);
  15. if($ret){
  16. HelpHander::success($ret);
  17. }else{
  18. HelpHander::error('用户信息获取失败');
  19. }
  20. }
  21. // 获取登录后信息 -- APP端
  22. public function appUserInfo(){
  23. $ret = model('User')->userinfo($this->userId,1);
  24. if($ret){
  25. HelpHander::success($ret);
  26. }else{
  27. HelpHander::error('用户信息获取失败');
  28. }
  29. }
  30. // 修改密码
  31. public function updatePassword(){
  32. $data = [
  33. 'account' => input('account','','trim'),
  34. 'password' => input('password','','trim'),
  35. 'newPassword' => input('newPassword','','trim'),
  36. ];
  37. $ret = model('User')->updatePassword($this->userId,$data);
  38. if($ret){
  39. $token = Db::name('token')->where('user_id',$this->userId)->find();
  40. HelpHander::success($token,'修改成功');
  41. }else{
  42. HelpHander::error('修改失败');
  43. }
  44. }
  45. // 重置密码
  46. public function resetPassword(){
  47. $id = input('id/d',0);
  48. $ret = model('User')->resetPassword($id);
  49. if($ret){
  50. HelpHander::success([],'操作成功');
  51. }else{
  52. HelpHander::error('操作失败');
  53. }
  54. }
  55. // 修改用户名
  56. public function updateAccount(){
  57. $account = input('account','','','trim');
  58. $ret = model('User')->updateAccount($this->userId,$account);
  59. if($ret){
  60. HelpHander::success([],'操作成功');
  61. }else{
  62. HelpHander::error('操作失败');
  63. }
  64. }
  65. // 根据用户ID获取组织列表
  66. public function queryOrgListByUserId(){
  67. $ret = model('Org')->queryOrgListByUserId($this->userId);
  68. HelpHander::success($ret);
  69. }
  70. // 获取组织下的所有人员
  71. public function queryUserListByOrg(){
  72. $ret = model('User')->queryUserListByOrg($this->orgId);
  73. HelpHander::success($ret);
  74. }
  75. // 根据用户和组织ID获取部门列表
  76. public function queryDepByUserId(){
  77. $ret = model('Dep')->queryUserListByOrg($this->orgId);
  78. HelpHander::success($ret);
  79. }
  80. // 获取指定组织下所有在职人员
  81. public function queryUserNameListOnTheJob(){
  82. $ret = model('User')->queryUserListByOrg($this->orgId);
  83. HelpHander::success($ret);
  84. }
  85. // 新版通讯录接口
  86. public function appAddressBook(){
  87. $ret = model('User')->appAddressBook($this->orgId);
  88. HelpHander::success($ret);
  89. }
  90. // 新版通讯录接口搜索
  91. public function selectUserTelList(){
  92. $keyword = input('keyWord','','trim');
  93. if(!$keyword){
  94. HelpHander::error('搜索关键词不能为空');
  95. }
  96. $ret = model('User')->selectUserTelList($this->orgId,$keyword);
  97. HelpHander::success($ret);
  98. }
  99. }