204 lines
5.3 KiB
PHP
204 lines
5.3 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\adminapi\validate\oa;
|
||
|
||
|
||
use app\common\model\auth\Admin;
|
||
use app\common\model\dict\DictData;
|
||
use app\common\model\oa\FlowType;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 审批流程验证器
|
||
* Class FlowValidate
|
||
* @package app\adminapi\validate\oa
|
||
*/
|
||
class FlowValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require',
|
||
'name' => 'require',
|
||
'flow_cate' => 'require|checkFlowCate',
|
||
'check_type' => 'require|checkCheckType',
|
||
'flow_list' => 'require|checkFlowList',
|
||
'status' => 'require|checkStatus',
|
||
'copy_uids' => 'array|checkCopyUids',
|
||
];
|
||
|
||
|
||
/**
|
||
* 参数描述
|
||
* @var string[]
|
||
*/
|
||
protected $field = [
|
||
'id' => 'id',
|
||
'name' => '审批流名称',
|
||
'flow_cate' => '审批类型',
|
||
'check_type' => '审批流类型',
|
||
'flow_list' => '审批流程',
|
||
'status' => '状态',
|
||
'copy_uids' => '抄送人',
|
||
];
|
||
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return FlowValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/31 14:44
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->remove('id', true)->remove('status', true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return FlowValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/31 14:44
|
||
*/
|
||
public function sceneEdit()
|
||
{
|
||
return $this->only(['id', 'name', 'flow_cate', 'check_type', 'flow_list', 'status', 'copy_uids']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return FlowValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/31 14:44
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id'])->remove('id', 'checkData');
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return FlowValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/31 14:44
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
public function checkFlowCate($value): bool|string
|
||
{
|
||
$data = FlowType::where('id', $value)->findOrEmpty();
|
||
if ($data->isEmpty()) {
|
||
return '审批类型信息不存在';
|
||
}
|
||
if ($data['status'] != 2) {
|
||
return '该审批类型已被禁用';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkCheckType($value): bool|string
|
||
{
|
||
$dict = DictData::where('type_value', 'flow_check_type')->column('value');
|
||
if (!in_array($value, $dict)) {
|
||
return '审批流类型值无效';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkFlowList($value, $rule, $data): bool|string
|
||
{
|
||
if (!is_array($value)) {
|
||
return '审批流程数据格式错误';
|
||
}
|
||
//固定审批
|
||
if ($data['check_type'] == 1) {
|
||
$dict = DictData::where('type_value', 'flow_step_flow_type')->column('value');
|
||
foreach ($value as $k => $v) {
|
||
if (empty($v['flow_step'])) {
|
||
return '请选择审批步骤类型';
|
||
} else {
|
||
if (!in_array($v['flow_step'], $dict)) {
|
||
return '审批步骤类型值无效';
|
||
}
|
||
}
|
||
if ($v['flow_step'] == 2 || $v['flow_step'] == 3) {
|
||
if (empty($v['flow_user'])) {
|
||
return '审批流程第' . ($k + 1) . '行的指定人未选择';
|
||
}
|
||
if (!is_array($v['flow_user'])) {
|
||
return '审批流程第' . ($k + 1) . '行的指定人数据格式错误';
|
||
}
|
||
foreach ($v['flow_user'] as $k2 => $v2) {
|
||
$admin = Admin::where('id', $v2)->findOrEmpty();
|
||
if ($admin->isEmpty()) {
|
||
return '审批流程第' . ($k + 1) . '行的第' . ($k2 + 1) . '个指定人信息不存在';
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if ($data['check_type'] == 2) {
|
||
foreach ($value as $k => $v) {
|
||
if (empty($v['flow_step'])) {
|
||
return '请填写审批步骤名称';
|
||
}
|
||
if (empty($v['flow_user'])) {
|
||
return '审批流程第' . ($k + 1) . '行的指定人未选择';
|
||
}
|
||
if (!is_array($v['flow_user'])) {
|
||
return '审批流程第' . ($k + 1) . '行的指定人数据格式错误';
|
||
}
|
||
foreach ($v['flow_user'] as $k2 => $v2) {
|
||
$admin = Admin::where('id', $v2)->findOrEmpty();
|
||
if ($admin->isEmpty()) {
|
||
return '审批流程第' . ($k + 1) . '行的第' . ($k2 + 1) . '个指定人信息不存在';
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkCopyUids($value): bool|string
|
||
{
|
||
foreach ($value as $k => $v) {
|
||
$admin = Admin::where('id', $v)->findOrEmpty();
|
||
if ($admin->isEmpty()) {
|
||
return '第' . ($k + 1) . '个抄送人信息不存在';
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkStatus($value)
|
||
{
|
||
$dict = DictData::where('type_value', 'flow_type_status')->column('value');
|
||
if (!in_array($value, $dict)) {
|
||
return '状态值无效';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
} |