mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-25 00:15:06 +08:00
【代码优化】商城: 完成代码评审 TODO
This commit is contained in:
@ -1,20 +0,0 @@
|
||||
package cn.iocoder.yudao.module.pay.api.wallet;
|
||||
|
||||
import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletUpdateBalanceReqDTO;
|
||||
|
||||
// TODO @puhui999:不在 MemberUserController 提供接口,而是 PayWalletController 增加。不然 member 耦合 pay 拉。
|
||||
/**
|
||||
* 会员钱包 API 接口
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
public interface PayWalletApi {
|
||||
|
||||
/**
|
||||
* 更新钱包余额
|
||||
*
|
||||
* @param reqDTO 请求
|
||||
*/
|
||||
void updateBalance(PayWalletUpdateBalanceReqDTO reqDTO);
|
||||
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package cn.iocoder.yudao.module.pay.api.wallet.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
// TODO @puhui999:不在 MemberUserController 提供接口,而是 PayWalletController 增加。不然 member 耦合 pay 拉。
|
||||
/**
|
||||
* 钱包余额更新 Request DTO
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Data
|
||||
public class PayWalletUpdateBalanceReqDTO {
|
||||
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 变动余额,正数为增加,负数为减少
|
||||
*/
|
||||
@NotNull(message = "变动余额不能为空")
|
||||
private Integer balance;
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package cn.iocoder.yudao.module.pay.api.wallet;
|
||||
|
||||
import cn.iocoder.yudao.module.pay.api.wallet.dto.PayWalletUpdateBalanceReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
|
||||
import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.enums.UserTypeEnum.MEMBER;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.WALLET_NOT_FOUND;
|
||||
|
||||
// @puhui999:不在 MemberUserController 提供接口,而是 PayWalletController 增加。不然 member 耦合 pay 拉。
|
||||
/**
|
||||
* 会员钱包 API 实现类
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class PayWalletApiImpl implements PayWalletApi {
|
||||
|
||||
@Resource
|
||||
private PayWalletService payWalletService;
|
||||
|
||||
@Override
|
||||
public void updateBalance(PayWalletUpdateBalanceReqDTO reqDTO) {
|
||||
// 获得用户钱包
|
||||
PayWalletDO wallet = payWalletService.getOrCreateWallet(reqDTO.getUserId(), MEMBER.getValue());
|
||||
if (wallet == null) {
|
||||
log.error("[updateBalance],reqDTO({}) 用户钱包不存在.", reqDTO);
|
||||
throw exception(WALLET_NOT_FOUND);
|
||||
}
|
||||
|
||||
// 更新钱包余额
|
||||
payWalletService.addWalletBalance(wallet.getId(), String.valueOf(reqDTO.getUserId()),
|
||||
PayWalletBizTypeEnum.UPDATE_BALANCE, reqDTO.getBalance());
|
||||
}
|
||||
|
||||
}
|
@ -4,9 +4,11 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletPageReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletRespVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletUpdateBalanceReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet.PayWalletUserReqVO;
|
||||
import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletConvert;
|
||||
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
|
||||
import cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@ -15,12 +17,12 @@ import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.enums.UserTypeEnum.MEMBER;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.WALLET_NOT_FOUND;
|
||||
|
||||
@Tag(name = "管理后台 - 用户钱包")
|
||||
@RestController
|
||||
@ -48,6 +50,21 @@ public class PayWalletController {
|
||||
return success(PayWalletConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
// TODO @puhui999:修改钱包余额,权限标识,记得加下噢
|
||||
@PutMapping("/update-balance")
|
||||
@Operation(summary = "更新会员用户余额")
|
||||
@PreAuthorize("@ss.hasPermission('pay:wallet:update-balance')")
|
||||
public CommonResult<Boolean> updateWalletBalance(@Valid @RequestBody PayWalletUpdateBalanceReqVO updateReqVO) {
|
||||
// 获得用户钱包
|
||||
PayWalletDO wallet = payWalletService.getOrCreateWallet(updateReqVO.getUserId(), MEMBER.getValue());
|
||||
if (wallet == null) {
|
||||
log.error("[updateWalletBalance],updateReqVO({}) 用户钱包不存在.", updateReqVO);
|
||||
throw exception(WALLET_NOT_FOUND);
|
||||
}
|
||||
|
||||
// 更新钱包余额
|
||||
payWalletService.addWalletBalance(wallet.getId(), String.valueOf(updateReqVO.getUserId()),
|
||||
PayWalletBizTypeEnum.UPDATE_BALANCE, updateReqVO.getBalance());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package cn.iocoder.yudao.module.pay.controller.admin.wallet.vo.wallet;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 修改钱包余额 Request VO")
|
||||
@Data
|
||||
public class PayWalletUpdateBalanceReqVO {
|
||||
|
||||
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23788")
|
||||
@NotNull(message = "用户编号不能为空")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "变动余额,正数为增加,负数为减少", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
|
||||
@NotNull(message = "变动余额不能为空")
|
||||
private Integer balance;
|
||||
|
||||
}
|
Reference in New Issue
Block a user