'require|checkData', 'project_id' => 'require|checkProject', 'apply_user' => 'require', 'apply_date' => 'require|dateFormat:Y-m-d', 'reimbursement_type' => 'require|checkReimbursementType', 'loan_apply_id' => 'requireCallback:check_require|checkLoanApply', 'offset_loan_amount' => 'requireCallback:check_require|float|egt:0', 'payee_name' => 'require', 'payee_bank' => 'require', 'payee_account' => 'require', 'annex' => 'checkAnnex', 'bank_account_id' => 'require|checkBankAccount', 'reimbursement_detail' => 'require|checkReimbursementDetail', 'invoice_detail' => 'require|checkInvoiceDetail', 'flow_id' => 'require|checkFlow', 'path' => 'require', ]; /** * 参数描述 * @var string[] */ protected $field = [ 'id' => 'id', 'project_id' => '项目id', 'apply_user' => '报销人', 'apply_date' => '报销日期', 'reimbursement_type' => '报销类型', 'loan_apply_id' => '借款申请id', 'offset_loan_amount' => '冲抵借款金额', 'payee_name' => '收款人姓名', 'payee_bank' => '收款银行', 'payee_account' => '收款账号', 'bank_account_id' => '付款银行账户id', 'reimbursement_detail' => '报销明细', 'invoice_detail' => '发票明细', ]; /** * @notes 添加场景 * @return ProjectExpenseReimbursementValidate * @author likeadmin * @date 2024/01/19 13:44 */ public function sceneAdd() { return $this->remove('id', true)->remove('flow_id', true)->remove('path', true); } /** * @notes 编辑场景 * @return ProjectExpenseReimbursementValidate * @author likeadmin * @date 2024/01/19 13:44 */ public function sceneEdit() { return $this->remove('flow_id', true)->remove('path', true); } /** * @notes 删除场景 * @return ProjectExpenseReimbursementValidate * @author likeadmin * @date 2024/01/19 13:44 */ public function sceneDelete() { return $this->only(['id'])->remove('id', 'checkData'); } /** * @notes 详情场景 * @return ProjectExpenseReimbursementValidate * @author likeadmin * @date 2024/01/19 13:44 */ public function sceneDetail() { return $this->only(['id']); } public function sceneApprove() { return $this->only(['id', 'flow_id', 'path']); } public function checkData($value): bool|string { $data = ProjectExpenseReimbursement::where('id', $value)->findOrEmpty(); if ($data->isEmpty()) { return '数据不存在'; } return true; } public function checkProject($value): bool|string { $data = Project::where('id', $value)->findOrEmpty(); if ($data->isEmpty()) { return '项目信息不存在'; } return true; } public function checkReimbursementType($value): bool|string { $data = explode(',', $value); if (empty($data)) { return '报销类型数据格式错误'; } foreach ($data as $v) { $dict = DictData::where('type_value', 'reimbursement_type')->column('value'); if (!in_array($v, $dict)) { return '报销类型数据无效'; } } return true; } function check_require($value, $data): bool { $reimbursement_type = explode(',', $data['reimbursement_type']); return in_array(1, $reimbursement_type); } public function checkLoanApply($value, $rule, $data): bool|string { $reimbursement_type = explode(',', $data['reimbursement_type']); if (!in_array(1, $reimbursement_type)) return true; $loan_apply_data = ProjectLoanApply::where('id', $value)->findOrEmpty(); if ($loan_apply_data->isEmpty()) { return '借款单信息不存在'; } return true; } public function checkAnnex($value): bool|string { if (!empty($value) && $value != '') { if (!is_array($value)) { return '附件格式错误'; } } return true; } public function checkBankAccount($value): bool|string { $data = BankAccount::where('id', $value)->findOrEmpty(); if ($data->isEmpty()) { return '付款银行账户信息不存在'; } return true; } public function checkReimbursementDetail($value): bool|string { if (empty($value) || !is_array($value)) { return '报销明细数据格式错误'; } foreach ($value as $v) { if (isset($v['id']) && $v['id'] != '') { $reimbursement_detail = ProjectExpenseReimbursementDetail::where('id', $v['id'])->findOrEmpty(); if ($reimbursement_detail->isEmpty()) { return '报销明细信息不存在'; } } if (empty($v['project_cost_temp_id'])) { return '请选择项目费用模板'; } else { $project_cost_temp = ProjectCostTempSet::where('id', $v['project_cost_temp_id'])->findOrEmpty(); if ($project_cost_temp->isEmpty()) { return '项目费用模板信息不存在'; } } if (empty($v['amount'])) { return '请填写报销明细金额'; } else { if (!is_numeric($v['amount']) || $v['amount'] < 0) { return '报销明细金额必须是大于0数字'; } } } return true; } public function checkInvoiceDetail($value): bool|string { if (empty($value) || !is_array($value)) { return '发票明细数据格式错误'; } foreach ($value as $v) { if (isset($v['id']) && $v['id'] != '') { $invoice_detail = ProjectExpenseReimbursementInvoiceDetail::where('id', $v['id'])->findOrEmpty(); if ($invoice_detail->isEmpty()) { return '发票明细信息不存在'; } } if (empty($v['invoice_type'])) { return '请选择发票类型'; } else { $invoice_type_dict = DictData::where('type_value', 'invoice_type')->column('value'); if (!in_array($v['invoice_type'], $invoice_type_dict)) { return '发票类型数据值无效'; } } if (empty($v['invoice_sn'])) { return '请填写发票号'; } if (empty($v['tax_rate'])) { return '请选择发票税率'; } else { $tax_rate_dict = DictData::where('type_value', 'tax_rate')->column('value'); if (!in_array($v['tax_rate'], $tax_rate_dict)) { return '发票税率数据值无效'; } } if (empty($v['invoice_form'])) { return '请选择发票形式'; } else { $invoice_form_dict = DictData::where('type_value', 'invoice_form')->column('value'); if (!in_array($v['invoice_form'], $invoice_form_dict)) { return '发票形式数据值无效'; } } if (empty($v['invoice_amount'])) { return '请填写发票金额'; } else { if (!is_numeric($v['invoice_amount']) || $v['invoice_amount'] < 0) { return '发票金额必须是大于0的数字'; } } if (isset($v['annex']) && $v['annex'] != '') { if (!is_array($v['annex'])) { return '发票附件格式错误'; } } } return true; } }