Merge branch 'dev' into prod
This commit is contained in:
commit
63574fda34
|
|
@ -79,9 +79,9 @@ public class DistributionTask {
|
||||||
} else {
|
} else {
|
||||||
item.setStatus(TableValueConstant.DistributionFlow.Status.SUCCESS.getCode());
|
item.setStatus(TableValueConstant.DistributionFlow.Status.SUCCESS.getCode());
|
||||||
ShopUser shopUser = shopUserService.getById(item.getDistributionUserId());
|
ShopUser shopUser = shopUserService.getById(item.getDistributionUserId());
|
||||||
distributionUserService.updateIncome(item.getRewardAmount().negate(), item.getRewardAmount(), BigDecimal.ZERO,
|
|
||||||
item.getDistributionUserId(), shopUser.getUserId(), item.getShopId(), item.getLevel());
|
|
||||||
distributionUserService.updateShopInfoAmount(orderInfo.getShopId(), item.getRewardAmount().negate(), orderInfo.getId(), TableValueConstant.DistributionAmountFlow.Type.SUB, "分销扣减");
|
distributionUserService.updateShopInfoAmount(orderInfo.getShopId(), item.getRewardAmount().negate(), orderInfo.getId(), TableValueConstant.DistributionAmountFlow.Type.SUB, "分销扣减");
|
||||||
|
distributionUserService.updateIncome(item.getRewardAmount().negate(), item.getRewardAmount(), BigDecimal.ZERO,
|
||||||
|
item.getDistributionUserId(), shopUser.getUserId(), item.getShopUserId(), item.getShopId(), item.getLevel());
|
||||||
}
|
}
|
||||||
distributionFlowService.updateById(item);
|
distributionFlowService.updateById(item);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -150,14 +150,6 @@ public class ShopUser implements Serializable {
|
||||||
private LocalDateTime endTime;
|
private LocalDateTime endTime;
|
||||||
private LocalDateTime deliverTime;
|
private LocalDateTime deliverTime;
|
||||||
private LocalDateTime nextDeliverTime;
|
private LocalDateTime nextDeliverTime;
|
||||||
// 分销员ID 邀请人id
|
|
||||||
private Long distributionUserId;
|
|
||||||
// 分销员ID 邀请人上级id
|
|
||||||
private Long distributionUserParentId;
|
|
||||||
//邀请人累计收益/一级分润
|
|
||||||
private BigDecimal oneIncome;
|
|
||||||
//邀请人上级累计收益/二级分润
|
|
||||||
private BigDecimal twoIncome;
|
|
||||||
// 是否分销员
|
// 是否分销员
|
||||||
private String distributionShops;
|
private String distributionShops;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,5 +36,5 @@ public interface ShopUserService extends IService<ShopUser> {
|
||||||
|
|
||||||
List<ShopUser> selectBirthdayUser(LocalDate current, Long mainShopId, String userType);
|
List<ShopUser> selectBirthdayUser(LocalDate current, Long mainShopId, String userType);
|
||||||
|
|
||||||
void updateOneOrTwoAmount(Long userId, Long mainShopId, BigDecimal bigDecimal, Integer isOne);
|
void updateOneOrTwoAmount(Long shopUserId, Long shopId, BigDecimal bigDecimal, Integer isOne);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
|
||||||
|
package com.czg.market.dto;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import com.alibaba.fastjson2.annotation.JSONField;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import java.io.Serial;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邀请与上级关联表 实体类。
|
||||||
|
*
|
||||||
|
* @author ww
|
||||||
|
* @since 2025-11-06
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class ShopUserInviteDTO implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (随机)
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 店铺ID
|
||||||
|
*/
|
||||||
|
private Long shopId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 店铺用户ID
|
||||||
|
*/
|
||||||
|
private Long shopUserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邀请人ID mk_distribution_user.id
|
||||||
|
*/
|
||||||
|
private Long distributionUserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邀请人上级ID mk_distribution_user.id
|
||||||
|
*/
|
||||||
|
private Long distributionUserParentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邀请人收益/一级分润
|
||||||
|
*/
|
||||||
|
private BigDecimal oneIncome;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邀请人上级收益/二级分润
|
||||||
|
*/
|
||||||
|
private BigDecimal twoIncome;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邀请时间
|
||||||
|
*/
|
||||||
|
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime inviteTime;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
package com.czg.market.entity;
|
||||||
|
|
||||||
|
import com.mybatisflex.annotation.Id;
|
||||||
|
import com.mybatisflex.annotation.KeyType;
|
||||||
|
import com.mybatisflex.annotation.Table;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邀请与上级关联表 实体类。
|
||||||
|
*
|
||||||
|
* @author ww
|
||||||
|
* @since 2025-11-06
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Table("tb_shop_user_invite")
|
||||||
|
public class ShopUserInvite implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (随机)
|
||||||
|
*/
|
||||||
|
@Id(keyType = KeyType.Auto)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 店铺ID
|
||||||
|
*/
|
||||||
|
private Long shopId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 店铺用户ID
|
||||||
|
*/
|
||||||
|
private Long shopUserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邀请人ID mk_distribution_user.id
|
||||||
|
*/
|
||||||
|
private Long distributionUserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邀请人上级ID mk_distribution_user.id
|
||||||
|
*/
|
||||||
|
private Long distributionUserParentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邀请人收益/一级分润
|
||||||
|
*/
|
||||||
|
private BigDecimal oneIncome;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邀请人上级收益/二级分润
|
||||||
|
*/
|
||||||
|
private BigDecimal twoIncome;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邀请时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime inviteTime;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -132,7 +132,7 @@ public interface MkDistributionUserService extends IService<MkDistributionUser>
|
||||||
*/
|
*/
|
||||||
void distribute(Long sourceId, String orderNo, BigDecimal amount, Long userId, Long shopId, String type);
|
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 shopUserId, Long shopId, Integer isOne);
|
||||||
|
|
||||||
|
|
||||||
Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO);
|
Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.czg.market.service;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.service.IService;
|
||||||
|
import com.czg.market.entity.ShopUserInvite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邀请与上级关联表 服务层。
|
||||||
|
*
|
||||||
|
* @author ww
|
||||||
|
* @since 2025-11-06
|
||||||
|
*/
|
||||||
|
public interface ShopUserInviteService extends IService<ShopUserInvite> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据店铺ID和店铺用户ID查询邀请记录
|
||||||
|
*
|
||||||
|
* @param shopId 店铺ID
|
||||||
|
* @param shopUserId 店铺用户ID
|
||||||
|
* @return 邀请记录
|
||||||
|
*/
|
||||||
|
ShopUserInvite getOneByShopIdAndShopUserId(Long shopId, Long shopUserId);
|
||||||
|
}
|
||||||
|
|
@ -72,6 +72,6 @@ public interface ShopUserMapper extends BaseMapper<ShopUser> {
|
||||||
*/
|
*/
|
||||||
List<InviteUserVO> getInviteUser(Long distributionUserId, Long shopUserId, Long distributionLevelId);
|
List<InviteUserVO> getInviteUser(Long distributionUserId, Long shopUserId, Long distributionLevelId);
|
||||||
|
|
||||||
void updateOneOrTwoAmount(Long userId, Long mainShopId, BigDecimal amount, Integer isOne);
|
void updateOneOrTwoAmount(Long shopUserId, Long shopId, BigDecimal amount, Integer isOne);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -171,7 +171,7 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateOneOrTwoAmount(Long userId, Long mainShopId, BigDecimal bigDecimal, Integer isOne) {
|
public void updateOneOrTwoAmount(Long shopUserId, Long shopId, BigDecimal bigDecimal, Integer isOne) {
|
||||||
mapper.updateOneOrTwoAmount(userId, mainShopId, bigDecimal, isOne);
|
mapper.updateOneOrTwoAmount(shopUserId, shopId, bigDecimal, isOne);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
and amount - #{money} >= 0
|
and amount - #{money} >= 0
|
||||||
</update>
|
</update>
|
||||||
<update id="updateOneOrTwoAmount">
|
<update id="updateOneOrTwoAmount">
|
||||||
update tb_shop_user
|
update tb_shop_user_invite
|
||||||
<set>
|
<set>
|
||||||
<if test="isOne != null and isOne == 1">
|
<if test="isOne != null and isOne == 1">
|
||||||
one_income = one_income + #{amount}
|
one_income = one_income + #{amount}
|
||||||
|
|
@ -27,8 +27,8 @@
|
||||||
two_income = two_income + #{amount}
|
two_income = two_income + #{amount}
|
||||||
</if>
|
</if>
|
||||||
</set>
|
</set>
|
||||||
where user_id = #{userId}
|
where shop_user_id = #{shopUserId}
|
||||||
and main_shop_id = #{mainShopId}
|
and shop_id = #{shopId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -281,8 +281,8 @@
|
||||||
u.head_img AS headImg,
|
u.head_img AS headImg,
|
||||||
u.nick_name AS shopUserName,
|
u.nick_name AS shopUserName,
|
||||||
u.phone AS shopUserPhone,
|
u.phone AS shopUserPhone,
|
||||||
u.one_income AS oneIncome,
|
invite.one_income AS oneIncome,
|
||||||
u.invite_time AS inviteTime,
|
invite.invite_time AS inviteTime,
|
||||||
dist.total_income AS totalIncome,
|
dist.total_income AS totalIncome,
|
||||||
dist.pending_income AS pendingIncome,
|
dist.pending_income AS pendingIncome,
|
||||||
dist.received_income AS receivedIncome,
|
dist.received_income AS receivedIncome,
|
||||||
|
|
@ -291,8 +291,9 @@
|
||||||
dist.distribution_level_id AS levelId,
|
dist.distribution_level_id AS levelId,
|
||||||
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` as u
|
FROM tb_shop_user_invite invite
|
||||||
left join mk_distribution_user dist on u.id = dist.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
|
||||||
WHERE u.`distribution_user_id` = #{distributionUserId}
|
WHERE u.`distribution_user_id` = #{distributionUserId}
|
||||||
<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 u.id = #{shopUserId}</if>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.czg.service.market.mapper;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.BaseMapper;
|
||||||
|
import com.czg.market.entity.ShopUserInvite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邀请与上级关联表 映射层。
|
||||||
|
*
|
||||||
|
* @author ww
|
||||||
|
* @since 2025-11-06
|
||||||
|
*/
|
||||||
|
public interface ShopUserInviteMapper extends BaseMapper<ShopUserInvite> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -74,6 +74,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
private MkDistributionWithdrawFlowService withdrawFlowService;
|
private MkDistributionWithdrawFlowService withdrawFlowService;
|
||||||
@Resource
|
@Resource
|
||||||
private MkDistributionDeliverService distributionDeliverService;
|
private MkDistributionDeliverService distributionDeliverService;
|
||||||
|
@Resource
|
||||||
|
private ShopUserInviteService shopUserInviteService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private AppWxServiceImpl appWxService;
|
private AppWxServiceImpl appWxService;
|
||||||
|
|
@ -127,7 +129,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
for (DistributionCenterShopVO unActivate : unActivates) {
|
for (DistributionCenterShopVO unActivate : unActivates) {
|
||||||
if (unActivate.getOrderCount() == 1) {
|
if (unActivate.getOrderCount() == 1) {
|
||||||
unActivate.setLabelContent("在本店下单过");
|
unActivate.setLabelContent("在本店下单过");
|
||||||
}else if (unActivate.getShopUser() == 1) {
|
} else if (unActivate.getShopUser() == 1) {
|
||||||
unActivate.setLabelContent("曾进入过店铺");
|
unActivate.setLabelContent("曾进入过店铺");
|
||||||
}
|
}
|
||||||
// else if("manual".equals(unActivate.getOpenType())){
|
// else if("manual".equals(unActivate.getOpenType())){
|
||||||
|
|
@ -151,8 +153,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
AssertUtil.isNull(shopUser, "店铺用户不存在");
|
AssertUtil.isNull(shopUser, "店铺用户不存在");
|
||||||
UserInfo userInfo = userInfoService.getById(shopUser.getUserId());
|
UserInfo userInfo = userInfoService.getById(shopUser.getUserId());
|
||||||
result.put("cashOutAmount", userInfo.getDistributionAmount() == null ? 0.0 : userInfo.getDistributionAmount());
|
result.put("cashOutAmount", userInfo.getDistributionAmount() == null ? 0.0 : userInfo.getDistributionAmount());
|
||||||
if (shopUser.getDistributionUserId() != null) {
|
ShopUserInvite shopUserInvite = shopUserInviteService.getOneByShopIdAndShopUserId(shopId, shopUser.getId());
|
||||||
MkDistributionUser mkDistributionUser = this.getById(shopUser.getDistributionUserId());
|
if (shopUserInvite != null && shopUserInvite.getDistributionUserId() != null) {
|
||||||
|
MkDistributionUser mkDistributionUser = this.getById(shopUserInvite.getDistributionUserId());
|
||||||
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());
|
||||||
|
|
@ -236,7 +239,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
public void bindInviteUser(MkDistributionUserDTO param) {
|
public void bindInviteUser(MkDistributionUserDTO param) {
|
||||||
ShopUser shopUser = shopUserService.getById(param.getId());
|
ShopUser shopUser = shopUserService.getById(param.getId());
|
||||||
AssertUtil.isNull(shopUser, "店铺用户不存在");
|
AssertUtil.isNull(shopUser, "店铺用户不存在");
|
||||||
if (shopUser.getDistributionUserId() != null) {
|
ShopUserInvite shopUserInvite = shopUserInviteService.getOneByShopIdAndShopUserId(param.getShopId(), shopUser.getId());
|
||||||
|
if (shopUserInvite != null && shopUserInvite.getDistributionUserId() != null) {
|
||||||
throw new CzgException("店铺用户已绑定分销员");
|
throw new CzgException("店铺用户已绑定分销员");
|
||||||
}
|
}
|
||||||
MkDistributionUser parent = getOne(QueryWrapper.create().eq(MkDistributionUser::getInviteCode, param.getInviteCode()));
|
MkDistributionUser parent = getOne(QueryWrapper.create().eq(MkDistributionUser::getInviteCode, param.getInviteCode()));
|
||||||
|
|
@ -252,24 +256,26 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
}
|
}
|
||||||
ShopUser parentShopUser = shopUserService.getById(parent.getId());
|
ShopUser parentShopUser = shopUserService.getById(parent.getId());
|
||||||
AssertUtil.isNull(parentShopUser, "邀请人不存在");
|
AssertUtil.isNull(parentShopUser, "邀请人不存在");
|
||||||
if (parentShopUser.getDistributionUserId() != null && parentShopUser.getDistributionUserId().equals(shopUser.getId())) {
|
ShopUserInvite parentShopUserInvite = shopUserInviteService.getOneByShopIdAndShopUserId(param.getShopId(), parentShopUser.getId());
|
||||||
|
if (parentShopUserInvite != null && parentShopUserInvite.getDistributionUserId() != null && parentShopUserInvite.getDistributionUserId().equals(shopUser.getId())) {
|
||||||
throw new CzgException("存在绑定关系,不可绑定");
|
throw new CzgException("存在绑定关系,不可绑定");
|
||||||
}
|
}
|
||||||
if (parentShopUser.getDistributionUserParentId() != null && parentShopUser.getDistributionUserParentId().equals(shopUser.getId())) {
|
if (parentShopUserInvite != null && parentShopUserInvite.getDistributionUserParentId() != null && parentShopUserInvite.getDistributionUserParentId().equals(shopUser.getId())) {
|
||||||
throw new CzgException("存在绑定关系,不可绑定");
|
throw new CzgException("存在绑定关系,不可绑定");
|
||||||
}
|
}
|
||||||
//更新自己的上级
|
//更新自己的上级
|
||||||
ShopUser newShopUser = new ShopUser();
|
ShopUserInvite newShopUserInvite = new ShopUserInvite();
|
||||||
newShopUser.setId(shopUser.getId());
|
newShopUserInvite.setShopId(param.getShopId());
|
||||||
newShopUser.setDistributionUserId(parentShopUser.getId());
|
newShopUserInvite.setShopUserId(shopUser.getId());
|
||||||
newShopUser.setDistributionUserParentId(parentShopUser.getDistributionUserId());
|
newShopUserInvite.setDistributionUserId(parentShopUser.getId());
|
||||||
newShopUser.setInviteTime(LocalDateTime.now());
|
newShopUserInvite.setDistributionUserParentId(parentShopUserInvite == null ? null : parentShopUserInvite.getDistributionUserParentId());
|
||||||
shopUserService.updateById(newShopUser);
|
newShopUserInvite.setInviteTime(LocalDateTime.now());
|
||||||
if (parentShopUser.getDistributionUserParentId() != null) {
|
shopUserInviteService.save(newShopUserInvite);
|
||||||
|
if (parentShopUserInvite != null && parentShopUserInvite.getDistributionUserParentId() != null) {
|
||||||
//更新自己的下级 的上级的上级 为自己的上级
|
//更新自己的下级 的上级的上级 为自己的上级
|
||||||
ShopUser childShopUser = new ShopUser();
|
ShopUserInvite childShopUserInvite = new ShopUserInvite();
|
||||||
childShopUser.setDistributionUserParentId(parentShopUser.getDistributionUserParentId());
|
childShopUserInvite.setDistributionUserParentId(parentShopUser.getId());
|
||||||
shopUserService.update(childShopUser, QueryWrapper.create().eq(ShopUser::getDistributionUserId, shopUser.getId()));
|
shopUserInviteService.update(childShopUserInvite, QueryWrapper.create().eq(ShopUserInvite::getDistributionUserId, shopUser.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
MkDistributionUser newDistributionUser = new MkDistributionUser();
|
MkDistributionUser newDistributionUser = new MkDistributionUser();
|
||||||
|
|
@ -316,8 +322,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
public void costUpgradeLevelBefore(Long userId, Long shopId) {
|
public void costUpgradeLevelBefore(Long userId, Long shopId) {
|
||||||
ShopUser shopUser = shopUserService.getShopUserInfo(shopId, userId);
|
ShopUser shopUser = shopUserService.getShopUserInfo(shopId, userId);
|
||||||
costUpgradeLevel(shopUser.getId(), shopId);
|
costUpgradeLevel(shopUser.getId(), shopId);
|
||||||
if (shopUser.getDistributionUserId() != null) {
|
ShopUserInvite shopUserInvite = shopUserInviteService.getOneByShopIdAndShopUserId(shopId, shopUser.getId());
|
||||||
costUpgradeLevel(shopUser.getDistributionUserId(), shopId);
|
if (shopUserInvite != null && shopUserInvite.getDistributionUserId() != null) {
|
||||||
|
costUpgradeLevel(shopUserInvite.getDistributionUserId(), shopId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -474,7 +481,6 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initLevel(MkDistributionConfig config, MkDistributionUser distributionUser) {
|
public void initLevel(MkDistributionConfig config, MkDistributionUser distributionUser) {
|
||||||
MkDistributionLevelConfig levelConfig = new MkDistributionLevelConfig();
|
MkDistributionLevelConfig levelConfig = new MkDistributionLevelConfig();
|
||||||
|
|
@ -572,7 +578,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
AssertUtil.isNull(currentDistributionUser, "分销员不存在");
|
AssertUtil.isNull(currentDistributionUser, "分销员不存在");
|
||||||
AssertUtil.isTrue(currentDistributionUser.getStatus() != 1, "分销员未开启");
|
AssertUtil.isTrue(currentDistributionUser.getStatus() != 1, "分销员未开启");
|
||||||
|
|
||||||
ShopUser currentShopUser = shopUserService.getById(currentDistributionUser.getId());
|
// ShopUser currentShopUser = shopUserService.getById(currentDistributionUser.getId());
|
||||||
|
ShopUserInvite currentShopUser = shopUserInviteService.getOneByShopIdAndShopUserId(config.getShopId(), currentDistributionUser.getId());
|
||||||
MkDistributionLevelConfig level = levelConfigService.getById(currentDistributionUser.getDistributionLevelId());
|
MkDistributionLevelConfig level = levelConfigService.getById(currentDistributionUser.getDistributionLevelId());
|
||||||
|
|
||||||
// 校验剩余分成比例
|
// 校验剩余分成比例
|
||||||
|
|
@ -633,10 +640,10 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
log.info("即时分销开始");
|
log.info("即时分销开始");
|
||||||
try {
|
try {
|
||||||
updateShopInfoAmount(currentDistributionUser.getShopId(), rewardAmount.negate(), sourceId, TableValueConstant.DistributionAmountFlow.Type.SUB, "分销扣除");
|
updateShopInfoAmount(currentDistributionUser.getShopId(), rewardAmount.negate(), sourceId, TableValueConstant.DistributionAmountFlow.Type.SUB, "分销扣除");
|
||||||
updateIncome(BigDecimal.ZERO, rewardAmount, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
|
updateIncome(BigDecimal.ZERO, rewardAmount, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getId(), config.getShopId(), currentLevel == 1 ? 1 : 2);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
mkDistributionFlow.setStatus(TableValueConstant.DistributionFlow.Status.PENDING.getCode());
|
mkDistributionFlow.setStatus(TableValueConstant.DistributionFlow.Status.PENDING.getCode());
|
||||||
updateIncome(rewardAmount, BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
|
updateIncome(rewardAmount, BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getId(), config.getShopId(), currentLevel == 1 ? 1 : 2);
|
||||||
distributionFlowService.updateById(mkDistributionFlow);
|
distributionFlowService.updateById(mkDistributionFlow);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -644,7 +651,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
mkDistributionFlow.setStatus(TableValueConstant.DistributionFlow.Status.PENDING.getCode());
|
mkDistributionFlow.setStatus(TableValueConstant.DistributionFlow.Status.PENDING.getCode());
|
||||||
distributionFlowService.save(mkDistributionFlow);
|
distributionFlowService.save(mkDistributionFlow);
|
||||||
log.info("延时分销开始");
|
log.info("延时分销开始");
|
||||||
updateIncome(rewardAmount, BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
|
updateIncome(rewardAmount, BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getId(), config.getShopId(), currentLevel == 1 ? 1 : 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -675,11 +682,11 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
refundFlow.setUpdateTime(DateUtil.date().toLocalDateTime());
|
refundFlow.setUpdateTime(DateUtil.date().toLocalDateTime());
|
||||||
if (TableValueConstant.DistributionFlow.Status.PENDING.getCode().equals(item.getStatus())) {
|
if (TableValueConstant.DistributionFlow.Status.PENDING.getCode().equals(item.getStatus())) {
|
||||||
item.setStatus(TableValueConstant.DistributionFlow.Status.SUCCESS.getCode());
|
item.setStatus(TableValueConstant.DistributionFlow.Status.SUCCESS.getCode());
|
||||||
updateIncome(item.getRewardAmount().negate(), BigDecimal.ZERO, BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopId(), item.getLevel());
|
updateIncome(item.getRewardAmount().negate(), BigDecimal.ZERO, BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopUserId(), item.getShopId(), item.getLevel());
|
||||||
distributionFlowService.updateById(item);
|
distributionFlowService.updateById(item);
|
||||||
} else {
|
} else {
|
||||||
// 执行扣款
|
// 执行扣款
|
||||||
updateIncome(BigDecimal.ZERO, item.getRewardAmount().negate(), BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), 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);
|
||||||
|
|
@ -695,12 +702,13 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
AssertUtil.isTrue(config.getIsEnable() != 1, "分销未开启");
|
AssertUtil.isTrue(config.getIsEnable() != 1, "分销未开启");
|
||||||
// 当前用户上级分销员
|
// 当前用户上级分销员
|
||||||
ShopUser sourceShopUserInfo = shopUserService.getShopUserInfo(shopId, sourceUserId);
|
ShopUser sourceShopUserInfo = shopUserService.getShopUserInfo(shopId, sourceUserId);
|
||||||
if (sourceShopUserInfo.getDistributionUserId() == null) {
|
ShopUserInvite sourceInviteUser = shopUserInviteService.getOneByShopIdAndShopUserId(shopId, sourceShopUserInfo.getId());
|
||||||
|
if (sourceInviteUser.getDistributionUserId() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.info("开始分销, 当前来源用户: {}, shopId: {}, 邀请人id: {}", sourceUserId, shopId, sourceShopUserInfo.getDistributionUserId());
|
log.info("开始分销, 当前来源用户: {}, shopId: {}, 邀请人id: {}", sourceUserId, shopId, sourceInviteUser.getDistributionUserId());
|
||||||
|
|
||||||
MkDistributionUser distributionUser = getById(sourceShopUserInfo.getDistributionUserId());
|
MkDistributionUser distributionUser = getById(sourceInviteUser.getDistributionUserId());
|
||||||
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);
|
||||||
|
|
@ -708,9 +716,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
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 shopUserId, Long shopId, Integer isOne) {
|
||||||
// 用户收益信息
|
// 用户收益信息
|
||||||
shopUserService.updateOneOrTwoAmount(userId, mainShopId, receivedIncome, isOne);
|
shopUserService.updateOneOrTwoAmount(shopUserId, shopId, receivedIncome, isOne);
|
||||||
// 用户可提现余额
|
// 用户可提现余额
|
||||||
userInfoService.updateDistributionAmount(userId, receivedIncome);
|
userInfoService.updateDistributionAmount(userId, receivedIncome);
|
||||||
//分销员余额
|
//分销员余额
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.czg.service.market.service.impl;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
|
import com.czg.market.entity.ShopUserInvite;
|
||||||
|
import com.czg.market.service.ShopUserInviteService;
|
||||||
|
import com.czg.service.market.mapper.ShopUserInviteMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邀请与上级关联表 服务层实现。
|
||||||
|
*
|
||||||
|
* @author ww
|
||||||
|
* @since 2025-11-06
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class ShopUserInviteServiceImpl extends ServiceImpl<ShopUserInviteMapper, ShopUserInvite> implements ShopUserInviteService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ShopUserInvite getOneByShopIdAndShopUserId(Long shopId, Long shopUserId) {
|
||||||
|
return getOne(QueryWrapper.create()
|
||||||
|
.eq(ShopUserInvite::getShopId, shopId)
|
||||||
|
.eq(ShopUserInvite::getShopUserId, shopUserId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.czg.service.market.mapper.ShopUserInviteMapper">
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Loading…
Reference in New Issue