Files
orico-official-website/app/admin/model/v1/AttachmentModel.php

72 lines
1.8 KiB
PHP

<?php
declare (strict_types = 1);
namespace app\admin\model\v1;
use app\common\model\AttachmentBaseModel;
use think\model\concern\SoftDelete;
/**
* 附件(下载管理)模型
* @mixin \think\Model
*/
class AttachmentModel extends AttachmentBaseModel
{
// 启用软删除
use SoftDelete;
// 软删除字段
protected $deleteTime = 'deleted_at';
// 自动写入时间格式
protected $autoWriteTimestamp = 'datetime';
// JSON字段
protected $json = ['attach'];
// 设置JSON数据返回数组
protected $jsonAssoc = true;
// JSON字段属性类型
protected $jsonType = [
'attach[*]->file_path' => 'string',
'attach[*]->file_ext' => 'string',
'attach[*]->btn_name' => 'string',
];
// 关联附件分类模型
public function category()
{
return $this->belongsTo(AttachmentCategoryModel::class, 'category_id', 'id');
}
// 名称搜索
public function searchNameAttr($query, $value)
{
if (empty($value)) return;
$query->where('name', 'like', '%' . $value . '%');
}
// 新增时间搜索
public function searchCreatedAtAttr($query, $value)
{
if (empty($value)) return;
if (is_array($value)) {
if (count($value) > 1) {
$query->whereBetweenTime('created_at', $value[0], $value[1]);
} else {
$query->whereTime('created_at', '>=', $value[0]);
}
}
}
// 语言查询
public function scopeLanguage($query, $value)
{
$query->where('language_id', '=', $value);
}
// 分类查询
public function scopeCategoryId($query, $value)
{
if (empty($value)) return;
$query->where('category_id', '=', $value);
}
}