From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 25 二月 2025 16:41:22 +0800 Subject: [PATCH] 淘宝转链接口更新 --- fanli/src/main/java/com/yeshi/fanli/service/impl/money/TeamRewardDebtServiceImpl.java | 271 +++++++++++++++++++++++++++--------------------------- 1 files changed, 136 insertions(+), 135 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/money/TeamRewardDebtServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/money/TeamRewardDebtServiceImpl.java index 8fb5c03..82dac09 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/money/TeamRewardDebtServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/money/TeamRewardDebtServiceImpl.java @@ -1,135 +1,136 @@ -package com.yeshi.fanli.service.impl.money; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import javax.annotation.Resource; - -import com.yeshi.fanli.entity.order.UserOrderWeiQuanRecord; -import com.yeshi.fanli.service.inter.order.UserOrderWeiQuanRecordService; -import com.yeshi.fanli.util.StringUtil; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import com.yeshi.fanli.dao.mybatis.money.TeamRewardDebtMapper; -import com.yeshi.fanli.dao.mybatis.money.TeamRewardDebtRepayHistoryMapper; -import com.yeshi.fanli.entity.money.TeamRewardDebt; -import com.yeshi.fanli.entity.money.TeamRewardDebtRepayHistory; -import com.yeshi.fanli.exception.money.TeamRewardDebtException; -import com.yeshi.fanli.service.inter.money.TeamRewardDebtService; - -@Service -public class TeamRewardDebtServiceImpl implements TeamRewardDebtService { - @Resource - private TeamRewardDebtMapper teamRewardDebtMapper; - - @Resource - private TeamRewardDebtRepayHistoryMapper teamRewardDebtRepayHistoryMapper; - - @Resource - private UserOrderWeiQuanRecordService userOrderWeiQuanRecordService; - - @Transactional(rollbackFor = Exception.class) - @Override - public void addDebt(TeamRewardDebt debt) throws TeamRewardDebtException { - if (debt == null || debt.getOriginMoney() == null || debt.getOriginMoney() == null || debt.getUid() == null || StringUtil.isNullOrEmpty(debt.getTradeId()) || debt.getSourceType() == null) { - throw new TeamRewardDebtException(1, "鏁版嵁涓嶅畬鏁�"); - } - if (debt.getCreateTime() == null) - debt.setCreateTime(new Date()); - debt.setLeftMoney(debt.getOriginMoney()); - teamRewardDebtMapper.insertSelective(debt); - } - - @Transactional(rollbackFor = Exception.class) - @Override - public void repayDebt(Long debtId, BigDecimal money) throws TeamRewardDebtException { - TeamRewardDebt debt = teamRewardDebtMapper.selectByPrimaryKeyForUpdate(debtId); - if (debt == null) - throw new TeamRewardDebtException(1, "鍊哄姟ID涓嶅瓨鍦�"); - if (money == null || money.compareTo(new BigDecimal(0)) <= 0) - throw new TeamRewardDebtException(3, "杩橀挶蹇呴』澶т簬0"); - if (debt.getLeftMoney().compareTo(money) < 0) - throw new TeamRewardDebtException(2, "杩橀挶杩囧"); - // 杩橀挶 - TeamRewardDebt update = new TeamRewardDebt(); - update.setId(debt.getId()); - update.setLeftMoney(debt.getLeftMoney().subtract(money)); - update.setUpdateTime(new Date()); - teamRewardDebtMapper.updateByPrimaryKeySelective(update); - // 鍔犲叆杩橀挶璁板綍 - TeamRewardDebtRepayHistory record = new TeamRewardDebtRepayHistory(); - record.setCreateTime(new Date()); - record.setDebt(debt); - record.setMoney(money); - record.setUid(debt.getUid()); - teamRewardDebtRepayHistoryMapper.insertSelective(record); - //杩橀挶鏄惁杩樺畬 - if (update.getLeftMoney().compareTo(new BigDecimal(0)) <= 0) { - //宸茬粡杩樺畬閽� - userOrderWeiQuanRecordService.weiQuanMoneyReturn(debt.getUid(), debt.getTradeId(), debt.getSourceType()); - } - } - - @Transactional(rollbackFor = Exception.class) - @Override - public BigDecimal repayDebtByUid(Long uid, Date maxEstimatePayTime, BigDecimal money) throws TeamRewardDebtException { - // 杩橀挶 - long count = countNeedRepayDebt(uid, maxEstimatePayTime); - int page = (int) (count % 200 == 0 ? count / 200 : count / 200 + 1); - List<TeamRewardDebt> totalList = new ArrayList<>(); - for (int i = 0; i < page; i++) { - List<TeamRewardDebt> tempList = listNeedRepayDebt(uid, maxEstimatePayTime, i + 1, 200); - if (tempList != null && tempList.size() > 0) { - totalList.addAll(tempList); - } - } - - // 鍓╀綑璧勯噾 - BigDecimal leftMoney = new BigDecimal(money.toString()); - - for (TeamRewardDebt debt : totalList) { - if (leftMoney.compareTo(new BigDecimal(0)) <= 0)// 浣欓涓嶈冻鎵f - break; - BigDecimal repayMoney = null; - if (debt.getLeftMoney().compareTo(leftMoney) >= 0) - repayMoney = new BigDecimal(leftMoney.toString()); - else - repayMoney = debt.getLeftMoney(); - try { - repayDebt(debt.getId(), repayMoney); - leftMoney = leftMoney.subtract(repayMoney); - } catch (TeamRewardDebtException e) { - // 涓婄瑪杩樻鏈垚鍔燂紝缁х画涓嬩竴绗旇繕娆� - } - } - - return leftMoney;// 杩斿洖鍓╀綑鐨勮祫閲� - } - - @Override - public List<TeamRewardDebt> listNeedRepayDebt(Long uid, Date maxEstimatePayTime, int page, int count) { - return teamRewardDebtMapper.listByLeftMoneyAndUidAndMaxEstimatePayTime(new BigDecimal("0.01"), null, uid, maxEstimatePayTime, (page - 1) * count, count); - } - - @Override - public long countNeedRepayDebt(Long uid, Date maxEstimatePayTime) { - return teamRewardDebtMapper.countByLeftMoneyAndUidAndMaxEstimatePayTime(new BigDecimal("0.01"), null, uid, maxEstimatePayTime); - } - - @Override - public BigDecimal getTotalDebtMoney(Long uid, Date maxEstimatePayTime) { - BigDecimal money = teamRewardDebtMapper.sumLeftMoneyByUid(uid, maxEstimatePayTime); - if (money == null) - money = new BigDecimal(0); - return money; - } - - @Override - public TeamRewardDebt selectBySourceId(Long sourceId) { - return teamRewardDebtMapper.selectBySourceId(sourceId); - } - -} +package com.yeshi.fanli.service.impl.money; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import javax.annotation.Resource; + +import com.yeshi.fanli.entity.order.UserOrderWeiQuanRecord; +import com.yeshi.fanli.service.inter.order.UserOrderWeiQuanRecordService; +import com.yeshi.fanli.util.StringUtil; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.yeshi.fanli.dao.mybatis.money.TeamRewardDebtMapper; +import com.yeshi.fanli.dao.mybatis.money.TeamRewardDebtRepayHistoryMapper; +import com.yeshi.fanli.entity.money.TeamRewardDebt; +import com.yeshi.fanli.entity.money.TeamRewardDebtRepayHistory; +import com.yeshi.fanli.exception.money.TeamRewardDebtException; +import com.yeshi.fanli.service.inter.money.TeamRewardDebtService; + +@Service +public class TeamRewardDebtServiceImpl implements TeamRewardDebtService { + @Resource + private TeamRewardDebtMapper teamRewardDebtMapper; + + @Resource + private TeamRewardDebtRepayHistoryMapper teamRewardDebtRepayHistoryMapper; + + @Resource + private UserOrderWeiQuanRecordService userOrderWeiQuanRecordService; + + @Transactional(rollbackFor = Exception.class) + @Override + public void addDebt(TeamRewardDebt debt) throws TeamRewardDebtException { + if (debt == null || debt.getOriginMoney() == null || debt.getOriginMoney() == null || debt.getUid() == null || StringUtil.isNullOrEmpty(debt.getTradeId()) || debt.getSourceType() == null) { + throw new TeamRewardDebtException(1, "鏁版嵁涓嶅畬鏁�"); + } + if (debt.getCreateTime() == null) + debt.setCreateTime(new Date()); + debt.setLeftMoney(debt.getOriginMoney()); + teamRewardDebtMapper.insertSelective(debt); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public void repayDebt(Long debtId, BigDecimal money, String beizhu) throws TeamRewardDebtException { + TeamRewardDebt debt = teamRewardDebtMapper.selectByPrimaryKeyForUpdate(debtId); + if (debt == null) + throw new TeamRewardDebtException(1, "鍊哄姟ID涓嶅瓨鍦�"); + if (money == null || money.compareTo(new BigDecimal(0)) <= 0) + throw new TeamRewardDebtException(3, "杩橀挶蹇呴』澶т簬0"); + if (debt.getLeftMoney().compareTo(money) < 0) + throw new TeamRewardDebtException(2, "杩橀挶杩囧"); + // 杩橀挶 + TeamRewardDebt update = new TeamRewardDebt(); + update.setId(debt.getId()); + update.setLeftMoney(debt.getLeftMoney().subtract(money)); + update.setUpdateTime(new Date()); + teamRewardDebtMapper.updateByPrimaryKeySelective(update); + // 鍔犲叆杩橀挶璁板綍 + TeamRewardDebtRepayHistory record = new TeamRewardDebtRepayHistory(); + record.setCreateTime(new Date()); + record.setDebt(debt); + record.setMoney(money); + record.setUid(debt.getUid()); + record.setBeiZhu(beizhu); + teamRewardDebtRepayHistoryMapper.insertSelective(record); + //杩橀挶鏄惁杩樺畬 + if (update.getLeftMoney().compareTo(new BigDecimal(0)) <= 0) { + //宸茬粡杩樺畬閽� + userOrderWeiQuanRecordService.weiQuanMoneyReturn(debt.getUid(), debt.getTradeId(), debt.getSourceType()); + } + } + + @Transactional(rollbackFor = Exception.class) + @Override + public BigDecimal repayDebtByUid(Long uid, Date maxEstimatePayTime, BigDecimal money) throws TeamRewardDebtException { + // 杩橀挶 + long count = countNeedRepayDebt(uid, maxEstimatePayTime); + int page = (int) (count % 200 == 0 ? count / 200 : count / 200 + 1); + List<TeamRewardDebt> totalList = new ArrayList<>(); + for (int i = 0; i < page; i++) { + List<TeamRewardDebt> tempList = listNeedRepayDebt(uid, maxEstimatePayTime, i + 1, 200); + if (tempList != null && tempList.size() > 0) { + totalList.addAll(tempList); + } + } + + // 鍓╀綑璧勯噾 + BigDecimal leftMoney = new BigDecimal(money.toString()); + + for (TeamRewardDebt debt : totalList) { + if (leftMoney.compareTo(new BigDecimal(0)) <= 0)// 浣欓涓嶈冻鎵f + break; + BigDecimal repayMoney = null; + if (debt.getLeftMoney().compareTo(leftMoney) >= 0) + repayMoney = new BigDecimal(leftMoney.toString()); + else + repayMoney = debt.getLeftMoney(); + try { + repayDebt(debt.getId(), repayMoney,null); + leftMoney = leftMoney.subtract(repayMoney); + } catch (TeamRewardDebtException e) { + // 涓婄瑪杩樻鏈垚鍔燂紝缁х画涓嬩竴绗旇繕娆� + } + } + + return leftMoney;// 杩斿洖鍓╀綑鐨勮祫閲� + } + + @Override + public List<TeamRewardDebt> listNeedRepayDebt(Long uid, Date maxEstimatePayTime, int page, int count) { + return teamRewardDebtMapper.listByLeftMoneyAndUidAndMaxEstimatePayTime(new BigDecimal("0.01"), null, uid, maxEstimatePayTime, (page - 1) * count, count); + } + + @Override + public long countNeedRepayDebt(Long uid, Date maxEstimatePayTime) { + return teamRewardDebtMapper.countByLeftMoneyAndUidAndMaxEstimatePayTime(new BigDecimal("0.01"), null, uid, maxEstimatePayTime); + } + + @Override + public BigDecimal getTotalDebtMoney(Long uid, Date maxEstimatePayTime) { + BigDecimal money = teamRewardDebtMapper.sumLeftMoneyByUid(uid, maxEstimatePayTime); + if (money == null) + money = new BigDecimal(0); + return money; + } + + @Override + public TeamRewardDebt selectBySourceId(Long sourceId) { + return teamRewardDebtMapper.selectBySourceId(sourceId); + } + +} -- Gitblit v1.8.0