bug修改

This commit is contained in:
zengtao01
2024-07-24 14:21:38 +08:00
parent ee29e19d95
commit 82eb8b56ce
32 changed files with 996 additions and 32 deletions

View File

@ -143,8 +143,8 @@ public class CardController {
@PutMapping("/recharge")
@Operation(summary = "充值")
//@PreAuthorize("@ss.hasPermission('member:card:update')")
public CommonResult<Boolean> recharge(BigDecimal money) {
return success(cardService.recharge(money, CardDO.ADD));
public CommonResult<Boolean> recharge(BigDecimal money,BigDecimal giftMoney) {
return success(cardService.recharge(money, CardDO.ADD,giftMoney));
}
@GetMapping("/getMoney")

View File

@ -99,9 +99,9 @@ public class AppCardController {
@PutMapping("/recharge")
@Operation(summary = "充值")
//@PreAuthorize("@ss.hasPermission('member:card:update')")
public CommonResult<Boolean> recharge(BigDecimal money) {
public CommonResult<Boolean> recharge(BigDecimal money,BigDecimal giftMoney) {
BigDecimal bigDecimal = money.divide(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP);
return success(cardService.recharge(bigDecimal,CardDO.ADD));
return success(cardService.recharge(bigDecimal,CardDO.ADD,giftMoney));
}

View File

@ -67,5 +67,11 @@ public class AppDiningPlatesController {
return success(diningPlatesService.getMoney(cId,dishesId));
}
@GetMapping("/getBind")
@Operation(summary = "获取绑定餐盘")
public CommonResult<List<String>> getBind() {
return success(diningPlatesService.getBindDiningPlatesList());
}
}

View File

@ -19,4 +19,6 @@ public class AppUserInfo {
private String dishesName;
private BigDecimal dishesBasePrice;
private BigDecimal orderMoney;
}

View File

@ -63,4 +63,14 @@ public class CardDO extends BaseDO {
*/
private BigDecimal giftAmount;
/**
* 现金金额
*/
private BigDecimal cashAmount;
/**
* 微信充值金额
*/
private BigDecimal wxAmount;
}

View File

@ -67,4 +67,19 @@ public class DishOrderDO extends BaseDO {
* 餐盘编号
*/
private String diningPlatesNum;
/**
* 赠送金额
*/
private BigDecimal giftAmount;
/**
* 现金金额
*/
private BigDecimal cashAmount;
/**
* 微信充值金额
*/
private BigDecimal wxAmount;
}

View File

@ -70,8 +70,35 @@ public class BalanceDeductionJob implements JobHandler {
Long userId = dishOrderDO.getUserId();
CardDO cardDO = new CardDO();
cardDO.setType(TimePeriodEnum.getTimePeriod(LocalDateTime.now()));
BigDecimal oldMoney = cardService.getMoneyByUserId(userId);
cardDO.setMoney(oldMoney.subtract(total).setScale(2, BigDecimal.ROUND_HALF_UP));
CardDO oldCardDO = cardService.getCardDoByUserId(userId);
BigDecimal money = oldCardDO.getMoney();
BigDecimal wxAmount = oldCardDO.getWxAmount();
BigDecimal giftAmount = oldCardDO.getGiftAmount();
BigDecimal cashAmount = oldCardDO.getCashAmount();
cardDO.setMoney(money.subtract(total).setScale(2, BigDecimal.ROUND_HALF_UP));
if(total.compareTo(wxAmount)<=0){
cardDO.setWxAmount(wxAmount.subtract(total).setScale(2, BigDecimal.ROUND_HALF_UP));
dishOrderDO.setWxAmount(total);
}else {
cardDO.setWxAmount(BigDecimal.ZERO);
dishOrderDO.setWxAmount(wxAmount);
BigDecimal total1 = total.subtract(wxAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
if(total1.compareTo(cashAmount)<=0){
cardDO.setCashAmount(cashAmount.subtract(total1).setScale(2, BigDecimal.ROUND_HALF_UP));
dishOrderDO.setCashAmount(total1);
}else {
cardDO.setCashAmount(BigDecimal.ZERO);
dishOrderDO.setCashAmount(cashAmount);
BigDecimal total2 = total1.subtract(cashAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
cardDO.setGiftAmount(giftAmount.subtract(total2).setScale(2, BigDecimal.ROUND_HALF_UP));
dishOrderDO.setGiftAmount(total2);
}
}
cardDO.setUserId(userId);
cardDO.setChangeMoney(total);
cardDO.setFlag(CardDO.MINUS);

View File

@ -69,7 +69,7 @@ public interface CardService {
/**
* 余额变动
*/
Boolean recharge(BigDecimal money, String flag);
Boolean recharge(BigDecimal money, String flag,BigDecimal giftMoney);
/**
* 获取余额
@ -81,6 +81,7 @@ public interface CardService {
*/
BigDecimal getMoneyByUserId(Long userId);
CardDO getCardDoByUserId(Long userId);
/**
* 批量扣款
*/
@ -98,5 +99,5 @@ public interface CardService {
FaceVo getFaceData(String faceId);
void refund(Long userId,BigDecimal money);
void refund(Long userId,BigDecimal money,Long orderId);
}

View File

@ -13,8 +13,10 @@ import cn.iocoder.yudao.module.member.controller.app.card.vo.AppCardMonthVO;
import cn.iocoder.yudao.module.member.controller.app.card.vo.AppCardPageReqVO;
import cn.iocoder.yudao.module.member.controller.app.card.vo.FaceVo;
import cn.iocoder.yudao.module.member.dal.dataobject.card.CardDO;
import cn.iocoder.yudao.module.member.dal.dataobject.order.DishOrderDO;
import cn.iocoder.yudao.module.member.dal.mysql.card.CardMapper;
import cn.iocoder.yudao.module.member.dal.mysql.group.MemberGroupMapper;
import cn.iocoder.yudao.module.member.dal.mysql.order.DishOrderMapper;
import cn.iocoder.yudao.module.member.enums.CostTypeEnum;
import cn.iocoder.yudao.module.member.util.MemberConstants;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@ -50,6 +52,9 @@ public class CardServiceImpl implements CardService {
@Resource
private MemberGroupMapper memberGroupMapper;
@Resource
private DishOrderMapper dishOrderMapper;
@Override
public Long createCard(CardSaveReqVO createReqVO) {
// 插入
@ -99,7 +104,7 @@ public class CardServiceImpl implements CardService {
@Override
public Boolean recharge(BigDecimal money, String flag) {
public Boolean recharge(BigDecimal money, String flag,BigDecimal giftMoney) {
//获取最新余额
CardDO lastCardDO = getLastCardDO();
CardDO cardDO = new CardDO();
@ -108,14 +113,21 @@ public class CardServiceImpl implements CardService {
cardDO.setChangeMoney(money);
cardDO.setType(CostTypeEnum.WX_PAY.getCode());
BigDecimal oldMoney = BigDecimal.ZERO;
BigDecimal wxOldMoney= BigDecimal.ZERO;
BigDecimal giftOldMoney= BigDecimal.ZERO;
if (ObjectUtil.isNotEmpty(lastCardDO) && lastCardDO.getMoney() != null) {
oldMoney = lastCardDO.getMoney();
}
if (CardDO.ADD.equals(flag)) {
cardDO.setMoney(oldMoney.add(money).setScale(2, BigDecimal.ROUND_HALF_UP));
} else {
cardDO.setMoney(oldMoney.subtract(money).setScale(2, BigDecimal.ROUND_HALF_UP));
if (ObjectUtil.isNotEmpty(lastCardDO) && lastCardDO.getWxAmount() != null) {
wxOldMoney = lastCardDO.getWxAmount();
}
if (ObjectUtil.isNotEmpty(lastCardDO) && lastCardDO.getGiftAmount() != null) {
giftOldMoney = lastCardDO.getGiftAmount();
}
cardDO.setMoney(oldMoney.add(money).setScale(2, BigDecimal.ROUND_HALF_UP));
cardDO.setWxAmount(wxOldMoney.add(money).setScale(2, BigDecimal.ROUND_HALF_UP));
cardDO.setGiftAmount(giftOldMoney.add(giftMoney).setScale(2, BigDecimal.ROUND_HALF_UP));
return cardMapper.insert(cardDO) > 0;
}
@ -138,6 +150,14 @@ public class CardServiceImpl implements CardService {
return lastCardDO.getMoney();
}
@Override
public CardDO getCardDoByUserId(Long userId) {
CardDO lastCardDO = cardMapper.selectOne(Wrappers.<CardDO>lambdaQuery().eq(CardDO::getUserId, userId)
.orderByDesc(CardDO::getCreateTime).last(MemberConstants.LIMIT_ONE));
return lastCardDO;
}
/**
* 获取当前用户最新余额明细
*
@ -213,6 +233,8 @@ public class CardServiceImpl implements CardService {
add.setType(CostTypeEnum.ADMIN_PAY.getCode());
BigDecimal oldMoney = cardDO.getMoney();
add.setMoney(oldMoney.add(vo.getMoney()).setScale(2, BigDecimal.ROUND_HALF_UP));
BigDecimal cashOldMoney = cardDO.getCashAmount();
add.setCashAmount(cashOldMoney.add(vo.getMoney()).setScale(2, BigDecimal.ROUND_HALF_UP));
addList.add(add);
}
//添加新的用户金额
@ -224,6 +246,7 @@ public class CardServiceImpl implements CardService {
add.setChangeMoney(vo.getMoney());
add.setType(CostTypeEnum.ADMIN_PAY.getCode());
add.setMoney(vo.getMoney());
add.setCashAmount(vo.getMoney());
addList.add(add);
}
}
@ -238,20 +261,47 @@ public class CardServiceImpl implements CardService {
}
@Override
public void refund(Long userId,BigDecimal money) {
public void refund(Long userId,BigDecimal money,Long orderId) {
//获取最新余额
CardDO lastCardDO = cardMapper.selectOne(Wrappers.<CardDO>lambdaQuery().eq(CardDO::getUserId, userId)
.orderByDesc(CardDO::getCreateTime).last(MemberConstants.LIMIT_ONE));
DishOrderDO dishOrderDO = dishOrderMapper.selectById(orderId);
CardDO cardDO = new CardDO();
cardDO.setUserId(userId);
cardDO.setFlag(CardDO.ADD);
cardDO.setChangeMoney(money);
cardDO.setType(CostTypeEnum.REFUND.getCode());
BigDecimal oldMoney = BigDecimal.ZERO;
if (ObjectUtil.isNotEmpty(lastCardDO) && lastCardDO.getMoney() != null) {
oldMoney = lastCardDO.getMoney();
}
cardDO.setMoney(oldMoney.add(money).setScale(2, BigDecimal.ROUND_HALF_UP));
BigDecimal wxAmount = lastCardDO.getWxAmount();
BigDecimal cashAmount = lastCardDO.getCashAmount();
BigDecimal giftAmount = lastCardDO.getGiftAmount();
BigDecimal dishWxAmount = dishOrderDO.getWxAmount();
BigDecimal dishCashAmount = dishOrderDO.getCashAmount();
BigDecimal dishGiftAmount = dishOrderDO.getGiftAmount();
if(money.compareTo(dishGiftAmount)<=0){
cardDO.setGiftAmount(giftAmount.add(money).setScale(2, BigDecimal.ROUND_HALF_UP));
}else {
cardDO.setGiftAmount(giftAmount.add(dishGiftAmount).setScale(2, BigDecimal.ROUND_HALF_UP));
BigDecimal money1 = money.subtract(dishGiftAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
if(money1.compareTo(dishCashAmount)<=0){
cardDO.setCashAmount(cashAmount.add(money1).setScale(2, BigDecimal.ROUND_HALF_UP));
}else {
cardDO.setCashAmount(cashAmount.add(dishCashAmount).setScale(2, BigDecimal.ROUND_HALF_UP));
BigDecimal money2 = money1.subtract(dishCashAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
cardDO.setWxAmount(wxAmount.add(money2).setScale(2, BigDecimal.ROUND_HALF_UP));
}
}
cardMapper.insert(cardDO);
}
}

View File

@ -98,4 +98,9 @@ public interface DiningPlatesService {
AppUserInfo getMoney(String diningPlatesNum, Long dishId);
/**
* 获取绑定餐盘列表
* @return
*/
List<String> getBindDiningPlatesList();
}

View File

@ -38,6 +38,7 @@ import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*;
@ -349,6 +350,7 @@ public class DiningPlatesServiceImpl implements DiningPlatesService {
}
@Override
@Transactional(rollbackFor = Exception.class)
public void unbind(String diningPlatesNum) {
String money = stringRedisTemplate.opsForValue().get(diningPlatesNum);
@ -363,6 +365,9 @@ public class DiningPlatesServiceImpl implements DiningPlatesService {
.eq(DiningPlatesDO::getDiningPlatesNum, diningPlatesNum)
.last("limit 1"));
dishOrderMapper.update(Wrappers.<DishOrderDO>lambdaUpdate()
.set(DishOrderDO::getOrderStatus,"1")
.eq(DishOrderDO::getId,diningPlatesDO.getOrderId()));
diningPlatesMapper.update(Wrappers.<DiningPlatesDO>lambdaUpdate()
.set(DiningPlatesDO::getPayFlag, DiningPlatesDO.TO_PAY)
.set(DiningPlatesDO::getStatus, DiningPlatesDO.FREE)
@ -370,6 +375,8 @@ public class DiningPlatesServiceImpl implements DiningPlatesService {
.set(DiningPlatesDO::getBindingTime, null)
.set(DiningPlatesDO::getOrderId, null)
.eq(DiningPlatesDO::getId,diningPlatesDO.getId()));
}
@Override
@ -386,9 +393,15 @@ public class DiningPlatesServiceImpl implements DiningPlatesService {
appUserInfo.setNickname(memberUserDO.getNickname())
.setDishesName(dish.getDishesName())
.setDishesBasePrice(dish.getDishesBasePrice())
.setMoney(moneyByUserId);
.setMoney(moneyByUserId).setOrderMoney(new BigDecimal(stringRedisTemplate.opsForValue().get(diningPlatesNum)));
return appUserInfo;
}
@Override
public List<String> getBindDiningPlatesList() {
List<DiningPlatesDO> diningPlatesDOS = diningPlatesMapper.selectList(Wrappers.<DiningPlatesDO>lambdaQuery()
.isNotNull(DiningPlatesDO::getUserId));
List<String> list = diningPlatesDOS.stream().map(DiningPlatesDO::getDiningPlatesNum).collect(Collectors.toList());
return list;
}
}

View File

@ -50,7 +50,7 @@ public class RefundServiceImpl implements RefundService {
RefundDO updateObj = BeanUtils.toBean(updateReqVO, RefundDO.class);
refundMapper.updateById(updateObj);
if(RefundStatusEnum.SUCCESS.getCode().equals(updateReqVO.getStatus())){
cardService.refund(updateReqVO.getUserId(),updateReqVO.getMoney());
cardService.refund(updateReqVO.getUserId(),updateReqVO.getMoney(),updateReqVO.getOrderId());
}
}