'require', 'project_id' => 'require|checkProject', 'payment_type' => 'require|checkPaymentType', 'apply_date' => 'require|dateFormat:Y-m-d', 'annex' => 'checkAnnex', 'payment_detail' => 'require|checkPaymentDetail' ]; protected $message = [ 'id.require' => '缺少必要参数', 'project_id.require' => '请选择项目', 'payment_type.require' => '请选择付款类型', 'apply_date.require' => '请选择申请日期', 'apply_date.dateFormat' => '申请日期格式错误', 'payment_detail.require' => '工资支付明细不能为空', ]; /** * @notes 添加场景 * @return ProjectSalaryPaymentValidate * @author likeadmin * @date 2023/12/27 16:08 */ public function sceneAdd() { return $this->remove('id',true); } /** * @notes 编辑场景 * @return ProjectSalaryPaymentValidate * @author likeadmin * @date 2023/12/27 16:08 */ public function sceneEdit() {} /** * @notes 删除场景 * @return ProjectSalaryPaymentValidate * @author likeadmin * @date 2023/12/27 16:08 */ public function sceneDelete() { return $this->only(['id']); } /** * @notes 详情场景 * @return ProjectSalaryPaymentValidate * @author likeadmin * @date 2023/12/27 16:08 */ public function sceneDetail() { return $this->only(['id']); } public function checkProject($value): bool|string { $data = Project::where('id',$value)->findOrEmpty(); if($data->isEmpty()){ return '项目不存在'; } return true; } public function checkPaymentType($value): bool|string { $dictData = DictData::where('type_value','salary_payment_type')->column('value'); if(!in_array($value,$dictData)){ return '付款类型无效'; } return true; } public function checkAnnex($value): bool|string { if(!empty($value) && $value != ''){ if(!is_array($value)){ return '附件必须是json数组'; } } return true; } public function checkPaymentDetail($value,$rule,$data): bool|string { $payment_detail = $value;//json_decode($value,true); if(empty($payment_detail) || !is_array($payment_detail)){ return '工资支付明细数据格式错误'; } foreach($payment_detail as $v) { if(isset($v['id']) && $v['id'] != ''){ $info = ProjectSalaryDetail::where('id',$v['id'])->findOrEmpty(); if($info->isEmpty()){ return '工资支付明细信息不存在'; } } if(empty($v['person_id'])){ return '请选择项目人员'; }else{ $person = ProjectPersonnel::where('id',$v['person_id'])->findOrEmpty(); if($person->isEmpty() || $person['project_id'] != $data['project_id']){ return '项目人员不存在'; } } if(empty($v['apply_amount'])){ return '申请付款金额不能为空'; }else{ if(!is_numeric($v['apply_amount']) || $v['apply_amount'] <= 0){ return '申请付款金额必须是大于0的数字'; } } } return true; } }