143 lines
4.1 KiB
PHP
143 lines
4.1 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\financial;
|
||
|
||
|
||
use app\common\model\dict\DictData;
|
||
use app\common\model\financial\FinancialFeeApplication;
|
||
use app\common\model\financial\FinancialFeeApplicationDetail;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 财务管理--费用申请验证器
|
||
* Class FinancialFeeApplicationValidate
|
||
* @package app\adminapi\validate\financial
|
||
*/
|
||
class FinancialFeeApplicationValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require|checkData',
|
||
'theme' => 'require',
|
||
'days' => 'require|float|egt:0',
|
||
'create_user' => 'require',
|
||
'create_time' => 'require|dateFormat:Y-m-d H:i:s',
|
||
'detail' => 'checkDetail'
|
||
];
|
||
|
||
|
||
/**
|
||
* 参数描述
|
||
* @var string[]
|
||
*/
|
||
protected $field = [
|
||
'id' => 'id',
|
||
'theme' => '单据主题',
|
||
'days' => '借款天数',
|
||
'create_user' => '申请人',
|
||
'create_time' => '申请日期',
|
||
];
|
||
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return FinancialFeeApplicationValidate
|
||
* @author likeadmin
|
||
* @date 2024/03/27 14:53
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->only(['theme', 'days', 'create_user', 'create_time', 'detail']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return FinancialFeeApplicationValidate
|
||
* @author likeadmin
|
||
* @date 2024/03/27 14:53
|
||
*/
|
||
public function sceneEdit()
|
||
{
|
||
return $this->only(['id', 'theme', 'days', 'create_user', 'create_time', 'detail']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return FinancialFeeApplicationValidate
|
||
* @author likeadmin
|
||
* @date 2024/03/27 14:53
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id'])->remove('id', 'checkData');
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return FinancialFeeApplicationValidate
|
||
* @author likeadmin
|
||
* @date 2024/03/27 14:53
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
public function checkData($value): bool|string
|
||
{
|
||
$data = FinancialFeeApplication::where('id', $value)->findOrEmpty();
|
||
return $data->isEmpty() ? '数据不存在' : true;
|
||
}
|
||
|
||
public function checkDetail($value): bool|string
|
||
{
|
||
if (empty($value) || $value == '') return true;
|
||
if (!is_array($value)) return '申请明细数据格式错误';
|
||
foreach ($value as $k => $v) {
|
||
if (isset($v['id']) && !empty($v['id'])) {
|
||
$data = FinancialFeeApplicationDetail::where('id', $v['id'])->findOrEmpty();
|
||
if ($data->isEmpty()) {
|
||
return '第' . ($k + 1) . '行申请明细信息不存在';
|
||
}
|
||
}
|
||
if (empty($v['subject_category'])) {
|
||
return '第' . ($k + 1) . '行科目类别为空';
|
||
} else {
|
||
$dict = DictData::where('type_value', 'subject_category')->column('value');
|
||
if (!in_array($v['subject_category'], $dict)) return '第' . ($k + 1) . '行科目类别数据值无效';
|
||
}
|
||
if (empty($v['bill_num'])) {
|
||
return '第' . ($k + 1) . '行票据张数为空';
|
||
} else {
|
||
if (!is_numeric($v['bill_num']) || $v['bill_num'] < 0) return '第' . ($k + 1) . '行票据张数必须是大于零的数字';
|
||
}
|
||
if (empty($v['amount'])) {
|
||
return '第' . ($k + 1) . '行申请金额为空';
|
||
} else {
|
||
if (!is_numeric($v['amount']) || $v['amount'] < 0) return '第' . ($k + 1) . '行申请金额必须是大于零的数字';
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
} |