Merge branch 'dev' into test

# Conflicts:
#	cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionUserServiceImpl.java
This commit is contained in:
2025-11-06 18:23:50 +08:00
15 changed files with 100 additions and 62 deletions

View File

@@ -48,7 +48,8 @@ public class DistributionUserController {
@RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "1") Integer page,
@RequestParam(required = false, defaultValue = "10") Integer size) { @RequestParam(required = false, defaultValue = "10") Integer size) {
AssertUtil.isNull(id, "邀请人ID"); AssertUtil.isNull(id, "邀请人ID");
return CzgResult.success(distributionUserService.getInviteUser(id, shopUserId, distributionLevelId, page, size)); Long shopId = StpKit.USER.getShopId();
return CzgResult.success(distributionUserService.getInviteUser(id,shopId, shopUserId, distributionLevelId, page, size));
} }
/** /**
@@ -99,7 +100,8 @@ public class DistributionUserController {
@SaAdminCheckPermission(value = "distribution:user:delete", name = "分销员删除") @SaAdminCheckPermission(value = "distribution:user:delete", name = "分销员删除")
public CzgResult<String> deleteDistributionUser(@RequestParam Long id) { public CzgResult<String> deleteDistributionUser(@RequestParam Long id) {
AssertUtil.isNull(id, "{}不能为空", "id"); AssertUtil.isNull(id, "{}不能为空", "id");
distributionUserService.deleteDistributionUser(id); Long shopId = StpKit.USER.getShopId();
distributionUserService.deleteDistributionUser(id,shopId);
return CzgResult.success(); return CzgResult.success();
} }

View File

@@ -119,10 +119,11 @@ public class UDistributionController {
@GetMapping("/inviteUser") @GetMapping("/inviteUser")
public CzgResult<Page<InviteUserVO>> getInviteUser( public CzgResult<Page<InviteUserVO>> getInviteUser(
@RequestParam Long id, @RequestParam Long id,
@RequestParam Long shopId,
@RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "1") Integer page,
@RequestParam(required = false, defaultValue = "10") Integer size) { @RequestParam(required = false, defaultValue = "10") Integer size) {
AssertUtil.isNull(id, "邀请人ID"); AssertUtil.isNull(id, "邀请人ID");
return CzgResult.success(distributionUserService.getInviteUser(id, null, null, page, size)); return CzgResult.success(distributionUserService.getInviteUser(id, shopId, null, null, page, size));
} }
/** /**

View File

@@ -34,6 +34,17 @@ public class CzgControllerAdvice {
@ExceptionHandler(value = Exception.class) @ExceptionHandler(value = Exception.class)
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
public CzgResult<Object> errorHandler(Exception ex) { public CzgResult<Object> errorHandler(Exception ex) {
Throwable rootCause = ex;
while (rootCause.getCause() != null) {
rootCause = rootCause.getCause();
if (rootCause instanceof CzgException) {
break;
}
}
// 处理自定义异常
if (rootCause instanceof CzgException czgException) {
return CzgResult.failure(czgException.getCode(), czgException.getMessage());
}
setErrorLog(ex); setErrorLog(ex);
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), ex.getMessage()); return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), ex.getMessage());
} }
@@ -143,7 +154,7 @@ public class CzgControllerAdvice {
} }
private void setErrorLog(Exception ex) { private void setErrorLog(Exception ex) {
log.error("错误",ex);
log.error(ex.getMessage()); log.error(ex.getMessage());
log.error("错误",ex);
} }
} }

View File

@@ -29,7 +29,7 @@ public interface ShopUserService extends IService<ShopUser> {
/** /**
* 获取邀请用户列表 * 获取邀请用户列表
*/ */
Page<InviteUserVO> getInviteUser(Long getDistributionUserId, Long shopUserId, Long distributionLevelId, Integer page, Integer size); Page<InviteUserVO> getInviteUser(Long getDistributionUserId, Long shopId, Long shopUserId, Long distributionLevelId, Integer page, Integer size);
boolean updateInfo(ShopUser shopUser); boolean updateInfo(ShopUser shopUser);

View File

