engineering/app/adminapi/validate/project/ProjectLaborBudgetValidate.php
2024-02-03 15:25:23 +08:00

185 lines
4.6 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\project;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\project\Project;
use app\common\model\project\ProjectJobType;
use app\common\model\project\ProjectLaborBudgetDetail;
use app\common\validate\BaseValidate;
/**
* 人工预算验证器
* Class ProjectLaborBudgetValidate
* @package app\adminapi\validate\project
*/
class ProjectLaborBudgetValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'org_id' => 'require|checkOrg',
'dept_id' => 'require|checkDept',
'project_id' => 'require|checkProject',
'annex' => 'checkAnnex',
'labor_budget_detail' => 'require|checkLaborBudgetDetail',
'approve_detail' => 'require|checkApproveDetail',
];
protected $message = [
'id.require' => '缺少必要参数',
'org_id.require' => '请选择组织',
'dept_id.require' => '请选择部门',
'project_id.require' => '请选择项目',
'labor_budget_detail.require' => '请填写人工预算清单',
'approve_detail.require' => '请填写审批流程信息',
];
/**
* @notes 添加场景
* @return ProjectLaborBudgetValidate
* @author likeadmin
* @date 2024/01/16 09:26
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return ProjectLaborBudgetValidate
* @author likeadmin
* @date 2024/01/16 09:26
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return ProjectLaborBudgetValidate
* @author likeadmin
* @date 2024/01/16 09:26
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ProjectLaborBudgetValidate
* @author likeadmin
* @date 2024/01/16 09:26
*/
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 != ''){
if(!is_array($value)){
return '附件格式错误';
}
}
return true;
}
public function checkLaborBudgetDetail($value): bool|string
{
if(empty($value) || !is_array($value)){
return '人工预算清单数据格式错误';
}
foreach($value as $v) {
if(isset($v['id']) && $v['id'] != ''){
$data = ProjectLaborBudgetDetail::where('id',$v['id'])->findOrEmpty();
if($data->isEmpty()){
return '人工预算明细信息不存在';
}
}
if(empty($v['job_type_id'])){
return '请选择工种';
}else{
$job_type = ProjectJobType::where('id',$v['job_type_id'])->findOrEmpty();
if($job_type->isEmpty()){
return '工种信息不存在';
}
}
if(empty($v['num'])){
return '数量不能为空';
}else{
if(!is_numeric($v['num']) || $v['num'] < 0){
return '数量必须是大于0的数字';
}
}
if(empty($v['price'])){
return '单价不能为空';
}else{
if(!is_numeric($v['price']) || $v['price'] < 0){
return '单价必须是大于0的数字';
}
}
}
return true;
}
}