Profile.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\admin\controller\general;
  3. use app\admin\model\AdminLog;
  4. use app\common\controller\Backend;
  5. use fast\Random;
  6. /**
  7. * 个人配置
  8. *
  9. * @icon fa fa-user
  10. */
  11. class Profile extends Backend
  12. {
  13. /**
  14. * 查看
  15. */
  16. public function index()
  17. {
  18. if ($this->request->isAjax())
  19. {
  20. $model = model('AdminLog');
  21. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  22. $total = $model
  23. ->where($where)
  24. ->order($sort, $order)
  25. ->count();
  26. $list = $model
  27. ->where($where)
  28. ->order($sort, $order)
  29. ->limit($offset, $limit)
  30. ->select();
  31. $result = array("total" => $total, "rows" => $list);
  32. return json($result);
  33. }
  34. return $this->view->fetch();
  35. }
  36. /**
  37. * 更新个人信息
  38. */
  39. public function update()
  40. {
  41. if ($this->request->isPost())
  42. {
  43. $this->code = -1;
  44. $params = $this->request->post("row/a");
  45. $params = array_filter(array_intersect_key($params, array_flip(array('email', 'nickname', 'password'))));
  46. unset($v);
  47. if (isset($params['password']))
  48. {
  49. $params['salt'] = Random::alnum();
  50. $params['password'] = md5(md5($params['password']) . $params['salt']);
  51. }
  52. if ($params)
  53. {
  54. model('admin')->where('id', $this->auth->id)->update($params);
  55. AdminLog::record(__('Update'), $params);
  56. $this->code = 1;
  57. }
  58. }
  59. return;
  60. }
  61. }