generated from liutk/owl-admin-base
66 lines
2.2 KiB
PHP
66 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Services;
|
|
|
|
use App\Admin\Filters\EmployeeSignRepairFilter;
|
|
use App\Models\Employee;
|
|
use App\Models\{EmployeeSignRepair, EmployeeSign, EmployeeSignLog};
|
|
use App\Models\WorkflowCheck;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class EmployeeSignRepairService extends BaseService
|
|
{
|
|
protected array $withRelationships = ['employee', 'store', 'workflow'];
|
|
|
|
protected string $modelName = EmployeeSignRepair::class;
|
|
|
|
protected string $modelFilterName = EmployeeSignRepairFilter::class;
|
|
|
|
public function resloveData($data, $model = null)
|
|
{
|
|
// 获取员工所在的门店
|
|
if (! isset($data['store_id']) && isset($data['employee_id'])) {
|
|
$data['store_id'] = Employee::where('id', $data['employee_id'])->value('store_id');
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function validate($data, $model = null)
|
|
{
|
|
$createRules = [
|
|
'employee_id' => ['required'],
|
|
'repair_type' => ['required'],
|
|
'date' => ['required'],
|
|
'store_id' => ['required'],
|
|
'reason' => ['required'],
|
|
];
|
|
$updateRules = [
|
|
];
|
|
$message = [
|
|
'date.required' => __('employee_sign_repair.date').'必填',
|
|
'store_id.required' => __('employee_sign_repair.store_id').'必填',
|
|
'employee_id.required' => __('employee_sign_repair.employee_id').'必填',
|
|
'reason.required' => __('employee_sign_repair.reason').'必填',
|
|
'repair_type.required' => __('employee_sign_repair.repair_type').'必填',
|
|
'date.unique' => __('employee_sign_repair.date').' 已经申请过了',
|
|
];
|
|
$validator = Validator::make($data, $model ? $updateRules : $createRules, $message);
|
|
if ($validator->fails()) {
|
|
return $validator->errors()->first();
|
|
}
|
|
if (EmployeeSignLog::filter([
|
|
'date' => $data['date'],
|
|
'employee_id' => $data['employee_id'],
|
|
'sign_time' => $data['repair_type']
|
|
])->exists()) {
|
|
return '已经打过卡了';
|
|
}
|
|
// todo 已经打卡不能申请
|
|
// todo 验证申请时间是否重复
|
|
|
|
return true;
|
|
}
|
|
}
|