lihaiMiddleOffice/app/oa/validate/jxgl/OaSelfExamineValidate.php
2025-03-01 16:57:42 +08:00

169 lines
4.3 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\oa\validate\jxgl;
use app\common\model\dict\DictData;
use app\common\model\jxgl\OaExamineTemp;
use app\common\model\jxgl\OaSelfExamine;
use app\common\model\jxgl\OaSelfExamineDetail;
use app\common\validate\BaseValidate;
/**
* 自评记录验证器
* Class OaSelfExamineValidate
* @package app\adminapi\validate\jxgl
*/
class OaSelfExamineValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require|checkData',
'examine_type' => 'require|checkExamineType',
'examine_temp_id' => 'require|checkExamineTemp',
'examine_month' => 'require|dateFormat:Y-m',
'detail' => 'require|checkDetail'
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'examine_type' => '考核类别',
'examine_temp_id' => '考核模板',
'examine_month' => '考核月份',
'detail' => '考核项',
];
/**
* @notes 添加场景
* @return OaSelfExamineValidate
* @author likeadmin
* @date 2024/06/03 15:36
*/
public function sceneAdd()
{
return $this->only(['examine_temp_id','examine_type','examine_month','detail']);
}
/**
* @notes 编辑场景
* @return OaSelfExamineValidate
* @author likeadmin
* @date 2024/06/03 15:36
*/
public function sceneEdit()
{
return $this->only(['id','examine_temp_id','examine_type','examine_month','detail']);
}
/**
* @notes 删除场景
* @return OaSelfExamineValidate
* @author likeadmin
* @date 2024/06/03 15:36
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return OaSelfExamineValidate
* @author likeadmin
* @date 2024/06/03 15:36
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkData($value): bool|string
{
$data = OaSelfExamine::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '数据不存在';
}
return true;
}
public function checkExamineType($value): bool|string
{
$dict = DictData::where('type_value','jxgl_check_type')->column('value');
if(!in_array($value,$dict)){
return '考核类别无效';
}
return true;
}
public function checkExamineTemp($value,$rule,$data): bool|string
{
$temp = OaExamineTemp::where('id',$value)->where('examine_type',$data['examine_type'])->findOrEmpty();
if($temp->isEmpty()){
return '考核模板信息不存在';
}
return true;
}
public function checkDetail($value): bool|string
{
if(!is_array($value) || empty($value)){
return '考核项数据格式错误';
}
foreach($value as $k => $v){
if(isset($v['id']) && !empty($v['id'])){
$data = OaSelfExamineDetail::where('id',$v['id'])->findOrEmpty();
if($data->isEmpty()){
return '第'.($k+1).'行数据不存在';
}
}
if(empty($v['examine_item'])){
return '第'.($k+1).'行考核项为空';
}
if(empty($v['score'])){
return '第'.($k+1).'行分数为空';
}else{
if(!is_numeric($v['score']) || $v['score'] < 0){
return '第'.($k+1).'行分数必须是大于0的数字';
}
}
if(empty($v['examine_desc'])){
return '第'.($k+1).'行考核说明为空';
}
if(empty($v['self_score'])){
return '第'.($k+1).'行自评评分为空';
}else{
if(!is_numeric($v['self_score']) || $v['self_score'] < 0){
return '第'.($k+1).'行自评评分必须是大于0的数字';
}
}
}
return true;
}
}