无关风月
21 小时以前 7cab5bda99ca42188bc15b2dae7d1fa4d1833fd9
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
package com.ruoyi.admin.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.admin.entity.Franchisee;
import com.ruoyi.admin.entity.User;
import com.ruoyi.admin.service.FranchiseeService;
import com.ruoyi.admin.service.UserService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.exception.GlobalException;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.annotation.Logical;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.order.api.entity.EvaluatePageVO;
import com.ruoyi.order.api.entity.Order;
import com.ruoyi.order.api.entity.UserWithdrawRecordVO;
import com.ruoyi.order.api.entity.WithdrawalSetting;
import com.ruoyi.order.api.feignClient.EvaluateClient;
import com.ruoyi.order.api.feignClient.OrderClient;
import com.ruoyi.order.api.feignClient.WithdrawClient;
import com.ruoyi.system.api.model.LoginUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * @author HJL
 * @version 1.0
 * @since 2024-05-29 17:51
 */
@RestController
@RequestMapping("/userManage")
@Api(tags = {"后台-用户管理-用户列表"})
public class UserManageController {
 
    @Resource
    private UserService userService;
    @Resource
    private OrderClient orderClient;
    @Resource
    private EvaluateClient evaluateClient;
    @Resource
    private WithdrawClient withdrawClient;
    @Resource
    private TokenService tokenService;
 
