| | |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.im.comm.Result; |
| | | import com.ruoyi.im.service.InsuranceProductService; |
| | | import com.ruoyi.im.service.UserKycService; |
| | | import com.ruoyi.im.service.UserPolicyService; |
| | | import com.ruoyi.im.util.PayService; |
| | | import com.ruoyi.im.util.ValidatorUtil; |
| | | import com.ruoyi.system.domain.InsuranceProduct; |
| | | import com.ruoyi.system.domain.UserAccount; |
| | | import com.ruoyi.system.domain.UserPolicy; |
| | | import com.ruoyi.system.domain.*; |
| | | import com.ruoyi.system.domain.dto.UserPolicyDto; |
| | | import com.ruoyi.system.mapper.UserPolicyMapper; |
| | | import com.ruoyi.system.service.PaymentRecordService; |
| | | import com.ruoyi.system.service.UserAccountService; |
| | | import org.json.JSONObject; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | UserAccountService userAccountService; |
| | | @Autowired |
| | | private PayService payService; |
| | | @Autowired |
| | | private PaymentRecordService paymentRecordService; |
| | | @Autowired |
| | | private UserKycService userKycService; |
| | | |
| | | |
| | | @Override |
| | |
| | | |
| | | ); |
| | | if(count > 0){ |
| | | return Result.error("你已申购此保险,请勿重复申购"); |
| | | return Result.error("请勿重复提交,如未支付请3-5分钟重新提交申请"); |
| | | } |
| | | InsuranceProduct insuranceProduct = insuranceProductService.getById(dto.getProductId()); |
| | | if(ObjectUtil.isEmpty(insuranceProduct)){ |
| | |
| | | userPolicy.setTerm(insuranceProduct.getTerm()); |
| | | userPolicy.setName(dto.getName()); |
| | | userPolicy.setGender(dto.getGender()); |
| | | userPolicy.setPayStatus(0); |
| | | userPolicy.setPayStatus(1); |
| | | userPolicy.setOrderNo(orderNo); |
| | | userPolicy.setBirthDate(LocalDate.parse(dto.getBirthDate())); |
| | | |
| | | userPolicy.setNumberDays(insuranceProduct.getNumberDays()); |
| | | userPolicy.setOccupation(dto.getOccupation()); |
| | | userPolicy.setIdCard(dto.getIdCard()); |
| | | userPolicy.setPhone(dto.getPhone()); |
| | |
| | | userPolicy.setIsLifelong(insuranceProduct.getTerm() == 0 ? 0 : 1); |
| | | |
| | | save(userPolicy); |
| | | extracted(userAccount, userPolicy.getId(), orderNo,PaymentRecord.PaymentStatus.PENDING.getCode(),userPolicy.getProductId(),userPolicy.getProductName()); |
| | | return Result.success(payUrl); |
| | | |
| | | case 401: |
| | | extracted(userAccount, null, orderNo,PaymentRecord.PaymentStatus.FAILED.getCode(),null,"获取支付通道失败"); |
| | | return Result.error("未授权访问支付系统"); |
| | | |
| | | case 403: |
| | | extracted(userAccount, null, orderNo,PaymentRecord.PaymentStatus.FAILED.getCode(),null,"获取支付通道失败"); |
| | | return Result.error("禁止访问支付系统"); |
| | | |
| | | case 404: |
| | | extracted(userAccount, null, orderNo,PaymentRecord.PaymentStatus.FAILED.getCode(),null,"获取支付通道失败"); |
| | | return Result.error("支付接口不存在"); |
| | | |
| | | case 0014: // 注意:0014可能是字符串,需要根据实际情况处理 |
| | | extracted(userAccount, null, orderNo,PaymentRecord.PaymentStatus.FAILED.getCode(),null,"获取支付通道失败"); |
| | | return Result.error("当前支付不可用,请更换其他支付方式!"); |
| | | |
| | | default: |
| | | extracted(userAccount, null, orderNo,PaymentRecord.PaymentStatus.FAILED.getCode(),null,"获取支付通道失败"); |
| | | // 其他错误码 |
| | | String message = (String) parse.get("message"); |
| | | if (message != null && !message.isEmpty()) { |
| | |
| | | userPolicy.setPayStatus(2); |
| | | userPolicy.setOrderNo(orderNo); |
| | | userPolicy.setBirthDate(LocalDate.parse(dto.getBirthDate())); |
| | | |
| | | userPolicy.setNumberDays(insuranceProduct.getNumberDays()); |
| | | userPolicy.setOccupation(dto.getOccupation()); |
| | | userPolicy.setIdCard(dto.getIdCard()); |
| | | userPolicy.setPhone(dto.getPhone()); |
| | |
| | | userPolicy.setIsLifelong(insuranceProduct.getTerm() == 0 ? 0 : 1); |
| | | |
| | | save(userPolicy); |
| | | |
| | | 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(userPolicy.getProductId()); |
| | | paymentRecord.setOrderId(userPolicy.getId()); |
| | | paymentRecord.setPayOrdeNo(orderNo); |
| | | paymentRecord.setAccount(userAccount.getAccount()); |
| | | paymentRecord.setName(userKyc.getName()); |
| | | paymentRecord.setInvitationCode(userAccount.getInvitationCode()); |
| | | paymentRecord.setProductName(insuranceProduct.getProductName()); |
| | | paymentRecordService.save(paymentRecord); |
| | | return Result.success(); |
| | | } |
| | | } |
| | | |
| | | private void extracted(UserAccount userAccount, Integer userPolicyId, String orderNo,Integer payCode,Integer productId,String productName) { |
| | | UserKyc userKyc = userKycService.getOne(new LambdaQueryWrapper<UserKyc>() |
| | | .eq(UserKyc::getAccount, userAccount.getAccount()) |
| | | ); |
| | | PaymentRecord paymentRecord = new PaymentRecord(); |
| | | paymentRecord.setUserId(userAccount.getId()); |
| | | paymentRecord.setAccount(userAccount.getAccount()); |
| | | paymentRecord.setName(userKyc.getName()); |
| | | paymentRecord.setInvitationCode(userAccount.getInvitationCode()); |
| | | paymentRecord.setProductName(productName); |
| | | paymentRecord.setPaymentStatus(payCode); |
| | | paymentRecord.setProductId(productId); |
| | | paymentRecord.setOrderId(userPolicyId); |
| | | paymentRecord.setPayOrdeNo(orderNo); |
| | | paymentRecordService.save(paymentRecord); |
| | | } |
| | | |
| | | private final Random random = new Random(); |
| | | /** |
| | | * 生成随机订单号 (格式: 时间戳 + 6位随机数) |