分销完善

This commit is contained in:
张松 2025-10-28 17:44:19 +08:00
parent 618286703e
commit 655b545bdb
6 changed files with 32 additions and 17 deletions

View File

@ -56,7 +56,8 @@ public class NotifyController {
@GetMapping("testOpen")
public Map<String, String> test1(String code) throws Exception {
return wxService.v3Pay("oeQYq5LzW-kSxJL9TR4s_UmOmNLE", new BigDecimal("0.01"), "测试", "testZs" + RandomUtil.randomNumbers(20), "distributionRecharge");
distributionUserService.distribute(54458L, "WX1980104754310836224", BigDecimal.valueOf(18), 36434L, 122L, "order");
return null;
}

View File

@ -14,5 +14,5 @@ import java.math.BigDecimal;
*/
public interface UserInfoMapper extends BaseMapper<UserInfo> {
boolean updateAmount(long userId, BigDecimal amount);
int updateAmount(long userId, BigDecimal amount);
}

View File

@ -102,8 +102,8 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> i
@Override
public void updateDistributionAmount(long userId, BigDecimal amount) {
boolean b = mapper.updateAmount(userId, amount);
if (!b) {
int b = mapper.updateAmount(userId, amount);
if (b <= 0) {
throw new CzgException("更新分销金额失败");
}
}

View File

@ -5,7 +5,7 @@
<mapper namespace="com.czg.service.account.mapper.UserInfoMapper">
<update id="updateAmount">
update tb_user_info set distribution_amount = distribution_amount + #{amount} where id = #{id}
update tb_user_info set distribution_amount = distribution_amount + #{amount} where id = #{userId}
and distribution_amount + #{amount} >= 0
</update>
</mapper>

View File

@ -494,6 +494,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
private void deepReward(MkDistributionConfigVO config, ShopUser sourceShopUser, BigDecimal amount, Long sourceId, String type, String orderNo, Integer currentLevel) {
if (currentLevel > 2) {
return;
}
MkDistributionUser distributionUser = getOne(new QueryWrapper().eq(MkDistributionUser::getId, sourceShopUser.getId()));
AssertUtil.isNull(distributionUser, "分销员不存在");
AssertUtil.isTrue(distributionUser.getStatus() != 1, "分销员未开启");
@ -526,16 +529,17 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
// 店铺信息
BigDecimal rewardAmount;
if (currentLevel == 1) {
rewardAmount = amount.multiply(level.getLevelOneCommission().divide(BigDecimal.valueOf(100), RoundingMode.DOWN));
} else {
rewardAmount = amount.multiply(level.getLevelTwoCommission().divide(BigDecimal.valueOf(100), RoundingMode.DOWN));
}
// if (currentLevel == 1) {
// rewardAmount = amount.multiply(level.getLevelOneCommission().divide(BigDecimal.valueOf(100), RoundingMode.DOWN));
// } else {
// rewardAmount = amount.multiply(level.getLevelTwoCommission().divide(BigDecimal.valueOf(100), RoundingMode.DOWN));
// }
rewardAmount = amount.multiply(level.getLevelTwoCommission().divide(BigDecimal.valueOf(100), RoundingMode.DOWN));
boolean flag = true;
BigDecimal finalAmount = BigDecimal.ZERO;
try {
shopInfoService.updateAmount(distributionUser.getShopId(), rewardAmount.negate());
finalAmount = shopInfoService.updateAmount(distributionUser.getShopId(), rewardAmount.negate());
} catch (Exception e) {
flag = false;
}
@ -554,9 +558,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
if (flag) {
distributionAmountFlowService.save(new MkDistributionAmountFlow()
.setType(TableValueConstant.DistributionAmountFlow.Type.SELF_RECHARGE.getCode())
.setShopId(config.getShopId()).setAmount(finalAmount).setChangeAmount(amount).setSourceId(mkDistributionFlow.getId())
.setRemark("自助充值").setOpAccount(StpKit.USER.getAccount()));
.setType(TableValueConstant.DistributionAmountFlow.Type.SUB.getCode())
.setShopId(config.getShopId()).setAmount(finalAmount).setChangeAmount(rewardAmount).setSourceId(mkDistributionFlow.getId())
.setRemark("分账扣除"));
}
}
@ -574,14 +578,18 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
return;
}
deepReward(config, sourceShopUserInfo, amount, sourceId, type, orderNo, 1);
}, "分销方法执行失败");
ShopUser parentUserInfo = shopUserService.getById(sourceShopUserInfo.getDistributionUserId());
deepReward(config, parentUserInfo, amount, sourceId, type, orderNo, 1);
});
}
@Override
public void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId) {
userInfoService.updateDistributionAmount(userId, receivedIncome);
boolean flag = mapper.updateIncome(pendingIncome, receivedIncome, withdrawIncome, id);
if (!flag) {
throw new CzgException("操作失败");
}
}
@Override

View File

@ -5,7 +5,13 @@
<mapper namespace="com.czg.service.market.mapper.MkDistributionUserMapper">
<update id="updateIncome">
update mk_distribution_user
set total_income = total_income + #{pendingIncome},
set
<if test="pendingIncome != null">
total_income = total_income + #{pendingIncome},
</if>
<if test="receivedIncome != null">
total_income = total_income + #{receivedIncome},
</if>
pending_income = pending_income + #{pendingIncome},
received_income = received_income + #{receivedIncome},
withdrawn_income = withdrawn_income + #{withdrawIncome}