1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace app\common\model\content;
- use app\common\Enum\StatusEnum;
- use think\Model;
- use traits\model\SoftDelete;
- class Category extends Model
- {
- use SoftDelete;
-
- // 表名
- protected $table = 'article_category';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'integer';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = 'deletetime';
- // 追加属性
- protected $append = [
- ];
-
- /**
- * 获取分类列表
- * @param int $parentId 父级ID
- * @param int $page 页码
- * @param int $pageSize 每页条数
- * @return \think\Paginator
- */
- public static function getCategoryList($parentId = 0, $page = 1, $pageSize = 10)
- {
- // 如果有
- $categoryList = self::where('status', StatusEnum::ENABLED)
- ->field('id,parent_id,title,brief_intr,image,sort')
- ->where(function ($query) use ($parentId) {
- if ($parentId) {
- $query->where('parent_id', $parentId);
- }
- })
- ->order('sort desc,id desc')
- ->paginate($pageSize, false, ['page' => $page]);
- return $categoryList;
- }
-
- }
|