SchoolSpeciality.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\api\model;
  13. use app\common\model\SchoolSpeciality as SchoolSpecialityModel;
  14. /**
  15. * 学校专业模型类
  16. * Class SchoolSpeciality
  17. * @package app\api\model
  18. */
  19. class SchoolSpeciality extends SchoolSpecialityModel
  20. {
  21. protected $globalScope = [''];
  22. /**
  23. * 隐藏字段
  24. * @var array
  25. */
  26. protected $hidden = [
  27. 'update_time'
  28. ];
  29. /**
  30. * 获取学校的专业
  31. * @param int $school_id 学校ID
  32. * @param string $field 返回字段
  33. * @param int $limit 返回数量
  34. * @return SchoolSpeciality[]|array|\think\Collection
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\DbException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. */
  39. public function getHots(int $school_id, $field='', $limit=3)
  40. {
  41. return $this->where(['school_id'=>$school_id,'status'=>1])
  42. ->field($field?:'speciality_id,speciality_name,school_id,recruit_num')
  43. ->order('views desc,speciality_id desc')
  44. ->limit($limit?? 3)
  45. ->select()??[];
  46. }
  47. }