xiaoyong931011
2021-03-14 90ebe50085945f76743de252b7875e8f3f088eae
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
package com.matrix.system.fenxiao.action;
 
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.matrix.biz.bean.BizUser;
import com.matrix.biz.dao.BizUserDao;
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.tools.StringUtils;
import com.matrix.core.tools.WebUtil;
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.fenxiao.dao.ShopSalesmanApplyDao;
import com.matrix.system.fenxiao.dao.ShopSalesmanGradeDao;
import com.matrix.system.fenxiao.dto.*;
import com.matrix.system.fenxiao.entity.ShopSalesmanApply;
import com.matrix.system.fenxiao.entity.ShopSalesmanGrade;
import com.matrix.system.fenxiao.service.ShopSalesmanApplyService;
import com.matrix.system.fenxiao.vo.*;
import com.matrix.system.hive.action.util.QueryUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
@RestController
@RequestMapping(value = "/fenXiao/fenXiaoUser")
public class FenXiaoUserAction {
    
    @Autowired
    private ShopSalesmanApplyService shopSalesmanApplyService;
    @Autowired
    private ShopSalesmanApplyDao shopSalesmanApplyDao;
    @Autowired
    private BizUserDao bizUserDao;
    @Autowired
    private ShopSalesmanGradeDao shopSalesmanGradeDao;
    
