generated from liutk/owl-admin-base
83 lines
2.1 KiB
PHP
83 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\{CheckStatus, CheckType};
|
|
use App\Traits\HasDateTimeFormatter;
|
|
use EloquentFilter\Filterable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
|
|
|
/**
|
|
* 审核申请
|
|
*/
|
|
class WorkflowCheck extends Model
|
|
{
|
|
use Filterable, HasDateTimeFormatter;
|
|
|
|
protected $attributes = [
|
|
'check_status' => CheckStatus::None,
|
|
];
|
|
|
|
protected $fillable = ['subject_type', 'subject_id', 'subject_data', 'key', 'employee_id', 'check_status', 'checked_at', 'check_remarks', 'check_type', 'check_value', 'check_name', 'apply_at'];
|
|
|
|
protected $casts = [
|
|
'subject_data' => 'json',
|
|
'apply_at' => 'datetime',
|
|
'check_status' => CheckStatus::class,
|
|
'checked_at' => 'datetime',
|
|
'check_type' => CheckType::class,
|
|
];
|
|
|
|
public function modelFilter()
|
|
{
|
|
return \App\Admin\Filters\WorkflowCheckFilter::class;
|
|
}
|
|
|
|
public function employee()
|
|
{
|
|
return $this->belongsTo(Employee::class, 'employee_id');
|
|
}
|
|
|
|
public function subject()
|
|
{
|
|
// 定义反向关联
|
|
// $this->morphMany(WorkflowLog::class, 'subject');
|
|
return $this->morphTo();
|
|
}
|
|
|
|
public function logs()
|
|
{
|
|
return $this->hasMany(WorkflowLog::class, 'check_id');
|
|
}
|
|
|
|
/**
|
|
* 是否审核通过
|
|
*/
|
|
public function isCheckSuccess(): bool
|
|
{
|
|
return $this->check_status === CheckStatus::Success;
|
|
}
|
|
|
|
/**
|
|
* 是否审核未通过
|
|
*/
|
|
public function isCheckFailed(): bool
|
|
{
|
|
return $this->check_status === CheckStatus::Fail;
|
|
}
|
|
|
|
public function subjectTypeText(): string
|
|
{
|
|
return match (Relation::getMorphedModel($this->subject_type)) {
|
|
EmployeeSignRepair::class => '补卡申请',
|
|
HolidayApply::class => '请假申请',
|
|
OvertimeApply::class => '加班申请',
|
|
OfficalBusiness::class => '出差报备',
|
|
EmployeePromotion::class => '升职申请',
|
|
Reimbursement::class => '报销申请',
|
|
default => '',
|
|
};
|
|
}
|
|
}
|