123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace app\common\model\content;
- use app\common\Enum\StatusEnum;
- use think\Model;
- use traits\model\SoftDelete;
- class Article extends Model
- {
- use SoftDelete;
-
- // 表名
- protected $table = 'article';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'integer';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = 'deletetime';
- // 追加属性
- protected $append = [
- ];
- /**
- * 获取文章
- * @param int $categoryId 分类ID
- * @param int $page 页码
- * @param int $pageSize 每页条数
- * @return \think\Paginator
- */
- public static function getArticleList($categoryId = 0, $page = 1, $pageSize = 10)
- {
- // 如果有
- $categoryList = self::where('status', StatusEnum::ENABLED)
- ->field('id,category_id,title,synopsis,author,image,sort')
- ->where(function ($query) use ($categoryId) {
- if ($categoryId) {
- $query->where('category_id', $categoryId);
- }
- })
- ->order('sort desc,id desc')
- ->paginate($pageSize, false, ['page' => $page]);
- return $categoryList;
- }
- /**
- * 获取文章详情
- * @param int $id 文章ID
- * @return array|bool|Model|string|\PDOStatement
- */
- public static function getArticleInfo($id = 0)
- {
- $categoryInfo = self::where('id', $id)
- ->field('id,category_id,title,synopsis,author,image,sort,content')
- ->find();
- return $categoryInfo;
- }
-
- }
|