From 6b4ffe8d97263adca6f48baa721e8a34738cb2ae Mon Sep 17 00:00:00 2001 From: zhangli <123879394@qq.com> Date: Wed, 29 Oct 2025 22:20:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E6=A0=B8=E9=94=80=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E9=A9=B3=E5=9B=9E=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/service/GroupBuyCouponService.java | 11 +- .../impl/GroupBuyCouponServiceImpl.java | 150 ++++++++++++++- .../order/service/impl/OrderServiceImpl.java | 173 ++++-------------- 3 files changed, 183 insertions(+), 151 deletions(-) diff --git a/src/main/java/com/sczx/order/service/GroupBuyCouponService.java b/src/main/java/com/sczx/order/service/GroupBuyCouponService.java index 77985d3..432834f 100644 --- a/src/main/java/com/sczx/order/service/GroupBuyCouponService.java +++ b/src/main/java/com/sczx/order/service/GroupBuyCouponService.java @@ -1,7 +1,8 @@ package com.sczx.order.service; -import com.sczx.order.dto.GroupBuyOrderInfoDto; +import com.sczx.order.dto.RentCarThirdPlatformOrderReq; import com.sczx.order.dto.SimpleUserInfoDTO; +import com.sczx.order.dto.VerifyGroupBuyCouponsReq; /** 团购券服务 * @Author: 张黎 @@ -17,10 +18,10 @@ public interface GroupBuyCouponService { SimpleUserInfoDTO getGroupBuyOrderInfoDto(String mobile); /** - * 校验团购券码 - * @param couponCode 团购券码 - * @param couponType 团购券类型 + * 验券获取三方平台订单信息 + * @param userInfoDTO + * @param req * @return */ - boolean checkCouponCode(String couponCode, String couponType); + RentCarThirdPlatformOrderReq getThirdPlatformOrder(SimpleUserInfoDTO userInfoDTO, VerifyGroupBuyCouponsReq req); } diff --git a/src/main/java/com/sczx/order/service/impl/GroupBuyCouponServiceImpl.java b/src/main/java/com/sczx/order/service/impl/GroupBuyCouponServiceImpl.java index b31a860..0999ae6 100644 --- a/src/main/java/com/sczx/order/service/impl/GroupBuyCouponServiceImpl.java +++ b/src/main/java/com/sczx/order/service/impl/GroupBuyCouponServiceImpl.java @@ -1,16 +1,33 @@ package com.sczx.order.service.impl; +import com.douyin.openapi.client.models.CertificatePrepareRequest; +import com.douyin.openapi.client.models.CertificatePrepareResponse; +import com.douyin.openapi.client.models.CertificateVerifyRequest; +import com.douyin.openapi.client.models.CertificateVerifyResponse; +import com.meituan.sdk.MeituanResponse; +import com.meituan.sdk.model.ddzh.tuangou.tuangouReceiptConsume.TuangouReceiptConsumeResponse; +import com.meituan.sdk.model.ddzh.tuangou.tuangouReceiptPrepare.TuangouReceiptPrepareResponse; import com.sczx.order.common.enums.CouponTypeEnum; -import com.sczx.order.dto.GroupBuyOrderInfoDto; +import com.sczx.order.dto.RentCarThirdPlatformOrderReq; import com.sczx.order.dto.SimpleUserInfoDTO; +import com.sczx.order.dto.VerifyGroupBuyCouponsReq; import com.sczx.order.exception.BizException; +import com.sczx.order.service.DouyinService; import com.sczx.order.service.GroupBuyCouponService; import com.sczx.order.service.MeiTuanService; +import com.sczx.order.thirdpart.dto.CarModelPackageDTO; +import com.sczx.order.thirdpart.dto.CompanyStoreDTO; +import com.sczx.order.thirdpart.integration.CarInteg; +import com.sczx.order.thirdpart.integration.StoreInteg; import com.sczx.order.thirdpart.integration.UserInteg; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; + /** * @Author: 张黎 * @Date: 2025/10/27/20:48 @@ -27,6 +44,15 @@ public class GroupBuyCouponServiceImpl implements GroupBuyCouponService { @Autowired private MeiTuanService meiTuanService; + @Autowired + private DouyinService douyinService; + + @Autowired + private CarInteg carInteg; + + @Autowired + private StoreInteg storeInteg; + @Override public SimpleUserInfoDTO getGroupBuyOrderInfoDto(String mobile) { SimpleUserInfoDTO userInfoDTO = userInteg.getUInfoByMobile(mobile); @@ -36,14 +62,128 @@ public class GroupBuyCouponServiceImpl implements GroupBuyCouponService { if(userInfoDTO.getAuthed()==0){ throw new BizException("用户未实名认证"); } - return null; + return userInfoDTO; } @Override - public boolean checkCouponCode(String couponCode, String couponType) { - if(CouponTypeEnum.MT.getCode().equals(couponType)){ + public RentCarThirdPlatformOrderReq getThirdPlatformOrder(SimpleUserInfoDTO userInfoDTO, VerifyGroupBuyCouponsReq req) { + RentCarThirdPlatformOrderReq thirdRentCarOrder = new RentCarThirdPlatformOrderReq(); + Map productIdMap = new HashMap<>(); + if (CouponTypeEnum.MT.getCode().equalsIgnoreCase(req.getCouponType())){ + //美团验券 + MeituanResponse prepareResponse =meiTuanService.prepare( req); + String phone = prepareResponse.getData().getMobile(); + if (phone != null && !phone.isEmpty()){ + if (comparePhoneNumbers(phone, req.getMobile())){ + throw new BizException("所提供的手机号码与团购手机号不一致"); + } + } + //使用输入的手机号进行后续操作 + //核销团购券 + MeituanResponse consumeResponse =meiTuanService.consume( req); + consumeResponse.getData().getResult().forEach(result -> { + productIdMap.put("mtOrderId",String.valueOf(result.getDealId())); + productIdMap.put("mtProductId", String.valueOf(result.getDealGroupId())); + }); + + + //生成第三方订单 + CarModelPackageDTO carModelPackageDTO = carInteg.getCarModelPackageByThireId(productIdMap.get("mtProductId"),null); + if (carModelPackageDTO == null){ + throw new BizException("无此对应团购套餐"); + } + + thirdRentCarOrder.setCarModelId(carModelPackageDTO.getCarModelId()); + thirdRentCarOrder.setRentCarRuleId(carModelPackageDTO.getCarRuleId()); + thirdRentCarOrder.setCustomerId(userInfoDTO.getUserId().longValue()); + thirdRentCarOrder.setStoreId(req.getStoreId()); + thirdRentCarOrder.setOrderSource(CouponTypeEnum.MT.getCode()); + thirdRentCarOrder.setCustomerName(userInfoDTO.getUserName()); + thirdRentCarOrder.setCustomerPhone(userInfoDTO.getPhoneNumber()); + thirdRentCarOrder.setThirdOrderNo(productIdMap.get("mtOrderId")); + thirdRentCarOrder.setCouponCode(req.getCouponCode()); + thirdRentCarOrder.setRentBatteyRuleId(carModelPackageDTO.getBatteyRuleId()); + + } else if (CouponTypeEnum.DY.getCode().equalsIgnoreCase(req.getCouponType())){ + + //根据门店ID获取抖音门店ID + CompanyStoreDTO store = storeInteg.getStoreById(req.getStoreId().intValue()); + String poiId = store.getDyStoreId(); + + //调用抖音验券接口 + CertificatePrepareRequest prepareRequest = new CertificatePrepareRequest(); + + prepareRequest.setPoiId(poiId); + prepareRequest.setEncryptedData(req.getCouponCode()); + + CertificatePrepareResponse response =douyinService.prepare(prepareRequest); + //获取核销所需信息 + String verifyToken = response.getData().getVerifyToken(); + AtomicReference phone = new AtomicReference<>(""); + response.getData().getCertificates().forEach(certificate -> { + productIdMap.put("dyOrderId",String.valueOf(certificate.getCertificateId())); + productIdMap.put("dyProductId", String.valueOf(certificate.getSku().getSkuId())); + certificate.getReserveInfo().getOrderReserveUserInfoList().forEach(orderReserveUserInfo -> { + phone.set(orderReserveUserInfo.getPhone()); + }); + }); + + String finalPhone = phone.get(); + + if (finalPhone != null && !finalPhone.isEmpty()) { + if (comparePhoneNumbers(finalPhone, req.getMobile())){ + throw new BizException("所提供的手机号码与团购手机号不一致"); + } + } + + //核销抖音团购券 + CertificateVerifyRequest verifyRequest = new CertificateVerifyRequest(); + verifyRequest.setVerifyToken(verifyToken); + verifyRequest.setPoiId(poiId); + + CertificateVerifyResponse verifyResponse =douyinService.verify(verifyRequest); + + verifyResponse.getData().getVerifyResults().forEach(verifyResult -> { + //撤销验券需要下面两个值 + productIdMap.put("dyCertificateId",verifyResult.getCertificateId()); + productIdMap.put("dyVerifyId",verifyResult.getVerifyId()); + }); + + //生成第三方订单 + CarModelPackageDTO carModelPackageDTO = carInteg.getCarModelPackageByThireId(null,productIdMap.get("dyProductId")); + if (carModelPackageDTO == null){ + throw new BizException("无此对应团购套餐"); + } + thirdRentCarOrder.setCarModelId(carModelPackageDTO.getCarModelId()); + thirdRentCarOrder.setRentCarRuleId(carModelPackageDTO.getCarRuleId()); + thirdRentCarOrder.setCustomerId(userInfoDTO.getUserId().longValue()); + thirdRentCarOrder.setStoreId(req.getStoreId()); + thirdRentCarOrder.setOrderSource(CouponTypeEnum.DY.getCode()); + thirdRentCarOrder.setCustomerName(userInfoDTO.getUserName()); + thirdRentCarOrder.setCustomerPhone(userInfoDTO.getPhoneNumber()); + thirdRentCarOrder.setThirdOrderNo(productIdMap.get("dyCertificateId")); + thirdRentCarOrder.setCouponCode(productIdMap.get("dyVerifyId")); + thirdRentCarOrder.setRentBatteyRuleId(carModelPackageDTO.getBatteyRuleId()); } - return false; + return thirdRentCarOrder; + } + + private boolean comparePhoneNumbers(String maskedPhone, String actualPhone) { + // 检查输入参数 + if (maskedPhone == null || actualPhone == null) { + return true; + } + + // 比较前3位 + String prefix1 = maskedPhone.substring(0, 3); + String prefix2 = actualPhone.substring(0, 3); + + // 比较后4位 + String suffix1 = maskedPhone.substring(maskedPhone.length() - 4); + String suffix2 = actualPhone.substring(actualPhone.length() - 4); + + // 返回比对结果 + return !prefix1.equals(prefix2) || !suffix1.equals(suffix2); } } diff --git a/src/main/java/com/sczx/order/service/impl/OrderServiceImpl.java b/src/main/java/com/sczx/order/service/impl/OrderServiceImpl.java index f1fbb87..c6dc42f 100644 --- a/src/main/java/com/sczx/order/service/impl/OrderServiceImpl.java +++ b/src/main/java/com/sczx/order/service/impl/OrderServiceImpl.java @@ -3,13 +3,6 @@ package com.sczx.order.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; -import com.douyin.openapi.client.models.CertificatePrepareRequest; -import com.douyin.openapi.client.models.CertificatePrepareResponse; -import com.douyin.openapi.client.models.CertificateVerifyRequest; -import com.douyin.openapi.client.models.CertificateVerifyResponse; -import com.meituan.sdk.MeituanResponse; -import com.meituan.sdk.model.ddzh.tuangou.tuangouReceiptConsume.TuangouReceiptConsumeResponse; -import com.meituan.sdk.model.ddzh.tuangou.tuangouReceiptPrepare.TuangouReceiptPrepareResponse; import com.sczx.order.common.constant.RedisKeyConstants; import com.sczx.order.common.enums.*; import com.sczx.order.convert.OrderCarImgConvert; @@ -22,8 +15,13 @@ import com.sczx.order.po.*; import com.sczx.order.repository.*; import com.sczx.order.service.*; import com.sczx.order.thirdpart.dto.*; -import com.sczx.order.thirdpart.dto.req.*; -import com.sczx.order.thirdpart.integration.*; +import com.sczx.order.thirdpart.dto.req.AlipayCloseRequest; +import com.sczx.order.thirdpart.dto.req.AlipayQueryFreezeRequest; +import com.sczx.order.thirdpart.dto.req.CarQueryConditionReq; +import com.sczx.order.thirdpart.integration.CarInteg; +import com.sczx.order.thirdpart.integration.PayInteg; +import com.sczx.order.thirdpart.integration.StoreInteg; +import com.sczx.order.thirdpart.integration.SyncInteg; import com.sczx.order.utils.JwtUtil; import com.sczx.order.utils.OrderUtil; import com.sczx.order.utils.RedisUtil; @@ -38,7 +36,6 @@ import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.*; -import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @Slf4j @@ -108,116 +105,10 @@ public class OrderServiceImpl implements OrderService { public RentCarOrderResultDTO verifyGroupBuyCoupons(VerifyGroupBuyCouponsReq req){ //校验用户是否存在,是否实名认证 SimpleUserInfoDTO userInfoDTO = groupBuyCouponService.getGroupBuyOrderInfoDto(req.getMobile()); - - RentCarThirdPlatformOrderReq thirdRentCarOrder = new RentCarThirdPlatformOrderReq(); - Map productIdMap = new HashMap<>(); - - if (req.getCouponType() == CouponTypeEnum.MT.getCode()){ - //TODO 调用美团验券接口 - //美团验券 - MeituanResponse prepareResponse =meiTuanService.prepare( req); - String phone = prepareResponse.getData().getMobile(); - if (phone != null && !phone.isEmpty()){ - if (!comparePhoneNumbers(phone, req.getMobile())){ - throw new BizException("所提供的手机号码与团购手机号不一致"); - } - } - //使用输入的手机号进行后续操作 - //核销团购券 - MeituanResponse consumeResponse =meiTuanService.consume( req); - consumeResponse.getData().getResult().forEach(result -> { - productIdMap.put("mtOrderId",String.valueOf(result.getDealId())); - productIdMap.put("mtProductId", String.valueOf(result.getDealGroupId())); - }); - - - //生成第三方订单 - CarModelPackageDTO carModelPackageDTO = carInteg.getCarModelPackageByThireId(productIdMap.get("mtProductId"),null); - if (carModelPackageDTO == null){ - throw new BizException("无此对应团购套餐"); - } - - thirdRentCarOrder.setCarModelId(carModelPackageDTO.getCarModelId()); - thirdRentCarOrder.setRentCarRuleId(carModelPackageDTO.getCarRuleId()); - thirdRentCarOrder.setCustomerId(userInfoDTO.getUserId().longValue()); - thirdRentCarOrder.setStoreId(req.getStoreId()); - thirdRentCarOrder.setOrderSource(CouponTypeEnum.MT.getCode()); - thirdRentCarOrder.setCustomerName(userInfoDTO.getUserName()); - thirdRentCarOrder.setCustomerPhone(userInfoDTO.getPhoneNumber()); - thirdRentCarOrder.setThirdOrderNo(productIdMap.get("mtOrderId")); - thirdRentCarOrder.setCouponCode(req.getCouponCode()); - thirdRentCarOrder.setRentBatteyRuleId(carModelPackageDTO.getBatteyRuleId()); - - RentCarOrderResultDTO rentCarOrderResultDTO = thirdPlatformRentCarOrder(thirdRentCarOrder); - return rentCarOrderResultDTO; - - }else if (req.getCouponType() == CouponTypeEnum.DY.getCode()){ - - //根据门店ID获取抖音门店ID - CompanyStoreDTO store = storeInteg.getStoreById(req.getStoreId().intValue()); - String poiId = store.getDyStoreId(); - - //调用抖音验券接口 - CertificatePrepareRequest prepareRequest = new CertificatePrepareRequest(); - - prepareRequest.setPoiId(poiId); - prepareRequest.setEncryptedData(req.getCouponCode()); - - CertificatePrepareResponse response =douyinService.prepare(prepareRequest); - //获取核销所需信息 - String verifyToken = response.getData().getVerifyToken(); - AtomicReference phone = new AtomicReference<>(""); - response.getData().getCertificates().forEach(certificate -> { - productIdMap.put("dyOrderId",String.valueOf(certificate.getCertificateId())); - productIdMap.put("dyProductId", String.valueOf(certificate.getSku().getSkuId())); - certificate.getReserveInfo().getOrderReserveUserInfoList().forEach(orderReserveUserInfo -> { - phone.set(orderReserveUserInfo.getPhone()); - }); - }); - - String finalPhone = phone.get(); - - if (finalPhone != null && !finalPhone.isEmpty()) { - if (!comparePhoneNumbers(finalPhone, req.getMobile())){ - throw new BizException("所提供的手机号码与团购手机号不一致"); - } - } - - //核销抖音团购券 - CertificateVerifyRequest verifyRequest = new CertificateVerifyRequest(); - verifyRequest.setVerifyToken(verifyToken); - verifyRequest.setPoiId(poiId); - - CertificateVerifyResponse verifyResponse =douyinService.verify(verifyRequest); - - verifyResponse.getData().getVerifyResults().forEach(verifyResult -> { - //撤销验券需要下面两个值 - productIdMap.put("dyCertificateId",verifyResult.getCertificateId()); - productIdMap.put("dyVerifyId",verifyResult.getVerifyId()); - }); - - //TODO 生成订单 - //生成第三方订单 - CarModelPackageDTO carModelPackageDTO = carInteg.getCarModelPackageByThireId(null,productIdMap.get("dyProductId")); - if (carModelPackageDTO == null){ - throw new BizException("无此对应团购套餐"); - } - thirdRentCarOrder.setCarModelId(carModelPackageDTO.getCarModelId()); - thirdRentCarOrder.setRentCarRuleId(carModelPackageDTO.getCarRuleId()); - thirdRentCarOrder.setCustomerId(userInfoDTO.getUserId().longValue()); - thirdRentCarOrder.setStoreId(req.getStoreId()); - thirdRentCarOrder.setOrderSource(CouponTypeEnum.DY.getCode()); - thirdRentCarOrder.setCustomerName(userInfoDTO.getUserName()); - thirdRentCarOrder.setCustomerPhone(userInfoDTO.getPhoneNumber()); - thirdRentCarOrder.setThirdOrderNo(productIdMap.get("dyCertificateId")); - thirdRentCarOrder.setCouponCode(productIdMap.get("dyVerifyId")); - thirdRentCarOrder.setRentBatteyRuleId(carModelPackageDTO.getBatteyRuleId()); - - RentCarOrderResultDTO rentCarOrderResultDTO = thirdPlatformRentCarOrder(thirdRentCarOrder); - - return rentCarOrderResultDTO; - } - throw new BizException("券码类型错误"); + //获取三方平台订单信息 + RentCarThirdPlatformOrderReq thirdRentCarOrder = groupBuyCouponService.getThirdPlatformOrder(userInfoDTO, req); + //生成订单 + return thirdPlatformRentCarOrder(thirdRentCarOrder); } public boolean comparePhoneNumbers(String maskedPhone, String actualPhone) { @@ -1384,12 +1275,6 @@ public class OrderServiceImpl implements OrderService { .eq(OrderSubPO::getPayStatus, PayStatusEnum.SUCCESS).last(" limit 1"); OrderSubPO orderSubPO = orderSubRepo.getOne(orderSubWrapper); - if(orderSubPO.getPaymentMethod().equals(PaymentTypeEnum.MT.getCode())){ - meiTuanService.reverseconsume(orderMainPO.getStoreId().intValue(), orderSubPO.getPaymentId(), orderSubPO.getTransactionId()); - }else if (orderSubPO.getPaymentMethod().equals(PaymentTypeEnum.DY.getCode())){ - douyinService.cancel(orderSubPO.getTransactionId(), orderSubPO.getPaymentId()); - } - //异步退款订单 ThreadPoolUtils.getThreadPool().execute(() -> { //变更订单状态,记录结束订单时间,记录订单备注 @@ -1400,21 +1285,27 @@ public class OrderServiceImpl implements OrderService { updateWrapper.eq(OrderMainPO::getOrderNo, rejectOrderReq.getOrderNo()); orderMainRepo.update(updateWrapper); if (Objects.nonNull(orderSubPO)) { - //退款调用成功则添加退款子订单 - String outRefundNo = payService.refundOrder(orderSubPO.getPaymentMethod(), orderMainPO.getOperatorId(), orderSubPO.getPaymentId(), orderMainPO.getOrderAmount(), orderMainPO.getOrderAmount()); - if (StringUtils.isNotBlank(outRefundNo)) { - OrderSubPO fdSubOrder = new OrderSubPO(); - fdSubOrder.setOrderId(orderMainPO.getOrderId()); - fdSubOrder.setSuborderNo(OrderUtil.generateSubOrderNo(OrderUtil.FD_PREFIX)); - fdSubOrder.setSuborderType(SubOrderTypeEnum.FD_REJECT.getCode()); - fdSubOrder.setAmount(orderMainPO.getOrderAmount()); - fdSubOrder.setPaymentMethod(orderSubPO.getPaymentMethod()); - fdSubOrder.setPayStatus(PayStatusEnum.REFUNDING.getCode()); - fdSubOrder.setPaymentId(orderSubPO.getPaymentId()); - fdSubOrder.setRefundId(outRefundNo); - fdSubOrder.setRemark(rejectOrderReq.getRejectReason()); - fdSubOrder.setCreatedAt(LocalDateTime.now()); - orderSubRepo.save(fdSubOrder); + if(orderSubPO.getPaymentMethod().equals(PaymentTypeEnum.MT.getCode())){ + meiTuanService.reverseconsume(orderMainPO.getStoreId().intValue(), orderSubPO.getPaymentId(), orderSubPO.getTransactionId()); + }else if (orderSubPO.getPaymentMethod().equals(PaymentTypeEnum.DY.getCode())){ + douyinService.cancel(orderSubPO.getTransactionId(), orderSubPO.getPaymentId()); + } else { + //退款调用成功则添加退款子订单 + String outRefundNo = payService.refundOrder(orderSubPO.getPaymentMethod(), orderMainPO.getOperatorId(), orderSubPO.getPaymentId(), orderMainPO.getOrderAmount(), orderMainPO.getOrderAmount()); + if (StringUtils.isNotBlank(outRefundNo)) { + OrderSubPO fdSubOrder = new OrderSubPO(); + fdSubOrder.setOrderId(orderMainPO.getOrderId()); + fdSubOrder.setSuborderNo(OrderUtil.generateSubOrderNo(OrderUtil.FD_PREFIX)); + fdSubOrder.setSuborderType(SubOrderTypeEnum.FD_REJECT.getCode()); + fdSubOrder.setAmount(orderMainPO.getOrderAmount()); + fdSubOrder.setPaymentMethod(orderSubPO.getPaymentMethod()); + fdSubOrder.setPayStatus(PayStatusEnum.REFUNDING.getCode()); + fdSubOrder.setPaymentId(orderSubPO.getPaymentId()); + fdSubOrder.setRefundId(outRefundNo); + fdSubOrder.setRemark(rejectOrderReq.getRejectReason()); + fdSubOrder.setCreatedAt(LocalDateTime.now()); + orderSubRepo.save(fdSubOrder); + } } }