| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace app\common\service;
- use app\common\model\SystemArticleModel;
- use utils\RedisCache;
- /**
- * 文章服务 by wes
- * Class ArticleService
- * @package app\common\service
- */
- class ArticleService
- {
- protected static $instance = null;
- protected $model = null;
- public function __construct()
- {
- $this->model = new SystemArticleModel();
- }
- /**
- * 静态化入口
- * @return static|null
- */
- public static function make()
- {
- if(!self::$instance){
- self::$instance = new static();
- }
- return self::$instance;
- }
- /**
- * 按类型获取列表
- * @param $groupKey 分组
- * @return array|mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getListByType($type)
- {
- $cacheKey = "caches:articles:list_{$type}";
- $data = RedisCache::get($cacheKey);
- if($data){
- return $data;
- }
- $where = ['type'=> $type];
- $data = $this->model->where($where)
- ->where('id', 'not in', '6,7')
- ->order('create_time desc')
- ->select();
- $data = $data? $data->toArray():[];
- if($data){
- RedisCache::set($cacheKey, $data, rand(10,20));
- }
- return $data;
- }
- }
|