generated from liutk/owl-admin-base
任务详情
parent
d9b3488359
commit
64bfcf4bbb
|
|
@ -34,8 +34,8 @@ MySQL;
|
||||||
$tasks = Task::with([
|
$tasks = Task::with([
|
||||||
'taskable' => function (MorphTo $morphTo) {
|
'taskable' => function (MorphTo $morphTo) {
|
||||||
$morphTo->morphWith([
|
$morphTo->morphWith([
|
||||||
TaskHygiene::class => ['task', 'workflow'],
|
TaskHygiene::class => ['workflow'],
|
||||||
TaskLedger::class => ['task'],
|
TaskLedger::class,
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
@ -60,7 +60,46 @@ MySQL;
|
||||||
->orderBy('end_at', 'ASC')
|
->orderBy('end_at', 'ASC')
|
||||||
->simplePaginate($request->query('per_page', 20));
|
->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)
|
public function submit($id, Request $request)
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ Route::group([
|
||||||
|
|
||||||
// 我的任务 - 任务列表
|
// 我的任务 - 任务列表
|
||||||
Route::get('tasks', [TaskController::class, 'index']);
|
Route::get('tasks', [TaskController::class, 'index']);
|
||||||
|
Route::get('tasks/{task}', [TaskController::class, 'show']);
|
||||||
// 我的任务 - 提交任务
|
// 我的任务 - 提交任务
|
||||||
Route::post('tasks/{task}/submit', [TaskController::class, 'submit']);
|
Route::post('tasks/{task}/submit', [TaskController::class, 'submit']);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue