licailing 5 лет назад
Родитель
Сommit
d2d4a3ecf4

+ 7 - 7
src/main/java/com/izouma/dingdong/service/user/ShoppingCartService.java

@@ -197,7 +197,7 @@ public class ShoppingCartService {
     }
     }
 
 
     //计算价钱
     //计算价钱
-    public ShoppingCart calculatePrice(Long cartId, Long userId) {
+    public ShoppingCart calculatePrice(Long cartId, Long userId, Long merchantId) {
 
 
         //购物车
         //购物车
         ShoppingCart cart = shoppingCartRepo.findById(cartId).orElseThrow(new BusinessException("无购物车"));
         ShoppingCart cart = shoppingCartRepo.findById(cartId).orElseThrow(new BusinessException("无购物车"));
@@ -234,7 +234,7 @@ public class ShoppingCartService {
         BigDecimal total = goodsTotal.add(packingPrice);
         BigDecimal total = goodsTotal.add(packingPrice);
 
 
         //按商家创建购物车
         //按商家创建购物车
-        Long merchantId = specs.get(0).getGoods().getMerchantId();
+        // Long merchantId = specs.get(0).getGoods().getMerchantId();
         //商家信息
         //商家信息
         MerchantSettings merchant = merchantSettingsRepo.findByMerchantId(merchantId).orElseThrow(new BusinessException("无商户"));
         MerchantSettings merchant = merchantSettingsRepo.findByMerchantId(merchantId).orElseThrow(new BusinessException("无商户"));
 
 
@@ -328,28 +328,28 @@ public class ShoppingCartService {
 
 
         this.changeOrderSpec(save, orderGoodsSpec);
         this.changeOrderSpec(save, orderGoodsSpec);
 
 
-        return this.calculatePrice(save.getId(), userId);
+        return this.calculatePrice(save.getId(), userId, save.getMerchantId());
     }
     }
 
 
     //减规格
     //减规格
     public ShoppingCart sub(Long specId, Long userId) {
     public ShoppingCart sub(Long specId, Long userId) {
         OrderGoodsSpec spec = orderGoodsSpecRepo.findById(specId).orElseThrow(new BusinessException("无订单详情"));
         OrderGoodsSpec spec = orderGoodsSpecRepo.findById(specId).orElseThrow(new BusinessException("无订单详情"));
-
+        Long merchantId = spec.getGoods().getMerchantId();
         Long cartId = spec.getShoppingCartId();
         Long cartId = spec.getShoppingCartId();
         //if (spec.getShoppingCartId() == null) {
         //if (spec.getShoppingCartId() == null) {
         orderGoodsSpecRepo.deleteById(specId);
         orderGoodsSpecRepo.deleteById(specId);
         //}
         //}
         //shoppingCartRepo.findById(spec.getShoppingCartId());
         //shoppingCartRepo.findById(spec.getShoppingCartId());
-        return this.calculatePrice(cartId, userId);
+        return this.calculatePrice(cartId, userId, merchantId);
     }
     }
 
 
     /*
     /*
     再来一单
     再来一单
      */
      */
-    public OrderInfo again(Long id){
+    public OrderInfo again(Long id) {
         OrderInfo orderInfo = orderInfoRepo.findById(id).orElseThrow(new BusinessException("无订单"));
         OrderInfo orderInfo = orderInfoRepo.findById(id).orElseThrow(new BusinessException("无订单"));
         List<OrderGoodsSpec> orderGoodsSpecs = orderInfo.getOrderGoodsSpecs();
         List<OrderGoodsSpec> orderGoodsSpecs = orderInfo.getOrderGoodsSpecs();
-        orderGoodsSpecs.forEach(o->{
+        orderGoodsSpecs.forEach(o -> {
 
 
         });
         });
 
 

+ 2 - 2
src/test/java/com/izouma/dingdong/service/ShoppingCartServiceTest.java

@@ -41,8 +41,8 @@ public class ShoppingCartServiceTest {
 
 
     @Test
     @Test
     public void testSub(){
     public void testSub(){
-        OrderGoodsSpec add = orderGoodsSpecService.add(607L, null, 1);
-        System.out.println(shoppingCartService.add(83L, add));
+        OrderGoodsSpec add = orderGoodsSpecService.add(1636L, null, 1);
+        System.out.println(shoppingCartService.add(82L, add));
         //System.out.println(shoppingCartService.sub(1500L, 83L));
         //System.out.println(shoppingCartService.sub(1500L, 83L));
     }
     }
 }
 }