门店提现申请接口
This commit is contained in:
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -5,6 +5,7 @@ import com.sczx.store.common.Result;
|
|||||||
import com.sczx.store.dto.BaseWalletChangeDTO;
|
import com.sczx.store.dto.BaseWalletChangeDTO;
|
||||||
import com.sczx.store.dto.BaseWalletDTO;
|
import com.sczx.store.dto.BaseWalletDTO;
|
||||||
import com.sczx.store.dto.WalletChangeQueryReq;
|
import com.sczx.store.dto.WalletChangeQueryReq;
|
||||||
|
import com.sczx.store.dto.WithdrawalReq;
|
||||||
import com.sczx.store.service.IWalletService;
|
import com.sczx.store.service.IWalletService;
|
||||||
import com.sczx.store.util.JwtUtil;
|
import com.sczx.store.util.JwtUtil;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@ -44,4 +45,12 @@ public class WalletController {
|
|||||||
public Result<List<BaseWalletChangeDTO>> listWalletChange(@RequestBody WalletChangeQueryReq baseWalletChangeQueryReq) {
|
public Result<List<BaseWalletChangeDTO>> listWalletChange(@RequestBody WalletChangeQueryReq baseWalletChangeQueryReq) {
|
||||||
return Result.ok(walletService.listWalletChange(baseWalletChangeQueryReq));
|
return Result.ok(walletService.listWalletChange(baseWalletChangeQueryReq));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "门店提现申请", notes = "门店提现申请")
|
||||||
|
@PostMapping("/storeWithdrawal")
|
||||||
|
public Result<Boolean> storeWithdrawal(@RequestBody WithdrawalReq withdrawalReq) {
|
||||||
|
walletService.storeWithdrawal(withdrawalReq);
|
||||||
|
return Result.ok(true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
18
src/main/java/com/sczx/store/dto/WithdrawalReq.java
Normal file
18
src/main/java/com/sczx/store/dto/WithdrawalReq.java
Normal file
@ -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;
|
||||||
|
}
|
||||||
@ -4,6 +4,7 @@ package com.sczx.store.service;
|
|||||||
import com.sczx.store.dto.BaseWalletChangeDTO;
|
import com.sczx.store.dto.BaseWalletChangeDTO;
|
||||||
import com.sczx.store.dto.BaseWalletDTO;
|
import com.sczx.store.dto.BaseWalletDTO;
|
||||||
import com.sczx.store.dto.WalletChangeQueryReq;
|
import com.sczx.store.dto.WalletChangeQueryReq;
|
||||||
|
import com.sczx.store.dto.WithdrawalReq;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -23,4 +24,10 @@ public interface IWalletService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<BaseWalletChangeDTO> listWalletChange(WalletChangeQueryReq baseWalletChangeQueryReq);
|
List<BaseWalletChangeDTO> listWalletChange(WalletChangeQueryReq baseWalletChangeQueryReq);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 门店提现申请
|
||||||
|
* @param withdrawalReq
|
||||||
|
*/
|
||||||
|
void storeWithdrawal(WithdrawalReq withdrawalReq);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,15 @@
|
|||||||
package com.sczx.store.service.impl;
|
package com.sczx.store.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
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.BaseWalletChangeConvert;
|
||||||
import com.sczx.store.convert.BaseWalletConvert;
|
import com.sczx.store.convert.BaseWalletConvert;
|
||||||
import com.sczx.store.dto.BaseWalletChangeDTO;
|
import com.sczx.store.dto.BaseWalletChangeDTO;
|
||||||
import com.sczx.store.dto.BaseWalletDTO;
|
import com.sczx.store.dto.BaseWalletDTO;
|
||||||
import com.sczx.store.dto.WalletChangeQueryReq;
|
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.BaseWalletChangePO;
|
||||||
import com.sczx.store.po.BaseWalletPO;
|
import com.sczx.store.po.BaseWalletPO;
|
||||||
import com.sczx.store.repository.BaseWalletChangeRepo;
|
import com.sczx.store.repository.BaseWalletChangeRepo;
|
||||||
@ -14,8 +18,11 @@ import com.sczx.store.service.IWalletService;
|
|||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class WalletServiceImpl implements IWalletService {
|
public class WalletServiceImpl implements IWalletService {
|
||||||
@ -41,4 +48,32 @@ public class WalletServiceImpl implements IWalletService {
|
|||||||
List<BaseWalletChangePO> baseWalletChangePOList = baseWalletChangeRepo.list(queryWrapper);
|
List<BaseWalletChangePO> baseWalletChangePOList = baseWalletChangeRepo.list(queryWrapper);
|
||||||
return BaseWalletChangeConvert.INSTANCE.pos2Dtos(baseWalletChangePOList);
|
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<BaseWalletPO> 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user