generated from liutk/owl-admin-base
37 lines
1.3 KiB
PHP
37 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Resources\KeywordResource;
|
|
use App\Models\{WorkflowLog, WorkflowCheck};
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
|
use App\Enums\CheckType;
|
|
use App\Http\Resources\WorkflowLogResource;
|
|
|
|
class WorkflowController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$request->validate([
|
|
'subject_type' => 'required',
|
|
'subject_id' => 'required',
|
|
]);
|
|
$user = $this->guard()->user();
|
|
$storeId = $user->store_id;
|
|
$jobs = $user->jobs;
|
|
$jobValue = [];
|
|
foreach($jobs as $item) {
|
|
array_push($jobValue, $storeId . '-' . $item->key);
|
|
}
|
|
$query = WorkflowLog::with(['check'])
|
|
->whereHas('check', fn($q) => $q->where('subject_type', $request->input('subject_type'))->where('subject_id', $request->input('subject_id')))
|
|
->where(fn($q) =>
|
|
$q->where(fn($q1) => $q1->where('check_type', CheckType::User)->where('check_value', $user->id))
|
|
->orWhere(fn($q1) => $q->where('check_type', CheckType::Job)->whereIn('check_value', $jobValue))
|
|
);
|
|
$list = $query->paginate($request->input('per_page'));
|
|
|
|
}
|
|
}
|