1.代客下单 支付折扣

This commit is contained in:
SongZhang 2024-09-03 11:09:36 +08:00
parent 37be5a521e
commit 44329cc64e
1 changed files with 8 additions and 5 deletions

View File

@ -38,6 +38,8 @@ import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;
@ -350,14 +352,15 @@ public class TbPayServiceImpl implements TbPayService {
throw new BadRequestException("用户不存在或已被禁用");
}
long flag = shopUserMapper.decrBalance(Integer.valueOf(orderInfo.getUserId()), orderInfo.getOrderAmount());
BigDecimal finalAmount = orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(discount)).setScale(2, RoundingMode.UP);
long flag = shopUserMapper.decrBalance(Integer.valueOf(orderInfo.getUserId()), finalAmount);
if (flag < 1) {
throw new BadRequestException("余额不足或扣除余额失败");
}
TbShopUserFlow userFlow = new TbShopUserFlow();
userFlow.setAmount(orderInfo.getOrderAmount());
userFlow.setBalance(shopUser.getAmount());
userFlow.setAmount(finalAmount);
userFlow.setBalance(shopUser.getAmount().subtract(finalAmount));
userFlow.setShopUserId(shopUser.getId());
userFlow.setBizCode("vipCardCash");
userFlow.setBizName("余额支付");
@ -365,7 +368,7 @@ public class TbPayServiceImpl implements TbPayService {
userFlow.setType("-");
shopUserFlowMapper.insert(userFlow);
orderInfo.setPayAmount(orderInfo.getOrderAmount());
orderInfo.setPayAmount(finalAmount);
orderInfo.setPayType("cash");
orderInfo.setStatus("closed");
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
@ -409,7 +412,7 @@ public class TbPayServiceImpl implements TbPayService {
// return Result.fail(CodeEnum.PAYTYPENOEXIST);
// }
orderInfo.setPayAmount(orderInfo.getOrderAmount());
orderInfo.setPayAmount(orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(payDTO.getDiscount()).setScale(2, RoundingMode.UP)));
orderInfo.setPayType("cash");
orderInfo.setStatus("closed");
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));