// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\common\model; use cores\BaseModel; /** * 学校图库模型类 * Class SchoolNew * @package app\common\model */ class SchoolNew extends BaseModel { protected $globalScope = ['']; // 定义表名 protected $name = 'school_news'; // 定义主键 protected $pk = 'news_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, $type = 1, $limitRow=0){ $cacheKey = "caches:schools:news:{$schoolId}_{$type}_{$limitRow}"; if($list = \think\facade\Cache::get($cacheKey)){ return $list; } $query = self::where(['school_id'=>$schoolId, 'type'=> $type, 'status'=>1]); if($limitRow){ $query->limit($limitRow); } $list = $query->order('addtime desc,news_id desc')->select(); $list->hidden(['content','update_time','status']); $list = $list? $list->toArray() :[]; if($list){ foreach ($list as &$item){ $item['logo_preview'] = $item['logo']? getPreview($item['logo']) : ''; $item['publish_time'] = $item['addtime']? date('Y/m/d', strtotime($item['addtime'])) : ''; } \think\facade\Cache::set($cacheKey, $list, rand(10, 30)); } return $list; } public function getList($where, $limitRow= 15){ } }