'require|checkData', 'budget_doc_id' => 'require|checkBudgetDoc', 'create_user' => 'require', 'create_time' => 'require|dateFormat:Y-m-d H:i:s', 'detail' => 'checkDetail' ]; /** * 参数描述 * @var string[] */ protected $field = [ 'id' => 'id', 'budget_doc_id' => '预算书id', 'create_user' => '结算人', 'create_time' => '结算日期', ]; /** * @notes 添加场景 * @return FinancialDepartmentIncomeSettlementValidate * @author likeadmin * @date 2024/03/27 09:46 */ public function sceneAdd() { return $this->only(['budget_doc_id', 'desc', 'create_user', 'create_time', 'detail']); } /** * @notes 编辑场景 * @return FinancialDepartmentIncomeSettlementValidate * @author likeadmin * @date 2024/03/27 09:46 */ public function sceneEdit() { return $this->only(['id', 'budget_doc_id', 'desc', 'create_user', 'create_time', 'detail']); } /** * @notes 删除场景 * @return FinancialDepartmentIncomeSettlementValidate * @author likeadmin * @date 2024/03/27 09:46 */ public function sceneDelete() { return $this->only(['id'])->remove('id', 'checkData'); } /** * @notes 详情场景 * @return FinancialDepartmentIncomeSettlementValidate * @author likeadmin * @date 2024/03/27 09:46 */ public function sceneDetail() { return $this->only(['id']); } public function checkData($value): bool|string { $data = FinancialDepartmentIncomeSettlement::where('id', $value)->findOrEmpty(); return $data->isEmpty() ? '数据不存在' : true; } public function checkBudgetDoc($value): bool|string { $data = FinancialBudgetDoc::where('id', $value)->findOrEmpty(); return $data->isEmpty() ? '项目预算书信息不存在' : true; } public function checkDetail($value): bool|string { if (empty($value) || $value == '') return true; if (!is_array($value)) return '结算明细数据格式错误'; foreach ($value as $k => $v) { if (isset($v['id']) && !empty($v['id'])) { $data = FinancialDepartmentIncomeSettlementDetail::where('id', $v['id'])->findOrEmpty(); if ($data->isEmpty()) { return '第' . ($k + 1) . '行结算明细信息不存在'; } } if (empty($v['dept_id'])) { return '第' . ($k + 1) . '行部门为空'; } else { $dept = Dept::where('id', $v['dept_id'])->findOrEmpty(); if ($dept->isEmpty()) return '第' . ($k + 1) . '行部门信息不存在'; } if (empty($v['type'])) { return '第' . ($k + 1) . '行预算分成方式为空'; } else { $dict = DictData::where('type_value', 'budget_share_method')->column('value'); if (!in_array($v['type'], $dict)) return '第' . ($k + 1) . '行预算分成方式数据值无效'; } if (empty($v['amount'])) { return '第' . ($k + 1) . '行预算分成金额为空'; } else { if (!is_numeric($v['amount']) || $v['amount'] < 0) return '第' . ($k + 1) . '行预算分成金额必须是大于零的数字'; } if (empty($v['settlement_amount'])) { return '第' . ($k + 1) . '行结算金额为空'; } else { if (!is_numeric($v['settlement_amount']) || $v['settlement_amount'] < 0) return '第' . ($k + 1) . '行结算金额必须是大于零的数字'; } } return true; } }