generated from liutk/owl-admin-base
86 lines
2.1 KiB
PHP
86 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Traits;
|
|
|
|
use App\Enums\CheckStatus;
|
|
use App\Models\{WorkflowLog, Employee};
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Support\Str;
|
|
|
|
trait HasCheckable
|
|
{
|
|
public function checkApply()
|
|
{
|
|
$this->update([
|
|
'check_status' => CheckStatus::Processing,
|
|
'checked_at' => null,
|
|
'check_remarks' => '',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 审核通过
|
|
*
|
|
* @param array $options {remarks: 不通过原因, time: 审核时间(默认当前时间)}
|
|
*/
|
|
public function checkSuccess(array $options = [])
|
|
{
|
|
$attributes = ['check_status' => CheckStatus::Success];
|
|
$attributes['checked_at'] = data_get($options, 'time', now());
|
|
$attributes['check_remarks'] = data_get($options, 'remarks');
|
|
$this->update($attributes);
|
|
}
|
|
|
|
/**
|
|
* 审核未通过
|
|
*
|
|
* @param array $options {remarks: 不通过原因, time: 审核时间(默认当前时间)}
|
|
*/
|
|
public function checkFail(array $options = [])
|
|
{
|
|
$attributes = ['check_status' => CheckStatus::Fail];
|
|
$attributes['checked_at'] = data_get($options, 'time', now());
|
|
$attributes['check_remarks'] = data_get($options, 'remarks');
|
|
$this->update($attributes);
|
|
}
|
|
|
|
public function checkCancel(array $options = [])
|
|
{
|
|
$this->update([
|
|
'check_status' => CheckStatus::Cancel,
|
|
'checked_at' => data_get($options, 'time', now()),
|
|
]);
|
|
}
|
|
|
|
public function getCheckKey()
|
|
{
|
|
return Str::snake(class_basename(__CLASS__));
|
|
}
|
|
|
|
/**
|
|
* 关联审核流水
|
|
*/
|
|
public function workflows()
|
|
{
|
|
return $this->morphMany(WorkflowLog::class, 'subject');
|
|
}
|
|
|
|
/**
|
|
* 关联申请人
|
|
*/
|
|
public function employee()
|
|
{
|
|
return $this->belongsTo(Employee::class, 'employee_id');
|
|
}
|
|
|
|
/**
|
|
* 查询审核通过的记录
|
|
*
|
|
* @param Builder $q
|
|
*/
|
|
public function scopeChecked(Builder $q): Builder
|
|
{
|
|
return $q->where('check_status', CheckStatus::Success);
|
|
}
|
|
}
|