User.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace addons\cms\controller;
  3. use think\Config;
  4. /**
  5. * 会员个人主页控制器
  6. */
  7. class User extends Base
  8. {
  9. public function index()
  10. {
  11. $config = get_addon_config('cms');
  12. if (!$config['userpage']) {
  13. $this->error("会员主页功能已关闭");
  14. }
  15. $user_id = $this->request->param('id');
  16. $user = \app\common\model\User::get($user_id);
  17. if (!$user) {
  18. $this->error("未找到指定会员");
  19. }
  20. if ($user['status'] == 'hidden') {
  21. $this->error("暂时无法浏览");
  22. }
  23. $pathArr = explode('/', $this->request->pathinfo());
  24. $type = end($pathArr);
  25. $type = is_numeric($type) || !in_array($type, ['archives', 'comment']) ? 'archives' : $type;
  26. $pagesize = 10;
  27. $page = $this->request->get('page/d', 1);
  28. $page = max(1, $page);
  29. if ($type == 'archives') {
  30. $archivesList = \addons\cms\model\Archives::with(['user', 'channel'])
  31. ->where('user_id', $user['id'])
  32. ->where('status', '<>', 'hidden')
  33. ->order('id', 'desc')
  34. ->paginate($pagesize, $config['pagemode'] == 'simple', ['type' => '\\addons\\cms\\library\\Bootstrap', 'var_page' => 'page', 'fragment' => '']);
  35. $this->view->assign('archivesList', $archivesList);
  36. $this->view->assign('__PAGELIST__', $archivesList);
  37. if ($this->request->isAjax()) {
  38. $this->success("", "", $this->view->fetch('common/list_item_ajax'));
  39. }
  40. } else {
  41. $commentList = \addons\cms\model\Comment::with(['user'])
  42. ->where('user_id', $user['id'])
  43. ->where('status', '<>', 'hidden')
  44. ->order('id', 'desc')
  45. ->paginate($pagesize, $config['pagemode'] == 'simple', ['type' => '\\addons\\cms\\library\\Bootstrap', '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. $statistics = [
  54. 'archives' => \addons\cms\model\Archives::where('user_id', $user['id'])->where('status', '<>', 'hidden')->count(),
  55. 'comments' => \addons\cms\model\Comment::where('user_id', $user['id'])->where('status', '<>', 'hidden')->count(),
  56. ];
  57. $this->view->assign('statistics', $statistics);
  58. $this->view->assign('title', ($this->auth->id == $user['id'] ? '我' : 'TA') . $title);
  59. $this->view->assign('page', $page);
  60. $this->view->assign('type', $type);
  61. $this->view->assign('__USER__', $user);
  62. return $this->view->fetch("/user");
  63. }
  64. }