清空购物车业务代码开发
This commit is contained in:
@@ -44,4 +44,16 @@ public class ShoppingCartController {
|
||||
List<ShoppingCart> list = shoppingCartService.showShoppingCart();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 清空购物车
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping("/clean")
|
||||
@ApiOperation("清空购物车")
|
||||
public Result clean(){
|
||||
shoppingCartService.cleanShoppingCart();
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.sky.mapper;
|
||||
|
||||
import com.sky.dto.ShoppingCartDTO;
|
||||
import com.sky.entity.ShoppingCart;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
@@ -33,4 +34,12 @@ public interface ShoppingCartMapper {
|
||||
+
|
||||
"values (#{name}, #{image}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor}, #{amount}, #{createTime}, #{number})")
|
||||
void insert(ShoppingCart shoppingCart);
|
||||
|
||||
|
||||
/**
|
||||
* 根据微信用户id删除购物车数据
|
||||
* @param userId
|
||||
*/
|
||||
@Delete("delete from shopping_cart where user_id = #{userId}")
|
||||
void deleteByUserId(Long userId);
|
||||
}
|
||||
|
||||
@@ -21,4 +21,10 @@ public interface ShoppingCartService {
|
||||
* @return
|
||||
*/
|
||||
List<ShoppingCart> showShoppingCart();
|
||||
|
||||
|
||||
/**
|
||||
* 清空购物车
|
||||
*/
|
||||
void cleanShoppingCart();
|
||||
}
|
||||
|
||||
@@ -96,4 +96,15 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
|
||||
List<ShoppingCart> list = shoppingCartMapper.list(shoppingCart);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 清空购物车
|
||||
*/
|
||||
@Override
|
||||
public void cleanShoppingCart() {
|
||||
//获取当前微信用户的id
|
||||
Long userId = BaseContext.getCurrentId();
|
||||
shoppingCartMapper.deleteByUserId(userId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user