| | |
| | | package com.dsh.activity.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.dsh.activity.entity.Coupon; |
| | | import com.dsh.activity.entity.UserCoupon; |
| | | import com.dsh.activity.feignclient.model.CouponListOfSearch; |
| | | import com.dsh.activity.model.CouponListVo; |
| | | import com.dsh.activity.model.request.CommodityRequest; |
| | | import com.dsh.activity.model.request.CouponPackageReq; |
| | | import com.dsh.activity.model.response.CouponPackageResp; |
| | | import com.dsh.activity.service.ICouponService; |
| | | import com.dsh.activity.service.UserCouponService; |
| | | import com.dsh.activity.util.GDMapGeocodingUtil; |
| | | import com.dsh.activity.util.ResultUtil; |
| | | import com.dsh.activity.util.TokenUtil; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | |
| | | @Autowired |
| | | private UserCouponService ucService; |
| | | |
| | | @Autowired |
| | | private GDMapGeocodingUtil gdMapGeocodingUtil; |
| | | |
| | | |
| | | |
| | | |
| | |
| | | @ApiImplicitParam(value = "1=积分购买,2=注册赠送", name = "distributionMethod", dataType = "int", required = true), |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public ResultUtil<List<CouponListVo>> queryCouponList(@RequestBody Integer distributionMethod){ |
| | | public ResultUtil<List<CouponListVo>> queryCouponList(Integer distributionMethod){ |
| | | if(null == distributionMethod){ |
| | | return ResultUtil.paranErr("distributionMethod"); |
| | | } |
| | |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public ResultUtil<List<CouponPackageResp>> queryAppuserCouponList(@RequestBody CouponPackageReq req){ |
| | | public ResultUtil<List<CouponPackageResp>> queryAppuserCouponList( CouponPackageReq req){ |
| | | try { |
| | | Integer uid = tokenUtil.getUserIdFormRedis(); |
| | | if(null == uid){ |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | @PostMapping("/base/coupon/getAllCoupons") |
| | | public List<Coupon> getAllCoupons(@RequestBody CommodityRequest request){ |
| | | String provinceCode = ""; |
| | | String cityCode = ""; |
| | | try { |
| | | Map<String, String> geocode = gdMapGeocodingUtil.geocode(request.getLon(), request.getLat()); |
| | | provinceCode = geocode.get("provinceCode"); |
| | | cityCode = geocode.get("cityCode"); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | try { |
| | | Integer userAppId = tokenUtil.getUserIdFormRedis(); |
| | | List<UserCoupon> list = ucService.list(new QueryWrapper<UserCoupon>() |
| | | .eq("userId",userAppId )); |
| | | List<Coupon> couponList = couponService.list(new QueryWrapper<Coupon>() |
| | | .eq("auditStatus",2) |
| | | .eq("state",1) |
| | | .eq("status",2)); |
| | | if (couponList.size() > 0 ){ |
| | | Iterator<Coupon> iterator = couponList.iterator(); |
| | | while (iterator.hasNext()) { |
| | | Coupon merchandise = iterator.next(); |
| | | if (merchandise.getUseScope() == 2 && (!Objects.equals(merchandise.getCityCode(), cityCode) && !Objects.equals(merchandise.getProvinceCode(), provinceCode))) { |
| | | iterator.remove(); // 移除符合条件的商品 |
| | | } |
| | | } |
| | | } |
| | | return couponList; |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | } |
| | | |
| | | @PostMapping("/base/coupon/getRedeemedNums") |
| | | public int getRedeemedQuantity(@RequestBody Integer id){ |
| | | return ucService.count(new QueryWrapper<UserCoupon>() |
| | | .eq("couponId",id)); |
| | | } |
| | | |
| | | |
| | | @PostMapping("/base/coupon/insertToAppuserCoupon") |
| | | public void insertToAppuserCoupon(@RequestBody UserCoupon coupon){ |
| | | ucService.save(coupon); |
| | | } |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/coupon/queryCouponListSearch") |
| | | public List<Map<String,Object>> getCouponListOfSearch(@RequestBody CouponListOfSearch ofSearch){ |
| | | List<Map<String, Object>> mapList = couponService.queryCouponListOfSearch(ofSearch); |
| | | if (mapList.size() > 0){ |
| | | for (Map<String, Object> stringObjectMap : mapList) { |
| | | Integer o = (Integer) stringObjectMap.get("id"); |
| | | Object startTime = stringObjectMap.get("startTime"); |
| | | Object endTime = stringObjectMap.get("endTime"); |
| | | stringObjectMap.put("timeValue",startTime + "至"+endTime); |
| | | int count = ucService.count(new LambdaQueryWrapper<UserCoupon>() |
| | | .eq(UserCoupon::getCouponId, o)); |
| | | stringObjectMap.put("hasPickQty",count); |
| | | } |
| | | } |
| | | return mapList; |
| | | } |
| | | |
| | | |
| | | } |