store-manage/app/Admin/Controllers/Plan/TaskController.php

85 lines
3.5 KiB
PHP

<?php
namespace App\Admin\Controllers\Plan;
use App\Admin\Controllers\AdminController;
use App\Admin\Filters\TaskFilter;
use App\Admin\Services\Plan\TaskService;
use App\Enums\CheckStatus;
use App\Enums\TaskHygieneStatus;
use App\Models\Task;
use App\Models\TaskHygiene;
use App\Models\TaskLedger;
use App\Models\TaskPerformance;
use App\Traits\HasCheckActions;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Http\Request;
use Slowlyo\OwlAdmin\Renderers\Form;
/**
* @property TaskService $service
*/
class TaskController extends AdminController
{
use HasCheckActions;
protected string $serviceName = TaskService::class;
public function detail(): Form
{
$taskDetailId = 'task-detail';
$workflowLogListId = 'task-workflow-service';
return $this->baseDetail()->id($taskDetailId)->title('')->onEvent([
'inited' => [
'actions' => [
['actionType' => 'reload', 'componentId' => $workflowLogListId],
],
],
])->body([
amis()->Property()->items([
['label' => __('plan.task_hygiene.month'), 'content' => '${taskable.month}'],
['label' => __('plan.task_hygiene.store'), 'content' => '${taskable.store.title}'],
['label' => __('plan.task_hygiene.store_master'), 'content' => '${taskable.store_master.name}'],
['label' => __('plan.task_hygiene.status'), 'content' => amis()->Mapping()->name('taskable.task_status')->map(TaskHygieneStatus::labelMap())],
['label' => __('plan.task.completed_at'), 'content' => '${completed_at}'],
['label' => __('plan.task.created_at'), 'content' => '${created_at}'],
['label' => __('plan.task_hygiene.description'), 'content' => '${taskable.description}', 'span' => 3],
['label' => __('plan.task_hygiene.photos'), 'content' => amis()->Images()->enlargeAble()->source('${taskable.photos}')->enlargeWithGallary(), 'span' => 3],
['label' => __('workflow_log.check_status'), 'content' => amis()->Mapping()->name('taskable.workflow.check_status')->map(CheckStatus::labelMap())],
['label' => __('workflow_log.checked_at'), 'content' => '${taskable.workflow.checked_at}'],
['label' => __('workflow_log.remarks'), 'content' => '${taskable.workflow.check_remarks}'],
]),
amis()->Divider(),
$this->baseWorkflowLogList($taskDetailId)
->id($workflowLogListId)
->api(admin_url('/api/workflow/logs?id=${taskable.workflow.id}'))
->visibleOn('${taskable_type === "'.(new TaskHygiene())->getMorphClass().'"}'),
]);
}
public function shareList(Request $request)
{
$tasks = Task::filter($request->input(), TaskFilter::class)
->with([
'taskable' => function (MorphTo $morphTo) {
$morphTo->morphWith([
TaskLedger::class => ['store', 'storeMaster'],
TaskPerformance::class => ['store', 'storeMaster'],
TaskHygiene::class => ['store', 'storeMaster', 'workflow'],
]);
},
])
->latest('id')
->get();
return $this->response()->success(
$tasks->map(function (Task $task) {
return tap($task, fn (Task $task) => $task->taskable?->setRelation('task', $task->withoutRelations()));
})
);
}
}