记得上下班打卡 | git大法好,push需谨慎

Commit d7799324 authored by zhengfuxin's avatar zhengfuxin

修改购物车问题

parent e12b3984
...@@ -32,7 +32,7 @@ public class GoblinFrontLoginController { ...@@ -32,7 +32,7 @@ public class GoblinFrontLoginController {
@ApiOperation("加入购物车") @ApiOperation("加入购物车")
public ResponseDto addShopCart(@RequestParam(name = "spuId", required = true) String spuId,@RequestParam(name = "storeId", required = true) String storeId,@RequestParam(name = "skuId", required = true) String skuId,@RequestParam(name = "number", required = false) Integer number,@RequestParam(name = "type", required = true) String type) { public ResponseDto addShopCart(@RequestParam(name = "spuId", required = true) String spuId,@RequestParam(name = "storeId", required = true) String storeId,@RequestParam(name = "skuId", required = true) String skuId,@RequestParam(name = "number", required = false) Integer number,@RequestParam(name = "type", required = true) String type) {
String userId=CurrentUtil.getCurrentUid(); String userId=CurrentUtil.getCurrentUid();
return ResponseDto.success( goblinFrontService.addShoopCart(spuId,storeId,skuId,number,userId,type)); return goblinFrontService.addShoopCart(spuId,storeId,skuId,number,userId,type);
} }
@GetMapping("updateShopCart") @GetMapping("updateShopCart")
@ApiOperation("修改购物车") @ApiOperation("修改购物车")
......
...@@ -3,6 +3,7 @@ package com.liquidnet.service.goblin.service.impl; ...@@ -3,6 +3,7 @@ package com.liquidnet.service.goblin.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.liquidnet.common.cache.redis.util.RedisUtil; import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.commons.lang.util.*; import com.liquidnet.commons.lang.util.*;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.base.SqlMapping; import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst; import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.constant.GoblinRedisConst; import com.liquidnet.service.goblin.constant.GoblinRedisConst;
...@@ -902,14 +903,34 @@ public class GoblinFrontServiceImpl implements GoblinFrontService { ...@@ -902,14 +903,34 @@ public class GoblinFrontServiceImpl implements GoblinFrontService {
return false; return false;
} }
} }
public boolean validateShoopCartNumber(String skuId,String type,Integer buyCount,String userId){
if(!type.equals("1")){
return true;
}
//获取sku
GoblinGoodsSkuInfoVo goblinGoodsSkuInfoVo=goblinRedisUtils.getGoodsSkuInfoVo(skuId);
if(null==goblinGoodsSkuInfoVo){
return false;
}
if(null==goblinGoodsSkuInfoVo.getBuyLimit()&&goblinGoodsSkuInfoVo.getBuyLimit()==0){
return true;
}
//已经购买的数量
Integer buyCounts=goblinRedisUtils.getSkuCountByUid(userId, skuId);
if(goblinGoodsSkuInfoVo.getBuyLimit()<(buyCounts+buyCount)){
//
return false;
}
return true;
}
/** /**
* @author zhangfuxin * @author zhangfuxin
* @Description:添加购物车 * @Description:添加购物车
* @date 2022/1/11 下午4:16 * @date 2022/1/11 下午4:16
*/ */
public boolean addShoopCart(String spuId, String storeId,String skuId,Integer number,String userId,String type){ public ResponseDto addShoopCart(String spuId, String storeId,String skuId,Integer number,String userId,String type){
if(null==number||number<=0){ if(null==number||number<=0){
return false; return ResponseDto.success(false);
} }
boolean isGoods=false; boolean isGoods=false;
String cardId=""; String cardId="";
...@@ -924,6 +945,9 @@ public class GoblinFrontServiceImpl implements GoblinFrontService { ...@@ -924,6 +945,9 @@ public class GoblinFrontServiceImpl implements GoblinFrontService {
goblinShoppingCartVo.setStoreId(storeId); goblinShoppingCartVo.setStoreId(storeId);
//该商铺下的所有商品 //该商铺下的所有商品
ArrayList<GoblinShoppingCartVoDetail> list1=ObjectUtil.goblinShoppingCartVoDetailArrayList(); ArrayList<GoblinShoppingCartVoDetail> list1=ObjectUtil.goblinShoppingCartVoDetailArrayList();
if(!validateShoopCartNumber(skuId,type,number,userId)){
return ResponseDto.failure("当前商品购买数量超过了限购数量");
}
//创建 购物车vo //创建 购物车vo
GoblinShoppingCartVoDetail goblinShoppingCartVoDetail=this.setValue(userId,storeId,spuId,skuId,number); GoblinShoppingCartVoDetail goblinShoppingCartVoDetail=this.setValue(userId,storeId,spuId,skuId,number);
list1.add(goblinShoppingCartVoDetail); list1.add(goblinShoppingCartVoDetail);
...@@ -946,6 +970,9 @@ public class GoblinFrontServiceImpl implements GoblinFrontService { ...@@ -946,6 +970,9 @@ public class GoblinFrontServiceImpl implements GoblinFrontService {
for(GoblinShoppingCartVoDetail goblinShoppingCartVoDetail:list1){ for(GoblinShoppingCartVoDetail goblinShoppingCartVoDetail:list1){
if(skuId.equals(goblinShoppingCartVoDetail.getSkuId())){ if(skuId.equals(goblinShoppingCartVoDetail.getSkuId())){
isGoods=true; isGoods=true;
if(!validateShoopCartNumber(skuId,type,(goblinShoppingCartVoDetail.getNumber()+number),userId)){
return ResponseDto.failure("当前商品购买数量超过了限购数量");
}
goblinShoppingCartVoDetail.setNumber((goblinShoppingCartVoDetail.getNumber()+number)); goblinShoppingCartVoDetail.setNumber((goblinShoppingCartVoDetail.getNumber()+number));
cardId=goblinShoppingCartVoDetail.getCarId(); cardId=goblinShoppingCartVoDetail.getCarId();
} }
...@@ -955,6 +982,9 @@ public class GoblinFrontServiceImpl implements GoblinFrontService { ...@@ -955,6 +982,9 @@ public class GoblinFrontServiceImpl implements GoblinFrontService {
//不需要做 //不需要做
}else{ }else{
//创建商品放入到list //创建商品放入到list
if(!validateShoopCartNumber(skuId,type,number,userId)){
return ResponseDto.failure("当前商品购买数量超过了限购数量");
}
GoblinShoppingCartVoDetail goblinShoppingCartVoDetail=this.setValue(userId,storeId,spuId,skuId,number); GoblinShoppingCartVoDetail goblinShoppingCartVoDetail=this.setValue(userId,storeId,spuId,skuId,number);
cardId=goblinShoppingCartVoDetail.getCarId(); cardId=goblinShoppingCartVoDetail.getCarId();
list1.add(goblinShoppingCartVoDetail); list1.add(goblinShoppingCartVoDetail);
...@@ -967,8 +997,11 @@ public class GoblinFrontServiceImpl implements GoblinFrontService { ...@@ -967,8 +997,11 @@ public class GoblinFrontServiceImpl implements GoblinFrontService {
goblinShoppingCartVo.setStoreId(storeId); goblinShoppingCartVo.setStoreId(storeId);
//该商铺下的所有商品 //该商铺下的所有商品
ArrayList<GoblinShoppingCartVoDetail> list1=ObjectUtil.goblinShoppingCartVoDetailArrayList(); ArrayList<GoblinShoppingCartVoDetail> list1=ObjectUtil.goblinShoppingCartVoDetailArrayList();
if(!validateShoopCartNumber(skuId,type,number,userId)){
return ResponseDto.failure("当前商品购买数量超过了限购数量");
}
//创建 购物车vo //创建 购物车vo
GoblinShoppingCartVoDetail goblinShoppingCartVoDetail=this.setValue(userId,storeId,spuId,skuId,1); GoblinShoppingCartVoDetail goblinShoppingCartVoDetail=this.setValue(userId,storeId,spuId,skuId,number);
list1.add(goblinShoppingCartVoDetail); list1.add(goblinShoppingCartVoDetail);
goblinShoppingCartVo.setSkuList(list1); goblinShoppingCartVo.setSkuList(list1);
list.add(goblinShoppingCartVo); list.add(goblinShoppingCartVo);
...@@ -980,7 +1013,7 @@ public class GoblinFrontServiceImpl implements GoblinFrontService { ...@@ -980,7 +1013,7 @@ public class GoblinFrontServiceImpl implements GoblinFrontService {
insertShopCartMysql(cardId,spuId,storeId,skuId,number,userId,type); insertShopCartMysql(cardId,spuId,storeId,skuId,number,userId,type);
} }
} }
return true; return ResponseDto.success(true);
} }
/*** /***
* @author zhangfuxin * @author zhangfuxin
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment