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.
136 lines
2.9 KiB
136 lines
2.9 KiB
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Adverse extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'adverse';
|
|
|
|
protected $fillable = [
|
|
'project_id',
|
|
'order_id',
|
|
'type',
|
|
'description',
|
|
'solved_at',
|
|
'solved_by',
|
|
'solved_status',
|
|
'solved_result'
|
|
];
|
|
|
|
protected $dates = [
|
|
'solved_at',
|
|
'created_at',
|
|
'updated_at',
|
|
'deleted_at'
|
|
];
|
|
|
|
// 状态常量
|
|
const STATUS_PENDING = 'pending'; // 待处理
|
|
const STATUS_PROCESSING = 'processing'; // 处理中
|
|
const STATUS_SOLVED = 'solved'; // 已解决
|
|
const STATUS_CLOSED = 'closed'; // 已关闭
|
|
|
|
// 类型常量
|
|
const TYPE_SERVICE = 'service'; // 服务问题
|
|
const TYPE_QUALITY = 'quality'; // 质量问题
|
|
const TYPE_SAFETY = 'safety'; // 安全问题
|
|
const TYPE_COMPLAINT = 'complaint'; // 投诉
|
|
const TYPE_OTHER = 'other'; // 其他
|
|
|
|
/**
|
|
* 获取状态列表
|
|
*/
|
|
public static function getStatusList()
|
|
{
|
|
return [
|
|
self::STATUS_PENDING => '待处理',
|
|
self::STATUS_PROCESSING => '处理中',
|
|
self::STATUS_SOLVED => '已解决',
|
|
self::STATUS_CLOSED => '已关闭'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 获取类型列表
|
|
*/
|
|
public static function getTypeList()
|
|
{
|
|
return [
|
|
self::TYPE_SAFETY => '意外事件',
|
|
self::TYPE_COMPLAINT => '沟通事件',
|
|
self::TYPE_OTHER => '其他'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 关联项目
|
|
*/
|
|
public function project()
|
|
{
|
|
return $this->belongsTo(Project::class);
|
|
}
|
|
|
|
/**
|
|
* 关联订单
|
|
*/
|
|
public function order()
|
|
{
|
|
return $this->belongsTo(Orders::class);
|
|
}
|
|
|
|
/**
|
|
* 关联解决人(管理员)
|
|
*/
|
|
public function solver()
|
|
{
|
|
return $this->belongsTo(\App\Admin::class, 'solved_by');
|
|
}
|
|
|
|
/**
|
|
* 获取状态文本
|
|
*/
|
|
public function getStatusTextAttribute()
|
|
{
|
|
$statusList = self::getStatusList();
|
|
return $statusList[$this->solved_status] ?? '未知状态';
|
|
}
|
|
|
|
/**
|
|
* 获取类型文本
|
|
*/
|
|
public function getTypeTextAttribute()
|
|
{
|
|
$typeList = self::getTypeList();
|
|
return $typeList[$this->type] ?? '未知类型';
|
|
}
|
|
|
|
/**
|
|
* 是否已解决
|
|
*/
|
|
public function isSolved()
|
|
{
|
|
return in_array($this->solved_status, [self::STATUS_SOLVED, self::STATUS_CLOSED]);
|
|
}
|
|
|
|
/**
|
|
* 是否待处理
|
|
*/
|
|
public function isPending()
|
|
{
|
|
return $this->solved_status === self::STATUS_PENDING;
|
|
}
|
|
|
|
/**
|
|
* 处理中
|
|
*/
|
|
public function isProcessing()
|
|
{
|
|
return $this->solved_status === self::STATUS_PROCESSING;
|
|
}
|
|
}
|