You've already forked guangan
1
This commit is contained in:
31
plugs/think-plugs-ticket/src/model/TicketReply.php
Normal file
31
plugs/think-plugs-ticket/src/model/TicketReply.php
Normal 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 '其他';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
68
plugs/think-plugs-ticket/src/model/TicketTicket.php
Normal file
68
plugs/think-plugs-ticket/src/model/TicketTicket.php
Normal 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');
|
||||
}
|
||||
}
|
23
plugs/think-plugs-ticket/src/model/TicketType.php
Normal file
23
plugs/think-plugs-ticket/src/model/TicketType.php
Normal 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');
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user