Profile.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\admin\controller\general;
  3. use think\Session;
  4. use app\admin\model\AdminLog;
  5. use app\common\controller\Backend;
  6. use fast\Random;
  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. model('admin')->where('id', $this->auth->id)->update($params);
  59. //因为个人资料面板读取的Session显示,修改自己资料后同时更新Session
  60. $admin = Session::get('admin');
  61. $admin_id = $admin ? $admin->id : 0;
  62. if($this->auth->id==$admin_id){
  63. $admin = model('admin')->get(['id' => $admin_id]);
  64. Session::set("admin", $admin);
  65. }
  66. $this->success();
  67. }
  68. $this->error();
  69. }
  70. return;
  71. }
  72. }