203 lines
5.2 KiB
PHP
203 lines
5.2 KiB
PHP
<?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\works\bgsp;
|
||
|
||
|
||
use app\common\model\auth\Admin;
|
||
use app\common\model\dept\Dept;
|
||
use app\common\model\dict\DictData;
|
||
use app\common\model\works\bgsp\OaFlowType;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 审批流程验证器
|
||
* Class OaFlowValidate
|
||
* @package app\adminapi\validate\works\bgsp
|
||
*/
|
||
class OaFlowValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require',
|
||
'name' => 'require',
|
||
'check_type' => 'require|integer|in:1,2,3',
|
||
'type' => 'require|checkType',
|
||
'flow_cate' => 'require|checkFlowCate',
|
||
'department_ids' => 'checkDept',
|
||
'copy_uids' => 'checkCopyUser',
|
||
'flow_list' => 'requireCallback:check_require|checkFlowList'
|
||
];
|
||
|
||
|
||
/**
|
||
* 参数描述
|
||
* @var string[]
|
||
*/
|
||
protected $field = [
|
||
'id' => 'id',
|
||
'name' => '审批流名称',
|
||
'check_type' => '流程类型',
|
||
'type' => '应用模块',
|
||
'flow_cate' => '应用审批类型',
|
||
'department_ids' => '应用部门',
|
||
'copy_uids' => '抄送人',
|
||
'flow_list' => '审批流程'
|
||
];
|
||
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return OaFlowValidate
|
||
* @author likeadmin
|
||
* @date 2024/05/24 14:16
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->only(['name','check_type','type','flow_cate','department_ids','copy_uids','remark','flow_list']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return OaFlowValidate
|
||
* @author likeadmin
|
||
* @date 2024/05/24 14:16
|
||
*/
|
||
public function sceneEdit()
|
||
{
|
||
return $this->only(['id','name','check_type','type','flow_cate','department_ids','copy_uids','remark','flow_list']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return OaFlowValidate
|
||
* @author likeadmin
|
||
* @date 2024/05/24 14:16
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return OaFlowValidate
|
||
* @author likeadmin
|
||
* @date 2024/05/24 14:16
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
public function checkType($value): bool|string
|
||
{
|
||
$dict = DictData::where('type_value', 'oa_approve_cate')->column('value');
|
||
if (!in_array($value, $dict)) {
|
||
return '所属分类数据值无效';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkDept($value): bool|string
|
||
{
|
||
if(!empty($value)){
|
||
$data = explode(',',$value);
|
||
if(empty($data)){
|
||
return '应用部门数据错误';
|
||
}
|
||
foreach($data as $v){
|
||
$dept = Dept::where('id',$v)->findOrEmpty();
|
||
if($dept->isEmpty()){
|
||
return '应用部门信息不存在';
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkCopyUser($value): bool|string
|
||
{
|
||
if(!empty($value)){
|
||
$data = explode(',',$value);
|
||
if(empty($data)){
|
||
return '抄送人数据错误';
|
||
}
|
||
foreach($data as $v){
|
||
$user = Admin::where('id',$v)->findOrEmpty();
|
||
if($user->isEmpty()){
|
||
return '抄送人信息不存在';
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkFlowCate($value): bool|string
|
||
{
|
||
$data = OaFlowType::where('id',$value)->findOrEmpty();
|
||
return $data->isEmpty() ? '审批类型不存在' : true;
|
||
}
|
||
|
||
public function check_require($value, $data): bool
|
||
{
|
||
if($data['check_type'] != 2){
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
public function checkFlowList($value,$rule,$data): bool|string
|
||
{
|
||
if($data['check_type'] != 2) {
|
||
if(empty($value) || !is_array($value)) return '审批流程数据格式错误';
|
||
if($data['check_type'] == 1){
|
||
foreach ($value as $k=>$v) {
|
||
if(!isset($v['flow_type']) || !isset($v['flow_uids'])){
|
||
return '固定审批流数据参数缺失';
|
||
}
|
||
if(empty($v['flow_type']) || !in_array($v['flow_type'],[1,2,3])){
|
||
return '固定审批流第'.($k+1).'行的类型未选择';
|
||
}
|
||
if($v['flow_type'] > 1 && empty($v['flow_uids'])){
|
||
return '固定审批流第'.($k+1).'行的指定人未选择';
|
||
}
|
||
}
|
||
}
|
||
if($data['check_type'] == 3){
|
||
foreach ($value as $k=>$v) {
|
||
if(!isset($v['flow_type']) || !isset($v['flow_uids']) || !isset($v['flow_name'])){
|
||
return '可回退的审批流数据参数缺失';
|
||
}
|
||
if(empty($v['flow_name'])){
|
||
return '可回退的审批流第'.($k+1).'行的流程名称未填写';
|
||
}
|
||
if(empty($v['flow_uids'])){
|
||
return '可回退的审批流第'.($k+1).'行的指定人未选择';
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
} |