购物车商品数量修改接口开发
This commit is contained in:
parent
bfa1377737
commit
9ea03fdf60
@ -41,6 +41,14 @@ public class CartController {
|
|||||||
return JsonData.buildSuccess();
|
return JsonData.buildSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation("添加到购物车")
|
||||||
|
@PostMapping("/change")
|
||||||
|
public JsonData changeItemNum(@ApiParam("购物项") @RequestBody CartItemRequest cartItemRequest) {
|
||||||
|
cartService.changeItemNum(cartItemRequest);
|
||||||
|
return JsonData.buildSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation("清空购物车")
|
@ApiOperation("清空购物车")
|
||||||
@DeleteMapping("/clear")
|
@DeleteMapping("/clear")
|
||||||
@ -55,4 +63,11 @@ public class CartController {
|
|||||||
CartVO cartVO = cartService.getMyCart();
|
CartVO cartVO = cartService.getMyCart();
|
||||||
return JsonData.buildSuccess(cartVO);
|
return JsonData.buildSuccess(cartVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation("删除购物项")
|
||||||
|
@DeleteMapping("/delete/{product_id}")
|
||||||
|
public JsonData deleteItem(@ApiParam(value = "商品id", required = true) @PathVariable("product_id") long productId) {
|
||||||
|
cartService.deleteItem(productId);
|
||||||
|
return JsonData.buildSuccess();
|
||||||
|
}
|
||||||
}
|
}
|
@ -22,4 +22,18 @@ public interface CartService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
CartVO getMyCart();
|
CartVO getMyCart();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除购物项
|
||||||
|
*
|
||||||
|
* @param productId
|
||||||
|
*/
|
||||||
|
void deleteItem(long productId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改购物车商品数量
|
||||||
|
*
|
||||||
|
* @param cartItemRequest
|
||||||
|
*/
|
||||||
|
void changeItemNum(CartItemRequest cartItemRequest);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import net.jieyuu.enums.BizCodeEnum;
|
|||||||
import net.jieyuu.exception.BizException;
|
import net.jieyuu.exception.BizException;
|
||||||
import net.jieyuu.interceptor.LoginInterceptor;
|
import net.jieyuu.interceptor.LoginInterceptor;
|
||||||
import net.jieyuu.model.LoginUser;
|
import net.jieyuu.model.LoginUser;
|
||||||
import net.jieyuu.model.ProductDO;
|
|
||||||
import net.jieyuu.request.CartItemRequest;
|
import net.jieyuu.request.CartItemRequest;
|
||||||
import net.jieyuu.service.CartService;
|
import net.jieyuu.service.CartService;
|
||||||
import net.jieyuu.service.ProductService;
|
import net.jieyuu.service.ProductService;
|
||||||
@ -95,6 +94,32 @@ public class CartServiceImpl implements CartService {
|
|||||||
return cartVO;
|
return cartVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteItem(long productId) {
|
||||||
|
|
||||||
|
BoundHashOperations<String, Object, Object> myCartOps = getMyCartOps();
|
||||||
|
myCartOps.delete(productId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改商品数量
|
||||||
|
*
|
||||||
|
* @param cartItemRequest
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void changeItemNum(CartItemRequest cartItemRequest) {
|
||||||
|
BoundHashOperations<String, Object, Object> myCartOps = getMyCartOps();
|
||||||
|
Object cartObj = myCartOps.get(cartItemRequest.getProductId());
|
||||||
|
if (cartObj == null || cartItemRequest.getBuyNum() <= 0) {
|
||||||
|
throw new BizException(BizCodeEnum.CART_FILE);
|
||||||
|
}
|
||||||
|
String obj = (String) cartObj;
|
||||||
|
|
||||||
|
CartItemVO cartItemVO = JSON.parseObject(obj, CartItemVO.class);
|
||||||
|
cartItemVO.setBuyNum(cartItemVO.getBuyNum());
|
||||||
|
myCartOps.put(cartItemRequest.getProductId(), JSON.toJSONString(cartItemVO));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取最新购物项
|
* 获取最新购物项
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user