进店即会员 取消

长链接 异常打印
This commit is contained in:
wangw 2024-05-31 10:18:40 +08:00
parent c403b69102
commit c81a2106d0
5 changed files with 104 additions and 92 deletions

View File

@ -90,7 +90,7 @@ public class UserContoller {
shopUser.setCode(dynamicCode);
shopUser.setTelephone(tbUserInfo.getTelephone());
shopUser.setAmount(BigDecimal.ZERO);
shopUser.setIsVip(Byte.parseByte("1"));
shopUser.setIsVip(Byte.parseByte("0"));
shopUser.setCreditAmount(BigDecimal.ZERO);
shopUser.setConsumeAmount(BigDecimal.ZERO);
shopUser.setConsumeNumber(0);

View File

@ -44,6 +44,13 @@ public class CartConsumer {
} else if(jsonObject.getString("type").equals("createOrder")){
String cartDetail = redisUtil.getMessage(RedisCst.TABLE_CART.concat(tableId).concat("-").concat(shopId));
if (StringUtils.isEmpty(cartDetail)){
log.info("createOrder购物车为空");
// JSONObject jsonObject1 = new JSONObject();
// jsonObject1.put("status", "success");
// jsonObject1.put("msg", "订单已存在");
// jsonObject1.put("type", jsonObject.getString("type"));
// jsonObject1.put("data", "{\"id\": \"-1\"}");
// AppWebSocketServer.AppSendInfo(jsonObject1,tableId+"-"+shopId, jsonObject.getString("userId"), true);
throw new MsgException("购物车为空无法下单");
}
JSONArray array = JSON.parseArray(cartDetail);

View File

@ -53,7 +53,7 @@ public class CartService {
private TbSystemCouponsMapper systemCouponsMapper;
// @Transactional(rollbackFor = Exception.class)
public void createCart(JSONObject jsonObject) throws Exception {
public void createCart(JSONObject jsonObject) {
try {
String tableId = jsonObject.getString("tableId");
String shopId = jsonObject.getString("shopId");
@ -144,55 +144,60 @@ public class CartService {
jsonObject1.put("amount", amount);
AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("tableId").concat("-").concat(shopId),"", false);
} catch (Exception e) {
e.getMessage();
log.info("长链接错误 createCart{}",e.getMessage());
}
}
private TbCashierCart addCart(String productId, String skuId, Integer userId, Integer num, String tableId, String shopId) throws Exception {
TbProduct product = productMapper.selectById(Integer.valueOf(productId));
String key=tableId+"-"+shopId;
if (Objects.isNull(product)) {
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "fail");
jsonObject1.put("msg", "该商品不存在");
jsonObject1.put("data", new ArrayList<>());
AppWebSocketServer.AppSendInfo(jsonObject1,key, userId.toString(), true);
throw new MsgException("该商品不存在");
try {
TbProduct product = productMapper.selectById(Integer.valueOf(productId));
String key=tableId+"-"+shopId;
if (Objects.isNull(product)) {
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "fail");
jsonObject1.put("msg", "该商品不存在");
jsonObject1.put("data", new ArrayList<>());
AppWebSocketServer.AppSendInfo(jsonObject1,key, userId.toString(), true);
throw new MsgException("该商品不存在");
}
TbProductSkuWithBLOBs productSku = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId));
if (Objects.isNull(productSku)) {
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "fail");
jsonObject1.put("msg", "该商品规格不存在");
jsonObject1.put("data", new ArrayList<>());
AppWebSocketServer.AppSendInfo(jsonObject1,key, userId.toString(), true);
throw new MsgException("该商品规格不存在");
}
TbCashierCart cashierCart = new TbCashierCart();
cashierCart.setProductId(productId);
cashierCart.setSkuId(skuId);
cashierCart.setNumber(num);
cashierCart.setCoverImg(product.getCoverImg());
cashierCart.setName(product.getName());
cashierCart.setCategoryId(product.getCategoryId());
cashierCart.setShopId(shopId);
cashierCart.setUserId(userId);
cashierCart.setTableId(tableId);
cashierCart.setSkuName(productSku.getSpecSnap());
cashierCart.setIsPack("false");
cashierCart.setIsGift("false");
cashierCart.setUserId(userId);
cashierCart.setStatus("create");
cashierCart.setType((byte) 0);
cashierCart.setSalePrice(productSku.getSalePrice());
cashierCart.setCreatedAt(Instant.now().toEpochMilli());
cashierCart.setUpdatedAt(Instant.now().toEpochMilli());
cashierCart.setTotalNumber(num);
cashierCart.setPackFee(BigDecimal.ZERO);
cashierCart.setRefundNumber(0);
cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(productSku.getSalePrice().add(cashierCart.getPackFee())));
cashierCartMapper.insert(cashierCart);
return cashierCart;
}catch (Exception e){
log.info("长链接错误 addCart{}",e.getMessage());
throw e;
}
TbProductSkuWithBLOBs productSku = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId));
if (Objects.isNull(productSku)) {
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "fail");
jsonObject1.put("msg", "该商品规格不存在");
jsonObject1.put("data", new ArrayList<>());
AppWebSocketServer.AppSendInfo(jsonObject1,key, userId.toString(), true);
throw new MsgException("该商品规格不存在");
}
TbCashierCart cashierCart = new TbCashierCart();
cashierCart.setProductId(productId);
cashierCart.setSkuId(skuId);
cashierCart.setNumber(num);
cashierCart.setCoverImg(product.getCoverImg());
cashierCart.setName(product.getName());
cashierCart.setCategoryId(product.getCategoryId());
cashierCart.setShopId(shopId);
cashierCart.setUserId(userId);
cashierCart.setTableId(tableId);
cashierCart.setSkuName(productSku.getSpecSnap());
cashierCart.setIsPack("false");
cashierCart.setIsGift("false");
cashierCart.setUserId(userId);
cashierCart.setStatus("create");
cashierCart.setType((byte) 0);
cashierCart.setSalePrice(productSku.getSalePrice());
cashierCart.setCreatedAt(Instant.now().toEpochMilli());
cashierCart.setUpdatedAt(Instant.now().toEpochMilli());
cashierCart.setTotalNumber(num);
cashierCart.setPackFee(BigDecimal.ZERO);
cashierCart.setRefundNumber(0);
cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(productSku.getSalePrice().add(cashierCart.getPackFee())));
cashierCartMapper.insert(cashierCart);
return cashierCart;
}
@Transactional(rollbackFor = Exception.class)
@ -411,6 +416,7 @@ public class CartService {
jsonObject12.put("data", new JSONArray());
AppWebSocketServer.AppSendInfo(jsonObject12, jsonObject.getString("tableId").concat("-").concat(shopId),"", false);
} catch (Exception e) {
log.info("长链接错误 addCart{}",e.getMessage());
e.printStackTrace();
}
}
@ -453,28 +459,33 @@ public class CartService {
return "WX" + date + randomNum;
}
public void clearCart(JSONObject jsonObject) throws IOException {
String shopId = jsonObject.getString("shopId");
if (redisUtil.exists(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))) {
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId))));
if (Objects.isNull(array) || array.isEmpty() || array.size() < 1) {
for (int i = 0; i < array.size(); i++) {
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(array.get(i).toString(), TbCashierCart.class);
public void clearCart(JSONObject jsonObject){
try{
String shopId = jsonObject.getString("shopId");
if (redisUtil.exists(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))) {
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId))));
if (Objects.isNull(array) || array.isEmpty() || array.size() < 1) {
for (int i = 0; i < array.size(); i++) {
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(array.get(i).toString(), TbCashierCart.class);
// String result = redisUtil.secAdd(RedisCst.PRODUCT+shopId+":"+jsonObject.getString("skuId"),cashierCart.getNumber().toString());
productSkuMapper.updateAddStockById(jsonObject.getString("skuId"), cashierCart.getNumber());
productSkuMapper.updateAddStockById(jsonObject.getString("skuId"), cashierCart.getNumber());
}
}
}
cashierCartMapper.updateStatusByTableId(jsonObject.getString("tableId"), "closed");
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)), new JSONArray().toJSONString());
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "success");
jsonObject1.put("msg", "成功");
jsonObject1.put("type", "clearCart");
jsonObject1.put("amount", BigDecimal.ZERO);
jsonObject1.put("data", new ArrayList<>());
AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("tableId").concat("-").concat(shopId),"", false);
}catch (Exception e){
log.info("长链接错误 clearCart{}",e.getMessage());
e.printStackTrace();
}
cashierCartMapper.updateStatusByTableId(jsonObject.getString("tableId"), "closed");
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)), new JSONArray().toJSONString());
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "success");
jsonObject1.put("msg", "成功");
jsonObject1.put("type", "clearCart");
jsonObject1.put("amount", BigDecimal.ZERO);
jsonObject1.put("data", new ArrayList<>());
AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("tableId").concat("-").concat(shopId),"", false);
}
@Transactional(rollbackFor = Exception.class)
@ -694,25 +705,31 @@ public class CartService {
jsonObject12.put("data", new JSONArray());
AppWebSocketServer.AppSendInfo(jsonObject12, jsonObject.getString("tableId").concat("-").concat(shopId),"", false);
} catch (Exception e) {
e.getMessage();
log.info("长链接错误 pendingOrder{}",e.getMessage());
e.printStackTrace();
}
}
public void queryCart(JSONObject jsonObject) throws IOException {
String shopId = jsonObject.getString("shopId");
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId))));
BigDecimal amount = BigDecimal.ZERO;
for (int i = 0; i < array.size(); i++) {
JSONObject object = array.getJSONObject(i);
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
public void queryCart(JSONObject jsonObject) {
try {
String shopId = jsonObject.getString("shopId");
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId))));
BigDecimal amount = BigDecimal.ZERO;
for (int i = 0; i < array.size(); i++) {
JSONObject object = array.getJSONObject(i);
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
}
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "success");
jsonObject1.put("msg", "成功");
jsonObject1.put("type", jsonObject.getString("type"));
jsonObject1.put("data", array);
jsonObject1.put("amount", amount);
AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("tableId").concat("-").concat(shopId),"", false);
}catch (Exception e){
log.info("长链接错误 queryCart{}",e.getMessage());
e.printStackTrace();
}
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "success");
jsonObject1.put("msg", "成功");
jsonObject1.put("type", jsonObject.getString("type"));
jsonObject1.put("data", array);
jsonObject1.put("amount", amount);
AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("tableId").concat("-").concat(shopId),"", false);
}
}

