diff --git a/zsw-bxg/src/main/java/co/yixiang/app/modules/cart/rest/StoreCartController.java b/zsw-bxg/src/main/java/co/yixiang/app/modules/cart/rest/StoreCartController.java index 79474821..025dcc61 100644 --- a/zsw-bxg/src/main/java/co/yixiang/app/modules/cart/rest/StoreCartController.java +++ b/zsw-bxg/src/main/java/co/yixiang/app/modules/cart/rest/StoreCartController.java @@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; +import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.Map; @@ -87,7 +88,7 @@ public class StoreCartController { @AuthCheck @GetMapping("/cart/list") @ApiOperation(value = "购物车列表",notes = "购物车列表") - public ApiResult> getList(){ + public ApiResult> getList(){ Long uid = LocalUser.getUser().getUid(); return ApiResult.ok(storeCartService.getUserProductCartList(uid,"",null)); } diff --git a/zsw-bxg/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreCouponUserServiceImpl.java b/zsw-bxg/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreCouponUserServiceImpl.java index 501370b5..007f6165 100644 --- a/zsw-bxg/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreCouponUserServiceImpl.java +++ b/zsw-bxg/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreCouponUserServiceImpl.java @@ -27,6 +27,7 @@ import co.yixiang.modules.activity.service.dto.YxStoreCouponUserQueryCriteria; import co.yixiang.modules.activity.service.mapper.YxStoreCouponUserMapper; import co.yixiang.modules.activity.vo.StoreCouponUserVo; import co.yixiang.modules.activity.vo.YxStoreCouponUserQueryVo; +import co.yixiang.modules.cart.domain.YxStoreBrandCart; import co.yixiang.modules.cart.service.YxStoreCartService; import co.yixiang.modules.cart.vo.YxStoreCartQueryVo; import co.yixiang.modules.user.domain.YxUser; @@ -96,11 +97,15 @@ public class YxStoreCouponUserServiceImpl extends BaseServiceImpl beUsableCouponList(Long uid,String cartIds) { - Map cartGroup = yxStoreCartService.getUserProductCartList(uid, + Map cartGroup = yxStoreCartService.getUserProductCartList(uid, cartIds, ShopConstants.ZSW_ONE_NUM); - - List cartInfo = (List)cartGroup.get("valid"); - + List list = new ArrayList<>(); + cartGroup.get("cartList").forEach(item-> { + YxStoreBrandCart yxStoreBrandCart = (YxStoreBrandCart) item; + list.addAll(yxStoreBrandCart.getValidProductList()); + }); +// List cartInfo = (List)cartGroup.get("valid"); + List cartInfo=list; BigDecimal sumPrice = BigDecimal.ZERO; for (YxStoreCartQueryVo storeCart : cartInfo) { sumPrice = NumberUtil.add(sumPrice,NumberUtil.mul(storeCart.getCartNum(),storeCart.getTruePrice())); diff --git a/zsw-bxg/src/main/java/co/yixiang/modules/cart/domain/YxStoreBrandCart.java b/zsw-bxg/src/main/java/co/yixiang/modules/cart/domain/YxStoreBrandCart.java new file mode 100644 index 00000000..f37e6394 --- /dev/null +++ b/zsw-bxg/src/main/java/co/yixiang/modules/cart/domain/YxStoreBrandCart.java @@ -0,0 +1,17 @@ +package co.yixiang.modules.cart.domain; + +import co.yixiang.modules.cart.vo.YxStoreCartQueryVo; +import lombok.Data; + +import java.util.List; +import java.util.Map; + +@Data +public class YxStoreBrandCart{ + //购物车品牌的信息 + private Map brand; + //购物车品牌下的有效的商品列表 + private List validProductList; + //购物车品牌下的有效的商品列表 + private List invalidProductList; +} diff --git a/zsw-bxg/src/main/java/co/yixiang/modules/cart/service/YxStoreCartService.java b/zsw-bxg/src/main/java/co/yixiang/modules/cart/service/YxStoreCartService.java index 856c3bb0..98360ffb 100644 --- a/zsw-bxg/src/main/java/co/yixiang/modules/cart/service/YxStoreCartService.java +++ b/zsw-bxg/src/main/java/co/yixiang/modules/cart/service/YxStoreCartService.java @@ -17,6 +17,7 @@ import org.springframework.data.domain.Pageable; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -48,7 +49,7 @@ public interface YxStoreCartService extends BaseService{ * @param status 0-购购物车列表 * @return map valid-有效购物车 invalid-失效购物车 */ - Map getUserProductCartList(Long uid,String cartIds,Integer status); + Map getUserProductCartList(Long uid, String cartIds, Integer status); /** * 返回当前用户购物车总数量 diff --git a/zsw-bxg/src/main/java/co/yixiang/modules/cart/service/impl/YxStoreCartServiceImpl.java b/zsw-bxg/src/main/java/co/yixiang/modules/cart/service/impl/YxStoreCartServiceImpl.java index 45cece75..d2104191 100644 --- a/zsw-bxg/src/main/java/co/yixiang/modules/cart/service/impl/YxStoreCartServiceImpl.java +++ b/zsw-bxg/src/main/java/co/yixiang/modules/cart/service/impl/YxStoreCartServiceImpl.java @@ -23,6 +23,7 @@ import co.yixiang.modules.activity.service.YxStoreBargainService; import co.yixiang.modules.activity.service.mapper.YxStoreBargainMapper; import co.yixiang.modules.activity.service.mapper.YxStoreCombinationMapper; import co.yixiang.modules.activity.service.mapper.YxStoreSeckillMapper; +import co.yixiang.modules.cart.domain.YxStoreBrandCart; import co.yixiang.modules.cart.domain.YxStoreCart; import co.yixiang.modules.cart.service.YxStoreCartService; import co.yixiang.modules.cart.service.dto.YxStoreCartDto; @@ -153,7 +154,7 @@ public class YxStoreCartServiceImpl extends BaseServiceImpl getUserProductCartList(Long uid, String cartIds, Integer status) { + public Map getUserProductCartList(Long uid, String cartIds, Integer status) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(YxStoreCart::getUid, uid) .eq(YxStoreCart::getIsPay, OrderInfoEnum.PAY_STATUS_0.getValue()) @@ -200,7 +201,6 @@ public class YxStoreCartServiceImpl extends BaseServiceImpl map = new LinkedHashMap<>(); + Map map = new LinkedHashMap<>(); //最终返回的有效商品的数组 ArrayList cartList=new ArrayList<>(); //获取不重复的品牌id数组 @@ -268,12 +268,12 @@ public class YxStoreCartServiceImpl extends BaseServiceImpl{ - Map map1 = new LinkedHashMap<>(); YxStoreBrand yxStoreBrand=yxStoreBrandMapper.selectById(item); Map list = new LinkedHashMap<>(); + YxStoreBrandCart yxStoreBrandCart=new YxStoreBrandCart(); list.put("brandName",yxStoreBrand.getBrandName()); list.put("pic",yxStoreBrand.getPic()); - map1.put("brand",list); + yxStoreBrandCart.setBrand(list); //对valid/invalid进行筛选,只要当前品牌下的商品 List validProductList = new ArrayList<>(); List invalidProductList = new ArrayList<>(); @@ -291,9 +291,9 @@ public class YxStoreCartServiceImpl extends BaseServiceImpl cartGroup = yxStoreCartService.getUserProductCartList(uid, + Map cartGroup = yxStoreCartService.getUserProductCartList(uid, cartIds, ShopConstants.ZSW_ONE_NUM); - if (ObjectUtil.isNotEmpty(cartGroup.get("invalid"))) { - throw new YshopException("有失效的商品请重新提交"); - } - if (ObjectUtil.isEmpty(cartGroup.get("valid"))) { - throw new YshopException("请提交购买的商品"); - } + List list = new ArrayList<>(); + cartGroup.get("cartList").forEach(item->{ + YxStoreBrandCart yxStoreBrandCart=(YxStoreBrandCart)item; + if (ObjectUtil.isNotEmpty(yxStoreBrandCart.getInvalidProductList())) { + throw new YshopException("有失效的商品请重新提交"); + } + if (ObjectUtil.isEmpty(yxStoreBrandCart.getValidProductList())) { + throw new YshopException("请提交购买的商品"); + } + list.addAll(yxStoreBrandCart.getValidProductList()); +// Class jsonClass = item.getClass();//通过item,获取运行时类的对象 +// Field invalidProductList = null; +// Field validProductList = null; +// try { +// //获取item中的invalidProductList属性 +// if (ObjectUtil.isNotEmpty(item.getClass().getDeclaredField("invalidProductList"))) { +// throw new YshopException("有失效的商品请重新提交"); +// } +// if (ObjectUtil.isEmpty(item.getClass().getDeclaredField("validProductList"))) { +// throw new YshopException("请提交购买的商品"); +// } +// } catch (NoSuchFieldException e) { +// e.printStackTrace(); +// } + }); OtherDto other = new OtherDto(); other.setIntegralRatio(systemConfigService.getData(SystemConfigConstants.INTERGRAL_RATIO)); other.setIntegralFull(systemConfigService.getData(SystemConfigConstants.INTERGRAL_FULL)); @@ -238,7 +259,8 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl cartInfo = (List) cartGroup.get("valid"); +// List cartInfo = (List) cartGroup.get("valid"); + List cartInfo=list; PriceGroupDto priceGroup = this.getOrderPriceGroup(cartInfo, userAddress); //判断积分是否满足订单额度 @@ -247,8 +269,6 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl productIds = cartInfo.stream() .map(YxStoreCartQueryVo::getProductId)