|
|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|