View File

@ -90,12 +90,6 @@ public class LoginService {
List<TbShopUser> tbShopUsers = tbShopUserMapper.selectByPhone(telephone);
if(CollectionUtils.isEmpty(tbShopUsers)){
for (TbShopUser tbShopUser : tbShopUsers) {
userInfo.setNickName(tbShopUser.getName());
userInfo.setSex(tbShopUser.getSex());
userInfo.setBirthDay(tbShopUser.getBirthDay());
tbShopUser.setLevel(Byte.parseByte("1"));
String dynamicCode = RandomUtil.randomNumbers(8);
tbShopUser.setCode(dynamicCode);
tbShopUser.setUserId(userInfo.getId() + "");
tbShopUserMapper.updateByPrimaryKey(tbShopUser);
}
@ -185,12 +179,6 @@ public class LoginService {
}
List<TbShopUser> tbShopUsers = tbShopUserMapper.selectByPhone(phone);
for (TbShopUser tbShopUser : tbShopUsers) {
userInfo.setNickName(tbShopUser.getName());
userInfo.setSex(tbShopUser.getSex());
userInfo.setBirthDay(tbShopUser.getBirthDay());
tbShopUser.setLevel(Byte.parseByte("1"));
String dynamicCode = RandomUtil.randomNumbers(8);
tbShopUser.setCode(dynamicCode);
tbShopUser.setUserId(userInfo.getId() + "");
tbShopUserMapper.updateByPrimaryKey(tbShopUser);
}

View File

@ -85,7 +85,7 @@ public class ProductService {
tbShopUser.setCode(RandomUtil.randomNumbers(8));
tbShopUser.setTelephone(tbUserInfo.getTelephone());
tbShopUser.setAmount(BigDecimal.ZERO);
tbShopUser.setIsVip(Byte.parseByte("1"));
tbShopUser.setIsVip(Byte.parseByte("0"));
tbShopUser.setCreditAmount(BigDecimal.ZERO);
tbShopUser.setConsumeAmount(BigDecimal.ZERO);
tbShopUser.setConsumeNumber(0);