196 lines
5.7 KiB
PHP
196 lines
5.7 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\FinancialUsingFunds;
|
||
use app\common\model\financial\FinancialUsingFundsDetail;
|
||
use app\common\model\marketing\MarketingContract;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 财务管理--用款申请单验证器
|
||
* Class FinancialUsingFundsValidate
|
||
* @package app\adminapi\validate\financial
|
||
*/
|
||
class FinancialUsingFundsValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require|checkData',
|
||
'approve_dept' => 'require|checkDept',
|
||
'cost_type' => 'require|checkCostType',
|
||
'pay_type' => 'require|checkPayType',
|
||
'pay_reason' => 'require',
|
||
'contract_id' => 'checkContract',
|
||
'has_pay_amount' => 'float|egt:0',
|
||
'this_pay_amount' => 'float|egt:0',
|
||
'accept_company' => 'require',
|
||
'accept_acount' => 'require',
|
||
'accept_bank' => 'require',
|
||
'accept_deposit' => 'require',
|
||
'bill_num' => 'float|egt:0',
|
||
'content' => 'require',
|
||
'create_user' => 'require',
|
||
'create_time' => 'require|dateFormat:Y-m-d H:i:s',
|
||
'detail' => 'checkDetail'
|
||
];
|
||
|
||
|
||
/**
|
||
* 参数描述
|
||
* @var string[]
|
||
*/
|
||
protected $field = [
|
||
'id' => 'id',
|
||
'code' => '单据编号',
|
||
'approve_dept' => '审批部门',
|
||
'cost_type' => '费用类别',
|
||
'pay_type' => '支付方式',
|
||
'pay_reason' => '付款原因',
|
||
'contract_id' => '支出合同',
|
||
'has_pay_amount' => '已支付金额',
|
||
'this_pay_amount' => '本次支付金额',
|
||
'accept_company' => '付往单位',
|
||
'accept_acount' => '收款账号',
|
||
'province' => '开户省份',
|
||
'city' => '开户城市',
|
||
'accept_bank' => '收款银行',
|
||
'accept_deposit' => '收款开户行',
|
||
'bill_num' => '附单据张数',
|
||
'content' => '事由',
|
||
'create_user' => '申请人',
|
||
'create_time' => '申请日期',
|
||
|
||
];
|
||
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return FinancialUsingFundsValidate
|
||
* @author likeadmin
|
||
* @date 2024/03/29 09:29
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->remove('id', true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return FinancialUsingFundsValidate
|
||
* @author likeadmin
|
||
* @date 2024/03/29 09:29
|
||
*/
|
||
public function sceneEdit()
|
||
{
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return FinancialUsingFundsValidate
|
||
* @author likeadmin
|
||
* @date 2024/03/29 09:29
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id'])->remove('id', 'checkData');
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return FinancialUsingFundsValidate
|
||
* @author likeadmin
|
||
* @date 2024/03/29 09:29
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
public function checkData($value): bool|string
|
||
{
|
||
$data = FinancialUsingFunds::where('id', $value)->findOrEmpty();
|
||
return $data->isEmpty() ? '数据不存在' : true;
|
||
}
|
||
|
||
public function checkDept($value): bool|string
|
||
{
|
||
$data = Dept::where('id', $value)->findOrEmpty();
|
||
return $data->isEmpty() ? '审批部门信息不存在' : true;
|
||
}
|
||
|
||
public function checkCostType($value): bool|string
|
||
{
|
||
$dict = DictData::where('type_value', 'cost_type')->column('value');
|
||
return !in_array($value, $dict) ? '费用类别数据值无效' : 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 checkContract($value): bool|string
|
||
{
|
||
if (empty($value)) return true;
|
||
$data = MarketingContract::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 = FinancialUsingFundsDetail::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;
|
||
}
|
||
|
||
} |