generated from liutk/owl-admin-base
54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\CheckStatus;
|
|
use App\Enums\CheckType;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* 审核流水
|
|
*/
|
|
class WorkflowLog extends Model
|
|
{
|
|
protected $fillable = ['check_id', 'batch_id', 'check_type', 'check_value', 'check_name', 'check_user_id', 'checked_at', 'remarks', 'check_status', 'sort'];
|
|
|
|
protected $casts = [
|
|
'check_type' => CheckType::class,
|
|
'check_status' => CheckStatus::class,
|
|
'checked_at' => 'datetime:Y-m-d H:i:s',
|
|
];
|
|
|
|
public function check()
|
|
{
|
|
return $this->belongsTo(WorkflowCheck::class, 'check_id');
|
|
}
|
|
|
|
public function checkUser()
|
|
{
|
|
return $this->belongsTo(Employee::class, 'check_user_id');
|
|
}
|
|
|
|
public function scopeSort($q)
|
|
{
|
|
return $q->orderBy('batch_id', 'desc')->orderBy('sort', 'desc');
|
|
}
|
|
|
|
public function scopeOwn($builder, $user)
|
|
{
|
|
$checkValue = [$user->id];
|
|
$userJobs = $user->jobs;
|
|
if ($userJobs && $userJobs->count() > 0) {
|
|
foreach($userJobs->unique('key') as $item) {
|
|
array_push($checkValue, $user->store_id . '-' . $item->key);
|
|
}
|
|
}
|
|
return $builder->whereIn('check_value', $checkValue);
|
|
}
|
|
|
|
public function isCheckProcessing(): bool
|
|
{
|
|
return $this->check_status === CheckStatus::Processing;
|
|
}
|
|
}
|