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> couponList(String couponName,Integer timeType,Integer grantType,Integer pageNum,Integer pageSize) { List res = couponService.couponList(couponName,timeType,grantType); List 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 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> 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 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 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> courseList() { List fitnessPositions = new ArrayList<>(); // 部位ids List state = fitnessPositionService .selectList(new EntityWrapper() .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 couponDetail(Integer id) { Coupon coupon = couponService.selectById(id); return ResultUtil.success(coupon); } }