generated from liutk/owl-admin-base
任务详情
parent
d9b3488359
commit
64bfcf4bbb
|
|
@ -34,8 +34,8 @@ MySQL;
|
|||
$tasks = Task::with([
|
||||
'taskable' => function (MorphTo $morphTo) {
|
||||
$morphTo->morphWith([
|
||||
TaskHygiene::class => ['task', 'workflow'],
|
||||
TaskLedger::class => ['task'],
|
||||
TaskHygiene::class => ['workflow'],
|
||||
TaskLedger::class,
|
||||
]);
|
||||
},
|
||||
])
|
||||
|
|
@ -60,7 +60,46 @@ MySQL;
|
|||
->orderBy('end_at', 'ASC')
|
||||
->simplePaginate($request->query('per_page', 20));
|
||||
|
||||
return TaskResource::collection($tasks);
|
||||
return TaskResource::collection(
|
||||
$tasks->through(function ($task) {
|
||||
$task->taskable->setRelation('task', $task->withoutRelations());
|
||||
return $task;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public function show($id, Request $request)
|
||||
{
|
||||
/** @var \App\Models\Employee */
|
||||
$user = $request->user();
|
||||
|
||||
$task = Task::with([
|
||||
'taskable' => function (MorphTo $morphTo) {
|
||||
$morphTo->morphWith([
|
||||
TaskHygiene::class => ['workflow', 'store'],
|
||||
TaskLedger::class => ['store'],
|
||||
]);
|
||||
},
|
||||
])->whereHasMorph(
|
||||
'taskable',
|
||||
[TaskHygiene::class, TaskLedger::class],
|
||||
function (Builder $query, string $type) use ($user) {
|
||||
switch ($type) {
|
||||
case TaskLedger::class:
|
||||
case TaskHygiene::class:
|
||||
if ($user->isStoreMaster()) {
|
||||
$query->where('store_id', $user->store_id);
|
||||
} else {
|
||||
$query->whereRaw('1!=1');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
)->findOrFail($id);
|
||||
|
||||
$task->taskable->setRelation('task', $task->withoutRelations());
|
||||
|
||||
return TaskResource::make($task);
|
||||
}
|
||||
|
||||
public function submit($id, Request $request)
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ Route::group([
|
|||
|
||||
// 我的任务 - 任务列表
|
||||
Route::get('tasks', [TaskController::class, 'index']);
|
||||
Route::get('tasks/{task}', [TaskController::class, 'show']);
|
||||
// 我的任务 - 提交任务
|
||||
Route::post('tasks/{task}/submit', [TaskController::class, 'submit']);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue