generated from liutk/owl-admin-base
153 lines
6.9 KiB
PHP
153 lines
6.9 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Services\AgreementService;
|
|
use App\Enums\CheckStatus;
|
|
use App\Enums\EmployeeStatus;
|
|
use App\Models\Agreement;
|
|
use App\Traits\HasCheckActions;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\{Storage};
|
|
use Illuminate\Support\{Arr};
|
|
use Slowlyo\OwlAdmin\Admin;
|
|
use Slowlyo\OwlAdmin\Renderers\Form;
|
|
use Slowlyo\OwlAdmin\Renderers\Page;
|
|
|
|
/**
|
|
* 合同管理
|
|
*/
|
|
class AgreementController extends AdminController
|
|
{
|
|
use HasCheckActions;
|
|
|
|
protected string $serviceName = AgreementService::class;
|
|
|
|
public function list(): Page
|
|
{
|
|
$user = Admin::user();
|
|
$crud = $this->baseCRUD()
|
|
->tableLayout('fixed')
|
|
->headerToolbar([
|
|
$this->createTypeButton('drawer', 'lg')->visible($user->can('admin.agreement.create')),
|
|
...$this->baseHeaderToolBar(),
|
|
])
|
|
->bulkActions([])
|
|
->filter($this->baseFilter()->body([
|
|
amis()->GroupControl()->mode('horizontal')->body([
|
|
amisMake()->TextControl()
|
|
->name('name')
|
|
->label(__('agreement.name'))
|
|
->columnRatio(3)
|
|
->clearable(),
|
|
amisMake()->TextControl()->name('employee_search')
|
|
->label(__('agreement.employee_id'))
|
|
->placeholder(__('employee.name').'/'.__('employee.phone'))
|
|
->columnRatio(3)
|
|
->clearable(),
|
|
amis()->SelectControl()->name('check_status')->label(__('workflow_log.check_status'))->options(Arr::except(CheckStatus::options(), [CheckStatus::Cancel->value]))->columnRatio(3)->clearable(),
|
|
amisMake()->DateRangeControl()
|
|
->name('date_range')
|
|
->label(__('agreement.created_at'))
|
|
->columnRatio(3)
|
|
->clearable(),
|
|
]),
|
|
]))
|
|
->filterDefaultVisible()
|
|
->columns([
|
|
amisMake()->TableColumn()->name('id')->label(__('agreement.id')),
|
|
amisMake()->TableColumn()->name('name')->label(__('agreement.name')),
|
|
amisMake()->TableColumn()->name('employee.name')->label(__('agreement.employee_id')),
|
|
amisMake()->TableColumn()->name('store.title')->label(__('agreement.store_id')),
|
|
amisMake()->TableColumn()->name('workflow.check_status')->label(__('workflow_log.check_status'))->set('type', 'mapping')->map(CheckStatus::options()),
|
|
amisMake()->TableColumn()->name('workflow.check_name')->label(__('workflow.value')),
|
|
amisMake()->TableColumn()->name('created_at')->label(__('agreement.created_at')),
|
|
amisMake()->Operation()->label(__('admin.actions'))->buttons([
|
|
$this->rowShowButton()->visibleOn('${ARRAYINCLUDES(row_actions, "view")}'),
|
|
$this->rowEditTypeButton('drawer', 'lg')->visibleOn('${ARRAYINCLUDES(row_actions, "edit")}'),
|
|
$this->rowDeleteButton()->visibleOn('${ARRAYINCLUDES(row_actions, "delete")}'),
|
|
$this->applyAction()->visibleOn('${ARRAYINCLUDES(row_actions, "apply")}'),
|
|
// $this->cancelAction()->visibleOn('${ARRAYINCLUDES(row_actions, "cancel")}'),
|
|
amisMake()->AjaxAction()
|
|
->label('打包下载')
|
|
->api(admin_url('agreement/download?id=${id}'))
|
|
->level('link')
|
|
->redirect(url('admin-api/_download_export').'?path=${path}')
|
|
->visibleOn('${ARRAYINCLUDES(row_actions, "download")}'),
|
|
]),
|
|
]);
|
|
|
|
return $this->baseList($crud);
|
|
}
|
|
|
|
public function form(): Form
|
|
{
|
|
return $this->baseForm()->body([
|
|
amisMake()->TextControl()->name('name')->label(__('agreement.name'))->required(),
|
|
amisMake()->SelectControl()->name('employee_id')->label(__('agreement.employee_id'))
|
|
->source(admin_url('api/employees?_all=1&store_id_gt=0&employee_status='.EmployeeStatus::Online->value))
|
|
->labelField('name')
|
|
->valueField('id')
|
|
->searchable()
|
|
->required(),
|
|
amisMake()->ImageControl()->name('images')->label(__('agreement.images'))
|
|
->receiver(admin_url('upload_image').'?full-url=1')
|
|
->multiple()
|
|
->draggable()
|
|
->joinValues(false),
|
|
amisMake()->TextControl()->name('remarks')->label(__('agreement.remarks')),
|
|
]);
|
|
}
|
|
|
|
public function detail(): Form
|
|
{
|
|
$detailId = 'agreement-detail';
|
|
$serviceId = 'agreement-checklog-service';
|
|
|
|
$detail = amisMake()->Property()->items([
|
|
['label' => __('agreement.name'), 'content' => '${name}'],
|
|
['label' => __('agreement.employee_id'), 'content' => '${employee.name}'],
|
|
['label' => __('agreement.store_id'), 'content' => '${store.title}'],
|
|
['label' => __('agreement.created_at'), 'content' => '${created_at}'],
|
|
['label' => __('agreement.remarks'), 'content' => '${remarks}', 'span' => 2],
|
|
['label' => __('agreement.images'), 'content' => amisMake()->Images()->name('images')->enlargeAble(), 'span' => 3],
|
|
['label' => __('workflow_log.check_status'), 'content' => amisMake()->Mapping()->name('workflow.check_status')->map(CheckStatus::options())],
|
|
['label' => __('workflow_log.checked_at'), 'content' => '${workflow.checked_at}'],
|
|
['label' => __('workflow_log.remarks'), 'content' => '${workflow.check_remarks}'],
|
|
]);
|
|
|
|
return $this->baseDetail()->id($detailId)->title('')->onEvent([
|
|
'inited' => [
|
|
'actions' => [
|
|
['actionType' => 'reload', 'componentId' => $serviceId],
|
|
],
|
|
],
|
|
])->body([
|
|
$detail,
|
|
amisMake()->Divider(),
|
|
$this->baseWorkflowLogList($detailId)->id($serviceId),
|
|
]);
|
|
}
|
|
|
|
public function download(Request $request)
|
|
{
|
|
$model = Agreement::findOrFail($request->input('id'));
|
|
if (! $model->images || count($model->images) == 0) {
|
|
return $this->response()->fail('没有图片下载');
|
|
}
|
|
$zip = new \ZipArchive();
|
|
$filename = time().'.zip';
|
|
$filepath = storage_path('app/'.$filename);
|
|
$zip->open($filepath, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
|
|
$baseUrl = Storage::disk('public')->url('');
|
|
foreach ($model->images as $item) {
|
|
$path = str_replace($baseUrl, '', $item);
|
|
$info = pathinfo($path);
|
|
$zip->addFile(Storage::disk('public')->path($path), data_get($info, 'basename'));
|
|
}
|
|
$zip->close();
|
|
|
|
return $this->response()->success(['path' => $filename]);
|
|
}
|
|
}
|