School.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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($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. $userInfo = UserService::getCurrentLoginUser(true);
  92. $userId = isset($userInfo['user_id'])? intval($userInfo['user_id']) : 0;
  93. $schoolId = isset($userInfo['info']['school_id'])? intval($userInfo['info']['school_id']) : 0;
  94. $userType = isset($userInfo['user_type'])? $userInfo['user_type'] : 0;
  95. $schoolId = $userType != 3? 0 : $schoolId;
  96. if($schoolId <= 0){
  97. return $this->renderSuccess('您无权访问或未绑定学校信息,请先绑定');
  98. }
  99. $list = $model->getList(['school_id'=> $schoolId]);
  100. return $this->renderSuccess(compact('list'));
  101. }
  102. }