NewsCategoryService.php 1.6 KB

1
  1. <?php /** * 信息分类服务 * @author wesmielr */ namespace app\index\service; use think\Db; class NewsCategoryService { /** * 获取资讯主分类 * @param int $num 条数 * @return array|\PDOStatement|string|\think\Collection * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public static function getCates($num=30){ $cacheKey = "cache:cates:list_".$num; $dataList = RedisService::get($cacheKey); if ($dataList) { return $dataList; } $dataList = Db::name('news_category') ->where('parent_id',0) ->field('id,catname,enname') ->order('list_order') ->limit($num) ->select(); $dataList = $dataList ? $dataList->toArray() : []; if ($dataList) { RedisService::set($cacheKey, $dataList, 3 * 3600); } return $dataList; } /** * 获取分类数据 * @param $ids * @return array|\PDOStatement|string|\think\Collection * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public static function getCatesListByIds($ids, $num=99999){ return Db::name('news_category') ->where('parent_id',0) ->whereIn('id',$ids) ->field('id,catname,enname') ->order('list_order') ->limit($num) ->select(); } }