@@ -40,6 +40,7 @@ public class MkDistributionUser implements Serializable {
/** /**
* 店铺id * 店铺id
*/ */
@Id
private Long shopId; private Long shopId;
private Long userId; private Long userId;

View File

@@ -67,7 +67,7 @@ public interface MkDistributionUserService extends IService<MkDistributionUser>
/** /**
* 获取分销员邀请人分页列表 * 获取分销员邀请人分页列表
*/ */
Page<InviteUserVO> getInviteUser(Long id, Long shopUserId, Long distributionLevelId, Integer page, Integer size); Page<InviteUserVO> getInviteUser(Long id, Long shopId, Long shopUserId, Long distributionLevelId, Integer page, Integer size);
/** /**
* 分销员:按消费金额升级等级 * 分销员:按消费金额升级等级
@@ -97,7 +97,7 @@ public interface MkDistributionUserService extends IService<MkDistributionUser>
* 删除分销员 * 删除分销员
* 逻辑删除分销员 * 逻辑删除分销员
*/ */
void deleteDistributionUser(Long id); void deleteDistributionUser(Long id, Long shopId);
@@ -152,4 +152,6 @@ public interface MkDistributionUserService extends IService<MkDistributionUser>
* CANCELLED 已撤销 * CANCELLED 已撤销
*/ */
void withdrawNotify(String outBillNo, String state, String failReason); void withdrawNotify(String outBillNo, String state, String failReason);
MkDistributionUser getMkDistributionUserByIdAndShopId(Long shopUserId, Long shopId);
} }

View File

@@ -70,7 +70,7 @@ public interface ShopUserMapper extends BaseMapper<ShopUser> {
* @param distributionUserId 分销员ID * @param distributionUserId 分销员ID
* @return 分页结果 * @return 分页结果
*/ */
List<InviteUserVO> getInviteUser(Long distributionUserId, Long shopUserId, Long distributionLevelId); List<InviteUserVO> getInviteUser(Long distributionUserId, Long shopId, Long shopUserId, Long distributionLevelId);
void updateOneOrTwoAmount(Long shopUserId, Long shopId, BigDecimal amount, Integer isOne); void updateOneOrTwoAmount(Long shopUserId, Long shopId, BigDecimal amount, Integer isOne);

View File

@@ -23,6 +23,7 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.processor.util.StrUtil;
import com.mybatisflex.spring.service.impl.ServiceImpl; import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
@@ -84,6 +85,9 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
shopUser.setSourceShopId(shopId); shopUser.setSourceShopId(shopId);
shopUser.setUserId(userId); shopUser.setUserId(userId);
shopUser.setId(null); shopUser.setId(null);
if (StrUtil.isBlank(shopUser.getBirthDay())) {
shopUser.setBirthDay(null);
}
save(shopUser); save(shopUser);
} }
if (shopUser.getMemberLevelId() != null) { if (shopUser.getMemberLevelId() != null) {
@@ -99,9 +103,9 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
} }
@Override @Override
public Page<InviteUserVO> getInviteUser(Long distributionUserId, Long shopUserId, Long distributionLevelId, Integer page, Integer size) { public Page<InviteUserVO> getInviteUser(Long distributionUserId, Long shopId, Long shopUserId, Long distributionLevelId, Integer page, Integer size) {
PageHelper.startPage(page, size); PageHelper.startPage(page, size);
List<InviteUserVO> inviteUser = mapper.getInviteUser(distributionUserId, shopUserId, distributionLevelId); List<InviteUserVO> inviteUser = mapper.getInviteUser(distributionUserId, shopId, shopUserId, distributionLevelId);
return PageUtil.convert(new PageInfo<>(inviteUser)); return PageUtil.convert(new PageInfo<>(inviteUser));
} }

View File

