'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']); } /** * @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; } }