无关风月
2024-12-25 042fbcd557ef21ab256a542f1fef039269684340
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
package com.jilongda.optometrist.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jilongda.common.basic.ApiResult;
import com.jilongda.common.basic.PageInfo;
import com.jilongda.optometrist.model.TAppUser;
import com.jilongda.optometrist.model.TCouponReceive;
import com.jilongda.optometrist.model.TOptometry;
import com.jilongda.optometrist.model.TOrder;
import com.jilongda.optometrist.query.TAppUserCouponQuery;
import com.jilongda.optometrist.query.TAppUserQuery;
import com.jilongda.optometrist.query.TOptometristQuery;
import com.jilongda.optometrist.service.TAppUserService;
import com.jilongda.optometrist.service.TCouponReceiveService;
import com.jilongda.optometrist.service.TOptometryService;
import com.jilongda.optometrist.service.TOrderService;
import com.jilongda.optometrist.vo.TAppUserCouponVO;
import com.jilongda.optometrist.vo.TAppUserVO;
import com.jilongda.optometrist.vo.TOptometristVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
 
/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author 无关风月
 * @since 2024-12-09
 */
@RestController
@Api(tags = "用户管理")
@RequestMapping("/t-app-user")
public class TAppUserController {
 
    @Resource
    private TAppUserService appUserService;
    @Resource
    private TOrderService orderService;
    @Resource
    private TOptometryService tOptometryService;
    @Resource
    private TCouponReceiveService couponReceiveService;
    @ApiOperation(value = "用户列表")
    @PostMapping(value = "/pageList")
    public ApiResult<PageInfo<TAppUserVO>> pageList(@RequestBody TAppUserQuery query) {
        if (StringUtils.hasLength(query.getStartTime())){
            query.setStartTime(query.getStartTime()+" 00:00:00");
            query.setEndTime(query.getEndTime()+" 23:59:59");
        }
        PageInfo<TAppUserVO> appUserVOPageInfo = appUserService.pageList(query);
        return ApiResult.success(appUserVOPageInfo);
    }
    @ApiOperation(value = "启用/禁用")
    @GetMapping(value = "/updateState")
    public ApiResult updateState(Integer id) {
        TAppUser byId = appUserService.getById(id);
        if (byId.getStatus()==1){
            byId.setStatus(2);
        }else{
            byId.setStatus(1);
        }
        appUserService.updateById(byId);
        return ApiResult.success();
    }
    @ApiOperation(value = "用户详情")
    @GetMapping(value = "/getDetailById")
    public ApiResult<TAppUserVO> getDetailById(Integer id) {
        TAppUser byId = appUserService.getById(id);
        TAppUserVO tAppUserVO = new TAppUserVO();
        BeanUtils.copyProperties(byId, tAppUserVO);
        // 查询消费次数
        long l = orderService.count(new LambdaQueryWrapper<TOrder>()
                .eq(TOrder::getUserId, tAppUserVO.getId()));
        tAppUserVO.setSalesCount((int) l);
        // 查询验光次数
        int size = tOptometryService.lambdaQuery().eq(TOptometry::getUserId, tAppUserVO.getId())
                .eq(TOptometry::getStatus, 3).list().size();
        tAppUserVO.setOptometryCount(size);
        // 查询最后消费时间
        tAppUserVO.setSalesTime(orderService.lambdaQuery().eq(TOrder::getUserId, tAppUserVO.getId())
                .orderByDesc(TOrder::getCreateTime).last("limit 1").one().getCreateTime());
        // 查询最后验光时间
        tAppUserVO.setOptometryTime(tOptometryService.lambdaQuery().eq(TOptometry::getUserId, tAppUserVO.getId())
                .eq(TOptometry::getStatus, 3).orderByDesc(TOptometry::getCreateTime).last("limit 1").one().getCreateTime());
        // 查询订单总额
        BigDecimal reduce = orderService.lambdaQuery().eq(TOrder::getUserId, byId.getId()).list().stream().map(TOrder::getPayMoney)
                .reduce(BigDecimal.ZERO, BigDecimal::add);
        tAppUserVO.setSalesAmount(reduce);
 
        return ApiResult.success(tAppUserVO);
    }
    @ApiOperation(value = "用户详情-查看优惠券")
    @GetMapping(value = "/getCouponDetailById")
    public ApiResult<PageInfo<TAppUserCouponVO>> getCouponDetailById(@RequestBody TAppUserCouponQuery query) {
        PageInfo<TAppUserCouponVO> appUserVOPageInfo = couponReceiveService.pageList(query);
        return ApiResult.success(appUserVOPageInfo);
    }
}