Profile.php 2.1 KB

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