| | |
| | | import com.ruoyi.im.service.UserPolicyService; |
| | | import com.ruoyi.im.util.PayService; |
| | | import com.ruoyi.im.util.ValidatorUtil; |
| | | import com.ruoyi.imenum.PaymentMode; |
| | | import com.ruoyi.system.domain.*; |
| | | import com.ruoyi.system.domain.dto.UserPolicyDto; |
| | | import com.ruoyi.system.mapper.UserPolicyMapper; |
| | |
| | | .eq(UserPolicy::getPolicyStatus, UserPolicy.PolicyStatus.PENDING) |
| | | .and(a-> a.eq(UserPolicy::getApprovalStatus, 0) |
| | | .or() |
| | | .eq(UserPolicy::getApprovalStatus, 1)) |
| | | .eq(UserPolicy::getPayStatus, 1)) |
| | | |
| | | ); |
| | | if(count > 0){ |
| | |
| | | if(ObjectUtil.isEmpty(insuranceProduct)){ |
| | | return Result.error("该产品停止购买或已下架!"); |
| | | } |
| | | if(userAccount.getBalance().compareTo(insuranceProduct.getPremium()) < 0){ |
| | | if(!dto.getPayProductId().equals("0")){ |
| | | String orderNo = generateOrderNo(); |
| | | String payOrder = payService.createOrder( |
| | | insuranceProduct.getPremium(), |
| | |
| | | userPolicy.setCreatedAt(new Date()); |
| | | userPolicy.setUpdatedAt(new Date()); |
| | | userPolicy.setApprovalStatus(0); |
| | | PaymentMode payment = PaymentMode.getByCode(dto.getPayProductId()); |
| | | if (payment != null) { |
| | | userPolicy.setModePayment(payment.getMode()); |
| | | } else { |
| | | // 处理未知支付方式 |
| | | userPolicy.setModePayment(0); |
| | | } |
| | | userPolicy.setIsLifelong(insuranceProduct.getTerm() == 0 ? 0 : 1); |
| | | |
| | | save(userPolicy); |
| | | extracted(userAccount, userPolicy.getId(), orderNo,PaymentRecord.PaymentStatus.PENDING.getCode(),userPolicy.getProductId(),userPolicy.getProductName(),userPolicy.getModePayment()); |
| | | return Result.success(payUrl); |
| | | case 401: |
| | | extracted(userAccount, null, orderNo,PaymentRecord.PaymentStatus.FAILED.getCode(),null,"获取支付通道失败"); |
| | | extracted(userAccount, null, orderNo,PaymentRecord.PaymentStatus.FAILED.getCode(),null,"获取支付通道失败",0); |
| | | return Result.error("未授权访问支付系统"); |
| | | case 403: |
| | | extracted(userAccount, null, orderNo,PaymentRecord.PaymentStatus.FAILED.getCode(),null,"获取支付通道失败"); |
| | | extracted(userAccount, null, orderNo,PaymentRecord.PaymentStatus.FAILED.getCode(),null,"获取支付通道失败",0); |
| | | return Result.error("禁止访问支付系统"); |
| | | case 404: |
| | | extracted(userAccount, null, orderNo,PaymentRecord.PaymentStatus.FAILED.getCode(),null,"获取支付通道失败"); |
| | | extracted(userAccount, null, orderNo,PaymentRecord.PaymentStatus.FAILED.getCode(),null,"获取支付通道失败",0); |
| | | return Result.error("支付接口不存在"); |
| | | case 0014: // 注意:0014可能是字符串,需要根据实际情况处理 |
| | | extracted(userAccount, null, orderNo,PaymentRecord.PaymentStatus.FAILED.getCode(),null,"获取支付通道失败"); |
| | | extracted(userAccount, null, orderNo,PaymentRecord.PaymentStatus.FAILED.getCode(),null,"获取支付通道失败",0); |
| | | return Result.error("当前支付不可用,请更换其他支付方式!"); |
| | | default: |
| | | extracted(userAccount, null, orderNo,PaymentRecord.PaymentStatus.FAILED.getCode(),null,"获取支付通道失败"); |
| | | extracted(userAccount, null, orderNo,PaymentRecord.PaymentStatus.FAILED.getCode(),null,"获取支付通道失败",0); |
| | | // 其他错误码 |
| | | String message = (String) parse.get("message"); |
| | | if (message != null && !message.isEmpty()) { |
| | |
| | | } |
| | | } |
| | | }else{ |
| | | if(userAccount.getBalance().compareTo(insuranceProduct.getPremium()) < 0){ |
| | | return Result.error("余额不足!"); |
| | | } |
| | | userAccount.setBalance(userAccount.getBalance().subtract(insuranceProduct.getPremium())); |
| | | |
| | | userAccountService.updateById(userAccount); |
| | |
| | | userPolicy.setCreatedAt(new Date()); |
| | | userPolicy.setUpdatedAt(new Date()); |
| | | userPolicy.setApprovalStatus(0); |
| | | userPolicy.setModePayment(3); |
| | | userPolicy.setIsLifelong(insuranceProduct.getTerm() == 0 ? 0 : 1); |
| | | |
| | | save(userPolicy); |
| | |
| | | paymentRecord.setName(userKyc.getName()); |
| | | paymentRecord.setInvitationCode(userAccount.getInvitationCode()); |
| | | paymentRecord.setProductName(insuranceProduct.getProductName()); |
| | | paymentRecord.setModePayment(3); |
| | | paymentRecordService.save(paymentRecord); |
| | | return Result.success(); |
| | | } |
| | | } |
| | | |
| | | private void extracted(UserAccount userAccount, Integer userPolicyId, String orderNo,Integer payCode,Integer productId,String productName) { |
| | | |
| | | private void extracted(UserAccount userAccount, Integer userPolicyId, |
| | | String orderNo,Integer payCode,Integer productId,String productName,Integer modePayment) { |
| | | UserKyc userKyc = userKycService.getOne(new LambdaQueryWrapper<UserKyc>() |
| | | .eq(UserKyc::getAccount, userAccount.getAccount()) |
| | | ); |
| | |
| | | paymentRecord.setInvitationCode(userAccount.getInvitationCode()); |
| | | paymentRecord.setProductName(productName); |
| | | paymentRecord.setPaymentStatus(payCode); |
| | | if(userPolicyId != null){ |
| | | paymentRecord.setOrderId(userPolicyId); |
| | | } |
| | | if(userPolicyId != null){ |
| | | paymentRecord.setOrderId(userPolicyId); |
| | | } |
| | | paymentRecord.setProductId(productId); |
| | | paymentRecord.setOrderId(userPolicyId); |
| | | |
| | | paymentRecord.setPayOrdeNo(orderNo); |
| | | paymentRecord.setModePayment(modePayment); |
| | | paymentRecordService.save(paymentRecord); |
| | | } |
| | | |