194 lines
4.9 KiB
PHP
194 lines
4.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\dept\Dept;
|
||
use app\common\model\dept\Orgs;
|
||
use app\common\model\project\Project;
|
||
use app\common\model\project\ProjectCostBudget;
|
||
use app\common\model\project\ProjectCostBudgetDetail;
|
||
use app\common\model\project\ProjectCostTempSet;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 费用预算验证器
|
||
* Class ProjectCostBudgetValidate
|
||
* @package app\adminapi\validate\project
|
||
*/
|
||
class ProjectCostBudgetValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require|checkData',
|
||
'org_id' => 'require|checkOrg',
|
||
'dept_id' => 'require|checkDept',
|
||
'project_id' => 'require|checkProject',
|
||
'annex' => 'checkAnnex',
|
||
'cost_budget_detail' => 'require|checkCostBudgetDetail',
|
||
'flow_id' => 'require|checkFlow',
|
||
'path' => 'require',
|
||
];
|
||
|
||
protected $message = [
|
||
'id.require' => '缺少必要参数',
|
||
'org_id.require' => '请选择组织',
|
||
'dept_id.require' => '请选择部门',
|
||
'project_id.require' => '请选择项目',
|
||
'cost_budget_detail.require' => '请填写费用预算清单',
|
||
];
|
||
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return ProjectCostBudgetValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/16 14:32
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->remove('id', true)->remove('flow_id', true)->remove('path', true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return ProjectCostBudgetValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/16 14:32
|
||
*/
|
||
public function sceneEdit()
|
||
{
|
||
return $this->remove('flow_id', true)->remove('path', true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return ProjectCostBudgetValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/16 14:32
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id'])->remove('id', 'checkData');
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return ProjectCostBudgetValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/16 14:32
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
public function sceneApprove()
|
||
{
|
||
return $this->only(['id', 'flow_id', 'path']);
|
||
}
|
||
|
||
public function checkData($value): bool|string
|
||
{
|
||
$data = ProjectCostBudget::where('id', $value)->findOrEmpty();
|
||
if ($data->isEmpty()) {
|
||
return '数据不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkOrg($value): bool|string
|
||
{
|
||
$org = Orgs::where('id', $value)->findOrEmpty();
|
||
if ($org->isEmpty()) {
|
||
return '组织不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkDept($value, $rule, $data): bool|string
|
||
{
|
||
$dept = Dept::where('id', $value)->findOrEmpty();
|
||
if ($dept->isEmpty()) {
|
||
return '部门不存在';
|
||
}
|
||
if ($dept['org_id'] != $data['org_id']) {
|
||
return '部门无效';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkProject($value): bool|string
|
||
{
|
||
$project = Project::where('id', $value)->findOrEmpty();
|
||
if ($project->isEmpty()) {
|
||
return '项目信息不存在';
|
||
}
|
||
if ($project['is_budget'] != 1) {
|
||
return '该项目没有编制总预算,不能添加材料预算';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkAnnex($value): bool|string
|
||
{
|
||
if (!empty($value) && $value != '') {
|
||
if (!is_array($value)) {
|
||
return '附件格式错误';
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkCostBudgetDetail($value): bool|string
|
||
{
|
||
if (empty($value) || !is_array($value)) {
|
||
return '费用预算清单数据格式错误';
|
||
}
|
||
foreach ($value as $v) {
|
||
if (isset($v['id']) && $v['id'] != '') {
|
||
$data = ProjectCostBudgetDetail::where('id', $v['id'])->findOrEmpty();
|
||
if ($data->isEmpty()) {
|
||
return '费用预算明细信息不存在';
|
||
}
|
||
}
|
||
if (empty($v['project_cost_temp_id'])) {
|
||
return '科目模板不能为空';
|
||
} else {
|
||
$temp = ProjectCostTempSet::where('id', $v['project_cost_temp_id'])->findOrEmpty();
|
||
if ($temp->isEmpty()) {
|
||
return '科目模板不存在';
|
||
}
|
||
}
|
||
if (empty($v['amount'])) {
|
||
return '预算金额不能为空';
|
||
} else {
|
||
if (!is_numeric($v['amount']) || $v['amount'] < 0) {
|
||
return '预算金额必须是大于0的数字';
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
} |