|  |  |  | 
|---|
|  |  |  | import com.mzl.flower.base.ReturnDataDTO; | 
|---|
|  |  |  | import com.mzl.flower.config.exception.ValidationException; | 
|---|
|  |  |  | import com.mzl.flower.dto.request.coupon.*; | 
|---|
|  |  |  | import com.mzl.flower.dto.response.coupon.CouponPointStatisVO; | 
|---|
|  |  |  | import com.mzl.flower.dto.response.coupon.CouponTemplatePointVO; | 
|---|
|  |  |  | import com.mzl.flower.dto.response.coupon.CouponTemplateVO; | 
|---|
|  |  |  | import com.mzl.flower.entity.coupon.CouponTemplateDO; | 
|---|
|  |  |  | import com.mzl.flower.enums.CouponCategoryEnum; | 
|---|
|  |  |  | import com.mzl.flower.enums.CouponStatusEnum; | 
|---|
|  |  |  | import com.mzl.flower.enums.CouponTypeEnum; | 
|---|
|  |  |  | import com.mzl.flower.enums.CouponUsageTypeEnum; | 
|---|
|  |  |  | import com.mzl.flower.service.coupon.CouponTemplateService2; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PutMapping("/{id}") | 
|---|
|  |  |  | @ApiOperation(value = "修改", notes = "修改") | 
|---|
|  |  |  | public ResponseEntity<ReturnDataDTO> update(@Validated @RequestBody CreateCouponTemplatePointDTO dto) { | 
|---|
|  |  |  | public ResponseEntity<ReturnDataDTO> update(@PathVariable String id,@Validated @RequestBody CreateCouponTemplatePointDTO dto) { | 
|---|
|  |  |  | // 信息校验 | 
|---|
|  |  |  | dto.setId(id); | 
|---|
|  |  |  | valid(dto); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | CouponTemplateDO couponTemplateDO = couponTemplateService.getById(dto.getId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | CreateCouponTemplateBO couponTemplateBO = new CreateCouponTemplateBO(); | 
|---|
|  |  |  | BeanUtils.copyProperties(couponTemplateDO,couponTemplateBO); | 
|---|
|  |  |  | BeanUtils.copyProperties(dto, couponTemplateBO); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 设置成积分优惠券 | 
|---|
|  |  |  | 
|---|
|  |  |  | return returnData(R.SUCCESS.getCode(), null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PutMapping("/batch/expire") | 
|---|
|  |  |  | @PostMapping("/batch/expire") | 
|---|
|  |  |  | @ApiOperation(value = "批量下架", notes = "批量下架") | 
|---|
|  |  |  | public ResponseEntity<ReturnDataDTO> expireBatch(BatchCouponTemplateDTO dto) { | 
|---|
|  |  |  | public ResponseEntity<ReturnDataDTO> expireBatch(@RequestBody BatchCouponTemplateDTO dto) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | couponTemplateService.expireBatchCouponTemplate(dto); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PutMapping("/batch/active") | 
|---|
|  |  |  | @PostMapping("/batch/active") | 
|---|
|  |  |  | @ApiOperation(value = "批量发布", notes = "批量发布") | 
|---|
|  |  |  | public ResponseEntity<ReturnDataDTO> activeBatch(BatchCouponTemplateDTO dto) { | 
|---|
|  |  |  | public ResponseEntity<ReturnDataDTO> activeBatch(@RequestBody BatchCouponTemplateDTO dto) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | couponTemplateService.activeBatchCouponTemplate(dto); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @DeleteMapping("/batch/del") | 
|---|
|  |  |  | @PostMapping("/batch/del") | 
|---|
|  |  |  | @ApiOperation(value = "批量删除", notes = "批量删除") | 
|---|
|  |  |  | public ResponseEntity<ReturnDataDTO> deleteBatch(BatchCouponTemplateDTO dto) { | 
|---|
|  |  |  | public ResponseEntity<ReturnDataDTO> deleteBatch(@RequestBody BatchCouponTemplateDTO dto) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | couponTemplateService.deleteBatchCouponTemplate(dto); | 
|---|
|  |  |  | return returnData(R.SUCCESS.getCode(), null); | 
|---|
|  |  |  | 
|---|
|  |  |  | public ResponseEntity<ReturnDataDTO> statistics(QueryCouponStatisticsDTO dto) { | 
|---|
|  |  |  | QueryCouponStatisticsBO queryCouponStatisticsBO=new QueryCouponStatisticsBO(); | 
|---|
|  |  |  | BeanUtils.copyProperties(dto,queryCouponStatisticsBO); | 
|---|
|  |  |  | CouponTemplateVO couponTemplateVO = couponTemplateService.statisCouponTemplatePoint(queryCouponStatisticsBO); | 
|---|
|  |  |  | return returnData(R.SUCCESS.getCode(), ConverterUtil.transObject(couponTemplateVO, CouponTemplatePointVO.class)); | 
|---|
|  |  |  | CouponPointStatisVO vo = couponTemplateService.statisCouponTemplatePoint(queryCouponStatisticsBO); | 
|---|
|  |  |  | return returnData(R.SUCCESS.getCode(), vo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("/active/list") | 
|---|
|  |  |  | @ApiOperation(value = "查询-全部", notes = "查询-全部") | 
|---|
|  |  |  | public ResponseEntity<ReturnDataDTO<Page<CouponTemplateVO>>> activeList(QueryActivePointCouponDTO dto) { | 
|---|
|  |  |  | // 设置只查询积分优惠券的 | 
|---|
|  |  |  | dto.setCategory(CouponCategoryEnum.POINT.getStatus()); | 
|---|
|  |  |  | dto.setStatus(CouponStatusEnum.ACTIVE.getStatus()); | 
|---|
|  |  |  | return returnData(R.SUCCESS.getCode(), ConverterUtil.transList(couponTemplateService.getPointList(dto), CouponTemplatePointVO.class)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("/active/page") | 
|---|
|  |  |  | @ApiOperation(value = "查询-分页", notes = "查询-分页") | 
|---|
|  |  |  | public ResponseEntity<ReturnDataDTO<Page<CouponTemplatePointVO>>> activePage(Page page, QueryActivePointCouponDTO dto) { | 
|---|
|  |  |  | // 设置只查询积分优惠券的 | 
|---|
|  |  |  | dto.setCategory(CouponCategoryEnum.POINT.getStatus()); | 
|---|
|  |  |  | dto.setStatus(CouponStatusEnum.ACTIVE.getStatus()); | 
|---|
|  |  |  | Page<CouponTemplateVO> resultPage = couponTemplateService.getPointPage(page, dto); | 
|---|
|  |  |  | return returnData(R.SUCCESS.getCode(), ConverterUtil.transPage(resultPage, CouponTemplatePointVO.class)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void valid(CreateCouponTemplatePointDTO dto){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (StringUtils.isNotBlank(dto.getCouponDiscountType()) | 
|---|
|  |  |  | && dto.getCouponDiscountType().equals(CouponTypeEnum.DISCOUNT.getType()) | 
|---|
|  |  |  | && dto.getMinOrderAmount().compareTo(dto.getCouponDiscountValue()) < 0) { | 
|---|
|  |  |  | throw new ValidationException("订单金额不能小于折扣金额"); | 
|---|
|  |  |  | if (StringUtils.isNotBlank(dto.getCouponDiscountType()) && dto.getCouponDiscountType().equals(CouponTypeEnum.DISCOUNT.getType())) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(dto.getMinOrderAmount().compareTo(BigDecimal.ZERO)<=0){ | 
|---|
|  |  |  | throw new ValidationException("优惠券使用条件不能小于0"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(dto.getMinOrderAmount().compareTo(dto.getCouponDiscountValue()) < 0){ | 
|---|
|  |  |  | throw new ValidationException("优惠券使用条件不能小于面值金额"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (StringUtils.isNotBlank(dto.getCouponDiscountType()) | 
|---|
|  |  |  | && dto.getCouponDiscountType().equals(CouponTypeEnum.DISCOUNT.getType()) | 
|---|
|  |  |  | && dto.getCouponDiscountValue().compareTo(BigDecimal.ZERO) <= 0) { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/exchange") | 
|---|
|  |  |  | @ApiOperation(value = "小程序-积分优惠券兑换", notes = "小程序-积分优惠券兑换") | 
|---|
|  |  |  | public ResponseEntity<ReturnDataDTO> exchangeCoupon(@Validated @RequestBody ExchangeCouponDTO dto) { | 
|---|
|  |  |  | couponTemplateService.exchangeCoupon(dto); | 
|---|
|  |  |  | return returnData(R.SUCCESS.getCode(), null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|