You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
3.7 KiB
148 lines
3.7 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace addon\zhjw\app\model\articles;
|
|
|
|
use core\base\BaseModel;
|
|
use think\model\concern\SoftDelete;
|
|
use think\model\relation\HasMany;
|
|
use think\model\relation\HasOne;
|
|
|
|
use app\model\sys\SysUser;
|
|
|
|
/**
|
|
* 文章管理模型
|
|
* Class Articles
|
|
* @package addon\zhjw\app\model\articles
|
|
*/
|
|
class Articles extends BaseModel
|
|
{
|
|
|
|
use SoftDelete;
|
|
|
|
/**
|
|
* 数据表主键
|
|
* @var string
|
|
*/
|
|
protected $pk = 'id';
|
|
|
|
/**
|
|
* 模型名称
|
|
* @var string
|
|
*/
|
|
protected $name = 'zhjw_articles';
|
|
|
|
/**
|
|
* 定义软删除标记字段.
|
|
* @var string
|
|
*/
|
|
protected $deleteTime = 'is_deleted';
|
|
|
|
/**
|
|
* 定义软删除字段的默认值.
|
|
* @var int
|
|
*/
|
|
protected $defaultSoftDelete = 0;
|
|
|
|
/**
|
|
* 搜索器:文章管理标题
|
|
* @param $value
|
|
* @param $data
|
|
*/
|
|
public function searchTitleAttr($query, $value, $data)
|
|
{
|
|
if ($value) {
|
|
$query->where("title", "like", "%".$value."%");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 搜索器:文章管理文章分类
|
|
* @param $value
|
|
* @param $data
|
|
*/
|
|
public function searchCategoryAttr($query, $value, $data)
|
|
{
|
|
if ($value) {
|
|
$query->where("category", $value);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 搜索器:文章管理发布人
|
|
* @param $value
|
|
* @param $data
|
|
*/
|
|
public function searchPublisherIdAttr($query, $value, $data)
|
|
{
|
|
if ($value) {
|
|
$query->where("publisher_id", $value);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 搜索器:文章管理状态
|
|
* @param $value
|
|
* @param $data
|
|
*/
|
|
public function searchStatusAttr($query, $value, $data)
|
|
{
|
|
if ($value) {
|
|
$query->where("status", $value);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 搜索器:文章管理添加时间
|
|
* @param $value
|
|
* @param $data
|
|
*/
|
|
public function searchCreateTimeAttr($query, $value, $data)
|
|
{
|
|
$start = empty($value[0]) ? 0 : strtotime($value[0]);
|
|
$end = empty($value[1]) ? 0 : strtotime($value[1]);
|
|
if ($start > 0 && $end > 0) {
|
|
$query->where([["create_time", "between", [$start, $end]]]);
|
|
} else if ($start > 0 && $end == 0) {
|
|
$query->where([["create_time", ">=", $start]]);
|
|
} else if ($start == 0 && $end > 0) {
|
|
$query->where([["create_time", "<=", $end]]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 搜索器:文章管理更新时间
|
|
* @param $value
|
|
* @param $data
|
|
*/
|
|
public function searchUpdateTimeAttr($query, $value, $data)
|
|
{
|
|
$start = empty($value[0]) ? 0 : strtotime($value[0]);
|
|
$end = empty($value[1]) ? 0 : strtotime($value[1]);
|
|
if ($start > 0 && $end > 0) {
|
|
$query->where([["update_time", "between", [$start, $end]]]);
|
|
} else if ($start > 0 && $end == 0) {
|
|
$query->where([["update_time", ">=", $start]]);
|
|
} else if ($start == 0 && $end > 0) {
|
|
$query->where([["update_time", "<=", $end]]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function sysUser(){
|
|
return $this->hasOne(SysUser::class, 'uid', 'publisher_id')->joinType('left')->withField('username,uid')->bind(['publisher_id_name'=>'username']);
|
|
}
|
|
|
|
}
|
|
|