generated from liutk/owl-admin-base
182 lines
6.8 KiB
PHP
182 lines
6.8 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers\Complaint;
|
|
|
|
use App\Admin\Controllers\AdminController;
|
|
use App\Admin\Services\Complaint\ComplaintService;
|
|
use App\Enums\ComplaintStatus;
|
|
use App\Models\Complaint;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Slowlyo\OwlAdmin\Admin;
|
|
use Slowlyo\OwlAdmin\Renderers\AjaxAction;
|
|
use Slowlyo\OwlAdmin\Renderers\DrawerAction;
|
|
use Slowlyo\OwlAdmin\Renderers\Form;
|
|
use Slowlyo\OwlAdmin\Renderers\Page;
|
|
|
|
/**
|
|
* @property ComplaintService $service
|
|
*/
|
|
class ComplaintController extends AdminController
|
|
{
|
|
protected string $serviceName = ComplaintService::class;
|
|
|
|
public function list(): Page
|
|
{
|
|
$crud = $this->baseCRUD()
|
|
->headerToolbar([
|
|
...$this->baseHeaderToolBar(),
|
|
])
|
|
->bulkActions([])
|
|
->filter($this->baseFilter()->body([
|
|
amis()->GroupControl()->mode('horizontal')->body([
|
|
amis()->TextControl()
|
|
->name('employee_name')
|
|
->label(__('complaint.complaint.employee'))
|
|
->placeholder(__('complaint.complaint.employee')),
|
|
amis()->InputDatetimeRange()
|
|
->name('created_at')
|
|
->label(__('complaint.complaint.created_at'))
|
|
->format('YYYY-MM-DD HH:mm:ss'),
|
|
amis()->SelectControl('complaint_status', __('complaint.complaint.complaint_status'))
|
|
->multiple()
|
|
->options(ComplaintStatus::options()),
|
|
]),
|
|
]))
|
|
->filterDefaultVisible()
|
|
->columns([
|
|
amis()->TableColumn()->name('created_at')->label(__('complaint.complaint.created_at')),
|
|
amis()->TableColumn()
|
|
->name('_employee')
|
|
->label(__('complaint.complaint.employee'))
|
|
->value('${anonymous ? "匿名" : employee.name}'),
|
|
amis()->TableColumn()
|
|
->name('content')
|
|
->label(__('complaint.complaint.content'))
|
|
->popOver('${content}')
|
|
->type('tpl')
|
|
->set('tpl', '${content|truncate:50}'),
|
|
amis()->TableColumn()
|
|
->name('result')
|
|
->label(__('complaint.complaint.result'))
|
|
->popOver('${result}')
|
|
->type('tpl')
|
|
->set('tpl', '${result|truncate:50}'),
|
|
amis()->TableColumn()
|
|
->name('complaint_status')
|
|
->label(__('complaint.complaint.complaint_status'))
|
|
->type('mapping')
|
|
->map(ComplaintStatus::labelMap()),
|
|
$this->rowActions([
|
|
$this->rowProcessStartButton()
|
|
->visible(Admin::user()->can('complaint.complaints.start'))
|
|
->visibleOn('${complaint_status === '.ComplaintStatus::Pending->value.'}'),
|
|
$this->rowProcessCompleteButton()
|
|
->visible(Admin::user()->can('complaint.complaints.complete'))
|
|
->visibleOn('${complaint_status === '.ComplaintStatus::Processing->value.'}'),
|
|
$this->rowShowButton()
|
|
->visible(Admin::user()->can('admin.complaint.complaints.view')),
|
|
]),
|
|
]);
|
|
|
|
return $this->baseList($crud);
|
|
}
|
|
|
|
public function detail(): Form
|
|
{
|
|
return $this->baseDetail()->title('')->body([
|
|
amis()->Property()->items([
|
|
['label' => __('complaint.complaint.employee'), 'content' => '${anonymous ? "匿名" : employee.name}'],
|
|
['label' => __('complaint.complaint.created_at'), 'content' => '${created_at}'],
|
|
['label' => __('complaint.complaint.complaint_status'), 'content' => amis()->Mapping()->name('complaint_status')->map(ComplaintStatus::labelMap())],
|
|
['label' => __('complaint.complaint.content'), 'content' => '${content}', 'span' => 3],
|
|
['label' => __('complaint.complaint.result'), 'content' => '${result}', 'span' => 3],
|
|
['label' => __('complaint.complaint.photos'), 'content' => amis()->Images()->enlargeAble()->source('${photos}')->enlargeWithGallary(), 'span' => 3],
|
|
]),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 处理开始
|
|
*/
|
|
public function start($id)
|
|
{
|
|
/** @var Complaint */
|
|
$complaint = Complaint::findOrFail($id);
|
|
|
|
if (! $complaint->isPending()) {
|
|
admin_abort('举报投诉记录的状态不是待审核');
|
|
}
|
|
|
|
$complaint->update([
|
|
'complaint_status' => ComplaintStatus::Processing->value,
|
|
]);
|
|
|
|
return $this->response()->successMessage('操作成功');
|
|
}
|
|
|
|
/**
|
|
* 处理结束
|
|
*/
|
|
public function complete($id, Request $request)
|
|
{
|
|
$validator = Validator::make(
|
|
data: $request->input(),
|
|
rules: [
|
|
'result' => ['bail', 'required', 'string'],
|
|
],
|
|
attributes: [
|
|
'result' => __('complaint.complaint.result'),
|
|
],
|
|
);
|
|
|
|
if ($validator->fails()) {
|
|
admin_abort($validator->errors()->first());
|
|
}
|
|
|
|
/** @var Complaint */
|
|
$complaint = Complaint::findOrFail($id);
|
|
|
|
if (! $complaint->isProcessing()) {
|
|
admin_abort('举报投诉记录的状态不是处理中');
|
|
}
|
|
|
|
$complaint->update([
|
|
'result' => $request->input('result'),
|
|
'complaint_status' => ComplaintStatus::Processed->value,
|
|
]);
|
|
|
|
return $this->response()->successMessage('操作成功');
|
|
}
|
|
|
|
/**
|
|
* 处理开始按钮
|
|
*/
|
|
protected function rowProcessStartButton(): AjaxAction
|
|
{
|
|
return amis()->AjaxAction()
|
|
->icon('fa fa-play-circle-o')
|
|
->label(__('complaint.complaint.start'))
|
|
->level('link')
|
|
->api('post:'.admin_url('/complaint/complaints/$id/start'))
|
|
->confirmText('是否开始处理选中的举报投诉记录')
|
|
->confirmTitle('系统消息');
|
|
}
|
|
|
|
/**
|
|
* 处理结束按钮
|
|
*/
|
|
protected function rowProcessCompleteButton(): DrawerAction
|
|
{
|
|
return amis()->DrawerAction()->icon('fa fa-stop-circle-o')->label(__('complaint.complaint.complete'))->level('link')->drawer(
|
|
amis()->Drawer()->title(__('complaint.complaint.result'))->body([
|
|
amis()->Form()->title('')
|
|
->api('post:'.admin_url('/complaint/complaints/$id/complete'))
|
|
->body([
|
|
amis()->TextareaControl('result', __('complaint.complaint.result'))->required()->minRows(15),
|
|
]),
|
|
])->size('lg')
|
|
);
|
|
}
|
|
}
|