175 lines
5.4 KiB
PHP
175 lines
5.4 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\dept\Dept;
|
||
use app\common\model\dict\DictData;
|
||
use app\common\model\financial\FinancialExpenseReimbursement;
|
||
use app\common\model\financial\FinancialExpenseReimbursementDetail;
|
||
use app\common\model\financial\FinancialFeeApplication;
|
||
use app\common\model\marketing\MarketingContract;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 财务管理--费用报销单验证器
|
||
* Class FinancialExpenseReimbursementValidate
|
||
* @package app\adminapi\validate\financial
|
||
*/
|
||
class FinancialExpenseReimbursementValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require|checkData',
|
||
'contract_id' => 'checkContract',
|
||
'fee_application_id' => 'checkFeeApplication',
|
||
'theme' => 'require',
|
||
'bill_num' => 'require|integer',
|
||
'pay_type' => 'require|checkPayType',
|
||
'content' => 'require',
|
||
'create_user' => 'require',
|
||
'create_time' => 'require|dateFormat:Y-m-d H:i:s',
|
||
'annex' => 'checkAnnex',
|
||
'detail' => 'checkDetail'
|
||
];
|
||
|
||
|
||
/**
|
||
* 参数描述
|
||
* @var string[]
|
||
*/
|
||
protected $field = [
|
||
'id' => 'id',
|
||
'contract_id' => '合同id',
|
||
'fee_application_id' => '费用申请id',
|
||
'theme' => '单据主题',
|
||
'bill_num' => '单据张数',
|
||
'pay_type' => '支付方式',
|
||
'content' => '事由',
|
||
'create_user' => '申请人员',
|
||
'create_time' => '报销日期',
|
||
];
|
||
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return FinancialExpenseReimbursementValidate
|
||
* @author likeadmin
|
||
* @date 2024/03/28 09:26
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->only(['contract_id', 'fee_application_id', 'theme', 'bill_num', 'pay_type', 'content', 'create_user', 'create_time', 'annex', 'detail']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return FinancialExpenseReimbursementValidate
|
||
* @author likeadmin
|
||
* @date 2024/03/28 09:26
|
||
*/
|
||
public function sceneEdit()
|
||
{
|
||
return $this->only(['id', 'contract_id', 'fee_application_id', 'theme', 'bill_num', 'pay_type', 'content', 'create_user', 'create_time', 'annex', 'detail']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return FinancialExpenseReimbursementValidate
|
||
* @author likeadmin
|
||
* @date 2024/03/28 09:26
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id'])->remove('id', 'checkData');
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return FinancialExpenseReimbursementValidate
|
||
* @author likeadmin
|
||
* @date 2024/03/28 09:26
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
public function checkData($value): bool|string
|
||
{
|
||
$data = FinancialExpenseReimbursement::where('id', $value)->findOrEmpty();
|
||
return $data->isEmpty() ? '数据不存在' : true;
|
||
}
|
||
|
||
public function checkContract($value): bool|string
|
||
{
|
||
if (empty($value)) return true;
|
||
$data = MarketingContract::where('id', $value)->findOrEmpty();
|
||
return $data->isEmpty() ? '合同信息不存在' : true;
|
||
}
|
||
|
||
public function checkFeeApplication($value): bool|string
|
||
{
|
||
if (empty($value)) return true;
|
||
$data = FinancialFeeApplication::where('id', $value)->findOrEmpty();
|
||
return $data->isEmpty() ? '费用申请信息不存在' : true;
|
||
}
|
||
|
||
public function checkPayType($value): bool|string
|
||
{
|
||
$dict = DictData::where('type_value', 'financial_pay_type')->column('value');
|
||
return !in_array($value, $dict) ? '支付方式数据值无效' : 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 = FinancialExpenseReimbursementDetail::where('id', $v['id'])->findOrEmpty();
|
||
if ($data->isEmpty()) {
|
||
return '第' . ($k + 1) . '行报销明细信息不存在';
|
||
}
|
||
}
|
||
if (empty($v['dept_id'])) {
|
||
return '第' . ($k + 1) . '行费用归属部门为空';
|
||
} else {
|
||
$dept = Dept::where('id', $v['dept_id'])->findOrEmpty();
|
||
if ($dept->isEmpty()) return '第' . ($k + 1) . '行费用归属部门信息不存在';
|
||
}
|
||
if (empty($v['subject_name'])) {
|
||
return '第' . ($k + 1) . '行科目名称为空';
|
||
} else {
|
||
$dict = DictData::where('type_value', 'subject_category')->column('value');
|
||
if (!in_array($v['subject_name'], $dict)) return '第' . ($k + 1) . '行科目名称数据值无效';
|
||
}
|
||
if (empty($v['amount'])) {
|
||
return '第' . ($k + 1) . '行金额为空';
|
||
} else {
|
||
if (!is_numeric($v['amount']) || $v['amount'] < 0) return '第' . ($k + 1) . '行金额必须是大于零的数字';
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
} |