| | |
| | | } |
| | | if(userAccount.getBalance().compareTo(insuranceProduct.getPremium()) < 0){ |
| | | String orderNo = generateOrderNo(); |
| | | String payOrder = payService.createOrder(insuranceProduct.getPremium().multiply(new BigDecimal("100")), orderNo,dto.getPayProductId()); |
| | | String payOrder = payService.createOrder( |
| | | insuranceProduct.getPremium(), |
| | | orderNo, |
| | | dto.getPayProductId() |
| | | ); |
| | | |
| | | Map<String, Object> parse = (Map<String, Object>) JSONUtils.parse(payOrder); |
| | | if("0014".equals(parse.get("errCode"))){ |
| | | return Result.error("当前支付不可用,请更换其他支付方式!"); |
| | | Integer code = (Integer) parse.get("code"); |
| | | if (code == null) { |
| | | return Result.error("支付系统返回异常"); |
| | | } |
| | | if("FAIL".equals(parse.get("retCode"))){ |
| | | return Result.error("获取支付通道失败!"); |
| | | } |
| | | String payUrl; |
| | | switch (code) { |
| | | case 200: |
| | | // 成功,获取支付链接 |
| | | payUrl = (String) parse.get("result"); |
| | | |
| | | userAccountService.updateById(userAccount); |
| | | userAccountService.updateById(userAccount); |
| | | |
| | | UserPolicy userPolicy = new UserPolicy(); |
| | | userPolicy.setAccount(userAccount.getAccount()); |
| | | userPolicy.setProductName(insuranceProduct.getProductName()); |
| | | userPolicy.setUserId(userAccount.getId()); |
| | | userPolicy.setProductId(insuranceProduct.getId()); |
| | | userPolicy.setCoverageAmount(insuranceProduct.getCoverageAmount()); |
| | | userPolicy.setPremium(insuranceProduct.getPremium()); |
| | | userPolicy.setTerm(insuranceProduct.getTerm()); |
| | | userPolicy.setName(dto.getName()); |
| | | userPolicy.setGender(dto.getGender()); |
| | | userPolicy.setPayStatus(0); |
| | | userPolicy.setOrderNo(orderNo); |
| | | userPolicy.setBirthDate(LocalDate.parse(dto.getBirthDate())); |
| | | UserPolicy userPolicy = new UserPolicy(); |
| | | userPolicy.setAccount(userAccount.getAccount()); |
| | | userPolicy.setProductName(insuranceProduct.getProductName()); |
| | | userPolicy.setUserId(userAccount.getId()); |
| | | userPolicy.setProductId(insuranceProduct.getId()); |
| | | userPolicy.setCoverageAmount(insuranceProduct.getCoverageAmount()); |
| | | userPolicy.setPremium(insuranceProduct.getPremium()); |
| | | userPolicy.setTerm(insuranceProduct.getTerm()); |
| | | userPolicy.setName(dto.getName()); |
| | | userPolicy.setGender(dto.getGender()); |
| | | userPolicy.setPayStatus(0); |
| | | userPolicy.setOrderNo(orderNo); |
| | | userPolicy.setBirthDate(LocalDate.parse(dto.getBirthDate())); |
| | | |
| | | userPolicy.setOccupation(dto.getOccupation()); |
| | | userPolicy.setIdCard(dto.getIdCard()); |
| | | userPolicy.setPhone(dto.getPhone()); |
| | | userPolicy.setPolicyNumber(generatePolicyNumber()); |
| | | userPolicy.setPolicyStatus(UserPolicy.PolicyStatus.PENDING); |
| | | userPolicy.setCreatedAt(new Date()); |
| | | userPolicy.setUpdatedAt(new Date()); |
| | | userPolicy.setApprovalStatus(0); |
| | | userPolicy.setIsLifelong(insuranceProduct.getTerm() == 0 ? 0 : 1); |
| | | userPolicy.setOccupation(dto.getOccupation()); |
| | | userPolicy.setIdCard(dto.getIdCard()); |
| | | userPolicy.setPhone(dto.getPhone()); |
| | | userPolicy.setPolicyNumber(generatePolicyNumber()); |
| | | userPolicy.setPolicyStatus(UserPolicy.PolicyStatus.PENDING); |
| | | userPolicy.setCreatedAt(new Date()); |
| | | userPolicy.setUpdatedAt(new Date()); |
| | | userPolicy.setApprovalStatus(0); |
| | | userPolicy.setIsLifelong(insuranceProduct.getTerm() == 0 ? 0 : 1); |
| | | |
| | | save(userPolicy); |
| | | // 获取 payUrl |
| | | Object payParamsObj = parse.get("payParams"); |
| | | if (payParamsObj instanceof Map) { |
| | | Map<?, ?> payParamsMap = (Map<?, ?>) payParamsObj; |
| | | String payUrl = (String) payParamsMap.get("payUrl"); |
| | | |
| | | if (payUrl != null && !payUrl.trim().isEmpty()) { |
| | | save(userPolicy); |
| | | return Result.success(payUrl); |
| | | } |
| | | } |
| | | |
| | | return Result.error("支付链接获取失败,请联系客服!"); |
| | | case 401: |
| | | return Result.error("未授权访问支付系统"); |
| | | |
| | | case 403: |
| | | return Result.error("禁止访问支付系统"); |
| | | |
| | | case 404: |
| | | return Result.error("支付接口不存在"); |
| | | |
| | | case 0014: // 注意:0014可能是字符串,需要根据实际情况处理 |
| | | return Result.error("当前支付不可用,请更换其他支付方式!"); |
| | | |
| | | default: |
| | | // 其他错误码 |
| | | String message = (String) parse.get("message"); |
| | | if (message != null && !message.isEmpty()) { |
| | | return Result.error("支付失败: " + message); |
| | | } else { |
| | | return Result.error("获取支付通道失败!"); |
| | | } |
| | | } |
| | | }else{ |
| | | userAccount.setBalance(userAccount.getBalance().subtract(insuranceProduct.getPremium())); |
| | | |