Profile.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. if ($this->request->isAjax())
  20. {
  21. $model = model('AdminLog');
  22. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  23. $total = $model
  24. ->where($where)
  25. ->where('admin_id', $this->auth->id)
  26. ->order($sort, $order)
  27. ->count();
  28. $list = $model
  29. ->where($where)
  30. ->where('admin_id', $this->auth->id)
  31. ->order($sort, $order)
  32. ->limit($offset, $limit)
  33. ->select();
  34. $result = array("total" => $total, "rows" => $list);
  35. return json($result);
  36. }
  37. return $this->view->fetch();
  38. }
  39. /**
  40. * 更新个人信息
  41. */
  42. public function update()
  43. {
  44. if ($this->request->isPost())
  45. {
  46. $this->code = -1;
  47. $params = $this->request->post("row/a");
  48. $params = array_filter(array_intersect_key($params, array_flip(array('email', 'nickname', 'password', 'avatar'))));
  49. unset($v);
  50. if (isset($params['password']))
  51. {
  52. $params['salt'] = Random::alnum();
  53. $params['password'] = md5(md5($params['password']) . $params['salt']);
  54. }
  55. if ($params)
  56. {
  57. model('admin')->where('id', $this->auth->id)->update($params);
  58. //因为个人资料面板读取的Session显示,修改自己资料后同时更新Session
  59. $admin = Session::get('admin');
  60. $admin_id = $admin ? $admin->id : 0;
  61. if($this->auth->id==$admin_id){
  62. $admin = model('admin')->get(['id' => $admin_id]);
  63. Session::set("admin", $admin);
  64. }
  65. $this->code = 1;
  66. }
  67. }
  68. return;
  69. }
  70. }