generated from liutk/owl-admin-base
74 lines
1.4 KiB
PHP
74 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Traits;
|
|
|
|
use App\Models\WorkflowCheck;
|
|
use Illuminate\Support\Str;
|
|
use App\Enums\CheckStatus;
|
|
|
|
trait HasCheckable
|
|
{
|
|
protected static function booted(): void
|
|
{
|
|
static::created(function ($model) {
|
|
// 创建审核申请
|
|
$model->workflow()->create([
|
|
'key' => $model->getCheckKey(),
|
|
]);
|
|
});
|
|
|
|
static::deleting(function ($model) {
|
|
// 删除审核流水记录
|
|
$model->workflow->logs()->delete();
|
|
// 删除审核流程
|
|
$model->workflow->delete();
|
|
});
|
|
}
|
|
|
|
public function getCheckKey(): string
|
|
{
|
|
if (property_exists($this, 'checkKey')) {
|
|
return $this->checkKey;
|
|
}
|
|
|
|
return Str::snake(class_basename(__CLASS__));
|
|
}
|
|
|
|
/**
|
|
* 审核通过
|
|
*/
|
|
public function checkSuccess()
|
|
{
|
|
|
|
}
|
|
|
|
/**
|
|
* 审核未通过
|
|
*/
|
|
public function checkFail()
|
|
{
|
|
|
|
}
|
|
|
|
/**
|
|
* 取消申请
|
|
*/
|
|
public function checkCancel()
|
|
{
|
|
|
|
}
|
|
|
|
public function canUpdate(): bool
|
|
{
|
|
return in_array($this->workflow?->check_status, [CheckStatus::None, CheckStatus::Fail, CheckStatus::Cancel]);
|
|
}
|
|
|
|
/**
|
|
* 关联审核流水
|
|
*/
|
|
public function workflow()
|
|
{
|
|
return $this->morphOne(WorkflowCheck::class, 'subject');
|
|
}
|
|
}
|