44323
2024-04-23 16b704d18a875d1fb63827aaa507790ba2bef5be
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
package com.stylefeng.guns.modular.code.controller;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.Page;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.system.vo.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 优惠券控制器
 */
@Controller
@RequestMapping("")
public class CouponController {
 
    @Autowired
    private IDeptService deptService;
    @Autowired
    private IPageService pageService;
    @Autowired
    private IProtocolService protocolService;
    @Autowired
    private IUseGuideService useGuideService;
    @Autowired
    private ISysSetService sysSetService;
    @Autowired
    private IRedPackageService redPackageService;
    @Autowired
    private IAppUserService appUserService;
    @Autowired
    private ICouponService couponService;
    @Autowired
    private IFitnessPositionService fitnessPositionService;
    @Autowired
    private IFitnessTypeService fitnessTypeService;
    @Autowired
    private ICourseService courseService;
    @ResponseBody
    @PostMapping("/base/coupon/couponList")
    @ApiOperation(value = "优惠券列表", tags = {"优惠券管理"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "优惠券名称", name = "couponName"),
            @ApiImplicitParam(value = "有效期类型", name = "timeType"),
            @ApiImplicitParam(value = "发放方式", name = "grantType"),
            @ApiImplicitParam(value = "页码,首页1", name = "pageNum", dataType = "int"),
            @ApiImplicitParam(value = "页条数", name = "pageSize", dataType = "int"),
    })
    public ResultUtil<PageInfo<CouponListVO>> couponList(String couponName,Integer timeType,Integer grantType,Integer pageNum,Integer pageSize) {
        List<Coupon> res = couponService.couponList(couponName,timeType,grantType);
        List<CouponListVO> result = new ArrayList<>();
        for (Coupon re : res) {
            CouponListVO couponListVO = new CouponListVO();
            BeanUtils.copyProperties(re,couponListVO);
            // 领取后
            if (re.getTimeType()==1){
                couponListVO.setTime(re.getAfterDay()+"天内有效");
            }else{
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                String s = format.format(re.getStartTime());
                String e = format.format(re.getEndTime());
                // 指定时间
                couponListVO.setTime(s+"至"+e);
            }
            result.add(couponListVO);
        }
//        PageHelper.startPage(pageNum,pageSize);
        PageInfo<CouponListVO> info=new PageInfo<>(result);
        return ResultUtil.success(info);
    }
 
 
    @ResponseBody
    @PostMapping("/base/coupon/couponReceive")
    @ApiOperation(value = "领取记录", tags = {"优惠券管理"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户名称", name = "userName"),
            @ApiImplicitParam(value = "联系电话", name = "phone"),
            @ApiImplicitParam(value = "领取类型1=打卡赠送 2=购课赠送 ", name = "receiveType"),
            @ApiImplicitParam(value = "状态 1= 未使用 2=已使用 3=已过期", name = "state"),
            @ApiImplicitParam(value = "优惠券id", name = "id"),
            @ApiImplicitParam(value = "页码,首页1", name = "pageNum", dataType = "int"),
            @ApiImplicitParam(value = "页条数", name = "pageSize", dataType = "int"),
    })
    public ResultUtil<PageInfo<CouponReceiveVO>> couponReceive
            (String userName,String phone,
            Integer state,Integer receiveType,Integer id,
             Integer pageNum,Integer pageSize) {
        CouPonQuery couPonQuery = new CouPonQuery();
        couPonQuery.setId(id);
        couPonQuery.setPhone(phone);
        couPonQuery.setUserName(userName);
        couPonQuery.setReceiveType(receiveType);
        couPonQuery.setState(state);
        couPonQuery.setPageNum(pageNum);
        couPonQuery.setPageSize(pageSize);
        List<CouponReceiveVO> res= couponService.couponReceive(couPonQuery);
        for (CouponReceiveVO re : res) {
            if (re.getReceiveType()==1||re.getReceiveType()==2){
                re.setReceiveType(1);
            }else{
                re.setReceiveType(2);
            }
            if (re.getState()==1){
                // 如果未使用 要判断这张优惠券是否过期了
                if (new Date().after(re.getEndTime())){
                    re.setState(3);
                }
            }
        }
//        PageHelper.startPage(pageNum,pageSize);
        PageInfo<CouponReceiveVO> info=new PageInfo<>(res);
        return ResultUtil.success(info);
    }
    @ResponseBody
    @PostMapping("/base/coupon/addCoupon")
    @ApiOperation(value = "优惠券添加/编辑", tags = {"优惠券管理"})
 
    public ResultUtil addCoupon(Coupon coupon) {
        if (coupon.getStartTime()!=null){
            Date startTime = coupon.getStartTime();
            Date endTime = coupon.getEndTime();
            LocalDateTime localStartDateTime = LocalDateTime.ofInstant(startTime.toInstant(), java.time.ZoneId.systemDefault());
            LocalDateTime localEndDateTime = LocalDateTime.ofInstant(endTime.toInstant(), java.time.ZoneId.systemDefault());
            // 设置开始时间的时分秒为00:00:00
            LocalDateTime startOfDay = localStartDateTime.toLocalDate().atStartOfDay();
            Timestamp startTimestamp = Timestamp.valueOf(startOfDay);
            startTime = new Date(startTimestamp.getTime());
            // 设置结束时间的时分秒为23:59:59
            LocalDate endDate = localEndDateTime.toLocalDate();
            LocalDateTime endOfDay = endDate.atTime(23, 59, 59);
            Timestamp endTimestamp = Timestamp.valueOf(endOfDay);
            endTime = new Date(endTimestamp.getTime());
            coupon.setStartTime(startTime);
            coupon.setEndTime(endTime);
        }
        if (coupon.getId()==null){
            // 添加
            couponService.insert(coupon);
            return ResultUtil.success("添加成功");
        }else {
            // 编辑
            couponService.updateById(coupon);
            return ResultUtil.success("编辑成功");
        }
    }
    @ResponseBody
    @PostMapping("/base/coupon/deleteCoupon")
    @ApiOperation(value = "优惠券删除", tags = {"优惠券管理"})
    public ResultUtil addCoupon(Integer id) {
        Coupon coupon = couponService.selectById(id);
        coupon.setIsDelete(1);
        couponService.updateById(coupon);
        return ResultUtil.success("删除成功");
    }
    @ResponseBody
    @PostMapping("/base/coupon/courseList")
    @ApiOperation(value = "优惠券添加/编辑选择课程", tags = {"优惠券管理"})
    public ResultUtil<List<FitnessPosition>> courseList() {
        List<FitnessPosition> fitnessPositions = new ArrayList<>();
        // 部位ids
        List<Integer> state = fitnessPositionService
                .selectList(new EntityWrapper<FitnessPosition>()
                        .eq("isDelete", 0)).stream().map(FitnessPosition::getId)
                .distinct()
                .collect(Collectors.toList());
        for (Integer position : state) {
            FitnessPosition fitnessPosition = new FitnessPosition();
            fitnessPosition.setId(position);
            FitnessPosition fitnessPosition1 = fitnessPositionService.selectById(position);
            String name = fitnessTypeService.selectById(fitnessPosition1.getTypeId()).getName();
            fitnessPosition.setName(name+"|"+fitnessPosition1.getName());
            fitnessPositions.add(fitnessPosition);
        }
        return ResultUtil.success(fitnessPositions);
    }
    @ResponseBody
    @PostMapping("/base/coupon/couponDetail")
    @ApiOperation(value = "查看详情", tags = {"优惠券管理"})
    public ResultUtil<Coupon> couponDetail(Integer id) {
        Coupon coupon = couponService.selectById(id);
        return ResultUtil.success(coupon);
    }
 
}