Browse Source

修复因购物车改变引起的订单流程

zyj
sj 2 years ago
parent
commit
4180aa5567
  1. 3
      zsw-bxg/src/main/java/co/yixiang/app/modules/cart/rest/StoreCartController.java
  2. 13
      zsw-bxg/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreCouponUserServiceImpl.java
  3. 17
      zsw-bxg/src/main/java/co/yixiang/modules/cart/domain/YxStoreBrandCart.java
  4. 3
      zsw-bxg/src/main/java/co/yixiang/modules/cart/service/YxStoreCartService.java
  5. 16
      zsw-bxg/src/main/java/co/yixiang/modules/cart/service/impl/YxStoreCartServiceImpl.java
  6. 42
      zsw-bxg/src/main/java/co/yixiang/modules/order/service/impl/YxStoreOrderServiceImpl.java

3
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.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
@ -87,7 +88,7 @@ public class StoreCartController {
@AuthCheck @AuthCheck
@GetMapping("/cart/list") @GetMapping("/cart/list")
@ApiOperation(value = "购物车列表",notes = "购物车列表") @ApiOperation(value = "购物车列表",notes = "购物车列表")
public ApiResult<Map<String,Object>> getList(){ public ApiResult<Map<String, ArrayList>> getList(){
Long uid = LocalUser.getUser().getUid(); Long uid = LocalUser.getUser().getUid();
return ApiResult.ok(storeCartService.getUserProductCartList(uid,"",null)); return ApiResult.ok(storeCartService.getUserProductCartList(uid,"",null));
} }

13
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.service.mapper.YxStoreCouponUserMapper;
import co.yixiang.modules.activity.vo.StoreCouponUserVo; import co.yixiang.modules.activity.vo.StoreCouponUserVo;
import co.yixiang.modules.activity.vo.YxStoreCouponUserQueryVo; 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.service.YxStoreCartService;
import co.yixiang.modules.cart.vo.YxStoreCartQueryVo; import co.yixiang.modules.cart.vo.YxStoreCartQueryVo;
import co.yixiang.modules.user.domain.YxUser; import co.yixiang.modules.user.domain.YxUser;
@ -96,11 +97,15 @@ public class YxStoreCouponUserServiceImpl extends BaseServiceImpl<YxStoreCouponU
@Override @Override
public List<StoreCouponUserVo> beUsableCouponList(Long uid,String cartIds) { public List<StoreCouponUserVo> beUsableCouponList(Long uid,String cartIds) {
Map<String, Object> cartGroup = yxStoreCartService.getUserProductCartList(uid, Map<String, ArrayList> cartGroup = yxStoreCartService.getUserProductCartList(uid,
cartIds, ShopConstants.ZSW_ONE_NUM); cartIds, ShopConstants.ZSW_ONE_NUM);
List<YxStoreCartQueryVo> list = new ArrayList<>();
List<YxStoreCartQueryVo> cartInfo = (List<YxStoreCartQueryVo>)cartGroup.get("valid"); cartGroup.get("cartList").forEach(item-> {
YxStoreBrandCart yxStoreBrandCart = (YxStoreBrandCart) item;
list.addAll(yxStoreBrandCart.getValidProductList());
});
// List<YxStoreCartQueryVo> cartInfo = (List<YxStoreCartQueryVo>)cartGroup.get("valid");
List<YxStoreCartQueryVo> cartInfo=list;
BigDecimal sumPrice = BigDecimal.ZERO; BigDecimal sumPrice = BigDecimal.ZERO;
for (YxStoreCartQueryVo storeCart : cartInfo) { for (YxStoreCartQueryVo storeCart : cartInfo) {
sumPrice = NumberUtil.add(sumPrice,NumberUtil.mul(storeCart.getCartNum(),storeCart.getTruePrice())); sumPrice = NumberUtil.add(sumPrice,NumberUtil.mul(storeCart.getCartNum(),storeCart.getTruePrice()));

17
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<String, Object> brand;
//购物车品牌下的有效的商品列表
private List<YxStoreCartQueryVo> validProductList;
//购物车品牌下的有效的商品列表
private List<YxStoreCartQueryVo> invalidProductList;
}

3
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 javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -48,7 +49,7 @@ public interface YxStoreCartService extends BaseService<YxStoreCart>{
* @param status 0-购购物车列表 * @param status 0-购购物车列表
* @return map valid-有效购物车 invalid-失效购物车 * @return map valid-有效购物车 invalid-失效购物车
*/ */
Map<String,Object> getUserProductCartList(Long uid,String cartIds,Integer status); Map<String, ArrayList> getUserProductCartList(Long uid, String cartIds, Integer status);
/** /**
* 返回当前用户购物车总数量 * 返回当前用户购物车总数量

16
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.YxStoreBargainMapper;
import co.yixiang.modules.activity.service.mapper.YxStoreCombinationMapper; import co.yixiang.modules.activity.service.mapper.YxStoreCombinationMapper;
import co.yixiang.modules.activity.service.mapper.YxStoreSeckillMapper; 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.domain.YxStoreCart;
import co.yixiang.modules.cart.service.YxStoreCartService; import co.yixiang.modules.cart.service.YxStoreCartService;
import co.yixiang.modules.cart.service.dto.YxStoreCartDto; import co.yixiang.modules.cart.service.dto.YxStoreCartDto;
@ -153,7 +154,7 @@ public class YxStoreCartServiceImpl extends BaseServiceImpl<StoreCartMapper, YxS
* @return map valid-有效购物车 invalid-失效购物车 * @return map valid-有效购物车 invalid-失效购物车
*/ */
@Override @Override
public Map<String, Object> getUserProductCartList(Long uid, String cartIds, Integer status) { public Map<String, ArrayList> getUserProductCartList(Long uid, String cartIds, Integer status) {
LambdaQueryWrapper<YxStoreCart> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<YxStoreCart> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(YxStoreCart::getUid, uid) wrapper.eq(YxStoreCart::getUid, uid)
.eq(YxStoreCart::getIsPay, OrderInfoEnum.PAY_STATUS_0.getValue()) .eq(YxStoreCart::getIsPay, OrderInfoEnum.PAY_STATUS_0.getValue())
@ -200,7 +201,6 @@ public class YxStoreCartServiceImpl extends BaseServiceImpl<StoreCartMapper, YxS
} else { } else {
storeProduct.setAttrInfo(productAttrValue); storeProduct.setAttrInfo(productAttrValue);
storeCartQueryVo.setProductInfo(storeProduct); storeCartQueryVo.setProductInfo(storeProduct);
//设置真实价格 //设置真实价格
//设置VIP价格 //设置VIP价格
double vipPrice = userService.setLevelPrice( double vipPrice = userService.setLevelPrice(
@ -252,7 +252,7 @@ public class YxStoreCartServiceImpl extends BaseServiceImpl<StoreCartMapper, YxS
} }
Map<String, Object> map = new LinkedHashMap<>(); Map<String, ArrayList> map = new LinkedHashMap<>();
//最终返回的有效商品的数组 //最终返回的有效商品的数组
ArrayList cartList=new ArrayList<>(); ArrayList cartList=new ArrayList<>();
//获取不重复的品牌id数组 //获取不重复的品牌id数组
@ -268,12 +268,12 @@ public class YxStoreCartServiceImpl extends BaseServiceImpl<StoreCartMapper, YxS
BrandIdList.add(storeProduct.getBrandId()); BrandIdList.add(storeProduct.getBrandId());
}); });
BrandIdList.forEach(item->{ BrandIdList.forEach(item->{
Map<String, Object> map1 = new LinkedHashMap<>();
YxStoreBrand yxStoreBrand=yxStoreBrandMapper.selectById(item); YxStoreBrand yxStoreBrand=yxStoreBrandMapper.selectById(item);
Map<String, Object> list = new LinkedHashMap<>(); Map<String, Object> list = new LinkedHashMap<>();
YxStoreBrandCart yxStoreBrandCart=new YxStoreBrandCart();
list.put("brandName",yxStoreBrand.getBrandName()); list.put("brandName",yxStoreBrand.getBrandName());
list.put("pic",yxStoreBrand.getPic()); list.put("pic",yxStoreBrand.getPic());
map1.put("brand",list); yxStoreBrandCart.setBrand(list);
//对valid/invalid进行筛选,只要当前品牌下的商品 //对valid/invalid进行筛选,只要当前品牌下的商品
List<YxStoreCartQueryVo> validProductList = new ArrayList<>(); List<YxStoreCartQueryVo> validProductList = new ArrayList<>();
List<YxStoreCartQueryVo> invalidProductList = new ArrayList<>(); List<YxStoreCartQueryVo> invalidProductList = new ArrayList<>();
@ -291,9 +291,9 @@ public class YxStoreCartServiceImpl extends BaseServiceImpl<StoreCartMapper, YxS
invalidProductList.add(item1); invalidProductList.add(item1);
} }
}); });
map1.put("validProductList",validProductList); yxStoreBrandCart.setValidProductList(validProductList);
map1.put("invalidProductList",invalidProductList); yxStoreBrandCart.setInvalidProductList(invalidProductList);
cartList.add(map1); cartList.add(yxStoreBrandCart);
}); });
// map.put("valid", valid); // map.put("valid", valid);
// map.put("invalid", invalid); // map.put("invalid", invalid);

