ArticleCategory.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace app\admin\model\article;
  3. use crmeb\traits\ModelTrait;
  4. use crmeb\basic\BaseModel;
  5. use app\admin\model\article\Article as ArticleModel;
  6. /**
  7. * 文章分类model
  8. * Class ArticleCategory
  9. * @package app\admin\model\wechat
  10. */
  11. class ArticleCategory extends BaseModel
  12. {
  13. use ModelTrait;
  14. protected $pk = 'id';
  15. protected $name = 'article_category';
  16. /**
  17. * 获取系统分页数据 分类
  18. * @param array $where
  19. * @return array
  20. */
  21. public static function systemPage($where = [])
  22. {
  23. $model = new self;
  24. if ($where['title'] !== '') $model = $model->where('title', 'LIKE', "%$where[title]%");
  25. if ($where['status'] !== '') $model = $model->where('status', $where['status']);
  26. $model = $model->where('is_del', 0);
  27. $model = $model->where('hidden', 0);
  28. return self::page($model);
  29. }
  30. /**
  31. * 删除分类
  32. * @param $id
  33. * @return bool
  34. */
  35. public static function delArticleCategory($id)
  36. {
  37. if (count(self::getArticle($id, '*')) > 0)
  38. return self::setErrorInfo('请先删除改分类下的文章!');
  39. return self::edit(['is_del' => 1], $id, 'id');
  40. }
  41. /**
  42. * 获取分类名称和id
  43. * @return array
  44. */
  45. public static function getField()
  46. {
  47. return self::where('is_del', 0)->where('status', 1)->where('hidden', 0)->column('title', 'id');
  48. }
  49. /**
  50. * 分级排序列表
  51. * @param null $model
  52. * @return array
  53. */
  54. public static function getTierList($model = null)
  55. {
  56. if ($model === null) $model = new self();
  57. return sort_list_tier($model->where('is_del', 0)->where('status', 1)->select()->toArray());
  58. }
  59. /**
  60. * 获取分类底下的文章
  61. * id 分类表中的分类id
  62. * return array
  63. * */
  64. public static function getArticle($id, $field)
  65. {
  66. $res = ArticleModel::where('status', 1)->where('hide', 0)->column($field, 'id');
  67. $new_res = array();
  68. foreach ($res as $k => $v) {
  69. $cid_arr = explode(',', $v['cid']);
  70. if (in_array($id, $cid_arr)) {
  71. $new_res[$k] = $res[$k];
  72. }
  73. }
  74. return $new_res;
  75. }
  76. /**
  77. * TODO 获取文章分类
  78. * @return array
  79. * @throws \think\db\exception\DataNotFoundException
  80. * @throws \think\db\exception\ModelNotFoundException
  81. * @throws \think\exception\DbException
  82. */
  83. public static function getArticleCategoryList()
  84. {
  85. $list = self::where('is_del', 0)->where('status', 1)->select();
  86. if ($list) return $list->toArray();
  87. return [];
  88. }
  89. /**
  90. * TODO 获取文章分类信息
  91. * @param $id
  92. * @param string $field
  93. * @return mixed
  94. */
  95. public static function getArticleCategoryInfo($id, $field = 'title')
  96. {
  97. $model = new self;
  98. if ($id) $model = $model->where('id', $id);
  99. $model = $model->where('is_del', 0);
  100. $model = $model->where('status', 1);
  101. return $model->column($field, 'id');
  102. }
  103. }