fix: 选择会员保存会员相关信息

This commit is contained in:
SongZhang 2024-10-30 17:48:24 +08:00
parent 09872cd71b
commit 6630141a99
3 changed files with 27 additions and 7 deletions

View File

@ -12,7 +12,7 @@ import java.math.BigDecimal;
public interface TbPayService {
TbOrderInfo scanPay(Integer shopId, String code, Integer merchantId, Integer memberId, BigDecimal payMount, TbOrderInfo orderInfo);
void vipPay(BigDecimal payMount, Integer vipUserId);
void vipPay(BigDecimal payMount, Integer userId, Integer vipUserId);
TbOrderInfo cashPay(PayDTO payDTO);

View File

@ -306,18 +306,19 @@ public class TbPayServiceImpl implements TbPayService {
}
@Override
public void vipPay(BigDecimal payMount, Integer vipUserId) {
public void vipPay(BigDecimal payMount, Integer userId, Integer vipUserId) {
// 扣减会员余额
TbShopUser shopUser = shopUserMapper.selectOne(new LambdaUpdateWrapper<TbShopUser>()
.eq(TbShopUser::getStatus, 1)
.eq(TbShopUser::getId, vipUserId));
.eq(TbShopUser::getId, vipUserId)
.eq(TbShopUser::getUserId, userId));
if (shopUser == null) {
throw new BadRequestException("用户不存在或已被禁用");
}
long flag = shopUserMapper.decrBalance(vipUserId, payMount);
long flag = shopUserMapper.decrBalance(shopUser.getId(), payMount);
if (flag < 1) {
throw new BadRequestException("余额不足或扣除余额失败");
}

View File

@ -117,6 +117,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
private final PayService payService;
private final TbOrderInfoService orderInfoService;
private final MpOrderInfoService mpOrderInfoService;
private final TbShopUserMapper tbShopUserMapper;
private TbOrderInfo getCurrentOrder(ShopEatTypeInfoDTO eatTypeInfoDTO) {
// 获取当前台桌最新订单先付款模式不获取
@ -1247,6 +1248,15 @@ public class TbShopTableServiceImpl implements TbShopTableService {
if (orderId != null) {
orderInfo = orderInfoMapper.selectById(orderId);
}
TbShopUser shopUser = null;
if (StrUtil.isNotBlank(createOrderDTO.getVipUserId())) {
shopUser = tbShopUserMapper.selectById(createOrderDTO.getVipUserId());
if (shopUser == null) {
throw new BadRequestException("用户不存在");
}
}
// 是否是第一次创建订单
boolean isFirst = false;
// 修改订单信息
@ -1270,7 +1280,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
orderInfo.setSeatCount(seatCart.getNumber());
}
if (StrUtil.isNotBlank(createOrderDTO.getVipUserId())) {
orderInfo.setUserId(createOrderDTO.getVipUserId());
orderInfo.setMemberId(createOrderDTO.getVipUserId());
orderInfo.setUserId(shopUser.getUserId());
}
orderInfo.setSendType(shopEatTypeInfoDTO.getSendType());
// 存在新添加的商品增加下单次数
@ -1306,6 +1317,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
orderInfo.setUseType(shopEatTypeInfoDTO.getUseType());
if (StrUtil.isNotBlank(createOrderDTO.getVipUserId())) {
orderInfo.setUserId(createOrderDTO.getVipUserId());
orderInfo.setUserId(shopUser.getUserId());
}
if (seatCart != null) {
orderInfo.setSeatAmount(seatCart.getTotalAmount());
@ -1607,7 +1619,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
if (payDTO.getVipUserId() != null) {
orderInfo.setUserId(String.valueOf(payDTO.getVipUserId()));
}
tbPayServiceImpl.vipPay(finalAmount, Integer.valueOf(orderInfo.getUserId()));
tbPayServiceImpl.vipPay(finalAmount, Integer.valueOf(orderInfo.getUserId()), payDTO.getVipUserId());
orderInfo.setPayOrderNo("vipPay".concat(SnowFlakeUtil.generateOrderNo()));
orderInfo.setPayType("deposit");
break;
@ -1749,16 +1761,23 @@ 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) {
return orderInfoMapper.update(null, new LambdaUpdateWrapper<TbOrderInfo>()
.eq(TbOrderInfo::getId, orderId)
.set(TbOrderInfo::getUserId, updateVipDTO.getVipUserId()));
.set(TbOrderInfo::getUserId, shopUser.getUserId())
.set(TbOrderInfo::getMemberId, updateVipDTO.getVipUserId()));
} else {
return orderInfoMapper.update(null, new LambdaUpdateWrapper<TbOrderInfo>()
.eq(TbOrderInfo::getId, orderId)
.set(TbOrderInfo::getUserId, null)
.set(TbOrderInfo::getUserId, null));
}
}