1.代客下单 新增后付款下单
This commit is contained in:
@@ -19,11 +19,13 @@ import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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.ShopWxMsgTypeEnum;
|
||||
import cn.ysk.cashier.enums.TableStateEnum;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mybatis.entity.TbShopOpenId;
|
||||
import cn.ysk.cashier.mybatis.mapper.*;
|
||||
@@ -101,11 +103,13 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||
private final WxAccountUtil wxAccountUtil;
|
||||
private final WxMsgUtils wxMsgUtils;
|
||||
private final TbShopPayTypeRepository payTypeRepository;
|
||||
private final MpShopTableMapper mpShopTableMapper;
|
||||
|
||||
/**
|
||||
* 桌码前缀
|
||||
*/
|
||||
private final String QRCODE = "https://kysh.sxczgkj.cn/codeplate?code=";
|
||||
private final RabbitMsgUtils rabbitMsgUtils;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryAll(TbShopTableQueryCriteria criteria, Pageable pageable) {
|
||||
@@ -276,8 +280,26 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||
return tbCashierCart;
|
||||
}
|
||||
|
||||
/**
|
||||
* 台桌状态校验
|
||||
* @param tableId 桌码
|
||||
* @return z
|
||||
*/
|
||||
private TbShopTable checkTableIsOpen(String tableId) {
|
||||
TbShopTable shopTable = tbShopTableRepository.findByQrcode(tableId);
|
||||
if (shopTable == null) {
|
||||
throw new BadRequestException("桌码不存在,桌码" + tableId);
|
||||
}
|
||||
if (!shopTable.getStatus().equals("opening") && !shopTable.getStatus().equals("idle")) {
|
||||
throw new BadRequestException("当前台桌非开台状态");
|
||||
}
|
||||
return shopTable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TbCashierCart addCartForUser(AddCartDTO addCartDTO) {
|
||||
checkTableIsOpen(addCartDTO.getTableId());
|
||||
|
||||
TbProductSku productSku = productMapper.selectSkuByIdAndShopId(addCartDTO.getShopId(), addCartDTO.getSkuId());
|
||||
TbProduct product = productMapper.selectByIdAndShopId(addCartDTO.getShopId(), addCartDTO.getProductId());
|
||||
|
||||
@@ -291,11 +313,6 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||
throw new BadRequestException("商品库存不足");
|
||||
}
|
||||
|
||||
TbShopTable shopTable = tbShopTableRepository.findByQrcode(addCartDTO.getTableId());
|
||||
if (shopTable == null) {
|
||||
throw new BadRequestException("桌码不存在,桌码" + addCartDTO.getTableId());
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<TbCashierCart> query = new LambdaQueryWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, addCartDTO.getShopId())
|
||||
.eq(TbCashierCart::getSkuId, addCartDTO.getSkuId())
|
||||
@@ -774,6 +791,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||
orderInfo.setTableId(String.valueOf(createOrderDTO.getTableId()));
|
||||
orderInfo.setSendType("table");
|
||||
orderInfo.setOrderType("cash");
|
||||
orderInfo.setUseType(createOrderDTO.isPostPay() ? "postPay" : "afterPay");
|
||||
orderInfo.setShopId(createOrderDTO.getShopId().toString());
|
||||
orderInfo.setRefundAble(1);
|
||||
orderInfo.setTradeDay(day);
|
||||
@@ -784,7 +802,6 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 添加订单详细数据
|
||||
orderId = orderInfo.getId();
|
||||
for (TbOrderDetail orderDetail : orderDetails) {
|
||||
@@ -816,6 +833,16 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||
|
||||
// 推送耗材信息
|
||||
pushConsMsg(orderInfo, cashierCarts);
|
||||
|
||||
// 后付款订单,修改台桌状态并打票
|
||||
if (createOrderDTO.isPostPay()) {
|
||||
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
||||
.eq(TbShopTable::getQrcode, createOrderDTO.getTableId())
|
||||
.set(TbShopTable::getStatus, "opening"));
|
||||
|
||||
rabbitMsgUtils.printTicket(String.valueOf(orderId));
|
||||
}
|
||||
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
@@ -947,6 +974,10 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||
return new BadRequestException("此订单不处于未支付状态");
|
||||
}
|
||||
|
||||
|
||||
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
||||
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
|
||||
.set(TbShopTable::getStatus, TableStateEnum.PAYING.getState()));
|
||||
// int count = shopInfoRepository.countSelectByShopIdAndPayType(orderInfo.getShopId(), "cash");
|
||||
// if (count < 1) {
|
||||
// return Result.fail(CodeEnum.PAYTYPENOEXIST);
|
||||
@@ -977,13 +1008,21 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.CART_ORDER_COLLECT_PUT, RabbitConstants.CART_ORDER_COLLECT_ROUTINGKEY_PUT, jsonObject.toJSONString(), new CorrelationData(UUID.randomUUID().toString()));
|
||||
|
||||
// 打印消息
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.PRINT_MECHINE_COLLECT_PUT, RabbitConstants.PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT, payDTO.getOrderId().toString(), new CorrelationData(UUID.randomUUID().toString()));
|
||||
if (StrUtil.isBlank(orderInfo.getUseType()) || orderInfo.getUseType().equals("afterPay")) {
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.PRINT_MECHINE_COLLECT_PUT, RabbitConstants.PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT, payDTO.getOrderId().toString(), new CorrelationData(UUID.randomUUID().toString()));
|
||||
}
|
||||
|
||||
// 发送库存记录mq消息
|
||||
JSONObject mqData = new JSONObject();
|
||||
mqData.put("orderId", payDTO.getOrderId());
|
||||
mqData.put("type", "pc");
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.EXCHANGE_STOCK_RECORD, RabbitConstants.ROUTING_STOCK_RECORD_SALE, mqData.toJSONString(), new CorrelationData(UUID.randomUUID().toString()));
|
||||
|
||||
// 修改台桌状态
|
||||
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
||||
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
|
||||
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user