mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-04 04:08:43 +08:00 
			
		
		
		
	code review:提现逻辑
This commit is contained in:
		@@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
 | 
			
		||||
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
 | 
			
		||||
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
 | 
			
		||||
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawAuditReqVO;
 | 
			
		||||
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawRejectReqVO;
 | 
			
		||||
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawPageReqVO;
 | 
			
		||||
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawRespVO;
 | 
			
		||||
import cn.iocoder.yudao.module.trade.convert.brokerage.withdraw.BrokerageWithdrawConvert;
 | 
			
		||||
@@ -20,9 +20,7 @@ import org.springframework.web.bind.annotation.*;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Resource;
 | 
			
		||||
import javax.validation.Valid;
 | 
			
		||||
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
 | 
			
		||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 | 
			
		||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
 | 
			
		||||
@@ -40,7 +38,7 @@ public class BrokerageWithdrawController {
 | 
			
		||||
    private MemberUserApi memberUserApi;
 | 
			
		||||
 | 
			
		||||
    @PutMapping("/approve")
 | 
			
		||||
    @Operation(summary = "佣金提现 - 通过申请")
 | 
			
		||||
    @Operation(summary = "通过申请")
 | 
			
		||||
    @PreAuthorize("@ss.hasPermission('trade:brokerage-withdraw:audit')")
 | 
			
		||||
    public CommonResult<Boolean> approveBrokerageWithdraw(@RequestParam("id") Integer id) {
 | 
			
		||||
        brokerageWithdrawService.auditBrokerageWithdraw(id, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS, "");
 | 
			
		||||
@@ -48,9 +46,9 @@ public class BrokerageWithdrawController {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PutMapping("/reject")
 | 
			
		||||
    @Operation(summary = "审核佣金提现 - 驳回申请")
 | 
			
		||||
    @Operation(summary = "驳回申请")
 | 
			
		||||
    @PreAuthorize("@ss.hasPermission('trade:brokerage-withdraw:audit')")
 | 
			
		||||
    public CommonResult<Boolean> rejectBrokerageWithdraw(@Valid @RequestBody BrokerageWithdrawAuditReqVO reqVO) {
 | 
			
		||||
    public CommonResult<Boolean> rejectBrokerageWithdraw(@Valid @RequestBody BrokerageWithdrawRejectReqVO reqVO) {
 | 
			
		||||
        brokerageWithdrawService.auditBrokerageWithdraw(reqVO.getId(), BrokerageWithdrawStatusEnum.AUDIT_FAIL, reqVO.getAuditReason());
 | 
			
		||||
        return success(true);
 | 
			
		||||
    }
 | 
			
		||||
@@ -71,11 +69,9 @@ public class BrokerageWithdrawController {
 | 
			
		||||
        // 分页查询
 | 
			
		||||
        PageResult<BrokerageWithdrawDO> pageResult = brokerageWithdrawService.getBrokerageWithdrawPage(pageVO);
 | 
			
		||||
 | 
			
		||||
        // 涉及到的用户
 | 
			
		||||
        Set<Long> userIds = convertSet(pageResult.getList(), BrokerageWithdrawDO::getUserId);
 | 
			
		||||
        // 查询用户信息
 | 
			
		||||
        Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(userIds);
 | 
			
		||||
 | 
			
		||||
        // 拼接信息
 | 
			
		||||
        Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(
 | 
			
		||||
                convertSet(pageResult.getList(), BrokerageWithdrawDO::getUserId));
 | 
			
		||||
        return success(BrokerageWithdrawConvert.INSTANCE.convertPage(pageResult, userMap));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -39,7 +39,7 @@ public class BrokerageWithdrawBaseVO {
 | 
			
		||||
    @Schema(description = "真实姓名", example = "赵六")
 | 
			
		||||
    private String name;
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "账号")
 | 
			
		||||
    @Schema(description = "账号", example = "88677912132")
 | 
			
		||||
    private String accountNo;
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "银行名称", example = "1")
 | 
			
		||||
 
 | 
			
		||||
@@ -30,7 +30,7 @@ public class BrokerageWithdrawPageReqVO extends PageParam {
 | 
			
		||||
    @Schema(description = "真实姓名", example = "赵六")
 | 
			
		||||
    private String name;
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "账号")
 | 
			
		||||
    @Schema(description = "账号", example = "886779132")
 | 
			
		||||
    private String accountNo;
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "银行名称", example = "1")
 | 
			
		||||
 
 | 
			
		||||
@@ -7,10 +7,10 @@ import lombok.ToString;
 | 
			
		||||
import javax.validation.constraints.NotEmpty;
 | 
			
		||||
import javax.validation.constraints.NotNull;
 | 
			
		||||
 | 
			
		||||
@Schema(description = "管理后台 - 佣金提现审核 Request VO")
 | 
			
		||||
@Schema(description = "管理后台 - 驳回申请 Request VO")
 | 
			
		||||
@Data
 | 
			
		||||
@ToString(callSuper = true)
 | 
			
		||||
public class BrokerageWithdrawAuditReqVO {
 | 
			
		||||
public class BrokerageWithdrawRejectReqVO {
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "7161")
 | 
			
		||||
    @NotNull(message = "编号不能为空")
 | 
			
		||||
@@ -19,7 +19,7 @@ public class BrokerageWithdrawRespVO extends BrokerageWithdrawBaseVO {
 | 
			
		||||
    @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
 | 
			
		||||
    private LocalDateTime createTime;
 | 
			
		||||
 | 
			
		||||
    @Schema(description = "用户昵称")
 | 
			
		||||
    @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
 | 
			
		||||
    private String userNickname;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.trade.convert.brokerage.withdraw;
 | 
			
		||||
 | 
			
		||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
 | 
			
		||||
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
 | 
			
		||||
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawAuditReqVO;
 | 
			
		||||
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawRejectReqVO;
 | 
			
		||||
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawRespVO;
 | 
			
		||||
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.withdraw.BrokerageWithdrawDO;
 | 
			
		||||
import org.mapstruct.Mapper;
 | 
			
		||||
@@ -22,7 +22,7 @@ public interface BrokerageWithdrawConvert {
 | 
			
		||||
 | 
			
		||||
    BrokerageWithdrawConvert INSTANCE = Mappers.getMapper(BrokerageWithdrawConvert.class);
 | 
			
		||||
 | 
			
		||||
    BrokerageWithdrawDO convert(BrokerageWithdrawAuditReqVO bean);
 | 
			
		||||
    BrokerageWithdrawDO convert(BrokerageWithdrawRejectReqVO bean);
 | 
			
		||||
 | 
			
		||||
    BrokerageWithdrawRespVO convert(BrokerageWithdrawDO bean);
 | 
			
		||||
 | 
			
		||||
@@ -33,8 +33,9 @@ public interface BrokerageWithdrawConvert {
 | 
			
		||||
    default PageResult<BrokerageWithdrawRespVO> convertPage(PageResult<BrokerageWithdrawDO> pageResult, Map<Long, MemberUserRespDTO> userMap) {
 | 
			
		||||
        PageResult<BrokerageWithdrawRespVO> result = convertPage(pageResult);
 | 
			
		||||
        for (BrokerageWithdrawRespVO vo : result.getList()) {
 | 
			
		||||
            vo.setUserNickname(Optional.ofNullable(userMap.get(vo.getUserId())).map(MemberUserRespDTO::getNickname).orElse(""));
 | 
			
		||||
            vo.setUserNickname(Optional.ofNullable(userMap.get(vo.getUserId())).map(MemberUserRespDTO::getNickname).orElse(null));
 | 
			
		||||
        }
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -32,18 +32,21 @@ public class BrokerageWithdrawDO extends BaseDO {
 | 
			
		||||
    private Integer id;
 | 
			
		||||
    /**
 | 
			
		||||
     * 用户编号
 | 
			
		||||
     *
 | 
			
		||||
     * 关联 MemberUserDO 的 id 字段
 | 
			
		||||
     */
 | 
			
		||||
    private Long userId;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 提现金额
 | 
			
		||||
     * 提现金额,单位:分
 | 
			
		||||
     */
 | 
			
		||||
    private Integer price;
 | 
			
		||||
    /**
 | 
			
		||||
     * 提现手续费
 | 
			
		||||
     * 提现手续费,单位:分
 | 
			
		||||
     */
 | 
			
		||||
    private Integer feePrice;
 | 
			
		||||
    /**
 | 
			
		||||
     * 当前总佣金
 | 
			
		||||
     * 当前总佣金,单位:分
 | 
			
		||||
     */
 | 
			
		||||
    private Integer totalPrice;
 | 
			
		||||
    /**
 | 
			
		||||
@@ -52,6 +55,7 @@ public class BrokerageWithdrawDO extends BaseDO {
 | 
			
		||||
     * 枚举 {@link BrokerageWithdrawTypeEnum}
 | 
			
		||||
     */
 | 
			
		||||
    private Integer type;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 真实姓名
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -33,4 +33,5 @@ public interface BrokerageWithdrawMapper extends BaseMapperX<BrokerageWithdrawDO
 | 
			
		||||
                .eq(BrokerageWithdrawDO::getId, id)
 | 
			
		||||
                .eq(BrokerageWithdrawDO::getStatus, status));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,9 +5,6 @@ import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.Brok
 | 
			
		||||
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.withdraw.BrokerageWithdrawDO;
 | 
			
		||||
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum;
 | 
			
		||||
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 佣金提现 Service 接口
 | 
			
		||||
 *
 | 
			
		||||
@@ -33,14 +30,6 @@ public interface BrokerageWithdrawService {
 | 
			
		||||
     */
 | 
			
		||||
    BrokerageWithdrawDO getBrokerageWithdraw(Integer id);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获得佣金提现列表
 | 
			
		||||
     *
 | 
			
		||||
     * @param ids 编号
 | 
			
		||||
     * @return 佣金提现列表
 | 
			
		||||
     */
 | 
			
		||||
    List<BrokerageWithdrawDO> getBrokerageWithdrawList(Collection<Integer> ids);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获得佣金提现分页
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
package cn.iocoder.yudao.module.trade.service.brokerage.withdraw;
 | 
			
		||||
 | 
			
		||||
import cn.hutool.core.collection.CollUtil;
 | 
			
		||||
import cn.hutool.core.collection.ListUtil;
 | 
			
		||||
import cn.hutool.core.date.LocalDateTimeUtil;
 | 
			
		||||
import cn.hutool.core.map.MapUtil;
 | 
			
		||||
import cn.hutool.core.util.ObjectUtil;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
 | 
			
		||||
import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
 | 
			
		||||
import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
 | 
			
		||||
@@ -19,8 +18,6 @@ import org.springframework.validation.annotation.Validated;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Resource;
 | 
			
		||||
import java.time.LocalDateTime;
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 | 
			
		||||
@@ -48,15 +45,14 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
 | 
			
		||||
    @Override
 | 
			
		||||
    @Transactional(rollbackFor = Exception.class)
 | 
			
		||||
    public void auditBrokerageWithdraw(Integer id, BrokerageWithdrawStatusEnum status, String auditReason) {
 | 
			
		||||
 | 
			
		||||
        // 校验存在
 | 
			
		||||
        BrokerageWithdrawDO withdrawDO = validateBrokerageWithdrawExists(id);
 | 
			
		||||
        // 校验状态为审核中
 | 
			
		||||
        if (!BrokerageWithdrawStatusEnum.AUDITING.getStatus().equals(withdrawDO.getStatus())) {
 | 
			
		||||
        // 1.1 校验存在
 | 
			
		||||
        BrokerageWithdrawDO withdraw = validateBrokerageWithdrawExists(id);
 | 
			
		||||
        // 1.2 校验状态为审核中
 | 
			
		||||
        if (ObjectUtil.notEqual(BrokerageWithdrawStatusEnum.AUDITING.getStatus(), withdraw.getStatus())) {
 | 
			
		||||
            throw exception(BROKERAGE_WITHDRAW_STATUS_NOT_AUDITING);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 更新
 | 
			
		||||
        // 2. 更新
 | 
			
		||||
        BrokerageWithdrawDO updateObj = new BrokerageWithdrawDO()
 | 
			
		||||
                .setStatus(status.getStatus())
 | 
			
		||||
                .setAuditReason(auditReason)
 | 
			
		||||
@@ -66,33 +62,33 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
 | 
			
		||||
            throw exception(BROKERAGE_WITHDRAW_STATUS_NOT_AUDITING);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 驳回时需要退还用户佣金
 | 
			
		||||
        // 3. 驳回时需要退还用户佣金
 | 
			
		||||
        String templateCode = MessageTemplateConstants.BROKERAGE_WITHDRAW_AUDIT_APPROVE;
 | 
			
		||||
        if (BrokerageWithdrawStatusEnum.AUDIT_FAIL.equals(status)) {
 | 
			
		||||
            templateCode = MessageTemplateConstants.BROKERAGE_WITHDRAW_AUDIT_REJECT;
 | 
			
		||||
 | 
			
		||||
            // todo @owen
 | 
			
		||||
//            brokerageRecordService.addBrokerage(withdrawDO.getUserId(), BrokerageRecordBizTypeEnum.WITHDRAW, withdrawDO.getPrice(), "");
 | 
			
		||||
//            brokerageRecordService.addBrokerage(withdraw.getUserId(), BrokerageRecordBizTypeEnum.WITHDRAW, withdraw.getPrice(), "");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 通知用户
 | 
			
		||||
        // 4. 通知用户
 | 
			
		||||
        Map<String, Object> templateParams = MapUtil.<String, Object>builder()
 | 
			
		||||
                .put("createTime", LocalDateTimeUtil.formatNormal(withdrawDO.getCreateTime()))
 | 
			
		||||
                .put("price", String.format("%.2f", withdrawDO.getPrice() / 100d))
 | 
			
		||||
                .put("reason", withdrawDO.getAuditReason())
 | 
			
		||||
                .put("createTime", LocalDateTimeUtil.formatNormal(withdraw.getCreateTime()))
 | 
			
		||||
                .put("price", String.format("%.2f", withdraw.getPrice() / 100d))
 | 
			
		||||
                .put("reason", withdraw.getAuditReason())
 | 
			
		||||
                .build();
 | 
			
		||||
        NotifySendSingleToUserReqDTO reqDTO = new NotifySendSingleToUserReqDTO()
 | 
			
		||||
                .setUserId(withdrawDO.getUserId())
 | 
			
		||||
                .setUserId(withdraw.getUserId())
 | 
			
		||||
                .setTemplateCode(templateCode).setTemplateParams(templateParams);
 | 
			
		||||
        notifyMessageSendApi.sendSingleMessageToMember(reqDTO);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private BrokerageWithdrawDO validateBrokerageWithdrawExists(Integer id) {
 | 
			
		||||
        BrokerageWithdrawDO withdrawDO = brokerageWithdrawMapper.selectById(id);
 | 
			
		||||
        if (withdrawDO == null) {
 | 
			
		||||
        BrokerageWithdrawDO withdraw = brokerageWithdrawMapper.selectById(id);
 | 
			
		||||
        if (withdraw == null) {
 | 
			
		||||
            throw exception(BROKERAGE_WITHDRAW_NOT_EXISTS);
 | 
			
		||||
        }
 | 
			
		||||
        return withdrawDO;
 | 
			
		||||
        return withdraw;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -100,14 +96,6 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService {
 | 
			
		||||
        return brokerageWithdrawMapper.selectById(id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<BrokerageWithdrawDO> getBrokerageWithdrawList(Collection<Integer> ids) {
 | 
			
		||||
        if (CollUtil.isEmpty(ids)) {
 | 
			
		||||
            return ListUtil.empty();
 | 
			
		||||
        }
 | 
			
		||||
        return brokerageWithdrawMapper.selectBatchIds(ids);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PageResult<BrokerageWithdrawDO> getBrokerageWithdrawPage(BrokerageWithdrawPageReqVO pageReqVO) {
 | 
			
		||||
        return brokerageWithdrawMapper.selectPage(pageReqVO);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user