|
@@ -18,6 +18,7 @@ import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
@@ -373,7 +374,6 @@ public class BackendCashierController extends BaseController {
|
|
|
if (StringUtil.isEmpty(userId)) {
|
|
|
isVisitor = YesOrNoEnum.YES.getKey();
|
|
|
}
|
|
|
-
|
|
|
if (StringUtil.isNotEmpty(cartIds)) {
|
|
|
String[] ids = cartIds.split(",");
|
|
|
if (ids.length > 0) {
|
|
@@ -400,34 +400,63 @@ public class BackendCashierController extends BaseController {
|
|
|
if (accountInfo == null) {
|
|
|
return getFailureResult(1001, I18nUtil.getMessage("notAuthenticated"));
|
|
|
}
|
|
|
+ // 获取当前店铺ID(从登录账户信息中)
|
|
|
Long storeId = accountInfo.getStoreId();
|
|
|
- //获取餐桌列表
|
|
|
- List<MtTableInfo> tableInfoList = tableInfoService.selectTableListByStoreId(storeId,categoryId);
|
|
|
+ // -------------------- 新增校验:分类存在性检查 --------------------
|
|
|
+ if (!tableInfoService.existCategory(categoryId)) {
|
|
|
+// log.warn("请求非法分类 | storeId={} categoryId={}", storeId, categoryId);
|
|
|
+ return getFailureResult(2001, "该餐桌分类不存在");
|
|
|
+ }
|
|
|
|
|
|
+ //获取指定分类的餐桌列表
|
|
|
+ //调用tableInfoService查询当前店铺下的餐桌
|
|
|
+ List<MtTableInfo> tableInfoList = tableInfoService.selectTableListByStoreId(storeId,categoryId);
|
|
|
+ // 构建返回数据列表
|
|
|
List<HangUpDto> dataList = new ArrayList<>();
|
|
|
|
|
|
+ // 遍历每个餐桌,检查是否有挂单
|
|
|
for (MtTableInfo mtTableInfo : tableInfoList) {
|
|
|
+ // 从餐桌信息中获取桌号作为挂单号
|
|
|
String hangNo = mtTableInfo.getTableNumber();
|
|
|
+ //构造查询参数
|
|
|
Map<String, Object> param = new HashMap<>();
|
|
|
- param.put("hangNo", hangNo);
|
|
|
- param.put("merchantId", accountInfo.getMerchantId());
|
|
|
- param.put("storeId", storeId);
|
|
|
+ param.put("hangNo", hangNo);// 当前桌号
|
|
|
+ param.put("merchantId", accountInfo.getMerchantId());// 商户ID
|
|
|
+ param.put("storeId", storeId); // 店铺ID
|
|
|
+ //查询关联的购物车列表(挂单记录)
|
|
|
List<MtCart> cartList = cartService.queryCartListByParams(param);
|
|
|
+ //构建返回DTO对象
|
|
|
HangUpDto dto = new HangUpDto();
|
|
|
+ // 设置默认值
|
|
|
dto.setIsEmpty(true);
|
|
|
if (!cartList.isEmpty()) {
|
|
|
+ // 存在挂单时的处理逻辑
|
|
|
+
|
|
|
+ //获取用户信息
|
|
|
Long userId = cartList.get(0).getUserId();
|
|
|
String isVisitor = cartList.get(0).getIsVisitor();
|
|
|
- Map<String, Object> cartInfo = orderService.calculateCartGoods(accountInfo.getMerchantId(), userId, cartList, 0L, false, PlatformTypeEnum.PC.getCode(), OrderModeEnum.ONESELF.getKey());
|
|
|
- dto.setNum(Integer.parseInt(cartInfo.get("totalNum").toString()));
|
|
|
- dto.setAmount(new BigDecimal(cartInfo.get("totalPrice").toString()));
|
|
|
+ // 计算购物车商品总价和数量 调用订单服务进行计算
|
|
|
+ Map<String, Object> cartInfo = orderService.calculateCartGoods(
|
|
|
+ accountInfo.getMerchantId(),
|
|
|
+ userId,
|
|
|
+ cartList,
|
|
|
+ 0L, // 使用的卡券ID 未使用优惠券
|
|
|
+ false, // isUsePoint 不使用积分
|
|
|
+ PlatformTypeEnum.PC.getCode(), // 平台类型:PC端
|
|
|
+ OrderModeEnum.ONESELF.getKey()// 订单模式:自取
|
|
|
+ );
|
|
|
+ //填充数据
|
|
|
+ dto.setNum(Integer.parseInt(cartInfo.get("totalNum").toString()));//数量
|
|
|
+ dto.setAmount(new BigDecimal(cartInfo.get("totalPrice").toString()));//商品总价
|
|
|
+ // 非访客订单时获取会员信息
|
|
|
if (isVisitor.equals(YesOrNoEnum.NO.getKey())) {
|
|
|
MtUser userInfo = memberService.queryMemberById(userId);
|
|
|
dto.setMemberInfo(userInfo);
|
|
|
}
|
|
|
+ //设置更新时间(取第一个购物车记录的更新时间)
|
|
|
String dateTime = DateUtil.formatDate(cartList.get(0).getUpdateTime(), "yyyy-MM-dd HH:mm:ss");
|
|
|
dto.setDateTime(dateTime);
|
|
|
- dto.setIsEmpty(false);
|
|
|
+ dto.setIsEmpty(false);// 标记为有挂单
|
|
|
}
|
|
|
dto.setHangNo(hangNo);
|
|
|
dataList.add(dto);
|