first commit
This commit is contained in:
94
app/common/model/Tickets.php
Normal file
94
app/common/model/Tickets.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
|
||||
class Tickets extends Model
|
||||
{
|
||||
protected $table = 'tickets';
|
||||
|
||||
# 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
# 定义时间戳字段名
|
||||
protected $createTime = 'create_time';
|
||||
protected $updateTime = 'update_time';
|
||||
|
||||
|
||||
# 定义字段类型
|
||||
protected $type = [
|
||||
'id' => 'integer',
|
||||
'company_id' => 'integer',
|
||||
'operator_id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'website' => 'string',
|
||||
'datanum' => 'string',
|
||||
'progress' => 'integer',
|
||||
'status' => 'integer',
|
||||
'remark' => 'string',
|
||||
'lock_time' => 'integer',
|
||||
'create_time' => 'integer',
|
||||
'update_time' => 'integer',
|
||||
];
|
||||
|
||||
|
||||
/*
|
||||
时间戳获取器
|
||||
*/
|
||||
public function getCreateTimeAttr($value)
|
||||
{
|
||||
return date('Y-m-d H:i', $value);
|
||||
}
|
||||
|
||||
public function getUpdateTimeAttr($value)
|
||||
{
|
||||
return date('Y-m-d H:i', $value);
|
||||
}
|
||||
|
||||
public function getLockTimeAttr($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return '';
|
||||
}
|
||||
return date('Y-m-d H:i', $value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 关联:工单关联负责人
|
||||
*/
|
||||
public function ticketStaff()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
public function ticketCompany()
|
||||
{
|
||||
return $this->belongsTo(Companys::class, 'company_id', 'id');
|
||||
}
|
||||
|
||||
public function ticketOperator()
|
||||
{
|
||||
return $this->belongsTo(CompanyOperators::class, 'operator_id', 'id');
|
||||
}
|
||||
|
||||
|
||||
// --- 定义虚拟属性 (获取关联表的值) ---
|
||||
|
||||
public function getUsernameAttr($value, $data)
|
||||
{
|
||||
return $this->ticketStaff->username ?? '';
|
||||
}
|
||||
|
||||
public function getCompanyNameAttr($value, $data)
|
||||
{
|
||||
return $this->ticketCompany->company_name ?? '';
|
||||
}
|
||||
|
||||
public function getOperatorNameAttr($value, $data)
|
||||
{
|
||||
return $this->ticketOperator->operator_name ?? '';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user