分账
This commit is contained in:
@@ -21,6 +21,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分销定时任务
|
||||
@@ -42,6 +43,8 @@ public class DistributionTask {
|
||||
@DubboReference
|
||||
private ShopUserService shopUserService;
|
||||
|
||||
List<String> list = List.of(OrderStatusEnums.REFUND.getCode(), OrderStatusEnums.PART_REFUND.getCode());
|
||||
|
||||
/**
|
||||
* 分销流水入账
|
||||
* AAMarketTasks 统一调用位置
|
||||
@@ -55,6 +58,10 @@ public class DistributionTask {
|
||||
// 4. 流水增加应该入账的时间(订单产生时带入)
|
||||
// 5. 定时任务 应该是一天执行一次。查询待入账状态和应入账时间小于当前时间的记录,循环处理:并且判断商户余额是否足够,余额不足忽略处理;余额足够变为已入账并扣除商户余额。
|
||||
// 6. 订单产生退款时,去流水表查询该订单的流水记录,如果未入账改为已入账,并插入一条退款扣钱的流水。
|
||||
|
||||
// shopInfo 查余额>0
|
||||
// 循环 shopId 查询 如果金额不足 终止
|
||||
//
|
||||
LocalDateTime localDateTime = DateUtil.date().toLocalDateTime();
|
||||
distributionFlowService.list(new QueryWrapper()
|
||||
.eq(MkDistributionFlow::getStatus, TableValueConstant.DistributionFlow.Status.PENDING.getCode()).le(MkDistributionFlow::getDeliverTime, localDateTime)).forEach(item -> {
|
||||
@@ -63,10 +70,12 @@ public class DistributionTask {
|
||||
|
||||
OrderInfo orderInfo = orderInfoService.getOne(new QueryWrapper().eq(OrderInfo::getOrderNo, item.getOrderNo()));
|
||||
if (orderInfo == null) {
|
||||
item.setStatus(TableValueConstant.DistributionFlow.Status.FAIL.getCode());
|
||||
distributionFlowService.updateById(item);
|
||||
log.warn("订单不存在, 订单号: {}", item.getOrderNo());
|
||||
return;
|
||||
}
|
||||
if (CollUtil.newArrayList(OrderStatusEnums.REFUND.getCode(), OrderStatusEnums.REFUNDING.getCode(), OrderStatusEnums.PART_REFUND.getCode()).contains(orderInfo.getStatus())) {
|
||||
if (list.contains(orderInfo.getStatus())) {
|
||||
log.warn("订单已退款, 订单号: {}", item.getOrderNo());
|
||||
distributionUserService.refund(orderInfo.getId(), orderInfo.getOrderNo());
|
||||
} else {
|
||||
|
||||
@@ -102,7 +102,7 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
||||
if (shopInfo.getExpireTime() != null && (DateUtil.date().toLocalDateTime().isAfter(shopInfo.getExpireTime()))) {
|
||||
throw new CzgException("店铺已过期,请联系商家");
|
||||
}
|
||||
if (SystemConstants.OneZero.ZERO == shopInfo.getOnSale() || shopInfo.getStatus() !=SystemConstants.OneZero.ONE) {
|
||||
if (SystemConstants.OneZero.ZERO == shopInfo.getOnSale() || shopInfo.getStatus() != SystemConstants.OneZero.ONE) {
|
||||
throw new CzgException("店铺已停业,请联系商家");
|
||||
}
|
||||
|
||||
@@ -460,8 +460,8 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
||||
@Override
|
||||
public BigDecimal updateAmount(Long id, BigDecimal amount) {
|
||||
ShopInfo shopInfo = getShopInfo(id);
|
||||
if (shopInfo.getAmount() == null) {
|
||||
shopInfo.setAmount(BigDecimal.ZERO);
|
||||
if (shopInfo.getAmount() == null || shopInfo.getAmount().compareTo(BigDecimal.ZERO) <= 0) {
|
||||
throw new CzgException("更新失败");
|
||||
}
|
||||
boolean flag = mapper.updateAmount(id, amount);
|
||||
if (!flag) {
|
||||
|
||||
@@ -674,12 +674,19 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void refund(Long orderId, String orderNo) {
|
||||
long count = distributionFlowService.count(new QueryWrapper().eq(MkDistributionFlow::getOrderNo, orderNo).eq(MkDistributionFlow::getStatus, TableValueConstant.DistributionFlow.Status.PENDING.getCode()));
|
||||
if (count >= 1) {
|
||||
boolean exists = distributionFlowService.exists(new QueryWrapper()
|
||||
.eq(MkDistributionFlow::getOrderNo, orderNo)
|
||||
.eq(MkDistributionFlow::getStatus, TableValueConstant.DistributionFlow.Status.REFUND.getCode()));
|
||||
if (exists) {
|
||||
log.warn("此分销已经退款");
|
||||
return;
|
||||
}
|
||||
distributionFlowService.list(new QueryWrapper().eq(MkDistributionFlow::getOrderNo, orderNo).ne(MkDistributionFlow::getStatus, TableValueConstant.DistributionFlow.Status.REFUND.getCode())).forEach(item -> {
|
||||
|
||||
List<MkDistributionFlow> list = distributionFlowService.list(new QueryWrapper()
|
||||
.eq(MkDistributionFlow::getOrderNo, orderNo)
|
||||
.ne(MkDistributionFlow::getStatus, TableValueConstant.DistributionFlow.Status.REFUND.getCode()));
|
||||
|
||||
list.forEach(item -> {
|
||||
MkDistributionFlow refundFlow = BeanUtil.copyProperties(item, MkDistributionFlow.class);
|
||||
refundFlow.setStatus(TableValueConstant.DistributionFlow.Status.REFUND.getCode());
|
||||
refundFlow.setSourceId(item.getId());
|
||||
@@ -688,7 +695,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
refundFlow.setUpdateTime(DateUtil.date().toLocalDateTime());
|
||||
if (TableValueConstant.DistributionFlow.Status.PENDING.getCode().equals(item.getStatus())) {
|
||||
item.setStatus(TableValueConstant.DistributionFlow.Status.SUCCESS.getCode());
|
||||
updateIncome(item.getRewardAmount().negate(), BigDecimal.ZERO, BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopUserId(), item.getShopId(), item.getLevel());
|
||||
// updateIncome(item.getRewardAmount().negate(), BigDecimal.ZERO, BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopUserId(), item.getShopId(), item.getLevel());
|
||||
distributionFlowService.updateById(item);
|
||||
} else {
|
||||
// 执行扣款
|
||||
@@ -737,14 +744,6 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
}
|
||||
}
|
||||
|
||||
static void main() {
|
||||
BigDecimal amount = new BigDecimal("0.18");
|
||||
BigDecimal fee = amount.multiply(BigDecimal.valueOf(0.08)).setScale(2, RoundingMode.UP);
|
||||
BigDecimal finalAmount = amount.subtract(fee);
|
||||
System.out.println(finalAmount);
|
||||
System.out.println(fee);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO) {
|
||||
UserInfo userInfo = userInfoService.getById(userId);
|
||||
|
||||
Reference in New Issue
Block a user