Profile.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace app\admin\controller\general;
  3. use app\admin\model\Admin;
  4. use app\common\controller\Backend;
  5. use fast\Random;
  6. use think\Session;
  7. /**
  8. * 个人配置
  9. *
  10. * @icon fa fa-user
  11. */
  12. class Profile extends Backend
  13. {
  14. /**
  15. * 查看
  16. */
  17. public function index()
  18. {
  19. //设置过滤方法
  20. $this->request->filter(['strip_tags']);
  21. if ($this->request->isAjax())
  22. {
  23. $model = model('AdminLog');
  24. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  25. $total = $model
  26. ->where($where)
  27. ->where('admin_id', $this->auth->id)
  28. ->order($sort, $order)
  29. ->count();
  30. $list = $model
  31. ->where($where)
  32. ->where('admin_id', $this->auth->id)
  33. ->order($sort, $order)
  34. ->limit($offset, $limit)
  35. ->select();
  36. $result = array("total" => $total, "rows" => $list);
  37. return json($result);
  38. }
  39. return $this->view->fetch();
  40. }
  41. /**
  42. * 更新个人信息
  43. */
  44. public function update()
  45. {
  46. if ($this->request->isPost())
  47. {
  48. $params = $this->request->post("row/a");
  49. $params = array_filter(array_intersect_key($params, array_flip(array('email', 'nickname', 'password', 'avatar'))));
  50. unset($v);
  51. if (isset($params['password']))
  52. {
  53. $params['salt'] = Random::alnum();
  54. $params['password'] = md5(md5($params['password']) . $params['salt']);
  55. }
  56. if ($params)
  57. {
  58. $admin = Admin::get($this->auth->id);
  59. $admin->save($params);
  60. //因为个人资料面板读取的Session显示,修改自己资料后同时更新Session
  61. Session::set("admin", $admin->toArray());
  62. $this->success();
  63. }
  64. $this->error();
  65. }
  66. return;
  67. }
  68. }