@@ -292,11 +292,11 @@
dist.distribution_level_name AS levelName, dist.distribution_level_name AS levelName,
u.distribution_shops AS distributionShops u.distribution_shops AS distributionShops
FROM tb_shop_user_invite invite FROM tb_shop_user_invite invite
left join tb_shop_user u on invite.shop_user_id = u.id left join tb_shop_user u on invite.shop_user_id = u.id
left join mk_distribution_user dist on u.id = dist.id left join mk_distribution_user dist on u.id = dist.id and dist.shop_id = #{shopId}
WHERE u.`distribution_user_id` = #{distributionUserId} WHERE invite.`distribution_user_id` = #{distributionUserId} and invite.shop_id = #{shopId}
<if test="distributionLevelId != null">and dist.distribution_level_id = #{distributionLevelId}</if> <if test="distributionLevelId != null">and dist.distribution_level_id = #{distributionLevelId}</if>
<if test="shopUserId != null">and u.id = #{shopUserId}</if> <if test="shopUserId != null">and invite.shop_user_id = #{shopUserId}</if>
ORDER BY u.`invite_time` DESC ORDER BY invite.`invite_time` DESC
</select> </select>
</mapper> </mapper>

View File

@@ -24,7 +24,7 @@ public interface MkDistributionUserMapper extends BaseMapper<MkDistributionUser>
*/ */
List<DistributionCenterShopVO> selectUnDistributionShops(Long userId); List<DistributionCenterShopVO> selectUnDistributionShops(Long userId);
boolean updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id); boolean updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long shopId);
/** /**
* 统计消费金额 * 统计消费金额

View File

@@ -40,6 +40,7 @@ public class MkDistributionAmountFlowServiceImpl extends ServiceImpl<MkDistribut
.eq(MkDistributionAmountFlow::getShopId, shopId) .eq(MkDistributionAmountFlow::getShopId, shopId)
.le(MkDistributionAmountFlow::getCreateTime, endTime) .le(MkDistributionAmountFlow::getCreateTime, endTime)
.ge(MkDistributionAmountFlow::getCreateTime, startTime) .ge(MkDistributionAmountFlow::getCreateTime, startTime)
.ne(MkDistributionAmountFlow::getType, TableValueConstant.DistributionAmountFlow.Type.OPEN.getCode())
.select(OrderInfo::getOrderNo); .select(OrderInfo::getOrderNo);
if (StrUtil.isNotBlank(type)) { if (StrUtil.isNotBlank(type)) {
String[] split = type.split(","); String[] split = type.split(",");

View File

@@ -155,14 +155,13 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
result.put("cashOutAmount", userInfo.getDistributionAmount() == null ? 0.0 : userInfo.getDistributionAmount()); result.put("cashOutAmount", userInfo.getDistributionAmount() == null ? 0.0 : userInfo.getDistributionAmount());
ShopUserInvite shopUserInvite = shopUserInviteService.getOneByShopIdAndShopUserId(shopId, shopUser.getId()); ShopUserInvite shopUserInvite = shopUserInviteService.getOneByShopIdAndShopUserId(shopId, shopUser.getId());
if (shopUserInvite != null && shopUserInvite.getDistributionUserId() != null) { if (shopUserInvite != null && shopUserInvite.getDistributionUserId() != null) {
MkDistributionUser mkDistributionUser = this.getById(shopUserInvite.getDistributionUserId()); MkDistributionUser mkDistributionUser = getMkDistributionUserByIdAndShopId(shopUserInvite.getDistributionUserId(), shopId);
AssertUtil.isNull(mkDistributionUser, "上级分销员不存在"); AssertUtil.isNull(mkDistributionUser, "上级分销员不存在");
ShopUser shopUserParent = shopUserService.getById(mkDistributionUser.getId()); ShopUser shopUserParent = shopUserService.getById(mkDistributionUser.getId());
result.put("parentName", shopUserParent.getNickName()); result.put("parentName", shopUserParent.getNickName());
result.put("parentPhone", shopUserParent.getPhone()); result.put("parentPhone", shopUserParent.getPhone());
} }
MkDistributionUser mkDistributionUser = this.getOne(QueryWrapper.create() MkDistributionUser mkDistributionUser = getMkDistributionUserByIdAndShopId(shopUser.getId(), shopId);
.eq(MkDistributionUser::getId, shopUser.getId()).eq(MkDistributionUser::getShopId, shopId));
MkDistributionConfigVO mkDistributionConfigVO = mkDistributionConfigService.detail(shopId); MkDistributionConfigVO mkDistributionConfigVO = mkDistributionConfigService.detail(shopId);
if (mkDistributionUser != null) { if (mkDistributionUser != null) {
Map<String, Object> distributionUser = new HashMap<>(); Map<String, Object> distributionUser = new HashMap<>();
@@ -212,8 +211,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
if (!"auto".equals(mkDistributionConfigVO.getOpenType())) { if (!"auto".equals(mkDistributionConfigVO.getOpenType())) {
throw new CzgException("该店铺不可自行成为分销员"); throw new CzgException("该店铺不可自行成为分销员");
} }
MkDistributionUser mkDistributionUser = this.getOne(QueryWrapper.create() MkDistributionUser mkDistributionUser = getMkDistributionUserByIdAndShopId(shopUser.getId(), shopId);
.eq(MkDistributionUser::getId, shopUser.getId()).eq(MkDistributionUser::getShopId, shopId));
if (mkDistributionUser == null) { if (mkDistributionUser == null) {
mkDistributionUser = new MkDistributionUser(); mkDistributionUser = new MkDistributionUser();
mkDistributionUser.setId(shopUser.getId()); mkDistributionUser.setId(shopUser.getId());
@@ -286,7 +284,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
if ("自主申请".equals(parent.getOpeningMethod()) && parent.getStatus() == 0 && mkDistributionConfig != null) { if ("自主申请".equals(parent.getOpeningMethod()) && parent.getStatus() == 0 && mkDistributionConfig != null) {
if (newDistributionUser.getInviteCount() >= mkDistributionConfig.getInviteCount()) { if (newDistributionUser.getInviteCount() >= mkDistributionConfig.getInviteCount()) {
ShopUser parentShopUser1 = new ShopUser(); ShopUser parentShopUser1 = new ShopUser();
parentShopUser1.setId(shopUser.getId()); parentShopUser1.setId(parentShopUser.getId());
parentShopUser1.upDistributionShop(param.getShopId(), 1); parentShopUser1.upDistributionShop(param.getShopId(), 1);
shopUserService.updateById(parentShopUser1); shopUserService.updateById(parentShopUser1);
} }
@@ -295,7 +293,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
if ("invite".equals(mkDistributionConfig.getUpgradeType())) { if ("invite".equals(mkDistributionConfig.getUpgradeType())) {
if (mkDistributionConfig.getInviteConsume() == 1) { if (mkDistributionConfig.getInviteConsume() == 1) {
long count = orderInfoService.count(QueryWrapper.create() long count = orderInfoService.count(QueryWrapper.create()
.eq(OrderInfo::getUserId, shopUser.getId()) .eq(OrderInfo::getUserId, shopUser.getUserId())
.eq(OrderInfo::getShopId, parent.getShopId()) .eq(OrderInfo::getShopId, parent.getShopId())
.eq(OrderInfo::getStatus, OrderStatusEnums.DONE.getCode())); .eq(OrderInfo::getStatus, OrderStatusEnums.DONE.getCode()));
if (count < 1) { if (count < 1) {
@@ -315,7 +313,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
costUpgradeLevel(parent.getId(), parent.getShopId()); costUpgradeLevel(parent.getId(), parent.getShopId());
} }
} }
this.updateById(newDistributionUser); update(newDistributionUser, QueryWrapper.create().eq(MkDistributionUser::getId, parent.getId())
.eq(MkDistributionUser::getShopId, parent.getShopId()));
} }
@Override @Override
@@ -333,7 +332,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
* 分销员:按消费金额升级等级 * 分销员:按消费金额升级等级
*/ */
public void costUpgradeLevel(Long shopUserId, Long shopId) { public void costUpgradeLevel(Long shopUserId, Long shopId) {
MkDistributionUser distributionUser = getById(shopUserId); MkDistributionUser distributionUser = getMkDistributionUserByIdAndShopId(shopUserId, shopId);
if (distributionUser == null || distributionUser.getIsAssignLevel() == 1) { if (distributionUser == null || distributionUser.getIsAssignLevel() == 1) {
return; return;
} }
@@ -360,7 +359,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
newDistributionUser.setDistributionLevelName(levelConfig.getName()); newDistributionUser.setDistributionLevelName(levelConfig.getName());
} }
} }
updateById(newDistributionUser); update(newDistributionUser, QueryWrapper.create().eq(MkDistributionUser::getId, shopUserId)
.eq(MkDistributionUser::getShopId, shopId));
} }
@@ -401,8 +401,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
} }
@Override @Override
public Page<InviteUserVO> getInviteUser(Long id, Long shopUserId, Long distributionLevelId, Integer page, Integer size) { public Page<InviteUserVO> getInviteUser(Long id, Long shopId, Long shopUserId, Long distributionLevelId, Integer page, Integer size) {
return shopUserService.getInviteUser(id, shopUserId, distributionLevelId, page, size); return shopUserService.getInviteUser(id, shopId, shopUserId, distributionLevelId, page, size);
} }
@Override @Override
@@ -413,9 +413,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
AssertUtil.isNull(param.getId(), "店铺用户ID不能为空"); AssertUtil.isNull(param.getId(), "店铺用户ID不能为空");
ShopUser shopUser = shopUserService.getById(param.getId()); ShopUser shopUser = shopUserService.getById(param.getId());
AssertUtil.isNull(shopUser, "店铺用户ID不能为空"); AssertUtil.isNull(shopUser, "店铺用户ID不能为空");
MkDistributionUser distributionUser = getOne(QueryWrapper.create() MkDistributionUser distributionUser = getMkDistributionUserByIdAndShopId(param.getId(), param.getShopId());
.eq(MkDistributionUser::getId, param.getId())
.eq(MkDistributionUser::getShopId, param.getShopId()));
if (distributionUser != null && distributionUser.getStatus() != 0) { if (distributionUser != null && distributionUser.getStatus() != 0) {
throw new CzgException("该用户已是分销员,不可重复添加"); throw new CzgException("该用户已是分销员,不可重复添加");
} }
@@ -424,6 +422,7 @@ 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.setInviteCount(0);
if (!"自主申请".equals(param.getOpeningMethod()) || config.getInviteCount() == 0) { if (!"自主申请".equals(param.getOpeningMethod()) || config.getInviteCount() == 0) {
initLevel(config, param); initLevel(config, param);
} }
@@ -432,7 +431,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
distributionUser.setDistributionLevelId(param.getDistributionLevelId()); distributionUser.setDistributionLevelId(param.getDistributionLevelId());
distributionUser.setDistributionLevelName(param.getDistributionLevelName()); distributionUser.setDistributionLevelName(param.getDistributionLevelName());
distributionUser.setStatus(1); distributionUser.setStatus(1);
updateById(distributionUser); update(distributionUser, QueryWrapper.create().eq(MkDistributionUser::getId, param.getId())
.eq(MkDistributionUser::getShopId, param.getShopId()));
} else { } else {
if ("手动添加".equals(param.getOpeningMethod())) { if ("手动添加".equals(param.getOpeningMethod())) {
param.setStatus(1); param.setStatus(1);
@@ -457,13 +457,14 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
public void updateDistributionUserById(MkDistributionUserDTO param) { public void updateDistributionUserById(MkDistributionUserDTO param) {
AssertUtil.isNull(param.getId(), "分销员ID不能为空"); AssertUtil.isNull(param.getId(), "分销员ID不能为空");
MkDistributionUser distributionUser = BeanUtil.toBean(param, MkDistributionUser.class); MkDistributionUser distributionUser = BeanUtil.toBean(param, MkDistributionUser.class);
updateById(distributionUser); update(distributionUser, QueryWrapper.create().eq(MkDistributionUser::getId, param.getId())
.eq(MkDistributionUser::getShopId, param.getShopId()));
} }
@Override @Override
public void resetDistributionUserLevel(MkDistributionUserDTO param) { public void resetDistributionUserLevel(MkDistributionUserDTO param) {
AssertUtil.isNull(param.getId(), "分销员ID不能为空"); AssertUtil.isNull(param.getId(), "分销员ID不能为空");
MkDistributionUser distributionUser = getById(param.getId()); MkDistributionUser distributionUser = getMkDistributionUserByIdAndShopId(param.getId(), param.getShopId());
AssertUtil.isNull(distributionUser, "分销员不存在"); AssertUtil.isNull(distributionUser, "分销员不存在");
AssertUtil.isTrue(distributionUser.getIsAssignLevel() == 0, "分销员并未指定等级,不可重置"); AssertUtil.isTrue(distributionUser.getIsAssignLevel() == 0, "分销员并未指定等级,不可重置");
MkDistributionConfig config = mkDistributionConfigService.getOne( MkDistributionConfig config = mkDistributionConfigService.getOne(
@@ -477,7 +478,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
newDistributionUser.setDistributionLevelId(distributionUser.getDistributionLevelId()); newDistributionUser.setDistributionLevelId(distributionUser.getDistributionLevelId());
newDistributionUser.setDistributionLevelName(distributionUser.getDistributionLevelName()); newDistributionUser.setDistributionLevelName(distributionUser.getDistributionLevelName());
newDistributionUser.setConsumeAmount(distributionUser.getConsumeAmount()); newDistributionUser.setConsumeAmount(distributionUser.getConsumeAmount());
updateById(newDistributionUser); update(newDistributionUser, QueryWrapper.create().eq(MkDistributionUser::getId, distributionUser.getId())
.eq(MkDistributionUser::getShopId, distributionUser.getShopId()));
} }
@@ -515,12 +517,12 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
} }
@Override @Override
public void deleteDistributionUser(Long id) { public void deleteDistributionUser(Long id, Long shopId) {
AssertUtil.isNull(id, "分销员ID不能为空"); AssertUtil.isNull(id, "分销员ID不能为空");
MkDistributionUser distributionUser = new MkDistributionUser(); MkDistributionUser distributionUser = new MkDistributionUser();
distributionUser.setId(id);
distributionUser.setIsDel(1); distributionUser.setIsDel(1);
updateById(distributionUser); update(distributionUser, QueryWrapper.create().eq(MkDistributionUser::getId, id)
.eq(MkDistributionUser::getShopId, shopId));
} }
@@ -543,11 +545,11 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
public void open(Long shopUserId, BigDecimal amount, Long shopId, Long sourceId) { public void open(Long shopUserId, BigDecimal amount, Long shopId, Long sourceId) {
ShopUser shopUserInfo = shopUserService.getById(shopUserId); 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("分销员购买"));
try { try {
addDistributionUser(new MkDistributionUser().setShopId(shopId) addDistributionUser(new MkDistributionUser().setShopId(shopId)
.setUserId(shopUserInfo.getUserId()) .setUserId(shopUserInfo.getUserId())
@@ -591,7 +593,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
// 上上级分销员 // 上上级分销员
if (currentShopUser != null && currentShopUser.getDistributionUserId() != null) { if (currentShopUser != null && currentShopUser.getDistributionUserId() != null) {
MkDistributionUser parent = getOne(new QueryWrapper().eq(MkDistributionUser::getId, currentShopUser.getDistributionUserId())); MkDistributionUser parent = getMkDistributionUserByIdAndShopId(currentShopUser.getDistributionUserId(), config.getShopId());
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) {
@@ -603,11 +605,13 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
log.info("当前分销员: {}, 上级分销员: {}, 分销等级: {}", currentDistributionUser.getId(), currentShopUser == null ? null : currentShopUser.getDistributionUserId(), level.getId()); log.info("当前分销员: {}, 上级分销员: {}, 分销等级: {}", currentDistributionUser.getId(), currentShopUser == null ? null : currentShopUser.getDistributionUserId(), level.getId());
if (config.getRewardCount() != null && config.getRewardCount() > 0) { if (config.getRewardCount() != null && config.getRewardCount() > 0) {
long count = distributionFlowService.count(new QueryWrapper().eq(MkDistributionFlow::getSourceShopUserId, currentDistributionUser.getId()) long count = distributionFlowService.count(new QueryWrapper()
.eq(MkDistributionFlow::getShopUserId, currentDistributionUser.getId())); .eq(MkDistributionFlow::getShopId, config.getShopId()).eq(MkDistributionFlow::getShopUserId, currentDistributionUser.getId()));
if (count >= config.getRewardCount()) { if (count >= config.getRewardCount()) {
log.info("分销员{}已达到奖励次数上限, 次数: {}", currentDistributionUser.getId(), config.getRewardCount()); log.info("分销员{}已达到奖励次数上限, 次数: {}", currentDistributionUser.getId(), config.getRewardCount());
return; return;
}else {
log.info("分销员奖励次数: {}", count);
} }
} }
@@ -686,7 +690,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
distributionFlowService.updateById(item); distributionFlowService.updateById(item);
} else { } else {
// 执行扣款 // 执行扣款
updateIncome(BigDecimal.ZERO, item.getRewardAmount().negate(), BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(),item.getShopUserId(), item.getShopId(), item.getLevel()); updateIncome(BigDecimal.ZERO, item.getRewardAmount().negate(), BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopUserId(), item.getShopId(), item.getLevel());
updateShopInfoAmount(item.getShopId(), item.getRewardAmount(), orderId, TableValueConstant.DistributionAmountFlow.Type.REFUND, "分销回退"); updateShopInfoAmount(item.getShopId(), item.getRewardAmount(), orderId, TableValueConstant.DistributionAmountFlow.Type.REFUND, "分销回退");
} }
distributionFlowService.save(refundFlow); distributionFlowService.save(refundFlow);
@@ -708,7 +712,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
} }
log.info("开始分销, 当前来源用户: {}, shopId: {}, 邀请人id: {}", sourceUserId, shopId, sourceInviteUser.getDistributionUserId()); log.info("开始分销, 当前来源用户: {}, shopId: {}, 邀请人id: {}", sourceUserId, shopId, sourceInviteUser.getDistributionUserId());
MkDistributionUser distributionUser = getById(sourceInviteUser.getDistributionUserId()); MkDistributionUser distributionUser = getMkDistributionUserByIdAndShopId(sourceInviteUser.getDistributionUserId(), shopId);
deepReward(sourceShopUserInfo, null, config, distributionUser, amount, sourceId, type, orderNo, 1); deepReward(sourceShopUserInfo, null, config, distributionUser, amount, sourceId, type, orderNo, 1);
}); });
distributionDeliverService.save(deliver); distributionDeliverService.save(deliver);
@@ -722,12 +726,20 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
// 用户可提现余额 // 用户可提现余额
userInfoService.updateDistributionAmount(userId, receivedIncome); userInfoService.updateDistributionAmount(userId, receivedIncome);
//分销员余额 //分销员余额
boolean flag = mapper.updateIncome(pendingIncome, receivedIncome, withdrawIncome, id); boolean flag = mapper.updateIncome(pendingIncome, receivedIncome, withdrawIncome, id, shopId);
if (!flag) { if (!flag) {
throw new CzgException("操作失败"); throw new CzgException("操作失败");
} }
} }
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 @Override
public Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO) { public Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO) {
UserInfo userInfo = userInfoService.getById(userId); UserInfo userInfo = userInfoService.getById(userId);
@@ -739,7 +751,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
throw new CzgException("请先实名认证"); throw new CzgException("请先实名认证");
} }
BigDecimal fee = withdrawFlowDTO.getAmount().multiply(BigDecimal.valueOf(0.08)); BigDecimal fee = withdrawFlowDTO.getAmount().multiply(BigDecimal.valueOf(0.08)).setScale(2, RoundingMode.UP);
BigDecimal finalAmount = withdrawFlowDTO.getAmount().subtract(fee); BigDecimal finalAmount = withdrawFlowDTO.getAmount().subtract(fee);
MkDistributionWithdrawFlow withdrawFlow = new MkDistributionWithdrawFlow().setUserId(userId) MkDistributionWithdrawFlow withdrawFlow = new MkDistributionWithdrawFlow().setUserId(userId)
@@ -785,4 +797,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
flow.setFailReason(failReason); flow.setFailReason(failReason);
withdrawFlowService.updateById(flow); withdrawFlowService.updateById(flow);
} }
@Override
public MkDistributionUser getMkDistributionUserByIdAndShopId(Long shopUserId, Long shopId) {
return getOne(new QueryWrapper().eq(MkDistributionUser::getId, shopUserId).eq(MkDistributionUser::getShopId, shopId));
}
} }

