generated from liutk/owl-admin-base
审批通知
parent
d604a383d9
commit
17e80b0d43
|
|
@ -2,13 +2,22 @@
|
||||||
|
|
||||||
namespace App\Admin\Services;
|
namespace App\Admin\Services;
|
||||||
|
|
||||||
|
use App\Enums\MessageType;
|
||||||
use App\Enums\{CheckStatus, CheckType};
|
use App\Enums\{CheckStatus, CheckType};
|
||||||
use App\Models\Employee;
|
use App\Models\Employee;
|
||||||
|
use App\Models\EmployeePromotion;
|
||||||
|
use App\Models\EmployeeSignRepair;
|
||||||
|
use App\Models\HolidayApply;
|
||||||
use App\Models\Keyword;
|
use App\Models\Keyword;
|
||||||
|
use App\Models\OfficalBusiness;
|
||||||
|
use App\Models\OvertimeApply;
|
||||||
|
use App\Models\Reimbursement;
|
||||||
use App\Models\Store;
|
use App\Models\Store;
|
||||||
use App\Models\Workflow;
|
use App\Models\Workflow;
|
||||||
use App\Models\WorkflowCheck;
|
use App\Models\WorkflowCheck;
|
||||||
use App\Models\WorkflowLog;
|
use App\Models\WorkflowLog;
|
||||||
|
use App\Services\MessageService;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
|
@ -101,6 +110,24 @@ class WorkFlowService extends BaseService
|
||||||
|
|
||||||
$check->subject->checkSuccess();
|
$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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,6 +144,24 @@ class WorkFlowService extends BaseService
|
||||||
|
|
||||||
$check->subject->checkFail();
|
$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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -187,6 +232,37 @@ class WorkFlowService extends BaseService
|
||||||
'check_type' => $log->check_type,
|
'check_type' => $log->check_type,
|
||||||
]);
|
]);
|
||||||
$log->update(['check_status' => CheckStatus::Processing]);
|
$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)) {
|
if ($this->authCheck($check->employee, $log)) {
|
||||||
return $this->check($check->employee, $log, true, ['remarks' => '自动审核通过']);
|
return $this->check($check->employee, $log, true, ['remarks' => '自动审核通过']);
|
||||||
|
|
@ -261,4 +337,17 @@ class WorkFlowService extends BaseService
|
||||||
|
|
||||||
return true;
|
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 => '',
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace App\Http\Resources;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
class WorkflowCheckResource extends JsonResource
|
class WorkflowCheckResource extends JsonResource
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue