| 
					
				 | 
			
			
				@@ -87,8 +87,10 @@ import static cn.newfeifan.mall.framework.common.exception.util.ServiceException 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import static cn.newfeifan.mall.framework.common.util.collection.CollectionUtils.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import static cn.newfeifan.mall.framework.common.util.date.LocalDateTimeUtils.minusTime; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import static cn.newfeifan.mall.framework.common.util.servlet.ServletUtils.getClientIP; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import static cn.newfeifan.mall.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import static cn.newfeifan.mall.framework.web.core.util.WebFrameworkUtils.getTerminal; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import static cn.newfeifan.mall.module.trade.enums.ErrorCodeConstants.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import static cn.newfeifan.mall.module.trade.enums.delivery.DeliveryTypeEnum.VIRTUAL_PRODUCT; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -273,6 +275,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             shopNameMap.put(shopDO.getId(), shopDO.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //如果是虚拟商品,则用自己的编写的程序返回 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(Objects.equals(settlementReqVO.getDeliveryType(), VIRTUAL_PRODUCT.getType())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return getSettlement(settlementReqVO.getItems()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 2. 计算价格 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           add by Ben 20240402 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -346,6 +353,95 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return respVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 虚拟商品自走程序 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param items 商品项数组 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return AppTradeOrderSettlementRespVO 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private AppTradeOrderSettlementRespVO getSettlement(List<AppTradeOrderSettlementReqVO.Item> items){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 4. 查询每个sku对应的店铺ID,并传回页面 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<AppTradeOrderSettlementReqVO.Item> productSkuList = items; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<Long> productSkuIdList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<Long, AppTradeOrderSettlementReqVO.Item> itemMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (AppTradeOrderSettlementReqVO.Item skuItem : productSkuList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            productSkuIdList.add(skuItem.getSkuId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            itemMap.put(skuItem.getSkuId(), skuItem); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 查询每个skuid对应的sku对象 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<ProductSkuDO> productSkuDOList = productSkuMapper.selectListBySKuId(productSkuIdList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //key为店铺ID,value为skuid的List 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<Long, List<Long>> shopSkuIds = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //key为店铺ID,value为item的Map 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<Long, List<AppTradeOrderSettlementReqVO.Item>> shopSkuItemMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (ProductSkuDO sku : productSkuDOList) {//把sku根据店聚合放到map中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Long skuId = sku.getId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Long shopId = sku.getShopId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<AppTradeOrderSettlementReqVO.Item> itemList = shopSkuItemMap.get(shopId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (itemList == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                itemList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                shopSkuItemMap.put(shopId, itemList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            AppTradeOrderSettlementReqVO.Item item = new AppTradeOrderSettlementReqVO.Item(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            itemList.add(itemMap.get(skuId)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<Long> shopSkuList = shopSkuIds.get(shopId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (shopSkuList == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                shopSkuList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                shopSkuIds.put(shopId, shopSkuList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            shopSkuList.add(skuId);//把sku根据店聚合放到map中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //把店铺id和店铺名称查出来放到map中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<Long> shopIds = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (Long shopid : shopSkuIds.keySet()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            shopIds.add(shopid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<ShopDO> shopDOList = shopMapper.selectListById(shopIds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<Long, String> shopNameMap = new HashMap<>();//key为店铺id,value为店铺名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (ShopDO shopDO : shopDOList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            shopNameMap.put(shopDO.getId(), shopDO.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AppTradeOrderSettlementRespVO respVO = new AppTradeOrderSettlementRespVO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        respVO.setShopNameMap(shopNameMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        respVO.setShopSkuIds(shopSkuIds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        IntegralDO integralDO = integralMapper.selectOne("user_id", getLoginUserId());//查询出用户积分相关信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Long currentQuota = integralDO.getCurrentQuota();//获取用户当前积分 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        respVO.setCurrentQuota(currentQuota); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //保存每个店铺返回页面的 订单信息汇总 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<Long, AppTradeOrderSettlementRespVO> shopRespVOMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //所有店铺支付总价 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AppTradeOrderSettlementRespVO.Price shopCalculateRespBO = new AppTradeOrderSettlementRespVO.Price(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //循环计算各个店铺的价格 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (Long shopId : shopSkuItemMap.keySet()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<AppTradeOrderSettlementReqVO.Item> orderItems = shopSkuItemMap.get(shopId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //计算价格 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            shopRespVOMap.put(shopId, respVO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ProductSkuDO productSkuDO = productSkuMapper.selectById(orderItems.get(0).getSkuId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            shopCalculateRespBO.setVirtualPayPrice(productSkuDO.getHighPrecisionPrice().doubleValue() * orderItems.get(0).getCount()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            shopCalculateRespBO.setVirtualTotalPrice(productSkuDO.getHighPrecisionPrice().doubleValue() * orderItems.get(0).getCount()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //把重复的收货地址置为空 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (Long shopId : shopRespVOMap.keySet()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            AppTradeOrderSettlementRespVO a = shopRespVOMap.get(shopId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            a.setAddress(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        respVO.setShopRespVOMap(shopRespVOMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        respVO.setPrice(shopCalculateRespBO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return respVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 获得用户地址 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -777,7 +873,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } else if (Objects.equals(createReqVO.getDeliveryType(), DeliveryTypeEnum.PICK_UP.getType())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             order.setReceiverName(createReqVO.getReceiverName()).setReceiverMobile(createReqVO.getReceiverMobile()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             order.setPickUpVerifyCode(RandomUtil.randomNumbers(8)); // 随机一个核销码,长度为 8 位 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } else if(Objects.equals(createReqVO.getDeliveryType(), DeliveryTypeEnum.VIRTUAL_PRODUCT.getType())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else if(Objects.equals(createReqVO.getDeliveryType(), VIRTUAL_PRODUCT.getType())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             MemberAddressRespDTO address = addressApi.getAddress(createReqVO.getAddressId(), userId,2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             order.setReceiverName(address.getName()).setReceiverMobile(address.getMobile()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     .setReceiverDetailAddress(address.getDetailAddress()); 
			 |