修改ws上下文对应的key规则,修改无tableId购物车缓存策略
This commit is contained in:
@@ -121,6 +121,9 @@ public class TbOrderInfo implements Serializable {
|
||||
// 下单次数
|
||||
private Integer placeNum;
|
||||
|
||||
private Integer seatCount;
|
||||
private BigDecimal seatAmount;
|
||||
|
||||
|
||||
//根据状态返回 需付款 已付款 未付款 已退
|
||||
@TableField(exist = false)
|
||||
|
||||
@@ -15,4 +15,6 @@ public class ChoseCountDTO {
|
||||
@NotNull
|
||||
@Min(1)
|
||||
private Integer num;
|
||||
@NotNull
|
||||
private String userId;
|
||||
}
|
||||
|
||||
@@ -88,13 +88,14 @@ public class PushToAppChannelHandlerAdapter extends NettyChannelHandlerAdapter {
|
||||
// 遍历webSocketMap,查找并移除对应的ChannelHandlerContext
|
||||
String key = ctxToUserIdMap.get(ctx);
|
||||
if (StringUtils.isNotBlank(key)) {
|
||||
String[] split = key.split(":");
|
||||
String[] split = key.split("-");
|
||||
ConcurrentHashMap<String, ChannelHandlerContext> tableMap = webSocketMap.get(split[0]);
|
||||
if (tableMap != null && !tableMap.isEmpty() && tableMap.size() > 0) {
|
||||
tableMap.remove(split[1]);
|
||||
if (tableMap.isEmpty() || tableMap.size() == 0) {
|
||||
webSocketMap.remove(split[0]);
|
||||
redisUtils.deleteByKey(RedisCst.TABLE_CART.concat(split[0]));
|
||||
// 删除购物车缓存
|
||||
redisUtils.deleteByKey(split[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,12 +134,13 @@ public class PushToAppChannelHandlerAdapter extends NettyChannelHandlerAdapter {
|
||||
channelInactive(ctx);
|
||||
return;
|
||||
}
|
||||
String key = tableId + "-" + shopId;
|
||||
|
||||
String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, Integer.valueOf(userId));
|
||||
log.info("netty连接 接收到数据 建立连接参数 param:{}",jsonObject);
|
||||
this.tableId=tableId;
|
||||
this.shopId=shopId;
|
||||
if (webSocketMap.containsKey(key)) {
|
||||
ConcurrentHashMap<String, ChannelHandlerContext> userSocketMap = webSocketMap.get(key);
|
||||
if (webSocketMap.containsKey(tableCartKey)) {
|
||||
ConcurrentHashMap<String, ChannelHandlerContext> userSocketMap = webSocketMap.get(tableCartKey);
|
||||
ChannelHandlerContext channelHandlerContext = userSocketMap.get(userId);
|
||||
if (channelHandlerContext != null) {
|
||||
channelHandlerContext.close();
|
||||
@@ -147,9 +149,9 @@ public class PushToAppChannelHandlerAdapter extends NettyChannelHandlerAdapter {
|
||||
} else {
|
||||
ConcurrentHashMap<String, ChannelHandlerContext> userSocketMap = new ConcurrentHashMap<>();
|
||||
userSocketMap.put(userId, ctx);
|
||||
webSocketMap.put(key,userSocketMap);
|
||||
webSocketMap.put(tableCartKey,userSocketMap);
|
||||
}
|
||||
ctxToUserIdMap.put(ctx, key + ":" + userId);
|
||||
ctxToUserIdMap.put(ctx, tableCartKey + "-" + userId);
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "success");
|
||||
jsonObject1.put("msg", "连接成功");
|
||||
@@ -163,11 +165,13 @@ public class PushToAppChannelHandlerAdapter extends NettyChannelHandlerAdapter {
|
||||
log.info("netty连接 接收到接口数据:meg:{}",msg);
|
||||
jsonObject.put("tableId", this.tableId);
|
||||
jsonObject.put("shopId", this.shopId);
|
||||
Integer userId = jsonObject.getInteger("userId");
|
||||
if("sku".equals(type)){
|
||||
boolean exist = redisUtils.exists(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)));
|
||||
String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, userId);
|
||||
boolean exist = redisUtils.exists(tableCartKey);
|
||||
Integer num = 0;
|
||||
if (exist){
|
||||
String message = redisUtils.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)));
|
||||
String message = redisUtils.getMessage(tableCartKey);
|
||||
JSONArray array = JSON.parseArray(message);
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject object = array.getJSONObject(i);
|
||||
@@ -226,11 +230,11 @@ public class PushToAppChannelHandlerAdapter extends NettyChannelHandlerAdapter {
|
||||
}
|
||||
|
||||
@Async
|
||||
public void AppSendInfo(String message, String tableId,String userId, boolean userFlag) {
|
||||
log.info("netty连接 发送消息 tableId:{} userId:{} userFlag:{} message:{}",tableId,userId,userFlag, JSONUtil.toJSONString(message));
|
||||
public void AppSendInfo(String message, String redisKey,String userId, boolean userFlag) {
|
||||
log.info("netty连接 发送消息 tableId:{} userId:{} userFlag:{} message:{}",redisKey,userId,userFlag, JSONUtil.toJSONString(message));
|
||||
if (userFlag) {
|
||||
if (webSocketMap.containsKey(tableId)) {
|
||||
ConcurrentHashMap<String, ChannelHandlerContext> webSockets = webSocketMap.get(tableId);
|
||||
if (webSocketMap.containsKey(redisKey)) {
|
||||
ConcurrentHashMap<String, ChannelHandlerContext> webSockets = webSocketMap.get(redisKey);
|
||||
if(!webSockets.isEmpty()){
|
||||
if (StringUtils.isNotBlank(userId)) {
|
||||
ChannelHandlerContext ctx = webSockets.get(userId);
|
||||
@@ -241,15 +245,15 @@ public class PushToAppChannelHandlerAdapter extends NettyChannelHandlerAdapter {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (StringUtils.isEmpty(tableId)) {
|
||||
if (StringUtils.isEmpty(redisKey)) {
|
||||
// 向所有用户发送信息
|
||||
for (ConcurrentHashMap<String, ChannelHandlerContext> value : webSocketMap.values()) {
|
||||
for (ChannelHandlerContext ctx : value.values()) {
|
||||
sendMesToApp(message,ctx);
|
||||
}
|
||||
}
|
||||
} else if (webSocketMap.containsKey(tableId)) {
|
||||
ConcurrentHashMap<String, ChannelHandlerContext> webSockets = webSocketMap.get(tableId);
|
||||
} else if (webSocketMap.containsKey(redisKey)) {
|
||||
ConcurrentHashMap<String, ChannelHandlerContext> webSockets = webSocketMap.get(redisKey);
|
||||
if(!webSockets.isEmpty()) {
|
||||
for (String user : webSockets.keySet()) {
|
||||
ChannelHandlerContext ctx = webSockets.get(user);
|
||||
@@ -261,10 +265,10 @@ public class PushToAppChannelHandlerAdapter extends NettyChannelHandlerAdapter {
|
||||
}
|
||||
}
|
||||
}else {
|
||||
log.info("netty连接 发送消息 桌码群发 tableId:{} 失败",tableId);
|
||||
log.info("netty连接 发送消息 桌码群发 tableId:{} 失败",redisKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ public class CartConsumer {
|
||||
JSONObject jsonObject = JSON.parseObject(message);
|
||||
String tableId = jsonObject.getString("tableId");
|
||||
String shopId = jsonObject.getString("shopId");
|
||||
Integer userId = jsonObject.getInteger("userId");
|
||||
if (jsonObject.getString("type").equals("initCart") ) {
|
||||
cartService.initCart(jsonObject);
|
||||
}
|
||||
@@ -46,13 +47,14 @@ public class CartConsumer {
|
||||
else if (jsonObject.getString("type").equals("queryCart") ) {
|
||||
cartService.queryCart(jsonObject);
|
||||
} else if(jsonObject.getString("type").equals("createOrder")){
|
||||
String cartDetail = redisUtil.getMessage(RedisCst.TABLE_CART.concat(tableId).concat("-").concat(shopId));
|
||||
String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, userId);
|
||||
String cartDetail = redisUtil.getMessage(tableCartKey);
|
||||
if (StringUtils.isEmpty(cartDetail)){
|
||||
log.info("createOrder购物车为空");
|
||||
throw new MsgException("购物车为空无法下单");
|
||||
}
|
||||
JSONArray array = JSON.parseArray(cartDetail);
|
||||
if (array.size() > 0){
|
||||
if (!array.isEmpty()){
|
||||
cartService.createOrder(jsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
package com.chaozhanggui.system.cashierservice.redis;
|
||||
|
||||
/** 功能描述:redis前缀
|
||||
* @params:
|
||||
* @return:
|
||||
* @Author: wgc
|
||||
* @Date: 2020-12-19 15:02
|
||||
*/
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* 功能描述:redis前缀
|
||||
*
|
||||
* @params:
|
||||
* @return:
|
||||
* @Author: wgc
|
||||
* @Date: 2020-12-19 15:02
|
||||
*/
|
||||
public class RedisCst {
|
||||
|
||||
//在线用户
|
||||
//在线用户
|
||||
public static final String ONLINE_USER = "ONLINE_USER:";
|
||||
public static final String PHONE_LIMIT = "PHONE_LIMIT:";
|
||||
public static final String ONLINE_APP_USER = "ONLINE_APP_USER:";
|
||||
public static final String LDBL_APP_VERSION = "LDBL_APP_VERSION:";
|
||||
public static final String TABLE_CART = "TABLE:CART:";
|
||||
// public static final String TABLE_CART = "TABLE:CART:";
|
||||
public static final String ORDER_EXPIRED = "ORDER:EXPIRED:";
|
||||
public static final String TABLE_ORDER = "TABLE:ORDER:";
|
||||
public static final String PRODUCT = "PRODUCT:";
|
||||
@@ -21,7 +25,7 @@ public class RedisCst {
|
||||
public static final String INTEGRAL_COIN_KEY = "INTEGRAL:COIN:KEY";
|
||||
public static final String COUPONS_COIN_KEY = "COUPONS:COIN:KEY";
|
||||
|
||||
public static final String OUT_NUMBER="ORDER:NUMBER:";
|
||||
public static final String OUT_NUMBER = "ORDER:NUMBER:";
|
||||
// 创建订单锁
|
||||
public static final String CREATE_ORDER_LOCK = "CREATE_ORDER_LOCK:";
|
||||
public static final String SEND_STOCK_WARN_MSG = "SEND_STOCK_WARN_MSG:";
|
||||
@@ -37,20 +41,40 @@ public class RedisCst {
|
||||
// 全局锁
|
||||
public static final String LOCK_KEY = "LOCK:";
|
||||
|
||||
// 外带购物车缓存
|
||||
public static final String TAKEOUT_TABLE_CART = "TAKEOUT_TABLE_CART:";
|
||||
// 店内就餐购物车缓存
|
||||
public static final String DINE_IN_TABLE_CART = "DINE_IN_TABLE_CART:";
|
||||
|
||||
|
||||
public static String getCurrentOrderKey(String tableId, String shopId) {
|
||||
return CURRENT_TABLE_ORDER + shopId + ":" + tableId;
|
||||
return CURRENT_TABLE_ORDER + shopId + ":" + tableId;
|
||||
}
|
||||
|
||||
public static String getTableCallNumKey(Integer shopId, Integer callTableId) {
|
||||
return TABLE_CALL_NUMBER + shopId + ":" + callTableId;
|
||||
}
|
||||
|
||||
public static String getLockKey(String sign, Object... args) {
|
||||
StringBuilder key = new StringBuilder(LOCK_KEY + ":" + sign + ":");
|
||||
for (Object arg : args) {
|
||||
key.append(":").append(arg.toString());
|
||||
public static String getLockKey(String sign, Object... args) {
|
||||
StringBuilder key = new StringBuilder(LOCK_KEY + ":" + sign + ":");
|
||||
for (Object arg : args) {
|
||||
key.append(":").append(arg.toString());
|
||||
}
|
||||
return key.toString();
|
||||
}
|
||||
|
||||
public static String getTakeoutTableCartKey(String shopId, Object userId) {
|
||||
return TAKEOUT_TABLE_CART + shopId + ":" + userId;
|
||||
}
|
||||
|
||||
public static String getDineInTableCartKey(String shopId, String tableId) {
|
||||
return DINE_IN_TABLE_CART + shopId + ":" + tableId;
|
||||
}
|
||||
|
||||
public static String getTableCartKey(String shopId, String tableId, Object userId) {
|
||||
if (StrUtil.isBlank(tableId)) {
|
||||
return getTakeoutTableCartKey(shopId, userId);
|
||||
}
|
||||
return getDineInTableCartKey(shopId, tableId);
|
||||
}
|
||||
return key.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,16 +6,15 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.Enum.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.ChoseCountDTO;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO;
|
||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
import com.chaozhanggui.system.cashierservice.mapper.MpCashierCartMapper;
|
||||
import com.chaozhanggui.system.cashierservice.mapper.MpOrderDetailMapper;
|
||||
import com.chaozhanggui.system.cashierservice.mapper.MpOrderInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.mapper.MpShopInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.mapper.*;
|
||||
import com.chaozhanggui.system.cashierservice.netty.PushToAppChannelHandlerAdapter;
|
||||
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
|
||||
import com.chaozhanggui.system.cashierservice.redis.RedisCst;
|
||||
@@ -118,6 +117,8 @@ public class CartService {
|
||||
private MpCashierCartMapper mpCashierCartMapper;
|
||||
@Autowired
|
||||
private MpOrderDetailMapper mpOrderDetailMapper;
|
||||
@Autowired
|
||||
private MpShopTableMapper mpShopTableMapper;
|
||||
|
||||
public CartService(TbUserShopMsgMapper tbUserShopMsgMapper, WechatUtil wechatUtil, WxAccountUtil wxAccountUtil, TbShopOpenIdMapper shopOpenIdMapper, ProductService productService, TbProductMapper tbProductMapper, RedisTemplate<String, Object> redisTemplate, StringRedisTemplate stringRedisTemplate, ShopUtils shopUtils) {
|
||||
this.tbUserShopMsgMapper = tbUserShopMsgMapper;
|
||||
@@ -164,11 +165,13 @@ public class CartService {
|
||||
public void initCart(JSONObject jsonObject) {
|
||||
String tableId = jsonObject.getString("tableId");
|
||||
String shopId = jsonObject.getString("shopId");
|
||||
String key = tableId + "-" + shopId;
|
||||
Integer userId = jsonObject.getInteger("userId");
|
||||
BigDecimal amount = BigDecimal.ZERO;
|
||||
JSONArray array = new JSONArray();
|
||||
if (redisUtil.exists(RedisCst.TABLE_CART.concat(key))) {
|
||||
array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId))));
|
||||
|
||||
String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, userId);
|
||||
if (redisUtil.exists(tableCartKey)) {
|
||||
array = JSON.parseArray(redisUtil.getMessage(tableCartKey));
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject object = array.getJSONObject(i);
|
||||
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
|
||||
@@ -184,7 +187,7 @@ public class CartService {
|
||||
if(cashierCart.getIsVip().equals((byte) 1)) continue;
|
||||
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
}
|
||||
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(key), array.toString());
|
||||
redisUtil.saveMessage(tableCartKey, array.toString());
|
||||
}
|
||||
}
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
@@ -193,7 +196,7 @@ public class CartService {
|
||||
jsonObject1.put("type", "addCart");
|
||||
jsonObject1.put("data", array);
|
||||
jsonObject1.put("amount", amount);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, "", false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,6 +212,7 @@ public class CartService {
|
||||
Integer type = jsonObject.getInteger("type");
|
||||
Integer buyNum = jsonObject.getInteger("num");
|
||||
Integer isVip = jsonObject.getInteger("isVip");
|
||||
Integer userId = jsonObject.getInteger("userId");
|
||||
// 商品备注
|
||||
String note = jsonObject.getString("note");
|
||||
if (StringUtils.isBlank(shopId) || StringUtils.isBlank(productId)
|
||||
@@ -216,7 +220,8 @@ public class CartService {
|
||||
return Result.fail("参数缺失");
|
||||
}
|
||||
|
||||
String key = tableId + "-" + shopId;
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.checkEatModel(tableId, shopId);
|
||||
String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, userId);
|
||||
TbProduct tbProduct = productMapper.selectById(Integer.valueOf(productId));
|
||||
if (tbProduct == null) {
|
||||
log.error("该商品不存在 productId:{}", productId);
|
||||
@@ -225,19 +230,19 @@ public class CartService {
|
||||
// 判断商品是否已下架
|
||||
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId));
|
||||
if (tbProductSkuWithBLOBs == null || tbProductSkuWithBLOBs.getIsGrounding().equals(0)) {
|
||||
rmCart(jsonObject, skuId, key);
|
||||
rmCart(jsonObject, skuId, tableCartKey);
|
||||
return Result.fail("商品已下架");
|
||||
}
|
||||
if (tbProduct.getIsStock() == 1) {
|
||||
// 1:共享库存 0:独立库存
|
||||
if (Integer.valueOf(tbProduct.getIsDistribute()).equals(1)) {
|
||||
if (tbProduct.getIsPauseSale() == 1) {//是否售罄
|
||||
rmCart(jsonObject, skuId, key);
|
||||
rmCart(jsonObject, skuId, tableCartKey);
|
||||
return Result.fail("该商品已售罄");
|
||||
}
|
||||
} else {
|
||||
if (tbProductSkuWithBLOBs.getIsPauseSale() == 1) {//是否售罄
|
||||
rmCart(jsonObject, skuId, key);
|
||||
rmCart(jsonObject, skuId, tableCartKey);
|
||||
return Result.fail("该商品已售罄");
|
||||
}
|
||||
}
|
||||
@@ -262,8 +267,8 @@ public class CartService {
|
||||
ArrayList<TbCashierCart> cashierCartArrayList = new ArrayList<>();
|
||||
BigDecimal amount = BigDecimal.ZERO;
|
||||
try{
|
||||
if (redisUtil.exists(RedisCst.TABLE_CART.concat(key))) {
|
||||
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(key)));
|
||||
if (redisUtil.exists(tableCartKey)) {
|
||||
JSONArray array = JSON.parseArray(redisUtil.getMessage(tableCartKey));
|
||||
if (Objects.isNull(array) || array.isEmpty()) {
|
||||
if (type == 1) {
|
||||
TbCashierCart cashierCart = addCart(productId, skuId,
|
||||
@@ -335,7 +340,7 @@ public class CartService {
|
||||
}
|
||||
}
|
||||
|
||||
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(key), jsonArray.toJSONString());
|
||||
redisUtil.saveMessage(tableCartKey, jsonArray.toJSONString());
|
||||
// 餐位费
|
||||
TbCashierCart seatCost = cashierCartArrayList.stream().findFirst().filter(info -> "-999".equals(info.getProductId())).orElse(null);
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
@@ -346,7 +351,7 @@ public class CartService {
|
||||
data.put("seatFee", seatCost);
|
||||
data.put("amount", amount);
|
||||
data.put("reqData", jsonObject);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(JSONObject.toJSONString(data), key, "", false);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(JSONObject.toJSONString(data), tableCartKey, "", false);
|
||||
} catch (Exception e) {
|
||||
log.error("长链接错误 createCar", e);
|
||||
}
|
||||
@@ -369,11 +374,11 @@ public class CartService {
|
||||
return list;
|
||||
}
|
||||
|
||||
private void rmCart(JSONObject jsonObject,String skuId, String key) {
|
||||
private void rmCart(JSONObject jsonObject,String skuId, String redisKey) {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
BigDecimal amount = BigDecimal.ZERO;
|
||||
if (redisUtil.exists(RedisCst.TABLE_CART.concat(key))) {
|
||||
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(key)));
|
||||
if (redisUtil.exists(redisKey)) {
|
||||
JSONArray array = JSON.parseArray(redisUtil.getMessage(redisKey));
|
||||
if (!Objects.isNull(array) && !array.isEmpty()) {
|
||||
boolean flag = false;
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
@@ -391,7 +396,7 @@ public class CartService {
|
||||
jsonArray.add(cashierCart);
|
||||
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
}
|
||||
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(key), jsonArray.toJSONString());
|
||||
redisUtil.saveMessage(redisKey, jsonArray.toJSONString());
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "success");
|
||||
jsonObject1.put("msg", "成功");
|
||||
@@ -400,7 +405,7 @@ public class CartService {
|
||||
jsonObject1.put("amount", amount);
|
||||
jsonObject1.put("reqData", jsonObject);
|
||||
if(flag){
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, "", false);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), redisKey, "", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -571,9 +576,10 @@ public class CartService {
|
||||
try {
|
||||
String shopId = jsonObject.getString("shopId");
|
||||
String tableId = jsonObject.getString("tableId");
|
||||
String userId = jsonObject.getString("userId");
|
||||
String remark = StringUtils.isBlank(jsonObject.getString("remark"))?"":jsonObject.getString("remark");
|
||||
String key = tableId + "-" + shopId;
|
||||
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(key)));
|
||||
String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, Integer.valueOf(userId));
|
||||
JSONArray array = JSON.parseArray(redisUtil.getMessage(tableCartKey));
|
||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
BigDecimal packAMount = BigDecimal.ZERO;
|
||||
BigDecimal originAmount = BigDecimal.ZERO;
|
||||
@@ -587,7 +593,6 @@ public class CartService {
|
||||
MsgException.throwException("生成订单错误");
|
||||
}
|
||||
|
||||
String userId = jsonObject.getString("userId");
|
||||
TbUserInfo tbUserInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId));
|
||||
if (tbUserInfo == null) {
|
||||
MsgException.throwException("生成订单失败");
|
||||
@@ -597,18 +602,63 @@ public class CartService {
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.checkEatModel(tableId, shopId);
|
||||
Integer currentPlaceNum = getCurrentPlaceNum(tableId, shopId, shopEatTypeInfoDTO);
|
||||
|
||||
// 就餐人数
|
||||
Integer mealNum = null;
|
||||
ArrayList<Integer> cashierIds = new ArrayList<>();
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject object = array.getJSONObject(i);
|
||||
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
|
||||
cashierIds.add(cashierCart.getId());
|
||||
if ("-999".equals(cashierCart.getProductId())) {
|
||||
mealNum = cashierCart.getNumber();
|
||||
// 查询购物车所有信息
|
||||
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, shopId)
|
||||
.eq(TbCashierCart::getStatus, "create");
|
||||
|
||||
Integer seatNum = 0;
|
||||
BigDecimal seatCost = BigDecimal.ZERO;
|
||||
|
||||
TbShopTable shopTable = null;
|
||||
// 外带模式
|
||||
if (shopEatTypeInfoDTO.isTakeout()) {
|
||||
queryWrapper.eq(TbCashierCart::getUserId, userId);
|
||||
// 台桌点单
|
||||
} else {
|
||||
queryWrapper
|
||||
.and(q -> {
|
||||
q.eq(TbCashierCart::getUserId, userId).or().isNull(TbCashierCart::getUserId);
|
||||
})
|
||||
.and(q -> {
|
||||
q.eq(TbCashierCart::getTableId, tableId).or().isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, "");
|
||||
});
|
||||
|
||||
shopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
|
||||
.eq(TbShopTable::getQrcode, tableId));
|
||||
if (shopTable == null) {
|
||||
throw new MsgException("台桌不存在");
|
||||
}
|
||||
|
||||
// 设置餐位费
|
||||
TbShopInfo shopInfo = mpShopInfoMapper.selectById(shopId);
|
||||
if (shopInfo.getIsTableFee() != null && shopInfo.getIsTableFee() == 0) {
|
||||
seatNum = jsonObject.getInteger("dinersNum");
|
||||
if (seatNum == null) {
|
||||
MsgException.throwException("dinersNum不能为空");
|
||||
}
|
||||
if (shopTable.getMaxCapacity() < seatNum) {
|
||||
throw new MsgException("当前台桌最大人数为: " + shopTable.getMaxCapacity());
|
||||
}
|
||||
seatCost = shopInfo.getTableFee().multiply(BigDecimal.valueOf(seatNum));
|
||||
|
||||
ChoseCountDTO choseCountDTO = new ChoseCountDTO();
|
||||
choseCountDTO.setTableId(tableId);
|
||||
choseCountDTO.setShopId(Integer.valueOf(shopId));
|
||||
choseCountDTO.setNum(seatNum);
|
||||
choseCountDTO.setUserId(userId);
|
||||
productService.choseCount(choseCountDTO);
|
||||
}
|
||||
}
|
||||
|
||||
// 所有订单信息
|
||||
List<TbCashierCart> cashierCartList = mpCashierCartMapper.selectList(queryWrapper);
|
||||
// 就餐人数
|
||||
ArrayList<Integer> cashierIds = new ArrayList<>();
|
||||
cashierCartList.forEach(cashierCart -> {
|
||||
cashierIds.add(cashierCart.getId());
|
||||
});
|
||||
|
||||
TbShopUser tbShopUser = shopUserMapper.selectByUserIdAndShopId(userId, shopId);
|
||||
boolean isVip= tbShopUser != null && tbShopUser.getIsVip().equals((byte) 1);
|
||||
|
||||
@@ -617,36 +667,34 @@ public class CartService {
|
||||
.in(TbOrderDetail::getCartId, cashierIds)
|
||||
.eq(TbOrderDetail::getShopId, shopId));
|
||||
HashMap<String, TbOrderDetail> oldOrderDetailMap = new HashMap<>();
|
||||
oldOrderDetailList.forEach(item -> {
|
||||
oldOrderDetailMap.put(item.getOrderId().toString() + item.getCartId(), item);
|
||||
});
|
||||
oldOrderDetailList.forEach(item -> oldOrderDetailMap.put(item.getOrderId().toString() + item.getCartId(), item));
|
||||
|
||||
//校验 库存 耗材
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject object = array.getJSONObject(i);
|
||||
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
|
||||
if (cashierCart.getIsVip().equals((byte) 1)) {
|
||||
for (TbCashierCart cart : cashierCartList) {
|
||||
// 设置用餐类型
|
||||
cart.setUseType(shopEatTypeInfoDTO.getUseType());
|
||||
if (cart.getIsVip().equals((byte) 1)) {
|
||||
if (isVip) {
|
||||
int i1 = activateInRecordService.queryByVipIdAndShopIdAndProId(
|
||||
Integer.valueOf(tbShopUser.getId()), Integer.valueOf(shopId), Integer.valueOf(cashierCart.getProductId()));
|
||||
if (i1 < cashierCart.getTotalNumber()) {
|
||||
Integer.valueOf(tbShopUser.getId()), Integer.valueOf(shopId), Integer.valueOf(cart.getProductId()));
|
||||
if (i1 < cart.getTotalNumber()) {
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "会员商品[" + cashierCart.getName() + "],可下单数量为" + i1);
|
||||
jsonObject1.put("msg", "会员商品[" + cart.getName() + "],可下单数量为" + i1);
|
||||
jsonObject1.put("data", new ArrayList<>());
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
return;
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "非会员用户不可下单会员商品");
|
||||
jsonObject1.put("data", new ArrayList<>());
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
return;
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
TbProductSkuWithBLOBs tbProduct = productSkuMapper.selectByPrimaryKey(Integer.valueOf(cashierCart.getSkuId()));
|
||||
TbProductSkuWithBLOBs tbProduct = productSkuMapper.selectByPrimaryKey(Integer.valueOf(cart.getSkuId()));
|
||||
TbProduct tbProduct1 = tbProductMapper.selectById(Integer.valueOf(tbProduct.getProductId()));
|
||||
|
||||
// 判断商品是否已下架
|
||||
@@ -655,83 +703,86 @@ public class CartService {
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "商品已下架:" + tbProduct1.getName());
|
||||
jsonObject1.put("data", new ArrayList<>());
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
return;
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
continue;
|
||||
}
|
||||
|
||||
log.info("下单,开始校验库存预警,购物车id:{}", cashierCart.getId());
|
||||
CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(tbProduct, tbProduct1, cashierCart.getNumber()));
|
||||
log.info("下单,开始校验库存预警,购物车id:{}", cart.getId());
|
||||
CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(tbProduct, tbProduct1, cart.getNumber()));
|
||||
|
||||
|
||||
log.info("开始修改库存,商品id:{},商品名:{}", tbProduct1.getId(), tbProduct1.getName());
|
||||
// 修改库存
|
||||
try {
|
||||
if (tbProduct1.getIsStock() == 1) {
|
||||
productService.updateStock(tbProduct.getProductId(), tbProduct.getId(), cashierCart.getNumber(), tbProduct1.getIsDistribute() == 1);
|
||||
} else {
|
||||
productService.updateStockAndNoCheck(tbProduct.getProductId(), tbProduct.getId(), cashierCart.getNumber(), tbProduct1.getIsDistribute() == 1);
|
||||
// 首次下单扣除库存
|
||||
if (StrUtil.isBlank(cart.getOrderId())) {
|
||||
if (tbProduct1.getIsStock() == 1) {
|
||||
productService.updateStock(tbProduct.getProductId(), tbProduct.getId(), cart.getNumber(), tbProduct1.getIsDistribute() == 1);
|
||||
} else {
|
||||
productService.updateStockAndNoCheck(tbProduct.getProductId(), tbProduct.getId(), cart.getNumber(), tbProduct1.getIsDistribute() == 1);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", tbProduct1.getName() + "库存不足");
|
||||
jsonObject1.put("data", new ArrayList<>());
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
return;
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
totalAmount = totalAmount.add(cashierCart.getTotalAmount());
|
||||
packAMount = packAMount.add(cashierCart.getPackFee());
|
||||
originAmount = originAmount.add(cashierCart.getTotalAmount());
|
||||
totalAmount = totalAmount.add(cart.getTotalAmount());
|
||||
packAMount = packAMount.add(cart.getPackFee());
|
||||
originAmount = originAmount.add(cart.getTotalAmount());
|
||||
saleAmount = saleAmount.add(tbProduct.getSalePrice());
|
||||
|
||||
TbOrderDetail orderDetail = oldOrderDetailMap.get(cashierCart.getOrderId() + cashierCart.getId());
|
||||
TbOrderDetail orderDetail = oldOrderDetailMap.get(cart.getOrderId() + cart.getId());
|
||||
if (orderDetail == null) {
|
||||
orderDetail = new TbOrderDetail();
|
||||
}
|
||||
orderDetail.setCreateTime(new Date());
|
||||
orderDetail.setNum(cashierCart.getNumber());
|
||||
orderDetail.setPrice(cashierCart.getSalePrice());
|
||||
if (cashierCart.getIsPack().equals("true")) {
|
||||
orderDetail.setPriceAmount(cashierCart.getTotalAmount().add(cashierCart.getPackFee()));
|
||||
orderDetail.setNum(cart.getNumber());
|
||||
orderDetail.setPrice(cart.getSalePrice());
|
||||
if (cart.getIsPack().equals("true")) {
|
||||
orderDetail.setPriceAmount(cart.getTotalAmount().add(cart.getPackFee()));
|
||||
} else {
|
||||
orderDetail.setPriceAmount(cashierCart.getTotalAmount());
|
||||
orderDetail.setPriceAmount(cart.getTotalAmount());
|
||||
}
|
||||
orderDetail.setProductId(Integer.valueOf(cashierCart.getProductId()));
|
||||
orderDetail.setProductSkuId(Integer.valueOf(cashierCart.getSkuId()));
|
||||
orderDetail.setProductId(Integer.valueOf(cart.getProductId()));
|
||||
orderDetail.setProductSkuId(Integer.valueOf(cart.getSkuId()));
|
||||
orderDetail.setProductSkuName(tbProduct.getSpecSnap());
|
||||
orderDetail.setProductName(cashierCart.getName());
|
||||
orderDetail.setProductName(cart.getName());
|
||||
orderDetail.setShopId(jsonObject.getInteger("shopId"));
|
||||
orderDetail.setPackAmount(cashierCart.getPackFee());
|
||||
orderDetail.setProductImg(cashierCart.getCoverImg());
|
||||
orderDetail.setPackAmount(cart.getPackFee());
|
||||
orderDetail.setProductImg(cart.getCoverImg());
|
||||
orderDetail.setStatus("unpaid");
|
||||
orderDetail.setIsVip(cashierCart.getIsVip());
|
||||
if (StringUtils.isNotEmpty(cashierCart.getOrderId())) {
|
||||
orderId = Integer.valueOf(cashierCart.getOrderId());
|
||||
orderDetail.setIsVip(cart.getIsVip());
|
||||
if (StringUtils.isNotEmpty(cart.getOrderId())) {
|
||||
orderId = Integer.valueOf(cart.getOrderId());
|
||||
}
|
||||
orderDetail.setUseType(shopEatTypeInfoDTO.getUseType());
|
||||
orderDetail.setPlaceNum(cashierCart.getPlaceNum());
|
||||
orderDetail.setPlaceNum(cart.getPlaceNum());
|
||||
|
||||
// 设置下单次数
|
||||
if (cashierCart.getPlaceNum() == null) {
|
||||
cashierCart.setPlaceNum(currentPlaceNum);
|
||||
if (cart.getPlaceNum() == null) {
|
||||
cart.setPlaceNum(currentPlaceNum);
|
||||
}
|
||||
|
||||
orderDetails.add(orderDetail);
|
||||
if (StringUtils.isNotEmpty(cashierCart.getOrderId())) {
|
||||
orderId = Integer.valueOf(cashierCart.getOrderId());
|
||||
if (StringUtils.isNotEmpty(cart.getOrderId())) {
|
||||
orderId = Integer.valueOf(cart.getOrderId());
|
||||
}
|
||||
|
||||
cashierCart.setStatus("final");
|
||||
if (cashierCart.getId() != null) {
|
||||
mpCashierCartMapper.updateById(cashierCart);
|
||||
}else {
|
||||
mpCashierCartMapper.insert(cashierCart);
|
||||
cart.setStatus("final");
|
||||
if (cart.getId() != null) {
|
||||
mpCashierCartMapper.updateById(cart);
|
||||
} else {
|
||||
mpCashierCartMapper.insert(cart);
|
||||
}
|
||||
}
|
||||
//总金额
|
||||
TbShopTable shopTable = shopTableMapper.selectQRcode(jsonObject.getString("tableId"));
|
||||
|
||||
|
||||
//生成订单
|
||||
TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId);
|
||||
|
||||
@@ -751,7 +802,7 @@ public class CartService {
|
||||
jsonObject1.put("msg", "优惠券已售空");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", "");
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return;
|
||||
}
|
||||
@@ -762,7 +813,7 @@ public class CartService {
|
||||
jsonObject1.put("msg", "订单金额小于优惠价金额");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", "");
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return;
|
||||
}
|
||||
@@ -794,7 +845,7 @@ public class CartService {
|
||||
|
||||
}
|
||||
|
||||
if (Objects.nonNull(orderInfo)) {
|
||||
if (orderInfo != null) {
|
||||
log.info("订单状态:" + orderInfo.getStatus());
|
||||
if (!"unpaid".equals(orderInfo.getStatus())) {
|
||||
log.info("开始处理订单");
|
||||
@@ -803,11 +854,10 @@ public class CartService {
|
||||
jsonObject1.put("msg", "订单正在支付中,请稍后再试");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", "");
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return;
|
||||
}
|
||||
|
||||
orderInfo.setUpdatedAt(System.currentTimeMillis());
|
||||
orderInfo.setSettlementAmount(totalAmount);
|
||||
orderInfo.setUserCouponId(couponId);
|
||||
@@ -823,8 +873,9 @@ public class CartService {
|
||||
orderInfo.setUserId(userId);
|
||||
orderInfo.setPlaceNum(currentPlaceNum);
|
||||
orderInfo.setUseType(shopEatTypeInfoDTO.getUseType());
|
||||
orderInfo.setSeatCount(seatNum);
|
||||
orderInfo.setSeatAmount(seatCost);
|
||||
mpOrderInfoMapper.updateById(orderInfo);
|
||||
|
||||
} else {
|
||||
orderInfo = getOrder(totalAmount, packAMount, shopTable, tbMerchantAccount.getId().toString(), jsonObject, originAmount);
|
||||
orderInfo.setMerchantId(String.valueOf(tbMerchantAccount.getId()));
|
||||
@@ -837,6 +888,8 @@ public class CartService {
|
||||
orderInfo.setUserId(userId);
|
||||
orderInfo.setPlaceNum(currentPlaceNum);
|
||||
orderInfo.setUseType(shopEatTypeInfoDTO.getUseType());
|
||||
orderInfo.setSeatCount(seatNum);
|
||||
orderInfo.setSeatAmount(seatCost);
|
||||
|
||||
JSONObject object = new JSONObject();
|
||||
String outNumber = redisUtil.getMessage(RedisCst.OUT_NUMBER.concat(jsonObject.getString("shopId")));
|
||||
@@ -858,8 +911,6 @@ public class CartService {
|
||||
redisUtil.saveMessage(RedisCst.OUT_NUMBER.concat(jsonObject.getString("shopId")), object.toString());
|
||||
mpOrderInfoMapper.insert(orderInfo);
|
||||
orderId = orderInfo.getId();
|
||||
|
||||
|
||||
}
|
||||
|
||||
for (TbOrderDetail orderDetail : orderDetails) {
|
||||
@@ -911,7 +962,7 @@ public class CartService {
|
||||
log.info("开始发送mq消息,消耗耗材,消息内容:{}", jsonObject2);
|
||||
producer.cons(jsonObject2.toString());
|
||||
|
||||
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId), array.toJSONString());
|
||||
redisUtil.saveMessage(tableCartKey, array.toJSONString());
|
||||
orderInfo.setDetailList(orderDetails);
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "success");
|
||||
@@ -919,8 +970,8 @@ public class CartService {
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", orderInfo);
|
||||
|
||||
redisUtil.deleteByKey(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId));
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
redisUtil.deleteByKey(tableCartKey);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
JSONObject jsonObject12 = new JSONObject();
|
||||
jsonObject12.put("status", "success");
|
||||
jsonObject12.put("msg", "成功");
|
||||
@@ -929,7 +980,7 @@ public class CartService {
|
||||
|
||||
jsonObject12.put("data", new JSONArray());
|
||||
// PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject12.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject12.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), jsonObject.getString("userId"));
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject12.toString(), tableCartKey, jsonObject.getString("userId"));
|
||||
|
||||
|
||||
redisUtil.saveMessage(RedisCst.ORDER_EXPIRED.concat(orderId.toString()), orderId.toString(), 60 * 16L);
|
||||
@@ -993,6 +1044,8 @@ public class CartService {
|
||||
public void clearCart(JSONObject jsonObject) {
|
||||
try {
|
||||
String shopId = jsonObject.getString("shopId");
|
||||
String tableId = jsonObject.getString("tableId");
|
||||
Integer userId = TokenUtil.getUserId();
|
||||
|
||||
// List<String> skuIds=new ArrayList<>();
|
||||
// if (redisUtil.exists(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))) {
|
||||
@@ -1009,7 +1062,8 @@ public class CartService {
|
||||
// }
|
||||
cashierCartMapper.updateStatusByOrderIdForMini(jsonObject.getString("tableId"), "closed");
|
||||
// cashierCartMapper.updateStatusByTableId(jsonObject.getString("tableId"), "closed");
|
||||
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)), new JSONArray().toJSONString());
|
||||
String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, userId);
|
||||
redisUtil.saveMessage(tableCartKey, new JSONArray().toJSONString());
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "success");
|
||||
jsonObject1.put("msg", "成功");
|
||||
@@ -1022,7 +1076,7 @@ public class CartService {
|
||||
// jsonObject2.put("skuIds",skuIds);
|
||||
// jsonObject2.put("shopId",shopId);
|
||||
// producer.cons(jsonObject2.toString());
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, "", false);
|
||||
} catch (Exception e) {
|
||||
log.info("长链接错误 clearCart{}", e.getMessage());
|
||||
e.printStackTrace();
|
||||
@@ -1034,8 +1088,9 @@ public class CartService {
|
||||
try {
|
||||
String shopId = jsonObject.getString("shopId");
|
||||
String tableId = jsonObject.getString("tableId");
|
||||
String key = tableId + "-" + shopId;
|
||||
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId))));
|
||||
String userId = jsonObject.getString("userId");
|
||||
String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, Integer.valueOf(userId));
|
||||
JSONArray array = JSON.parseArray(redisUtil.getMessage(tableCartKey));
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
BigDecimal packAMount = BigDecimal.ZERO;
|
||||
@@ -1051,7 +1106,6 @@ public class CartService {
|
||||
throw new MsgException("生成订单错误");
|
||||
}
|
||||
|
||||
String userId = jsonObject.getString("userId");
|
||||
TbUserInfo tbUserInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId));
|
||||
if (tbUserInfo == null) {
|
||||
throw new MsgException("生成订单失败");
|
||||
@@ -1112,7 +1166,7 @@ public class CartService {
|
||||
jsonObject1.put("msg", "优惠券已售空");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", "");
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return;
|
||||
}
|
||||
@@ -1123,7 +1177,7 @@ public class CartService {
|
||||
jsonObject1.put("msg", "订单金额小于优惠价金额");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", "");
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return;
|
||||
}
|
||||
@@ -1151,7 +1205,7 @@ public class CartService {
|
||||
jsonObject1.put("msg", "优惠券已使用");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", "");
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return;
|
||||
}
|
||||
@@ -1162,7 +1216,7 @@ public class CartService {
|
||||
jsonObject1.put("msg", "订单金额小于优惠价金额");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", "");
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return;
|
||||
}
|
||||
@@ -1184,7 +1238,7 @@ public class CartService {
|
||||
jsonObject1.put("msg", "订单正在支付中,请稍后再试");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", "");
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return;
|
||||
}
|
||||
@@ -1248,16 +1302,16 @@ public class CartService {
|
||||
object.put("updatedAt", System.currentTimeMillis());
|
||||
object.put("orderId", orderId + "");
|
||||
}
|
||||
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId), array.toJSONString());
|
||||
redisUtil.saveMessage(tableCartKey, array.toJSONString());
|
||||
orderInfo.setDetailList(orderDetails);
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "success");
|
||||
jsonObject1.put("msg", "成功");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", orderInfo);
|
||||
redisUtil.deleteByKey(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId));
|
||||
redisUtil.deleteByKey(tableCartKey);
|
||||
redisUtil.saveMessage(RedisCst.TABLE_ORDER.concat(orderInfo.getOrderNo()), JSONObject.toJSONString(orderInfo), 24 * 60 * 60L);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
JSONObject jsonObject12 = new JSONObject();
|
||||
jsonObject12.put("status", "success");
|
||||
jsonObject12.put("msg", "成功");
|
||||
@@ -1265,7 +1319,7 @@ public class CartService {
|
||||
jsonObject12.put("amount", BigDecimal.ZERO);
|
||||
|
||||
jsonObject12.put("data", new JSONArray());
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject12.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject12.toString(), tableCartKey, "", false);
|
||||
} catch (Exception e) {
|
||||
log.info("长链接错误 pendingOrder{}", e.getMessage());
|
||||
e.printStackTrace();
|
||||
@@ -1275,7 +1329,10 @@ public class CartService {
|
||||
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))));
|
||||
Integer userId = jsonObject.getInteger("userId");
|
||||
String tableId = jsonObject.getString("tableId");
|
||||
String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, userId);
|
||||
JSONArray array = JSON.parseArray(redisUtil.getMessage(tableCartKey));
|
||||
BigDecimal amount = BigDecimal.ZERO;
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject object = array.getJSONObject(i);
|
||||
@@ -1288,7 +1345,7 @@ public class CartService {
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", array);
|
||||
jsonObject1.put("amount", amount);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, "", false);
|
||||
} catch (Exception e) {
|
||||
log.info("长链接错误 queryCart{}", e.getMessage());
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -256,9 +256,8 @@ public class PayService {
|
||||
|
||||
|
||||
tbOrderInfoMapper.updateByPrimaryKey(orderInfo);
|
||||
String key = RedisCst.TABLE_CART.concat(orderInfo.getTableId()).concat("-").concat(orderInfo.getShopId());
|
||||
//清除缓存购物车数据
|
||||
redisUtil.deleteByKey(key);
|
||||
redisUtil.deleteByKey(RedisCst.getTableCartKey(orderInfo.getTableId(), orderInfo.getTableId(), orderInfo.getUserId()));
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "success");
|
||||
jsonObject1.put("msg", "成功");
|
||||
@@ -297,9 +296,8 @@ public class PayService {
|
||||
|
||||
|
||||
tbOrderInfoMapper.updateByPrimaryKey(orderInfo);
|
||||
String key = RedisCst.TABLE_CART.concat(orderInfo.getTableId()).concat("-").concat(orderInfo.getShopId());
|
||||
//清除缓存购物车数据
|
||||
redisUtil.deleteByKey(key);
|
||||
redisUtil.deleteByKey(RedisCst.getTableCartKey(orderInfo.getShopId(), orderInfo.getTableId(), orderInfo.getUserId()));
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "success");
|
||||
jsonObject1.put("msg", "成功");
|
||||
|
||||
@@ -912,6 +912,7 @@ public class ProductService {
|
||||
tbCashierCart.setTotalNumber(choseCountDTO.getNum());
|
||||
tbCashierCart.setUseType(shopEatTypeInfoDTO.getUseType());
|
||||
tbCashierCart.setPlatformType(PlatformTypeEnum.MINI_APP.getValue());
|
||||
tbCashierCart.setUserId(Integer.valueOf(choseCountDTO.getUserId()));
|
||||
mpCashierCartMapper.insert(tbCashierCart);
|
||||
} else {
|
||||
tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(shopInfo.getTableFee()));
|
||||
@@ -919,6 +920,7 @@ public class ProductService {
|
||||
tbCashierCart.setTotalNumber(choseCountDTO.getNum());
|
||||
tbCashierCart.setUseType(shopEatTypeInfoDTO.getUseType());
|
||||
tbCashierCart.setPlatformType(PlatformTypeEnum.MINI_APP.getValue());
|
||||
tbCashierCart.setUserId(Integer.valueOf(choseCountDTO.getUserId()));
|
||||
mpCashierCartMapper.updateById(tbCashierCart);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user