智慧教务系统
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.
 
 
 
 
 
 

119 lines
2.7 KiB

<?php
namespace app\model\document;
use core\base\BaseModel;
use think\model\relation\HasOne;
use app\model\contract\Contract;
/**
* 文档生成记录模型
*/
class DocumentGenerateLog extends BaseModel
{
protected $pk = 'id';
protected $name = 'document_generate_log';
/**
* 关联合同表
*/
public function contract(): HasOne
{
return $this->hasOne(Contract::class, 'id', 'template_id');
}
/**
* 搜索器:状态
*/
public function searchStatusAttr($query, $value, $data)
{
if ($value) {
$query->where("status", $value);
}
}
/**
* 搜索器:用户类型
*/
public function searchUserTypeAttr($query, $value, $data)
{
if ($value) {
$query->where("user_type", $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')] ?? '未知';
}
}