清空购物车业务代码开发

This commit is contained in:
zvv
2026-04-02 17:16:51 +08:00
parent 689ce56914
commit 209934c668
4 changed files with 38 additions and 0 deletions

View File

@@ -44,4 +44,16 @@ public class ShoppingCartController {
List<ShoppingCart> list = shoppingCartService.showShoppingCart(); List<ShoppingCart> list = shoppingCartService.showShoppingCart();
return Result.success(list); return Result.success(list);
} }
/**
* 清空购物车
* @return
*/
@DeleteMapping("/clean")
@ApiOperation("清空购物车")
public Result clean(){
shoppingCartService.cleanShoppingCart();
return Result.success();
}
} }

View File

@@ -3,6 +3,7 @@ package com.sky.mapper;
import com.sky.dto.ShoppingCartDTO; import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart; import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update; import org.apache.ibatis.annotations.Update;
@@ -33,4 +34,12 @@ public interface ShoppingCartMapper {
+ +
"values (#{name}, #{image}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor}, #{amount}, #{createTime}, #{number})") "values (#{name}, #{image}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor}, #{amount}, #{createTime}, #{number})")
void insert(ShoppingCart shoppingCart); void insert(ShoppingCart shoppingCart);
/**
* 根据微信用户id删除购物车数据
* @param userId
*/
@Delete("delete from shopping_cart where user_id = #{userId}")
void deleteByUserId(Long userId);
} }

View File

@@ -21,4 +21,10 @@ public interface ShoppingCartService {
* @return * @return
*/ */
List<ShoppingCart> showShoppingCart(); List<ShoppingCart> showShoppingCart();
/**
* 清空购物车
*/
void cleanShoppingCart();
} }

View File

@@ -96,4 +96,15 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
List<ShoppingCart> list = shoppingCartMapper.list(shoppingCart); List<ShoppingCart> list = shoppingCartMapper.list(shoppingCart);
return list; return list;
} }
/**
* 清空购物车
*/
@Override
public void cleanShoppingCart() {
//获取当前微信用户的id
Long userId = BaseContext.getCurrentId();
shoppingCartMapper.deleteByUserId(userId);
}
} }