分销修改
This commit is contained in:
parent
ea1c656034
commit
0b6a54b914
|
|
@ -10,6 +10,7 @@ import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -110,4 +111,6 @@ public class UserInfo implements Serializable {
|
||||||
private String realName;
|
private String realName;
|
||||||
private String idCard;
|
private String idCard;
|
||||||
|
|
||||||
|
private BigDecimal distributionAmount;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ import com.czg.account.dto.user.userinfo.UserInfoPwdEditDTO;
|
||||||
import com.czg.account.entity.UserInfo;
|
import com.czg.account.entity.UserInfo;
|
||||||
import com.mybatisflex.core.service.IService;
|
import com.mybatisflex.core.service.IService;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务层。
|
* 服务层。
|
||||||
*
|
*
|
||||||
|
|
@ -22,4 +24,7 @@ public interface UserInfoService extends IService<UserInfo> {
|
||||||
Boolean updatePwd(long userId, UserInfoPwdEditDTO userInfoPwdEditDTO);
|
Boolean updatePwd(long userId, UserInfoPwdEditDTO userInfoPwdEditDTO);
|
||||||
|
|
||||||
Boolean getCode(Long userId, String type);
|
Boolean getCode(Long userId, String type);
|
||||||
|
|
||||||
|
void updateDistributionAmount(long userId, BigDecimal amount);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,6 @@ import lombok.NoArgsConstructor;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
public class MkDistributionWithdrawFlowDTO implements Serializable {
|
public class MkDistributionWithdrawFlowDTO implements Serializable {
|
||||||
@NotNull
|
|
||||||
private Long shopId;
|
|
||||||
@NotNull(message = "提现金额不为空")
|
@NotNull(message = "提现金额不为空")
|
||||||
@DecimalMin(value = "30", message = "提现金额不能小于30")
|
@DecimalMin(value = "30", message = "提现金额不能小于30")
|
||||||
private BigDecimal amount;
|
private BigDecimal amount;
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,6 @@ public class MkDistributionWithdrawFlow implements Serializable {
|
||||||
@Id(keyType = KeyType.Auto)
|
@Id(keyType = KeyType.Auto)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
|
||||||
* 店铺id
|
|
||||||
*/
|
|
||||||
private Long shopId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 店铺用户id
|
* 店铺用户id
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,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);
|
void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId);
|
||||||
|
|
||||||
|
|
||||||
Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO);
|
Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@ package com.czg.service.account.mapper;
|
||||||
|
|
||||||
import com.czg.account.entity.UserInfo;
|
import com.czg.account.entity.UserInfo;
|
||||||
import com.mybatisflex.core.BaseMapper;
|
import com.mybatisflex.core.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 映射层。
|
* 映射层。
|
||||||
|
|
@ -11,4 +14,5 @@ import com.mybatisflex.core.BaseMapper;
|
||||||
*/
|
*/
|
||||||
public interface UserInfoMapper extends BaseMapper<UserInfo> {
|
public interface UserInfoMapper extends BaseMapper<UserInfo> {
|
||||||
|
|
||||||
|
boolean updateAmount(long userId, BigDecimal amount);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,8 @@
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.czg.service.account.mapper.UserInfoMapper">
|
<mapper namespace="com.czg.service.account.mapper.UserInfoMapper">
|
||||||
|
|
||||||
|
<update id="updateAmount">
|
||||||
|
update tb_user_info set distribution_amount = distribution_amount + #{amount} where id = #{id}
|
||||||
|
and distribution_amount + #{amount} >= 0
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
|
|
@ -481,8 +481,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
.setRewardAmount(rewardAmount).setBillNo(IdUtil.simpleUUID());
|
.setRewardAmount(rewardAmount).setBillNo(IdUtil.simpleUUID());
|
||||||
distributionFlowService.save(mkDistributionFlow);
|
distributionFlowService.save(mkDistributionFlow);
|
||||||
|
|
||||||
|
ShopUser shopUser = shopUserService.getById(distributionUser.getId());
|
||||||
updateIncome(!flag ? rewardAmount : BigDecimal.ZERO,
|
updateIncome(!flag ? rewardAmount : BigDecimal.ZERO,
|
||||||
flag ? rewardAmount : BigDecimal.ZERO, BigDecimal.ZERO, distributionUser.getId());
|
flag ? rewardAmount : BigDecimal.ZERO, BigDecimal.ZERO, distributionUser.getId(), shopUser.getUserId());
|
||||||
|
|
||||||
if (flag) {
|
if (flag) {
|
||||||
distributionAmountFlowService.save(new MkDistributionAmountFlow()
|
distributionAmountFlowService.save(new MkDistributionAmountFlow()
|
||||||
|
|
@ -511,26 +512,27 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id) {
|
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);
|
boolean flag = mapper.updateIncome(pendingIncome, receivedIncome, withdrawIncome, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO) {
|
public Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO) {
|
||||||
ShopUser shopUserInfo = shopUserService.getShopUserInfo(withdrawFlowDTO.getShopId(), userId);
|
UserInfo userInfo = userInfoService.getById(userId);
|
||||||
UserInfo userInfo = userInfoService.getById(shopUserInfo.getUserId());
|
if (userInfo.getDistributionAmount().subtract(withdrawFlowDTO.getAmount()).compareTo(BigDecimal.ZERO) < 0) {
|
||||||
MkDistributionUser distributionUser = getOne(new QueryWrapper().eq(MkDistributionUser::getId, shopUserInfo.getId()));
|
|
||||||
AssertUtil.isNull(distributionUser, "分销员不存在");
|
|
||||||
if (distributionUser.getReceivedIncome().subtract(withdrawFlowDTO.getAmount()).compareTo(BigDecimal.ZERO) < 0) {
|
|
||||||
throw new CzgException("可提现金额不足");
|
throw new CzgException("可提现金额不足");
|
||||||
}
|
}
|
||||||
|
|
||||||
BigDecimal fee = withdrawFlowDTO.getAmount().multiply(BigDecimal.valueOf(0.08));
|
BigDecimal fee = withdrawFlowDTO.getAmount().multiply(BigDecimal.valueOf(0.08));
|
||||||
BigDecimal finalAmount = withdrawFlowDTO.getAmount().subtract(fee);
|
BigDecimal finalAmount = withdrawFlowDTO.getAmount().subtract(fee);
|
||||||
|
|
||||||
MkDistributionWithdrawFlow withdrawFlow = new MkDistributionWithdrawFlow().setShopId(withdrawFlowDTO.getShopId()).setUserId(userId)
|
MkDistributionWithdrawFlow withdrawFlow = new MkDistributionWithdrawFlow().setUserId(userId)
|
||||||
.setAmount(finalAmount).setServiceFee(fee).setBillNo(IdUtil.simpleUUID()).setStatus(TableValueConstant.DistributionWithdrawFlow.Status.PENDING.getCode());
|
.setAmount(finalAmount).setServiceFee(fee).setBillNo(IdUtil.simpleUUID()).setStatus(TableValueConstant.DistributionWithdrawFlow.Status.PENDING.getCode());
|
||||||
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, withdrawFlow.getAmount().negate());
|
||||||
return withdrawFlowService.save(withdrawFlow);
|
return withdrawFlowService.save(withdrawFlow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue