新增创建订单 切换就餐模式接口

This commit is contained in:
2024-09-29 15:45:48 +08:00
parent 70ad132780
commit 095773f62a
6 changed files with 87 additions and 31 deletions

View File

@@ -14,6 +14,7 @@ import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.Enum.*;
import com.chaozhanggui.system.cashierservice.entity.dto.ChoseCountDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.ChoseEatModelDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.mapper.*;
@@ -723,7 +724,7 @@ public class CartService {
}
@Transactional(rollbackFor = Exception.class)
public void createOrder(JSONObject jsonObject) {
public Result createOrder(JSONObject jsonObject) {
try {
JSONObject responseData = new JSONObject();
@@ -795,7 +796,7 @@ public class CartService {
responseData.put("msg", "购物车为空");
responseData.put("data", new ArrayList<>());
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true);
return;
return Result.fail("购物车为空");
}
// 就餐人数
@@ -819,9 +820,9 @@ public class CartService {
// 设置餐位费
TbShopInfo shopInfo = mpShopInfoMapper.selectById(shopId);
if (!shopEatTypeInfoDTO.isTakeout() && shopInfo.getIsTableFee() != null && shopInfo.getIsTableFee() == 0
&& seatNum < 1) {
&& (seatNum < 1 || cashierCartList.size() < 2)) {
log.info("消息推送");
responseData.put("msg", "请选择就餐人数");
responseData.put("msg", "购物车为空");
if (shopTable.getMaxCapacity() < seatNum) {
responseData.put("msg", "当前台桌最大人数为: " + shopTable.getMaxCapacity());
}
@@ -829,7 +830,7 @@ public class CartService {
responseData.put("type", jsonObject.getString("type"));
responseData.put("data", "");
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true);
return;
return Result.fail(responseData.getString("msg"));
}
@@ -1014,7 +1015,7 @@ public class CartService {
responseData.put("data", "");
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true);
log.info("消息推送");
return;
return Result.fail("优惠券已售空");
}
if (N.gt(systemCoupons.getCouponsAmount(), totalAmount)) {
log.info("开始处理订单");
@@ -1024,7 +1025,7 @@ public class CartService {
responseData.put("data", "");
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true);
log.info("消息推送");
return;
return Result.fail("订单金额小于优惠价金额");
}
totalAmount = totalAmount.add(systemCoupons.getCouponsPrice()).subtract(systemCoupons.getCouponsAmount());
originAmount = originAmount.add(systemCoupons.getCouponsPrice());
@@ -1064,7 +1065,7 @@ public class CartService {
responseData.put("data", "");
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true);
log.info("消息推送");
return;
return Result.fail("订单正在支付中,请稍后再试");
}
orderInfo.setUpdatedAt(System.currentTimeMillis());
orderInfo.setSettlementAmount(totalAmount);
@@ -1135,11 +1136,10 @@ public class CartService {
}
// 去除餐位费信息
cashierCartList = cashierCartList.stream().filter(item -> !"-999".equals(item.getProductId())).collect(Collectors.toList());
List<TbActivateOutRecord> outRecords = new ArrayList<>();
for (TbCashierCart cashierCart : cashierCartList) {
if (cashierCart.getIsVip().equals((byte) 1)) {
if (!cashierCart.getProductId().equals("-999") && cashierCart.getIsVip().equals((byte) 1)) {
List<TbActivateInRecord> actInRecords = activateInRecordService.queryAllByVipIdAndShopIdAndProId(
Integer.valueOf(tbShopUser.getId()), Integer.valueOf(orderInfo.getShopId()), Integer.valueOf(cashierCart.getProductId()));
Integer totalNumber = cashierCart.getTotalNumber();
@@ -1169,6 +1169,9 @@ public class CartService {
mpCashierCartMapper.updateById(cashierCart);
}
cashierCartList = cashierCartList.stream().filter(item -> !"-999".equals(item.getProductId())).collect(Collectors.toList());
// 删除旧的餐位费信息
if (shopEatTypeInfoDTO.isTakeout() && seatCartInfo != null) {
cashierCartMapper.deleteByPrimaryKey(seatCartInfo.getId());
@@ -1228,10 +1231,13 @@ public class CartService {
}
});
return Result.successWithData(orderInfo);
} catch (Exception e) {
log.info("长链接错误 createOrder{}", e.getMessage());
e.printStackTrace();
}
return Result.fail("失败");
}
private TbOrderInfo getOrder(BigDecimal totalAmount, BigDecimal packAMount,
@@ -1578,4 +1584,33 @@ public class CartService {
}
}
public List<TbCashierCart> choseEatModel(ChoseEatModelDTO choseEatModelDTO) {
Integer userId = TokenUtil.getUserId();
List<TbCashierCart> cashierCartList;
if (choseEatModelDTO.getType() == 1) {
// 查询购物车所有信息
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
.eq(TbCashierCart::getShopId, choseEatModelDTO.getShopId())
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
.isNull(TbCashierCart::getOrderId)
.ne(TbCashierCart::getProductId, "-999")
.eq(TbCashierCart::getStatus, "create");
// 外带模式
queryWrapper.eq(TbCashierCart::getUserId, userId);
cashierCartList = mpCashierCartMapper.selectList(queryWrapper);
}else {
cashierCartList = new ArrayList<>();
String tableCartKey = RedisCst.getTableCartKey(choseEatModelDTO.getShopId().toString(), choseEatModelDTO.getTableId(), userId);
String message = redisUtil.getMessage(tableCartKey);
if (StrUtil.isNotBlank(message)) {
JSONObject.parseArray(message).forEach(item -> {
TbCashierCart cart = JSONObject.parseObject(item.toString(), TbCashierCart.class);
cashierCartList.add(cart);
});
}
}
// 所有订单信息
return cashierCartList;
}
}

View File

@@ -994,7 +994,6 @@ public class ProductService {
return mpCashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
.eq(TbCashierCart::getShopId, choseTableDTO.getShopId())
.eq(TbCashierCart::getUserId, choseTableDTO.getUserId())
.isNull(TbCashierCart::getUseType)
.eq(TbCashierCart::getStatus, "create")
.set(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType())) ;