package com.ruoyi.user.service.impl;
|
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.ruoyi.common.core.constant.Constants;
|
import com.ruoyi.common.core.exception.GlobalException;
|
import com.ruoyi.order.api.entity.Order;
|
import com.ruoyi.order.api.feignClient.WithdrawClient;
|
import com.ruoyi.user.entity.RecoveryServe;
|
import com.ruoyi.user.entity.User;
|
import com.ruoyi.user.service.RecoveryServeService;
|
import com.ruoyi.user.service.UserService;
|
import com.ruoyi.user.service.WithdrawService;
|
import com.ruoyi.user.vo.WithdrawListVO;
|
import com.ruoyi.user.vo.WithdrawMoneyVO;
|
import com.ruoyi.user.vo.WithdrawOrderVO;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
/**
|
* 用户提现申请记录表 服务实现类
|
*
|
* @author hjl
|
* @since 2024-06-07
|
*/
|
@Service
|
public class WithdrawServiceImpl implements WithdrawService {
|
|
@Resource
|
private RecoveryServeService recoveryServeService;
|
@Resource
|
private UserService userService;
|
@Resource
|
private WithdrawClient withdrawClient;
|
|
@Override
|
public WithdrawListVO withdrawList(Integer userid, Integer pageNum, Integer pageSize) {
|
WithdrawListVO withdrawList = new WithdrawListVO();
|
Page<Order> orderList = withdrawClient.withdrawListByUser(userid, pageNum, pageSize).getData();
|
// 总金额
|
BigDecimal totalMoney = BigDecimal.ZERO;
|
// 未提现金额
|
BigDecimal undelivered = BigDecimal.ZERO;
|
// 已提现金额
|
BigDecimal withdrawn = BigDecimal.ZERO;
|
if (!orderList.getRecords().isEmpty()) {
|
// 总金额
|
totalMoney = orderList.getRecords().stream().map(Order::getOrderMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
|
BigDecimal reduce = orderList.getRecords().stream().filter(e->e.getSubsidy()!=null).map(Order::getSubsidy).reduce(BigDecimal.ZERO, BigDecimal::add);
|
totalMoney = reduce.add(totalMoney);
|
// 未提现金额withdrawn
|
withdrawn = orderList.getRecords().stream().filter(data -> Constants.ZERO.equals(data.getIsWithdrawal()))
|
.map(Order::getOrderMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
|
BigDecimal reduce1 = orderList.getRecords().stream().filter(data -> Constants.ZERO.equals(data.getIsWithdrawal())&&data.getSubsidy()!=null)
|
.map(Order::getSubsidy).reduce(BigDecimal.ZERO, BigDecimal::add);
|
withdrawn = reduce1.add(withdrawn);
|
// 已提现金额
|
undelivered = orderList.getRecords().stream().filter(data -> Constants.ONE.equals(data.getIsWithdrawal()))
|
.map(Order::getOrderMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
|
BigDecimal reduce2 = orderList.getRecords().stream().filter(data -> Constants.ONE.equals(data.getIsWithdrawal())&&data.getSubsidy()!=null)
|
.map(Order::getSubsidy).reduce(BigDecimal.ZERO, BigDecimal::add);
|
undelivered = reduce2.add(undelivered);
|
}
|
withdrawList.setMoneyCount(new WithdrawMoneyVO(totalMoney, undelivered, withdrawn));
|
// 回收服务列表
|
List<Integer> serveIds = orderList.getRecords().stream().map(Order::getServeId).collect(Collectors.toList());
|
LambdaQueryChainWrapper<RecoveryServe> wrapper = recoveryServeService.lambdaQuery()
|
.eq(RecoveryServe::getIsDelete, 0);
|
wrapper = serveIds.isEmpty() ? wrapper : wrapper.in(RecoveryServe::getId, serveIds);
|
List<RecoveryServe> serveList = wrapper.list();
|
Map<Integer, RecoveryServe> serveMap = serveList.stream().collect(Collectors.toMap(RecoveryServe::getId, serve -> serve));
|
// 订单列表
|
List<WithdrawOrderVO> list = new ArrayList<>();
|
for (Order order : orderList.getRecords()) {
|
RecoveryServe recoveryServe = serveMap.get(order.getServeId());
|
WithdrawOrderVO withdrawOrder = new WithdrawOrderVO();
|
withdrawOrder.setOrderId(order.getId());
|
withdrawOrder.setOrderNumber(order.getOrderNumber());
|
withdrawOrder.setServeId(order.getServeId());
|
withdrawOrder.setServeName(recoveryServe.getServeName());
|
withdrawOrder.setServeDescribe(recoveryServe.getServeDescribe());
|
withdrawOrder.setCover(recoveryServe.getCover());
|
withdrawOrder.setCompleteTime(order.getCreateTime());
|
withdrawOrder.setIsWithdrawal(order.getIsWithdrawal());
|
withdrawOrder.setMoney(order.getSubsidy()!=null?order.getSubsidy().add(order.getOrderMoney()):order.getOrderMoney());
|
withdrawOrder.setPackageInfo(order.getPackageInfo());
|
if (order.getAddress()!=null) {
|
withdrawOrder.setAddress(order.getReservationAddress() + order.getAddress());
|
}else {
|
withdrawOrder.setAddress(order.getReservationAddress());
|
}
|
list.add(withdrawOrder);
|
}
|
Page<WithdrawOrderVO> page = new Page<>();
|
page.setSize(orderList.getSize());
|
page.setCurrent(orderList.getCurrent());
|
page.setPages(orderList.getPages());
|
page.setTotal(orderList.getTotal());
|
page.setRecords(list);
|
withdrawList.setWithdrawOrder(page);
|
return withdrawList;
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public Boolean confirmWithdraw(String orderId, Integer userid) {
|
User user = userService.lambdaQuery().eq(User::getId, userid).eq(User::getIsDelete, 0).one();
|
if (null == user) {
|
throw new GlobalException("提现失败,登录用户信息异常!");
|
}
|
return withdrawClient.confirmWithdrawByUser(orderId, userid, user.getOpenId(), user.getPhone()).getData();
|
}
|
|
}
|