| | |
| | | import com.mzl.flower.base.BaseController; |
| | | import com.mzl.flower.base.R; |
| | | import com.mzl.flower.base.ReturnDataDTO; |
| | | import com.mzl.flower.config.exception.ValidationException; |
| | | import com.mzl.flower.config.security.SecurityUtils; |
| | | import com.mzl.flower.dto.request.coupon.CreateCouponRecordAppDTO; |
| | | import com.mzl.flower.dto.request.coupon.CreateCouponRecordDTO; |
| | | import com.mzl.flower.dto.request.coupon.QueryActivityEffectCouponDTO; |
| | | import com.mzl.flower.dto.request.coupon.QueryCouponDTO; |
| | | import com.mzl.flower.dto.request.coupon.QueryMineCouponRecordDTO; |
| | | import com.mzl.flower.dto.response.coupon.CouponTemplateAppVO; |
| | | import com.mzl.flower.dto.response.coupon.CouponTemplateVO; |
| | | import com.mzl.flower.dto.response.customer.CustomerDTO; |
| | | import com.mzl.flower.entity.coupon.CouponTemplateDO; |
| | | import com.mzl.flower.enums.CouponCategoryEnum; |
| | | import com.mzl.flower.enums.CouponGetTypeEnum; |
| | | import com.mzl.flower.enums.CouponStatusEnum; |
| | | import com.mzl.flower.enums.CouponUsedStatusEnum; |
| | | import com.mzl.flower.mapper.customer.CustomerMapper; |
| | | import com.mzl.flower.service.coupon.CouponRecordService; |
| | | import com.mzl.flower.service.coupon.CouponTemplateService2; |
| | | import com.mzl.flower.utils.ConverterUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | |
| | | /** |
| | |
| | | @Autowired |
| | | CouponTemplateService2 couponTemplateService; |
| | | |
| | | @GetMapping("/home/list") |
| | | @ApiOperation(value = "查询-首页弹框", notes = "查询-首页弹框") |
| | | public ResponseEntity<ReturnDataDTO<Page<CouponTemplateVO>>> homeList(QueryActivityEffectCouponDTO dto) { |
| | | // TODO 需要查找到领取时间优惠券的开始时间和结束时间内的优惠券 |
| | | @Autowired |
| | | CouponRecordService couponRecordService; |
| | | |
| | | |
| | | @Autowired |
| | | CustomerMapper customerMapper; |
| | | |
| | | // @GetMapping("/home/list") |
| | | // @ApiOperation(value = "查询-首页弹框", notes = "查询-首页弹框") |
| | | // public ResponseEntity<ReturnDataDTO<Page<CouponTemplateVO>>> homeList(QueryActivityEffectCouponDTO dto) { |
| | | // // 活动优惠券 |
| | | // dto.setCategory(CouponCategoryEnum.ACTIVITY.getStatus()); |
| | | // // 已经发布 |
| | | // dto.setStatus(CouponStatusEnum.ACTIVE.getStatus()); |
| | | // // 首页弹窗 |
| | | // dto.setGetType(CouponGetTypeEnum.HOME.getType()); |
| | | // return returnData(R.SUCCESS.getCode(), ConverterUtil.transList(couponTemplateService.getActivityEffectList(dto), CouponTemplateAppVO.class)); |
| | | // } |
| | | |
| | | @GetMapping("/home/alert") |
| | | @ApiOperation(value = "查询-首页弹框", notes = "查询-首页弹框") |
| | | public ResponseEntity<ReturnDataDTO<CouponTemplateVO>> homeAlert(QueryActivityEffectCouponDTO dto) { |
| | | // 活动优惠券 |
| | | dto.setCategory(CouponCategoryEnum.ACTIVITY.getStatus()); |
| | | // 已经发布 |
| | | dto.setStatus(CouponStatusEnum.ACTIVE.getStatus()); |
| | | // 首页弹窗 |
| | | dto.setGetType(CouponGetTypeEnum.HOME.getType()); |
| | | |
| | | couponTemplateService.getActivityEffectList(dto); |
| | | |
| | | return returnData(R.SUCCESS.getCode(),null); |
| | | // 如果当前人员已经领取过的话,则不返回 |
| | | return returnData(R.SUCCESS.getCode(), ConverterUtil.transObject(couponTemplateService.getHomeActivityEffectAlert(dto), CouponTemplateAppVO.class)); |
| | | } |
| | | |
| | | @GetMapping("/activy/list") |
| | | @ApiOperation(value = "查询-活动", notes = "查询-活动") |
| | | @ApiOperation(value = "查询-活动入口", notes = "查询-活动入口") |
| | | public ResponseEntity<ReturnDataDTO<Page<CouponTemplateVO>>> activyList(QueryActivityEffectCouponDTO dto) { |
| | | // TODO |
| | | // 活动优惠券 |
| | | dto.setCategory(CouponCategoryEnum.ACTIVITY.getStatus()); |
| | | // 已经发布 |
| | | dto.setStatus(CouponStatusEnum.ACTIVE.getStatus()); |
| | | // 活动入口 |
| | | dto.setGetType(CouponGetTypeEnum.ACTIVITY.getType()); |
| | | return returnData(R.SUCCESS.getCode(), ConverterUtil.transList(couponTemplateService.getActivityEffectList(dto), CouponTemplateAppVO.class)); |
| | | |
| | | return returnData(R.SUCCESS.getCode(),null); |
| | | } |
| | | |
| | | @GetMapping("/center/list") |
| | | @ApiOperation(value = "查询-中心", notes = "查询-中心") |
| | | @ApiOperation(value = "查询-领券中心", notes = "查询-领券中心") |
| | | public ResponseEntity<ReturnDataDTO<Page<CouponTemplateVO>>> centerList(QueryActivityEffectCouponDTO dto) { |
| | | // TODO |
| | | // 活动优惠券 |
| | | dto.setCategory(CouponCategoryEnum.ACTIVITY.getStatus()); |
| | | // 已经发布 |
| | | dto.setStatus(CouponStatusEnum.ACTIVE.getStatus()); |
| | | // 首页弹窗 |
| | | dto.setGetType(CouponGetTypeEnum.CENTER.getType()); |
| | | |
| | | return returnData(R.SUCCESS.getCode(),null); |
| | | return returnData(R.SUCCESS.getCode(), ConverterUtil.transList(couponTemplateService.getActivityEffectList(dto), CouponTemplateAppVO.class)); |
| | | |
| | | } |
| | | |
| | | @GetMapping("/mine/unused/list") |
| | | @ApiOperation(value = "我的优惠券-未使用", notes = "我的优惠券-未使用") |
| | | public ResponseEntity<ReturnDataDTO<Page<CouponTemplateVO>>> unusedList(QueryMineCouponRecordDTO dto) { |
| | | // 未使用 |
| | | dto.setStatus(CouponUsedStatusEnum.UNUSED.getType()); |
| | | dto.setUserId(SecurityUtils.getUserId()); |
| | | |
| | | return returnData(R.SUCCESS.getCode(), ConverterUtil.transList(couponRecordService.getMineCouponRecordList(dto), CouponTemplateAppVO.class)); |
| | | |
| | | } |
| | | @GetMapping("/mine/used/list") |
| | | @ApiOperation(value = "我的优惠券-已使用", notes = "我的优惠券-已使用") |
| | | public ResponseEntity<ReturnDataDTO<Page<CouponTemplateVO>>> usedList(QueryMineCouponRecordDTO dto) { |
| | | |
| | | // 已使用 |
| | | dto.setStatus(CouponUsedStatusEnum.USED.getType()); |
| | | dto.setUserId(SecurityUtils.getUserId()); |
| | | return returnData(R.SUCCESS.getCode(), ConverterUtil.transList(couponRecordService.getMineCouponRecordList(dto), CouponTemplateAppVO.class)); |
| | | |
| | | } |
| | | |
| | | @GetMapping("/mine/expired/list") |
| | | @ApiOperation(value = "我的优惠券-已过期", notes = "我的优惠券-已过期") |
| | | public ResponseEntity<ReturnDataDTO<Page<CouponTemplateVO>>> expiredList(QueryMineCouponRecordDTO dto) { |
| | | // 已过期 |
| | | dto.setStatus(CouponUsedStatusEnum.EXPIRED.getType()); |
| | | dto.setUserId(SecurityUtils.getUserId()); |
| | | return returnData(R.SUCCESS.getCode(), ConverterUtil.transList(couponRecordService.getMineCouponRecordList(dto), CouponTemplateAppVO.class)); |
| | | |
| | | } |
| | | |
| | | @PostMapping("/receive") |
| | | @ApiOperation(value = "优惠券领取", notes = "优惠券领取") |
| | | public ResponseEntity<ReturnDataDTO> create(@Validated @RequestBody CreateCouponRecordAppDTO dto) { |
| | | |
| | | final CouponTemplateDO couponTemplateDO = couponTemplateService.getById(dto.getCouponId()); |
| | | if(null==couponTemplateDO){ |
| | | throw new ValidationException("优惠券不存在"); |
| | | } |
| | | |
| | | if(StringUtils.isNotBlank(couponTemplateDO.getStatus()) && couponTemplateDO.getStatus().equals(CouponStatusEnum.INACTIVE.getStatus())){ |
| | | throw new ValidationException("优惠券还未发布"); |
| | | } |
| | | if(StringUtils.isNotBlank(couponTemplateDO.getStatus()) && couponTemplateDO.getStatus().equals(CouponStatusEnum.EXPIRED.getStatus())){ |
| | | throw new ValidationException("优惠券已下架"); |
| | | } |
| | | |
| | | // 根据当前获取获取商户的ID |
| | | CustomerDTO currentCustomer = customerMapper.getCurrentCustomer(SecurityUtils.getUserId()); |
| | | if(null==currentCustomer){ |
| | | throw new ValidationException("当前登录的用户记录不存在"); |
| | | } |
| | | // 设置当前用户为登录用户 |
| | | dto.setCustomerId(currentCustomer.getId()); |
| | | |
| | | CreateCouponRecordDTO dtoTrans=new CreateCouponRecordDTO(); |
| | | BeanUtils.copyProperties(dto,dtoTrans); |
| | | |
| | | couponRecordService.createCouponRecord(dtoTrans); |
| | | return returnData(R.SUCCESS.getCode(), null); |
| | | } |
| | | |
| | | |
| | | } |