|
|
@@ -15,6 +15,7 @@ use app\common\exception\BaseException;
|
|
|
use app\common\library\helper;
|
|
|
use app\common\model\Region;
|
|
|
use app\common\model\SchoolSpeciality as SchoolSpecialityModel;
|
|
|
+use think\facade\Cache;
|
|
|
|
|
|
/**
|
|
|
* 学校专业模型类
|
|
|
@@ -113,16 +114,27 @@ class SchoolSpeciality extends SchoolSpecialityModel
|
|
|
*/
|
|
|
public function getHots(int $school_id, $field='', $limit=3)
|
|
|
{
|
|
|
+ $cacheKey = "caches:speciality:hots:{$school_id}_{$limit}_".md5($school_id.$field);
|
|
|
+ $datas = Cache::get($cacheKey);
|
|
|
+ if($datas){
|
|
|
+ return $datas;
|
|
|
+ }
|
|
|
+
|
|
|
$where = ['status'=>1];
|
|
|
if($school_id){
|
|
|
$where['school_id'] = $school_id;
|
|
|
}
|
|
|
|
|
|
- return $this->where($where)
|
|
|
+ $datas = $this->where($where)
|
|
|
->field($field?:'speciality_id,speciality_name,school_id,recruit_num')
|
|
|
->order('views desc,speciality_id desc')
|
|
|
->limit($limit?? 3)
|
|
|
->select()??[];
|
|
|
+ if($datas){
|
|
|
+ Cache::set($cacheKey, $datas, rand(5, 10));
|
|
|
+ }
|
|
|
+
|
|
|
+ return $datas;
|
|
|
}
|
|
|
|
|
|
/**
|