Profile.php 2.2 KB

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