1.创建订单同步保存用户id

2.代客下单订单不重复出票
3.订单支付完毕清楚当前台桌缓存订单号
This commit is contained in:
2024-08-31 16:47:12 +08:00
parent 1ee3c33fa0
commit 7be5d2354f
6 changed files with 85 additions and 39 deletions

View File

@@ -25,6 +25,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@@ -93,6 +94,8 @@ public class CartService {
private final RedisTemplate<String, Object> redisTemplate;
private final StringRedisTemplate stringRedisTemplate;
@Autowired
private TbProskuConMapper tbProskuConMapper;
@@ -100,7 +103,7 @@ public class CartService {
@Autowired
TbConsInfoMapper tbConsInfoMapper;
public CartService(TbUserShopMsgMapper tbUserShopMsgMapper, WechatUtil wechatUtil, WxAccountUtil wxAccountUtil, TbShopOpenIdMapper shopOpenIdMapper, ProductService productService, TbProductMapper tbProductMapper, RedisTemplate<String, Object> redisTemplate) {
public CartService(TbUserShopMsgMapper tbUserShopMsgMapper, WechatUtil wechatUtil, WxAccountUtil wxAccountUtil, TbShopOpenIdMapper shopOpenIdMapper, ProductService productService, TbProductMapper tbProductMapper, RedisTemplate<String, Object> redisTemplate, StringRedisTemplate stringRedisTemplate) {
this.tbUserShopMsgMapper = tbUserShopMsgMapper;
this.wechatUtil = wechatUtil;
this.wxAccountUtil = wxAccountUtil;
@@ -108,6 +111,7 @@ public class CartService {
this.productService = productService;
this.tbProductMapper = tbProductMapper;
this.redisTemplate = redisTemplate;
this.stringRedisTemplate = stringRedisTemplate;
}
public void initCart(JSONObject jsonObject) {
@@ -708,6 +712,7 @@ public class CartService {
orderInfo.setIsBuyCoupon(isBuyYhq);
orderInfo.setIsUseCoupon(isuseYhq);
orderInfo.setRemark(remark);
orderInfo.setUserId(userId);
orderInfoMapper.updateByPrimaryKeySelective(orderInfo);
} else {
@@ -719,6 +724,7 @@ public class CartService {
orderInfo.setIsUseCoupon(isuseYhq);
orderInfo.setUserCouponAmount(couponAmount);
orderInfo.setRemark(remark);
orderInfo.setUserId(userId);
JSONObject object = new JSONObject();
String outNumber = redisUtil.getMessage(RedisCst.OUT_NUMBER.concat(jsonObject.getString("shopId")));

View File

@@ -31,6 +31,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -158,6 +159,8 @@ public class PayService {
private final TbShopSongOrderService shopSongOrderService;
@Autowired
private MQUtils mQUtils;
@Autowired
private StringRedisTemplate stringRedisTemplate;
public PayService(@Qualifier("tbShopSongOrderServiceImpl") TbShopSongOrderService shopSongOrderService) {
this.shopSongOrderService = shopSongOrderService;
@@ -330,6 +333,7 @@ public class PayService {
if (ObjectUtil.isEmpty(orderInfo)) {
return Result.fail("订单信息不存在");
}
if (System.currentTimeMillis() - orderInfo.getCreatedAt() > 60 * 15 * 1000) {
return Result.fail("订单十五分钟内有效,当前已超时,请重新下单。");
}
@@ -432,10 +436,12 @@ public class PayService {
baObj.put("time",flow.getCreateTime());
producer.balance(baObj.toString());
// 为代客下单清楚当前台桌最新订单
String currentOrderKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(), orderInfo.getShopId());
String currentOrderId = stringRedisTemplate.opsForValue().get(currentOrderKey);
if (currentOrderId != null && currentOrderId.equals(orderId)) {
stringRedisTemplate.delete(currentOrderKey);
}
return Result.success(CodeEnum.SUCCESS, "1");
}
@@ -916,6 +922,13 @@ public class PayService {
sendOrderToClient(orderInfo);
redisUtil.deleteByKey(RedisCst.ORDER_EXPIRED.concat(orderInfo.getId().toString()));
// 为代客下单清除当前台桌最新订单
String currentOrderKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(), orderInfo.getShopId());
String currentOrderId = stringRedisTemplate.opsForValue().get(currentOrderKey);
if (currentOrderId != null && currentOrderId.equals(orderInfo.getId().toString())) {
stringRedisTemplate.delete(currentOrderKey);
}
// 发送mq消息并保存库存记录
JSONObject data = new JSONObject();
data.put("orderId", orderInfo.getId());
@@ -967,6 +980,13 @@ public class PayService {
sendOrderToClient(orderInfo);
redisUtil.deleteByKey(RedisCst.ORDER_EXPIRED.concat(orderInfo.getId().toString()));
// 为代客下单清楚当前台桌最新订单
String currentOrderKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(), orderInfo.getShopId());
String currentOrderId = stringRedisTemplate.opsForValue().get(currentOrderKey);
if (currentOrderId != null && currentOrderId.equals(orderInfo.getId().toString())) {
stringRedisTemplate.delete(currentOrderKey);
}
// 发送mq消息并保存库存记录
JSONObject data = new JSONObject();
data.put("orderId", orderInfo.getId());