分账提现接口
This commit is contained in:
parent
078b8d1c5d
commit
d8171cfb75
|
|
@ -130,4 +130,12 @@ public class UDistributionController {
|
||||||
return CzgResult.success(distributionUserService.getInviteUser(id, page, size));
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提现记录表 实体类。
|
* 提现记录表 实体类。
|
||||||
|
|
@ -26,6 +27,7 @@ import lombok.NoArgsConstructor;
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Table("mk_distribution_withdraw_flow")
|
@Table("mk_distribution_withdraw_flow")
|
||||||
|
@Accessors(chain = true)
|
||||||
public class MkDistributionWithdrawFlow implements Serializable {
|
public class MkDistributionWithdrawFlow implements Serializable {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
|
|
|
||||||
|
|
@ -116,4 +116,5 @@ public interface MkDistributionUserService extends IService<MkDistributionUser>
|
||||||
|
|
||||||
Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO);
|
Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO);
|
||||||
|
|
||||||
|
Map<String, Object> withdrawDetail(long userId, Long shopId, Long id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
interface DistributionFlow {
|
||||||
@Getter
|
@Getter
|
||||||
enum Status {
|
enum Status {
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
private MkDistributionAmountFlowService distributionAmountFlowService;
|
private MkDistributionAmountFlowService distributionAmountFlowService;
|
||||||
@Resource
|
@Resource
|
||||||
private MkDistributionFlowService distributionFlowService;
|
private MkDistributionFlowService distributionFlowService;
|
||||||
|
@Resource
|
||||||
|
private MkDistributionWithdrawFlowService withdrawFlowService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private AppWxServiceImpl appWxService;
|
private AppWxServiceImpl appWxService;
|
||||||
|
|
@ -447,9 +449,33 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
@Override
|
@Override
|
||||||
public Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO) {
|
public Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO) {
|
||||||
ShopUser shopUserInfo = shopUserService.getShopUserInfo(withdrawFlowDTO.getShopId(), userId);
|
ShopUser shopUserInfo = shopUserService.getShopUserInfo(withdrawFlowDTO.getShopId(), userId);
|
||||||
|
UserInfo userInfo = userInfoService.getById(shopUserInfo.getUserId());
|
||||||
MkDistributionUser distributionUser = getOne(new QueryWrapper().eq(MkDistributionUser::getShopUserId, shopUserInfo.getId()));
|
MkDistributionUser distributionUser = getOne(new QueryWrapper().eq(MkDistributionUser::getShopUserId, shopUserInfo.getId()));
|
||||||
AssertUtil.isNull(distributionUser, "分销员不存在");
|
AssertUtil.isNull(distributionUser, "分销员不存在");
|
||||||
// if (distributionUser.get)
|
if (distributionUser.getReceivedIncome().subtract(withdrawFlowDTO.getAmount()).compareTo(BigDecimal.ZERO) < 0) {
|
||||||
return null;
|
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()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue