154 lines
3.9 KiB
PHP
154 lines
3.9 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\project;
|
||
|
||
|
||
use app\common\model\dict\DictData;
|
||
use app\common\model\project\ProjectExpenseReimbursement;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 发票明细验证器
|
||
* Class ProjectExpenseReimbursementInvoiceDetailValidate
|
||
* @package app\adminapi\validate\project
|
||
*/
|
||
class ProjectExpenseReimbursementInvoiceDetailValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require',
|
||
'expense_reimbursement_id' => 'require|checkExpenseReimbursement',
|
||
'invoice_type' => 'require|checkInvoiceType',
|
||
'invoice_sn' => 'require',
|
||
'tax_rate' => 'require|checkTaxRate',
|
||
'invoice_form' => 'require|checkInvoiceForm',
|
||
'invoice_amount' => 'require|float|gt:0',
|
||
'annex' => 'checkAnnex'
|
||
];
|
||
|
||
|
||
/**
|
||
* 参数描述
|
||
* @var string[]
|
||
*/
|
||
protected $field = [
|
||
'id' => 'id',
|
||
'expense_reimbursement_id' => '费用报销单id',
|
||
'invoice_type' => '发票类型',
|
||
'invoice_sn' => '发票号',
|
||
'tax_rate' => '发票税率',
|
||
'invoice_form' => '发票形式',
|
||
'invoice_amount' => '发票金额',
|
||
];
|
||
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return ProjectExpenseReimbursementInvoiceDetailValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/19 13:44
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->remove('id', true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return ProjectExpenseReimbursementInvoiceDetailValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/19 13:44
|
||
*/
|
||
public function sceneEdit()
|
||
{
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return ProjectExpenseReimbursementInvoiceDetailValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/19 13:44
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id'])->remove('id', 'checkData');
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return ProjectExpenseReimbursementInvoiceDetailValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/19 13:44
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
public function checkExpenseReimbursement($value): bool|string
|
||
{
|
||
$data = ProjectExpenseReimbursement::where('id', $value)->findOrEmpty();
|
||
if ($data->isEmpty()) {
|
||
return '费用报销信息不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkInvoiceType($value): bool|string
|
||
{
|
||
$dict = DictData::where('type_value', 'invoice_type')->column('value');
|
||
if (!in_array($value, $dict)) {
|
||
return '发票类型数据值无效';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkTaxRate($value): bool|string
|
||
{
|
||
$dict = DictData::where('type_value', 'tax_rate')->column('value');
|
||
if (!in_array($value, $dict)) {
|
||
return '发票税率数据值无效';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkInvoiceForm($value)
|
||
{
|
||
$dict = DictData::where('type_value', 'invoice_form')->column('value');
|
||
if (!in_array($value, $dict)) {
|
||
return '发票形式数据值无效';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkAnnex($value): bool|string
|
||
{
|
||
if (!empty($value) && $value != '') {
|
||
if (!is_array($value)) {
|
||
return '附件格式错误';
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
} |