generated from liutk/owl-admin-base
api 审核流程
parent
fffc0a393c
commit
6dec9bba36
|
|
@ -5,10 +5,11 @@ namespace App\Http\Controllers\Api;
|
|||
use App\Admin\Services\WorkFlowService;
|
||||
use App\Exceptions\RuntimeException;
|
||||
use App\Http\Resources\ReimbursementResource;
|
||||
use App\Models\Keyword;
|
||||
use App\Models\{Keyword, Reimbursement, WorkflowCheck};
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\Rule;
|
||||
use App\Enums\CheckStatus;
|
||||
use Throwable;
|
||||
|
||||
class ReimbursementController extends Controller
|
||||
|
|
|
|||
|
|
@ -6,8 +6,9 @@ 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;
|
||||
use App\Enums\{CheckStatus};
|
||||
use App\Http\Resources\{WorkflowLogResource, WorkflowCheckResource};
|
||||
use App\Exceptions\RuntimeException;
|
||||
|
||||
class WorkflowController extends Controller
|
||||
{
|
||||
|
|
@ -15,22 +16,25 @@ class WorkflowController extends Controller
|
|||
{
|
||||
$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))
|
||||
);
|
||||
$query = WorkflowLog::with(['check.subject'])
|
||||
->whereHas('check',fn($q) => $q->where('subject_type', $request->input('subject_type')))
|
||||
->own($user)
|
||||
->where('check_status', CheckStatus::Processing)
|
||||
->orderBy('created_at', 'desc');
|
||||
$list = $query->paginate($request->input('per_page'));
|
||||
return WorkflowLogResource::collection($list);
|
||||
}
|
||||
|
||||
public function show($id, Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'subject_type' => 'required',
|
||||
]);
|
||||
$user = $this->guard()->user();
|
||||
$info = WorkflowLog::with(['check.subject'])->own($user)->findOrFail($id);
|
||||
|
||||
return WorkflowLogResource::make($info);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,22 @@ class WorkflowCheckResource extends JsonResource
|
|||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$resource = $this->mapResource($this->subject_type);
|
||||
return [
|
||||
'check_status' => $this->check_status,
|
||||
'check_status_text' => $this->check_status?->text(),
|
||||
'checked_at' => $this->checked_at?->getTimestamp(),
|
||||
'check_remarks' => (string) $this->check_remarks,
|
||||
'subject' => $resource ? $resource::make($this->whenLoaded('subject')) : '',
|
||||
'logs' => WorkflowLogResource::collection($this->whenLoaded('logs')),
|
||||
];
|
||||
}
|
||||
|
||||
protected function mapResource($key)
|
||||
{
|
||||
$map = [
|
||||
'reimbursements' => ReimbursementResource::class,
|
||||
];
|
||||
return data_get($map, $key);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,20 @@ class WorkflowLogResource extends JsonResource
|
|||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'check_id' => $this->check_id,
|
||||
'batch_id' => $this->batch_id,
|
||||
'check_type' => $this->check_type,
|
||||
'check_value' => $this->check_type,
|
||||
'check_name' => $this->check_name,
|
||||
'check_user_id' => $this->check_user_id,
|
||||
'checked_at' => $this->checked_at?->timestamp,
|
||||
'remarks' => $this->remarks,
|
||||
'check_status' => $this->check_status,
|
||||
'check_status_text' => $this->check_status?->text(),
|
||||
'sort' => $this->sort,
|
||||
'check' => WorkflowCheckResource::make($this->whenLoaded('check')),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* 报销管理
|
||||
*/
|
||||
class Reimbursement extends Model
|
||||
{
|
||||
use Filterable, HasCheckable, HasDateTimeFormatter, HasFactory;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\CheckStatus;
|
||||
use App\Enums\{CheckStatus, CheckType};
|
||||
use App\Traits\HasDateTimeFormatter;
|
||||
use EloquentFilter\Filterable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,17 @@ class WorkflowLog extends Model
|
|||
|
||||
public function scopeSort($q)
|
||||
{
|
||||
return $q->orderBy('sort');
|
||||
return $q->orderBy('batch_id')->orderBy('sort');
|
||||
}
|
||||
|
||||
public function scopeOwn($builder, $user)
|
||||
{
|
||||
$storeId = $user->store_id;
|
||||
$jobs = $user->jobs;
|
||||
$jobValue = [$user->id];
|
||||
foreach($jobs as $item) {
|
||||
array_push($jobValue, $storeId . '-' . $item->key);
|
||||
}
|
||||
return $builder->whereIn('check_value', $jobValue);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,10 @@ return new class extends Migration
|
|||
$table->timestamp('checked_at')->nullable()->comment('审核通过时间');
|
||||
$table->string('check_remarks')->nullable()->comment('审核未通过原因');
|
||||
|
||||
$table->string('check_type')->comment('审核类型{job, user}');
|
||||
$table->string('check_value')->comment('审核类型值');
|
||||
$table->string('check_name')->comment('审核名称(展示用)');
|
||||
|
||||
$table->timestamps();
|
||||
$table->comment('审核申请');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -43,9 +43,6 @@ Route::group([
|
|||
Route::get('/ledger/ledgers/{date}', [LedgerController::class, 'show']);
|
||||
Route::get('/ledger/lottery-types', [LotteryTypeController::class, 'index']);
|
||||
|
||||
// 报销管理
|
||||
Route::apiResource('reimbursements', ReimbursementController::class);
|
||||
|
||||
// 举报投诉
|
||||
Route::post('complaints', [ComplaintController::class, 'store']);
|
||||
// 意见箱
|
||||
|
|
@ -58,7 +55,12 @@ Route::group([
|
|||
});
|
||||
|
||||
// 报销管理
|
||||
Route::group(['middleware' => ['user_role:store_user']], function () {
|
||||
// Route::group(['middleware' => ['user_role:store_user']], function () {
|
||||
// });
|
||||
Route::get('reimbursements/checks', [\App\Http\Controllers\Api\ReimbursementController::class, 'checkList']);
|
||||
Route::apiResource('reimbursements', \App\Http\Controllers\Api\ReimbursementController::class);
|
||||
});
|
||||
|
||||
// 审核
|
||||
Route::get('workflow', [\App\Http\Controllers\Api\WorkflowController::class, 'index']);
|
||||
Route::get('workflow/{id}', [\App\Http\Controllers\Api\WorkflowController::class, 'show']);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue