No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Profile.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Yzncms [ 御宅男工作室 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018 http://yzncms.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 御宅男 <530765310@qq.com>
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 个人资料
  13. // +----------------------------------------------------------------------
  14. namespace app\admin\controller\general;
  15. use app\admin\model\Adminlog as AdminlogModel;
  16. use app\admin\model\AdminUser;
  17. use app\common\controller\Adminbase;
  18. use think\facade\Session;
  19. use think\facade\Validate;
  20. class Profile extends Adminbase
  21. {
  22. public function index()
  23. {
  24. if ($this->request->isAjax()) {
  25. $this->modelClass = new AdminlogModel;
  26. [$page, $limit, $where, $sort, $order] = $this->buildTableParames();
  27. $count = $this->modelClass
  28. ->where($where)
  29. ->where('admin_id', (int) $this->auth->id)
  30. ->order($sort, $order)
  31. ->count();
  32. $list = $this->modelClass
  33. ->where($where)
  34. ->where('admin_id', (int) $this->auth->id)
  35. ->order($sort, $order)
  36. ->page($page, $limit)
  37. ->select();
  38. $result = ["code" => 0, 'count' => $count, 'data' => $list];
  39. return json($result);
  40. }
  41. return $this->fetch();
  42. }
  43. //更新个人信息
  44. public function update()
  45. {
  46. if ($this->request->isPost()) {
  47. $this->token();
  48. $params = $this->request->post();
  49. $params['id'] = $this->auth->id;
  50. $rule = [
  51. 'email|邮箱' => 'require|email|unique:admin',
  52. 'mobile|手机' => 'mobile|unique:admin',
  53. ];
  54. $result = $this->validate($params, $rule);
  55. if (true !== $result) {
  56. $this->error($result);
  57. }
  58. if (isset($params['password']) && $params['password']) {
  59. if (!Validate::regex($params['password'], "/^[\S]{6,16}$/")) {
  60. $this->error('密码长度必须在6-16位之间,不能包含空格');
  61. }
  62. $data = encrypt_password($params['password']);
  63. $params['encrypt'] = $data['encrypt'];
  64. $params['password'] = $data['password'];
  65. } else {
  66. unset($params['password'], $params['encrypt']);
  67. }
  68. if ($params) {
  69. $admin = AdminUser::get($this->auth->id);
  70. $admin->save($params);
  71. //因为个人资料面板读取的Session显示,修改自己资料后同时更新Session
  72. Session::set("admin", $admin->toArray());
  73. Session::set("admin.safecode", $this->auth->getEncryptSafecode($admin));
  74. $this->success('修改成功!');
  75. }
  76. $this->error();
  77. }
  78. return;
  79. }
  80. }