Category.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\common\model\content;
  3. use app\common\Enum\StatusEnum;
  4. use think\Model;
  5. use traits\model\SoftDelete;
  6. class Category extends Model
  7. {
  8. use SoftDelete;
  9. // 表名
  10. protected $table = 'article_category';
  11. // 自动写入时间戳字段
  12. protected $autoWriteTimestamp = 'integer';
  13. // 定义时间戳字段名
  14. protected $createTime = 'createtime';
  15. protected $updateTime = 'updatetime';
  16. protected $deleteTime = 'deletetime';
  17. // 追加属性
  18. protected $append = [
  19. ];
  20. /**
  21. * 获取分类列表
  22. * @param int $parentId 父级ID
  23. * @param int $page 页码
  24. * @param int $pageSize 每页条数
  25. * @return \think\Paginator
  26. */
  27. public static function getCategoryList($parentId = 0, $page = 1, $pageSize = 10)
  28. {
  29. // 如果有
  30. $categoryList = self::where('status', StatusEnum::ENABLED)
  31. ->field('id,parent_id,title,brief_intr,image,sort')
  32. ->where(function ($query) use ($parentId) {
  33. if ($parentId) {
  34. $query->where('parent_id', $parentId);
  35. }
  36. })
  37. ->order('sort desc,id desc')
  38. ->paginate($pageSize, false, ['page' => $page]);
  39. return $categoryList;
  40. }
  41. }