Browse Source

8.1 购物车去重

Mechrevo 1 year ago
parent
commit
e1b560aadb

+ 9 - 4
sp-service/level-one-server/src/main/java/com/pj/tb_goods_cart/TbGoodsCartService.java

@@ -3,12 +3,12 @@ package com.pj.tb_goods_cart;
 import java.util.Date;
 import java.util.List;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.pj.api.client.admin.AdminInterface;
 import com.pj.api.dto.AppUserDto;
 import com.pj.common.core.exception.ServiceException;
 import com.pj.current.dto.APPLoginUserInfo;
 import com.pj.current.satoken.StpAPPUserUtil;
-import com.pj.current.satoken.StpUserUtil;
 import com.pj.enummj.DeleteStatus;
 import com.pj.tb_goods_cart.dto.GoodsCartInfoDto;
 import com.pj.tb_goods_transit.TbGoodsTransit;
@@ -74,6 +74,13 @@ public class TbGoodsCartService extends ServiceImpl<TbGoodsCartMapper, TbGoodsCa
 		//获取购买者对象
 		AppUserDto appUser = adminInterface.getAppUserById(id);
 		if(appUser == null || appUser.getId() == null)return AjaxJson.getError("购买者账号异常");
+		//购物车查重
+		int size = tbGoodsCartMapper.selectList(new LambdaQueryWrapper<TbGoodsCart>()
+				.eq(TbGoodsCart::getBuyUserId, id).eq(TbGoodsCart::getSaleGoodsInfoId,
+						goodsCartInfoDto.getSaleGoodsInfoId()).eq(TbGoodsCart::getDeleteStatus,
+						DeleteStatus.DELETE_STATUS_ON.getCode())).size();
+		if(size != 0)
+			throw new ServiceException("当前商品已存在您的购物车中,请勿重复添加");
 		//获取商品对象
 		Long infoId = goodsCartInfoDto.getSaleGoodsInfoId();
 		TbGoodsTransit tbGoodsTransit = tbGoodsTransitMapper.selectById(infoId);
@@ -90,9 +97,7 @@ public class TbGoodsCartService extends ServiceImpl<TbGoodsCartMapper, TbGoodsCa
 		//当前商品的单位
 		tbGoodsCart.setGoodsUnit(tbGoodsTransit.getGoodsUnits());
 		//商品价格
-		tbGoodsCart.setTotalPrice((goodsCartInfoDto.getBuyWeight() == null? tbGoodsCart.getBuyWeight() : goodsCartInfoDto.getBuyWeight())
-				*
-				(tbGoodsTransit.getPrice() == null? 0 : tbGoodsTransit.getPrice()));
+		tbGoodsCart.setTotalPrice(tbGoodsTransit.getPrice());
 		//设置基本属性
 		tbGoodsCart.setCreateTime(new Date());
 		tbGoodsCart.setDeleteStatus(DeleteStatus.DELETE_STATUS_ON.getCode());

+ 2 - 3
sp-service/level-one-server/src/main/java/com/pj/tb_goods_cart/dto/GoodsCartInfoDto.java

@@ -6,7 +6,6 @@ import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
-import javax.validation.constraints.DecimalMin;
 import javax.validation.constraints.NotNull;
 
 /**
@@ -50,7 +49,7 @@ public class GoodsCartInfoDto {
     /** 商品名称 */
     @NotNull(message = "商品名称必填")
     private String goodsName;
-    /** 购买个数 */
-    private Double buyWeight;
+//    /**  */
+//    private Double buyWeight;
 
 }