engineering/app/adminapi/validate/financial/FinancialBudgetDocValidate.php
2024-04-06 11:39:32 +08:00

156 lines
4.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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\FinancialBudgetDoc;
use app\common\model\financial\FinancialBudgetDocDetail;
use app\common\model\marketing\MarketingContract;
use app\common\validate\BaseValidate;
/**
* 财务管理--项目预算书验证器
* Class FinancialBudgetDocValidate
* @package app\adminapi\validate\financial
*/
class FinancialBudgetDocValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require|checkData',
'contract_id' => 'require|checkContract',
'name' => 'require',
'issue_date' => 'require|dateFormat:Y-m-d',
'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',
'name' => '预算书名称',
'issue_date' => '下达日期',
'remark' => '备注',
'create_user' => '创建人',
'create_time' => '创建时间'
];
/**
* @notes 添加场景
* @return FinancialBudgetDocValidate
* @author likeadmin
* @date 2024/03/26 13:54
*/
public function sceneAdd()
{
return $this->only(['contract_id', 'name', 'issue_date', 'remark', 'create_user', 'create_time', 'annex', 'detail']);
}
/**
* @notes 编辑场景
* @return FinancialBudgetDocValidate
* @author likeadmin
* @date 2024/03/26 13:54
*/
public function sceneEdit()
{
return $this->only(['id', 'contract_id', 'name', 'issue_date', 'remark', 'create_user', 'create_time', 'annex', 'detail']);
}
/**
* @notes 删除场景
* @return FinancialBudgetDocValidate
* @author likeadmin
* @date 2024/03/26 13:54
*/
public function sceneDelete()
{
return $this->only(['id'])->remove('id', 'checkData');
}
/**
* @notes 详情场景
* @return FinancialBudgetDocValidate
* @author likeadmin
* @date 2024/03/26 13:54
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkData($value): bool|string
{
$data = FinancialBudgetDoc::where('id', $value)->findOrEmpty();
return $data->isEmpty() ? '数据不存在' : true;
}
public function checkContract($value): bool|string
{
$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 = FinancialBudgetDocDetail::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['type'])) {
return '第' . ($k + 1) . '行预算分成方式为空';
} else {
$dict = DictData::where('type_value', 'budget_share_method')->column('value');
if (!in_array($v['type'], $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;
}
}