School.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\model\School as SchoolModel;
  4. use app\api\model\SchoolNew;
  5. use app\api\model\UserDynamic;
  6. use app\api\service\User as UserService;
  7. use app\common\model\SchoolAlbum;
  8. /**
  9. * 学校控制器
  10. * Class School
  11. * @package app\api\controller
  12. */
  13. class School extends Controller
  14. {
  15. /**
  16. * 学校列表
  17. * @return \think\response\Json
  18. * @throws \think\db\exception\DbException
  19. */
  20. public function list()
  21. {
  22. // 获取列表数据
  23. $model = new SchoolModel();
  24. $pageSize = $this->request->param('pageSize', 15);
  25. $list = $model->getList($this->request->param(), $pageSize);
  26. return $this->renderSuccess(compact('list'));
  27. }
  28. /**
  29. * 选项列表
  30. * @return \think\response\Json
  31. * @throws \think\db\exception\DbException
  32. */
  33. public function options()
  34. {
  35. $model = new SchoolModel();
  36. $list = $model->getOptionList($this->request->param());
  37. return $this->renderSuccess(compact('list'));
  38. }
  39. /**
  40. * 获取学校主页数据
  41. * @return \think\response\Json
  42. * @throws \cores\exception\BaseException
  43. * @throws \think\db\exception\DataNotFoundException
  44. * @throws \think\db\exception\DbException
  45. * @throws \think\db\exception\ModelNotFoundException
  46. */
  47. public function homeData()
  48. {
  49. $schoolId = $this->request->param('school_id', 0);
  50. if($schoolId<=0){
  51. $userInfo = UserService::getCurrentLoginUser(true);
  52. $schoolId = isset($userInfo['info']['school_id'])? intval($userInfo['info']['school_id']) : 0;
  53. $userType = isset($userInfo['user_type'])? $userInfo['user_type'] : 0;
  54. $schoolId = $userType != 3? 0 : $schoolId;
  55. }
  56. if($schoolId <= 0){
  57. return $this->renderSuccess('您无权访问或未绑定学校信息,请先绑定');
  58. }
  59. $data = [
  60. 'info'=> SchoolModel::detail($schoolId),
  61. 'albums'=> SchoolAlbum::getShowList($schoolId, 6),
  62. 'news'=> SchoolNew::getShowList($schoolId, 1, 3),
  63. 'scenery'=> SchoolNew::getShowList($schoolId, 2, 6)
  64. ];
  65. return $this->renderSuccess($data);
  66. }
  67. /**
  68. * 校园时态
  69. * @return \think\response\Json
  70. * @throws \think\db\exception\DbException
  71. */
  72. public function dynamic(){
  73. $model = new UserDynamic();
  74. $list = $model->getList($this->request->param());
  75. return $this->renderSuccess(compact('list'));
  76. }
  77. }