分销金额

This commit is contained in:
张松
2025-10-29 19:06:42 +08:00
parent c027336989
commit 3820d86c8a
10 changed files with 36 additions and 16 deletions

View File

@@ -6,6 +6,7 @@ import com.czg.market.vo.InviteUserVO;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService; import com.mybatisflex.core.service.IService;
import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List; import java.util.List;
@@ -34,4 +35,6 @@ public interface ShopUserService extends IService<ShopUser> {
boolean updateInfo(ShopUser shopUser); boolean updateInfo(ShopUser 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);
} }

View File

@@ -25,6 +25,6 @@ public interface UserInfoService extends IService<UserInfo> {
Boolean getCode(Long userId, String type); Boolean getCode(Long userId, String type);
void updateDistributionAmount(long userId, BigDecimal amount, Integer isOne); void updateDistributionAmount(long userId, BigDecimal amount);
} }

View File

@@ -125,7 +125,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, Integer isOne); void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId, Long shopId, Integer isOne);
Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO); Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO);

View File

@@ -71,4 +71,7 @@ public interface ShopUserMapper extends BaseMapper<ShopUser> {
* @return 分页结果 * @return 分页结果
*/ */
List<InviteUserVO> getInviteUser(Long distributionUserId, Long shopUserId); List<InviteUserVO> getInviteUser(Long distributionUserId, Long shopUserId);
void updateOneOrTwoAmount(Long userId, Long mainShopId, BigDecimal bigDecimal, Integer isOne);
} }

View File

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

View File

@@ -169,4 +169,9 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
return list(queryWrapper); return list(queryWrapper);
} }
@Override
public void updateOneOrTwoAmount(Long userId, Long mainShopId, BigDecimal bigDecimal, Integer isOne) {
mapper.updateOneOrTwoAmount(userId, mainShopId, bigDecimal, isOne);
}
} }

View File

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

View File

@@ -17,6 +17,20 @@
where id = #{id} where id = #{id}
and amount - #{money} >= 0 and amount - #{money} >= 0
</update> </update>
<update id="updateOneOrTwoAmount">
update tb_shop_user
<set>
<if test="isOne != null and isOne == 1">
one_income = one_income + #{amount}
</if>
<if test="isOne != null and isOne == 2">
two_income = two_income + #{amount}
</if>
</set>
where user_id = #{userId}
and shop_id = #{shopId}
</update>
<select id="selectUserSummary" resultType="com.czg.account.dto.shopuser.ShopUserSummaryDTO"> <select id="selectUserSummary" resultType="com.czg.account.dto.shopuser.ShopUserSummaryDTO">

View File

@@ -8,12 +8,6 @@
update tb_user_info update tb_user_info
<set> <set>
distribution_amount = distribution_amount + #{amount} distribution_amount = distribution_amount + #{amount}
<if test="isOne != null and isOne == 1">
, one_income = one_income + #{amount}
</if>
<if test="isOne != null and isOne == 2">
, two_income = two_income + #{amount}
</if>
</set> </set>
where id = #{userId} where id = #{userId}
and distribution_amount + #{amount} >= 0 and distribution_amount + #{amount} >= 0

View File

@@ -618,7 +618,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
distributionFlowService.save(mkDistributionFlow); distributionFlowService.save(mkDistributionFlow);
updateIncome(!flag ? rewardAmount : BigDecimal.ZERO, updateIncome(!flag ? rewardAmount : BigDecimal.ZERO,
flag ? rewardAmount : BigDecimal.ZERO, BigDecimal.ZERO, distributionUser.getId(), shopUser.getUserId(), currentLevel == 1 ? 1 : 2); flag ? rewardAmount : BigDecimal.ZERO, BigDecimal.ZERO, distributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
if (flag) { if (flag) {
distributionAmountFlowService.save(new MkDistributionAmountFlow() distributionAmountFlowService.save(new MkDistributionAmountFlow()
@@ -649,8 +649,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
} }
@Override @Override
public void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId, Integer isOne) { public void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId, Long mainShopId, Integer isOne) {
userInfoService.updateDistributionAmount(userId, receivedIncome, isOne); shopUserService.updateOneOrTwoAmount(userId, mainShopId, receivedIncome == null ? pendingIncome : receivedIncome, isOne);
userInfoService.updateDistributionAmount(userId, receivedIncome);
boolean flag = mapper.updateIncome(pendingIncome, receivedIncome, withdrawIncome, id); boolean flag = mapper.updateIncome(pendingIncome, receivedIncome, withdrawIncome, id);
if (!flag) { if (!flag) {
throw new CzgException("操作失败"); throw new CzgException("操作失败");
@@ -676,7 +677,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
JSONObject jsonObject = appWxService.transferBalance(userInfo.getWechatOpenId(), userInfo.getRealName(), finalAmount, "提现", withdrawFlow.getBillNo()); JSONObject jsonObject = appWxService.transferBalance(userInfo.getWechatOpenId(), userInfo.getRealName(), finalAmount, "提现", withdrawFlow.getBillNo());
withdrawFlow.setPackageInfo(jsonObject.getString("package_info")); withdrawFlow.setPackageInfo(jsonObject.getString("package_info"));
// 扣减余额 // 扣减余额
userInfoService.updateDistributionAmount(userId, withdrawFlowDTO.getAmount().negate(), null); userInfoService.updateDistributionAmount(userId, withdrawFlowDTO.getAmount().negate());
return withdrawFlowService.save(withdrawFlow); return withdrawFlowService.save(withdrawFlow);
} }
@@ -707,7 +708,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
case "CANCELLED": case "CANCELLED":
flow.setStatus(TableValueConstant.DistributionWithdrawFlow.Status.FAIL.getCode()); flow.setStatus(TableValueConstant.DistributionWithdrawFlow.Status.FAIL.getCode());
// 扣减余额 // 扣减余额
userInfoService.updateDistributionAmount(flow.getUserId(), flow.getAmount().add(flow.getServiceFee()), null); userInfoService.updateDistributionAmount(flow.getUserId(), flow.getAmount().add(flow.getServiceFee()));
break; break;
} }