SchoolSpeciality.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\model\School;
  4. use app\api\model\SchoolSpeciality as SchoolSpecialityModel;
  5. use think\response\Json;
  6. /**
  7. * 学校专业控制器
  8. * Class SchoolSpeciality
  9. * @package app\api\controller
  10. */
  11. class SchoolSpeciality extends Controller
  12. {
  13. /**
  14. * 学校列表
  15. * @return \think\response\Json
  16. * @throws \think\db\exception\DbException
  17. */
  18. public function list()
  19. {
  20. // 获取列表数据
  21. $model = new SchoolSpecialityModel;
  22. $pageSize = $this->request->param('pageSize', 12);
  23. $list = $model->getList($this->request->param(), $pageSize);
  24. return $this->renderSuccess(compact('list'));
  25. }
  26. /**
  27. * 文章详情
  28. * @param int $articleId
  29. * @return array|\think\response\Json
  30. * @throws \app\common\exception\BaseException
  31. */
  32. public function detail(int $id)
  33. {
  34. $detail = SchoolSpecialityModel::getDetail($id);
  35. return $this->renderSuccess(compact('detail'));
  36. }
  37. /**
  38. * 同类专业学校
  39. * @return Json
  40. * @throws \think\db\exception\DbException
  41. */
  42. public function sameList()
  43. {
  44. // 获取列表数据
  45. $model = new School;
  46. $pageSize = $this->request->param('pageSize', 12);
  47. $list = $model->getListBySpeciality($this->request->param(), $pageSize);
  48. return $this->renderSuccess(compact('list'));
  49. }
  50. /**
  51. * 获取热门专业
  52. * @return Json
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\DbException
  55. * @throws \think\db\exception\ModelNotFoundException
  56. */
  57. public function hots(){
  58. $limit = $this->request->param('limit', 6);
  59. $list = (new SchoolSpecialityModel)->getHots(0,'speciality_id,speciality_name,views', (int)$limit);
  60. return $this->renderSuccess(compact('list'));
  61. }
  62. }