付款 @param paymentRequest 付款表单
(PaymentRequest paymentRequest)
| 1363 | * @param paymentRequest 付款表单 |
| 1364 | */ |
| 1365 | public void payment(PaymentRequest paymentRequest){ |
| 1366 | if(paymentRequest.getId() ==null){ |
| 1367 | throw new BusinessException(Map.of("userId", "用户Id不能为空")); |
| 1368 | } |
| 1369 | User user = userRepository.findUserById(paymentRequest.getId()); |
| 1370 | if(user == null){ |
| 1371 | throw new BusinessException(Map.of("userId", "用户不存在")); |
| 1372 | } |
| 1373 | |
| 1374 | if(!paymentType.contains(paymentRequest.getType())){ |
| 1375 | throw new BusinessException(Map.of("type", "支付类型错误")); |
| 1376 | } |
| 1377 | |
| 1378 | |
| 1379 | String staffName = "";//员工名称 |
| 1380 | Object obj = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); |
| 1381 | if(obj instanceof UserDetails){ |
| 1382 | staffName =((UserDetails)obj).getUsername(); |
| 1383 | } |
| 1384 | Map<String, String> errors = new HashMap<String, String>(); |
| 1385 | if(paymentRequest.getType().equals(1)){//1:支付流水号 |
| 1386 | |
| 1387 | if(paymentRequest.getPaymentRunningNumberAmount() == null){ |
| 1388 | errors.put("paymentRunningNumberAmount", "请填写金额"); |
| 1389 | }else{ |
| 1390 | if(!Verification.hasAtMostTwoDecimalPlaces(paymentRequest.getPaymentRunningNumberAmount())){ |
| 1391 | errors.put("paymentRunningNumberAmount", "最多只能有两位小数"); |
| 1392 | } |
| 1393 | if(paymentRequest.getPaymentRunningNumberAmount().compareTo(new BigDecimal("0")) <=0){ |
| 1394 | errors.put("paymentRunningNumberAmount", "金额必须大于0"); |
| 1395 | } |
| 1396 | if(paymentRequest.getPaymentRunningNumberAmount().compareTo(new BigDecimal("999999999999")) >0){ |
| 1397 | errors.put("paymentRunningNumberAmount", "金额不能超过12位数字"); |
| 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | if(paymentRequest.getPaymentRunningNumber() == null || paymentRequest.getPaymentRunningNumber().trim().isEmpty()){ |
| 1402 | errors.put("paymentRunningNumber", "流水号不能为空"); |
| 1403 | }else{ |
| 1404 | if(paymentRequest.getPaymentRunningNumber().trim().length() >64){ |
| 1405 | errors.put("paymentRunningNumber", "流水号不能超过64位"); |
| 1406 | } |
| 1407 | } |
| 1408 | if (!errors.isEmpty()) { |
| 1409 | throw new BusinessException(errors); |
| 1410 | } |
| 1411 | |
| 1412 | |
| 1413 | PaymentVerificationLog paymentVerificationLog = paymentRepository.findPaymentVerificationLogById(paymentRequest.getPaymentRunningNumber().trim()); |
| 1414 | if(paymentVerificationLog == null) { |
| 1415 | throw new BusinessException(Map.of("paymentRunningNumber", "流水号不存在")); |
| 1416 | } |
| 1417 | if(!paymentVerificationLog.getPaymentModule().equals(5)) {//5.用户充值 |
| 1418 | throw new BusinessException(Map.of("paymentRunningNumber", "流水号不属于充值模块")); |
| 1419 | } |
| 1420 | if(!user.getUserName().equals(paymentVerificationLog.getUserName())) { |
| 1421 | throw new BusinessException(Map.of("paymentRunningNumber", "流水号不属于当前用户")); |
| 1422 | } |
nothing calls this directly
no test coverage detected