Profile.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * ----------------------------------------------------------------------------
  4. * 行到水穷处,坐看云起时
  5. * 开发软件,找贵阳云起信息科技,官网地址:https://www.56q7.com/
  6. * ----------------------------------------------------------------------------
  7. * Author: 老成
  8. * email:85556713@qq.com
  9. */
  10. declare(strict_types=1);
  11. namespace app\admin\controller\general;
  12. use app\common\model\Admin;
  13. use app\common\controller\Backend;
  14. use app\common\model\AdminLog;
  15. use think\annotation\route\Group;
  16. use think\annotation\route\Route;
  17. use think\facade\Session;
  18. use think\facade\Validate;
  19. /**
  20. * 个人信息
  21. */
  22. #[Group("general/profile")]
  23. class Profile extends Backend
  24. {
  25. protected $noNeedRight='*';
  26. protected $relationField=[];
  27. public function _initialize()
  28. {
  29. parent::_initialize();
  30. $this->model=new AdminLog();
  31. }
  32. /**
  33. * 查看
  34. */
  35. #[Route("*",'index')]
  36. public function index()
  37. {
  38. if (false === $this->request->isAjax()) {
  39. $thirdLogin=addons_installed('uniapp') && site_config("uniapp.scan_login");
  40. $field='id,username,nickname,mobile,avatar';
  41. if($thirdLogin){
  42. $field.=',third_id';
  43. }
  44. $this->assign('thirdLogin',$thirdLogin);
  45. $this->assign('admininfo',Admin::field($field)->find($this->auth->id));
  46. return $this->fetch();
  47. }
  48. $where=[];
  49. if(!$this->auth->isSuperAdmin()){
  50. $where[]=['admin_id','=',$this->auth->id];
  51. }
  52. [$where, $order, $limit, $with] = $this->buildparams($where);
  53. $list = $this->model
  54. ->where($where)
  55. ->order($order)
  56. ->paginate($limit);
  57. $result = ['total' => $list->total(), 'rows' => $list->items()];
  58. return json($result);
  59. }
  60. /**
  61. * 更新个人信息
  62. */
  63. #[Route("POST",'update')]
  64. public function update()
  65. {
  66. $params = $this->request->post("row/a");
  67. if(!empty($params['password'])){
  68. if (!Validate::is($params['password'], '\S{6,30}')) {
  69. $this->error(__('密码长度不对!'));
  70. }
  71. $params['salt'] = str_rand(4);
  72. $params['password'] = md5(md5($params['password']) . $params['salt']);
  73. }else{
  74. unset($params['password']);
  75. }
  76. $admin=Admin::find($this->auth->id);
  77. $admin->save($params);
  78. Session::set('admin.mobile',$params['mobile']);
  79. Session::set('admin.nickname',$params['nickname']);
  80. Session::set('admin.avatar',$params['avatar']);
  81. Session::save();
  82. $this->success();
  83. }
  84. }