ArticleCategory.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. return self::where('hidden',0)->where('is_del',0)->where('status',1)->where('pid',0)->order('sort DESC')->field('id,title')->select();
  32. }
  33. /**
  34. * TODO 获取分类字段
  35. * @param $id $id 编号
  36. * @param string $field $field 字段
  37. * @return mixed|string
  38. */
  39. public static function getArticleCategoryField($id,$field = 'title'){
  40. if(!$id) return '';
  41. return self::where('id',$id)->value($field);
  42. }
  43. /**
  44. * @param $cid
  45. * @param $first
  46. * @param $limit
  47. * @param string $field
  48. * @return \think\Collection
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. * @throws \think\exception\DbException
  52. */
  53. public static function cidByArticleList($cid, $first, $limit, $field = '*')
  54. {
  55. $model = new Article();
  56. if ($cid) $model->where('cid',$cid);
  57. return $model->field($field)->where('status', 1)->where('hide', 0)->order('sort DESC,add_time DESC')->limit($first, $limit)->select();
  58. }
  59. }