This commit is contained in:
parent
58f9622656
commit
4d6cac0e1f
|
|
@ -13,8 +13,8 @@ import org.springframework.web.bind.annotation.*;
|
|||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* 分销相关
|
||||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
@RestController
|
||||
|
|
@ -58,9 +58,9 @@ public class UDistributionController {
|
|||
/**
|
||||
* 分销员中心-配置信息
|
||||
*/
|
||||
@PostMapping("/centerConfig")
|
||||
public CzgResult<Map<String, Object>> centerConfig() {
|
||||
return CzgResult.success(distributionUserService.centerConfig(StpKit.USER.getLoginIdAsLong()));
|
||||
@GetMapping("/centerConfig")
|
||||
public CzgResult<Map<String, Object>> centerConfig(@RequestParam Long shopId) {
|
||||
return CzgResult.success(distributionUserService.centerConfig(StpKit.USER.getLoginIdAsLong(), shopId));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,10 +93,6 @@ public class MkDistributionConfig implements Serializable {
|
|||
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 主店id
|
||||
*/
|
||||
private Long mainShopId;
|
||||
private Long shopId;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,6 +111,10 @@ public class MkDistributionUser implements Serializable {
|
|||
/**
|
||||
* 是否删除 0 未删除 1 已删除
|
||||
*/
|
||||
private boolean isDel;
|
||||
private Integer isDel;
|
||||
/**
|
||||
* 邀请码
|
||||
*/
|
||||
private String inviteCode;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public interface MkDistributionUserService extends IService<MkDistributionUser>
|
|||
/**
|
||||
* 分销员中心-配置信息
|
||||
*/
|
||||
Map<String, Object> centerConfig(Long userId);
|
||||
Map<String, Object> centerConfig(Long userId, Long shopId);
|
||||
|
||||
/**
|
||||
* 获取分销员分页列表
|
||||
|
|
@ -84,11 +84,12 @@ public interface MkDistributionUserService extends IService<MkDistributionUser>
|
|||
|
||||
/**
|
||||
* 发放分销奖励
|
||||
*
|
||||
* @param sourceId 来源id
|
||||
* @param orderNo 订单编号
|
||||
* @param amount 金额
|
||||
* @param userId 用户id
|
||||
* @param shopId 店铺id
|
||||
* @param orderNo 订单编号
|
||||
* @param amount 金额
|
||||
* @param userId 用户id
|
||||
* @param shopId 店铺id
|
||||
*/
|
||||
void distribute(Long sourceId, String orderNo, BigDecimal amount, Long userId, Long shopId, String type);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
package com.czg.utils;
|
||||
|
||||
import cn.hutool.core.lang.id.NanoId;
|
||||
|
||||
/**
|
||||
* @author ww
|
||||
* @description
|
||||
*/
|
||||
public class CzgRandomUtils {
|
||||
|
||||
private static final char[] DEFAULT_ALPHABET =
|
||||
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
|
||||
|
||||
/**
|
||||
* 默认长度
|
||||
*/
|
||||
public static final int DEFAULT_SIZE = 12;
|
||||
|
||||
|
||||
/**
|
||||
* 随机生成指定长度的字符串
|
||||
*
|
||||
* @return 随机字符串
|
||||
*/
|
||||
public static String randomString() {
|
||||
return NanoId.randomNanoId(null, DEFAULT_ALPHABET, DEFAULT_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机生成指定长度的字符串
|
||||
*
|
||||
* @param length 字符串长度
|
||||
* @return 随机字符串
|
||||
*/
|
||||
public static String randomString(int length) {
|
||||
return NanoId.randomNanoId(null, DEFAULT_ALPHABET, length);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +1,21 @@
|
|||
package com.czg.service.market.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
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.MkDistributionConfigDTO;
|
||||
import com.czg.market.entity.MkDistributionAmountFlow;
|
||||
import com.czg.market.entity.MkDistributionUser;
|
||||
import com.czg.market.service.MkDistributionAmountFlowService;
|
||||
import com.czg.market.service.MkDistributionUserService;
|
||||
import com.czg.order.dto.MkDistributionPayDTO;
|
||||
import com.czg.market.entity.MkDistributionConfig;
|
||||
import com.czg.market.entity.MkDistributionLevelConfig;
|
||||
import com.czg.market.service.MkDistributionConfigService;
|
||||
import com.czg.market.service.MkDistributionLevelConfigService;
|
||||
import com.czg.market.vo.MkDistributionConfigVO;
|
||||
import com.czg.order.entity.OrderPayment;
|
||||
import com.czg.order.service.OrderPaymentService;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.system.service.WxService;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.service.market.mapper.MkDistributionConfigMapper;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.market.entity.MkDistributionConfig;
|
||||
import com.czg.market.service.MkDistributionConfigService;
|
||||
import com.czg.service.market.mapper.MkDistributionConfigMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 分销配置 服务层实现。
|
||||
*
|
||||
|
|
@ -49,20 +28,14 @@ public class MkDistributionConfigServiceImpl extends ServiceImpl<MkDistributionC
|
|||
|
||||
@Resource
|
||||
private MkDistributionLevelConfigService levelConfigService;
|
||||
@DubboReference
|
||||
private ShopInfoService shopInfoService;
|
||||
|
||||
@Override
|
||||
@Cacheable(key = "#shopId")
|
||||
public MkDistributionConfigVO detail(Long shopId) {
|
||||
Long mainIdByShopId = shopInfoService.getMainIdByShopId(shopId);
|
||||
MkDistributionConfig config = getOne(new QueryWrapper().eq(MkDistributionConfig::getShopId, shopId));
|
||||
if (config == null) {
|
||||
config = new MkDistributionConfig().setShopId(shopId).setMainShopId(mainIdByShopId);
|
||||
save(config);
|
||||
config = getOne(new QueryWrapper().eq(MkDistributionConfig::getShopId, shopId));
|
||||
return null;
|
||||
}
|
||||
|
||||
MkDistributionConfigVO configVO = BeanUtil.copyProperties(config, MkDistributionConfigVO.class);
|
||||
configVO.setLevelConfigList(levelConfigService.list(new QueryWrapper().eq(MkDistributionLevelConfig::getDistributionConfigId, config.getId())));
|
||||
return configVO;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ 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.czg.utils.CzgRandomUtils;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
|
@ -84,16 +85,16 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|||
QueryWrapper totalIncomeSumQueryWrapper = new QueryWrapper();
|
||||
totalIncomeSumQueryWrapper.select("sum(total_income) as totalIncome,sum(pending_income) as pendingIncome,sum(withdrawn_income) as cashOutAmount");
|
||||
totalIncomeSumQueryWrapper.eq(MkDistributionUser::getUserId, userId);
|
||||
totalIncomeSumQueryWrapper.eq(MkDistributionUser::isDel, 0);
|
||||
totalIncomeSumQueryWrapper.eq(MkDistributionUser::getIsDel, 0);
|
||||
DistributionCenterTopVO centerTopVO = getObjAs(totalIncomeSumQueryWrapper, DistributionCenterTopVO.class);
|
||||
// 封装顶部收益数据
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Map<String, Object> result = new HashMap<>(5);
|
||||
result.put("totalIncome", centerTopVO.getTotalIncome());
|
||||
result.put("pendingIncome", centerTopVO.getPendingIncome());
|
||||
result.put("cashOutAmount", centerTopVO.getUnCashOutAmount());
|
||||
|
||||
result.put("activates",activates(userId,1,5));
|
||||
result.put("unActivates",unActivates(userId,1,3));
|
||||
result.put("activates", activates(userId, 1, 5));
|
||||
result.put("unActivates", unActivates(userId, 1, 3));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -111,12 +112,12 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|||
for (DistributionCenterShopVO unActivate : unActivates) {
|
||||
|
||||
//'pay购买开通 auto自动开通 manual手动开通'
|
||||
if("pay".equals(unActivate.getOpenType())){
|
||||
if(unActivate.getShopUser() == 1){
|
||||
if ("pay".equals(unActivate.getOpenType())) {
|
||||
if (unActivate.getShopUser() == 1) {
|
||||
unActivate.setLabelContent("曾进入过店铺");
|
||||
}
|
||||
}else if("auto".equals(unActivate.getOpenType())){
|
||||
if(unActivate.getOrderCount() == 1){
|
||||
} else if ("auto".equals(unActivate.getOpenType())) {
|
||||
if (unActivate.getOrderCount() == 1) {
|
||||
unActivate.setLabelContent("在本店下单过");
|
||||
}
|
||||
}
|
||||
|
|
@ -130,7 +131,22 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|||
|
||||
|
||||
@Override
|
||||
public Map<String, Object> centerConfig(Long userId) {
|
||||
public Map<String, Object> centerConfig(Long userId, Long shopId) {
|
||||
Map<String, Object> result = new HashMap<>(3);
|
||||
ShopInfo shopInfo = shopInfoService.getById(shopId);
|
||||
AssertUtil.isNull(shopInfo, "店铺不存在");
|
||||
ShopUser shopUser = shopUserService.getShopUserInfo(userId, shopId);
|
||||
AssertUtil.isNull(shopUser, "店铺用户不存在");
|
||||
if (shopUser.getDistributionUserId() != null) {
|
||||
MkDistributionUser mkDistributionUser = this.getById(shopUser.getDistributionUserId());
|
||||
AssertUtil.isNull(mkDistributionUser, "上级分销员不存在");
|
||||
}
|
||||
MkDistributionUser mkDistributionUser = this.getOne(QueryWrapper.create()
|
||||
.eq(MkDistributionUser::getShopUserId, shopUser.getId()).eq(MkDistributionUser::getShopId, shopId));
|
||||
MkDistributionConfigVO mkDistributionConfigVO = mkDistributionConfigService.detail(shopId);
|
||||
if (mkDistributionUser != null) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -193,6 +209,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|||
AssertUtil.isNull(levelConfig, "店铺未配置分销等级");
|
||||
param.setDistributionLevelId(levelConfig.getId());
|
||||
param.setDistributionLevelName(levelConfig.getName());
|
||||
param.setInviteCode(CzgRandomUtils.randomString(10));
|
||||
save(param);
|
||||
}
|
||||
|
||||
|
|
@ -208,7 +225,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|||
AssertUtil.isNull(id, "分销员ID不能为空");
|
||||
MkDistributionUser distributionUser = new MkDistributionUser();
|
||||
distributionUser.setId(id);
|
||||
distributionUser.setDel(true);
|
||||
distributionUser.setIsDel(1);
|
||||
updateById(distributionUser);
|
||||
}
|
||||
|
||||
|
|
@ -281,7 +298,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|||
}
|
||||
try {
|
||||
deepReward(config, shopUserService.getById(parent.getShopUserId()), amount, sourceId, type, orderNo, ++currentLevel);
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
log.warn("分销奖励失败: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
@ -302,7 +319,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|||
BigDecimal rewardAmount;
|
||||
if (currentLevel == 1) {
|
||||
rewardAmount = amount.multiply(level.getLevelOneCommission().divide(BigDecimal.valueOf(100), RoundingMode.DOWN));
|
||||
}else {
|
||||
} else {
|
||||
rewardAmount = amount.multiply(level.getLevelTwoCommission().divide(BigDecimal.valueOf(100), RoundingMode.DOWN));
|
||||
}
|
||||
|
||||
|
|
@ -310,7 +327,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
|||
BigDecimal finalAmount = BigDecimal.ZERO;
|
||||
try {
|
||||
shopInfoService.updateAmount(distributionUser.getShopId(), rewardAmount.negate());
|
||||
}catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
flag = false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -763,7 +763,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
if (orderDetail.getIsGift() == 1 || orderDetail.getIsTemporary() == 1) {
|
||||
continue;
|
||||
}
|
||||
if (!isAllFoods || !couponFoodIds.contains(orderDetail.getProductId())) {
|
||||
if (!isAllFoods || (CollUtil.isNotEmpty(couponFoodIds) && !couponFoodIds.contains(orderDetail.getProductId()))) {
|
||||
continue;
|
||||
}
|
||||
BigDecimal num = orderDetail.getNum().subtract(orderDetail.getReturnNum());
|
||||
|
|
|
|||
Loading…
Reference in New Issue