    /**
     * 分销员详情页面信息
     */
    @ApiOperation(value = "分销员详情页面信息")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK",  response = ShopSalesmanDetailVo.class)
    })
    @PostMapping(value = "/findShopSalesmanDetail")
    public @ResponseBody
    AjaxResult findShopSalesmanDetail(@RequestBody ShopSalesmanDetailDto shopSalesmanDetailDto) {
        //设置用户公司ID
        QueryUtil.setQueryLimitCom(shopSalesmanDetailDto);
        AjaxResult result= AjaxResult.buildSuccessInstance("查询成功");
        //根据OPENID查询基础信息
        String userId = shopSalesmanDetailDto.getUserId();
        String applyId = shopSalesmanDetailDto.getApplyId();
        SalesmanBasicDetailVo salesmanBasicDetailVo = shopSalesmanApplyService.selectShopSalesmanDetailByOpenId(userId,Long.parseLong(applyId));
        result.putInMap("basicdetail", salesmanBasicDetailVo);
        //排序
        if(StringUtils.isBlank(shopSalesmanDetailDto.getSort())){
            shopSalesmanDetailDto.setSort("create_time");
            shopSalesmanDetailDto.setOrder("desc");
        }
        //查询绑定客户信息
        Page<ShopCustomDetailVo> page = new Page(shopSalesmanDetailDto.getPageNum(), shopSalesmanDetailDto.getPageSize());
        IPage<ShopCustomDetailVo> customDetailRows = shopSalesmanApplyService.findCustomDetail(page,shopSalesmanDetailDto);
        result.putInMap("customDetailRecords", customDetailRows.getRecords());
        result.putInMap("customDetailTotal", customDetailRows.getTotal());
        //查询邀请下级信息
        Page<ShopCustomDetailVo> pageLow = new Page(shopSalesmanDetailDto.getPageNum(), shopSalesmanDetailDto.getPageSize());
        IPage<ShopCustomDetailVo> customLowRows = shopSalesmanApplyService.findCustomLow(pageLow,shopSalesmanDetailDto);
        result.putInMap("customLowRecords", customLowRows.getRecords());
        result.putInMap("customLowTotal", customLowRows.getTotal());
        //查询收益订单
        Page<ShopOrderDetailVo> pageOrder = new Page(shopSalesmanDetailDto.getPageNum(), shopSalesmanDetailDto.getPageSize());
        IPage<ShopOrderDetailVo> orderRows = shopSalesmanApplyService.findShopOrderDetail(pageOrder,shopSalesmanDetailDto);
        result.putInMap("orderRecords", orderRows.getRecords());
        result.putInMap("orderTotal", orderRows.getTotal());
        return result;
    }
 
    /**
     *修改等级
     */
    @ApiOperation(value = "修改等级")
    @PostMapping(value = "/changeSaleManGrade")
    public @ResponseBody
    AjaxResult changeSaleManGrade(@RequestBody ChangeSaleManGradeDto changeSaleManGradeDto) {
        return shopSalesmanApplyService.changeSaleManGrade(changeSaleManGradeDto);
    }
    
    /**
     *解绑
     */
    @ApiOperation(value = "解绑")
    @PostMapping(value = "/unbundlingSaleMan")
    public @ResponseBody
    AjaxResult unbundlingSaleMan(@RequestBody UnbundlingSaleManDto unbundlingSaleManDto) {
        return shopSalesmanApplyService.unbundlingSaleMan(unbundlingSaleManDto);
    }
    
    /**
     * 分佣方案
     */
    @ApiOperation(value = "查询分佣方案")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK",  response = FyfaManageVo.class)
    })
    @PostMapping(value = "/findFyfaManageList")
    public @ResponseBody
    AjaxResult findFyfaManageList(@RequestBody FyfaManageDto fyfaManageDto) {
        //设置用户公司ID
        QueryUtil.setQueryLimitCom(fyfaManageDto);
        //排序
        if(StringUtils.isBlank(fyfaManageDto.getSort())){
            fyfaManageDto.setSort("create_time");
            fyfaManageDto.setOrder("asc");
        }
        Page<FyfaManageVo> page = new Page(fyfaManageDto.getPageNum(), fyfaManageDto.getPageSize());
        IPage<FyfaManageVo> rows = shopSalesmanApplyService.findFyfaManageList(page,fyfaManageDto);
        AjaxResult result = AjaxResult.buildSuccessInstance(rows.getRecords(),rows.getTotal());
        return result;
    }
 
    /**
     *新增分佣方案
     */
    @ApiOperation(value = "新增分佣方案")
    @RequestMapping(value = "/addFyfa")
    private @ResponseBody AjaxResult addFyfa(){
        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
        shopSalesmanApplyService.addFyfa(user);
        return AjaxResult.buildSuccessInstance("新增成功");
    }
    
    /**
     *修改分佣方案
     */
    @ApiOperation(value = "修改分佣方案")
    @PostMapping(value = "/updateFyfa")
    public @ResponseBody
    AjaxResult updateFyfa(@RequestBody UpdateFyfaDto updateFyfaDto) {
        return shopSalesmanApplyService.updateFyfa(updateFyfaDto);
    }
    
    /**
     *删除分佣方案
     */
    @ApiOperation(value = "删除分佣方案")
    @PostMapping(value = "/delFyfaApply")
    public @ResponseBody
    AjaxResult delFyfaApply(@RequestBody DelFyfaApplyDto delFyfaApplyDto) {
        return shopSalesmanApplyService.delFyfaApply(delFyfaApplyDto);
    }
 
    /**
     * 查询分销员审核记录
     */
    @ApiOperation(value = "查询分销员审核记录")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK",  response = ShopSalesmanApplyVo.class)
    })
    @PostMapping(value = "/findShopSalesmanApplyList")
    public @ResponseBody
    AjaxResult findShopSalesmanApplyList(@RequestBody ShopSalesmanApplyDto shopSalesmanApplyDto) {
        //设置用户公司ID
        QueryUtil.setQueryLimitCom(shopSalesmanApplyDto);
        //排序
        if(StringUtils.isBlank(shopSalesmanApplyDto.getSort())){
            shopSalesmanApplyDto.setSort("create_time");
            shopSalesmanApplyDto.setOrder("desc");
        }
        Page<ShopSalesmanApplyVo> page = new Page(shopSalesmanApplyDto.getPageNum(), shopSalesmanApplyDto.getPageSize());
        IPage<ShopSalesmanApplyVo> rows = shopSalesmanApplyService.findShopSalesmanApplyList(page,shopSalesmanApplyDto);
        AjaxResult result = AjaxResult.buildSuccessInstance(rows.getRecords(),rows.getTotal());
 
        return result;
    }
    
    /**
     *获取分销员待审核记录
     */
    @ApiOperation(value = "获取分销员待审核记录")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK",  response = ShopSalesmanAppliingVo.class)
    })
    @PostMapping(value = "/findShopSalesmanAppliingList")
    public @ResponseBody
    AjaxResult findShopSalesmanAppliingList(@RequestBody ShopSalesmanAppliingDto shopSalesmanAppliingDto) {
        //设置用户公司ID
        QueryUtil.setQueryLimitCom(shopSalesmanAppliingDto);
        //排序
        if(StringUtils.isBlank(shopSalesmanAppliingDto.getSort())){
            shopSalesmanAppliingDto.setSort("create_time");
            shopSalesmanAppliingDto.setOrder("desc");
        }
 
        Page<ShopSalesmanAppliingVo> page = new Page(shopSalesmanAppliingDto.getPageNum(), shopSalesmanAppliingDto.getPageSize());
        IPage<ShopSalesmanAppliingVo> rows = shopSalesmanApplyService.selectBizUserApplyList(page,shopSalesmanAppliingDto);
 
        //IPage<ShopSalesmanAppliingVo> rows = shopSalesmanApplyService.findShopSalesmanAppliingList(page,shopSalesmanAppliingDto);
        AjaxResult result = AjaxResult.buildSuccessInstance(rows.getRecords(),rows.getTotal());
        return result;
    }
 
    /**
     *新增分销员
     */
    @ApiOperation(value = "新增分销员")
    @PostMapping(value = "/addSaleManApply")
    public @ResponseBody
    AjaxResult addSaleManApply(@RequestBody AddSaleManApplyDto addSaleManApplyDto) {
        String gradeId = addSaleManApplyDto.getGradeId();
        if(StrUtil.isBlankOrUndefined(gradeId)) {
            return AjaxResult.buildSuccessInstance("请选择分销等级");
        }
        ShopSalesmanGrade selectById = shopSalesmanGradeDao.selectById(Long.parseLong(gradeId));
        if(ObjectUtil.isEmpty(selectById)) {
            return AjaxResult.buildSuccessInstance("请选择分销等级");
        }
        
        //设置用户公司ID
        QueryUtil.setQueryLimitCom(addSaleManApplyDto);
 
        shopSalesmanApplyService.addSaleManApply(addSaleManApplyDto.getOpenId(),gradeId);
        return AjaxResult.buildSuccessInstance("设置成功");
    }
    
    /**
     *删除---设置成不是分销员
     */
    @ApiOperation(value = "删除---设置成不是分销员")
    @PostMapping(value = "/delSaleManGradeApply")
    public @ResponseBody
    AjaxResult delSaleManGradeApply(@RequestBody DelSaleManGradeApplyDto delSaleManGradeApplyDto) {
        return shopSalesmanApplyService.delSaleManGradeApply(delSaleManGradeApplyDto);
    }
    
    /**
     *审核分销员
     */
    @ApiOperation(value = "审核分销员")
    @PostMapping(value = "/examineSaleManApply")
    public @ResponseBody
    AjaxResult examineSaleManApply(@RequestBody ExamineSaleManApplyDto examineSaleManApplyDto) {
        //设置用户公司ID
        QueryUtil.setQueryLimitCom(examineSaleManApplyDto);
        String userId = examineSaleManApplyDto.getUserId();
        //待审核状态才允许提交
        ShopSalesmanApply shopSalesmanApply = shopSalesmanApplyDao.selectById(examineSaleManApplyDto.getApplyId());
        if(ObjectUtil.isEmpty(shopSalesmanApply)) {
            return  AjaxResult.buildFailInstance("当前记录有误");
        }
        
        BizUser bizUser = bizUserDao.findByOpenId(userId);
        if(ObjectUtil.isEmpty(bizUser)) {
            return  AjaxResult.buildFailInstance("当前记录有误");
        }
        
        Integer applyStatus = shopSalesmanApply.getApplyStatus();
        if(ObjectUtil.isNotEmpty(applyStatus) && ShopSalesmanApply.APPLY_STATUS_DSH == applyStatus) {
            Integer applyState = examineSaleManApplyDto.getApplyState();
            shopSalesmanApplyService.examineSaleManApply(shopSalesmanApply,applyState);
            return AjaxResult.buildSuccessInstance("审核成功");
        }else{
            return  AjaxResult.buildFailInstance("当前记录不是待审核状态");
        }
    }
 
    /**
     *获取对应的分销员等级
     */
    @RequestMapping(value = "/getShopSalesmanGrade")
    private @ResponseBody AjaxResult getShopSalesmanGradeVo(){
        AjaxResult result= AjaxResult.buildSuccessInstance("查询成功");
        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
 
        List<ShopSalesmanGradeVo> dataList = shopSalesmanApplyService.getShopSalesmanGradeVo(user.getCompanyId());
        result.putInMap("salesGrade", dataList);
        return result;
    }
 
}