This commit is contained in:
2024-11-21 16:40:44 +08:00
commit a5029a2be7
69 changed files with 3160 additions and 0 deletions

View File

@ -0,0 +1,31 @@
<?php
namespace plugin\ticket\model;
use think\admin\Model;
use think\admin\model\SystemUser;
class TicketReply extends Model
{
protected $append = ['type_name'];
public function ticket()
{
return $this->belongsTo(TicketTicket::class, 'ticket_id');
}
public function user()
{
return $this->belongsTo(SystemUser::class, 'user_id');
}
public function getTypeNameAttr($value, $data)
{
switch ($data['type']) {
case 0: return '流转';
case 1: return '回复';
case 9: return '退回';
default: return '其他';
}
}
}

View File

@ -0,0 +1,68 @@
<?php
namespace plugin\ticket\model;
use plugin\account\model\PluginAccountBind;
use think\admin\Model;
class TicketTicket extends Model
{
protected $append = ['status_text', 'type_name'];
public function type()
{
return $this->belongsTo(TicketType::class, 'type_id');
}
public function user()
{
return $this->belongsTo(PluginAccountBind::class, 'uid');
}
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 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');
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace plugin\ticket\model;
use think\admin\Model;
class TicketType extends Model
{
public static function getList()
{
return self::mk()->scope('active')->order('sort', 'asc')->field('name, id')->select();
}
public function tickets()
{
return $this->hasMany(TicketTicket::class, 'type_id');
}
public function scopeActive($query)
{
return $query->where('status', '=', '1');
}
}