generated from liutk/owl-admin-base
49 lines
998 B
PHP
49 lines
998 B
PHP
<?php
|
|
|
|
namespace App\Traits;
|
|
|
|
use App\Models\WorkflowCheck;
|
|
use Illuminate\Support\Str;
|
|
|
|
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 workflow()
|
|
{
|
|
return $this->morphOne(WorkflowCheck::class, 'subject');
|
|
}
|
|
}
|