支付修改
This commit is contained in:
@ -9,5 +9,18 @@ import java.math.BigDecimal;
|
||||
*/
|
||||
public interface CardApi {
|
||||
|
||||
/**
|
||||
* 微信充值
|
||||
* @param money
|
||||
* @param userId
|
||||
*/
|
||||
void recharge(BigDecimal money,Long userId);
|
||||
|
||||
/**
|
||||
* 微信提现
|
||||
* @param amount
|
||||
* @param userId
|
||||
*/
|
||||
void wxDraw(Integer amount, Long userId);
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.member.api.card;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.card.CardDO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.rechargeamount.RechargeAmountDO;
|
||||
import cn.iocoder.yudao.module.member.service.amount.DeductionService;
|
||||
import cn.iocoder.yudao.module.member.service.amount.WxRechargeService;
|
||||
import cn.iocoder.yudao.module.member.service.card.CardService;
|
||||
import cn.iocoder.yudao.module.member.service.rechargeamount.RechargeAmountService;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -21,7 +23,11 @@ public class CardApiImpl implements CardApi{
|
||||
private CardService cardService;
|
||||
@Resource
|
||||
private RechargeAmountService rechargeAmountService;
|
||||
@Resource
|
||||
private DeductionService deductionService;
|
||||
|
||||
@Resource
|
||||
private WxRechargeService wxRechargeService;
|
||||
|
||||
@Override
|
||||
public void recharge(BigDecimal money,Long userId){
|
||||
@ -32,6 +38,11 @@ public class CardApiImpl implements CardApi{
|
||||
giftMoney = giftMoney.add(recharge.getDonateMoney());
|
||||
}
|
||||
|
||||
cardService.recharge(money, CardDO.ADD,giftMoney,userId);
|
||||
wxRechargeService.wxRecharge(money, money.subtract(giftMoney),giftMoney,userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void wxDraw(Integer amount, Long userId) {
|
||||
deductionService.wxDraw(amount,userId);
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.member.dal.dataobject.card.CardDO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.diningplates.DiningPlatesDO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.order.DishOrderDO;
|
||||
import cn.iocoder.yudao.module.member.enums.TimePeriodEnum;
|
||||
import cn.iocoder.yudao.module.member.service.amount.DeductionService;
|
||||
import cn.iocoder.yudao.module.member.service.business.BusinessService;
|
||||
import cn.iocoder.yudao.module.member.service.card.CardService;
|
||||
import cn.iocoder.yudao.module.member.service.diningplates.DiningPlatesService;
|
||||
@ -48,6 +49,10 @@ public class BalanceDeductionJob implements JobHandler {
|
||||
private MemberUserService userService;
|
||||
@Resource
|
||||
private BusinessService businessService;
|
||||
|
||||
@Resource
|
||||
private DeductionService deductionService;
|
||||
|
||||
/**
|
||||
* 30分钟之后自动解绑并扣款
|
||||
*/
|
||||
@ -69,120 +74,13 @@ public class BalanceDeductionJob implements JobHandler {
|
||||
//platesService.updatePayFlag(ids,DiningPlatesDO.PAY);
|
||||
//获取用户订单
|
||||
List<DishOrderDO> toPay = orderService.getToPayByOrder(orderIds);
|
||||
//扣除余额
|
||||
List<CardDO> list = new ArrayList<>();
|
||||
|
||||
toPay.forEach(dishOrderDO -> {
|
||||
//新的总价
|
||||
String s = stringRedisTemplate.opsForValue().get(dishOrderDO.getDiningPlatesNum() + "-" + dishOrderDO.getStoreId());
|
||||
BigDecimal total = new BigDecimal(StrUtil.isBlank(s) ? "0" : s);
|
||||
//BigDecimal total = new BigDecimal(0.01);
|
||||
Long userId = dishOrderDO.getUserId();
|
||||
CardDO cardDO = new CardDO();
|
||||
cardDO.setType(TimePeriodEnum.getTimePeriod(dishOrderDO.getCreateTime()));
|
||||
CardDO oldCardDO = cardService.getCardDoByUserId(userId);
|
||||
|
||||
|
||||
BigDecimal money = oldCardDO.getMoney();
|
||||
//计算减免价格
|
||||
BigDecimal reductionAmount = BigDecimal.ZERO;
|
||||
if (total.compareTo(BigDecimal.ZERO) > 0) {
|
||||
reductionAmount = userService.getReductionAmount(userId, total, dishOrderDO.getCreateTime());
|
||||
}
|
||||
if(dishOrderDO.getReductionAmount().compareTo(BigDecimal.ZERO) > 0){
|
||||
reductionAmount = reductionAmount.add(dishOrderDO.getReductionAmount());
|
||||
dishOrderDO.setReductionAmount(reductionAmount);
|
||||
}else {
|
||||
dishOrderDO.setReductionAmount(reductionAmount);
|
||||
}
|
||||
dishOrderDO.setReductionState(reductionAmount.compareTo(BigDecimal.ZERO) > 0 ? "1" : "0");
|
||||
|
||||
//计算减免后的总价
|
||||
if (total.compareTo(reductionAmount) < 0) {
|
||||
total = BigDecimal.ZERO;
|
||||
} else {
|
||||
total = total.subtract(reductionAmount);
|
||||
}
|
||||
|
||||
BigDecimal wxAmount = oldCardDO.getWxAmount();
|
||||
BigDecimal giftAmount = oldCardDO.getGiftAmount();
|
||||
BigDecimal cashAmount = oldCardDO.getCashAmount();
|
||||
cardDO.setMoney(money.subtract(total).setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
//待支付金额 最大退款金额
|
||||
dishOrderDO.setRefundAmount(total);
|
||||
if (money.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
dishOrderDO.setPayAmount(total);
|
||||
dishOrderDO.setRefundAmount(BigDecimal.ZERO);
|
||||
} else {
|
||||
if (total.compareTo(money) > 0) {
|
||||
dishOrderDO.setPayAmount(total.subtract(money).setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
dishOrderDO.setRefundAmount(money);
|
||||
}
|
||||
}
|
||||
|
||||
if (total.compareTo(money) > 0) {
|
||||
dishOrderDO.setOrderStatus(DishOrderDO.TOCOMPLETE);
|
||||
dishOrderDO.setWxAmount(wxAmount);
|
||||
dishOrderDO.setCashAmount(cashAmount);
|
||||
dishOrderDO.setGiftAmount(giftAmount);
|
||||
} else {
|
||||
cardDO.setWxAmount(wxAmount);
|
||||
cardDO.setCashAmount(cashAmount);
|
||||
cardDO.setGiftAmount(giftAmount);
|
||||
dishOrderDO.setOrderStatus(DishOrderDO.COMPLETE);
|
||||
//计算金额
|
||||
if (total.compareTo(cashAmount) <= 0) {
|
||||
cardDO.setCashAmount(cashAmount.subtract(total).setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
dishOrderDO.setCashAmount(total);
|
||||
} else {
|
||||
cardDO.setCashAmount(BigDecimal.ZERO);
|
||||
dishOrderDO.setCashAmount(cashAmount);
|
||||
BigDecimal total1 = total.subtract(cashAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
if (total1.compareTo(giftAmount) <= 0) {
|
||||
cardDO.setGiftAmount(giftAmount.subtract(total1).setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
dishOrderDO.setGiftAmount(total1);
|
||||
} else {
|
||||
cardDO.setGiftAmount(BigDecimal.ZERO);
|
||||
dishOrderDO.setGiftAmount(giftAmount);
|
||||
BigDecimal total2 = total1.subtract(giftAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
cardDO.setWxAmount(wxAmount.subtract(total2).setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
dishOrderDO.setWxAmount(total2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cardDO.setUserId(userId);
|
||||
cardDO.setChangeMoney(total);
|
||||
cardDO.setFlag(CardDO.MINUS);
|
||||
cardService.insertOne(cardDO);
|
||||
//String redisData = stringRedisTemplate.opsForValue().get("DATA-money"+ userId);
|
||||
//
|
||||
//if(StrUtil.isNotBlank(redisData)){
|
||||
// stringRedisTemplate.opsForValue().set("DATA-money"+userId, cardDO.getMoney().toString());
|
||||
//
|
||||
//}
|
||||
list.add(cardDO);
|
||||
|
||||
dishOrderDO.setTotalMoney(total);
|
||||
dishOrderDO.setUpdateTime(LocalDateTime.now());
|
||||
stringRedisTemplate.delete(dishOrderDO.getDiningPlatesNum() + "-" + dishOrderDO.getStoreId());
|
||||
|
||||
//更新营业数据
|
||||
if(dishOrderDO.getOrderStatus().equals(DishOrderDO.COMPLETE)){
|
||||
StatisticsVo statisticsVo = new StatisticsVo();
|
||||
statisticsVo.setCarteenId(dishOrderDO.getStoreId());
|
||||
statisticsVo.setTotalMoney(dishOrderDO.getTotalMoney());
|
||||
statisticsVo.setOrder_sum(1);
|
||||
statisticsVo.setReduceMoney(dishOrderDO.getReductionAmount());
|
||||
statisticsVo.setTime(dishOrderDO.getCreateTime());
|
||||
statisticsVo.setOrderId(dishOrderDO.getId());
|
||||
businessService.updateStatistics(statisticsVo);
|
||||
}
|
||||
|
||||
deductionService.deduction(dishOrderDO);
|
||||
});
|
||||
//取消批量,防止同一人订餐少扣款
|
||||
//cardService.insertBatch(list);
|
||||
size = list.size();
|
||||
size = toPay.size();
|
||||
//餐盘解绑
|
||||
platesService.updateBind(ids);
|
||||
//更新订单状态和总价
|
||||
|
@ -10,7 +10,7 @@ public interface DeductionService {
|
||||
/**
|
||||
* 餐盘扣减余额
|
||||
*/
|
||||
DishOrderDO deduction(DishOrderDO dishOrderDO);
|
||||
void deduction(DishOrderDO dishOrderDO);
|
||||
|
||||
/**
|
||||
* 现金提现
|
||||
@ -18,7 +18,7 @@ public interface DeductionService {
|
||||
void cashDraw(Long userId, BigDecimal money);
|
||||
|
||||
/**
|
||||
* 微信提现
|
||||
* 微信提现 金额单位:分
|
||||
*/
|
||||
void wxDraw(Integer amount, Long userId);
|
||||
|
||||
|
@ -51,7 +51,7 @@ public class DeductionServiceImpl implements DeductionService {
|
||||
private BusinessService businessService;
|
||||
|
||||
@Override
|
||||
public DishOrderDO deduction(DishOrderDO dishOrderDO) {
|
||||
public void deduction(DishOrderDO dishOrderDO) {
|
||||
Long userId = dishOrderDO.getUserId();
|
||||
|
||||
BigDecimal newMoney;
|
||||
@ -175,7 +175,6 @@ public class DeductionServiceImpl implements DeductionService {
|
||||
statisticsVo.setOrderId(dishOrderDO.getId());
|
||||
businessService.updateStatistics(statisticsVo);
|
||||
}
|
||||
return dishOrderDO;
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,6 +26,7 @@ import cn.iocoder.yudao.module.member.dal.mysql.refundlog.RefundLogMapper;
|
||||
import cn.iocoder.yudao.module.member.enums.CostTypeEnum;
|
||||
import cn.iocoder.yudao.module.member.service.amount.AmountService;
|
||||
import cn.iocoder.yudao.module.member.service.amount.CashRechargeService;
|
||||
import cn.iocoder.yudao.module.member.service.amount.DeductionService;
|
||||
import cn.iocoder.yudao.module.member.service.amount.WxRechargeService;
|
||||
import cn.iocoder.yudao.module.member.util.MemberConstants;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@ -87,6 +88,9 @@ public class CardServiceImpl implements CardService {
|
||||
@Resource
|
||||
private CashRechargeService cashRechargeService;
|
||||
|
||||
@Resource
|
||||
private DeductionService deductionService;
|
||||
|
||||
@Override
|
||||
public Long createCard(CardSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
@ -201,62 +205,10 @@ public class CardServiceImpl implements CardService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void refund(Long userId, BigDecimal money, Long orderId) {
|
||||
//获取最新余额
|
||||
CardDO lastCardDO = cardMapper.selectOne(Wrappers.<CardDO>lambdaQuery().eq(CardDO::getUserId, userId)
|
||||
.orderByDesc(CardDO::getCreateTime).orderByDesc(CardDO::getId).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();
|
||||
|
||||
BigDecimal newMoney = money;
|
||||
if(oldMoney.compareTo(BigDecimal.ZERO)<0){
|
||||
newMoney = cardDO.getMoney();
|
||||
}
|
||||
|
||||
|
||||
if (cardDO.getMoney().compareTo(BigDecimal.ZERO) <= 0) {
|
||||
cardDO.setWxAmount(BigDecimal.ZERO);
|
||||
cardDO.setGiftAmount(BigDecimal.ZERO);
|
||||
cardDO.setCashAmount(BigDecimal.ZERO);
|
||||
} else {
|
||||
if (newMoney.compareTo(dishGiftAmount) <= 0) {
|
||||
cardDO.setGiftAmount(giftAmount.add(newMoney).setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
} else {
|
||||
cardDO.setGiftAmount(giftAmount.add(dishGiftAmount).setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
BigDecimal money1 = newMoney.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);
|
||||
if (money2.compareTo(dishWxAmount) <= 0) {
|
||||
cardDO.setWxAmount(wxAmount.add(money2).setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
} else {
|
||||
cardDO.setWxAmount(wxAmount.add(dishWxAmount).setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
deductionService.refund(userId, money,dishOrderDO);
|
||||
//记录
|
||||
refundLog(dishOrderDO,money);
|
||||
//订单处理
|
||||
@ -276,7 +228,6 @@ public class CardServiceImpl implements CardService {
|
||||
}
|
||||
}
|
||||
dishOrderMapper.updateById(dishOrderDO);
|
||||
cardMapper.insert(cardDO);
|
||||
}
|
||||
|
||||
public void handleOtherMoney(DishOrderDO dishOrderDO,BigDecimal money){
|
||||
@ -488,29 +439,8 @@ public class CardServiceImpl implements CardService {
|
||||
|
||||
@Override
|
||||
public Boolean cashDraw(Long userId, BigDecimal money) {
|
||||
CardDO lastCardDO = cardMapper.selectOne(Wrappers.<CardDO>lambdaQuery().eq(CardDO::getUserId, userId)
|
||||
.orderByDesc(CardDO::getCreateTime).orderByDesc(CardDO::getId).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;
|
||||
deductionService.cashDraw(userId, money);
|
||||
return true;
|
||||
}
|
||||
|
||||
void updateOrderStatus(Long userId) {
|
||||
|
@ -15,6 +15,7 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO;
|
||||
import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO;
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.divide.PayDivideRefundStatusRespEnum;
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.divide.PayDivideStatusRespEnum;
|
||||
import cn.iocoder.yudao.module.member.api.card.CardApi;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.divide.vo.DividePageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.divide.vo.DivideSaveReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.app.divide.vo.DrawMoneyVO;
|
||||
@ -93,6 +94,9 @@ public class DivideServiceImpl implements DivideService {
|
||||
@Resource
|
||||
private StringRedisTemplate divideRedisTemplate;
|
||||
|
||||
@Resource
|
||||
private CardApi cardApi;
|
||||
|
||||
|
||||
@Override
|
||||
public Long createDivide(DivideSaveReqVO createReqVO) {
|
||||
@ -740,27 +744,7 @@ public class DivideServiceImpl implements DivideService {
|
||||
|
||||
@Override
|
||||
public void subtractWx(Integer amount, Long userId) {
|
||||
DivideCardDO lastCardDO = divideCardMapper.selectOne(Wrappers.<DivideCardDO>lambdaQuery()
|
||||
.eq(DivideCardDO::getUserId, userId)
|
||||
.orderByDesc(DivideCardDO::getCreateTime)
|
||||
.orderByDesc(DivideCardDO::getId)
|
||||
.last("limit 1"));
|
||||
|
||||
BigDecimal changeMoney = new BigDecimal(amount).divide(new BigDecimal("100"));
|
||||
//获取最新余额
|
||||
DivideCardDO cardDO = new DivideCardDO();
|
||||
cardDO.setUserId(userId);
|
||||
cardDO.setFlag(DivideCardDO.MINUS);
|
||||
cardDO.setChangeMoney(changeMoney);
|
||||
cardDO.setType("7");
|
||||
BigDecimal oldMoney = lastCardDO.getMoney();
|
||||
BigDecimal wxOldMoney = lastCardDO.getWxAmount();
|
||||
|
||||
cardDO.setMoney(oldMoney.subtract(changeMoney).setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
cardDO.setWxAmount(wxOldMoney.subtract(changeMoney).setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||
cardDO.setGiftAmount(lastCardDO.getGiftAmount());
|
||||
cardDO.setCashAmount(lastCardDO.getCashAmount());
|
||||
divideCardMapper.insert(cardDO);
|
||||
cardApi.wxDraw(amount, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,4 +31,7 @@ public class AppSaveVO {
|
||||
|
||||
@Schema(description = "时段", example = "早")
|
||||
private String timeSlot;
|
||||
|
||||
@Schema(description = "", example = "早")
|
||||
private Long carteenId;
|
||||
}
|
||||
|
Reference in New Issue
Block a user