Profile.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. $model = model('AdminLog');
  23. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  24. $total = $model
  25. ->where($where)
  26. ->where('admin_id', $this->auth->id)
  27. ->order($sort, $order)
  28. ->count();
  29. $list = $model
  30. ->where($where)
  31. ->where('admin_id', $this->auth->id)
  32. ->order($sort, $order)
  33. ->limit($offset, $limit)
  34. ->select();
  35. $result = array("total" => $total, "rows" => $list);
  36. return json($result);
  37. }
  38. return $this->view->fetch();
  39. }
  40. /**
  41. * 更新个人信息
  42. */
  43. public function update()
  44. {
  45. if ($this->request->isPost()) {
  46. $this->token();
  47. $params = $this->request->post("row/a");
  48. $params = array_filter(array_intersect_key(
  49. $params,
  50. array_flip(array('email', 'nickname', 'password', 'avatar'))
  51. ));
  52. unset($v);
  53. if (isset($params['password'])) {
  54. $params['salt'] = Random::alnum();
  55. $params['password'] = md5(md5($params['password']) . $params['salt']);
  56. }
  57. if ($params) {
  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. }