View File

@@ -5,7 +5,7 @@
<mapper namespace="com.czg.service.market.mapper.MkDistributionFlowMapper"> <mapper namespace="com.czg.service.market.mapper.MkDistributionFlowMapper">
<select id="pageInfo" resultType="com.czg.market.vo.MkDistributionFlowVO"> <select id="pageInfo" resultType="com.czg.market.vo.MkDistributionFlowVO">
select a.*, b.phone, c.phone as sourcePhone, e.shop_name from mk_distribution_flow as a select distinct a.*, b.phone, c.phone as sourcePhone, e.shop_name from mk_distribution_flow as a
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

View File

@@ -15,7 +15,7 @@
pending_income = pending_income + #{pendingIncome}, pending_income = pending_income + #{pendingIncome},
received_income = received_income + #{receivedIncome}, received_income = received_income + #{receivedIncome},
withdrawn_income = withdrawn_income + #{withdrawIncome} withdrawn_income = withdrawn_income + #{withdrawIncome}
where id = #{id} where id = #{id} and shop_id = #{shopId}
</update> </update>
<select id="selectMyDistributionShops" resultType="com.czg.market.vo.DistributionCenterShopVO"> <select id="selectMyDistributionShops" resultType="com.czg.market.vo.DistributionCenterShopVO">
@@ -56,17 +56,16 @@
</select> </select>
<select id="getOrderConsumeAmountByList" resultType="java.math.BigDecimal"> <select id="getOrderConsumeAmountByList" resultType="java.math.BigDecimal">
SELECT SELECT IFNULL(SUM(ord.pay_amount), 0) AS totalAmount
IFNULL( SUM( ord.pay_amount ), 0 ) AS totalAmount FROM tb_shop_user_invite invite
FROM INNER JOIN tb_shop_user su on invite.shop_user_id = su.id
tb_shop_user su INNER JOIN tb_order_info ord ON su.user_id = ord.user_id
INNER JOIN tb_order_info ord ON su.user_id = ord.user_id and invite.shop_id = #{shopId}
AND ord.shop_id = #{shopId} AND ord.shop_id = #{shopId}
AND ord.STATUS = 'done' AND ord.STATUS = 'done'
AND ord.pay_type NOT IN ( 'vip_pay', 'credit_pay' ) AND ord.pay_type NOT IN ('vip_pay', 'credit_pay')
AND ord.paid_time >= su.invite_time AND ord.paid_time >= invite.invite_time
WHERE WHERE invite.distribution_user_id = #{inviterId}
su.distribution_user_id = #{inviterId}
</select> </select>
<select id="getOrderConsumeAmountById" resultType="java.math.BigDecimal"> <select id="getOrderConsumeAmountById" resultType="java.math.BigDecimal">

