diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java index 642dd8f..66a4127 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java @@ -4,6 +4,7 @@ package com.chaozhanggui.system.cashierservice.controller; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.entity.dto.ChoseCountDTO; +import com.chaozhanggui.system.cashierservice.entity.dto.ChoseEatModelDTO; import com.chaozhanggui.system.cashierservice.entity.dto.QuerySpecDTO; import com.chaozhanggui.system.cashierservice.service.CartService; import com.chaozhanggui.system.cashierservice.service.ProductService; @@ -107,6 +108,13 @@ public class ProductController { return Result.success(CodeEnum.SUCCESS, productService.choseCount(choseCountDTO)); } + @PostMapping("/choseEatModel") + public Result choseEatModel( + @Validated @RequestBody ChoseEatModelDTO choseEatModelDTO + ) { + return Result.success(CodeEnum.SUCCESS, productService.choseEatModel(choseEatModelDTO)); + } + @PostMapping("cleanCart") public Result cleanCart(@RequestBody JSONObject jsonObject) { log.info("清空购物车数据:{}", jsonObject); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/ChoseEatModelDTO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/ChoseEatModelDTO.java new file mode 100644 index 0000000..f27de02 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/ChoseEatModelDTO.java @@ -0,0 +1,16 @@ +package com.chaozhanggui.system.cashierservice.entity.dto; + +import lombok.Data; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +@Data +public class ChoseEatModelDTO { + @NotNull + private Integer shopId; + private String tableId; + @NotNull + private Integer userId; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 8dc7525..c83b500 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -8,15 +8,13 @@ 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.PlatformTypeEnum; import com.chaozhanggui.system.cashierservice.entity.Enum.ShopInfoEatModelEnum; -import com.chaozhanggui.system.cashierservice.entity.dto.ChoseCountDTO; -import com.chaozhanggui.system.cashierservice.entity.dto.HomeDto; -import com.chaozhanggui.system.cashierservice.entity.dto.QuerySpecDTO; -import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO; +import com.chaozhanggui.system.cashierservice.entity.dto.*; import com.chaozhanggui.system.cashierservice.entity.vo.*; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.mapper.MpCashierCartMapper; @@ -926,4 +924,24 @@ public class ProductService { return tbCashierCart; } + + public Object choseEatModel(ChoseEatModelDTO choseTableDTO) { + ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.checkEatModel(choseTableDTO.getTableId(), choseTableDTO.getShopId()); + if (!shopEatTypeInfoDTO.isTakeout()) { + TbShopTable shopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper() + .notIn(TbShopTable::getStatus, "closed", "cleaning") + .eq(TbShopTable::getQrcode, choseTableDTO.getTableId())); + + if (shopTable == null) { + throw new MsgException("台桌未开台或不存在"); + } + } + + return mpCashierCartMapper.update(null, new LambdaUpdateWrapper() + .eq(TbCashierCart::getShopId, choseTableDTO.getShopId()) + .eq(TbCashierCart::getUserId, choseTableDTO.getUserId()) + .isNull(TbCashierCart::getUseType) + .eq(TbCashierCart::getStatus, "create") + .set(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType())) ; + } }