School.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\model\School as SchoolModel;
  4. use app\api\model\SchoolSpeciality;
  5. use app\api\model\SchoolNew;
  6. use app\api\model\UserDynamic;
  7. use app\api\service\User as UserService;
  8. use app\common\model\SchoolAlbum;
  9. /**
  10. * 学校控制器
  11. * Class School
  12. * @package app\api\controller
  13. */
  14. class School extends Controller
  15. {
  16. /**
  17. * 学校列表
  18. * @return \think\response\Json
  19. * @throws \think\db\exception\DbException
  20. */
  21. public function list()
  22. {
  23. // 获取列表数据
  24. $model = new SchoolModel();
  25. $pageSize = $this->request->param('pageSize', 15);
  26. $list = $model->getList($this->request->param(), $pageSize);
  27. return $this->renderSuccess(compact('list'));
  28. }
  29. /**
  30. * 选项列表
  31. * @return \think\response\Json
  32. * @throws \think\db\exception\DbException
  33. */
  34. public function options()
  35. {
  36. $model = new SchoolModel();
  37. $list = $model->getOptionList($this->request->param());
  38. return $this->renderSuccess(compact('list'));
  39. }
  40. /**
  41. * 获取学校主页数据
  42. * @return \think\response\Json
  43. * @throws \cores\exception\BaseException
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\DbException
  46. * @throws \think\db\exception\ModelNotFoundException
  47. */
  48. public function homeData()
  49. {
  50. $schoolId = $this->request->param('school_id', 0);
  51. if($schoolId<=0){
  52. $userInfo = UserService::getCurrentLoginUser(true);
  53. $schoolId = isset($userInfo['info']['school_id'])? intval($userInfo['info']['school_id']) : 0;
  54. $userType = isset($userInfo['user_type'])? $userInfo['user_type'] : 0;
  55. $schoolId = $userType != 3? 0 : $schoolId;
  56. }
  57. if($schoolId <= 0){
  58. return $this->renderSuccess('您无权访问或未绑定学校信息,请先绑定');
  59. }
  60. $data = [
  61. 'info'=> SchoolModel::detail((int)$schoolId),
  62. 'albums'=> SchoolAlbum::getShowList($schoolId, 6),
  63. 'news'=> SchoolNew::getShowList($schoolId, 1, 3),
  64. 'scenery'=> SchoolNew::getShowList($schoolId, 2, 6)
  65. ];
  66. return $this->renderSuccess($data);
  67. }
  68. /**
  69. * 校园时态
  70. * @return \think\response\Json
  71. * @throws \think\db\exception\DbException
  72. */
  73. public function dynamic(){
  74. $model = new UserDynamic();
  75. $schoolId = $this->request->param('school_id', 0);
  76. $userInfo = UserService::getCurrentLoginUser(true);
  77. $userId = isset($userInfo['user_id'])? intval($userInfo['user_id']) : 0;
  78. if($schoolId <= 0){
  79. return $this->renderSuccess('您无权访问或未绑定学校信息,请先绑定');
  80. }
  81. $list = $model->getListBySchool($schoolId, $userId, $this->request->param());
  82. return $this->renderSuccess(compact('list'));
  83. }
  84. /**
  85. * 校园专业时态
  86. * @return \think\response\Json
  87. * @throws \think\db\exception\DbException
  88. */
  89. public function specialityDynamic(){
  90. $model = new SchoolSpeciality;
  91. $schoolId = $this->request->param('school_id', 0);
  92. if($schoolId<=0){
  93. $userInfo = UserService::getCurrentLoginUser(true);
  94. $userId = isset($userInfo['user_id'])? intval($userInfo['user_id']) : 0;
  95. $schoolId = isset($userInfo['info']['school_id'])? intval($userInfo['info']['school_id']) : 0;
  96. $userType = isset($userInfo['user_type'])? $userInfo['user_type'] : 0;
  97. $schoolId = $userType != 3? 0 : $schoolId;
  98. }
  99. if($schoolId <= 0){
  100. return $this->renderSuccess('您无权访问或未绑定学校信息,请先绑定');
  101. }
  102. $list = $model->getList(['school_id'=> $schoolId]);
  103. return $this->renderSuccess(compact('list'));
  104. }
  105. /**
  106. * @return \think\response\Json
  107. * @throws \think\db\exception\DataNotFoundException
  108. * @throws \think\db\exception\DbException
  109. * @throws \think\db\exception\ModelNotFoundException
  110. */
  111. public function comparison()
  112. {
  113. $ids = $this->request->param('ids','');
  114. $ids = $ids? explode(',', $ids) : [];
  115. if(empty($ids)){
  116. return $this->renderSuccess('请先选择对比学校');
  117. }
  118. if(count($ids) > 3){
  119. return $this->renderSuccess('一次最多选择3个');
  120. }
  121. $model = new SchoolModel;
  122. $list = $model->getComparisonList($ids, 3);
  123. return $this->renderSuccess(compact('list'));
  124. }
  125. /**
  126. * 校园时态
  127. * @return \think\response\Json
  128. * @throws \think\db\exception\DbException
  129. */
  130. public function news(){
  131. $model = new SchoolNew();
  132. $pageSize = $this->request->param('pageSize', 15);
  133. $list = $model->getList($this->request->param(), (int)$pageSize);
  134. return $this->renderSuccess(compact('list'));
  135. }
  136. /**
  137. * 校园时态
  138. * @return \think\response\Json
  139. * @throws \think\db\exception\DbException
  140. */
  141. public function newsDetail(){
  142. $model = new SchoolNew();
  143. $info = $model->getDetail((int)$this->request->param('news_id'));
  144. return $this->renderSuccess(compact('info'));
  145. }
  146. }