Merge remote-tracking branch 'origin/hph' into test

# Conflicts:
#	eladmin-system/src/main/java/cn/ysk/cashier/service/impl/TbPayServiceImpl.java
This commit is contained in:
牛叉闪闪
2024-09-02 14:43:29 +08:00
9 changed files with 124 additions and 227 deletions

View File

@@ -1,6 +1,5 @@
package cn.ysk.cashier.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.ysk.cashier.dto.ScanPayDTO;
import cn.ysk.cashier.dto.shoptable.PayDTO;
@@ -27,8 +26,7 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Timestamp;
import java.util.List;
@Service
@@ -298,7 +296,7 @@ public class TbPayServiceImpl implements TbPayService {
private final TbShopUserFlowMapper shopUserFlowMapper;
@Override
public TbOrderInfo vipPay(@NotNull Integer shopId, @NotNull Integer orderId, Double discount, Integer vipUserId) {
public TbOrderInfo vipPay(@NotNull Integer shopId, @NotNull Integer orderId) {
TbOrderInfo orderInfo = orderInfoMapper.selectById(orderId);
@@ -310,9 +308,6 @@ public class TbPayServiceImpl implements TbPayService {
throw new BadRequestException("订单非未支付状态");
}
if (vipUserId != null) {
orderInfo.setUserId(String.valueOf(vipUserId));
}
// 扣减会员余额
TbShopUser shopUser = shopUserMapper.selectOne(new LambdaUpdateWrapper<TbShopUser>()
@@ -323,29 +318,22 @@ public class TbPayServiceImpl implements TbPayService {
throw new BadRequestException("用户不存在或已被禁用");
}
BigDecimal payMount = discount == null ? orderInfo.getOrderAmount() : orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(discount)).setScale(2, RoundingMode.UP);
long flag = shopUserMapper.decrBalance(Integer.valueOf(orderInfo.getUserId()), payMount);
long flag = shopUserMapper.decrBalance(Integer.valueOf(orderInfo.getUserId()), orderInfo.getOrderAmount());
if (flag < 1) {
throw new BadRequestException("余额不足或扣除余额失败");
}
TbShopUserFlow userFlow = new TbShopUserFlow();
userFlow.setAmount(payMount);
userFlow.setAmount(orderInfo.getOrderAmount());
userFlow.setBalance(shopUser.getAmount());
userFlow.setShopUserId(shopUser.getId());
userFlow.setBizCode("vipCardCash");
userFlow.setBizName("余额支付");
userFlow.setCreateTime(DateUtil.date());
userFlow.setBizName("代客下单会员余额支付");
userFlow.setCreateTime(new Timestamp(System.currentTimeMillis()));
userFlow.setType("-");
shopUserFlowMapper.insert(userFlow);
orderInfo.setPayAmount(payMount);
if (discount != null && discount != 1) {
orderInfo.setDiscountAmount(orderInfo.getOrderAmount().subtract(orderInfo.getPayAmount()));
orderInfo.setDiscountRatio(BigDecimal.valueOf(discount));
}
orderInfo.setPayAmount(orderInfo.getOrderAmount());
orderInfo.setPayType("cash");
orderInfo.setStatus("closed");
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
@@ -384,12 +372,7 @@ public class TbPayServiceImpl implements TbPayService {
// return Result.fail(CodeEnum.PAYTYPENOEXIST);
// }
orderInfo.setPayAmount(payDTO.getDiscount() == null ? orderInfo.getOrderAmount() : orderInfo.getOrderAmount()
.multiply(BigDecimal.valueOf(payDTO.getDiscount())).setScale(2, RoundingMode.UP));
if (payDTO.getDiscount() != null && payDTO.getDiscount() != 1) {
orderInfo.setDiscountAmount(orderInfo.getOrderAmount().subtract(orderInfo.getPayAmount()));
orderInfo.setDiscountRatio(BigDecimal.valueOf(payDTO.getDiscount()));
}
orderInfo.setPayAmount(orderInfo.getOrderAmount());
orderInfo.setPayType("cash");
orderInfo.setStatus("closed");
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));

View File

@@ -32,9 +32,9 @@ import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.*;
import java.util.regex.Pattern;
/**
* @author lyf
@@ -252,7 +252,7 @@ public class TbShopUserServiceImpl implements TbShopUserService {
flow.setShopUserId(tbShopUser.getId());
flow.setAmount(amount);
flow.setBalance(tbShopUser.getAmount());
flow.setCreateTime(new Date());
flow.setCreateTime(new Timestamp(System.currentTimeMillis()));
tbShopUserFlowMapper.insert(flow);