就餐模式切换设置打包费
This commit is contained in:
parent
5be2e74d81
commit
f4bf18218f
|
|
@ -0,0 +1,16 @@
|
|||
package cn.ysk.cashier.mybatis.service;
|
||||
|
||||
import cn.ysk.cashier.pojo.order.TbCashierCart;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* (TbShopPermission)表服务接口
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2024-09-14 17:08:48
|
||||
*/
|
||||
public interface MpCashierCartService extends IService<TbCashierCart> {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package cn.ysk.cashier.mybatis.service.impl;
|
||||
|
||||
import cn.ysk.cashier.mybatis.mapper.TbCashierCartMapper;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbOrderDetailMapper;
|
||||
import cn.ysk.cashier.mybatis.service.MpCashierCartService;
|
||||
import cn.ysk.cashier.mybatis.service.MpOrderDetailService;
|
||||
import cn.ysk.cashier.pojo.order.TbCashierCart;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* (TbShopPermission)表服务实现类
|
||||
*
|
||||
* @author makejava
|
||||
* @since 2024-09-14 17:08:49
|
||||
*/
|
||||
@Service
|
||||
public class MpCashierCartServiceImpl extends ServiceImpl<TbCashierCartMapper, TbCashierCart> implements MpCashierCartService {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -14,6 +14,7 @@ import cn.ysk.cashier.enums.*;
|
|||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mybatis.entity.TbShopOpenId;
|
||||
import cn.ysk.cashier.mybatis.mapper.*;
|
||||
import cn.ysk.cashier.mybatis.service.MpCashierCartService;
|
||||
import cn.ysk.cashier.mybatis.service.MpOrderDetailService;
|
||||
import cn.ysk.cashier.mybatis.service.MpShopTableService;
|
||||
import cn.ysk.cashier.pojo.TbShopPayType;
|
||||
|
|
@ -108,6 +109,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
private final MpShopAreaMapper mpShopAreaMapper;
|
||||
private final MpShopInfoMapper mpShopInfoMapper;
|
||||
private final MpOrderDetailService mpOrderDetailService;
|
||||
private final MpCashierCartService mpCashierCartService;
|
||||
|
||||
private TbOrderInfo getCurrentOrder(ShopEatTypeInfoDTO eatTypeInfoDTO) {
|
||||
// 获取当前台桌最新订单,先付款模式不获取
|
||||
|
|
@ -460,6 +462,11 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
tbCashierCart.setNumber(addCartDTO.getNum());
|
||||
tbCashierCart.setCategoryId(product.getCategoryId());
|
||||
tbCashierCart.setNote(addCartDTO.getNote());
|
||||
// 设置打包费
|
||||
if (shopEatTypeInfoDTO.isTakeout()) {
|
||||
tbCashierCart.setPackFee(product.getPackFee() != null ?
|
||||
product.getPackFee().multiply(BigDecimal.valueOf(addCartDTO.getNum())) : BigDecimal.ZERO);
|
||||
}
|
||||
cashierCartRepository.save(tbCashierCart);
|
||||
|
||||
} else {
|
||||
|
|
@ -483,7 +490,12 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
tbCashierCart.setTotalNumber(addCartDTO.getNum());
|
||||
tbCashierCart.setNumber(addCartDTO.getNum());
|
||||
tbCashierCart.setUpdatedAt(DateUtil.current());
|
||||
cashierCartRepository.save(tbCashierCart);
|
||||
// 设置打包费
|
||||
if (shopEatTypeInfoDTO.isTakeout()) {
|
||||
tbCashierCart.setPackFee(product.getPackFee() != null ?
|
||||
product.getPackFee().multiply(BigDecimal.valueOf(addCartDTO.getNum())) : BigDecimal.ZERO);
|
||||
}
|
||||
cashierCartMapper.insert(tbCashierCart);
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(addCartDTO.getTableId())) {
|
||||
|
|
@ -1796,16 +1808,55 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
public Object choseModel(ChoseModelDTO choseModelDTO) {
|
||||
if (!OrderUseTypeEnum.TAKEOUT.getValue().equals(choseModelDTO.getUseType()) && StrUtil.isBlank(choseModelDTO.getTableId())) {
|
||||
throw new BadRequestException("堂食tableId必须传递");
|
||||
// 外带设置餐位费
|
||||
}
|
||||
cashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, choseModelDTO.getShopId())
|
||||
.in(TbCashierCart::getId, choseModelDTO.getCartIds())
|
||||
.set(TbCashierCart::getTableId, OrderUseTypeEnum.TAKEOUT.getValue().equals(choseModelDTO.getUseType()) ? null : choseModelDTO.getTableId())
|
||||
.set(TbCashierCart::getUseType, choseModelDTO.getUseType()));
|
||||
|
||||
return orderDetailMapper.update(null, new LambdaUpdateWrapper<TbOrderDetail>()
|
||||
.in(TbOrderDetail::getCartId, choseModelDTO.getCartIds())
|
||||
.set(TbOrderDetail::getUseType, choseModelDTO.getUseType()));
|
||||
List<TbCashierCart> cashierCarts = cashierCartMapper.selectList(new LambdaQueryWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, choseModelDTO.getShopId())
|
||||
.in(TbCashierCart::getId, choseModelDTO.getCartIds()));
|
||||
if (cashierCarts.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
if (OrderUseTypeEnum.TAKEOUT.getValue().equals(choseModelDTO.getUseType()) ) {
|
||||
ArrayList<Integer> productIds = new ArrayList<>();
|
||||
List<TbProduct> productList = productMapper.selectBatchIds(productIds);
|
||||
Map<String, TbProduct> productMap = productList.stream()
|
||||
.collect(Collectors.toMap(product -> String.valueOf(product.getId()), product -> product));
|
||||
cashierCarts.forEach(item -> {
|
||||
TbProduct product = productMap.get(item.getProductId());
|
||||
// 设置打包费
|
||||
item.setPackFee(product.getPackFee() != null ?
|
||||
product.getPackFee().multiply(BigDecimal.valueOf(item.getNumber())) : BigDecimal.ZERO);
|
||||
item.setTableId(null);
|
||||
});
|
||||
|
||||
List<TbOrderDetail> detailList = orderDetailMapper.selectList(new LambdaQueryWrapper<TbOrderDetail>()
|
||||
.in(TbOrderDetail::getCartId, choseModelDTO.getCartIds())
|
||||
.eq(TbOrderDetail::getShopId, choseModelDTO.getShopId()));
|
||||
detailList.forEach(item -> {
|
||||
TbProduct product = productMap.get(item.getProductId().toString());
|
||||
// 设置打包费
|
||||
item.setPackAmount(product.getPackFee() != null ?
|
||||
product.getPackFee().multiply(BigDecimal.valueOf(item.getNum())) : BigDecimal.ZERO);
|
||||
});
|
||||
|
||||
if (!detailList.isEmpty()) {
|
||||
mpOrderDetailService.updateBatchById(detailList);
|
||||
}
|
||||
|
||||
return mpCashierCartService.updateBatchById(cashierCarts);
|
||||
}else {
|
||||
cashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
|
||||
.in(TbCashierCart::getId, choseModelDTO.getCartIds())
|
||||
.eq(TbCashierCart::getShopId, choseModelDTO.getShopId())
|
||||
.set(TbCashierCart::getTableId, choseModelDTO.getTableId())
|
||||
.set(TbCashierCart::getUseType, choseModelDTO.getUseType())
|
||||
.set(TbCashierCart::getPackFee, BigDecimal.ZERO));
|
||||
return orderDetailMapper.update(null, new LambdaUpdateWrapper<TbOrderDetail>()
|
||||
.in(TbOrderDetail::getCartId, choseModelDTO.getCartIds())
|
||||
.set(TbOrderDetail::getUseType, choseModelDTO.getUseType())
|
||||
.set(TbOrderDetail::getPackAmount, BigDecimal.ZERO));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue