ArticleCategoryDao.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\dao\article;
  12. use app\dao\BaseDao;
  13. use app\model\article\ArticleCategory;
  14. /**
  15. * 文章分类
  16. * Class ArticleCategoryDao
  17. * @package app\dao\article
  18. */
  19. class ArticleCategoryDao extends BaseDao
  20. {
  21. /**
  22. * 设置模型
  23. * @return string
  24. */
  25. protected function setModel(): string
  26. {
  27. return ArticleCategory::class;
  28. }
  29. /**
  30. * 获取文章分类列表
  31. * @param array $where
  32. * @param int $page
  33. * @param int $limit
  34. * @return mixed
  35. * @throws \ReflectionException
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\DbException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. */
  40. public function getList(array $where, int $page = 0, int $limit = 0)
  41. {
  42. return $this->search($where)->when(!$page && !$limit, function ($query) use ($page, $limit) {
  43. $query->page($page, $limit);
  44. })->order('sort desc,id desc')->select()->toArray();
  45. }
  46. /**
  47. * 前台获取文章分类
  48. * @return array
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\DbException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. */
  53. public function getArticleCategory()
  54. {
  55. return $this->search(['hidden' => 0, 'is_del' => 0, 'status' => 1, 'pid' => 0])->with(['children'])
  56. ->order('sort DESC,id DESC')
  57. ->field('id,pid,title')
  58. ->select()->toArray();
  59. }
  60. /**
  61. * 二级文章分类
  62. * @return array
  63. * @throws \think\db\exception\DataNotFoundException
  64. * @throws \think\db\exception\DbException
  65. * @throws \think\db\exception\ModelNotFoundException
  66. */
  67. public function getArticleTwoCategory()
  68. {
  69. return $this->getModel()
  70. ->where('hidden', 0)
  71. ->where('is_del', 0)
  72. ->where('status', 1)
  73. ->order('sort DESC,id DESC')
  74. ->field('id,pid,title')
  75. ->select()->toArray();
  76. }
  77. /**
  78. * 添加修改选择上级分类列表
  79. * @param array $where
  80. * @return array
  81. * @throws \ReflectionException
  82. */
  83. public function getMenus(array $where)
  84. {
  85. return $this->search($where)->order('sort desc,id desc')->column('title,pid,id,is_del,status');
  86. }
  87. /**
  88. * 树形列表
  89. * @param array $where
  90. * @param array $field
  91. * @return array
  92. * @throws \ReflectionException
  93. * @throws \think\db\exception\DataNotFoundException
  94. * @throws \think\db\exception\DbException
  95. * @throws \think\db\exception\ModelNotFoundException
  96. * @author: 吴汐
  97. * @email: 442384644@qq.com
  98. * @date: 2023/9/7
  99. */
  100. public function getTreeList(array $where, array $field)
  101. {
  102. return $this->search($where)->field($field)->order('sort desc,id desc')->select()->toArray();
  103. }
  104. }