diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java index 64491fc..945551a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java @@ -47,6 +47,21 @@ public class OrderController { return orderService.orderInfo(orderId); } + + /** + * 订单详情 + * @param shopId 店铺id + * @param orderId 订单id + * @return 订单信息 + */ + @GetMapping ("/orderDetail") + public Result getCartByOrderId( + @RequestParam Integer shopId, + @RequestParam Integer orderId + ){ + return Result.successWithData(orderService.orderDetail(shopId, orderId)); + } + @GetMapping("/orderList") private Result orderList(@RequestParam Integer userId,@RequestParam Integer page, @RequestParam Integer size, @RequestParam String status){ diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopTable.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopTable.java index 219cdb8..1b87b87 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopTable.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopTable.java @@ -1,10 +1,12 @@ package com.chaozhanggui.system.cashierservice.entity; import com.baomidou.mybatisplus.annotation.TableField; +import lombok.Data; import java.io.Serializable; import java.math.BigDecimal; +@Data public class TbShopTable implements Serializable { private Integer id; @@ -41,142 +43,8 @@ public class TbShopTable implements Serializable { @TableField(exist = false) private String areaname; + @TableField(exist = false) + private Integer orderId; - public String getAreaname() { - return areaname; - } - public void setAreaname(String areaname) { - this.areaname = areaname; - } - - public String getQrcode() { - return qrcode; - } - - public void setQrcode(String qrcode) { - this.qrcode = qrcode; - } - - private static final long serialVersionUID = 1L; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name == null ? null : name.trim(); - } - - public Integer getShopId() { - return shopId; - } - - public void setShopId(Integer shopId) { - this.shopId = shopId; - } - - public Integer getMaxCapacity() { - return maxCapacity; - } - - public void setMaxCapacity(Integer maxCapacity) { - this.maxCapacity = maxCapacity; - } - - public Integer getSort() { - return sort; - } - - public void setSort(Integer sort) { - this.sort = sort; - } - - public Integer getAreaId() { - return areaId; - } - - public void setAreaId(Integer areaId) { - this.areaId = areaId; - } - - public Byte getIsPredate() { - return isPredate; - } - - public void setIsPredate(Byte isPredate) { - this.isPredate = isPredate; - } - - public BigDecimal getPredateAmount() { - return predateAmount; - } - - public void setPredateAmount(BigDecimal predateAmount) { - this.predateAmount = predateAmount; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status == null ? null : status.trim(); - } - - public Byte getType() { - return type; - } - - public void setType(Byte type) { - this.type = type; - } - - public BigDecimal getAmount() { - return amount; - } - - public void setAmount(BigDecimal amount) { - this.amount = amount; - } - - public BigDecimal getPerhour() { - return perhour; - } - - public void setPerhour(BigDecimal perhour) { - this.perhour = perhour; - } - - public String getView() { - return view; - } - - public void setView(String view) { - this.view = view == null ? null : view.trim(); - } - - public Long getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Long createdAt) { - this.createdAt = createdAt; - } - - public Long getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Long updatedAt) { - this.updatedAt = updatedAt; - } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java index 23c2434..9e28068 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java @@ -1,11 +1,17 @@ package com.chaozhanggui.system.cashierservice.service; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; +import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO; import com.chaozhanggui.system.cashierservice.entity.vo.OrderVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; +import com.chaozhanggui.system.cashierservice.mapper.MpCashierCartMapper; +import com.chaozhanggui.system.cashierservice.mapper.MpOrderDetailMapper; +import com.chaozhanggui.system.cashierservice.mapper.MpOrderInfoMapper; import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer; import com.chaozhanggui.system.cashierservice.redis.RedisCst; import com.chaozhanggui.system.cashierservice.redis.RedisUtil; @@ -25,11 +31,10 @@ import javax.annotation.Resource; import java.io.IOException; import java.math.BigDecimal; import java.text.ParseException; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; /** * @author 12847 @@ -78,6 +83,13 @@ public class OrderService { @Autowired private TbOrderInfoMapper tbOrderInfoMapper; + @Autowired + private MpCashierCartMapper mpCashierCartMapper; + @Autowired + private MpOrderDetailMapper mpOrderDetailMapper; + @Autowired + private MpOrderInfoMapper mpOrderInfoMapper; + /** * 创建订单 * @@ -432,4 +444,51 @@ public class OrderService { } return Result.success(CodeEnum.SUCCESS); } + + public Object orderDetail(Integer shopId, Integer orderId) { + TbOrderInfo orderInfo = mpOrderInfoMapper.selectOne(new LambdaQueryWrapper() + .eq(TbOrderInfo::getId, orderId) + .eq(TbOrderInfo::getShopId, shopId)); + + if (orderInfo == null) { + return Result.fail("订单不存在"); + } + + if (!"unpaid".equals(orderInfo.getStatus())) { + return Result.fail("订单不处于待支付状态"); + } + + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .eq(TbOrderDetail::getShopId, shopId) + .eq(TbOrderDetail::getOrderId, orderId); + + List list = mpOrderDetailMapper.selectList(queryWrapper); + AtomicReference mealCashierCart = new AtomicReference<>(); + list.forEach(item -> { + item.setPlaceNum(item.getPlaceNum() == null ? 0 : item.getPlaceNum()); + if (item.getProductId() == -999) { + mealCashierCart.set(item); + } + }); + + // 根据placeNum进行分组 + Map> groupedByPlaceNum = list.stream() + .collect(Collectors.groupingBy(TbOrderDetail::getPlaceNum)); + + ArrayList> dataList = new ArrayList<>(); + groupedByPlaceNum.forEach((k, v) -> { + HashMap item = new HashMap<>(); + item.put("placeNum", k); + item.put("info", v); + dataList.add(item); + }); + + + Map map = new HashMap<>(); + // 餐位费 + map.put("seatFee", mealCashierCart); + map.put("detailList", dataList); + map.put("orderInfo", orderInfo); + return map; + } } 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 7b379e2..5818124 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -7,6 +7,7 @@ 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.extension.plugins.pagination.Page; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.Enum.PlatformTypeEnum; @@ -18,6 +19,7 @@ import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO; import com.chaozhanggui.system.cashierservice.entity.vo.*; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.mapper.MpCashierCartMapper; +import com.chaozhanggui.system.cashierservice.mapper.MpOrderInfoMapper; import com.chaozhanggui.system.cashierservice.mapper.MpShopTableMapper; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; @@ -95,11 +97,28 @@ public class ProductService { private MpShopTableMapper mpShopTableMapper; @Autowired private MpCashierCartMapper mpCashierCartMapper; + @Autowired + private MpOrderInfoMapper mpOrderInfoMapper; public ProductService(ShopUtils shopUtils) { this.shopUtils = shopUtils; } + private TbOrderInfo getCurrentOrder(ShopEatTypeInfoDTO eatTypeInfoDTO, String tableId, Object shopId) { + // 获取当前台桌最新订单,先付款模式不获取 + if (eatTypeInfoDTO.isDineInBefore()) { + return null; + } + List orderInfoList = mpOrderInfoMapper.selectPage(new Page<>(1, 1), new LambdaQueryWrapper() + .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); + } + public Result queryShopIdByTableCode(String userId, String openId, String code, String lat, String lng) { if (StringUtils.isBlank(code)) return Result.fail("桌码信息为空"); if (StringUtils.isBlank(lat) || lat.equals("undefined")) { @@ -115,6 +134,11 @@ public class ProductService { Double.parseDouble(lng), Double.parseDouble(lat), Double.parseDouble(shopInfo.getLng()), Double.parseDouble(shopInfo.getLat())); ConcurrentMap concurrentMap = new ConcurrentHashMap<>(); + + // 获取当前台桌最新订单id + ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.checkEatModel(code, shopInfo.getId()); + TbOrderInfo order = getCurrentOrder(shopEatTypeInfoDTO, code, shopInfo.getId()); + tbShopTable.setOrderId(order == null ? null : order.getId()); concurrentMap.put("shopTableInfo", tbShopTable); concurrentMap.put("storeInfo", shopInfo); concurrentMap.put("distance", distance);