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.
133 lines
3.3 KiB
133 lines
3.3 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\model\document;
|
|
|
|
use core\base\BaseModel;
|
|
use think\model\relation\BelongsTo;
|
|
|
|
/**
|
|
* 文档生成记录模型
|
|
* Class DocumentGenerateLog
|
|
* @package app\model\document
|
|
*/
|
|
class DocumentGenerateLog extends BaseModel
|
|
{
|
|
/**
|
|
* 数据表主键
|
|
* @var string
|
|
*/
|
|
protected $pk = 'id';
|
|
|
|
/**
|
|
* 模型名称
|
|
* @var string
|
|
*/
|
|
protected $name = 'document_generate_log';
|
|
|
|
/**
|
|
* 关联模板
|
|
* @return BelongsTo
|
|
*/
|
|
public function template()
|
|
{
|
|
return $this->belongsTo(\app\model\contract\Contract::class, 'template_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* 搜索器:状态
|
|
* @param $query
|
|
* @param $value
|
|
* @param $data
|
|
*/
|
|
public function searchStatusAttr($query, $value, $data)
|
|
{
|
|
if ($value) {
|
|
$query->where("status", $value);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 搜索器:模板ID
|
|
* @param $query
|
|
* @param $value
|
|
* @param $data
|
|
*/
|
|
public function searchTemplateIdAttr($query, $value, $data)
|
|
{
|
|
if ($value) {
|
|
$query->where("template_id", $value);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 搜索器:用户ID
|
|
* @param $query
|
|
* @param $value
|
|
* @param $data
|
|
*/
|
|
public function searchUserIdAttr($query, $value, $data)
|
|
{
|
|
if ($value) {
|
|
$query->where("user_id", $value);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 搜索器:创建时间
|
|
* @param $query
|
|
* @param $value
|
|
* @param $data
|
|
*/
|
|
public function searchCreatedAtAttr($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([["created_at", "between", [$start, $end]]]);
|
|
} else if ($start > 0 && $end == 0) {
|
|
$query->where([["created_at", ">=", $start]]);
|
|
} else if ($start == 0 && $end > 0) {
|
|
$query->where([["created_at", "<=", $end]]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 状态获取器
|
|
* @param $value
|
|
* @return string
|
|
*/
|
|
public function getStatusTextAttr($value)
|
|
{
|
|
$statusMap = [
|
|
'pending' => '等待中',
|
|
'processing' => '处理中',
|
|
'completed' => '已完成',
|
|
'failed' => '失败'
|
|
];
|
|
return $statusMap[$this->getAttr('status')] ?? '未知';
|
|
}
|
|
|
|
/**
|
|
* 用户类型获取器
|
|
* @param $value
|
|
* @return string
|
|
*/
|
|
public function getUserTypeTextAttr($value)
|
|
{
|
|
$typeMap = [
|
|
'admin' => '管理员',
|
|
'staff' => '员工',
|
|
'member' => '会员'
|
|
];
|
|
return $typeMap[$this->getAttr('user_type')] ?? '未知';
|
|
}
|
|
}
|