| | |
| | | import com.ruoyi.imenum.PaymentMode; |
| | | import com.ruoyi.system.domain.*; |
| | | import com.ruoyi.system.domain.dto.UserPolicyDto; |
| | | import com.ruoyi.system.mapper.SystemConfigurationMapper; |
| | | import com.ruoyi.system.mapper.UserPolicyMapper; |
| | | import com.ruoyi.system.service.FundsLogService; |
| | | import com.ruoyi.system.service.GroupWelcomeConfigService; |
| | |
| | | private GroupWelcomeConfigService groupWelcomeConfigService; |
| | | @Autowired |
| | | private FundsLogService fundsLogService; |
| | | @Autowired |
| | | private SystemConfigurationMapper systemConfigurationMapper; |
| | | @Autowired |
| | | private UserPolicyService userPolicyService; |
| | | |
| | | |
| | | @Override |
| | |
| | | if(!isPhoneValid){ |
| | | return Result.error("手机号格式不正确!"); |
| | | } |
| | | |
| | | SystemConfiguration systemConfiguration = systemConfigurationMapper.selectById(1); |
| | | if(ObjectUtil.isEmpty(systemConfiguration)){ |
| | | return Result.error("无可用支付方式!"); |
| | | } |
| | | long count = count(new LambdaQueryWrapper<UserPolicy>() |
| | | .eq(UserPolicy::getUserId, userAccount.getId()) |
| | | .eq(UserPolicy::getProductId,dto.getProductId()) |
| | | .eq(UserPolicy::getPolicyStatus, UserPolicy.PolicyStatus.PENDING) |
| | | .and(a-> a.eq(UserPolicy::getApprovalStatus, 0) |
| | | .and(a-> a.eq(UserPolicy::getApprovalStatus, 1) |
| | | .or() |
| | | .eq(UserPolicy::getPayStatus, 1)) |
| | | .eq(UserPolicy::getPayStatus, 2)) |
| | | |
| | | ); |
| | | if(count > 0){ |
| | | return Result.error("请勿重复提交,如未支付请3-5分钟重新提交申请"); |
| | | return Result.error("你已购此保险,请勿重复申请!"); |
| | | } |
| | | InsuranceProduct insuranceProduct = insuranceProductService.getById(dto.getProductId()); |
| | | if(ObjectUtil.isEmpty(insuranceProduct)){ |
| | |
| | | String payOrder = payService.createOrder( |
| | | insuranceProduct.getPremium(), |
| | | orderNo, |
| | | dto.getPayProductId() |
| | | dto.getPayProductId(), |
| | | systemConfiguration.getCallBackUrl() |
| | | ); |
| | | |
| | | Map<String, Object> parse = (Map<String, Object>) JSONUtils.parse(payOrder); |
| | |
| | | |
| | | userAccountService.updateById(userAccount); |
| | | |
| | | |
| | | UserPolicy one = getOne(new LambdaQueryWrapper<UserPolicy>() |
| | | .eq(UserPolicy::getUserId, userAccount.getId()) |
| | | .eq(UserPolicy::getProductId, dto.getProductId()) |
| | | .eq(UserPolicy::getPolicyStatus, UserPolicy.PolicyStatus.PENDING) |
| | | .eq(UserPolicy::getApprovalStatus, 0) |
| | | .ne(UserPolicy::getPayStatus, 2) |
| | | ); |
| | | PaymentMode payment = PaymentMode.getByCode(dto.getPayProductId()); |
| | | if(ObjectUtil.isEmpty(one)){ |
| | | UserPolicy userPolicy = new UserPolicy(); |
| | | userPolicy.setAccount(userAccount.getAccount()); |
| | | userPolicy.setProductName(insuranceProduct.getProductName()); |
| | |
| | | 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.setIsLifelong(insuranceProduct.getTerm() == 0 ? 0 : 1); |
| | | |
| | | save(userPolicy); |
| | | extracted(userAccount, userPolicy.getId(), orderNo,PaymentRecord.PaymentStatus.PENDING.getCode(),userPolicy.getProductId(),userPolicy.getProductName(),userPolicy.getModePayment()); |
| | | extracted(userAccount, userPolicy.getId(), orderNo,PaymentRecord.PaymentStatus.PENDING.getCode(),userPolicy.getProductId(),userPolicy.getProductName(),payment.getMode()); |
| | | return Result.success(payUrl); |
| | | }else{ |
| | | extracted(userAccount, one.getId(), orderNo,PaymentRecord.PaymentStatus.PENDING.getCode(),one.getProductId(),one.getProductName(),payment.getMode()); |
| | | return Result.success(payUrl); |
| | | } |
| | | case 401: |
| | | extracted(userAccount, null, orderNo,PaymentRecord.PaymentStatus.FAILED.getCode(),null,"获取支付通道失败",0); |
| | | return Result.error("未授权访问支付系统"); |
| | |
| | | |
| | | String orderNo = generateOrderNo(); |
| | | |
| | | |
| | | UserPolicy one = getOne(new LambdaQueryWrapper<UserPolicy>() |
| | | .eq(UserPolicy::getUserId, userAccount.getId()) |
| | | .eq(UserPolicy::getProductId, dto.getProductId()) |
| | | .eq(UserPolicy::getPolicyStatus, UserPolicy.PolicyStatus.PENDING) |
| | | .eq(UserPolicy::getApprovalStatus, 0) |
| | | .ne(UserPolicy::getPayStatus, 2) |
| | | ); |
| | | if(ObjectUtil.isEmpty(one)){ |
| | | UserPolicy userPolicy = new UserPolicy(); |
| | | userPolicy.setAccount(userAccount.getAccount()); |
| | | userPolicy.setProductName(insuranceProduct.getProductName()); |
| | |
| | | fundsLogService.addLog(userAccount.getId(), userAccount.getAccount(), insuranceProduct.getPremium(), OperationType.USER_ORDER); |
| | | // 生成资金日志 |
| | | return Result.success(); |
| | | }else{ |
| | | one.setApprovalStatus(1); |
| | | updateById(one); |
| | | |
| | | UserKyc userKyc = userKycService.getOne(new LambdaQueryWrapper<UserKyc>() |
| | | .eq(UserKyc::getAccount, userAccount.getAccount()) |
| | | ); |
| | | PaymentRecord paymentRecord = new PaymentRecord(); |
| | | paymentRecord.setUserId(userAccount.getId()); |
| | | paymentRecord.setPaymentStatus(PaymentRecord.PaymentStatus.PAID.getCode()); |
| | | paymentRecord.setProductId(one.getProductId()); |
| | | paymentRecord.setOrderId(one.getId()); |
| | | paymentRecord.setPayOrdeNo(orderNo); |
| | | paymentRecord.setAccount(userAccount.getAccount()); |
| | | paymentRecord.setName(userKyc.getName()); |
| | | paymentRecord.setInvitationCode(userAccount.getInvitationCode()); |
| | | paymentRecord.setProductName(insuranceProduct.getProductName()); |
| | | paymentRecord.setModePayment(3); |
| | | paymentRecordService.save(paymentRecord); |
| | | |
| | | fundsLogService.addLog(userAccount.getId(), userAccount.getAccount(), insuranceProduct.getPremium(), OperationType.USER_ORDER); |
| | | // 生成资金日志 |
| | | return Result.success(); |
| | | } |
| | | } |
| | | } |
| | | |