KKSU
2025-01-03 548a01654a5fdb158aa2cca86ae83ffaebbb0395
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package cc.mrbird.febs.mall.service.impl;
 
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.common.enumerates.RunVipMoneyFlowTypeEnum;
import cc.mrbird.febs.common.enumerates.YesOrNoEnum;
import cc.mrbird.febs.common.exception.FebsException;
import cc.mrbird.febs.mall.entity.*;
import cc.mrbird.febs.mall.mapper.*;
import cc.mrbird.febs.mall.service.IAdminRunVipService;
import cc.mrbird.febs.mall.service.IApiMallMemberWalletService;
import cc.mrbird.febs.rabbit.producter.AgentProducer;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.List;
 
@Slf4j
@Service
@RequiredArgsConstructor
@Transactional
public class AdminRunVipServiceImpl extends ServiceImpl<RunVipMapper, RunVip> implements IAdminRunVipService {
 
    private final MallChargeMapper mallChargeMapper;
    private final MallMemberWithdrawMapper mallMemberWithdrawMapper;
    private final MallMoneyFlowMapper mallMoneyFlowMapper;
    private final AgentProducer agentProducer;
    private final IApiMallMemberWalletService walletService;
    private final RunNodeSetMapper runNodeSetMapper;
    @Override
    public IPage<RunVip> runVipListInPage(RunVip runVip,QueryRequest request) {
        Page<RunVip> page = new Page<>(request.getPageNum(), request.getPageSize());
        return this.baseMapper.selectRunVipListInPage(page);
    }
 
    @Override
    public IPage<RunNodeSet> nodeListInPage(RunNodeSet runNodeSet, QueryRequest request) {
        Page<RunNodeSet> page = new Page<>(request.getPageNum(), request.getPageSize());
        return runNodeSetMapper.selectPage(
                page,
                new LambdaQueryWrapper<RunNodeSet>()
                        .orderByAsc(RunNodeSet::getOrderNumber)
        );
    }
 
    @Override
    public void addVip(RunVip config) {
        this.baseMapper.insert(config);
    }
 
    @Override
    public void editVip(RunVip config) {
        this.baseMapper.updateById(config);
    }
 
    @Override
    public IPage<MallCharge> buyList(MallCharge mallCharge, QueryRequest request) {
        Page<MallCharge> page = new Page<>(request.getPageNum(), request.getPageSize());
        IPage<MallCharge> adminChargeListVoIPage = mallChargeMapper.selectAdminChargeListInPage(page, mallCharge);
        return adminChargeListVoIPage;
    }
 
    @Override
    public FebsResponse chargeAgree(Integer state, Long id) {
        MallCharge mallCharge = mallChargeMapper.selectById(id);
 
        if(ObjectUtil.isEmpty(mallCharge)){
            throw new FebsException("记录不存在");
        }
        if(YesOrNoEnum.ING.getValue() != mallCharge.getState()){
            throw new FebsException("记录不是进行中状态");
        }
        if(YesOrNoEnum.YES.getValue() == state){
            mallCharge.setState(YesOrNoEnum.YES.getValue());
        }
        if(YesOrNoEnum.NO.getValue() == state){
            mallCharge.setState(YesOrNoEnum.NO.getValue());
        }
        mallCharge.setRevision(mallCharge.getRevision()+1);
        mallChargeMapper.updateById(mallCharge);
 
        if(mallCharge.getState() == YesOrNoEnum.YES.getValue()){
            agentProducer.sendBuyVipSuccessMsg(mallCharge.getId());
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public FebsResponse sellAgree(Integer state, Long id) {
        MallMemberWithdraw mallMemberWithdraw = mallMemberWithdrawMapper.selectById(id);
        if(ObjectUtil.isEmpty(mallMemberWithdraw)){
            throw new FebsException("记录不存在");
        }
        if(YesOrNoEnum.ING.getValue() != mallMemberWithdraw.getStatus()){
            throw new FebsException("记录不是进行中状态");
        }
        if(YesOrNoEnum.YES.getValue() == state){
            mallMemberWithdraw.setStatus(YesOrNoEnum.YES.getValue());
        }
        if(YesOrNoEnum.NO.getValue() == state){
            mallMemberWithdraw.setStatus(YesOrNoEnum.NO.getValue());
        }
        mallMemberWithdraw.setRevision(mallMemberWithdraw.getRevision()+1);
        mallMemberWithdrawMapper.updateById(mallMemberWithdraw);
 
        MallMoneyFlow mallMoneyFlow = mallMoneyFlowMapper.selectOne(new LambdaQueryWrapper<MallMoneyFlow>().eq(MallMoneyFlow::getOrderNo, mallMemberWithdraw.getWithdrawNo()));
        mallMoneyFlow.setStatus(mallMemberWithdraw.getStatus());
        mallMoneyFlowMapper.updateById(mallMoneyFlow);
        if(mallMemberWithdraw.getStatus() == YesOrNoEnum.NO.getValue()){
            walletService.addCommission(mallMemberWithdraw.getWithdrawTimes(), mallMemberWithdraw.getMemberId());
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public IPage<MallMemberWithdraw> sellList(MallMemberWithdraw mallMemberWithdraw, QueryRequest request) {
        Page<MallMemberWithdraw> page = new Page<>(request.getPageNum(), request.getPageSize());
        IPage<MallMemberWithdraw> adminChargeListVoIPage = mallChargeMapper.selectAdminWithdrawListInPage(page, mallMemberWithdraw);
        return adminChargeListVoIPage;
    }
 
    @Override
    public List<MallMoneyFlow> allMoneyType() {
        List<MallMoneyFlow> mallMoneyFlows = new ArrayList<>();
        RunVipMoneyFlowTypeEnum[] values = RunVipMoneyFlowTypeEnum.values();
        for (RunVipMoneyFlowTypeEnum value : values) {
            MallMoneyFlow mallMoneyFlow = new MallMoneyFlow();
            mallMoneyFlow.setType(value.getValue());
            mallMoneyFlow.setDescription(value.getDescription());
            mallMoneyFlow.setRemark(value.getTypeDec());
            mallMoneyFlows.add(mallMoneyFlow);
        }
 
        return mallMoneyFlows;
    }
 
    @Override
    public void addRunNodeSet(RunNodeSet config) {
        runNodeSetMapper.insert(config);
    }
 
    @Override
    public void editRunNodeSet(RunNodeSet config) {
        runNodeSetMapper.updateById(config);
    }
 
    @Override
    public void deleteNodeById(Long id) {
        runNodeSetMapper.deleteById(id);
    }
}