|
|
@@ -192,9 +192,20 @@ public class MyProductController {
|
|
|
* */
|
|
|
@PostMapping("/addProductShoppingCart")
|
|
|
public R addProductShoppingCart(@RequestBody ProductShoppingCartBo bo) {
|
|
|
-
|
|
|
- bo.setUserId(LoginHelper.getUserId());
|
|
|
- productShoppingCartService.insertByBo(bo);
|
|
|
+ Long userId = LoginHelper.getUserId();
|
|
|
+ //查看是否存在同一个商品
|
|
|
+ ProductShoppingCart one = productShoppingCartService.getOne(Wrappers.lambdaQuery(ProductShoppingCart.class)
|
|
|
+ .eq(ProductShoppingCart::getUserId, userId)
|
|
|
+ .eq(ProductShoppingCart::getProductId, bo.getProductId())
|
|
|
+ );
|
|
|
+ if(one != null){
|
|
|
+ one.setProductNum(one.getProductNum() + bo.getProductNum());
|
|
|
+ productShoppingCartService.updateById(one);
|
|
|
+ return R.ok();
|
|
|
+ }else {
|
|
|
+ bo.setUserId(userId);
|
|
|
+ productShoppingCartService.insertByBo(bo);
|
|
|
+ }
|
|
|
return R.ok();
|
|
|
}
|
|
|
|