168 lines
4.8 KiB
PHP
168 lines
4.8 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\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 项目总预算验证器
|
||
* Class ProjectTotalBudgetValidate
|
||
* @package app\adminapi\validate\project
|
||
*/
|
||
class ProjectTotalBudgetValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require',
|
||
'org_id' => 'require|checkOrg',
|
||
'dept_id' => 'require|checkDept',
|
||
'project_id' => 'require|checkProject',
|
||
'contract_amount' => 'require|float|egt:0',
|
||
'cl_cost' => 'float|egt:0',
|
||
'fb_cost' => 'float|egt:0',
|
||
'rg_cost' => 'float|egt:0',
|
||
'fy_cost' => 'float|egt:0',
|
||
'jj_cost' => 'float|egt:0',
|
||
'budget_list' => 'checkAnnex',
|
||
'budget_date' => 'require|dateFormat:Y-m-d',
|
||
'project_manager' => 'require',
|
||
'approve_detail' => 'require|checkApproveDetail',
|
||
];
|
||
|
||
protected $message = [
|
||
'id.require' => '缺少必要参数',
|
||
'org_id.require' => '请选择组织',
|
||
'dept_id.require' => '请选择部门',
|
||
'project_id.require' => '请选择项目',
|
||
'contract_amount.require' => '请填写合同金额',
|
||
'contract_amount.float' => '合同金额值必须是数字',
|
||
'contract_amount.egt' => '合同金额值必须大于等于0',
|
||
'cl_cost.float' => '材料成本值必须是数字',
|
||
'cl_cost.egt' => '材料成本值必须大于等于0',
|
||
'fb_cost.float' => '分包成本值必须是数字',
|
||
'fb_cost.egt' => '分包成本值必须大于等于0',
|
||
'rg_cost.float' => '人工成本值必须是数字',
|
||
'rg_cost.egt' => '人工成本值必须大于等于0',
|
||
'fy_cost.float' => '费用成本值必须是数字',
|
||
'fy_cost.egt' => '费用成本值必须大于等于0',
|
||
'jj_cost.float' => '机具成本值必须是数字',
|
||
'jj_cost.egt' => '机具成本值必须大于等于0',
|
||
'budget_date.dateFormat' => '预算日期数据格式错误',
|
||
'project_manager' => '请填写项目经理',
|
||
'approve_detail.require' => '请填写审批流程信息',
|
||
];
|
||
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return ProjectTotalBudgetValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/08 14:25
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->remove('id',true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return ProjectTotalBudgetValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/08 14:25
|
||
*/
|
||
public function sceneEdit()
|
||
{
|
||
return $this->remove('org_id',true)->remove('dept_id',true)->remove('project_id',true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return ProjectTotalBudgetValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/08 14:25
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return ProjectTotalBudgetValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/08 14:25
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
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 != ''){
|
||
$annex = $value;//json_decode($value,true);
|
||
if(empty($annex) || !is_array($annex)){
|
||
return '预算清单格式错误';
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
} |