|
|
@@ -113,13 +113,41 @@ class SchoolSpeciality extends SchoolSpecialityModel
|
|
|
*/
|
|
|
public function getHots(int $school_id, $field='', $limit=3)
|
|
|
{
|
|
|
- return $this->where(['school_id'=>$school_id,'status'=>1])
|
|
|
+ $where = ['status'=>1];
|
|
|
+ if($school_id){
|
|
|
+ $where['school_id'] = $school_id;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->where($where)
|
|
|
->field($field?:'speciality_id,speciality_name,school_id,recruit_num')
|
|
|
->order('views desc,speciality_id desc')
|
|
|
->limit($limit?? 3)
|
|
|
->select()??[];
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取学校的专业
|
|
|
+ * @param string $name 专业名称
|
|
|
+ * @param string $field 返回字段
|
|
|
+ * @return SchoolSpeciality[]|array|\think\Collection
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function getDataByName(string $name, $field='')
|
|
|
+ {
|
|
|
+ $data = $this->where(['status'=>1])
|
|
|
+ ->where('speciality_name','like', "%{$name}%")
|
|
|
+ ->field($field?:'speciality_id,speciality_name,school_id,recruit_num')
|
|
|
+ ->order('views desc,speciality_id desc')
|
|
|
+ ->find();
|
|
|
+ if($data['speciality_id']){
|
|
|
+ $bookNum = SpecialityBook::getBooks($data['speciality_id']);
|
|
|
+ $data['book_num'] = intval($bookNum);
|
|
|
+ $data['remainder_num'] = max(0,$data['recruit_num'] - $bookNum);
|
|
|
+ }
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 获取详情并累计访问次数
|