feat: 转台并台实现
This commit is contained in:
@@ -143,6 +143,14 @@ public class OrderController {
|
||||
return orderService.createOrder(orderVo, clientType, token, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转台并台
|
||||
*/
|
||||
@PutMapping("/switch")
|
||||
public ResponseEntity<?> switchTable(@Validated @RequestBody SwitchTableDTO switchTableDTO, @RequestHeader("token") String token) {
|
||||
return ResponseEntity.ok(orderService.switchTable(switchTableDTO, token));
|
||||
}
|
||||
|
||||
@PostMapping("/createBackOrder")
|
||||
public Result createBackOrder(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.chaozhanggui.system.cashierservice.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class SwitchTableDTO {
|
||||
@NotNull
|
||||
private Integer shopId;
|
||||
@NotEmpty(message = "取餐码不为空")
|
||||
private String masterId;
|
||||
private Integer orderId;
|
||||
private List<Integer> cartIds;
|
||||
private Boolean isFull;
|
||||
@NotEmpty(message = "当前台桌id不为空")
|
||||
private String currentTableId;
|
||||
@NotEmpty(message = "目标台桌id不为空")
|
||||
private String targetTableId;
|
||||
}
|
||||
@@ -61,5 +61,17 @@ public interface MpCashierCartService extends IService<TbCashierCart> {
|
||||
* @param statuses 状态
|
||||
*/
|
||||
List<TbCashierCart> selectByIds(Integer shopId, Integer orderId, List<Integer> ids, TableConstant.OrderInfo.Status... statuses);
|
||||
|
||||
/**
|
||||
* 根据就餐模式查询购物车信息
|
||||
* @param shopEatTypeInfoDTO 就餐模式
|
||||
* @param masterId 取餐码
|
||||
* @param orderId 订单id
|
||||
* @param onlySearchPc 只查询pc
|
||||
* @param statuses 状态
|
||||
*/
|
||||
List<TbCashierCart> selectByShopEatTypeAndOrderId(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId, Integer orderId, boolean onlySearchPc, TableConstant.OrderInfo.Status... statuses);
|
||||
|
||||
Long countByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId, Integer orderId, boolean onlySearchPc, TableConstant.OrderInfo.Status... statuses);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,5 +15,12 @@ import java.util.List;
|
||||
*/
|
||||
public interface MpShopTableService extends IService<TbShopTable> {
|
||||
|
||||
/**
|
||||
* 查询台桌信息
|
||||
* @param tableId 台桌id
|
||||
* @param shopId 店铺id
|
||||
* @return 台桌信息
|
||||
*/
|
||||
TbShopTable selectByTableId(String tableId, Integer shopId);
|
||||
}
|
||||
|
||||
|
||||
@@ -2392,4 +2392,120 @@ public class OrderService {
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Object switchTable(SwitchTableDTO switchTableDTO, String token) {
|
||||
// 查询当前台桌信息
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(switchTableDTO.getShopId(), switchTableDTO.getCurrentTableId());
|
||||
ShopEatTypeInfoDTO targetShopEatTypeInfoDTO = checkEatModel(switchTableDTO.getShopId(), switchTableDTO.getTargetTableId());
|
||||
if (!shopEatTypeInfoDTO.isDineInAfter()) {
|
||||
throw new MsgException("仅后付费模式支持转台");
|
||||
}
|
||||
TbShopTable shopTable = mpShopTableService.selectByTableId(switchTableDTO.getTargetTableId(), switchTableDTO.getShopId());
|
||||
if (shopTable == null) {
|
||||
throw new MsgException("目标台桌信息不存在");
|
||||
}
|
||||
|
||||
if (TableConstant.ShopTable.State.CLEANING.getValue().equals(shopTable.getStatus())) {
|
||||
throw new MsgException("当前台桌清理中,不能转台");
|
||||
}
|
||||
|
||||
List<TbCashierCart> cashierCarts;
|
||||
long totalSize = 99999;
|
||||
if (switchTableDTO.getIsFull() != null && switchTableDTO.getIsFull()) {
|
||||
cashierCarts = mpCashierCartService.selectByShopEatTypeAndOrderId(shopEatTypeInfoDTO, switchTableDTO.getMasterId(), switchTableDTO.getOrderId(),
|
||||
true, TableConstant.OrderInfo.Status.CREATE, TableConstant.OrderInfo.Status.RETURN);
|
||||
}else {
|
||||
if (switchTableDTO.getCartIds().isEmpty()) {
|
||||
throw new MsgException("请选择转单商品");
|
||||
}
|
||||
|
||||
totalSize = mpCashierCartService.countByShopEatType(shopEatTypeInfoDTO, switchTableDTO.getMasterId(), switchTableDTO.getOrderId(),
|
||||
true, TableConstant.OrderInfo.Status.CREATE, TableConstant.OrderInfo.Status.RETURN);
|
||||
cashierCarts = mpCashierCartService.selectByIds(switchTableDTO.getShopId(), null, switchTableDTO.getCartIds(),
|
||||
TableConstant.OrderInfo.Status.CREATE, TableConstant.OrderInfo.Status.RETURN);
|
||||
}
|
||||
|
||||
if (cashierCarts.isEmpty()) {
|
||||
throw new MsgException("当前台桌购物车为空");
|
||||
}
|
||||
|
||||
String masterId = ((JSONObject)createCode(switchTableDTO.getShopId().toString(), "pc", "", "0", switchTableDTO.getTargetTableId()).getData()).getString("code");
|
||||
// String masterId = getMasterId(switchTableDTO.getShopId(), switchTableDTO.getTargetTableId(), null).getString("masterId");
|
||||
// 查询目标购物车
|
||||
List<TbCashierCart> targetCarts = mpCashierCartService.selectByShopEatTypeAndOrderId(targetShopEatTypeInfoDTO, masterId, null, false);
|
||||
TbCashierCart targetSeatFee = null;
|
||||
Integer targetOrderId = null;
|
||||
for (TbCashierCart targetCart : targetCarts) {
|
||||
if (TableConstant.CART_SEAT_ID.equals(targetCart.getProductId())) {
|
||||
targetSeatFee = targetCart;
|
||||
}
|
||||
|
||||
if (targetCart.getOrderId() != null) {
|
||||
targetOrderId = targetCart.getOrderId();
|
||||
}
|
||||
}
|
||||
|
||||
// 修改原有购物车数据
|
||||
ArrayList<Integer> cartIds = new ArrayList<>();
|
||||
Integer orderId = switchTableDTO.getOrderId();
|
||||
TbCashierCart currentSeatFee = null;
|
||||
ArrayList<TbCashierCart> updateCartInfos = new ArrayList<>();
|
||||
for (TbCashierCart item : cashierCarts) {
|
||||
if (targetSeatFee == null || !TableConstant.CART_SEAT_ID.equals(item.getProductId())) {
|
||||
item.setTableId(switchTableDTO.getTargetTableId());
|
||||
item.setMasterId(masterId);
|
||||
updateCartInfos.add(item);
|
||||
}
|
||||
cartIds.add(item.getId());
|
||||
|
||||
if (item.getOrderId() != null) {
|
||||
orderId = item.getOrderId();
|
||||
}
|
||||
|
||||
if (TableConstant.CART_SEAT_ID.equals(item.getProductId())) {
|
||||
currentSeatFee = item;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentSeatFee != null && targetSeatFee != null) {
|
||||
targetSeatFee.setNumber(currentSeatFee.getNumber().add(targetSeatFee.getNumber()));
|
||||
targetSeatFee.setTotalNumber(currentSeatFee.getTotalNumber().add(targetSeatFee.getTotalNumber()));
|
||||
targetSeatFee.setTotalAmount(targetSeatFee.getSalePrice().multiply(targetSeatFee.getTotalNumber()));
|
||||
mpCashierCartService.updateById(targetSeatFee);
|
||||
mpCashierCartService.removeById(currentSeatFee.getId());
|
||||
}
|
||||
mpCashierCartService.updateBatchById(updateCartInfos);
|
||||
mpCashierCartService.update(new LambdaUpdateWrapper<TbCashierCart>()
|
||||
.in(TbCashierCart::getId, cartIds)
|
||||
.set(TbCashierCart::getOrderId, null)
|
||||
.set(TbCashierCart::getPlaceNum, null));
|
||||
mpOrderDetailService.removeByCartIds(cartIds);
|
||||
|
||||
// 删除原有台桌detail和order信息
|
||||
if (orderId != null && ((switchTableDTO.getIsFull() != null && switchTableDTO.getIsFull()) || switchTableDTO.getCartIds().size() == totalSize)) {
|
||||
mpOrderInfoService.removeById(orderId);
|
||||
}
|
||||
|
||||
if (switchTableDTO.getIsFull() != null && !switchTableDTO.getIsFull() && switchTableDTO.getCartIds().size() != totalSize){
|
||||
// 重新创建订单数据
|
||||
OrderVo createOrderDTO = new OrderVo();
|
||||
createOrderDTO.setMasterId(switchTableDTO.getMasterId());
|
||||
createOrderDTO.setShopId(switchTableDTO.getShopId());
|
||||
createOrderDTO.setTableId(switchTableDTO.getCurrentTableId());
|
||||
createOrder(createOrderDTO, "pc", token, switchTableDTO.getOrderId());
|
||||
}
|
||||
|
||||
if (targetOrderId != null) {
|
||||
// 重新创建订单数据
|
||||
OrderVo createOrderDTO = new OrderVo();
|
||||
createOrderDTO.setMasterId(masterId);
|
||||
createOrderDTO.setShopId(switchTableDTO.getShopId());
|
||||
createOrderDTO.setTableId(switchTableDTO.getTargetTableId());
|
||||
createOrder(createOrderDTO, "pc", token, targetOrderId);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.chaozhanggui.system.cashierservice.bean.OrderPlatformTypeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.bean.constant.TableConstant;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbCashierCart;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
|
||||
@@ -17,8 +19,10 @@ import com.chaozhanggui.system.cashierservice.service.MpCashierCartService;
|
||||
import com.chaozhanggui.system.cashierservice.service.MpOrderDetailService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* (TbShopPermission)表服务实现类
|
||||
@@ -96,7 +100,9 @@ public class MpCashierCartServiceImpl extends ServiceImpl<MPCashierCartMapper, T
|
||||
.eq(TbCashierCart::getShopId, shopId)
|
||||
.eq(TbCashierCart::getId, cartId);
|
||||
if (statuses.length != 0) {
|
||||
queryWrapper.in(TbCashierCart::getStatus, CollUtil.newArrayList(statuses));
|
||||
queryWrapper.in(TbCashierCart::getStatus, Arrays.stream(statuses)
|
||||
.map(TableConstant.OrderInfo.Status::getValue)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
return getOne(queryWrapper);
|
||||
}
|
||||
@@ -104,13 +110,99 @@ public class MpCashierCartServiceImpl extends ServiceImpl<MPCashierCartMapper, T
|
||||
public List<TbCashierCart> selectByIds(Integer shopId, Integer orderId, List<Integer> ids, TableConstant.OrderInfo.Status... statuses) {
|
||||
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, shopId)
|
||||
.eq(TbCashierCart::getOrderId, orderId)
|
||||
.in(TbCashierCart::getId, ids);
|
||||
if (orderId != null) {
|
||||
queryWrapper.eq(TbCashierCart::getOrderId, orderId);
|
||||
}
|
||||
if (statuses.length != 0) {
|
||||
queryWrapper.in(TbCashierCart::getStatus, CollUtil.newArrayList(statuses));
|
||||
queryWrapper.in(TbCashierCart::getStatus, Arrays.stream(statuses)
|
||||
.map(TableConstant.OrderInfo.Status::getValue)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
return list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TbCashierCart> selectByShopEatTypeAndOrderId(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId,
|
||||
Integer orderId, boolean onlySearchPc, TableConstant.OrderInfo.Status... statuses) {
|
||||
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, shopEatTypeInfoDTO.getShopId())
|
||||
.eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType())
|
||||
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
|
||||
.and(q -> q.eq(TbCashierCart::getMasterId, masterId).or().isNull(TbCashierCart::getMasterId));
|
||||
|
||||
if (statuses.length == 0) {
|
||||
queryWrapper.in(TbCashierCart::getStatus, "create", "return");
|
||||
} else {
|
||||
queryWrapper.in(TbCashierCart::getStatus, Arrays.stream(statuses)
|
||||
.map(TableConstant.OrderInfo.Status::getValue)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
if (orderId != null) {
|
||||
queryWrapper.and(q -> q.eq(TbCashierCart::getOrderId, orderId)
|
||||
.or().isNull(TbCashierCart::getOrderId));
|
||||
}
|
||||
|
||||
if (onlySearchPc) {
|
||||
queryWrapper.ne(TbCashierCart::getPlatformType, "mimiapp");
|
||||
}
|
||||
|
||||
// 非堂食校验台桌状态
|
||||
if (shopEatTypeInfoDTO.isTakeout()) {
|
||||
queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, ""))
|
||||
.in(TbCashierCart::getPlatformType, OrderPlatformTypeEnum.PC.getValue(), OrderPlatformTypeEnum.CASH.getValue());
|
||||
} else {
|
||||
if (StrUtil.isNotBlank(shopEatTypeInfoDTO.getTableId())) {
|
||||
queryWrapper.eq(TbCashierCart::getTableId, shopEatTypeInfoDTO.getTableId());
|
||||
} else {
|
||||
queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, ""));
|
||||
}
|
||||
|
||||
}
|
||||
return list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId,
|
||||
Integer orderId, boolean onlySearchPc, TableConstant.OrderInfo.Status... statuses) {
|
||||
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, shopEatTypeInfoDTO.getShopId())
|
||||
.eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType())
|
||||
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
|
||||
.and(q -> q.eq(TbCashierCart::getMasterId, masterId).or().isNull(TbCashierCart::getMasterId));
|
||||
|
||||
if (statuses.length == 0) {
|
||||
queryWrapper.in(TbCashierCart::getStatus, "create", "return");
|
||||
} else {
|
||||
queryWrapper.in(TbCashierCart::getStatus, Arrays.stream(statuses)
|
||||
.map(TableConstant.OrderInfo.Status::getValue)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
if (orderId != null) {
|
||||
queryWrapper.and(q -> q.eq(TbCashierCart::getOrderId, orderId)
|
||||
.or().isNull(TbCashierCart::getOrderId));
|
||||
}
|
||||
|
||||
if (onlySearchPc) {
|
||||
queryWrapper.ne(TbCashierCart::getPlatformType, "mimiapp");
|
||||
}
|
||||
|
||||
// 非堂食校验台桌状态
|
||||
if (shopEatTypeInfoDTO.isTakeout()) {
|
||||
queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, ""))
|
||||
.in(TbCashierCart::getPlatformType, OrderPlatformTypeEnum.PC.getValue(), OrderPlatformTypeEnum.CASH.getValue());
|
||||
} else {
|
||||
if (StrUtil.isNotBlank(shopEatTypeInfoDTO.getTableId())) {
|
||||
queryWrapper.eq(TbCashierCart::getTableId, shopEatTypeInfoDTO.getTableId());
|
||||
} else {
|
||||
queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, ""));
|
||||
}
|
||||
|
||||
}
|
||||
return (long) count(queryWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.chaozhanggui.system.cashierservice.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.chaozhanggui.system.cashierservice.bean.constant.TableConstant;
|
||||
@@ -22,6 +23,12 @@ import java.util.List;
|
||||
@Service
|
||||
public class MpShopTableServiceImpl extends ServiceImpl<MpShopTableMapper, TbShopTable> implements MpShopTableService {
|
||||
|
||||
@Override
|
||||
public TbShopTable selectByTableId(String tableId, Integer shopId) {
|
||||
return getOne(new LambdaQueryWrapper<TbShopTable>()
|
||||
.eq(TbShopTable::getShopId, shopId)
|
||||
.eq(TbShopTable::getQrcode, tableId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user