|
@@ -162,26 +162,27 @@ public class CartHandlers {
|
|
|
*/
|
|
|
@ResponseBody
|
|
|
@RequestMapping("/addProductToCart")
|
|
|
- public ResultMsg addProductToCart(@RequestParam("productId") String productId,
|
|
|
- @RequestParam(value = "cartNum", required = false, defaultValue = "1") Integer cartNum,
|
|
|
+ public ResultMsg addProductToCart(@RequestParam("productId") String productId,
|
|
|
+ @RequestParam("productColorId") String productColorId,
|
|
|
+ @RequestParam(value = "cartNum", required = false, defaultValue = "1") Integer cartNum,
|
|
|
HttpServletRequest request) throws Exception {
|
|
|
String openId = wechatUtils.getUserBySession(request).getUserOpenid();
|
|
|
CartDto cartDto = new CartDto();
|
|
|
ResultMsg remsg=new ResultMsg();
|
|
|
|
|
|
- Integer pid = 0;
|
|
|
- if (productId != null && !"".equals(productId) && !"null".equals(productId) && StaticInfo.pattern.matcher(productId).find()) {
|
|
|
- pid = Integer.parseInt(productId);
|
|
|
+ Integer cid = 0;
|
|
|
+ if (productColorId != null && !"".equals(productColorId) && !"null".equals(productColorId) && StaticInfo.pattern.matcher(productColorId).find()) {
|
|
|
+ cid = Integer.parseInt(productColorId);
|
|
|
} else {
|
|
|
- if (productId == null || "".equals(productId)) {
|
|
|
+ if (productColorId == null || "".equals(productColorId)) {
|
|
|
remsg.setMessage(ResultInfo.ERRORINFO);
|
|
|
remsg.setResultCode(ResultInfo.ERRORCODE);
|
|
|
remsg.setStatus(false);
|
|
|
return remsg;
|
|
|
}
|
|
|
try {
|
|
|
- String productIdString = StaticInfo.md5.decrypt(productId);
|
|
|
- pid = Integer.parseInt(productIdString);
|
|
|
+ String productIdString = StaticInfo.md5.decrypt(productColorId);
|
|
|
+ cid = Integer.parseInt(productIdString);
|
|
|
} catch (Exception e) {
|
|
|
remsg.setMessage(ResultInfo.ERRORINFO);
|
|
|
remsg.setResultCode(ResultInfo.ERRORCODE);
|
|
@@ -192,8 +193,8 @@ public class CartHandlers {
|
|
|
}
|
|
|
|
|
|
cartDto.setCartOpenId(openId);
|
|
|
- cartDto.setCartProductId(pid);
|
|
|
- //根据用户id和商品id查询购物车中是否存在
|
|
|
+ cartDto.setCartColorId(cid);
|
|
|
+ //根据颜色id和商品id查询购物车中是否存在
|
|
|
CartDto cart = cartService.getCartByCartProductId(cartDto);
|
|
|
if (null != cart) {
|
|
|
cartDto.setCartNum(cartNum + cart.getCartNum());
|
|
@@ -238,12 +239,22 @@ public class CartHandlers {
|
|
|
@ResponseBody
|
|
|
@RequestMapping(value = "/addCart",method = RequestMethod.GET)
|
|
|
public ResultMsg addCart(HttpServletRequest request,@RequestParam("productId") Integer productId,
|
|
|
+ @RequestParam("productColorId") String productColorId,
|
|
|
@RequestParam(value = "cartNum", required = false, defaultValue = "1") Integer cartNum) throws Exception {
|
|
|
String openId = wechatUtils.getUserBySession(request).getUserOpenid();
|
|
|
ResultMsg remsg=new ResultMsg();
|
|
|
+ Integer cid = 0;
|
|
|
+ if (productColorId != null && !"".equals(productColorId) && !"null".equals(productColorId) && StaticInfo.pattern.matcher(productColorId).find()) {
|
|
|
+ cid = Integer.parseInt(productColorId);
|
|
|
+ }else{
|
|
|
+ remsg.setMessage(ResultInfo.ERRORINFO);
|
|
|
+ remsg.setResultCode(ResultInfo.ERRORCODE);
|
|
|
+ remsg.setStatus(false);
|
|
|
+ return remsg;
|
|
|
+ }
|
|
|
CartDto cartDto = new CartDto();
|
|
|
cartDto.setCartOpenId(openId);
|
|
|
- cartDto.setCartProductId(productId);
|
|
|
+ cartDto.setCartColorId(cid);
|
|
|
Integer productNum = cartService.getCartNumByOpenId(cartDto);
|
|
|
cartDto.setCartNum(productNum + cartNum);
|
|
|
Integer num = cartService.updateCartByOpenId(cartDto);
|
|
@@ -262,27 +273,27 @@ public class CartHandlers {
|
|
|
/**
|
|
|
* 点击减号按钮删除商品
|
|
|
* @param request
|
|
|
- * @param productId
|
|
|
+ * @param productColorId
|
|
|
* @param cartNum
|
|
|
* @return ResultMsg
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@ResponseBody
|
|
|
@RequestMapping(value = "/deleteCart",method = RequestMethod.GET)
|
|
|
- public ResultMsg deleteCart(HttpServletRequest request,@RequestParam("productId") Integer productId,
|
|
|
+ public ResultMsg deleteCart(HttpServletRequest request,@RequestParam("productColorId") Integer productColorId,
|
|
|
@RequestParam(value = "cartNum", required = false, defaultValue = "1") Integer cartNum) throws Exception {
|
|
|
String openId = wechatUtils.getUserBySession(request).getUserOpenid();
|
|
|
ResultMsg remsg=new ResultMsg();
|
|
|
CartDto cartDto = new CartDto();
|
|
|
cartDto.setCartOpenId(openId);
|
|
|
- cartDto.setCartProductId(productId);
|
|
|
+ cartDto.setCartColorId(productColorId);
|
|
|
Integer productNum = cartService.getCartNumByOpenId(cartDto);
|
|
|
Integer num = 0;
|
|
|
if (productNum > 1) {
|
|
|
cartDto.setCartNum(productNum - cartNum);
|
|
|
num = cartService.updateCartByOpenId(cartDto);
|
|
|
} else {
|
|
|
- this.deleteCartByProductId(request,productId);
|
|
|
+ this.deleteCartByProductId(request,productColorId);
|
|
|
}
|
|
|
if (num > 0) {
|
|
|
remsg.setMessage(ResultInfo.SUCCESSINFO);
|
|
@@ -299,17 +310,16 @@ public class CartHandlers {
|
|
|
/**
|
|
|
* 点击垃圾桶按钮删除购物车物品信息
|
|
|
* @param request
|
|
|
- * @param cartId
|
|
|
* @return ResultMsg
|
|
|
*/
|
|
|
@ResponseBody
|
|
|
@RequestMapping(value = "/deleteCartByProductId",method = RequestMethod.GET)
|
|
|
- public ResultMsg deleteCartByProductId(HttpServletRequest request,@RequestParam("productId") Integer productId) throws Exception{
|
|
|
+ public ResultMsg deleteCartByProductId(HttpServletRequest request,@RequestParam("productColorId") Integer productColorId) throws Exception{
|
|
|
String openId = wechatUtils.getUserBySession(request).getUserOpenid();
|
|
|
CartDto cartDto = new CartDto();
|
|
|
ResultMsg remsg=new ResultMsg();
|
|
|
cartDto.setCartOpenId(openId);
|
|
|
- cartDto.setCartProductId(productId);
|
|
|
+ cartDto.setCartColorId(productColorId);
|
|
|
if (cartService.deleteCartByCartId(cartDto) >= 1) {
|
|
|
remsg.setMessage(ResultInfo.SUCCESSINFO);
|
|
|
remsg.setResultCode(ResultInfo.SUCCESSCODE);
|