Profile.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. $params = $this->request->post("row/a");
  47. $params = array_filter(array_intersect_key(
  48. $params,
  49. array_flip(array('email', 'nickname', 'password', 'avatar'))
  50. ));
  51. unset($v);
  52. if (isset($params['password'])) {
  53. $params['salt'] = Random::alnum();
  54. $params['password'] = md5(md5($params['password']) . $params['salt']);
  55. }
  56. if ($params) {
  57. $admin = Admin::get($this->auth->id);
  58. $admin->save($params);
  59. //因为个人资料面板读取的Session显示,修改自己资料后同时更新Session
  60. Session::set("admin", $admin->toArray());
  61. $this->success();
  62. }
  63. $this->error();
  64. }
  65. return;
  66. }
  67. }