User.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2021 勾股工作室
  4. * @license https://opensource.org/licenses/Apache-2.0
  5. * @link https://www.gougucms.com
  6. */
  7. declare (strict_types = 1);
  8. namespace app\home\controller;
  9. use app\home\BaseController;
  10. use think\facade\Db;
  11. use think\facade\View;
  12. class User extends BaseController
  13. {
  14. public function index()
  15. {
  16. $uid = get_login_user('id');
  17. $userInfo = Db::name('User')->where(['id' => $uid])->find();
  18. $userInfo['showname'] = empty($userInfo['nickname']) ? $userInfo['username'] : $userInfo['nickname'];
  19. $userInfo['level_title'] = Db::name('UserLevel')->where(['id' => $userInfo['level']])->value('title');
  20. $userInfo['sex'] = ($userInfo['sex'] == 1) ? '男' : '女';
  21. add_user_log('view', '个人中心');
  22. View::assign('userInfo', $userInfo);
  23. return view();
  24. }
  25. public function info_edit()
  26. {
  27. $uid = get_login_user('id');
  28. $userInfo = Db::name('User')->where(['id' => $uid])->find();
  29. $userInfo['birthday'] = $userInfo['birthday']==0 ? '' : date('Y-m-d', $userInfo['birthday']);
  30. add_user_log('view', '个人信息');
  31. View::assign('userInfo', $userInfo);
  32. return view();
  33. }
  34. public function edit_submit()
  35. {
  36. $param = get_params();
  37. $param['birthday'] = strtotime($param['birthday']);
  38. $param['update_time'] = time();
  39. $res = Db::name('User')->where(['id' => $param['id']])->strict(false)->field(true)->update($param);
  40. if ($res !== false) {
  41. add_user_log('edit', '个人信息', $param['id'], $param);
  42. to_assign(0, '操作成功');
  43. } else {
  44. to_assign(1, '操作失败');
  45. }
  46. }
  47. }