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:
commit
a4a0f7b2d9
|
|
@ -1,13 +1,22 @@
|
||||||
package com.czg.task;
|
package com.czg.task;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
|
import com.czg.account.entity.ShopInfo;
|
||||||
import com.czg.account.entity.ShopUser;
|
import com.czg.account.entity.ShopUser;
|
||||||
|
import com.czg.account.service.ShopInfoService;
|
||||||
import com.czg.account.service.ShopUserService;
|
import com.czg.account.service.ShopUserService;
|
||||||
|
import com.czg.constant.TableValueConstant;
|
||||||
import com.czg.market.entity.MkDistributionDeliver;
|
import com.czg.market.entity.MkDistributionDeliver;
|
||||||
|
import com.czg.market.entity.MkDistributionFlow;
|
||||||
import com.czg.market.service.MkBirthdayGiftService;
|
import com.czg.market.service.MkBirthdayGiftService;
|
||||||
import com.czg.market.service.MkDistributionDeliverService;
|
import com.czg.market.service.MkDistributionDeliverService;
|
||||||
|
import com.czg.market.service.MkDistributionFlowService;
|
||||||
import com.czg.market.service.MkDistributionUserService;
|
import com.czg.market.service.MkDistributionUserService;
|
||||||
import com.czg.order.entity.OrderInfo;
|
import com.czg.order.entity.OrderInfo;
|
||||||
import com.czg.order.service.OrderInfoService;
|
import com.czg.order.service.OrderInfoService;
|
||||||
|
import com.czg.service.market.enums.OrderStatusEnums;
|
||||||
import com.czg.utils.FunUtils;
|
import com.czg.utils.FunUtils;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
|
@ -28,9 +37,13 @@ public class DistributionTask {
|
||||||
private MkDistributionDeliverService distributionDeliverService;
|
private MkDistributionDeliverService distributionDeliverService;
|
||||||
@Resource
|
@Resource
|
||||||
private MkDistributionUserService distributionUserService;
|
private MkDistributionUserService distributionUserService;
|
||||||
|
@Resource
|
||||||
|
private MkDistributionFlowService distributionFlowService;
|
||||||
|
|
||||||
@DubboReference
|
@DubboReference
|
||||||
private OrderInfoService orderInfoService;
|
private OrderInfoService orderInfoService;
|
||||||
|
@DubboReference
|
||||||
|
private ShopInfoService shopInfoService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生日有礼奖励发放
|
* 生日有礼奖励发放
|
||||||
|
|
@ -38,18 +51,24 @@ public class DistributionTask {
|
||||||
*/
|
*/
|
||||||
// @Scheduled(cron = "0 0 0 * * ?")
|
// @Scheduled(cron = "0 0 0 * * ?")
|
||||||
public void deliver() {
|
public void deliver() {
|
||||||
distributionDeliverService.list(new QueryWrapper().eq(MkDistributionDeliver::getStatus, "pending")).forEach(item -> {
|
distributionFlowService.list(new QueryWrapper().ge(MkDistributionFlow::getDeliverTime, DateUtil.date())
|
||||||
|
.eq(MkDistributionFlow::getStatus, TableValueConstant.DistributionFlow.Status.PENDING.getCode())).forEach(item -> {
|
||||||
FunUtils.safeRunVoid(() -> {
|
FunUtils.safeRunVoid(() -> {
|
||||||
log.info("开始处理延时分账, orderNo: {}, 类型: {}", item.getOrderNo(), item.getType());
|
log.info("开始处理延时分账, id: {}, orderNo: {}, 类型: {}", item.getId(), item.getOrderNo(), item.getType());
|
||||||
|
|
||||||
OrderInfo orderInfo = orderInfoService.getOne(new QueryWrapper().eq(OrderInfo::getOrderNo, item.getOrderNo()));
|
OrderInfo orderInfo = orderInfoService.getOne(new QueryWrapper().eq(OrderInfo::getOrderNo, item.getOrderNo()));
|
||||||
if (orderInfo == null) {
|
if (orderInfo == null) {
|
||||||
log.warn("订单不存在, 订单号: {}", item.getOrderNo());
|
log.warn("订单不存在, 订单号: {}", item.getOrderNo());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (CollUtil.newArrayList(OrderStatusEnums.REFUND.getCode(), OrderStatusEnums.REFUNDING.getCode(), OrderStatusEnums.PART_REFUND.getCode()).contains(orderInfo.getStatus())) {
|
||||||
distributionUserService.distribute(orderInfo.getId(), orderInfo.getOrderNo(), orderInfo.getPayAmount(), orderInfo.getUserId(), orderInfo.getShopId(), "order", true);
|
log.warn("订单已退款, 订单号: {}", item.getOrderNo());
|
||||||
item.setStatus("success");
|
item.setStatus(TableValueConstant.DistributionFlow.Status.REFUND.getCode());
|
||||||
distributionDeliverService.updateById(item);
|
}else {
|
||||||
|
item.setStatus(TableValueConstant.DistributionFlow.Status.SUCCESS.getCode());
|
||||||
|
distributionUserService.updateShopInfoAmount(orderInfo.getShopId(), item.getRewardAmount(), orderInfo.getId());
|
||||||
|
}
|
||||||
|
distributionFlowService.updateById(item);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,8 @@ public class NotifyController {
|
||||||
|
|
||||||
@GetMapping("testOpen")
|
@GetMapping("testOpen")
|
||||||
public JSONObject test1(String code) throws Exception {
|
public JSONObject test1(String code) throws Exception {
|
||||||
JSONObject jsonObject = wxService.transferBalance("or1l86yipGvwyfPhrKIAcQuSfAV8", "叶明飞", new BigDecimal("0.01"), "转账测试", "testTranymf0001");
|
distributionUserService.distribute(54659L, "WX1983728389726539776", BigDecimal.valueOf(1), 474L, 122L, "order");
|
||||||
return jsonObject;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,4 +112,5 @@ public class MkDistributionFlow implements Serializable {
|
||||||
|
|
||||||
private BigDecimal commission;
|
private BigDecimal commission;
|
||||||
private BigDecimal parentCommission;
|
private BigDecimal parentCommission;
|
||||||
|
private LocalDateTime deliverTime;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,17 +102,19 @@ public interface MkDistributionUserService extends IService<MkDistributionUser>
|
||||||
/**
|
/**
|
||||||
* 分销员开通
|
* 分销员开通
|
||||||
*
|
*
|
||||||
* @param userId 用户
|
* @param shopUserId 用户
|
||||||
* @param amount 金额
|
* @param amount 金额
|
||||||
* @param shopId 店铺id
|
* @param shopId 店铺id
|
||||||
*/
|
*/
|
||||||
void open(Long userId, BigDecimal amount, Long shopId, Long sourceId);
|
void open(Long shopUserId, BigDecimal amount, Long shopId, Long sourceId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分销商户运营余额充值回调
|
* 分销商户运营余额充值回调
|
||||||
*/
|
*/
|
||||||
void rechargeCallBack(Long shopId, BigDecimal amount, Long paymentId);
|
void rechargeCallBack(Long shopId, BigDecimal amount, Long paymentId);
|
||||||
|
|
||||||
|
BigDecimal updateShopInfoAmount(Long shopId, BigDecimal changeAmount, Long sourceId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发放分销奖励
|
* 发放分销奖励
|
||||||
*
|
*
|
||||||
|
|
@ -122,7 +124,7 @@ public interface MkDistributionUserService extends IService<MkDistributionUser>
|
||||||
* @param userId 用户id
|
* @param userId 用户id
|
||||||
* @param shopId 店铺id
|
* @param shopId 店铺id
|
||||||
*/
|
*/
|
||||||
void distribute(Long sourceId, String orderNo, BigDecimal amount, Long userId, Long shopId, String type, boolean isTask);
|
void distribute(Long sourceId, String orderNo, BigDecimal amount, Long userId, Long shopId, String type);
|
||||||
|
|
||||||
void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId, Long shopId, Integer isOne);
|
void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId, Long shopId, Integer isOne);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@ public interface TableValueConstant {
|
||||||
enum Status {
|
enum Status {
|
||||||
PENDING("pending", "待入账"),
|
PENDING("pending", "待入账"),
|
||||||
SUCCESS("success", "已入账"),
|
SUCCESS("success", "已入账"),
|
||||||
|
REFUND("REFUND", "已退款"),
|
||||||
FAIL("fail", "失败");
|
FAIL("fail", "失败");
|
||||||
private final String code;
|
private final String code;
|
||||||
private final String msg;
|
private final String msg;
|
||||||
|
|
|
||||||
|
|
@ -447,6 +447,7 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
||||||
return list(queryWrapper);
|
return list(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CacheEvict(key = "#id")
|
||||||
@Override
|
@Override
|
||||||
public BigDecimal updateAmount(Long id, BigDecimal amount) {
|
public BigDecimal updateAmount(Long id, BigDecimal amount) {
|
||||||
ShopInfo shopInfo = getShopInfo(id);
|
ShopInfo shopInfo = getShopInfo(id);
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import com.czg.service.market.mapper.MkDistributionFlowMapper;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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);
|
List<MkDistributionFlowVO> list = mapper.pageInfo(shopId, startTime, endTime, status, key, id, null);
|
||||||
Page<MkDistributionFlowVO> page = PageUtil.convert(new PageInfo<>(list));
|
Page<MkDistributionFlowVO> page = PageUtil.convert(new PageInfo<>(list));
|
||||||
Map<String, Object> map = BeanUtil.beanToMap(page);
|
Map<String, Object> map = BeanUtil.beanToMap(page);
|
||||||
map.put("successAmount", getOne(new QueryWrapper().eq(MkDistributionFlow::getShopId, shopId)
|
map.put("successAmount", getOneAs(new QueryWrapper().eq(MkDistributionFlow::getShopId, shopId)
|
||||||
.eq(MkDistributionFlow::getType, TableValueConstant.DistributionFlow.Status.SUCCESS.getCode())
|
.eq(MkDistributionFlow::getStatus, TableValueConstant.DistributionFlow.Status.SUCCESS.getCode())
|
||||||
.select("sum(reward_amount)")));
|
.select("sum(reward_amount)"), BigDecimal.class));
|
||||||
map.put("pendingAmount", getOne(new QueryWrapper().eq(MkDistributionFlow::getShopId, shopId)
|
map.put("pendingAmount", getOneAs(new QueryWrapper().eq(MkDistributionFlow::getShopId, shopId)
|
||||||
.eq(MkDistributionFlow::getType, TableValueConstant.DistributionFlow.Status.PENDING.getCode())
|
.eq(MkDistributionFlow::getStatus, TableValueConstant.DistributionFlow.Status.PENDING.getCode())
|
||||||
.select("sum(reward_amount)")));
|
.select("sum(reward_amount)"), BigDecimal.class));
|
||||||
map.put("balanceAmount", shopInfoService.getById(shopId).getAmount());
|
map.put("balanceAmount", shopInfoService.getById(shopId).getAmount());
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> distributionFlow(long userId, String startTime, String endTime, Long shopId, String status) {
|
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());
|
PageHelper.startPage(PageUtil.buildPageHelp());
|
||||||
List<MkDistributionFlowVO> list = mapper.pageInfo(shopId, StrUtil.isBlank(startTime) ? null : DateUtil.parseLocalDateTime(startTime),
|
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));
|
Page<MkDistributionFlowVO> page = PageUtil.convert(new PageInfo<>(list));
|
||||||
Map<String, Object> map = BeanUtil.beanToMap(page);
|
Map<String, Object> map = BeanUtil.beanToMap(page);
|
||||||
map.put("totalAmount", mapper.totalAmount(shopId, StrUtil.isBlank(startTime) ? null : DateUtil.parseLocalDateTime(startTime),
|
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;
|
return map;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -410,7 +410,6 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
.eq(MkDistributionConfig::getIsEnable, 1));
|
.eq(MkDistributionConfig::getIsEnable, 1));
|
||||||
AssertUtil.isNull(config, "店铺未配置分销");
|
AssertUtil.isNull(config, "店铺未配置分销");
|
||||||
param.setStatus(0);
|
param.setStatus(0);
|
||||||
//自主申请、付费开通、手动添加
|
|
||||||
param.setId(param.getId());
|
param.setId(param.getId());
|
||||||
param.setUserId(shopUser.getUserId());
|
param.setUserId(shopUser.getUserId());
|
||||||
param.setInviteCode(CzgRandomUtils.randomString(10));
|
param.setInviteCode(CzgRandomUtils.randomString(10));
|
||||||
|
|
@ -510,17 +509,21 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void open(Long userId, BigDecimal amount, Long shopId, Long sourceId) {
|
public void open(Long shopUserId, BigDecimal amount, Long shopId, Long sourceId) {
|
||||||
ShopUser shopUserInfo = shopUserService.getShopUserInfo(shopId, userId);
|
ShopUser shopUserInfo = shopUserService.getById(shopUserId);
|
||||||
Long mainShopId = shopInfoService.getMainIdByShopId(shopId);
|
Long mainShopId = shopInfoService.getMainIdByShopId(shopId);
|
||||||
BigDecimal finalAmount = shopInfoService.updateAmount(shopId, amount);
|
BigDecimal finalAmount = shopInfoService.updateAmount(shopId, amount);
|
||||||
distributionAmountFlowService.save(new MkDistributionAmountFlow()
|
distributionAmountFlowService.save(new MkDistributionAmountFlow()
|
||||||
.setType(TableValueConstant.DistributionAmountFlow.Type.OPEN.getCode())
|
.setType(TableValueConstant.DistributionAmountFlow.Type.OPEN.getCode())
|
||||||
.setMainShopId(mainShopId).setShopId(shopId).setAmount(finalAmount).setChangeAmount(amount).setSourceId(sourceId)
|
.setMainShopId(mainShopId).setShopId(shopId).setAmount(finalAmount).setChangeAmount(amount).setSourceId(sourceId)
|
||||||
.setRemark("分销员购买"));
|
.setRemark("分销员购买"));
|
||||||
addDistributionUser(new MkDistributionUser().setShopId(shopId)
|
try {
|
||||||
.setUserId(shopUserInfo.getUserId())
|
addDistributionUser(new MkDistributionUser().setShopId(shopId)
|
||||||
.setId(shopUserInfo.getId()).setOpeningMethod("付费开通"));
|
.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()
|
distributionAmountFlowService.save(new MkDistributionAmountFlow()
|
||||||
.setType(TableValueConstant.DistributionAmountFlow.Type.SELF_RECHARGE.getCode())
|
.setType(TableValueConstant.DistributionAmountFlow.Type.SELF_RECHARGE.getCode())
|
||||||
.setMainShopId(mainShopId).setShopId(shopId).setAmount(finalAmount).setChangeAmount(amount).setSourceId(paymentId)
|
.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) {
|
if (currentShopUser.getDistributionUserId() != null) {
|
||||||
MkDistributionUser parent = getOne(new QueryWrapper().eq(MkDistributionUser::getId, currentDistributionUser.getDistributionLevelId()));
|
MkDistributionUser parent = getOne(new QueryWrapper().eq(MkDistributionUser::getId, currentShopUser.getDistributionUserId()));
|
||||||
if (parent == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
deepReward(orderSourceShopUser, level, config, parent, amount, sourceId, type, orderNo, currentLevel + 1);
|
deepReward(orderSourceShopUser, level, config, parent, amount, sourceId, type, orderNo, currentLevel + 1);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -587,56 +587,55 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
// }
|
// }
|
||||||
rewardAmount = amount.multiply(finalCommission.divide(BigDecimal.valueOf(100), RoundingMode.DOWN));
|
rewardAmount = amount.multiply(finalCommission.divide(BigDecimal.valueOf(100), RoundingMode.DOWN));
|
||||||
|
|
||||||
boolean flag = true;
|
// 延时发放时间
|
||||||
BigDecimal finalAmount = BigDecimal.ZERO;
|
LocalDateTime delayTime = config.getSettlementDay() == null || config.getSettlementDay() == 0 ? null : DateUtil.offsetDay(DateUtil.date(), config.getSettlementDay()).toLocalDateTime();
|
||||||
try {
|
|
||||||
finalAmount = shopInfoService.updateAmount(currentDistributionUser.getShopId(), rewardAmount.negate());
|
|
||||||
} catch (Exception e) {
|
|
||||||
flag = false;
|
|
||||||
}
|
|
||||||
ShopUser shopUser = shopUserService.getById(currentDistributionUser.getId());
|
|
||||||
|
|
||||||
|
// 用户分账明细
|
||||||
|
ShopUser shopUser = shopUserService.getById(currentDistributionUser.getId());
|
||||||
MkDistributionFlow mkDistributionFlow = new MkDistributionFlow().setShopUserId(currentDistributionUser.getId())
|
MkDistributionFlow mkDistributionFlow = new MkDistributionFlow().setShopUserId(currentDistributionUser.getId())
|
||||||
.setShopId(currentDistributionUser.getShopId()).setDistributionUserId(currentDistributionUser.getId())
|
.setShopId(currentDistributionUser.getShopId()).setDistributionUserId(currentDistributionUser.getId())
|
||||||
.setNickName(shopUser.getNickName()).setSourceShopUserId(orderSourceShopUser.getId()).setSourceNickName(orderSourceShopUser.getNickName())
|
.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)
|
.setLevelId(currentDistributionUser.getDistributionLevelId()).setLevel(currentLevel == 1 ? 1 : 2).setOrderNo(orderNo)
|
||||||
.setSourceId(sourceId).setAmount(amount).setType(type).setStatus(flag ? TableValueConstant.DistributionFlow.Status.SUCCESS.getCode() :
|
.setSourceId(sourceId).setAmount(amount).setType(type)
|
||||||
TableValueConstant.DistributionFlow.Status.PENDING.getCode())
|
|
||||||
.setRewardAmount(rewardAmount).setBillNo(IdUtil.simpleUUID());
|
.setRewardAmount(rewardAmount).setBillNo(IdUtil.simpleUUID());
|
||||||
distributionFlowService.save(mkDistributionFlow);
|
|
||||||
|
|
||||||
updateIncome(!flag ? rewardAmount : BigDecimal.ZERO,
|
if (delayTime == null) {
|
||||||
flag ? rewardAmount : BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
|
mkDistributionFlow.setStatus(TableValueConstant.DistributionFlow.Status.SUCCESS.getCode());
|
||||||
|
distributionFlowService.save(mkDistributionFlow);
|
||||||
if (flag) {
|
log.info("即时分销开始");
|
||||||
distributionAmountFlowService.save(new MkDistributionAmountFlow()
|
try {
|
||||||
.setType(TableValueConstant.DistributionAmountFlow.Type.SUB.getCode())
|
updateShopInfoAmount(currentDistributionUser.getShopId(), rewardAmount, mkDistributionFlow.getId());
|
||||||
.setShopId(config.getShopId()).setAmount(finalAmount).setChangeAmount(rewardAmount).setSourceId(mkDistributionFlow.getId())
|
updateIncome(BigDecimal.ZERO, rewardAmount, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
|
||||||
.setRemark("分账扣除"));
|
} 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
|
@Override
|
||||||
public void distribute(Long sourceId, String orderNo, BigDecimal amount, Long sourceUserId, Long shopId, String type, boolean isTask) {
|
public BigDecimal updateShopInfoAmount(Long shopId, BigDecimal changeAmount, Long sourceId) {
|
||||||
MkDistributionDeliver deliver = new MkDistributionDeliver().setSourceId(sourceId).setOrderNo(orderNo).setShopId(shopId).setType(type).setStatus("pending");
|
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(() -> {
|
FunUtils.safeRunVoid(() -> {
|
||||||
AssertUtil.isTrue(amount.compareTo(BigDecimal.ZERO) == 0, "分销金额不能为0");
|
AssertUtil.isTrue(amount.compareTo(BigDecimal.ZERO) == 0, "分销金额不能为0");
|
||||||
MkDistributionConfigVO config = mkDistributionConfigService.detail(shopId);
|
MkDistributionConfigVO config = mkDistributionConfigService.detail(shopId);
|
||||||
AssertUtil.isTrue(config.getIsEnable() != 1, "分销未开启");
|
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);
|
ShopUser sourceShopUserInfo = shopUserService.getShopUserInfo(shopId, sourceUserId);
|
||||||
if (sourceShopUserInfo.getDistributionUserId() == null) {
|
if (sourceShopUserInfo.getDistributionUserId() == null) {
|
||||||
|
|
@ -647,15 +646,16 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
MkDistributionUser distributionUser = getById(sourceShopUserInfo.getDistributionUserId());
|
MkDistributionUser distributionUser = getById(sourceShopUserInfo.getDistributionUserId());
|
||||||
deepReward(sourceShopUserInfo, null, config, distributionUser, amount, sourceId, type, orderNo, 1);
|
deepReward(sourceShopUserInfo, null, config, distributionUser, amount, sourceId, type, orderNo, 1);
|
||||||
});
|
});
|
||||||
if (!isTask) {
|
distributionDeliverService.save(deliver);
|
||||||
distributionDeliverService.save(deliver);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId, Long mainShopId, Integer isOne) {
|
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);
|
userInfoService.updateDistributionAmount(userId, receivedIncome);
|
||||||
|
//分销员余额
|
||||||
boolean flag = mapper.updateIncome(pendingIncome, receivedIncome, withdrawIncome, id);
|
boolean flag = mapper.updateIncome(pendingIncome, receivedIncome, withdrawIncome, id);
|
||||||
if (!flag) {
|
if (!flag) {
|
||||||
throw new CzgException("操作失败");
|
throw new CzgException("操作失败");
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
left join mk_distribution_user as d on d.id=a.distribution_user_id
|
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_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 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>
|
<where>
|
||||||
<if test="shopId != null">
|
<if test="shopId != null">
|
||||||
and a.shop_id=#{shopId}
|
and a.shop_id=#{shopId}
|
||||||
|
|
|
||||||
|
|
@ -74,16 +74,15 @@ public class DistributionPayServiceImpl implements DistributionPayService {
|
||||||
orderPaymentService.save(orderPayment);
|
orderPaymentService.save(orderPayment);
|
||||||
|
|
||||||
InitInfo initInfo = new InitInfo().setConfig(detail);
|
InitInfo initInfo = new InitInfo().setConfig(detail);
|
||||||
if (!isRecharge) {
|
if (isRecharge) {
|
||||||
|
String openId = wxService.getOpenId(payParam.getCode());
|
||||||
|
initInfo.setOpenId(openId);
|
||||||
|
initInfo.setPayment(orderPayment);
|
||||||
|
} else {
|
||||||
UserInfo userInfo = userInfoService.getById(userId);
|
UserInfo userInfo = userInfoService.getById(userId);
|
||||||
initInfo.setPayment(orderPayment).setShopUser(shopUserInfo)
|
initInfo.setPayment(orderPayment).setShopUser(shopUserInfo)
|
||||||
.setOpenId("aliPay".equals(payParam.getPayType()) ? userInfo.getAlipayOpenId() : userInfo.getWechatOpenId());
|
.setOpenId("aliPay".equals(payParam.getPayType()) ? userInfo.getAlipayOpenId() : userInfo.getWechatOpenId());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StrUtil.isNotBlank(payParam.getCode())) {
|
|
||||||
String openId = wxService.getOpenId(payParam.getCode());
|
|
||||||
initInfo.setOpenId(openId);
|
|
||||||
}
|
|
||||||
return initInfo;
|
return initInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1066,7 +1066,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||||
// 分销员升级等级
|
// 分销员升级等级
|
||||||
distributionUserService.costUpgradeLevelBefore(orderInfo.getUserId(), orderInfo.getShopId());
|
distributionUserService.costUpgradeLevelBefore(orderInfo.getUserId(), orderInfo.getShopId());
|
||||||
// 分销奖励
|
// 分销奖励
|
||||||
distributionUserService.distribute(orderInfo.getId(), payment.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), orderInfo.getShopId(), "order",false);
|
distributionUserService.distribute(orderInfo.getId(), payment.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), orderInfo.getShopId(), "order");
|
||||||
} else if ("memberIn".equals(payment.getPayType()) || "free".equals(payment.getPayType())) {
|
} else if ("memberIn".equals(payment.getPayType()) || "free".equals(payment.getPayType())) {
|
||||||
boolean isFree = "free".equals(payment.getPayType());
|
boolean isFree = "free".equals(payment.getPayType());
|
||||||
ShopUser shopUser = shopUserService.getById(payment.getSourceId());
|
ShopUser shopUser = shopUserService.getById(payment.getSourceId());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue