80 lines
1.9 KiB
PHP
80 lines
1.9 KiB
PHP
<?php
|
|
declare (strict_types = 1);
|
|
|
|
namespace app\admin\model\v1;
|
|
|
|
use think\Model;
|
|
use think\model\concern\SoftDelete;
|
|
|
|
/**
|
|
* @mixin \think\Model
|
|
*/
|
|
class ArticleModel extends Model
|
|
{
|
|
// 启用软件删除
|
|
use SoftDelete;
|
|
// 软删除标记数据字段
|
|
protected $deleteTime = 'deleted_at';
|
|
|
|
// 表名
|
|
protected $name = 'article';
|
|
|
|
// 主键
|
|
protected $pk = 'id';
|
|
|
|
// 字段信息
|
|
protected $schema = [
|
|
'id' => 'int',
|
|
'language_id' => 'int',
|
|
'category_id' => 'int',
|
|
'title' => 'string',
|
|
'author' => 'string',
|
|
'source' => 'string',
|
|
'image' => 'string',
|
|
'desc' => 'string',
|
|
'recommend' => 'int',
|
|
'release_time' => 'int',
|
|
'sort' => 'int',
|
|
'link' => 'string',
|
|
'content' => 'string',
|
|
'view_count' => 'int',
|
|
'praise_count' => 'int',
|
|
'seo_title' => 'string',
|
|
'seo_keywords' => 'string',
|
|
'seo_desc' => 'string',
|
|
'created_at' => 'datetime',
|
|
'updated_at' => 'datetime',
|
|
'deleted_at' => 'datetime',
|
|
];
|
|
|
|
// 搜索名称
|
|
public function searchTitleAttr($query, $value, $data)
|
|
{
|
|
$query->where('title', 'like', '%' . $value . '%');
|
|
}
|
|
|
|
// 搜索发布时间
|
|
public function searchCreatedAtAttr($query, $value, $data)
|
|
{
|
|
if (is_array($value)) {
|
|
if (count($value) == 2) {
|
|
$query->whereBetweenTime('created_at', $value[0], $value[1]);
|
|
} else {
|
|
$query->whereTime('created_at', '>=', $value[0]);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 主键查询
|
|
public function scopeId($query, $value)
|
|
{
|
|
$query->where('id', '=', $value);
|
|
}
|
|
|
|
// 分类查询
|
|
public function scopeCategory($query, $value)
|
|
{
|
|
$query->where('category_id', '=', $value);
|
|
}
|
|
}
|