Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
commit
bfa30e0b72
|
|
@ -4,6 +4,8 @@ import lombok.Data;
|
|||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class CreateOrderDTO {
|
||||
|
|
@ -18,4 +20,8 @@ public class CreateOrderDTO {
|
|||
@NotEmpty
|
||||
private String useType;
|
||||
private String vipUserId;
|
||||
// 使用的优惠券
|
||||
private List<Integer> userCouponIds = new ArrayList<>();
|
||||
// 使用的积分抵扣数量
|
||||
private Integer pointsNum ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package cn.ysk.cashier.mybatis.service;
|
||||
|
||||
import cn.ysk.cashier.cons.TableConstant;
|
||||
import cn.ysk.cashier.dto.shoptable.ShopEatTypeInfoDTO;
|
||||
import cn.ysk.cashier.enums.OrderStatusEnums;
|
||||
import cn.ysk.cashier.pojo.order.TbCashierCart;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
|
@ -55,5 +56,13 @@ public interface MpCashierCartService extends IService<TbCashierCart> {
|
|||
* @param orderId 订单id
|
||||
*/
|
||||
boolean updateStateByOrderId(TableConstant.OrderInfo.Status status, Integer orderId);
|
||||
|
||||
/**
|
||||
* 根据店就餐模式查询购物车
|
||||
* @param shopEatTypeInfoDTO 就餐模式
|
||||
* @return 购物车信息
|
||||
*/
|
||||
List<TbCashierCart> selectByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,5 +42,13 @@ public interface MpOrderDetailService extends IService<TbOrderDetail> {
|
|||
*/
|
||||
List<TbOrderDetail> selectByOrderId(Integer orderId);
|
||||
|
||||
/**
|
||||
* 根据购物车id和订单id查询订单详情
|
||||
* @param shopId 店铺id
|
||||
* @param cartIdList 购物车id
|
||||
* @param orderId 订单id
|
||||
* @return 详情信息
|
||||
*/
|
||||
List<TbOrderDetail> selectByCartIdOrOrderId(Integer shopId, ArrayList<Integer> cartIdList, Integer orderId);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,16 +3,16 @@ package cn.ysk.cashier.mybatis.service.impl;
|
|||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.ysk.cashier.cons.TableConstant;
|
||||
import cn.ysk.cashier.enums.OrderStatusEnums;
|
||||
import cn.ysk.cashier.enums.OrderUseTypeEnum;
|
||||
import cn.ysk.cashier.enums.ShopInfoEatModelEnum;
|
||||
import cn.ysk.cashier.enums.ShopInfoRegisterlEnum;
|
||||
import cn.ysk.cashier.dto.shoptable.ShopEatTypeInfoDTO;
|
||||
import cn.ysk.cashier.enums.*;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mybatis.mapper.MpShopInfoMapper;
|
||||
import cn.ysk.cashier.mybatis.mapper.MpShopTableMapper;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbCashierCartMapper;
|
||||
import cn.ysk.cashier.mybatis.service.MpCashierCartService;
|
||||
import cn.ysk.cashier.pojo.order.TbCashierCart;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopInfo;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopTable;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
|
@ -32,8 +32,11 @@ import java.util.List;
|
|||
public class MpCashierCartServiceImpl extends ServiceImpl<TbCashierCartMapper, TbCashierCart> implements MpCashierCartService {
|
||||
private final MpShopInfoMapper mpShopInfoMapper;
|
||||
|
||||
public MpCashierCartServiceImpl(MpShopInfoMapper mpShopInfoMapper) {
|
||||
private final MpShopTableMapper shopTableMapper;
|
||||
|
||||
public MpCashierCartServiceImpl(MpShopInfoMapper mpShopInfoMapper, MpShopTableMapper shopTableMapper) {
|
||||
this.mpShopInfoMapper = mpShopInfoMapper;
|
||||
this.shopTableMapper = shopTableMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -93,5 +96,31 @@ public class MpCashierCartServiceImpl extends ServiceImpl<TbCashierCartMapper, T
|
|||
.eq(TbCashierCart::getOrderId, orderId)
|
||||
.set(TbCashierCart::getStatus, status.getValue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TbCashierCart> selectByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId) {
|
||||
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, shopEatTypeInfoDTO.getShopId())
|
||||
.eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType())
|
||||
.in(TbCashierCart::getStatus, "create", "return")
|
||||
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
|
||||
.and(q -> q.eq(TbCashierCart::getMasterId, masterId).or().isNull(TbCashierCart::getMasterId));
|
||||
|
||||
// 非堂食校验台桌状态
|
||||
TbShopTable tbShopTable;
|
||||
if (shopEatTypeInfoDTO.isTakeout()) {
|
||||
queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, ""))
|
||||
.in(TbCashierCart::getPlatformType, OrderPlatformTypeEnum.PC.getValue(), OrderPlatformTypeEnum.CASH.getValue());
|
||||
} else {
|
||||
if (StrUtil.isNotBlank(shopEatTypeInfoDTO.getTableId())) {
|
||||
|
||||
queryWrapper.eq(TbCashierCart::getTableId, shopEatTypeInfoDTO.getTableId());
|
||||
} else {
|
||||
queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, ""));
|
||||
}
|
||||
|
||||
}
|
||||
return list(queryWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,5 +46,12 @@ public class MpOrderDetailServiceImpl extends ServiceImpl<TbOrderDetailMapper, T
|
|||
return list(new LambdaQueryWrapper<TbOrderDetail>()
|
||||
.eq(TbOrderDetail::getOrderId, orderId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TbOrderDetail> selectByCartIdOrOrderId(Integer shopId, ArrayList<Integer> cartIdList, Integer orderId) {
|
||||
return list(new LambdaQueryWrapper<TbOrderDetail>()
|
||||
.and(q -> q.in(TbOrderDetail::getCartId, cartIdList).or().eq(TbOrderDetail::getOrderId, orderId))
|
||||
.eq(TbOrderDetail::getShopId, shopId));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -240,6 +240,16 @@ public class TbOrderInfo implements Serializable {
|
|||
|
||||
@Column(name = "`refund_remark`")
|
||||
private String refundRemark;
|
||||
|
||||
// 积分折扣金额
|
||||
private BigDecimal pointsDiscountAmount;
|
||||
// 使用的积分数量
|
||||
private Integer pointsNum;
|
||||
// 用户优惠券id
|
||||
private String activateInInfoList;
|
||||
// 优惠券折扣金额
|
||||
private BigDecimal activateInDiscountAmount;
|
||||
|
||||
public void copy(TbOrderInfo source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import cn.ysk.cashier.config.security.security.TokenProvider;
|
|||
import cn.ysk.cashier.cons.RedisConstant;
|
||||
import cn.ysk.cashier.cons.TableConstant;
|
||||
import cn.ysk.cashier.cons.rabbit.RabbitConstants;
|
||||
import cn.ysk.cashier.dto.points.OrderDeductionPointsDTO;
|
||||
import cn.ysk.cashier.dto.shop.TbShopTableDto;
|
||||
import cn.ysk.cashier.dto.shop.TbShopTableQueryCriteria;
|
||||
import cn.ysk.cashier.dto.shoptable.*;
|
||||
|
|
@ -18,10 +19,7 @@ import cn.ysk.cashier.enums.*;
|
|||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mapper.shop.TbShopTableMapper;
|
||||
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.MpOrderInfoService;
|
||||
import cn.ysk.cashier.mybatis.service.MpShopTableService;
|
||||
import cn.ysk.cashier.mybatis.service.*;
|
||||
import cn.ysk.cashier.pojo.TbShopPayType;
|
||||
import cn.ysk.cashier.pojo.order.TbCashierCart;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||
|
|
@ -98,6 +96,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
private final MpShopTableService mpShopTableService;
|
||||
private final MpShopUnitMapper mpShopUnitMapper;
|
||||
private final MpProductStockDetailMapper mpProductStockDetailMapper;
|
||||
private final TbMemberPointsService memberPointsService;
|
||||
private final TbShopCouponService shopCouponService;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -1107,50 +1107,31 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
TbShopInfo shopInfo = shopInfoRepository.findById(createOrderDTO.getShopId()).orElse(null);
|
||||
if (shopInfo == null) throw new BadRequestException("店铺信息不存在");
|
||||
|
||||
// 非堂食校验台桌状态
|
||||
TbShopTable tbShopTable = null;
|
||||
if (StrUtil.isNotBlank(createOrderDTO.getTableId())) {
|
||||
tbShopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
|
||||
.eq(TbShopTable::getQrcode, createOrderDTO.getTableId())
|
||||
.in(TbShopTable::getStatus, "idle", "using"));
|
||||
if (tbShopTable == null) {
|
||||
throw new BadRequestException("台桌未开台或不存在");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 就餐模式信息
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(createOrderDTO.getShopId(), createOrderDTO.getTableId(), createOrderDTO.getUseType());
|
||||
|
||||
// 传递orderId直接取否则取当前缓存id
|
||||
Integer orderId = shopEatTypeInfoDTO.isDineInAfter() ?
|
||||
getCurrentOrderId(shopEatTypeInfoDTO) : null;
|
||||
|
||||
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, createOrderDTO.getShopId())
|
||||
.eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType())
|
||||
.in(TbCashierCart::getStatus, "create", "return")
|
||||
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
|
||||
.and(q -> q.eq(TbCashierCart::getMasterId, createOrderDTO.getMasterId()).or().isNull(TbCashierCart::getMasterId));
|
||||
|
||||
// 非堂食校验台桌状态
|
||||
TbShopTable tbShopTable = null;
|
||||
if (shopEatTypeInfoDTO.isTakeout()) {
|
||||
queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, ""))
|
||||
.in(TbCashierCart::getPlatformType, OrderPlatformTypeEnum.PC.getValue(), OrderPlatformTypeEnum.CASH.getValue());
|
||||
} else {
|
||||
if (StrUtil.isNotBlank(createOrderDTO.getTableId())) {
|
||||
tbShopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
|
||||
.eq(TbShopTable::getQrcode, createOrderDTO.getTableId())
|
||||
.in(TbShopTable::getStatus, "idle", "using"));
|
||||
if (tbShopTable == null) {
|
||||
throw new BadRequestException("台桌未开台或不存在");
|
||||
}
|
||||
queryWrapper.eq(TbCashierCart::getTableId, createOrderDTO.getTableId());
|
||||
} else {
|
||||
queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, ""));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List<TbCashierCart> allCashierCarts = cashierCartMapper
|
||||
.selectList(queryWrapper);
|
||||
|
||||
List<TbCashierCart> allCashierCarts = mpCashierCartService.selectByShopEatType(shopEatTypeInfoDTO, createOrderDTO.getMasterId());
|
||||
List<TbCashierCart> cashierCarts = new ArrayList<>();
|
||||
TbCashierCart seatCart = null;
|
||||
for (TbCashierCart allCashierCart : allCashierCarts) {
|
||||
if (TableConstant.CART_SEAT_ID.equals(allCashierCart.getProductId())) {
|
||||
seatCart = allCashierCart;
|
||||
}
|
||||
|
||||
// if (OrderStatusEnums.CREATE.getValue().equals(allCashierCart.getStatus())) {
|
||||
// cashierCarts.add(allCashierCart);
|
||||
// }
|
||||
|
|
@ -1176,12 +1157,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
cartIdList.add(tbCashierCart.getId());
|
||||
}
|
||||
// 查询历史orderDetail
|
||||
Integer finalOrderId = orderId;
|
||||
LambdaQueryWrapper<TbOrderDetail> query = new LambdaQueryWrapper<TbOrderDetail>()
|
||||
.and(q -> q.in(TbOrderDetail::getCartId, cartIdList).or().eq(TbOrderDetail::getOrderId, finalOrderId))
|
||||
.eq(TbOrderDetail::getShopId, createOrderDTO.getShopId());
|
||||
List<TbOrderDetail> oldOrderDetailList = mpOrderDetailService.selectByCartIdOrOrderId(createOrderDTO.getShopId(), cartIdList, orderId);
|
||||
|
||||
List<TbOrderDetail> oldOrderDetailList = orderDetailMapper.selectList(query);
|
||||
ArrayList<Integer> removeOrderDetailIds = new ArrayList<>();
|
||||
ArrayList<TbOrderDetail> removeOrderDetailList = new ArrayList<>();
|
||||
HashMap<String, TbOrderDetail> oldOrderDetailMap = new HashMap<>();
|
||||
|
|
@ -1203,7 +1180,6 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
List<TbOrderDetail> orderDetails = new ArrayList<>();
|
||||
List<TbOrderDetail> addOrderDetails = new ArrayList<>();
|
||||
|
||||
|
||||
boolean hasNewInfo = false;
|
||||
for (TbCashierCart cashierCart : cashierCarts) {
|
||||
if (!"return".equals(cashierCart.getStatus())) {
|
||||
|
|
@ -1239,7 +1215,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
orderDetail.setProductName(cashierCart.getName());
|
||||
orderDetail.setShopId(Integer.valueOf(cashierCart.getShopId()));
|
||||
orderDetail.setPackAmount(cashierCart.getPackFee());
|
||||
orderDetail.setStatus("unpaid");
|
||||
orderDetail.setStatus(TableConstant.CashierCart.Status.RETURN.equalsVals(cashierCart.getStatus()) ? cashierCart.getStatus() : "unpaid");
|
||||
orderDetail.setUseType(shopEatTypeInfoDTO.getUseType());
|
||||
orderDetail.setProductImg(cashierCart.getCoverImg());
|
||||
orderDetail.setCartId(cashierCart.getId());
|
||||
|
|
@ -1250,7 +1226,6 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
orderDetails.add(orderDetail);
|
||||
}
|
||||
|
||||
|
||||
// 查询订单
|
||||
TbOrderInfo orderInfo = null;
|
||||
if (orderId != null) {
|
||||
|
|
@ -1275,7 +1250,6 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
orderInfo.setSettlementAmount(totalAmount);
|
||||
orderInfo.setAmount(totalAmount);
|
||||
orderInfo.setOriginAmount(totalAmount);
|
||||
// orderInfo.setStatus("unpaid");
|
||||
orderInfo.setOrderAmount(totalAmount);
|
||||
orderInfo.setRemark(createOrderDTO.getNote());
|
||||
orderInfo.setFreightAmount(feeAmount);
|
||||
|
|
@ -1449,6 +1423,30 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
|
||||
}
|
||||
|
||||
private void calculateOrderCouponAndPoints(TbOrderInfo orderInfo, List<Integer> userCouponList, Integer pointsNum) {
|
||||
BigDecimal shouldPayAmount = BigDecimal.ZERO;
|
||||
if (pointsNum != null) {
|
||||
Long memberId = Long.valueOf(orderInfo.getMemberId());
|
||||
OrderDeductionPointsDTO memberUsablePoints = memberPointsService.getMemberUsablePoints(memberId, orderInfo.getOrderAmount());
|
||||
if (!memberUsablePoints.getUsable()) {
|
||||
throw new BadRequestException(memberUsablePoints.getUnusableReason());
|
||||
}
|
||||
if (pointsNum < memberUsablePoints.getMinDeductionPoints() || pointsNum > memberUsablePoints.getMaxUsablePoints()) {
|
||||
throw new BadRequestException("可抵扣积分区间为: [" + memberUsablePoints.getMinDeductionPoints() + "-" + memberUsablePoints.getMaxUsablePoints() + "]");
|
||||
}
|
||||
|
||||
BigDecimal discountAmount = memberPointsService.calcDeductionAmount(memberId, orderInfo.getOrderAmount(), pointsNum);
|
||||
orderInfo.setPointsNum(pointsNum);
|
||||
orderInfo.setPointsDiscountAmount(discountAmount);
|
||||
shouldPayAmount = shouldPayAmount.subtract(discountAmount);
|
||||
memberPointsService.deductPoints(memberId, pointsNum, "霸王餐充值抵扣", Long.valueOf(orderInfo.getId()));
|
||||
}
|
||||
|
||||
if (!userCouponList.isEmpty()) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object pending(PendingDTO pendingDTO) {
|
||||
|
|
@ -1770,15 +1768,14 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
.in(TbCashierCart::getPlatformType, OrderPlatformTypeEnum.PC.getValue(), OrderPlatformTypeEnum.CASH.getValue());
|
||||
}
|
||||
|
||||
TbShopUser shopUser = tbShopUserMapper.selectById(updateVipDTO.getVipUserId());
|
||||
if (shopUser == null) {
|
||||
throw new BadRequestException("用户信息不存在");
|
||||
}
|
||||
|
||||
List<TbCashierCart> tbCashierCarts = cashierCartMapper.selectList(queryWrapper.isNotNull(TbCashierCart::getOrderId));
|
||||
if (!tbCashierCarts.isEmpty()) {
|
||||
Integer orderId = tbCashierCarts.get(0).getOrderId();
|
||||
if (updateVipDTO.getType() == 0) {
|
||||
TbShopUser shopUser = tbShopUserMapper.selectById(updateVipDTO.getVipUserId());
|
||||
if (shopUser == null) {
|
||||
throw new BadRequestException("用户信息不存在");
|
||||
}
|
||||
return orderInfoMapper.update(null, new LambdaUpdateWrapper<TbOrderInfo>()
|
||||
.eq(TbOrderInfo::getId, orderId)
|
||||
.set(TbOrderInfo::getUserId, shopUser.getUserId())
|
||||
|
|
@ -1787,7 +1784,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
return orderInfoMapper.update(null, new LambdaUpdateWrapper<TbOrderInfo>()
|
||||
.eq(TbOrderInfo::getId, orderId)
|
||||
.set(TbOrderInfo::getUserId, null)
|
||||
.set(TbOrderInfo::getUserId, null));
|
||||
.set(TbOrderInfo::getMemberId, null));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue