From aefe81a52fcbda2175b40575982d18e648e7013c Mon Sep 17 00:00:00 2001
From: huliguo <2023611923@qq.com>
Date: 星期二, 08 七月 2025 11:36:22 +0800
Subject: [PATCH] bug修改

---
 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java |  158 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 137 insertions(+), 21 deletions(-)

diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java
index fcd22cb..bc08919 100644
--- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java
+++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java
@@ -184,7 +184,7 @@
         if(shop!=null&&shop.getShopStatus()!=1){
             throw new ServiceException(AppErrorConstant.SHOP_CLOSED);
         }
-        Shop belongShop = remoteShopService.getShop(shop.getBelongShopId()).getData();
+//        Shop belongShop = remoteShopService.getShop(shop.getBelongShopId()).getData();
         // 初始化订单对象
         AppSureOrderVo appSureOrderVo = new AppSureOrderVo();
         // 初始化订单商品列表
@@ -268,15 +268,20 @@
             appShopGoodsGetDto.setGoodsId(goods.getGoodsId());
             appShopGoodsGetDto.setShopId(appSureOrderDto.getShopId());
             ShopGoods shopGoods = remoteGoodsService.getShopGoods(appShopGoodsGetDto).getData();
+            //商户是否定制价格
             if (shopGoods != null) {
                 goodsPrice = shopGoods.getSalesPrice();
-            } else {
+            }
+            //是否绑定经销商
+            if(shop.getBelongShopId()!=null &&shop.getShopType()==2){
                 //经销商定制价格
-                appShopGoodsGetDto.setGoodsId(goods.getGoodsId());
-                appShopGoodsGetDto.setShopId(belongShop.getShopId());
-                shopGoods = remoteGoodsService.getShopGoods(appShopGoodsGetDto).getData();
+                AppShopGoodsGetDto shopGoodsGetDto=new AppShopGoodsGetDto();
+                shopGoodsGetDto.setGoodsId(goods.getGoodsId());
+                shopGoodsGetDto.setShopId(shop.getBelongShopId());
+                Shop belongShop = remoteShopService.getShop(shop.getBelongShopId()).getData();
+                shopGoods = remoteGoodsService.getShopGoods(shopGoodsGetDto).getData();
                 if (1 == belongShop.getModifyPricePermission() && null != shopGoods) {
-                    goodsPrice = shopGoods.getSalesPrice();
+                    goodsPrice=shopGoods.getSalesPrice();
                 }
             }
             appSureOrderGoodsVo.setGoodsPrice(goodsPrice);
