User.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace addons\cms\controller;
  3. use addons\cms\model\SpiderLog;
  4. use think\Config;
  5. /**
  6. * 会员个人主页控制器
  7. * Class User
  8. * @package addons\cms\controller
  9. */
  10. class User extends Base
  11. {
  12. public function index()
  13. {
  14. $config = get_addon_config('cms');
  15. if (!$config['userpage']) {
  16. $this->error("会员主页功能已关闭");
  17. }
  18. $user_id = $this->request->param('id');
  19. $user = \app\common\model\User::get($user_id);
  20. if (!$user) {
  21. $this->error("未找到指定会员");
  22. }
  23. if ($user['status'] == 'hidden') {
  24. $this->error("暂时无法浏览");
  25. }
  26. $pathArr = explode('/', $this->request->pathinfo());
  27. $type = end($pathArr);
  28. $type = is_numeric($type) || !in_array($type, ['archives', 'comment']) ? 'archives' : $type;
  29. $pagesize = 10;
  30. $page = $this->request->get('page/d', 1);
  31. $page = max(1, $page);
  32. if ($type == 'archives') {
  33. $archivesList = \addons\cms\model\Archives::with(['user', 'channel'])
  34. ->where('user_id', $user['id'])
  35. ->where('status', 'normal')
  36. ->order('id', 'desc')
  37. ->paginate($pagesize, $config['pagemode'] == 'simple', ['var_page' => 'page', 'fragment' => '']);
  38. $this->view->assign('archivesList', $archivesList);
  39. $this->view->assign('__PAGELIST__', $archivesList);
  40. } else {
  41. $commentList = \addons\cms\model\Comment::with(['user'])
  42. ->where('user_id', $user['id'])
  43. ->where('status', 'normal')
  44. ->order('id', 'desc')
  45. ->paginate($pagesize, $config['pagemode'] == 'simple', ['var_page' => 'page', 'fragment' => '']);
  46. $collection = $commentList->getCollection();
  47. load_relation($collection, 'source');
  48. $this->view->assign('commentList', $commentList);
  49. $this->view->assign('__PAGELIST__', $commentList);
  50. }
  51. $title = $type == 'archives' ? '的文章' : '的评论';
  52. Config::set('cms.title', $user['nickname'] . $title);
  53. Config::set('cms.image', isset($user['avatar']) && $user['avatar'] ? cdnurl($user['avatar'], true) : '');
  54. SpiderLog::record('user', $user['id']);
  55. $statistics = [
  56. 'archives' => \addons\cms\model\Archives::where('user_id', $user['id'])->where('status', 'normal')->count(),
  57. 'comments' => \addons\cms\model\Comment::where('user_id', $user['id'])->where('status', 'normal')->count(),
  58. ];
  59. $this->view->assign('statistics', $statistics);
  60. $this->view->assign('title', ($this->auth->id == $user['id'] ? '我' : 'TA') . $title);
  61. $this->view->assign('page', $page);
  62. $this->view->assign('type', $type);
  63. $this->view->assign('__USER__', $user);
  64. if ($this->request->isAjax()) {
  65. $this->success("", "", $this->view->fetch('ajax/user'));
  66. }
  67. return $this->view->fetch("/user");
  68. }
  69. }