baseCRUD() ->tableLayout('fixed') ->headerToolbar([ $this->createButton(), ...$this->baseHeaderToolBar(), ]) ->bulkActions([]) ->filter($this->baseFilter()->body([ amis()->GroupControl()->mode('horizontal')->body([ amisMake()->TextControl()->name('search')->label(__('admin.keyword'))->placeholder(__('workflow.key').'/'.__('workflow.name'))->columnRatio(3)->clearable(), ]), ])) ->filterDefaultVisible() ->columns([ amisMake()->TableColumn()->name('id')->label(__('workflow.id')), amisMake()->TableColumn()->name('key')->label(__('workflow.key')), amisMake()->TableColumn()->name('name')->label(__('workflow.name')), $this->rowActions([ $this->rowShowButton(), $this->rowEditButton(), $this->rowDeleteButton(), ]), ]); return $this->baseList($crud); } public function create() { $this->isCreate = true; $form = amis()->Card() ->className('base-form') ->header(['title' => __('admin.create')]) ->toolbar([$this->backButton()]) ->body($this->form(false)->api($this->getStorePath())); $page = $this->basePage()->id('workflow-form-page')->body($form); return $this->response()->success($page); } public function edit($id) { $this->isEdit = true; if ($this->actionOfGetData()) { return $this->response()->success($this->service->getEditData($id)); } $form = amis()->Card() ->className('base-form') ->header(['title' => __('admin.edit')]) ->toolbar([$this->backButton()]) ->body( $this->form(true)->api($this->getUpdatePath())->initApi($this->getEditGetDataPath()) ); $page = $this->basePage()->id('workflow-form-page')->body($form); return $this->response()->success($page); } public function form($edit): Form { return $this->baseForm()->title('')->className('h-screen')->body([ amisMake()->TextControl()->name('key')->label(__('workflow.key'))->required(), amisMake()->TextControl()->name('name')->label(__('workflow.name'))->required(), amisMake()->TableControl()->name('config')->label(__('workflow.config'))->showIndex()->addable()->removable()->needConfirm(false)->columns([ amisMake()->SelectControl()->options(CheckType::options())->name('type')->label(__('workflow.type')), // amisMake()->PickerControl() // ->source(admin_url('api/keywords/tree-list?parent_key=job')) // ->valueField('key') // ->labelField('name') // ->multiple(false) // ->size('lg') // ->pickerSchema( // amis()->CRUDTable()->mode('table')->loadDataOnce(true)->syncLocation(false)->draggable(false)->columns([ // amis()->TableColumn()->name('key')->label(__('keyword.key')), // amis()->TableColumn()->name('name')->label(__('keyword.name')), // ]) // ) // ->name('job') // ->label(__('workflow.job')), // amis()->PickerControl() // ->source(admin_url('api/employees?enable=1')) // ->valueField('id') // ->labelField('name') // ->multiple(false) // ->size('lg') // ->pickerSchema( // amis()->CRUDTable()->mode('table')->syncLocation(false)->draggable(false) // ->filter($this->baseFilter()->body([ // amisMake()->TextControl()->name('name')->label(__('employee.name'))->size('md')->clearable(), // amisMake()->TextControl()->name('phone')->label(__('employee.phone'))->size('md')->clearable(), // ])) // ->columns([ // amis()->TableColumn()->name('id')->label(__('employee.id')), // amis()->TableColumn()->name('name')->label(__('employee.name')), // amis()->TableColumn()->name('phone')->label(__('employee.phone')), // ]) // ) // ->name('user') // ->label(__('workflow.user')), // amis()->PickerControl() // ->source(admin_url('api/workflow/value-options?type=${type}')) // ->multiple(false) // ->size('lg') // ->pickerSchema( // amis()->CRUD2Table()->mode('table')->syncLocation(false)->draggable(false) // ->filter($this->baseFilter()->body([ // amisMake()->TextControl()->name('search')->label('关键字')->size('md')->clearable(), // ])) // ->columns([ // amis()->TableColumn()->name('value'), // amis()->TableColumn()->name('label'), // ]) // ) // ->name('value') // ->label(__('workflow.value')), amisMake()->SelectControl() ->source(admin_url('api/workflow/value-options?type=${type}')) ->searchable() ->name('value') ->label(__('workflow.value')), ]), ]); } public function detail(): Form { $detail = amisMake()->Property()->items([ ['label' => __('workflow.key'), 'content' => '${key}'], ['label' => __('workflow.name'), 'content' => '${name}'], ['label' => __('workflow.config'), 'content' => amisMake()->Steps()->labelPlacement('horizontal')->source('${config}'), 'span' => 3], ]); return $this->baseDetail()->title('')->body($detail); } public function getValueOptions(Request $request) { $options = match (CheckType::tryFrom($request->input('type'))) { CheckType::Job => Keyword::where('parent_key', 'job')->get(['key', 'name']), CheckType::User => Employee::enable()->get(['id', 'name']), default => collect(), }; return $this->response()->success( $options->map(function ($item) { switch (get_class($item)) { case Keyword::class: return ['value' => $item->key, 'label' => $item->name]; break; case Employee::class: return ['value' => $item->id, 'label' => $item->name]; break; default: return $item; break; } })->all() ); } public function apply(Request $request) { $model = WorkflowCheck::findOrFail($request->input('id')); $employee = $request->whenFilled('user', function ($id) { if ($employee = Employee::find($id)) { return $employee; } admin_abort('员工未找到'); }, function () { if ($employee = Employee::where('admin_user_id', Admin::user()->id)->first()) { return $employee; } admin_abort('当前登录账户未关联员工'); }); try { DB::beginTransaction(); if (! $this->service->apply($model, $employee)) { return $this->response()->fail($this->service->getError()); } DB::commit(); return $this->response()->success(); } catch (\Exception $e) { DB::rollBack(); return $this->response()->fail($e->getMessage()); } } public function cancel(Request $request) { $model = WorkflowCheck::findOrFail($request->input('id')); try { DB::beginTransaction(); if (! $this->service->cancel($model)) { return $this->response()->fail($this->service->getError()); } DB::commit(); return $this->response()->success(); } catch (\Exception $e) { DB::rollBack(); return $this->response()->fail($e->getMessage()); } } public function success(Request $request) { $user = Admin::user(); $employee = Employee::where('admin_user_id', $user->id)->first(); if (! $employee) { return $this->response()->fail('当前登录账户未关联员工'); } $log = WorkflowLog::find($request->input('id')); if (! $log) { return $this->response()->fail('审核已取消'); } try { DB::beginTransaction(); if (! $this->service->check($employee, $log, true)) { return $this->response()->fail($this->service->getError()); } DB::commit(); return $this->response()->success(); } catch (\Exception $e) { DB::rollBack(); return $this->response()->fail($e->getMessage()); } } public function fail(Request $request) { if (! $request->input('remarks')) { return $this->response()->fail('请填写未通过原因'); } $user = Admin::user(); $employee = Employee::where('admin_user_id', $user->id)->first(); if (! $employee) { return $this->response()->fail('当前登录账户未关联员工'); } $log = WorkflowLog::find($request->input('id')); if (! $log) { return $this->response()->fail('审核已取消'); } try { DB::beginTransaction(); if (! $this->service->check($employee, $log, false, ['remarks' => $request->input('remarks')])) { return $this->response()->fail($this->service->getError()); } DB::commit(); return $this->response()->success(); } catch (\Exception $e) { DB::rollBack(); return $this->response()->fail($e->getMessage()); } } public function logs(Request $request) { $list = WorkflowLog::with(['checkUser'])->where('check_id', $request->input('id'))->sort()->get(); // 判断当前用户是否有权限审核 $user = Employee::with(['jobs'])->where('admin_user_id', Admin::user()->id)->first(); if ($user) { foreach ($list as &$item) { $item->checkable = $item->check_status == CheckStatus::Processing && $this->service->authCheck($user, $item); } } return $this->response()->success($list); } }