退款提现
This commit is contained in:
		| @ -160,5 +160,17 @@ public class CardController { | ||||
|         return success(cardService.rechargeByAdmin(vo)); | ||||
|     } | ||||
|  | ||||
|     @GetMapping("/getCashMoney") | ||||
|     @Operation(summary = "获取现金充值") | ||||
|     public CommonResult<BigDecimal> getCashMoney(Long userId) { | ||||
|         return success(cardService.getCashMoney(userId)); | ||||
|     } | ||||
|  | ||||
|     @GetMapping("/cashDraw") | ||||
|     @Operation(summary = "现金提现") | ||||
|     public CommonResult<Boolean> cashDraw(Long userId,BigDecimal money) { | ||||
|         return success(cardService.cashDraw(userId,money)); | ||||
|     } | ||||
|  | ||||
|  | ||||
| } | ||||
| @ -17,4 +17,5 @@ public class MemberUserListVO extends PageParam { | ||||
|     @Schema(description = "小组id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||||
|     private Long groupId; | ||||
|     private String name; | ||||
|     private String mobile; | ||||
| } | ||||
|  | ||||
| @ -25,7 +25,6 @@ import org.springframework.web.bind.annotation.RestController; | ||||
| import javax.annotation.Resource; | ||||
| import javax.validation.Valid; | ||||
| import java.math.BigDecimal; | ||||
| import java.math.RoundingMode; | ||||
|  | ||||
| import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||||
|  | ||||
| @ -100,8 +99,8 @@ public class AppCardController { | ||||
|     @Operation(summary = "充值") | ||||
|     //@PreAuthorize("@ss.hasPermission('member:card:update')") | ||||
|     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,giftMoney)); | ||||
|         //BigDecimal bigDecimal = money.divide(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP); | ||||
|         return success(cardService.recharge(money,CardDO.ADD,giftMoney)); | ||||
|  | ||||
|     } | ||||
|  | ||||
|  | ||||
| @ -30,6 +30,7 @@ public class DishOrderDO extends BaseDO { | ||||
|  | ||||
|     public final static String COMPLETE = "1"; | ||||
|     public final static String INCOMPLETE = "0"; | ||||
|     public final static String TOCOMPLETE = "2"; | ||||
|  | ||||
|  | ||||
|     /** | ||||
|  | ||||
| @ -106,6 +106,7 @@ public interface MemberUserMapper extends BaseMapperX<MemberUserDO> { | ||||
|         // 分页查询 | ||||
|         return selectPage(listVO, new LambdaQueryWrapperX<MemberUserDO>() | ||||
|                 .likeIfPresent(MemberUserDO::getNickname, listVO.getName()) | ||||
|                 .likeIfPresent(MemberUserDO::getMobile,listVO.getMobile()) | ||||
|                 .notIn(CollectionUtil.isNotEmpty(listVO.getIds()) ,MemberUserDO::getId, listVO.getIds()) | ||||
|                 .orderByDesc(MemberUserDO::getId)); | ||||
|     } | ||||
|  | ||||
| @ -17,7 +17,9 @@ public enum CostTypeEnum { | ||||
|     NOON("3", "午餐"), | ||||
|     NIGHT("4", "晚餐"), | ||||
|     ADMIN_PAY("5","管理后台充值"), | ||||
|     REFUND("6","退款") | ||||
|     REFUND("6","退款"), | ||||
|     WITHDRAW("7","微信提现"), | ||||
|     CASH_WITHDRAW("8","现金提现"), | ||||
|     ; | ||||
|  | ||||
|     /** | ||||
|  | ||||
| @ -54,7 +54,7 @@ public class BalanceDeductionJob implements JobHandler { | ||||
|         List<DiningPlatesDO> diningPlatesToCharging = platesService.getDiningPlatesToCharging(EXPIRATION_TIME); | ||||
|         int size = 0; | ||||
|  | ||||
|         if(CollectionUtil.isNotEmpty(diningPlatesToCharging)){ | ||||
|         if (CollectionUtil.isNotEmpty(diningPlatesToCharging)) { | ||||
|             List<Long> ids = diningPlatesToCharging.stream().map(DiningPlatesDO::getId).collect(Collectors.toList()); | ||||
|             List<Long> orderIds = diningPlatesToCharging.stream().map(DiningPlatesDO::getOrderId).collect(Collectors.toList()); | ||||
|             //先更改状态防止重复消费 | ||||
| @ -74,29 +74,38 @@ public class BalanceDeductionJob implements JobHandler { | ||||
|  | ||||
|  | ||||
|                 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); | ||||
|                 if (total.compareTo(money) > 0) { | ||||
|                     dishOrderDO.setOrderStatus(DishOrderDO.TOCOMPLETE); | ||||
|                 } else { | ||||
|                     dishOrderDO.setOrderStatus(DishOrderDO.COMPLETE); | ||||
|                     //计算金额 | ||||
|                     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.setGiftAmount(giftAmount.subtract(total2).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|                             dishOrderDO.setGiftAmount(total2); | ||||
|                         } | ||||
|                     } | ||||
|  | ||||
|                 } | ||||
|  | ||||
|                 cardDO.setUserId(userId); | ||||
| @ -104,8 +113,8 @@ public class BalanceDeductionJob implements JobHandler { | ||||
|                 cardDO.setFlag(CardDO.MINUS); | ||||
|                 cardService.insertOne(cardDO); | ||||
|                 list.add(cardDO); | ||||
|  | ||||
|                 dishOrderDO.setTotalMoney(total); | ||||
|                 dishOrderDO.setOrderStatus(DishOrderDO.COMPLETE); | ||||
|                 dishOrderDO.setUpdateTime(LocalDateTime.now()); | ||||
|                 stringRedisTemplate.delete(dishOrderDO.getDiningPlatesNum()); | ||||
|             }); | ||||
|  | ||||
| @ -100,4 +100,8 @@ public interface CardService { | ||||
|     FaceVo getFaceData(String faceId); | ||||
|  | ||||
|     void refund(Long userId,BigDecimal money,Long orderId); | ||||
|  | ||||
|     BigDecimal getCashMoney(Long userId); | ||||
|  | ||||
|     Boolean cashDraw(Long userId,BigDecimal money); | ||||
| } | ||||
| @ -2,6 +2,7 @@ package cn.iocoder.yudao.module.member.service.card; | ||||
|  | ||||
| import cn.hutool.core.collection.CollectionUtil; | ||||
| import cn.hutool.core.util.ObjectUtil; | ||||
| import cn.iocoder.yudao.framework.common.exception.ErrorCode; | ||||
| import cn.iocoder.yudao.framework.common.exception.ServiceException; | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||
| import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||||
| @ -19,6 +20,7 @@ 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.conditions.query.LambdaQueryWrapper; | ||||
| import com.baomidou.mybatisplus.core.toolkit.Wrappers; | ||||
| import org.springframework.stereotype.Service; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
| @ -35,8 +37,7 @@ 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.CARD_NOT_EXISTS; | ||||
| import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.NEED_ADD_USER; | ||||
| import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*; | ||||
|  | ||||
| /** | ||||
|  * 余额变动明细 Service 实现类 | ||||
| @ -115,6 +116,7 @@ public class CardServiceImpl implements CardService { | ||||
|         BigDecimal oldMoney = BigDecimal.ZERO; | ||||
|         BigDecimal wxOldMoney= BigDecimal.ZERO; | ||||
|         BigDecimal giftOldMoney= BigDecimal.ZERO; | ||||
|         BigDecimal cashAmount= BigDecimal.ZERO; | ||||
|         if (ObjectUtil.isNotEmpty(lastCardDO) && lastCardDO.getMoney() != null) { | ||||
|             oldMoney = lastCardDO.getMoney(); | ||||
|         } | ||||
| @ -124,11 +126,24 @@ public class CardServiceImpl implements CardService { | ||||
|         if (ObjectUtil.isNotEmpty(lastCardDO) && lastCardDO.getGiftAmount() != null) { | ||||
|             giftOldMoney = lastCardDO.getGiftAmount(); | ||||
|         } | ||||
|         if (ObjectUtil.isNotEmpty(lastCardDO) && lastCardDO.getGiftAmount() != null) { | ||||
|             cashAmount = lastCardDO.getCashAmount(); | ||||
|         } | ||||
|  | ||||
|         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; | ||||
|         cardDO.setCashAmount(cashAmount); | ||||
|         cardDO.setGiftAmount(giftOldMoney); | ||||
|         cardDO.setWxAmount(giftOldMoney); | ||||
|         if(cardDO.getMoney().compareTo(BigDecimal.ZERO) >0){ | ||||
|             BigDecimal wxAmount = money; | ||||
|             if(giftMoney!=null){ | ||||
|                 cardDO.setGiftAmount(giftOldMoney.add(giftMoney).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|                 wxAmount = wxAmount.subtract(giftMoney); | ||||
|             } | ||||
|             cardDO.setWxAmount(wxOldMoney.add(wxAmount).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|         } | ||||
|         int i =cardMapper.insert(cardDO); | ||||
|         return i > 0; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
| @ -233,10 +248,16 @@ 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)); | ||||
|  | ||||
|             if(cardDO.getMoney().compareTo(BigDecimal.ZERO) >0){ | ||||
|                 BigDecimal cashOldMoney = cardDO.getCashAmount(); | ||||
|                 add.setCashAmount(cashOldMoney.add(vo.getMoney()).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|                 add.setWxAmount(cardDO.getWxAmount()); | ||||
|                 add.setGiftAmount(cardDO.getGiftAmount()); | ||||
|             } | ||||
|             addList.add(add); | ||||
|         } | ||||
|  | ||||
|         //添加新的用户金额 | ||||
|         if (CollectionUtil.isNotEmpty(newIds)) { | ||||
|             for (Long id : newIds) { | ||||
| @ -304,4 +325,59 @@ public class CardServiceImpl implements CardService { | ||||
|         } | ||||
|         cardMapper.insert(cardDO); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     public BigDecimal checkOrder(Long userId) { | ||||
|  | ||||
|         LambdaQueryWrapper<DishOrderDO> wrapper = new LambdaQueryWrapper<>(); | ||||
|  | ||||
|         wrapper.eq(DishOrderDO::getUserId,userId); | ||||
|         wrapper.eq(DishOrderDO::getOrderStatus,DishOrderDO.TOCOMPLETE); | ||||
|  | ||||
|         List<DishOrderDO> dishOrderDOS = dishOrderMapper.selectList(wrapper); | ||||
|  | ||||
|         if(CollectionUtil.isNotEmpty(dishOrderDOS)){ | ||||
|             BigDecimal reduce = dishOrderDOS.stream().map(DishOrderDO::getTotalMoney).reduce(BigDecimal.ZERO, BigDecimal::add); | ||||
|             return reduce; | ||||
|         }else { | ||||
|             return BigDecimal.ZERO; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public BigDecimal getCashMoney(Long userId) { | ||||
|         CardDO lastCardDO = cardMapper.selectOne(Wrappers.<CardDO>lambdaQuery().eq(CardDO::getUserId, userId) | ||||
|                 .orderByDesc(CardDO::getCreateTime).last(MemberConstants.LIMIT_ONE)); | ||||
|         if(ObjectUtil.isNotEmpty(lastCardDO)){ | ||||
|             return lastCardDO.getCashAmount(); | ||||
|         } | ||||
|         return BigDecimal.ZERO; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Boolean cashDraw(Long userId,BigDecimal money) { | ||||
|         CardDO lastCardDO = cardMapper.selectOne(Wrappers.<CardDO>lambdaQuery().eq(CardDO::getUserId, userId) | ||||
|                 .orderByDesc(CardDO::getCreateTime).last(MemberConstants.LIMIT_ONE)); | ||||
|         if(ObjectUtil.isEmpty(lastCardDO) || lastCardDO.getCashAmount().compareTo(BigDecimal.ZERO)<1 | ||||
|             || money.compareTo(lastCardDO.getCashAmount())>0){ | ||||
|             throw exception(CASH_AMOUNT_NOT_ENOUGH); | ||||
|         } | ||||
|         CardDO cardDO = new CardDO(); | ||||
|         cardDO.setUserId(userId); | ||||
|         cardDO.setFlag(CardDO.MINUS); | ||||
|         cardDO.setChangeMoney(money); | ||||
|         cardDO.setType(CostTypeEnum.CASH_WITHDRAW.getCode()); | ||||
|  | ||||
|         BigDecimal oldMoney  = lastCardDO.getMoney(); | ||||
|         BigDecimal oldWxAmount = lastCardDO.getWxAmount(); | ||||
|         BigDecimal oldCashAmount = lastCardDO.getCashAmount(); | ||||
|         BigDecimal oldGiftAmount = lastCardDO.getGiftAmount(); | ||||
|  | ||||
|         cardDO.setWxAmount(oldWxAmount); | ||||
|         cardDO.setGiftAmount(oldGiftAmount); | ||||
|         cardDO.setMoney(oldMoney.subtract(money)); | ||||
|         cardDO.setCashAmount(oldCashAmount.subtract(money)); | ||||
|         int insert = cardMapper.insert(cardDO); | ||||
|         return insert>0; | ||||
|     } | ||||
| } | ||||
| @ -3,6 +3,7 @@ package cn.iocoder.yudao.module.member.service.diningplates; | ||||
| import cn.hutool.core.collection.CollectionUtil; | ||||
| import cn.hutool.core.util.StrUtil; | ||||
| import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||||
| import cn.iocoder.yudao.framework.common.exception.ErrorCode; | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||
| import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||||
| import cn.iocoder.yudao.framework.websocket.core.sender.WebSocketMessageSender; | ||||
| @ -167,6 +168,9 @@ public class DiningPlatesServiceImpl implements DiningPlatesService { | ||||
|                 .eq(MemberUserDO::getCardId, cardId) | ||||
|                 .last(MemberConstants.LIMIT_ONE)); | ||||
|         checkMemberUser(memberUserDO, false); | ||||
|         //订单验证 | ||||
|         checkOrder(memberUserDO.getId()); | ||||
|  | ||||
|         //余额验证 | ||||
|         BigDecimal money = cardService.getMoneyByUserId(memberUserDO.getId()); | ||||
|         checkMoney(money); | ||||
| @ -208,6 +212,8 @@ public class DiningPlatesServiceImpl implements DiningPlatesService { | ||||
|                 .eq(MemberUserDO::getFaceId, faceId) | ||||
|                 .last(MemberConstants.LIMIT_ONE)); | ||||
|         checkMemberUser(memberUserDO, true); | ||||
|         //订单验证 | ||||
|         checkOrder(memberUserDO.getId()); | ||||
|         //余额验证 | ||||
|         BigDecimal money = cardService.getMoneyByUserId(memberUserDO.getId()); | ||||
|         checkMoney(money); | ||||
| @ -293,6 +299,21 @@ public class DiningPlatesServiceImpl implements DiningPlatesService { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void checkOrder(Long userId) { | ||||
|  | ||||
|         LambdaQueryWrapper<DishOrderDO> wrapper = new LambdaQueryWrapper<>(); | ||||
|  | ||||
|         wrapper.eq(DishOrderDO::getUserId,userId); | ||||
|         wrapper.eq(DishOrderDO::getOrderStatus,DishOrderDO.TOCOMPLETE); | ||||
|  | ||||
|         List<DishOrderDO> dishOrderDOS = dishOrderMapper.selectList(wrapper); | ||||
|         BigDecimal moneyByUserId = cardService.getMoneyByUserId(userId); | ||||
|         ErrorCode code = new ErrorCode(1_004_099_008, "存在未支付完的订单,待支付金额:"+moneyByUserId.abs()+"元"); | ||||
|         if(CollectionUtil.isNotEmpty(dishOrderDOS)){ | ||||
|             throw exception(code); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|  | ||||
|     @Override | ||||
|     public List<DiningPlatesStoreVO> getDiningPlatesNum(LocalDateTime localDateTime, Integer time) { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 zengtao01
					zengtao01