ArticleCategory.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\models\article;
  3. use crmeb\traits\ModelTrait;
  4. use crmeb\basic\BaseModel;
  5. /**
  6. * TODO 文章分类Model
  7. * Class ArticleCategory
  8. * @package app\models\article
  9. */
  10. class ArticleCategory extends BaseModel
  11. {
  12. /**
  13. * 数据表主键
  14. * @var string
  15. */
  16. protected $pk = 'id';
  17. /**
  18. * 模型名称
  19. * @var string
  20. */
  21. protected $name = 'article_category';
  22. use ModelTrait;
  23. /**
  24. * TODO 获取文章分类
  25. * @return false|\PDOStatement|string|\think\Collection
  26. * @throws \think\db\exception\DataNotFoundException
  27. * @throws \think\db\exception\ModelNotFoundException
  28. * @throws \think\exception\DbException
  29. */
  30. public static function getArticleCategory()
  31. {
  32. return self::where('hidden', 0)->where('is_del', 0)->where('status', 1)->where('pid', 0)->order('sort DESC')->field('id,title')->select();
  33. }
  34. /**
  35. * TODO 获取分类字段
  36. * @param $id $id 编号
  37. * @param string $field $field 字段
  38. * @return mixed|string
  39. */
  40. public static function getArticleCategoryField($id, $field = 'title')
  41. {
  42. if (!$id) return '';
  43. return self::where('id', $id)->value($field);
  44. }
  45. /**
  46. * @param $cid
  47. * @param $first
  48. * @param $limit
  49. * @param string $field
  50. * @return \think\Collection
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. * @throws \think\exception\DbException
  54. */
  55. public static function cidByArticleList($cid, $first, $limit, $field = '*')
  56. {
  57. $model = new Article();
  58. if ($cid) $model->where('cid', $cid);
  59. return $model->field($field)->where('status', 1)->where('hide', 0)->order('sort DESC,add_time DESC')->limit($first, $limit)->select();
  60. }
  61. }