42
zsw-bxg/src/main/java/co/yixiang/modules/order/service/impl/YxStoreOrderServiceImpl.java

@ -7,7 +7,6 @@
* 一经发现盗用分享等行为将追究法律责任后果自负 * 一经发现盗用分享等行为将追究法律责任后果自负
*/ */
package co.yixiang.modules.order.service.impl; package co.yixiang.modules.order.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
@ -35,6 +34,7 @@ import co.yixiang.modules.activity.service.YxStoreBargainUserService;
import co.yixiang.modules.activity.service.YxStoreCouponUserService; import co.yixiang.modules.activity.service.YxStoreCouponUserService;
import co.yixiang.modules.activity.service.YxStorePinkService; import co.yixiang.modules.activity.service.YxStorePinkService;
import co.yixiang.modules.activity.vo.StoreCouponUserVo; import co.yixiang.modules.activity.vo.StoreCouponUserVo;
import co.yixiang.modules.cart.domain.YxStoreBrandCart;
import co.yixiang.modules.cart.domain.YxStoreCart; import co.yixiang.modules.cart.domain.YxStoreCart;
import co.yixiang.modules.cart.service.YxStoreCartService; import co.yixiang.modules.cart.service.YxStoreCartService;
import co.yixiang.modules.cart.service.mapper.StoreCartMapper; import co.yixiang.modules.cart.service.mapper.StoreCartMapper;
@ -100,6 +100,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -199,15 +201,34 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<StoreOrderMapper, Y
@Override @Override
public ConfirmOrderVo confirmOrder(YxUser yxUser, String cartIds) { public ConfirmOrderVo confirmOrder(YxUser yxUser, String cartIds) {
Long uid = yxUser.getUid(); Long uid = yxUser.getUid();
Map<String, Object> cartGroup = yxStoreCartService.getUserProductCartList(uid, Map<String, ArrayList> cartGroup = yxStoreCartService.getUserProductCartList(uid,
cartIds, ShopConstants.ZSW_ONE_NUM); cartIds, ShopConstants.ZSW_ONE_NUM);
if (ObjectUtil.isNotEmpty(cartGroup.get("invalid"))) { List<YxStoreCartQueryVo> list = new ArrayList<>();
throw new YshopException("有失效的商品请重新提交");
}
if (ObjectUtil.isEmpty(cartGroup.get("valid"))) {
throw new YshopException("请提交购买的商品");
}
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(); OtherDto other = new OtherDto();
other.setIntegralRatio(systemConfigService.getData(SystemConfigConstants.INTERGRAL_RATIO)); other.setIntegralRatio(systemConfigService.getData(SystemConfigConstants.INTERGRAL_RATIO));
other.setIntegralFull(systemConfigService.getData(SystemConfigConstants.INTERGRAL_FULL)); other.setIntegralFull(systemConfigService.getData(SystemConfigConstants.INTERGRAL_FULL));
@ -238,7 +259,8 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<StoreOrderMapper, Y
.eq(YxUserAddress::getUid, uid) .eq(YxUserAddress::getUid, uid)
.eq(YxUserAddress::getIsDefault, ShopCommonEnum.DEFAULT_1.getValue()), false); .eq(YxUserAddress::getIsDefault, ShopCommonEnum.DEFAULT_1.getValue()), false);
List<YxStoreCartQueryVo> cartInfo = (List<YxStoreCartQueryVo>) cartGroup.get("valid"); // List<YxStoreCartQueryVo> cartInfo = (List<YxStoreCartQueryVo>) cartGroup.get("valid");
List<YxStoreCartQueryVo> cartInfo=list;
PriceGroupDto priceGroup = this.getOrderPriceGroup(cartInfo, userAddress); PriceGroupDto priceGroup = this.getOrderPriceGroup(cartInfo, userAddress);
//判断积分是否满足订单额度 //判断积分是否满足订单额度
@ -247,8 +269,6 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<StoreOrderMapper, Y
} }
String cacheKey = this.cacheOrderInfo(uid, cartInfo, priceGroup, other); String cacheKey = this.cacheOrderInfo(uid, cartInfo, priceGroup, other);
//获取可用优惠券 //获取可用优惠券
List<String> productIds = cartInfo.stream() List<String> productIds = cartInfo.stream()
.map(YxStoreCartQueryVo::getProductId) .map(YxStoreCartQueryVo::getProductId)

Loading…
Cancel
Save