    /**
     * 用户信息分页列表
     *
     * @param pageNum  页码
     * @param pageSize 每页显示条数
     */
    @RequiresPermissions("user_list")
    @ApiOperation(value = "用户管理-用户分页列表", tags = {"后台-用户管理-用户列表"})
    @GetMapping(value = "/page")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户昵称", name = "nickname", dataType = "String"),
            @ApiImplicitParam(value = "手机号", name = "phone", dataType = "String"),
            @ApiImplicitParam(value = "状态", name = "state", dataType = "Integer"),
            @ApiImplicitParam(value = "页码", name = "pageNum", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", dataType = "Integer", required = true)
    })
    public R<IPage<User>> queryPageList(String nickname, String phone, Integer state,
                                        @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        LambdaQueryChainWrapper<User> query = userService.lambdaQuery();
        // 穆湖匹配规则
        query = StringUtils.isNotBlank(nickname) ? query.like(User::getNickname, nickname) : query;
        query = StringUtils.isNotBlank(phone) ? query.like(User::getPhone, phone) : query;
        // 账号是否启用
        query = null != state ? query.eq(User::getState, state) : query;
        return R.ok(query.orderByDesc(User::getCreateTime).eq(User::getIsDelete, 0)
                .orderByDesc(User::getCreateTime).page(Page.of(pageNum, pageSize)));
    }
 
    /**
     * 前台用户详情
     *
     * @param id 前台用户id
     */
    @RequiresPermissions("user_detail")
    @ApiOperation(value = "用户管理-用户详情", tags = {"后台-用户管理-用户列表"})
    @GetMapping(value = "/detail")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "前台用户id", name = "id", dataType = "Integer", required = true)
    })
    public R<User> detail(@RequestParam Integer id) {
        return R.ok(userService.getById(id));
    }
 
    /**
     * 根据id批量删除前台用户
     *
     * @param ids 前台用户多条id拼接
     */
    @RequiresPermissions("user_delete")
    @ApiOperation(value = "用户管理-批量删除用户", tags = {"后台-用户管理-用户列表"})
    @GetMapping(value = "/batchDelete")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "多条前台用户id ',' 拼接", name = "ids", dataType = "String", required = true)
    })
    public R<String> batchDelete(@RequestParam String ids) {
        List<String> idList = Arrays.stream(ids.split(",")).collect(Collectors.toList());
        List<User> list = userService.lambdaQuery().in(User::getId, idList).list();
        list.forEach(data -> data.setIsDelete(1));
        return userService.updateBatchById(list) ? R.ok() : R.fail();
    }
 
    @Resource
    private FranchiseeService franchiseeService;
    /**
     * 用户所关联订单记录分页列表
     *
     * @param userId   手机号
     * @param pageNum  页码
     * @param pageSize 每页显示条数
     * @return 分页列表
     */
    @RequiresPermissions("user_detail")
    @ApiOperation(value = "用户详情-订单记录分页列表", tags = {"后台-用户管理-用户列表"})
    @GetMapping(value = "/orderList")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户id", name = "userId", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "页码", name = "pageNum", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", dataType = "Integer", required = true)
    })
    public R<IPage<Order>> orderList(@RequestParam("userId") Integer userId,
                                     @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                     @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        LoginUser loginUser = tokenService.getLoginUser();
        if (null == loginUser) {
            return R.loginExpire("登录失效!");
        }
 
        List<String> cityList= new ArrayList<>();
        if (loginUser.getCityList()!=null) {
            cityList = loginUser.getCityList();
        }
        Integer franchiseeId = loginUser.getSysUser().getFranchiseeId();
        String[] siteIds = new String[0];
        if (franchiseeId!=null){
        Franchisee byId = franchiseeService.getById(franchiseeId);
        siteIds = byId.getSiteIds().split(",");
        if (loginUser.getIsFranchisee()&&siteIds.length==0){
            return R.ok();
        }
        }
 
 
        R<Page<Order>> iPageR = orderClient.orderList1(userId,cityList, pageNum, pageSize, Arrays.asList(siteIds));
        Page<Order> data = iPageR.getData();
 
            List<Order> records = data.getRecords();
            if (!records.isEmpty()) {
                for (Order record : records) {
                    if (record.getAddress() != null) {
                        record.setReservationAddress(record.getReservationAddress() + record.getAddress());
                    }
 
                }
            }
 
        return R.ok(data);
    }
 
 
    @ApiOperation(value = "师傅订单详情", tags = {"后台-师傅管理-师傅列表管理"})
    @GetMapping(value = "/workOrderList")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户id", name = "workId", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "页码", name = "pageNum", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", dataType = "Integer", required = true)
    })
    public R<IPage<Order>> workOrderList(@RequestParam("workId") Integer workId,
                                     @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                     @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        LoginUser loginUser = tokenService.getLoginUser();
        if (null == loginUser) {
            return R.loginExpire("登录失效!");
        }
 
        Integer franchiseeId = loginUser.getSysUser().getFranchiseeId();
        String [] siteIds = new String[0];
        if (franchiseeId!=null) {
            Franchisee byId = franchiseeService.getById(franchiseeId);
            siteIds = byId.getSiteIds().split(",");
            if (loginUser.getIsFranchisee() && siteIds.length == 0) {
                return R.ok(new Page<Order>());
            }
        }
        R<Page<Order>> iPageR = orderClient.workOrderList(workId, pageNum, pageSize,siteIds);
        Page<Order> data = iPageR.getData();
        List<Order> records = data.getRecords();
        for (Order record : records) {
            if (record.getAddress()!=null) {
                record.setReservationAddress(record.getReservationAddress() + record.getAddress());
            }
        }
        return R.ok(data);
    }
 
    /**
     * 用户所关联评价记录分页列表
     *
     * @param userId   用户id
     * @param pageNum  页码
     * @param pageSize 每页显示条数
     * @return 分页列表
     */
    @RequiresPermissions("user_detail")
    @ApiOperation(value = "用户详情-评价记录分页列表", tags = {"后台-用户管理-用户列表"})
    @GetMapping(value = "/evaluateList")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户id", name = "userId", dataType = "Integer"),
            @ApiImplicitParam(value = "页码", name = "pageNum", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", dataType = "Integer", required = true)
    })
    public R<Page<EvaluatePageVO>> evaluateList(Integer userId,
                                                @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        LoginUser loginUser = tokenService.getLoginUser();
        List<String> cityList = loginUser.getCityList();
        Integer franchiseeId = loginUser.getSysUser().getFranchiseeId();
        String[] siteIds = new String[0];
        if (franchiseeId!=null) {
            Franchisee byId = franchiseeService.getById(franchiseeId);
            siteIds  = byId.getSiteIds().split(",");
            if (loginUser.getIsFranchisee() && siteIds.length == 0) {
                return R.ok(new Page<>());
            }
        }
        return evaluateClient.evaluateList1(cityList,userId, pageNum, pageSize,Arrays.asList(siteIds));
    }
 
    /**
     * 删除评价记录
     *
     * @param id 评价记录id
     */
    @RequiresPermissions("user_detail")
    @ApiOperation(value = "用户详情-删除评价记录", tags = {"后台-用户管理-用户列表"})
    @GetMapping(value = "/deleteEvaluateRecord")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "评价记录id", name = "id", dataType = "Integer", required = true)
    })
    public R<String> deleteEvaluateRecord(@RequestParam Long id) {
        return evaluateClient.batchDelete(String.valueOf(id));
    }
 
    /**
     * 修改系统设置-关闭/开启审核
     *
     * @return 操作结果
     */
    @RequiresPermissions("user_withdrawal_setting")
    @ApiOperation(value = "关闭/开启审核", tags = {"后台-用户管理-用户列表"})
    @GetMapping(value = "/enableProcess")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "审核状态(0:未开启,1:已开启)", name = "enableProcess", dataType = "Integer", required = true)
    })
    public R<Boolean> enableProcess(@RequestParam("enableProcess") Integer enableProcess) {
        return withdrawClient.enableProcess(enableProcess);
    }
 
    /**
     * 获取系统设置-审核设置
     * --远程调用
     *
     * @return 操作结果
     */
    @GetMapping(value = "/withdrawProcess")
    public R<WithdrawalSetting> withdrawProcess() {
        return withdrawClient.withdrawProcess();
    }
 
    /**
     * 全局审核状态
     */
    @ApiOperation(value = "全局审核状态", tags = {"后台-用户管理-用户列表"})
    @GetMapping(value = "/withdrawState")
    public R<WithdrawalSetting> withdrawState() {
        return withdrawClient.withdrawProcess();
    }
 
    /**
     * 用户所关联提现记录分页列表
     *
     * @param userId   用户id
     * @param pageNum  页码
     * @param pageSize 每页显示条数
     * @return 分页列表
     */
    @RequiresPermissions("user_detail")
    @ApiOperation(value = "用户详情-提现记录分页列表", tags = {"后台-用户管理-用户列表"})
    @GetMapping(value = "/withdrawList")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户id", name = "userId", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "页码", name = "pageNum", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", dataType = "Integer", required = true)
    })
    public R<Page<UserWithdrawRecordVO>> withdrawList(@RequestParam Integer userId,
                                                      @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        LoginUser loginUser = tokenService.getLoginUser();
        List<String> cityList = new ArrayList<>();
        if (loginUser.getCityList()!=null) {
          cityList = loginUser.getCityList();
        }
        Integer franchiseeId = loginUser.getSysUser().getFranchiseeId();
        String[] siteIds = new String[0];
        if (franchiseeId!=null){
            Franchisee byId = franchiseeService.getById(franchiseeId);
            siteIds = byId.getSiteIds().split(",");
            if (loginUser.getIsFranchisee()&&siteIds.length==0){
                return R.ok();
            }
        }
 
        return withdrawClient.withdrawList1(cityList,userId, pageNum, pageSize,Arrays.asList(siteIds));
    }
 
    /**
     * 删除提现记录
     *
     * @param id 提现记录id
     */
    @RequiresPermissions(value = {"user_detail", "user_withdrawal_delete"}, logical = Logical.OR)
    @ApiOperation(value = "用户详情/用户提现管理-删除提现记录", tags = {"后台-用户管理-用户列表"})
    @GetMapping(value = "/deleteWithdrawRecord")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "提现记录id", name = "id", dataType = "Integer", required = true)
    })
    public R<String> deleteWithdrawRecord(@RequestParam Long id) {
        return withdrawClient.batchDelete(String.valueOf(id));
    }
 
    /**
     * 用户所关联提现记录分页列表
     *
     * @param id      提现记录id
     * @param state   审批结果
     * @param opinion 审批意见
     */
    @RequiresPermissions(value = {"user_detail", "user_withdrawal_audit"}, logical = Logical.OR)
    @ApiOperation(value = "用户详情/用户提现管理-提现审批", tags = {"后台-用户管理-用户列表"})
    @GetMapping(value = "/withdrawExamine")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "提现记录id", name = "id", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "审批意见", name = "opinion", dataType = "String"),
            @ApiImplicitParam(value = "审批同意/不同意(1同意;2驳回)", name = "state", dataType = "Integer", required = true)
    })
    public R<String> withdrawExamine(@RequestParam Long id, @RequestParam Integer state, String opinion) {
        com.ruoyi.order.api.entity.Withdraw withdraw = withdrawClient.withdrawRecordDetail(id).getData();
        if (null == withdraw) {
            throw new GlobalException("提现记录不存在或已删除!");
        }
        User user = userService.lambdaQuery()
                .eq(User::getId, withdraw.getUserId())
                .eq(User::getIsDelete, 0).one();
        if (null == user) {
            throw new GlobalException("提交申请的用户信息不存在!");
        }
        Boolean data = withdrawClient.withdrawExamine(id, state, opinion, user.getOpenId(), user.getId()).getData();
        if (null != data) {
            return data ? R.ok(null, "审批成功!") : R.fail("审批失败!");
        } else {
            return R.fail("审批失败!");
        }
    }
 
}