|
@@ -13,6 +13,8 @@ import cn.newfeifan.mall.framework.common.util.json.JsonUtils;
|
|
|
import cn.newfeifan.mall.framework.common.util.number.MoneyUtils;
|
|
|
import cn.newfeifan.mall.module.member.api.address.MemberAddressApi;
|
|
|
import cn.newfeifan.mall.module.member.api.address.dto.MemberAddressRespDTO;
|
|
|
+import cn.newfeifan.mall.module.member.dal.dataobject.user.MemberUserDO;
|
|
|
+import cn.newfeifan.mall.module.member.dal.mysql.user.MemberUserMapper;
|
|
|
import cn.newfeifan.mall.module.pay.api.order.PayOrderApi;
|
|
|
import cn.newfeifan.mall.module.pay.api.order.dto.PayOrderCreateReqDTO;
|
|
|
import cn.newfeifan.mall.module.pay.api.order.dto.PayOrderRespDTO;
|
|
@@ -56,6 +58,7 @@ import cn.newfeifan.mall.module.trade.service.price.calculator.TradePriceCalcula
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.ehcache.shadow.org.terracotta.offheapstore.HashingMap;
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -80,6 +83,9 @@ import static cn.newfeifan.mall.module.trade.enums.ErrorCodeConstants.*;
|
|
|
@Slf4j
|
|
|
public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
|
|
|
+ @Resource
|
|
|
+ private MemberUserMapper memberUserMapper;//add by ben 20240314
|
|
|
+
|
|
|
@Resource
|
|
|
private ProductSkuMapper productSkuMapper;//add by ben 20240314
|
|
|
|
|
@@ -125,27 +131,35 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
settlementReqVO.setAddressId(address.getId());
|
|
|
}
|
|
|
|
|
|
- // 2. 计算价格
|
|
|
- TradePriceCalculateRespBO calculateRespBO = calculatePrice(userId, settlementReqVO);
|
|
|
-
|
|
|
- // 3. 拼接返回
|
|
|
- AppTradeOrderSettlementRespVO respVO = TradeOrderConvert.INSTANCE.convert(calculateRespBO, address);
|
|
|
-
|
|
|
// add by Ben 20240314
|
|
|
// 4. 查询每个sku对应的店铺ID,并传回页面
|
|
|
List<AppTradeOrderSettlementReqVO.Item> productSkuList = settlementReqVO.getItems();
|
|
|
- List<Long> productSkuIdList = new ArrayList<>();
|
|
|
+ List<Long> productSkuIdList = new ArrayList<Long>();
|
|
|
+ Map<Long,AppTradeOrderSettlementReqVO.Item> itemMap = new HashMap<Long,AppTradeOrderSettlementReqVO.Item>();
|
|
|
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<Long, List<Long>>();
|
|
|
+ //key为店铺ID,value为item的Map
|
|
|
+ Map<Long,List<AppTradeOrderSettlementReqVO.Item>> shopSkuItemMap = new HashMap<Long,List<AppTradeOrderSettlementReqVO.Item>>();
|
|
|
+
|
|
|
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<AppTradeOrderSettlementReqVO.Item>();
|
|
|
+ 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<Long>();
|
|
@@ -154,7 +168,6 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
shopSkuList.add(skuId);//把sku根据店聚合放到map中
|
|
|
}
|
|
|
|
|
|
- respVO.setShopSkuIds(shopSkuIds);//把sku根据店聚合放到map中
|
|
|
|
|
|
//把店铺id和店铺名称查出来放到map中
|
|
|
List<Long> shopIds = new ArrayList<Long>();
|
|
@@ -166,10 +179,65 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
for (ShopDO shopDO : shopDOList) {
|
|
|
shopNameMap.put(shopDO.getId(),shopDO.getName());
|
|
|
}
|
|
|
+
|
|
|
+ // 2. 计算价格
|
|
|
+ /**
|
|
|
+ * add by Ben 20240402
|
|
|
+ * 原来下面的代码中是取settlementReqVO.getItems()的所有项计算的,其中Items含不同店铺的商品,现在要把不同店铺的商品分开计算
|
|
|
+ *
|
|
|
+ */
|
|
|
+ //保存每个店铺返回页面的 订单信息汇总
|
|
|
+ Map<Long,AppTradeOrderSettlementRespVO> shopRespVOMap = new HashMap<Long,AppTradeOrderSettlementRespVO>();
|
|
|
+ //所有店铺支付总价
|
|
|
+ Integer allShopPayPrice = 0;
|
|
|
+ //所有店商品不算运费的商品总价
|
|
|
+ Integer allShopItemPrice = 0;
|
|
|
+ //所有店运费总价
|
|
|
+ Integer allShopDeliveryPrice = 0;
|
|
|
+
|
|
|
+ //循环计算各个店铺的价格
|
|
|
+ for(Long shopId:shopSkuItemMap.keySet()){
|
|
|
+ List<AppTradeOrderSettlementReqVO.Item> items = shopSkuItemMap.get(shopId);
|
|
|
+ AppTradeOrderSettlementReqVO shopSettlementReqVO = new AppTradeOrderSettlementReqVO();
|
|
|
+ BeanUtils.copyProperties(settlementReqVO, shopSettlementReqVO);
|
|
|
+ shopSettlementReqVO.setItems(items);//设置每个店铺的商品。
|
|
|
+ shopSettlementReqVO.setShopId(shopId);
|
|
|
+
|
|
|
+ //计算价格
|
|
|
+ TradePriceCalculateRespBO shopCalculateRespBO = calculatePrice(userId, shopSettlementReqVO);
|
|
|
+ // 3. 拼接返回
|
|
|
+ AppTradeOrderSettlementRespVO respVO = TradeOrderConvert.INSTANCE.convert(shopCalculateRespBO, address);
|
|
|
+ shopRespVOMap.put(shopId,respVO);
|
|
|
+
|
|
|
+ //所有店铺支付总价
|
|
|
+ allShopPayPrice += shopCalculateRespBO.getPrice().getPayPrice();
|
|
|
+ //所有店商品不算运费的商品总价
|
|
|
+ allShopItemPrice += shopCalculateRespBO.getPrice().getTotalPrice();
|
|
|
+ //所有店运费总价
|
|
|
+ allShopDeliveryPrice += shopCalculateRespBO.getPrice().getDeliveryPrice();
|
|
|
+ }
|
|
|
+
|
|
|
+// TradePriceCalculateRespBO calculateRespBO = calculatePrice(userId, settlementReqVO);
|
|
|
+
|
|
|
+ TradePriceCalculateRespBO calculateRespBO = new TradePriceCalculateRespBO();
|
|
|
+ calculateRespBO.getPrice().setPayPrice(allShopPayPrice);
|
|
|
+ calculateRespBO.getPrice().setTotalPrice(allShopItemPrice);
|
|
|
+ calculateRespBO.getPrice().setDeliveryPrice(allShopDeliveryPrice);
|
|
|
+
|
|
|
+ //2.5 加载用户有的积分
|
|
|
+ MemberUserDO memberUserDO = memberUserMapper.selectById(userId);
|
|
|
+ Long memberPoints = memberUserDO.getCurrentMemberPoints();//用户当前积分
|
|
|
+
|
|
|
+ // 3. 拼接返回
|
|
|
+ AppTradeOrderSettlementRespVO respVO = TradeOrderConvert.INSTANCE.convert(calculateRespBO, address);
|
|
|
+
|
|
|
+ // add by Ben
|
|
|
+ respVO.setShopSkuIds(shopSkuIds);//把sku根据店聚合放到map中
|
|
|
respVO.setShopNameMap(shopNameMap);
|
|
|
+ respVO.setCurrentMemberPoints(memberPoints);//用户当前积分
|
|
|
|
|
|
- System.out.println("shopSkuIds@@@@@@@@"+shopSkuIds);
|
|
|
- System.out.println("shopNameMap@@@@@@@@"+shopNameMap);
|
|
|
+// System.out.println("shopSkuIds@@@@@@@@"+shopSkuIds);
|
|
|
+// System.out.println("shopNameMap@@@@@@@@"+shopNameMap);
|
|
|
|
|
|
return respVO;
|
|
|
}
|
|
@@ -204,6 +272,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
TradePriceCalculateReqBO calculateReqBO = TradeOrderConvert.INSTANCE.convert(userId, settlementReqVO, cartList);
|
|
|
calculateReqBO.getItems().forEach(item -> Assert.isTrue(item.getSelected(), // 防御性编程,保证都是选中的
|
|
|
"商品({}) 未设置为选中", item.getSkuId()));
|
|
|
+
|
|
|
+ calculateReqBO.setShopId(settlementReqVO.getShopId());
|
|
|
return tradePriceService.calculatePrice(calculateReqBO);
|
|
|
}
|
|
|
|