View File

@@ -70,7 +70,7 @@ public class DistributionPayServiceImpl implements DistributionPayService {
ShopUser shopUserInfo = shopUserService.getShopUserInfo(payParam.getShopId(), userId); ShopUser shopUserInfo = shopUserService.getShopUserInfo(payParam.getShopId(), userId);
OrderPayment orderPayment = new OrderPayment().setShopId(payParam.getShopId()).setSourceId(isRecharge ? payParam.getShopId() : shopUserInfo.getId()) OrderPayment orderPayment = new OrderPayment().setShopId(payParam.getShopId()).setSourceId(isRecharge ? payParam.getShopId() : shopUserInfo.getId())
.setPayType(isRecharge ? "distributionRecharge" : "distribution").setOrderNo(payParam.getPlatformType() + IdUtil.getSnowflakeNextId()).setAmount(detail.getPayAmount()); .setPayType(isRecharge ? "distributionRecharge" : "distribution").setOrderNo(payParam.getPlatformType() + IdUtil.getSnowflakeNextId()).setAmount(isRecharge ? payParam.getAmount() : detail.getPayAmount());
orderPaymentService.save(orderPayment); orderPaymentService.save(orderPayment);
InitInfo initInfo = new InitInfo().setConfig(detail); InitInfo initInfo = new InitInfo().setConfig(detail);