| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace app\api\controller;
- use app\api\model\School as SchoolModel;
- use app\api\model\SchoolSpeciality;
- use app\api\model\SchoolNew;
- use app\api\model\UserDynamic;
- use app\api\service\User as UserService;
- use app\common\model\SchoolAlbum;
- /**
- * 学校控制器
- * Class School
- * @package app\api\controller
- */
- class School extends Controller
- {
- /**
- * 学校列表
- * @return \think\response\Json
- * @throws \think\db\exception\DbException
- */
- public function list()
- {
- // 获取列表数据
- $model = new SchoolModel();
- $pageSize = $this->request->param('pageSize', 15);
- $list = $model->getList($this->request->param(), $pageSize);
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 选项列表
- * @return \think\response\Json
- * @throws \think\db\exception\DbException
- */
- public function options()
- {
- $model = new SchoolModel();
- $list = $model->getOptionList($this->request->param());
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 获取学校主页数据
- * @return \think\response\Json
- * @throws \cores\exception\BaseException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function homeData()
- {
- $schoolId = $this->request->param('school_id', 0);
- if($schoolId<=0){
- $userInfo = UserService::getCurrentLoginUser(true);
- $schoolId = isset($userInfo['info']['school_id'])? intval($userInfo['info']['school_id']) : 0;
- $userType = isset($userInfo['user_type'])? $userInfo['user_type'] : 0;
- $schoolId = $userType != 3? 0 : $schoolId;
- }
- if($schoolId <= 0){
- return $this->renderSuccess('您无权访问或未绑定学校信息,请先绑定');
- }
- $data = [
- 'info'=> SchoolModel::detail($schoolId),
- 'albums'=> SchoolAlbum::getShowList($schoolId, 6),
- 'news'=> SchoolNew::getShowList($schoolId, 1, 3),
- 'scenery'=> SchoolNew::getShowList($schoolId, 2, 6)
- ];
- return $this->renderSuccess($data);
- }
- /**
- * 校园时态
- * @return \think\response\Json
- * @throws \think\db\exception\DbException
- */
- public function dynamic(){
- $model = new UserDynamic();
- $schoolId = $this->request->param('school_id', 0);
- $userInfo = UserService::getCurrentLoginUser(true);
- $userId = isset($userInfo['user_id'])? intval($userInfo['user_id']) : 0;
- if($schoolId <= 0){
- return $this->renderSuccess('您无权访问或未绑定学校信息,请先绑定');
- }
- $list = $model->getListBySchool($schoolId, $userId, $this->request->param());
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 校园专业时态
- * @return \think\response\Json
- * @throws \think\db\exception\DbException
- */
- public function specialityDynamic(){
- $model = new SchoolSpeciality;
- $userInfo = UserService::getCurrentLoginUser(true);
- $userId = isset($userInfo['user_id'])? intval($userInfo['user_id']) : 0;
- $schoolId = isset($userInfo['info']['school_id'])? intval($userInfo['info']['school_id']) : 0;
- $userType = isset($userInfo['user_type'])? $userInfo['user_type'] : 0;
- $schoolId = $userType != 3? 0 : $schoolId;
- if($schoolId <= 0){
- return $this->renderSuccess('您无权访问或未绑定学校信息,请先绑定');
- }
- $list = $model->getList(['school_id'=> $schoolId]);
- return $this->renderSuccess(compact('list'));
- }
- }
|