// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\common\model; use cores\BaseModel; /** * 学校图库模型类 * Class SchoolAlbum * @package app\common\model */ class SchoolAlbum extends BaseModel { protected $globalScope = ['']; // 定义表名 protected $name = 'school_album'; // 定义主键 protected $pk = 'album_id'; /** * 获取学校的图库列表 * @param $schoolId * @param int $limitRow * @return array|mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public static function getShowList($schoolId, $limitRow=0){ if($list = \think\facade\Cache::get('caches:schools:albums:'.$schoolId)){ return $list; } $query = self::where(['school_id'=>$schoolId]); if($limitRow){ $query->limit($limitRow); } $list = $query->field('album_id,title,album_url') ->order('album_id desc') ->select(); $list = $list? $list->toArray() :[]; if($list){ foreach ($list as &$item){ $item['image'] = $item['album_url']? getPreview($item['album_url']) : ''; } \think\facade\Cache::set('caches:schools:albums:'.$schoolId, $list, rand(5, 10)); } return $list; } }