@@ -461,7 +466,9 @@
         ShopGoods shopGoods = remoteGoodsService.getShopGoods(appShopGoodsGetDto).getData();
         if (shopGoods != null) {
             goodsPrice = shopGoods.getSalesPrice();
-        } else {
+        }
+        //是否绑定经销商
+        if(shop.getBelongShopId()!=null &&shop.getShopType()==2){
             //经销商定制价格
             Shop belongShop = remoteShopService.getShop(shop.getBelongShopId()).getData();
             appShopGoodsGetDto = new AppShopGoodsGetDto();
@@ -503,8 +510,8 @@
      * @return
      */
     @Override
-    @Transactional
-    @GlobalTransactional(rollbackFor = Exception.class)
+    @Transactional   // todo  放开分布式事务注解
+//    @GlobalTransactional(rollbackFor = Exception.class)
     public AppPlaceOrderVo placeOrder(AppPlaceOrderDto appPlaceOrderDto) {
         // 获取用户ID
         Long userId = appPlaceOrderDto.getUserId();
@@ -577,6 +584,10 @@
         //使用优惠券
         StringJoiner memberCouponSJ = new StringJoiner(",");
         List<String> goodsNameList = new ArrayList<>();
+        Shop shop = remoteShopService.getShop(appPlaceOrderDto.getShopId()).getData();
+        if(shop!=null&&shop.getShopStatus()!=1){
+            throw new ServiceException(AppErrorConstant.SHOP_CLOSED);
+        }
         // 遍历购买的商品列表
         for (AppBuyGoodsDto appBuyGoodsDto : appBuyGoodsDtoList) {
             appSureOrderGoodsVo = new AppSureOrderGoodsVo();
@@ -610,9 +621,10 @@
             if (shopGoods != null) {
                 goodsPrice = shopGoods.getSalesPrice();
                 serviceNum = shopGoods.getServiceNum();
-            } else {
+            }
+            //是否绑定经销商
+            if(shop.getBelongShopId()!=null &&shop.getShopType()==2){
                 //经销商定制价格
-                Shop shop = remoteShopService.getShop(appPlaceOrderDto.getShopId()).getData();
                 Shop belongShop = remoteShopService.getShop(shop.getBelongShopId()).getData();
                 appShopGoodsGetDto = new AppShopGoodsGetDto();
                 appShopGoodsGetDto.setGoodsId(goods.getGoodsId());
@@ -1027,7 +1039,7 @@
      */
     @Override
     @Transactional
-    @GlobalTransactional(rollbackFor = Exception.class)
+//    @GlobalTransactional(rollbackFor = Exception.class) todo 放开分布式事务注解
     public AppPlaceOrderVo placeActivityOrder(AppPlaceActivityDto appPlaceActivityDto) {
         Long userId = appPlaceActivityDto.getUserId();
         Member member = remoteMemberService.getMember(userId).getData();
@@ -1875,7 +1887,7 @@
      */
     @Override
     @Transactional
-    @GlobalTransactional(rollbackFor = Exception.class)
+//    @GlobalTransactional(rollbackFor = Exception.class) todo 放开分布式事务注解
     public MerVerifyOrderVo sureVerifyOrder(MerVerifyOrderDto merVerifyOrderDto) {
         String orderId = merVerifyOrderDto.getOrderId();
         BigDecimal relReceiveMoney = merVerifyOrderDto.getRelReceiveMoney();
@@ -2117,7 +2129,7 @@
      */
     @Override
     @Transactional
-    @GlobalTransactional(rollbackFor = Exception.class)
+//    @GlobalTransactional(rollbackFor = Exception.class) todo 放开分布式事务注解
     public MerVerifyOrderVo sureVerifyOrderDouYin(MerVerifyOrderDto merVerifyOrderDto) {
         String phone = merVerifyOrderDto.getPhone();
         String orderId = merVerifyOrderDto.getOrderId();
@@ -2538,7 +2550,7 @@
      */
     @Override
     @Transactional
-    @GlobalTransactional(rollbackFor = Exception.class)
+//    @GlobalTransactional(rollbackFor = Exception.class) todo 放开分布式事务注解
     public MerVerifyCouponVo sureVerifyCoupon(MerVerifyCouponDto merVerifyCouponDto) {
         R<MerVerifyCouponGetVo> verifyCoupon = remoteCouponService.getVerifyCoupon(merVerifyCouponDto.getMemberCouponId());
         if(verifyCoupon.getCode() != 200){
@@ -2678,7 +2690,7 @@
      */
     @Override
     @Transactional
-    @GlobalTransactional(rollbackFor = Exception.class)
+//    @GlobalTransactional(rollbackFor = Exception.class) todo 放开分布式事务注解
     public MerVerifyAwardVo sureVerifyPrize(MerVerifyPrizeDto merVerifyPrizeDto) {
         MerVerifyAwardVo merVerifyAwardVo = new MerVerifyAwardVo();
         MemberGiftRecord memberGiftRecord = remoteMemberService.getVerifyPrize(merVerifyPrizeDto.getPrizeId()).getData();
@@ -2917,7 +2929,7 @@
      */
     @Override
     @Transactional
-    @GlobalTransactional(rollbackFor = Exception.class)
+//    @GlobalTransactional(rollbackFor = Exception.class) todo 放开分布式事务注解
     public void createNewOrder(MerNewOrderDto merNewOrderDto) {
         Long userId = merNewOrderDto.getBuyUserId();
         Date nowTime = new Date();
@@ -5551,7 +5563,7 @@
      */
     @Override
     @Transactional
-    @GlobalTransactional(rollbackFor = Exception.class)
+//    @GlobalTransactional(rollbackFor = Exception.class) todo 放开分布式事务注解
     public void autoCancelOrder(String orderId) {
         //更新订单信息
         Order order = this.getById(orderId);
@@ -5621,7 +5633,7 @@
      */
     @Override
     @Transactional
-    @GlobalTransactional(rollbackFor = Exception.class)
+//    @GlobalTransactional(rollbackFor = Exception.class) todo 放开分布式事务注解
     public void payBack(PartnerTransactionsResult transaction, BigDecimal feeAmount) {
         log.info("订单支付回调---"+transaction.toString());
         // 更新订单状态 outTradeNo
@@ -5767,7 +5779,7 @@
      */
     @Override
     @Transactional
-    @GlobalTransactional(rollbackFor = Exception.class)
+//    @GlobalTransactional(rollbackFor = Exception.class) todo 放开分布式事务注解
     public void refundOrder(String orderId) {
         // 更新订单信息
         Order order = this.getById(orderId);
@@ -6511,7 +6523,7 @@
         }
     }
 
-    @GlobalTransactional(rollbackFor = Exception.class)
+//    @GlobalTransactional(rollbackFor = Exception.class) todo 放开分布式事务注解
     private void autoTimeCancelOrder(Order order) {
         String orderId = order.getOrderId();
         order.setOrderStatus(0);
@@ -6765,4 +6777,108 @@
         return R.ok();
 
     }
+
+    @Override
+    public List<MgtThirdOrderPageVo> pageMgtThirdOrder(Page<MgtThirdOrderPageVo> page, MgtThirdOrderPageDto dto) {
+        //如果区域代码不为null获取对应的商户id
+        if (StringUtils.isNotBlank(dto.getKeyword()) || StringUtils.isNotBlank(dto.getShopProvinceCode()) || StringUtils.isNotBlank(dto.getShopCityCode()) || StringUtils.isNotBlank(dto.getShopAreaCode())) {
+            MgtShopIdByCodeDto mgtShopIdByCodeDto = new MgtShopIdByCodeDto();
+            mgtShopIdByCodeDto.setShopProvinceCode(dto.getShopProvinceCode());
+            mgtShopIdByCodeDto.setShopCityCode(dto.getShopCityCode());
+            mgtShopIdByCodeDto.setShopAreaCode(dto.getShopAreaCode());
+            MgtShopIdByCodeVo mgtShopIdByCodeVo = remoteShopService.getShopIdByCode(mgtShopIdByCodeDto).getData();
+            if (StringUtils.isNotBlank(mgtShopIdByCodeVo.getShopIds())) {
+                dto.setShopIds(mgtShopIdByCodeVo.getShopIds());
+            }
+        }
+        //如果关键词不为null获取对应的用户id
+        if (StringUtils.isNotBlank(dto.getKeyword())) {
+            MgtUserIdByKeywordDto mgtUserIdByKeywordDto = new MgtUserIdByKeywordDto();
+            mgtUserIdByKeywordDto.setKeyword(dto.getKeyword());
+            MgtUserIdByKeywordVo mgtUserIdByKeywordVo = remoteMemberService.getUserIdByKeyword(mgtUserIdByKeywordDto).getData();
+            if (StringUtils.isNotBlank(mgtUserIdByKeywordVo.getUserIds())) {
+                dto.setUserIds(mgtUserIdByKeywordVo.getUserIds());
+            }
+        }
+        //数据权限
+        List<Long> userId = remoteUserService.getScopeOfAuthorityUserId();
+        BoardMemberTotalDto boardMemberTotalDto = new BoardMemberTotalDto();
+        boardMemberTotalDto.setUserIds(userId);
+        List<Shop> shops = remoteShopService.getShopBySysUserIds(boardMemberTotalDto);
+        if (!shops.isEmpty()) {
+            List<Long> collect = shops.stream().map(Shop::getShopId).collect(Collectors.toList());
+            String join = collect.stream().map(Object::toString).collect(Collectors.joining(","));
+            String shopIds = dto.getShopIds();
+            if(StringUtils.isNotEmpty(shopIds)){
+                shopIds = shopIds + "," + join;
+            }else{
+                shopIds = join;
+            }
+            dto.setShopIds(shopIds);
+        }
+
+        // 从数据库中获取第三方订单列表
+        List<MgtThirdOrderPageVo> thirdOrderPageVoList = orderMapper.pageMgtThirdOrder(page, dto);
+        // 如果列表不为空
+        if (!thirdOrderPageVoList.isEmpty()) {
+            // 定义变量
+            HashSet<Long> shopIdSet = new HashSet<>();
+            BigDecimal zeroBig = new BigDecimal("0.00");
+            // 遍历列表,获取店铺 ID 和用户 ID
+            for (MgtThirdOrderPageVo mgtActivityOrderPageVo : thirdOrderPageVoList) {
+                if(mgtActivityOrderPageVo.getShopId()!=null){
+                    shopIdSet.add(mgtActivityOrderPageVo.getShopId());
+                }
+            }
+            // 将店铺 ID 和用户 ID 转换为逗号分隔的字符串
+            String shopJoinedString = String.join(",", shopIdSet.stream().map(Object::toString).collect(Collectors.toList()));
+            // 从远程服务获取店铺和用户信息
+            MgtBaseBathDto mgtBaseBathDto = new MgtBaseBathDto();
+            mgtBaseBathDto.setIds(shopJoinedString);
+            List<MgtSimpleShopVo> simpleShopVoList = remoteShopService.listShopSimpleVoByIds(mgtBaseBathDto).getData();
+            Map<Long, MgtSimpleShopVo> shopMap = simpleShopVoList.stream()
+                    .collect(Collectors.toMap(MgtSimpleShopVo::getShopId, Function.identity()));
+            mgtBaseBathDto = new MgtBaseBathDto();
+            // 遍历列表,设置店铺名称
+            for (MgtThirdOrderPageVo mgtActivityOrderPageVo : thirdOrderPageVoList) {
+                if(mgtActivityOrderPageVo.getShopId()!=null){
+                    MgtSimpleShopVo mgtSimpleShopVo = shopMap.get(mgtActivityOrderPageVo.getShopId());
+                    mgtActivityOrderPageVo.setShopName(null == mgtSimpleShopVo ? "" : mgtSimpleShopVo.getShopName());
+                }
+            }
+        }
+
+        return thirdOrderPageVoList;
+
+    }
+
+    @Override
+    public MgtPlTotalThirdOrderStaticsVO getPlTotalThirdOrderStatics(MgtBasePlatformDto mgtBasePlatformDto) {
+        MgtPlTotalThirdOrderStaticsVO vo = new MgtPlTotalThirdOrderStaticsVO();
+        //数据权限
+        List<Long> userIdList = mgtBasePlatformDto.getUserIdList();
+        List<Long> userIds = remoteUserService.getScopeOfAuthorityUserId();
+        if(null != userIds){
+            if(null != userIdList){
+                userIdList.addAll(userIds);
+            }else{
+                userIdList = userIds;
+            }
+            mgtBasePlatformDto.setUserIdList(userIdList);
+        }
+        List<Long> shopIdList = remoteShopService.listShopIdByPlTotal(mgtBasePlatformDto).getData();
+        if (mgtBasePlatformDto.getUserId() != null || StringUtils.isNotBlank(mgtBasePlatformDto.getShopProvinceCode()) || StringUtils.isNotBlank(mgtBasePlatformDto.getShopCityCode()) || StringUtils.isNotBlank(mgtBasePlatformDto.getShopAreaCode())) {
+            if(shopIdList==null||shopIdList.isEmpty()){
+                return vo;
+            }
+        }
+        if(mgtBasePlatformDto.getShopId()!=null){
+            shopIdList = new ArrayList<>();
+            shopIdList.add(mgtBasePlatformDto.getShopId());
+        }
+        mgtBasePlatformDto.setShopIdList(shopIdList);
+        // 从数据库中获取第三方订单统计
+         vo = orderMapper.getPlTotalThirdOrderStatics(mgtBasePlatformDto);
+        return vo;
+    }
 }

--
Gitblit v1.7.1