generated from liutk/owl-admin-base
59 lines
1.9 KiB
PHP
59 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Services;
|
|
|
|
use App\Enums\CheckType;
|
|
use App\Models\{Workflow, Keyword, Employee};
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class WorkFlowService extends BaseService
|
|
{
|
|
protected array $withRelationships = [];
|
|
|
|
protected string $modelName = Workflow::class;
|
|
|
|
protected string $modelFilterName = '';
|
|
|
|
public function resloveData($data, $model = null)
|
|
{
|
|
if (isset($data['config'])) {
|
|
foreach($data['config'] as $key => &$item) {
|
|
$item['title'] = match($item['type']) {
|
|
CheckType::Job->value => CheckType::Job->text(),
|
|
CheckType::User->value => CheckType::User->text(),
|
|
};
|
|
$item['subTitle'] = match($item['type']) {
|
|
CheckType::Job->value => Keyword::where('key', $item['job'])->value('name'),
|
|
CheckType::User->value => Employee::where('id', $item['user'])->value('name'),
|
|
};
|
|
$item['value'] = match($item['type']) {
|
|
CheckType::Job->value => $item['job'],
|
|
CheckType::User->value => $item['user'],
|
|
};
|
|
$item['sort'] = $key + 1;
|
|
}
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
public function validate($data, $model = null)
|
|
{
|
|
$createRules = [
|
|
'key' => ['required', Rule::unique('workflows', 'key')],
|
|
'name' => ['required'],
|
|
];
|
|
$updateRules = [
|
|
'key' => [Rule::unique('workflows', 'key')->ignore($model?->id)]
|
|
];
|
|
$validator = Validator::make($data, $model ? $updateRules : $createRules, [
|
|
'key.unique' => ':input 已经存在'
|
|
]);
|
|
if ($validator->fails()) {
|
|
return $validator->errors()->first();
|
|
}
|
|
return true;
|
|
}
|
|
} |