| | |
| | | package com.xiaopeng.account.controller; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.xiaopeng.account.model.dto.ReceiveCouponDto; |
| | | import com.xiaopeng.account.model.dto.SendCouponDto; |
| | |
| | | import com.xiaopeng.account.model.vo.XpAppUserCouponTotalVo; |
| | | import com.xiaopeng.account.model.vo.XpAppUserCouponVo; |
| | | import com.xiaopeng.account.service.IXpAppUserCouponService; |
| | | import com.xiaopeng.account.vo.CouponReceiptRecordDto; |
| | | import com.xiaopeng.account.vo.CouponReceiptRecordVo; |
| | | import com.xiaopeng.account.vo.UserCouponListVo; |
| | | import com.xiaopeng.api.dto.account.GetUserCouponDto; |
| | | import com.xiaopeng.api.dto.account.NavigationCouponPickerRequest; |
| | | import com.xiaopeng.api.dto.account.UseUserCouponDto; |
| | | import com.xiaopeng.api.dto.account.UserResourcesDto; |
| | | import com.xiaopeng.api.feignClient.account.UserResourcesClient; |
| | | import com.xiaopeng.api.feignClient.account.XpAppUserClient; |
| | | import com.xiaopeng.api.feignClient.operation.XpActicityClient; |
| | | import com.xiaopeng.api.feignClient.operation.XpCouponClient; |
| | | import com.xiaopeng.api.feignClient.operation.XpOpenCityClient; |
| | | import com.xiaopeng.api.model.account.XpAppUserCoupon; |
| | | import com.xiaopeng.api.model.operation.XpCoupon; |
| | | import com.xiaopeng.api.query.account.XpAppUserCouponPageListQuery; |
| | | import com.xiaopeng.api.vo.account.AppUserCouponSaveBatchVo; |
| | | import com.xiaopeng.api.vo.account.CalculateDiscountAmountVo; |
| | | import com.xiaopeng.api.vo.account.NavigationCouponPickerVo; |
| | | import com.xiaopeng.api.vo.account.UserCouponVo; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | import com.xiaopeng.common.log.annotation.AdminOperationLog; |
| | | import com.xiaopeng.common.log.enums.AdminBusinessType; |
| | | import com.xiaopeng.common.log.enums.AdminOperationType; |
| | | import com.xiaopeng.unifiedverification.interceptor.XpClientCheck; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import org.springframework.stereotype.Controller; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.validation.Valid; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Arrays; |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | import com.xiaopeng.common.log.annotation.AdminOperationLog; |
| | | import com.xiaopeng.common.log.enums.AdminBusinessType; |
| | | import com.xiaopeng.common.log.enums.AdminOperationType; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | private final UserResourcesClient userResourcesClient; |
| | | private final XpCouponClient xpCouponClient; |
| | | |
| | | @Resource |
| | | private XpActicityClient xpActicityClient; |
| | | |
| | | |
| | | public XpAppUserCouponController(IXpAppUserCouponService xpAppUserCouponService, XpOpenCityClient xpOpenCityClient, UserResourcesClient userResourcesClient, XpCouponClient xpCouponClient) { |
| | | this.xpAppUserCouponService = xpAppUserCouponService; |
| | |
| | | this.xpCouponClient = xpCouponClient; |
| | | } |
| | | |
| | | @PostMapping("/v1/api/appUserCoupon/pageList") |
| | | @ApiOperation(value = "白名单用户优惠券列表",tags = {"管理后台-白名单-用户优惠券列表"},response = XpAppUserCouponListVo.class) |
| | | public R<PageInfo<XpAppUserCouponListVo>> pageList(@RequestBody XpAppUserCouponPageListQuery query) { |
| | | |
| | | @PostMapping("/inner/appUserCoupon/getUserCoupon") |
| | | if(StrUtil.isNotBlank(query.getActicityName()) ){ |
| | | List<String> acticityIds = xpActicityClient.findListToIds(query.getActicityName()).getData(); |
| | | query.setActicityIds(acticityIds); |
| | | } |
| | | |
| | | PageInfo<XpAppUserCouponListVo> pageList = xpAppUserCouponService.pageList(query); |
| | | return R.ok(pageList); |
| | | } |
| | | |
| | | @PostMapping("/v1/api/appUserCoupon/deleteByIds") |
| | | @ApiOperation(value = "根据ids删除用户优惠券", tags = {"管理后台-白名单-删除用户优惠券"}) |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.APP_USER_COUPON, |
| | | operationType = AdminOperationType.DELETE, |
| | | content = "根据ids删除用户优惠券", |
| | | appendRequestData = true |
| | | ) |
| | | public R<Boolean> deleteByIds(@RequestBody XpAppUserCouponPageListQuery query ) { |
| | | if (query.getIds() == null || query.getIds().isEmpty()) { |
| | | return R.fail("ID列表不能为空"); |
| | | } |
| | | boolean result = xpAppUserCouponService.removeByIds(query.getIds()); |
| | | return R.ok(result); |
| | | } |
| | | |
| | | @PostMapping("/logan/inner/appUserCoupon/getUserCoupon") |
| | | public R<UserCouponVo> getUserCoupon(@RequestBody GetUserCouponDto dto) { |
| | | // String phone ="18888888888"; |
| | | // if(dto.getUserId()>1){ |
| | |
| | | |
| | | UserCouponVo userCouponVo = new UserCouponVo(); |
| | | // 获取用户所有优惠券 |
| | | List<XpAppUserCoupon> couponList = xpAppUserCouponService.list(new LambdaQueryWrapper<XpAppUserCoupon>().eq(dto.getUserCouponId()!=null,XpAppUserCoupon::getId, dto.getUserCouponId()).eq(XpAppUserCoupon::getStatus, 1).eq(XpAppUserCoupon::getAppUserId,dto.getUserId()).apply("(FIND_IN_SET({0}, open_city_id) or open_city_id='0')", dto.getOpenCityId()) ); |
| | | List<XpAppUserCoupon> couponList = xpAppUserCouponService.list(new LambdaQueryWrapper<XpAppUserCoupon>() |
| | | .eq(dto.getUserCouponId()!=null,XpAppUserCoupon::getId, dto.getUserCouponId()).eq(XpAppUserCoupon::getStatus, 1) |
| | | .eq(XpAppUserCoupon::getAppUserId,dto.getUserId())); |
| | | if(couponList.isEmpty()){ |
| | | return R.ok(userCouponVo); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | // 优先用满足条件且抵扣金额最大的 |
| | | List<XpAppUserCoupon> discountUserCoupons = couponList.stream().filter(e -> e.getCouponType() == 1).sorted(Comparator.comparing(XpAppUserCoupon::getMoney).reversed()).collect(Collectors.toList()); |
| | | if(!discountUserCoupons.isEmpty()){ |
| | | userCouponVo.setId(discountUserCoupons.get(0).getId()); |
| | | userCouponVo.setMoney(discountUserCoupons.get(0).getMoney().doubleValue()); |
| | | if(dto.getUserCouponId()!=null){ |
| | | XpAppUserCoupon coupon = couponList.get(0); |
| | | userCouponVo.setId(coupon.getId()); |
| | | userCouponVo.setCouponType(coupon.getCouponType()); |
| | | userCouponVo.setMoney(coupon.getMoney().doubleValue()); |
| | | return R.ok(userCouponVo); |
| | | }else { |
| | | // 优先用满足条件且抵扣金额最大的 |
| | | List<XpAppUserCoupon> discountUserCoupons = couponList.stream().filter(e -> e.getCouponType() == 1).sorted(Comparator.comparing(XpAppUserCoupon::getMoney).reversed()).collect(Collectors.toList()); |
| | | if(!discountUserCoupons.isEmpty()){ |
| | | userCouponVo.setCouponType(discountUserCoupons.get(0).getCouponType()); |
| | | userCouponVo.setId(discountUserCoupons.get(0).getId()); |
| | | userCouponVo.setMoney(discountUserCoupons.get(0).getMoney().doubleValue()); |
| | | return R.ok(userCouponVo); |
| | | } |
| | | List<XpAppUserCoupon> fullUserCoupons = couponList.stream().filter(e -> e.getCouponType() == 2 && dto.getTotalAmount() >= e.getFullMoney().doubleValue()).sorted(Comparator.comparing(XpAppUserCoupon::getMoney).reversed()).collect(Collectors.toList()); |
| | | if(!fullUserCoupons.isEmpty()){ |
| | | userCouponVo.setCouponType(fullUserCoupons.get(0).getCouponType()); |
| | | userCouponVo.setId(fullUserCoupons.get(0).getId()); |
| | | userCouponVo.setMoney(fullUserCoupons.get(0).getMoney().doubleValue()); |
| | | return R.ok(userCouponVo); |
| | | } |
| | | return R.ok(userCouponVo); |
| | | } |
| | | List<XpAppUserCoupon> fullUserCoupons = couponList.stream().filter(e -> e.getCouponType() == 2 && e.getFullMoney().doubleValue()>dto.getTotalAmount()).sorted(Comparator.comparing(XpAppUserCoupon::getMoney).reversed()).collect(Collectors.toList()); |
| | | if(!fullUserCoupons.isEmpty()){ |
| | | userCouponVo.setId(fullUserCoupons.get(0).getId()); |
| | | userCouponVo.setMoney(fullUserCoupons.get(0).getMoney().doubleValue()); |
| | | return R.ok(userCouponVo); |
| | | } |
| | | return R.ok(userCouponVo); |
| | | |
| | | } |
| | | @PostMapping("/inner/appUserCoupon/useUserCoupon") |
| | | |
| | | |
| | | @PostMapping("/logan/inner/appUserCoupon/useUserCoupon") |
| | | public R<BigDecimal> useUserCoupon(@RequestBody UseUserCouponDto dto) { |
| | | XpAppUserCoupon appUserCoupon = xpAppUserCouponService.getById(dto.getUserCouponId()); |
| | | appUserCoupon.setStatus(2); |
| | |
| | | return R.ok(appUserCoupon.getMoney()); |
| | | } |
| | | |
| | | /** |
| | | * 退回用户的优惠卷 |
| | | * @param dto |
| | | * @return |
| | | */ |
| | | @PostMapping("/logan/inner/appUserCoupon/backUserCoupon") |
| | | public R<BigDecimal> backUserCoupon(@RequestBody UseUserCouponDto dto) { |
| | | if(dto.getUserCouponId() == null){ |
| | | return R.ok(); |
| | | } |
| | | XpAppUserCoupon appUserCoupon = xpAppUserCouponService.getById(dto.getUserCouponId()); |
| | | //状态(1=未使用,2=已使用,3=已过期 0=待领取 4=占用中) |
| | | if(appUserCoupon.getExpirationTime().isAfter(LocalDateTime.now())){ |
| | | appUserCoupon.setStatus(3); |
| | | }else{ |
| | | appUserCoupon.setStatus(1); |
| | | } |
| | | appUserCoupon.setUseTime(null); |
| | | appUserCoupon.setAppUserId(null); |
| | | xpAppUserCouponService.updateById(appUserCoupon); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | |
| | | /** |
| | | * 获取优惠券列表 |
| | | */ |
| | | @PostMapping("/api/v1/mini-program/coupon/navigation-picker") |
| | | @ApiOperation(value = "导航下单-选券弹窗(排序、最佳优惠、气泡文案)", tags = {"小程序-优惠券"}) |
| | | @XpClientCheck(checkToken = false, checkOtpToken = true) |
| | | public R<NavigationCouponPickerVo> navigationCouponPicker(@RequestBody @Valid NavigationCouponPickerRequest request, |
| | | HttpServletRequest httpRequest) { |
| | | String uid = httpRequest.getHeader("XP-Uid"); |
| | | return R.ok(xpAppUserCouponService.navigationCouponPicker(Long.valueOf(uid), request)); |
| | | } |
| | | |
| | | @PostMapping("/api/v1/mini-program/coupon/list") |
| | | @ApiOperation(value = "获取用户获取优惠券列表", tags = {"小程序-获取用户获取优惠券列表"}) |
| | | @XpClientCheck(checkToken = false, checkOtpToken = true) |
| | |
| | | // phone = JSONObject.parseObject(data.toString()).getString("mobile"); |
| | | // } |
| | | XpAppUserCoupon coupon = xpAppUserCouponService.getById(couponId); |
| | | if(uid.equals(coupon.getAppUserId().toString())){ |
| | | if(Long.valueOf(uid).equals(coupon.getAppUserId())){ |
| | | XpAppUserCouponListVo vo = new XpAppUserCouponListVo(); |
| | | vo.setCouponId(coupon.getId().toString()); |
| | | vo.setTitle(coupon.getCouponName()); |
| | |
| | | } |
| | | return R.ok(null); |
| | | } |
| | | /** |
| | | * 获取即将过期的优惠卷 |
| | | */ |
| | | @GetMapping("/api/v1/mini-program/coupon/findListExpirationTime") |
| | | @ApiOperation(value = "获取即将过期的优惠卷", tags = {"小程序-获取即将过期的优惠卷"}) |
| | | @XpClientCheck(checkToken = false, checkOtpToken = true) |
| | | public R<List<XpAppUserCoupon>> findListExpirationTime(HttpServletRequest request) { |
| | | String uid = request.getHeader("XP-Uid"); |
| | | List<XpAppUserCoupon> listExpirationTime = xpAppUserCouponService.findListExpirationTime(uid); |
| | | return R.ok(listExpirationTime); |
| | | } |
| | | |
| | | /** |
| | | * 获取优惠券列表total |
| | |
| | | } |
| | | |
| | | |
| | | @PostMapping("/api/v1/appUserCoupon/saveInfo_activity") |
| | | @ApiOperation(value = "活动发放优惠券", tags = {"管理后台-活动发放优惠券"}) |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.APP_USER_COUPON, |
| | | operationType = AdminOperationType.ISSUE, |
| | | content = "活动发放优惠券", |
| | | appendRequestData = true |
| | | ) |
| | | public R<String> saveInfo_activity(@RequestBody UseUserCouponDto dto) { |
| | | xpAppUserCouponService.saveInfo_activity(dto); |
| | | return R.ok(); |
| | | } |
| | | /** |
| | | * 发放优惠券 |
| | | */ |
| | | @PostMapping("/api/v1/appUserCoupon/send") |
| | | @ApiOperation(value = "发放优惠券", tags = {"管理后台-发放优惠券"}) |
| | | @AdminOperationLog( |
| | | businessType = AdminBusinessType.APP_USER_COUPON, |
| | | operationType = AdminOperationType.ISSUE, |
| | | content = "发放优惠券", |
| | | appendRequestData = true |
| | | ) |
| | | public R<String> send(@RequestBody SendCouponDto dto) { |
| | | xpAppUserCouponService.send(dto); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | @GetMapping("/logan/inner/appUserCoupon/holding") |
| | | @ApiOperation(value = "查询优惠券是否已有用户使用", tags = {"管理后台-优惠券是否占用"}) |
| | | public R<Boolean> holding(@RequestParam Long couponId) { |
| | | |
| | | return R.ok(xpAppUserCouponService.holding(couponId)); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 1.0获取用户可用优惠券数量 |
| | | */ |
| | | @GetMapping("/api/v1/mini-program/getUserCouponNum") |
| | | @ApiOperation(value = "1.0获取用户可用优惠券数量", tags = {"小程序-获取用户可用优惠券数量"}) |
| | | @XpClientCheck(checkToken = false, checkOtpToken = true) |
| | | public R<Integer> getUserCouponNum(HttpServletRequest request) { |
| | | // uid已通过拦截器otp校验,可以直接使用 |
| | | String uid = request.getHeader("XP-Uid"); |
| | | Integer num = xpAppUserCouponService.getUserCouponNum(uid); |
| | | return R.ok(num); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取优惠券切换页面列表 |
| | | * @param orderMoney |
| | | * @param request |
| | | * @return |
| | | */ |
| | | @GetMapping("/api/v1/mini-program/getUserCouponList") |
| | | @ApiOperation(value = "获取优惠券切换页面列表", tags = {"小程序-获取用户可用优惠券数量"}) |
| | | @XpClientCheck(checkToken = false, checkOtpToken = true) |
| | | public R<UserCouponListVo> getUserCouponList(BigDecimal orderMoney, HttpServletRequest request) { |
| | | // uid已通过拦截器otp校验,可以直接使用 |
| | | String uid = request.getHeader("XP-Uid"); |
| | | UserCouponListVo userCouponList = xpAppUserCouponService.getUserCouponList(orderMoney, uid); |
| | | return R.ok(userCouponList); |
| | | } |
| | | |
| | | /** |
| | | * 获取用户活动领取的优惠券 |
| | | * @return |
| | | */ |
| | | @PostMapping("/logan/inner/appUserCoupon/getXpAppUserCoupon") |
| | | public R<List<XpAppUserCoupon>> getXpAppUserCoupon(@RequestParam Long activityId){ |
| | | List<XpAppUserCoupon> list = xpAppUserCouponService.list(new QueryWrapper<XpAppUserCoupon>() |
| | | .eq("activity_id", activityId).eq("is_deleted", 0)); |
| | | return R.ok(list); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @PostMapping("/api/v1/activity/getCouponReceiptRecord") |
| | | @ApiOperation(value = "获取活动领取记录", tags = {"管理后台-活动管理"}) |
| | | public R<PageInfo<CouponReceiptRecordDto>> getCouponReceiptRecord(@RequestBody CouponReceiptRecordVo vo){ |
| | | PageInfo<CouponReceiptRecordDto> pageInfo = new PageInfo<CouponReceiptRecordDto>(vo.getPageNum(), vo.getPageSize()); |
| | | List<CouponReceiptRecordDto> couponReceiptRecord = xpAppUserCouponService.getCouponReceiptRecord(pageInfo, vo); |
| | | pageInfo.setRecords(couponReceiptRecord); |
| | | return R.ok(pageInfo); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 计算优惠金额 |
| | | * @param vo |
| | | * @return |
| | | */ |
| | | @PostMapping("/logan/inner/appUserCoupon/calculateDiscountAmount") |
| | | public R<BigDecimal> calculateDiscountAmount(@RequestBody CalculateDiscountAmountVo vo){ |
| | | BigDecimal bigDecimal = xpAppUserCouponService.calculateDiscountAmount(vo); |
| | | return R.ok(bigDecimal); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 批量保存数据 |
| | | * @param vo |
| | | * @return |
| | | */ |
| | | @PostMapping("/logan/inner/appUserCoupon/saveBatch") |
| | | public R<?> saveBatch(@RequestBody AppUserCouponSaveBatchVo vo){ |
| | | xpAppUserCouponService.saveBatch(vo.getXpAppUserCoupons()); |
| | | return R.ok(); |
| | | } |
| | | } |