内外部工单

This commit is contained in:
2024-12-01 16:40:07 +08:00
parent 3ec08279fe
commit a9dc2f46f7
16 changed files with 851 additions and 12 deletions

View File

@ -0,0 +1,90 @@
<?php
namespace plugin\ticket\model;
class TicketTicketInter extends TicketTicket
{
protected $append = ['status_text', 'type_name'];
protected $globalScope = ['inter'];
protected $table = 'ticket_ticket';
public function type()
{
return $this->belongsTo(TicketType::class, 'type_id');
}
public function user()
{
return $this->morphTo('user');
}
public function reply()
{
return $this->hasMany(TicketReply::class, 'ticket_id')->order("create_at", 'asc');
}
public function getImgsArrAttr($value, $data)
{
return str2arr($data['imgs'] ?: '', '|');
}
public function getLastReplyAttr($value, $data)
{
return $this->reply()->order('create_at', 'desc')->find();
}
public function getSourceTypeNameAttr($value, $data)
{
if (!empty($this->getSourceTypeList()[$data['source_type']])) {
return $this->getSourceTypeList()[$data['source_type']];
} else {
return '未知';
}
}
public function getSourceTypeList()
{
return [
0 => '其他',
1 => '用户随手拍',
2 => '工单',
];
}
public function getTypeNameAttr($value, $data)
{
$type = $this->type()->find();
if (!empty($type)) {
return $type['name'];
} else {
return '未知';
}
}
public function getStatusTextAttr($value, $data)
{
if (!empty($this->getStatusList()[$data['status']])) {
return $this->getStatusList()[$data['status']];
} else {
return '未知';
}
}
private function getStatusList()
{
return [
-1 => '已关闭',
0 => '待处理',
1 => '已作处理',
];
}
public function scopeAvail($query)
{
return $query->where('status', '>=', '0');
}
public function userShares()
{
return $this->hasMany(TicketUserShare::class, 'linked_ticket_id');
}
}