|
|
|
|
@@ -10,13 +10,11 @@ import cn.ysk.cashier.config.security.security.TokenProvider;
|
|
|
|
|
import cn.ysk.cashier.cons.RedisConstant;
|
|
|
|
|
import cn.ysk.cashier.cons.rabbit.RabbitConstants;
|
|
|
|
|
import cn.ysk.cashier.dto.shoptable.*;
|
|
|
|
|
import cn.ysk.cashier.enums.OrderUseTypeEnum;
|
|
|
|
|
import cn.ysk.cashier.enums.ShopInfoTypeEnums;
|
|
|
|
|
import cn.ysk.cashier.enums.ShopWxMsgTypeEnum;
|
|
|
|
|
import cn.ysk.cashier.enums.TableStateEnum;
|
|
|
|
|
import cn.ysk.cashier.enums.*;
|
|
|
|
|
import cn.ysk.cashier.exception.BadRequestException;
|
|
|
|
|
import cn.ysk.cashier.mybatis.entity.TbShopOpenId;
|
|
|
|
|
import cn.ysk.cashier.mybatis.mapper.*;
|
|
|
|
|
import cn.ysk.cashier.mybatis.service.MpOrderDetailService;
|
|
|
|
|
import cn.ysk.cashier.mybatis.service.MpShopTableService;
|
|
|
|
|
import cn.ysk.cashier.pojo.TbShopPayType;
|
|
|
|
|
import cn.ysk.cashier.pojo.order.TbCashierCart;
|
|
|
|
|
@@ -112,6 +110,65 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
private final TbOrderDetailMapper tbOrderDetailMapper;
|
|
|
|
|
private final StringRedisTemplate stringRedisTemplate;
|
|
|
|
|
private final MpShopAreaMapper mpShopAreaMapper;
|
|
|
|
|
private final MpShopInfoMapper mpShopInfoMapper;
|
|
|
|
|
private final MpOrderDetailService mpOrderDetailService;
|
|
|
|
|
|
|
|
|
|
private TbOrderInfo getCurrentOrder(ShopEatTypeInfoDTO eatTypeInfoDTO, String tableId, Object shopId) {
|
|
|
|
|
// 获取当前台桌最新订单,先付款模式不获取
|
|
|
|
|
if (eatTypeInfoDTO.isDineInBefore()) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
List<TbOrderInfo> orderInfoList = orderInfoMapper.selectPage(new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(1, 1), new LambdaQueryWrapper<TbOrderInfo>()
|
|
|
|
|
.eq(TbOrderInfo::getStatus, "unpaid")
|
|
|
|
|
.eq(TbOrderInfo::getUseType, eatTypeInfoDTO.getUseType())
|
|
|
|
|
.eq(TbOrderInfo::getShopId, shopId)
|
|
|
|
|
.eq(TbOrderInfo::getTableId, tableId)
|
|
|
|
|
.eq(TbOrderInfo::getTradeDay, DateUtils.getDay())
|
|
|
|
|
.orderByDesc(TbOrderInfo::getId)).getRecords();
|
|
|
|
|
return orderInfoList.isEmpty() ? null : orderInfoList.get(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TbOrderInfo getCurrentOrder(boolean isDineInAfter, String tableId, Object shopId) {
|
|
|
|
|
// 获取当前台桌最新订单,先付款模式不获取
|
|
|
|
|
String currentOrderKey = RedisConstant.getCurrentOrderKey(tableId,
|
|
|
|
|
shopId.toString());
|
|
|
|
|
String orderIdValue = redisTemplate.opsForValue().get(currentOrderKey);
|
|
|
|
|
Integer orderId = isDineInAfter ? orderIdValue != null ? Integer.parseInt(orderIdValue) : null : null;
|
|
|
|
|
TbOrderInfo orderInfo = orderInfoMapper.selectOne(new LambdaUpdateWrapper<TbOrderInfo>()
|
|
|
|
|
.eq(TbOrderInfo::getStatus, "unpaid")
|
|
|
|
|
.eq(TbOrderInfo::getId, orderId));
|
|
|
|
|
if (orderInfo == null) {
|
|
|
|
|
redisTemplate.delete(currentOrderKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return orderInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ShopEatTypeInfoDTO checkEatModel(Integer shopId, String useType) {
|
|
|
|
|
String eatModel = OrderUseTypeEnum.TAKEOUT.getValue().equals(useType) ? ShopInfoEatModelEnum.TAKE_OUT.getValue() : ShopInfoEatModelEnum.DINE_IN.getValue();
|
|
|
|
|
TbShopInfo shopInfo = mpShopInfoMapper.selectOne(new LambdaQueryWrapper<TbShopInfo>()
|
|
|
|
|
.eq(TbShopInfo::getId, shopId)
|
|
|
|
|
.eq(TbShopInfo::getStatus, 1));
|
|
|
|
|
if (shopInfo == null) {
|
|
|
|
|
throw new BadRequestException("店铺信息不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!shopInfo.getEatModel().contains(eatModel)) {
|
|
|
|
|
throw new BadRequestException("当前店铺未开启此就餐模式");
|
|
|
|
|
}
|
|
|
|
|
boolean isTakeout = ShopInfoEatModelEnum.TAKE_OUT.getValue().equals(eatModel);
|
|
|
|
|
// 是否是快餐版/先付费
|
|
|
|
|
boolean isMunchies = StrUtil.isNotBlank(shopInfo.getRegisterType()) &&
|
|
|
|
|
ShopInfoRegisterlEnum.MUNCHIES.getValue().equals(shopInfo.getRegisterType());
|
|
|
|
|
|
|
|
|
|
boolean isDineInAfter = !isMunchies && !isTakeout;
|
|
|
|
|
boolean isDineInBefore = isMunchies && !isTakeout;
|
|
|
|
|
|
|
|
|
|
return new ShopEatTypeInfoDTO(isTakeout, isMunchies, isDineInAfter, isDineInBefore, shopInfo, isTakeout ? OrderUseTypeEnum.TAKEOUT.getValue() :
|
|
|
|
|
isMunchies ? OrderUseTypeEnum.DINE_IN_BEFORE.getValue() : OrderUseTypeEnum.DINE_IN_AFTER.getValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String, Object> queryAll(TbShopTableQueryCriteria criteria, Pageable pageable) {
|
|
|
|
|
@@ -348,11 +405,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public TbCashierCart addCartForUser(AddCartDTO addCartDTO) {
|
|
|
|
|
if (StrUtil.isNotBlank(addCartDTO.getTableId())) {
|
|
|
|
|
checkTableIsOpen(addCartDTO.getTableId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int currentPlaceNum = getCurrentPlaceNum(addCartDTO.getTableId(), addCartDTO.getShopId().toString(), addCartDTO.getUseType());
|
|
|
|
|
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(addCartDTO.getShopId(), addCartDTO.getUseType());
|
|
|
|
|
|
|
|
|
|
TbProductSku productSku = productMapper.selectSkuByIdAndShopId(addCartDTO.getShopId(), addCartDTO.getSkuId());
|
|
|
|
|
TbProduct product = productMapper.selectByIdAndShopId(addCartDTO.getShopId(), addCartDTO.getProductId());
|
|
|
|
|
@@ -369,21 +422,23 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<TbCashierCart> query = new LambdaQueryWrapper<TbCashierCart>()
|
|
|
|
|
.eq(TbCashierCart::getShopId, addCartDTO.getShopId())
|
|
|
|
|
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
|
|
|
|
|
.eq(TbCashierCart::getSkuId, addCartDTO.getSkuId())
|
|
|
|
|
.eq(TbCashierCart::getProductId, addCartDTO.getProductId())
|
|
|
|
|
.isNull(TbCashierCart::getPlaceNum)
|
|
|
|
|
.eq(TbCashierCart::getUseType, addCartDTO.getUseType())
|
|
|
|
|
.in(TbCashierCart::getStatus, "create", "refund")
|
|
|
|
|
.and(query2 -> query2.and(query3 -> query3.eq(TbCashierCart::getTradeDay, DateUtils.getDay())
|
|
|
|
|
.eq(TbCashierCart::getMasterId, addCartDTO.getMasterId()))
|
|
|
|
|
.or((query4 -> query4.isNull(TbCashierCart::getTradeDay)
|
|
|
|
|
.eq(TbCashierCart::getMasterId, ""))));
|
|
|
|
|
.eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType())
|
|
|
|
|
.eq(TbCashierCart::getStatus, "create")
|
|
|
|
|
.and(q -> q.eq(TbCashierCart::getMasterId, addCartDTO.getMasterId()).or().isNull(TbCashierCart::getMasterId));
|
|
|
|
|
|
|
|
|
|
if (addCartDTO.getCartId() != null) {
|
|
|
|
|
query.eq(TbCashierCart::getId, addCartDTO.getCartId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (StrUtil.isNotBlank(addCartDTO.getTableId())) {
|
|
|
|
|
// 外带只查询pc和收银机商品
|
|
|
|
|
if (shopEatTypeInfoDTO.isTakeout()) {
|
|
|
|
|
query.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, ""))
|
|
|
|
|
.in(TbCashierCart::getPlatformType, "pc", "cash");
|
|
|
|
|
}else {
|
|
|
|
|
query.eq(TbCashierCart::getTableId, addCartDTO.getTableId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -974,46 +1029,33 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
TbShopInfo shopInfo = shopInfoRepository.findById(createOrderDTO.getShopId()).orElse(null);
|
|
|
|
|
if (shopInfo == null) throw new BadRequestException("店铺信息不存在");
|
|
|
|
|
|
|
|
|
|
// 就餐模式信息
|
|
|
|
|
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(createOrderDTO.getShopId(), createOrderDTO.getUseType());
|
|
|
|
|
|
|
|
|
|
// 传递orderId直接取否则取当前缓存id
|
|
|
|
|
Integer orderId = shopEatTypeInfoDTO.isDineInAfter() ?
|
|
|
|
|
Integer.valueOf(getCurrentOrderId(createOrderDTO.getTableId(), createOrderDTO.getShopId())) : null;
|
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
|
|
|
|
|
.eq(TbCashierCart::getShopId, createOrderDTO.getShopId())
|
|
|
|
|
.eq(TbCashierCart::getUseType, createOrderDTO.getUseType())
|
|
|
|
|
.in(TbCashierCart::getStatus, "create")
|
|
|
|
|
.and(q -> q.eq(TbCashierCart::getMasterId, createOrderDTO.getMasterId()).or().isNull(TbCashierCart::getMasterId));
|
|
|
|
|
|
|
|
|
|
// 非堂食校验台桌状态
|
|
|
|
|
TbShopTable tbShopTable = null;
|
|
|
|
|
boolean tableFlag = StrUtil.isNotBlank(createOrderDTO.getTableId());
|
|
|
|
|
if (tableFlag) {
|
|
|
|
|
if (shopEatTypeInfoDTO.isTakeout()) {
|
|
|
|
|
queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, ""))
|
|
|
|
|
.in(TbCashierCart::getPlatformType, OrderPlatformTypeEnum.PC.getValue(), OrderPlatformTypeEnum.CASH.getValue());
|
|
|
|
|
}else {
|
|
|
|
|
queryWrapper.eq(TbCashierCart::getTableId, createOrderDTO.getTableId());
|
|
|
|
|
|
|
|
|
|
tbShopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
|
|
|
|
|
.eq(TbShopTable::getQrcode, createOrderDTO.getTableId())
|
|
|
|
|
.in(TbShopTable::getStatus, "idle", "using"));
|
|
|
|
|
|
|
|
|
|
if (tbShopTable == null) {
|
|
|
|
|
throw new BadRequestException("台桌未开台或不存在");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 传递orderId直接取否则取当前缓存id
|
|
|
|
|
String currentOrderKey = RedisConstant.getCurrentOrderKey(createOrderDTO.getTableId(),
|
|
|
|
|
createOrderDTO.getShopId().toString());
|
|
|
|
|
String orderIdValue = redisTemplate.opsForValue().get(currentOrderKey);
|
|
|
|
|
Integer orderId = orderIdValue == null ? null : Integer.parseInt(orderIdValue);
|
|
|
|
|
orderId = tableFlag ? createOrderDTO.getOrderId() != null ? createOrderDTO.getOrderId() : orderId : null;
|
|
|
|
|
|
|
|
|
|
// 查询订单
|
|
|
|
|
TbOrderInfo orderInfo = null;
|
|
|
|
|
if (orderId != null) {
|
|
|
|
|
orderInfo = orderInfoMapper.selectById(orderId);
|
|
|
|
|
|
|
|
|
|
if (orderInfo == null || !"unpaid".equals(orderInfo.getStatus())) {
|
|
|
|
|
redisTemplate.delete(currentOrderKey);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String day = DateUtils.getDay();
|
|
|
|
|
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
|
|
|
|
|
.eq(TbCashierCart::getShopId, createOrderDTO.getShopId())
|
|
|
|
|
.in(TbCashierCart::getStatus, "create")
|
|
|
|
|
.eq(TbCashierCart::getUseType, createOrderDTO.getUseType())
|
|
|
|
|
.and(query2 -> query2.or(query3 -> query3.eq(TbCashierCart::getTradeDay, DateUtils.getDay())
|
|
|
|
|
.eq(TbCashierCart::getMasterId, createOrderDTO.getMasterId()))
|
|
|
|
|
.or((query4 -> query4.isNull(TbCashierCart::getTradeDay)
|
|
|
|
|
.isNull(TbCashierCart::getMasterId))));
|
|
|
|
|
|
|
|
|
|
if (StrUtil.isNotBlank(createOrderDTO.getTableId())) {
|
|
|
|
|
queryWrapper.eq(TbCashierCart::getTableId, createOrderDTO.getTableId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1023,20 +1065,41 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
throw new BadRequestException("购物车为空,请先添加商品");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ArrayList<Integer> cartIdList = new ArrayList<>();
|
|
|
|
|
for (TbCashierCart tbCashierCart : cashierCarts) {
|
|
|
|
|
if (tbCashierCart.getOrderId() != null) {
|
|
|
|
|
orderId = tbCashierCart.getOrderId();
|
|
|
|
|
}
|
|
|
|
|
cartIdList.add(tbCashierCart.getId());
|
|
|
|
|
}
|
|
|
|
|
// 查询历史orderDetail
|
|
|
|
|
Integer finalOrderId = orderId;
|
|
|
|
|
LambdaQueryWrapper<TbOrderDetail> query = new LambdaQueryWrapper<TbOrderDetail>()
|
|
|
|
|
.and(q -> q.in(TbOrderDetail::getCartId, cartIdList).or().eq(TbOrderDetail::getOrderId, finalOrderId))
|
|
|
|
|
.eq(TbOrderDetail::getShopId, createOrderDTO.getShopId());
|
|
|
|
|
|
|
|
|
|
List<TbOrderDetail> oldOrderDetailList = orderDetailMapper.selectList(query);
|
|
|
|
|
ArrayList<Integer> removeOrderDetailIds = new ArrayList<>();
|
|
|
|
|
HashMap<String, TbOrderDetail> oldOrderDetailMap = new HashMap<>();
|
|
|
|
|
oldOrderDetailList.forEach(item -> {
|
|
|
|
|
if (cartIdList.contains(item.getCartId())) {
|
|
|
|
|
oldOrderDetailMap.put(item.getOrderId().toString() + item.getCartId(), item);
|
|
|
|
|
}else {
|
|
|
|
|
removeOrderDetailIds.add(item.getId());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
BigDecimal totalAmount = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal packAMount = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal feeAmount = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal saleAmount = BigDecimal.ZERO;
|
|
|
|
|
// 当前下单次数
|
|
|
|
|
int placeNum = StrUtil.isNotBlank(createOrderDTO.getTableId()) ? getCurrentPlaceNum(createOrderDTO.getTableId(), createOrderDTO.getShopId().toString(), createOrderDTO.getUseType()) : 1;
|
|
|
|
|
int placeNum = !shopEatTypeInfoDTO.isTakeout() ? getCurrentPlaceNum(createOrderDTO.getTableId(), createOrderDTO.getShopId().toString(), createOrderDTO.getUseType()) : 1;
|
|
|
|
|
List<TbOrderDetail> orderDetails = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
BigDecimal mealAmount = null;
|
|
|
|
|
Integer mealNum = null;
|
|
|
|
|
boolean unAdd = cashierCarts.stream().noneMatch(item -> item.getPlaceNum() == null);
|
|
|
|
|
if (ShopInfoTypeEnums.RESTAURANT.getValue().equals(shopInfo.getRegisterType()) && addMaterId && unAdd) {
|
|
|
|
|
throw new BadRequestException("此次未添加新商品,清先添加商品");
|
|
|
|
|
}
|
|
|
|
|
boolean hasNewInfo = false;
|
|
|
|
|
for (TbCashierCart cashierCart : cashierCarts) {
|
|
|
|
|
if ("-999".equals(cashierCart.getProductId())) {
|
|
|
|
|
mealAmount = cashierCart.getTotalAmount();
|
|
|
|
|
@@ -1049,7 +1112,15 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TbProductSku productSku = productSkuRepository.findById(Integer.valueOf(cashierCart.getSkuId())).orElse(null);
|
|
|
|
|
TbOrderDetail orderDetail = new TbOrderDetail();
|
|
|
|
|
TbOrderDetail orderDetail = null;
|
|
|
|
|
if (cashierCart.getOrderId() != null) {
|
|
|
|
|
orderDetail = oldOrderDetailMap.get(cashierCart.getOrderId().toString() + cashierCart.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (orderDetail == null) {
|
|
|
|
|
orderDetail = new TbOrderDetail();
|
|
|
|
|
hasNewInfo = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Objects.nonNull(productSku)) {
|
|
|
|
|
saleAmount = saleAmount.add(productSku.getSalePrice());
|
|
|
|
|
@@ -1070,26 +1141,32 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
orderDetail.setUseType(createOrderDTO.getUseType());
|
|
|
|
|
orderDetail.setProductImg(cashierCart.getCoverImg());
|
|
|
|
|
orderDetail.setCartId(cashierCart.getId());
|
|
|
|
|
orderDetails.add(orderDetail);
|
|
|
|
|
if (cashierCart.getOrderId() != null) {
|
|
|
|
|
orderId = cashierCart.getOrderId();
|
|
|
|
|
}
|
|
|
|
|
orderDetail.setOrderId(orderId);
|
|
|
|
|
orderDetail.setPlaceNum(placeNum);
|
|
|
|
|
orderDetails.add(orderDetail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (shopInfo.getIsTableFee() != null && shopInfo.getIsTableFee() == 0
|
|
|
|
|
&& (OrderUseTypeEnum.DINE_IN_BEFORE.getValue().equals(createOrderDTO.getUseType()) || OrderUseTypeEnum.DINE_IN_AFTER.getValue().equals(createOrderDTO.getUseType()))
|
|
|
|
|
&& !shopEatTypeInfoDTO.isTakeout()
|
|
|
|
|
&& mealAmount == null) {
|
|
|
|
|
throw new BadRequestException("请选择用餐人数");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询订单
|
|
|
|
|
TbOrderInfo orderInfo = null;
|
|
|
|
|
if (orderId != null) {
|
|
|
|
|
orderInfo = orderInfoMapper.selectById(orderId);
|
|
|
|
|
}
|
|
|
|
|
// 是否是第一次创建订单
|
|
|
|
|
boolean isFirst = false;
|
|
|
|
|
// 修改订单信息
|
|
|
|
|
if (orderInfo != null) {
|
|
|
|
|
// 删除历史订单
|
|
|
|
|
// 更新取餐号
|
|
|
|
|
orderInfo.setOutNumber(updateOutNumber(String.valueOf(createOrderDTO.getShopId())).toString());
|
|
|
|
|
orderDetailMapper.delete(new LambdaQueryWrapper<TbOrderDetail>().eq(TbOrderDetail::getOrderId, orderId));
|
|
|
|
|
orderInfo.setUpdatedAt(System.currentTimeMillis());
|
|
|
|
|
orderInfo.setSettlementAmount(totalAmount);
|
|
|
|
|
orderInfo.setAmount(totalAmount);
|
|
|
|
|
@@ -1100,16 +1177,17 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
orderInfo.setFreightAmount(feeAmount);
|
|
|
|
|
orderInfo.setProductAmount(saleAmount);
|
|
|
|
|
orderInfo.setTradeDay(DateUtils.getDay());
|
|
|
|
|
orderInfo.setUseType(createOrderDTO.isPostPay() ? "postPay" : "afterPay");
|
|
|
|
|
orderInfo.setUseType(createOrderDTO.getUseType());
|
|
|
|
|
orderInfo.setCreatedAt(DateUtil.current());
|
|
|
|
|
orderInfo.setSeatAmount(mealAmount);
|
|
|
|
|
orderInfo.setSeatCount(mealNum);
|
|
|
|
|
if (!unAdd) {
|
|
|
|
|
// 存在新添加的商品,增加下单次数
|
|
|
|
|
if (hasNewInfo) {
|
|
|
|
|
orderInfo.setPlaceNum(placeNum);
|
|
|
|
|
}
|
|
|
|
|
orderInfoMapper.updateById(orderInfo);
|
|
|
|
|
} else {
|
|
|
|
|
isFirst = true;
|
|
|
|
|
String orderNo = generateOrderNumber();
|
|
|
|
|
orderInfo = new TbOrderInfo();
|
|
|
|
|
orderInfo.setOrderNo(orderNo);
|
|
|
|
|
@@ -1127,7 +1205,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
orderInfo.setOrderType("cash");
|
|
|
|
|
orderInfo.setShopId(createOrderDTO.getShopId().toString());
|
|
|
|
|
orderInfo.setRefundAble(1);
|
|
|
|
|
orderInfo.setTradeDay(day);
|
|
|
|
|
orderInfo.setTradeDay(cn.ysk.cashier.utils.DateUtils.getDay());
|
|
|
|
|
orderInfo.setMasterId(createOrderDTO.getMasterId());
|
|
|
|
|
orderInfo.setOutNumber(createOrderDTO.getMasterId());
|
|
|
|
|
orderInfo.setRemark(createOrderDTO.getNote());
|
|
|
|
|
@@ -1145,11 +1223,6 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
}
|
|
|
|
|
orderInfo.setMerchantId(merchantAccount.getId().toString());
|
|
|
|
|
orderInfoMapper.insert(orderInfo);
|
|
|
|
|
|
|
|
|
|
// 台桌下单才保存订单信息
|
|
|
|
|
if (tableFlag) {
|
|
|
|
|
redisTemplate.opsForValue().set(currentOrderKey, orderInfo.getId().toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1157,12 +1230,13 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
orderId = orderInfo.getId();
|
|
|
|
|
for (TbOrderDetail orderDetail : orderDetails) {
|
|
|
|
|
orderDetail.setOrderId(orderId);
|
|
|
|
|
orderDetailMapper.insert(orderDetail);
|
|
|
|
|
}
|
|
|
|
|
// 删除已经移除购物车的订单 修改并保存数据
|
|
|
|
|
mpOrderDetailService.saveOrUpdateBatch(orderDetails);
|
|
|
|
|
orderDetailMapper.deleteBatchIds(removeOrderDetailIds);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 更新购物车记录的orderId
|
|
|
|
|
// 是否是第一次添加的商品
|
|
|
|
|
boolean isFirst = true;
|
|
|
|
|
for (TbCashierCart cashierCart : cashierCarts) {
|
|
|
|
|
if (!"-999".equals(cashierCart.getProductId())) {
|
|
|
|
|
TbProduct product = productMapper.selectById(cashierCart.getProductId());
|
|
|
|
|
@@ -1171,10 +1245,9 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
log.info("下单,开始校验库存预警,购物车id:{}", cashierCart.getId());
|
|
|
|
|
CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(productSku, product, Integer.valueOf(cashierCart.getShopId()), cashierCart.getNumber()));
|
|
|
|
|
// 已经添加的商品,修改数量
|
|
|
|
|
isFirst = updateStock(cashierCart);
|
|
|
|
|
updateStock(cashierCart);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cashierCart.setOrderId(orderId);
|
|
|
|
|
cashierCart.setUpdatedAt(System.currentTimeMillis());
|
|
|
|
|
cashierCart.setStatus("pending".equals(orderInfo.getStatus()) ? "refund" : cashierCart.getStatus());
|
|
|
|
|
@@ -1183,17 +1256,17 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
}
|
|
|
|
|
cashierCartMapper.updateById(cashierCart);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isFirst) {
|
|
|
|
|
// 后付费,不增加当前台桌取餐号
|
|
|
|
|
if (createOrderDTO.isPostPay()) {
|
|
|
|
|
addGlobalCode(day, "pc", String.valueOf(createOrderDTO.getShopId()));
|
|
|
|
|
if (!shopEatTypeInfoDTO.isTakeout()) {
|
|
|
|
|
addGlobalCode(cn.ysk.cashier.utils.DateUtils.getDay(), "pc", String.valueOf(createOrderDTO.getShopId()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!createOrderDTO.isPostPay() || (addMaterId && "pending".equals(orderInfo.getStatus()))) {
|
|
|
|
|
String key = "SHOP:CODE:USER:pc" + ":" + createOrderDTO.getShopId() + ":" + day + ":" + orderInfo.getTableId();
|
|
|
|
|
if (!shopEatTypeInfoDTO.isTakeout() || (addMaterId && "pending".equals(orderInfo.getStatus()))) {
|
|
|
|
|
String key = "SHOP:CODE:USER:pc" + ":" + createOrderDTO.getShopId() + ":" + cn.ysk.cashier.utils.DateUtils.getDay() + ":" + orderInfo.getTableId();
|
|
|
|
|
redisTemplate.delete(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 推送耗材信息
|
|
|
|
|
@@ -1526,18 +1599,18 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|
|
|
|
return cashierCartMapper.update(null, queryWrapper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getCurrentOrderId(String tableId, String shopId) {
|
|
|
|
|
String currentOrderKey = RedisConstant.getCurrentOrderKey(tableId, shopId);
|
|
|
|
|
private String getCurrentOrderId(String tableId, Object shopId) {
|
|
|
|
|
String currentOrderKey = RedisConstant.getCurrentOrderKey(tableId, shopId.toString());
|
|
|
|
|
return redisTemplate.opsForValue().get(currentOrderKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setCurrentOrderId(String tableId, String shopId, String orderId) {
|
|
|
|
|
String currentOrderKey = RedisConstant.getCurrentOrderKey(tableId, shopId);
|
|
|
|
|
private void setCurrentOrderId(String tableId, Object shopId, String orderId) {
|
|
|
|
|
String currentOrderKey = RedisConstant.getCurrentOrderKey(tableId, shopId.toString());
|
|
|
|
|
redisTemplate.opsForValue().set(currentOrderKey, orderId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String removeCurrentOrderId(String tableId, String shopId) {
|
|
|
|
|
String currentOrderKey = RedisConstant.getCurrentOrderKey(tableId, shopId);
|
|
|
|
|
private String removeCurrentOrderId(String tableId, Object shopId) {
|
|
|
|
|
String currentOrderKey = RedisConstant.getCurrentOrderKey(tableId, shopId.toString());
|
|
|
|
|
String orderId = redisTemplate.opsForValue().get(currentOrderKey);
|
|
|
|
|
redisTemplate.delete(currentOrderKey);
|
|
|
|
|
return orderId;
|
|
|
|
|
|