Merge remote-tracking branch 'origin/test' into test
# Conflicts: # cash-common/cash-common-service/src/main/java/com/czg/market/service/MkDistributionConfigService.java # cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionConfigServiceImpl.java
This commit is contained in:
@@ -60,8 +60,6 @@ public class MkDistributionConfigServiceImpl extends ServiceImpl<MkDistributionC
|
||||
private OrderPaymentService orderPaymentService;
|
||||
@DubboReference
|
||||
private ShopInfoService shopInfoService;
|
||||
@DubboReference
|
||||
private WxService wxService;
|
||||
|
||||
@Override
|
||||
@Cacheable(key = "#shopId")
|
||||
|
||||
@@ -1,13 +1,45 @@
|
||||
package com.czg.service.market.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.czg.account.entity.ShopInfo;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.account.service.ShopInfoService;
|
||||
import com.czg.account.service.ShopUserService;
|
||||
import com.czg.constant.TableValueConstant;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.market.dto.MkDistributionUserDTO;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.market.entity.MkDistributionAmountFlow;
|
||||
import com.czg.market.entity.MkDistributionConfig;
|
||||
import com.czg.market.entity.MkDistributionLevelConfig;
|
||||
import com.czg.market.entity.MkDistributionUser;
|
||||
import com.czg.market.service.MkDistributionAmountFlowService;
|
||||
import com.czg.market.service.MkDistributionConfigService;
|
||||
import com.czg.market.service.MkDistributionLevelConfigService;
|
||||
import com.czg.market.service.MkDistributionUserService;
|
||||
import com.czg.market.vo.MkDistributionConfigVO;
|
||||
import com.czg.order.dto.MkDistributionPayDTO;
|
||||
import com.czg.order.entity.OrderPayment;
|
||||
import com.czg.order.service.OrderPaymentService;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.market.mapper.MkDistributionUserMapper;
|
||||
import com.czg.system.service.WxService;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 分销员表 服务层实现。
|
||||
*
|
||||
@@ -15,25 +47,137 @@ import org.springframework.stereotype.Service;
|
||||
* @since 2025-10-27
|
||||
*/
|
||||
@Service
|
||||
public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUserMapper, MkDistributionUser> implements MkDistributionUserService{
|
||||
public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUserMapper, MkDistributionUser> implements MkDistributionUserService {
|
||||
|
||||
@Resource
|
||||
private MkDistributionConfigService mkDistributionConfigService;
|
||||
@Resource
|
||||
private MkDistributionLevelConfigService levelConfigService;
|
||||
@DubboReference
|
||||
private ShopUserService shopUserService;
|
||||
@Resource
|
||||
private MkDistributionAmountFlowService distributionAmountFlowService;
|
||||
@Resource
|
||||
private MkDistributionUserService distributionUserService;
|
||||
|
||||
@DubboReference
|
||||
private OrderPaymentService orderPaymentService;
|
||||
@DubboReference
|
||||
private ShopInfoService shopInfoService;
|
||||
@DubboReference
|
||||
private WxService wxService;
|
||||
|
||||
@Override
|
||||
public Page<MkDistributionUserDTO> getDistributionUser(MkDistributionUserDTO param) {
|
||||
return null;
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
queryWrapper.eq(MkDistributionUser::getShopId, param.getShopId());
|
||||
queryWrapper.eq(MkDistributionUser::getParentId, param.getParentId());
|
||||
queryWrapper.eq(MkDistributionUser::getShopUserId, param.getShopUserId());
|
||||
queryWrapper.ge(MkDistributionUser::getCreateTime, param.getStartTime());
|
||||
queryWrapper.le(MkDistributionUser::getCreateTime, param.getEndTime());
|
||||
queryWrapper.orderBy(MkDistributionUser::getCreateTime).desc();
|
||||
Page<MkDistributionUserDTO> page = pageAs(new Page<>(param.getPage(), param.getSize()), queryWrapper, MkDistributionUserDTO.class);
|
||||
Map<Long, ShopUser> shopUserMap = new HashMap<>();
|
||||
if (CollUtil.isNotEmpty(page.getRecords())) {
|
||||
if (param.getShopUserId() != null) {
|
||||
shopUserMap.put(param.getShopUserId(), shopUserService.getById(param.getShopUserId()));
|
||||
} else {
|
||||
Set<Long> shopUserIds = page.getRecords().stream()
|
||||
.map(MkDistributionUserDTO::getShopUserId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
shopUserMap = shopUserService.list(QueryWrapper.create().in(ShopUser::getId, shopUserIds))
|
||||
.stream().collect(Collectors.toMap(ShopUser::getId, shopUser -> shopUser));
|
||||
}
|
||||
for (MkDistributionUserDTO record : page.getRecords()) {
|
||||
ShopUser shopUser = shopUserMap.get(record.getShopUserId());
|
||||
if (shopUser == null || shopUser.getId() == null) {
|
||||
continue;
|
||||
}
|
||||
record.setShopUserName(shopUser.getNickName());
|
||||
record.setShopUserPhone(shopUser.getPhone());
|
||||
}
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDistributionUser(MkDistributionUser param) {
|
||||
|
||||
AssertUtil.isNull(param.getShopId(), "店铺ID不能为空");
|
||||
AssertUtil.isNull(param.getOpeningMethod(), "开通方式不能为空");
|
||||
MkDistributionConfig config = mkDistributionConfigService.getOne(
|
||||
QueryWrapper.create().eq(MkDistributionConfig::getShopId, param.getShopId())
|
||||
.eq(MkDistributionConfig::getIsEnable, 1));
|
||||
AssertUtil.isNull(config, "店铺未配置分销");
|
||||
if (config.getInviteCount() == 0) {
|
||||
param.setStatus(1);
|
||||
MkDistributionLevelConfig levelConfig = levelConfigService.getOne(QueryWrapper.create()
|
||||
.eq(MkDistributionLevelConfig::getShopId, param.getShopId())
|
||||
.eq(MkDistributionLevelConfig::getLevel, 1));
|
||||
AssertUtil.isNull(levelConfig, "店铺未配置分销等级");
|
||||
param.setDistributionLevelId(levelConfig.getId());
|
||||
param.setDistributionLevelName(levelConfig.getName());
|
||||
}
|
||||
save(param);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDistributionUserById(MkDistributionUserDTO param) {
|
||||
|
||||
AssertUtil.isNull(param.getId(), "分销员ID不能为空");
|
||||
MkDistributionUser distributionUser = BeanUtil.toBean(param, MkDistributionUser.class);
|
||||
updateById(distributionUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDistributionUser(Long id) {
|
||||
AssertUtil.isNull(id, "分销员ID不能为空");
|
||||
MkDistributionUser distributionUser = new MkDistributionUser();
|
||||
distributionUser.setId(id);
|
||||
distributionUser.setDel(true);
|
||||
updateById(distributionUser);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Object> pay(long userId, MkDistributionPayDTO payDTO) {
|
||||
MkDistributionConfigVO detail = mkDistributionConfigService.detail(payDTO.getShopId());
|
||||
AssertUtil.isTrue(detail.getIsEnable() != 1, "分销未开启");
|
||||
if (!TableValueConstant.DistributionConfig.OpenType.PAY.getCode().equals(detail.getOpenType())) {
|
||||
throw new CzgException("当前未开启购买分销配置");
|
||||
}
|
||||
|
||||
OrderPayment orderPayment = new OrderPayment().setShopId(payDTO.getShopId()).setSourceId(userId)
|
||||
.setPayType("distribution").setOrderNo(payDTO.getPlatformType() + IdUtil.getSnowflakeNextId()).setAmount(detail.getPayAmount());
|
||||
orderPaymentService.save(orderPayment);
|
||||
|
||||
return Map.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean cashPayOrder(long adminId, MkDistributionPayDTO payParam) {
|
||||
ShopInfo shopInfo = shopInfoService.getById(payParam.getShopId());
|
||||
AssertUtil.isNull(shopInfo, "店铺不存在");
|
||||
BigDecimal amount = shopInfoService.updateAmount(shopInfo.getId(), payParam.getAmount());
|
||||
Long mainShopId = shopInfoService.getMainIdByShopId(shopInfo.getId());
|
||||
|
||||
distributionAmountFlowService.save(new MkDistributionAmountFlow()
|
||||
.setType(payParam.getAmount().compareTo(BigDecimal.ZERO) < 0 ? TableValueConstant.DistributionAmountFlow.Type.MANUAL_SUB.getCode() :
|
||||
TableValueConstant.DistributionAmountFlow.Type.MANUAL_RECHARGE.getCode())
|
||||
.setMainShopId(mainShopId).setShopId(shopInfo.getId()).setAmount(amount).setChangeAmount(payParam.getAmount())
|
||||
.setRemark(payParam.getRemark()).setOpAccount(StpKit.USER.getAccount()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(Long userId, BigDecimal amount, Long shopId, Long sourceId) {
|
||||
ShopUser shopUserInfo = shopUserService.getShopUserInfo(shopId, userId);
|
||||
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("分销员购买").setOpAccount(StpKit.USER.getAccount()));
|
||||
distributionUserService.addDistributionUser(new MkDistributionUser().setParentId(null).setShopId(shopId)
|
||||
.setShopUserId(shopUserInfo.getId()).setOpeningMethod("付费开通"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
@Resource
|
||||
private MkConsumeCashbackService consumeCashbackService;
|
||||
@Resource
|
||||
private MkDistributionConfigService distributionConfigService;
|
||||
private MkDistributionUserService distributionUserService;
|
||||
// 延迟 5 秒
|
||||
private static final long DELAY = 5;
|
||||
//重试次数
|
||||
@@ -1158,7 +1158,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
|
||||
// 分销员开通
|
||||
} else if ("distribution".equals(payment.getPayType())) {
|
||||
distributionConfigService.open(payment.getSourceId(), payment.getAmount(), payment.getShopId(), payment.getId());
|
||||
distributionUserService.open(payment.getSourceId(), payment.getAmount(), payment.getShopId(), payment.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user