NewsCategoryService.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * 信息分类服务
  4. * @author wesmielr
  5. */
  6. namespace app\index\service;
  7. use think\Db;
  8. class NewsCategoryService
  9. {
  10. /**
  11. * 获取资讯主分类
  12. * @param int $num 条数
  13. * @return array|\PDOStatement|string|\think\Collection
  14. * @throws \think\db\exception\DataNotFoundException
  15. * @throws \think\db\exception\ModelNotFoundException
  16. * @throws \think\exception\DbException
  17. */
  18. public static function getCates($num=30){
  19. return Db::name('news_category')
  20. ->where('parent_id',0)
  21. ->field('id,catname,enname')
  22. ->order('list_order')
  23. ->limit($num)
  24. ->select();
  25. }
  26. /**
  27. * 获取分类数据
  28. * @param $ids
  29. * @return array|\PDOStatement|string|\think\Collection
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. * @throws \think\exception\DbException
  33. */
  34. public static function getCatesListByIds($ids, $num=99999){
  35. return Db::name('news_category')
  36. ->where('parent_id',0)
  37. ->whereIn('id',$ids)
  38. ->field('id,catname,enname')
  39. ->order('list_order')
  40. ->limit($num)
  41. ->select();
  42. }
  43. }