From 72ccd0cff62d25f52c8e1656ea46829d009b1b18 Mon Sep 17 00:00:00 2001 From: zhangli <123879394@qq.com> Date: Sun, 24 Aug 2025 14:37:32 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=A8=E5=BA=97=E6=8F=90=E7=8E=B0=E7=94=B3?= =?UTF-8?q?=E8=AF=B7=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/enums/WalletChangeTypeEnum.java | 23 ++++++++++++ .../store/controller/WalletController.java | 9 +++++ .../com/sczx/store/dto/WithdrawalReq.java | 18 ++++++++++ .../sczx/store/service/IWalletService.java | 7 ++++ .../store/service/impl/WalletServiceImpl.java | 35 +++++++++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 src/main/java/com/sczx/store/common/enums/WalletChangeTypeEnum.java create mode 100644 src/main/java/com/sczx/store/dto/WithdrawalReq.java diff --git a/src/main/java/com/sczx/store/common/enums/WalletChangeTypeEnum.java b/src/main/java/com/sczx/store/common/enums/WalletChangeTypeEnum.java new file mode 100644 index 0000000..8f23298 --- /dev/null +++ b/src/main/java/com/sczx/store/common/enums/WalletChangeTypeEnum.java @@ -0,0 +1,23 @@ +package com.sczx.store.common.enums; + +import lombok.Getter; + +/** + * 小程序类型枚举 + */ +@Getter +public enum WalletChangeTypeEnum { + REFERRAL("REFERRAL", "引荐"), + WITHDRAWAL("WITHDRAWAL", "提现"); + + private final String code; + + private final String desc; + + + WalletChangeTypeEnum(String code, String desc) { + this.code = code; + this.desc = desc; + } + +} diff --git a/src/main/java/com/sczx/store/controller/WalletController.java b/src/main/java/com/sczx/store/controller/WalletController.java index e5997f8..ed40a0f 100644 --- a/src/main/java/com/sczx/store/controller/WalletController.java +++ b/src/main/java/com/sczx/store/controller/WalletController.java @@ -5,6 +5,7 @@ import com.sczx.store.common.Result; import com.sczx.store.dto.BaseWalletChangeDTO; import com.sczx.store.dto.BaseWalletDTO; import com.sczx.store.dto.WalletChangeQueryReq; +import com.sczx.store.dto.WithdrawalReq; import com.sczx.store.service.IWalletService; import com.sczx.store.util.JwtUtil; import io.swagger.annotations.Api; @@ -44,4 +45,12 @@ public class WalletController { public Result> listWalletChange(@RequestBody WalletChangeQueryReq baseWalletChangeQueryReq) { return Result.ok(walletService.listWalletChange(baseWalletChangeQueryReq)); } + + @ApiOperation(value = "门店提现申请", notes = "门店提现申请") + @PostMapping("/storeWithdrawal") + public Result storeWithdrawal(@RequestBody WithdrawalReq withdrawalReq) { + walletService.storeWithdrawal(withdrawalReq); + return Result.ok(true); + } + } diff --git a/src/main/java/com/sczx/store/dto/WithdrawalReq.java b/src/main/java/com/sczx/store/dto/WithdrawalReq.java new file mode 100644 index 0000000..ed666d0 --- /dev/null +++ b/src/main/java/com/sczx/store/dto/WithdrawalReq.java @@ -0,0 +1,18 @@ +package com.sczx.store.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +@ApiModel(value = "提现请求") +@Data +public class WithdrawalReq { + + @ApiModelProperty("门店id") + private Long storeId; + + @ApiModelProperty("提现金额") + private BigDecimal withdrawalAmount; +} diff --git a/src/main/java/com/sczx/store/service/IWalletService.java b/src/main/java/com/sczx/store/service/IWalletService.java index 94aa1f0..639ac92 100644 --- a/src/main/java/com/sczx/store/service/IWalletService.java +++ b/src/main/java/com/sczx/store/service/IWalletService.java @@ -4,6 +4,7 @@ package com.sczx.store.service; import com.sczx.store.dto.BaseWalletChangeDTO; import com.sczx.store.dto.BaseWalletDTO; import com.sczx.store.dto.WalletChangeQueryReq; +import com.sczx.store.dto.WithdrawalReq; import java.util.List; @@ -23,4 +24,10 @@ public interface IWalletService { * @return */ List listWalletChange(WalletChangeQueryReq baseWalletChangeQueryReq); + + /** + * 门店提现申请 + * @param withdrawalReq + */ + void storeWithdrawal(WithdrawalReq withdrawalReq); } diff --git a/src/main/java/com/sczx/store/service/impl/WalletServiceImpl.java b/src/main/java/com/sczx/store/service/impl/WalletServiceImpl.java index ec43299..1be5427 100644 --- a/src/main/java/com/sczx/store/service/impl/WalletServiceImpl.java +++ b/src/main/java/com/sczx/store/service/impl/WalletServiceImpl.java @@ -1,11 +1,15 @@ package com.sczx.store.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.sczx.store.common.enums.WalletChangeTypeEnum; import com.sczx.store.convert.BaseWalletChangeConvert; import com.sczx.store.convert.BaseWalletConvert; import com.sczx.store.dto.BaseWalletChangeDTO; import com.sczx.store.dto.BaseWalletDTO; import com.sczx.store.dto.WalletChangeQueryReq; +import com.sczx.store.dto.WithdrawalReq; +import com.sczx.store.exception.BizException; import com.sczx.store.po.BaseWalletChangePO; import com.sczx.store.po.BaseWalletPO; import com.sczx.store.repository.BaseWalletChangeRepo; @@ -14,8 +18,11 @@ import com.sczx.store.service.IWalletService; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; import java.util.List; +import java.util.Objects; @Service public class WalletServiceImpl implements IWalletService { @@ -41,4 +48,32 @@ public class WalletServiceImpl implements IWalletService { List baseWalletChangePOList = baseWalletChangeRepo.list(queryWrapper); return BaseWalletChangeConvert.INSTANCE.pos2Dtos(baseWalletChangePOList); } + + @Transactional(rollbackFor = Exception.class) + @Override + public void storeWithdrawal(WithdrawalReq withdrawalReq) { + //先 + BaseWalletPO baseWalletPO = baseWalletRepo.getById(withdrawalReq.getStoreId()); + if(Objects.isNull(baseWalletPO)){ + throw new BizException("门店钱包未创建"); + } + if(baseWalletPO.getAvailableAmount().compareTo(withdrawalReq.getWithdrawalAmount()) < 0){ + throw new BizException("钱包可用余额不足"); + } + //更新钱包信息 + LambdaUpdateWrapper updateWalletWrapper = new LambdaUpdateWrapper<>(); + updateWalletWrapper.eq(BaseWalletPO::getUserId, withdrawalReq.getStoreId()) + .set(BaseWalletPO::getAvailableAmount, baseWalletPO.getAvailableAmount().subtract(withdrawalReq.getWithdrawalAmount())) + .set(BaseWalletPO::getFreezeAmount, baseWalletPO.getFreezeAmount().add(withdrawalReq.getWithdrawalAmount())); + baseWalletRepo.update(updateWalletWrapper); + + //添加钱包变动记录 + BaseWalletChangePO baseWalletChangePO = new BaseWalletChangePO(); + baseWalletChangePO.setUserId(withdrawalReq.getStoreId()); + baseWalletChangePO.setChangeType(WalletChangeTypeEnum.WITHDRAWAL.getCode()); + baseWalletChangePO.setChangeTime(LocalDateTime.now()); + baseWalletChangePO.setChangeAmount(withdrawalReq.getWithdrawalAmount()); + baseWalletChangePO.setChangeStatus("UNREVIEWED"); + baseWalletChangeRepo.save(baseWalletChangePO); + } }