Merge remote-tracking branch 'origin/test' into test
# Conflicts: # cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionUserServiceImpl.java
This commit is contained in:
@@ -24,6 +24,7 @@ import com.czg.service.market.mapper.MkDistributionFlowMapper;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -47,26 +48,29 @@ public class MkDistributionFlowServiceImpl extends ServiceImpl<MkDistributionFlo
|
||||
List<MkDistributionFlowVO> list = mapper.pageInfo(shopId, startTime, endTime, status, key, id, null);
|
||||
Page<MkDistributionFlowVO> page = PageUtil.convert(new PageInfo<>(list));
|
||||
Map<String, Object> map = BeanUtil.beanToMap(page);
|
||||
map.put("successAmount", getOne(new QueryWrapper().eq(MkDistributionFlow::getShopId, shopId)
|
||||
.eq(MkDistributionFlow::getType, TableValueConstant.DistributionFlow.Status.SUCCESS.getCode())
|
||||
.select("sum(reward_amount)")));
|
||||
map.put("pendingAmount", getOne(new QueryWrapper().eq(MkDistributionFlow::getShopId, shopId)
|
||||
.eq(MkDistributionFlow::getType, TableValueConstant.DistributionFlow.Status.PENDING.getCode())
|
||||
.select("sum(reward_amount)")));
|
||||
map.put("successAmount", getOneAs(new QueryWrapper().eq(MkDistributionFlow::getShopId, shopId)
|
||||
.eq(MkDistributionFlow::getStatus, TableValueConstant.DistributionFlow.Status.SUCCESS.getCode())
|
||||
.select("sum(reward_amount)"), BigDecimal.class));
|
||||
map.put("pendingAmount", getOneAs(new QueryWrapper().eq(MkDistributionFlow::getShopId, shopId)
|
||||
.eq(MkDistributionFlow::getStatus, TableValueConstant.DistributionFlow.Status.PENDING.getCode())
|
||||
.select("sum(reward_amount)"), BigDecimal.class));
|
||||
map.put("balanceAmount", shopInfoService.getById(shopId).getAmount());
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> distributionFlow(long userId, String startTime, String endTime, Long shopId, String status) {
|
||||
ShopUser shopUserInfo = shopUserService.getShopUserInfo(shopId, userId);
|
||||
ShopUser shopUserInfo = null;
|
||||
if (shopId != null) {
|
||||
shopUserInfo = shopUserService.getShopUserInfo(shopId, userId);
|
||||
}
|
||||
PageHelper.startPage(PageUtil.buildPageHelp());
|
||||
List<MkDistributionFlowVO> list = mapper.pageInfo(shopId, StrUtil.isBlank(startTime) ? null : DateUtil.parseLocalDateTime(startTime),
|
||||
StrUtil.isBlank(endTime) ? null : DateUtil.parseLocalDateTime(endTime), status,null, shopUserInfo.getId(), null);
|
||||
StrUtil.isBlank(endTime) ? null : DateUtil.parseLocalDateTime(endTime), status,null, shopUserInfo == null ? null : shopUserInfo.getId(), null);
|
||||
Page<MkDistributionFlowVO> page = PageUtil.convert(new PageInfo<>(list));
|
||||
Map<String, Object> map = BeanUtil.beanToMap(page);
|
||||
map.put("totalAmount", mapper.totalAmount(shopId, StrUtil.isBlank(startTime) ? null : DateUtil.parseLocalDateTime(startTime),
|
||||
StrUtil.isBlank(endTime) ? null : DateUtil.parseLocalDateTime(endTime), status,null, shopUserInfo.getId(), null));
|
||||
StrUtil.isBlank(endTime) ? null : DateUtil.parseLocalDateTime(endTime), status,null, shopUserInfo == null ? null : shopUserInfo.getId(), null));
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,7 +410,6 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
.eq(MkDistributionConfig::getIsEnable, 1));
|
||||
AssertUtil.isNull(config, "店铺未配置分销");
|
||||
param.setStatus(0);
|
||||
//自主申请、付费开通、手动添加
|
||||
param.setId(param.getId());
|
||||
param.setUserId(shopUser.getUserId());
|
||||
param.setInviteCode(CzgRandomUtils.randomString(10));
|
||||
@@ -510,17 +509,21 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(Long userId, BigDecimal amount, Long shopId, Long sourceId) {
|
||||
ShopUser shopUserInfo = shopUserService.getShopUserInfo(shopId, userId);
|
||||
public void open(Long shopUserId, BigDecimal amount, Long shopId, Long sourceId) {
|
||||
ShopUser shopUserInfo = shopUserService.getById(shopUserId);
|
||||
Long mainShopId = shopInfoService.getMainIdByShopId(shopId);
|
||||
BigDecimal finalAmount = shopInfoService.updateAmount(shopId, amount);
|
||||
distributionAmountFlowService.save(new MkDistributionAmountFlow()
|
||||
.setType(TableValueConstant.DistributionAmountFlow.Type.OPEN.getCode())
|
||||
.setMainShopId(mainShopId).setShopId(shopId).setAmount(finalAmount).setChangeAmount(amount).setSourceId(sourceId)
|
||||
.setRemark("分销员购买"));
|
||||
addDistributionUser(new MkDistributionUser().setShopId(shopId)
|
||||
.setUserId(shopUserInfo.getUserId())
|
||||
.setId(shopUserInfo.getId()).setOpeningMethod("付费开通"));
|
||||
try {
|
||||
addDistributionUser(new MkDistributionUser().setShopId(shopId)
|
||||
.setUserId(shopUserInfo.getUserId())
|
||||
.setId(shopUserInfo.getId()).setOpeningMethod("付费开通"));
|
||||
}catch (Exception e) {
|
||||
log.error("分销员开通失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -531,7 +534,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
distributionAmountFlowService.save(new MkDistributionAmountFlow()
|
||||
.setType(TableValueConstant.DistributionAmountFlow.Type.SELF_RECHARGE.getCode())
|
||||
.setMainShopId(mainShopId).setShopId(shopId).setAmount(finalAmount).setChangeAmount(amount).setSourceId(paymentId)
|
||||
.setRemark("自助充值").setOpAccount(StpKit.USER.getAccount()));
|
||||
.setRemark("自助充值"));
|
||||
}
|
||||
|
||||
|
||||
@@ -555,10 +558,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
|
||||
// 上上级分销员
|
||||
if (currentShopUser.getDistributionUserId() != null) {
|
||||
MkDistributionUser parent = getOne(new QueryWrapper().eq(MkDistributionUser::getId, currentDistributionUser.getDistributionLevelId()));
|
||||
if (parent == null) {
|
||||
return;
|
||||
}
|
||||
MkDistributionUser parent = getOne(new QueryWrapper().eq(MkDistributionUser::getId, currentShopUser.getDistributionUserId()));
|
||||
try {
|
||||
deepReward(orderSourceShopUser, level, config, parent, amount, sourceId, type, orderNo, currentLevel + 1);
|
||||
} catch (Exception e) {
|
||||
@@ -587,56 +587,55 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
// }
|
||||
rewardAmount = amount.multiply(finalCommission.divide(BigDecimal.valueOf(100), RoundingMode.DOWN));
|
||||
|
||||
boolean flag = true;
|
||||
BigDecimal finalAmount = BigDecimal.ZERO;
|
||||
try {
|
||||
finalAmount = shopInfoService.updateAmount(currentDistributionUser.getShopId(), rewardAmount.negate());
|
||||
} catch (Exception e) {
|
||||
flag = false;
|
||||
}
|
||||
ShopUser shopUser = shopUserService.getById(currentDistributionUser.getId());
|
||||
// 延时发放时间
|
||||
LocalDateTime delayTime = config.getSettlementDay() == null || config.getSettlementDay() == 0 ? null : DateUtil.offsetDay(DateUtil.date(), config.getSettlementDay()).toLocalDateTime();
|
||||
|
||||
// 用户分账明细
|
||||
ShopUser shopUser = shopUserService.getById(currentDistributionUser.getId());
|
||||
MkDistributionFlow mkDistributionFlow = new MkDistributionFlow().setShopUserId(currentDistributionUser.getId())
|
||||
.setShopId(currentDistributionUser.getShopId()).setDistributionUserId(currentDistributionUser.getId())
|
||||
.setNickName(shopUser.getNickName()).setSourceShopUserId(orderSourceShopUser.getId()).setSourceNickName(orderSourceShopUser.getNickName())
|
||||
.setCommission(finalCommission).setParentCommission(parentLevel.getLevelOneCommission())
|
||||
.setCommission(finalCommission).setParentCommission(parentLevel != null ? parentLevel.getLevelOneCommission() : null)
|
||||
.setLevelId(currentDistributionUser.getDistributionLevelId()).setLevel(currentLevel == 1 ? 1 : 2).setOrderNo(orderNo)
|
||||
.setSourceId(sourceId).setAmount(amount).setType(type).setStatus(flag ? TableValueConstant.DistributionFlow.Status.SUCCESS.getCode() :
|
||||
TableValueConstant.DistributionFlow.Status.PENDING.getCode())
|
||||
.setSourceId(sourceId).setAmount(amount).setType(type)
|
||||
.setRewardAmount(rewardAmount).setBillNo(IdUtil.simpleUUID());
|
||||
distributionFlowService.save(mkDistributionFlow);
|
||||
|
||||
updateIncome(!flag ? rewardAmount : BigDecimal.ZERO,
|
||||
flag ? rewardAmount : BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
|
||||
|
||||
if (flag) {
|
||||
distributionAmountFlowService.save(new MkDistributionAmountFlow()
|
||||
.setType(TableValueConstant.DistributionAmountFlow.Type.SUB.getCode())
|
||||
.setShopId(config.getShopId()).setAmount(finalAmount).setChangeAmount(rewardAmount).setSourceId(mkDistributionFlow.getId())
|
||||
.setRemark("分账扣除"));
|
||||
if (delayTime == null) {
|
||||
mkDistributionFlow.setStatus(TableValueConstant.DistributionFlow.Status.SUCCESS.getCode());
|
||||
distributionFlowService.save(mkDistributionFlow);
|
||||
log.info("即时分销开始");
|
||||
try {
|
||||
updateShopInfoAmount(currentDistributionUser.getShopId(), rewardAmount, mkDistributionFlow.getId());
|
||||
updateIncome(BigDecimal.ZERO, rewardAmount, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
|
||||
} catch (Exception e) {
|
||||
mkDistributionFlow.setStatus(TableValueConstant.DistributionFlow.Status.PENDING.getCode());
|
||||
distributionFlowService.updateById(mkDistributionFlow);
|
||||
}
|
||||
}else {
|
||||
mkDistributionFlow.setStatus(TableValueConstant.DistributionFlow.Status.PENDING.getCode());
|
||||
distributionFlowService.save(mkDistributionFlow);
|
||||
log.info("延时分销开始");
|
||||
updateIncome(rewardAmount, BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void distribute(Long sourceId, String orderNo, BigDecimal amount, Long sourceUserId, Long shopId, String type, boolean isTask) {
|
||||
MkDistributionDeliver deliver = new MkDistributionDeliver().setSourceId(sourceId).setOrderNo(orderNo).setShopId(shopId).setType(type).setStatus("pending");
|
||||
public BigDecimal updateShopInfoAmount(Long shopId, BigDecimal changeAmount, Long sourceId) {
|
||||
BigDecimal finalAmount = shopInfoService.updateAmount(shopId, changeAmount.negate());
|
||||
distributionAmountFlowService.save(new MkDistributionAmountFlow()
|
||||
.setType(TableValueConstant.DistributionAmountFlow.Type.SUB.getCode())
|
||||
.setShopId(shopId).setAmount(finalAmount).setChangeAmount(changeAmount).setSourceId(sourceId)
|
||||
.setRemark("分账扣除"));
|
||||
return finalAmount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void distribute(Long sourceId, String orderNo, BigDecimal amount, Long sourceUserId, Long shopId, String type) {
|
||||
MkDistributionDeliver deliver = new MkDistributionDeliver().setSourceId(sourceId).setOrderNo(orderNo).setShopId(shopId).setType(type).setStatus("success");
|
||||
FunUtils.safeRunVoid(() -> {
|
||||
AssertUtil.isTrue(amount.compareTo(BigDecimal.ZERO) == 0, "分销金额不能为0");
|
||||
MkDistributionConfigVO config = mkDistributionConfigService.detail(shopId);
|
||||
AssertUtil.isTrue(config.getIsEnable() != 1, "分销未开启");
|
||||
|
||||
|
||||
if (!isTask) {
|
||||
if (config.getSettlementDay() != null && config.getSettlementDay() != 0) {
|
||||
deliver.setShouldDeliverTime(DateUtil.offsetDay(DateUtil.date(), config.getSettlementDay()).toLocalDateTime());
|
||||
log.info("延时发放, {}", config.getSettlementDay());
|
||||
return;
|
||||
} else {
|
||||
deliver.setStatus("success");
|
||||
}
|
||||
}
|
||||
|
||||
// 当前用户上级分销员
|
||||
ShopUser sourceShopUserInfo = shopUserService.getShopUserInfo(shopId, sourceUserId);
|
||||
if (sourceShopUserInfo.getDistributionUserId() == null) {
|
||||
@@ -647,15 +646,16 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
MkDistributionUser distributionUser = getById(sourceShopUserInfo.getDistributionUserId());
|
||||
deepReward(sourceShopUserInfo, null, config, distributionUser, amount, sourceId, type, orderNo, 1);
|
||||
});
|
||||
if (!isTask) {
|
||||
distributionDeliverService.save(deliver);
|
||||
}
|
||||
distributionDeliverService.save(deliver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId, Long mainShopId, Integer isOne) {
|
||||
shopUserService.updateOneOrTwoAmount(userId, mainShopId, receivedIncome == null ? pendingIncome : receivedIncome, isOne);
|
||||
// 用户收益信息
|
||||
shopUserService.updateOneOrTwoAmount(userId, mainShopId, receivedIncome, isOne);
|
||||
// 用户可提现余额
|
||||
userInfoService.updateDistributionAmount(userId, receivedIncome);
|
||||
//分销员余额
|
||||
boolean flag = mapper.updateIncome(pendingIncome, receivedIncome, withdrawIncome, id);
|
||||
if (!flag) {
|
||||
throw new CzgException("操作失败");
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
left join mk_distribution_user as d on d.id=a.distribution_user_id
|
||||
left join tb_shop_info as e on e.id=a.shop_id
|
||||
left join tb_shop_user as b on a.shop_user_id=b.id
|
||||
left join tb_shop_user as c on c.id=a.shop_user_id
|
||||
left join tb_shop_user as c on c.id=a.source_shop_user_id
|
||||
<where>
|
||||
<if test="shopId != null">
|
||||
and a.shop_id=#{shopId}
|
||||
|
||||
Reference in New Issue
Block a user