1
dd
2025-10-27 11ffae1ecbe3d26863fd51262d7ffb043eb089da
ruoyi-admin/src/main/java/com/ruoyi/im/service/impl/UserPolicyServiceImpl.java
@@ -16,6 +16,7 @@
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;
@@ -53,6 +54,10 @@
    private GroupWelcomeConfigService groupWelcomeConfigService;
    @Autowired
    private FundsLogService fundsLogService;
    @Autowired
    private SystemConfigurationMapper systemConfigurationMapper;
    @Autowired
    private UserPolicyService userPolicyService;
    @Override
@@ -75,18 +80,21 @@
        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)){
@@ -105,7 +113,8 @@
            String payOrder = payService.createOrder(
                    insuranceProduct.getPremium(),
                    orderNo,
                    dto.getPayProductId()
                    dto.getPayProductId(),
                    systemConfiguration.getCallBackUrl()
            );
            Map<String, Object> parse = (Map<String, Object>) JSONUtils.parse(payOrder);
@@ -121,6 +130,16 @@
                    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());
@@ -143,7 +162,6 @@
                    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 {
@@ -153,8 +171,12 @@
                    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("未授权访问支付系统");
@@ -187,6 +209,15 @@
            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());
@@ -233,6 +264,30 @@
            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();
            }
        }
    }