分账提现接口

This commit is contained in:
张松 2025-10-27 20:38:06 +08:00
parent 078b8d1c5d
commit d8171cfb75
5 changed files with 58 additions and 2 deletions

View File

@ -130,4 +130,12 @@ public class UDistributionController {
return CzgResult.success(distributionUserService.getInviteUser(id, page, size));
}
/**
* 提现详情
*/
@PostMapping("/withdraw/detail")
public CzgResult<Map<String, Object>> withdraw(@RequestParam Long id, @RequestParam Long shopId) {
return CzgResult.success(distributionUserService.withdrawDetail(StpKit.USER.getLoginIdAsLong(), shopId, id));
}
}

View File

@ -14,6 +14,7 @@ import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
/**
* 提现记录表 实体类
@ -26,6 +27,7 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@AllArgsConstructor
@Table("mk_distribution_withdraw_flow")
@Accessors(chain = true)
public class MkDistributionWithdrawFlow implements Serializable {
@Serial

View File

@ -116,4 +116,5 @@ public interface MkDistributionUserService extends IService<MkDistributionUser>
Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO);
Map<String, Object> withdrawDetail(long userId, Long shopId, Long id);
}

View File

@ -60,6 +60,25 @@ public interface TableValueConstant {
}
interface DistributionWithdrawFlow {
@Getter
enum Status {
PENDING("pending", "提现中"),
SUB("sub", "系统扣减"),
OPEN("open", "分销员购买"),
FINISH("finish", "已提现"),
SELF_RECHARGE("self_recharge", "自助充值");
private final String code;
private final String msg;
Status(String code, String msg) {
this.code = code;
this.msg = msg;
}
}
}
interface DistributionFlow {
@Getter
enum Status {

View File

@ -75,6 +75,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
private MkDistributionAmountFlowService distributionAmountFlowService;
@Resource
private MkDistributionFlowService distributionFlowService;
@Resource
private MkDistributionWithdrawFlowService withdrawFlowService;
@Resource
private AppWxServiceImpl appWxService;
@ -447,9 +449,33 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
@Override
public Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO) {
ShopUser shopUserInfo = shopUserService.getShopUserInfo(withdrawFlowDTO.getShopId(), userId);
UserInfo userInfo = userInfoService.getById(shopUserInfo.getUserId());
MkDistributionUser distributionUser = getOne(new QueryWrapper().eq(MkDistributionUser::getShopUserId, shopUserInfo.getId()));
AssertUtil.isNull(distributionUser, "分销员不存在");
// if (distributionUser.get)
return null;
if (distributionUser.getReceivedIncome().subtract(withdrawFlowDTO.getAmount()).compareTo(BigDecimal.ZERO) < 0) {
throw new CzgException("可提现金额不足");
}
BigDecimal fee = withdrawFlowDTO.getAmount().multiply(BigDecimal.valueOf(0.08));
BigDecimal finalAmount = withdrawFlowDTO.getAmount().subtract(fee);
MkDistributionWithdrawFlow withdrawFlow = new MkDistributionWithdrawFlow().setShopId(withdrawFlowDTO.getShopId()).setShopUserId(shopUserInfo.getId())
.setAmount(finalAmount).setServiceFee(fee).setBillNo(IdUtil.simpleUUID()).setStatus(TableValueConstant.DistributionWithdrawFlow.Status.PENDING.getCode());
JSONObject jsonObject = appWxService.transferBalance(userInfo.getWechatOpenId(), userInfo.getRealName(), finalAmount, "提现", withdrawFlow.getBillNo());
withdrawFlow.setPackageInfo(jsonObject.getString("package_info"));
return withdrawFlowService.save(withdrawFlow);
}
@Override
public Map<String, Object> withdrawDetail(long userId, Long shopId, Long id) {
ShopUser shopUserInfo = shopUserService.getShopUserInfo(shopId, userId);
MkDistributionWithdrawFlow flow = withdrawFlowService.getOne(new QueryWrapper().eq(MkDistributionWithdrawFlow::getId, id).eq(MkDistributionWithdrawFlow::getShopUserId, shopUserInfo.getId()));
AssertUtil.isNull(flow, "提现记录不存在");
AssertUtil.isTrue(TableValueConstant.DistributionWithdrawFlow.Status.FINISH.getCode().equals(flow.getStatus()), "已经提现");
return Map.of(
"mchId", appWxService.config.mchId,
"appId", appWxService.config.appId,
"package", flow.getPackageInfo()
);
}
}