81 lines
2.1 KiB
PHP
81 lines
2.1 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2006-2018 http://thinkphp.cn All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Liu21st <liu21st@gmail.com>
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\model;
|
|
|
|
use think\Model;
|
|
use think\model\concern\SoftDelete;
|
|
|
|
/**
|
|
* 文章分类模型
|
|
*/
|
|
class ArticlesCategory extends Model
|
|
{
|
|
// 启用软删除
|
|
use SoftDelete;
|
|
|
|
// 数据库表名
|
|
protected $name = 'mete_articles_category';
|
|
|
|
// 自动写入时间戳
|
|
protected $autoWriteTimestamp = true;
|
|
|
|
// 时间戳字段名
|
|
protected $createTime = 'create_time';
|
|
protected $updateTime = 'update_time';
|
|
protected $deleteTime = 'delete_time';
|
|
|
|
// 字段类型转换
|
|
protected $type = [
|
|
'id' => 'integer',
|
|
'sort' => 'integer',
|
|
'status' => 'integer',
|
|
'create_time' => 'datetime',
|
|
'update_time' => 'datetime',
|
|
'delete_time' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* 关联文章
|
|
*/
|
|
public function articles()
|
|
{
|
|
return $this->hasMany('app\index\model\Articles', 'cate', 'id');
|
|
}
|
|
|
|
/**
|
|
* 获取所有分类
|
|
*/
|
|
public static function allCategories()
|
|
{
|
|
return self::where('delete_time', null)->order('sort asc, id asc');
|
|
}
|
|
|
|
/**
|
|
* 获取启用的分类
|
|
*/
|
|
public static function enabled()
|
|
{
|
|
return self::where('status', 1)->where('delete_time', null);
|
|
}
|
|
|
|
/**
|
|
* 获取分类下的文章数量
|
|
*/
|
|
public function articleCount()
|
|
{
|
|
return $this->hasMany('app\index\model\Articles', 'cate', 'id')
|
|
->where('status', 1)
|
|
->where('delete_time', null)
|
|
->count();
|
|
}
|
|
}
|