diff --git a/app/Admin/Services/WorkFlowService.php b/app/Admin/Services/WorkFlowService.php index 85fa559..c2eda16 100644 --- a/app/Admin/Services/WorkFlowService.php +++ b/app/Admin/Services/WorkFlowService.php @@ -2,13 +2,22 @@ namespace App\Admin\Services; +use App\Enums\MessageType; use App\Enums\{CheckStatus, CheckType}; use App\Models\Employee; +use App\Models\EmployeePromotion; +use App\Models\EmployeeSignRepair; +use App\Models\HolidayApply; use App\Models\Keyword; +use App\Models\OfficalBusiness; +use App\Models\OvertimeApply; +use App\Models\Reimbursement; use App\Models\Store; use App\Models\Workflow; use App\Models\WorkflowCheck; use App\Models\WorkflowLog; +use App\Services\MessageService; +use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\Facades\Validator; use Illuminate\Validation\Rule; @@ -101,6 +110,24 @@ class WorkFlowService extends BaseService $check->subject->checkSuccess(); + if ($employee = $check->employee) { + $text = $this->mapSubjectTypeText($check->subject_type); + if ($text !== '') { + (new MessageService())->create( + MessageType::Approval, + '审批提醒', + "您有一条【{$text}】已通过审核。", + [$employee], + [ + 'workflow_check' => [ + 'subject_id' => $check->subject_id, + 'subject_type' => $check->subject_type, + ], + ], + ); + } + } + return true; } @@ -117,6 +144,24 @@ class WorkFlowService extends BaseService $check->subject->checkFail(); + if ($employee = $check->employee) { + $text = $this->mapSubjectTypeText($check->subject_type); + if ($text !== '') { + (new MessageService())->create( + MessageType::Approval, + '审批提醒', + "您有一条【{$text}】未通过审核。", + [$employee], + [ + 'workflow_check' => [ + 'subject_id' => $check->subject_id, + 'subject_type' => $check->subject_type, + ], + ], + ); + } + } + return true; } @@ -187,6 +232,37 @@ class WorkFlowService extends BaseService 'check_type' => $log->check_type, ]); $log->update(['check_status' => CheckStatus::Processing]); + + $employees = []; + switch ($log->check_type) { + case CheckType::Job: + [$storeId, $jobId] = explode('-', $log->check_value); + $employees = Employee::where('store_id', $storeId) + ->whereHas('jobs', fn ($query) => $query->where('job_id', $jobId)) + ->pluck('id') + ->all(); + break; + + case CheckType::User: + $employees = [$log->check_value]; + break; + } + + if (count($employees)) { + $text = $this->mapSubjectTypeText($check->subject_type); + if ($text !== '') { + (new MessageService())->create( + MessageType::Approval, + '审批提醒', + "您有一条【{$text}】待审批。", + $employees, + [ + 'workflow_log' => ['id' => $log->id], + ], + ); + } + } + // 自动审核通过 if ($this->authCheck($check->employee, $log)) { return $this->check($check->employee, $log, true, ['remarks' => '自动审核通过']); @@ -261,4 +337,17 @@ class WorkFlowService extends BaseService return true; } + + protected function mapSubjectTypeText(string $subjectType): string + { + return match (Relation::getMorphedModel($subjectType)) { + EmployeeSignRepair::class => '补卡申请', + HolidayApply::class => '请假申请', + OvertimeApply::class => '加班申请', + OfficalBusiness::class => '出差报备', + EmployeePromotion::class => '升职申请', + Reimbursement::class => '报销申请', + default => '', + }; + } } diff --git a/app/Http/Resources/WorkflowCheckResource.php b/app/Http/Resources/WorkflowCheckResource.php index ddc4307..4df8d16 100644 --- a/app/Http/Resources/WorkflowCheckResource.php +++ b/app/Http/Resources/WorkflowCheckResource.php @@ -5,6 +5,7 @@ namespace App\Http\Resources; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Database\Eloquent\Relations\Relation; +use RuntimeException; class WorkflowCheckResource extends JsonResource {