engineering/app/adminapi/validate/project/ProjectAttendanceDetailValidate.php
2024-01-18 15:03:29 +08:00

162 lines
5.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\project;
use app\common\model\project\Project;
use app\common\model\project\ProjectPersonnel;
use app\common\validate\BaseValidate;
/**
* 考勤明细验证器
* Class ProjectAttendanceDetailValidate
* @package app\adminapi\validate\project
*/
class ProjectAttendanceDetailValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'project_id' => 'require|checkProject',
'person_id' => 'require|checkPerson',
'attendance_date' => 'require|dateFormat:Y-m-d',
'work_start_time' => 'checkWorkStartTime',
'work_end_time' => 'checkWorkEndTime',
'work_record_num' => 'require|float|gt:0',
'daily_salary' => 'require|float|gt:0',
'daily_living' => 'require|float|gt:0',
'daily_subsidy' => 'require|float|egt:0',
'daily_other' => 'require|float|egt:0',
'daily_income' => 'require|float|gt:0',
];
protected $message = [
'id.require' => '缺少必要参数',
'project_id.require' => '请选择项目',
'person_id.require' => '请选择项目人员',
'attendance_date.require' => '请选择考勤日期',
'attendance_date.dateFormat' => '考勤日期格式错误',
'work_record_num.require' => '请填写记工数量',
'work_record_num.float' => '记工数量值必须是数字',
'work_record_num.gt' => '记工数量值必须大于0',
'daily_salary.require' => '请填写日工资',
'daily_salary.float' => '日工资值必须是数字',
'daily_salary.gt' => '日工资值必须大于0',
'daily_living.require' => '请填写日生活费',
'daily_living.float' => '日生活费值必须是数字',
'daily_living.gt' => '日生活费值必须大于0',
'daily_subsidy.require' => '请填写日补贴',
'daily_subsidy.float' => '日补贴值必须是数字',
'daily_subsidy.egt' => '日补贴值必须大于等于0',
'daily_other.require' => '请填写日其它',
'daily_other.float' => '日其它值必须是数字',
'daily_other.egt' => '日其它值必须大于等于0',
'daily_income.require' => '请填写日收入',
'daily_income.float' => '日收入必须是数字',
'daily_income.gt' => '日收入值必须大于0',
];
/**
* @notes 添加场景
* @return ProjectAttendanceDetailValidate
* @author likeadmin
* @date 2023/12/26 10:54
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return ProjectAttendanceDetailValidate
* @author likeadmin
* @date 2023/12/26 10:54
*/
public function sceneEdit()
{
return $this->only(['id','attendance_date','work_start_time','work_end_time','work_record_num','daily_salary','daily_living','daily_subsidy','daily_other','daily_income']);
}
/**
* @notes 删除场景
* @return ProjectAttendanceDetailValidate
* @author likeadmin
* @date 2023/12/26 10:54
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ProjectAttendanceDetailValidate
* @author likeadmin
* @date 2023/12/26 10:54
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkProject($value): bool|string
{
$data = Project::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '项目不存在';
}
return true;
}
public function checkPerson($value,$rule,$data): bool|string
{
$person = ProjectPersonnel::where('id',$value)->findOrEmpty();
if($person->isEmpty() || $person['project_id'] != $data['project_id']){
return '项目人员不存在';
}
return true;
}
public function checkWorkStartTime($value): bool|string
{
if($value != ''){
if(date('Y-m-d H:i',strtotime($value)) != $value){
return '上班时间格式错误';
}
}
return true;
}
public function checkWorkEndTime($value,$rule,$data): bool|string
{
if($value != ''){
if(date('Y-m-d H:i',strtotime($value)) != $value){
return '下班时间格式错误';
}
if(strtotime($value) - strtotime($data['work_start_time']) <= 0){
return '下班时间不能小于上班时间';
}
}
return true;
}
}