| | |
| | | import com.dsh.activity.feignclient.account.model.TStoreStaff; |
| | | import com.dsh.activity.feignclient.model.CouponExamineListSearch; |
| | | import com.dsh.activity.feignclient.model.CouponListOfSearch; |
| | | import com.dsh.activity.feignclient.other.OperatorClient; |
| | | import com.dsh.activity.feignclient.other.RegionClient; |
| | | import com.dsh.activity.feignclient.other.StoreClient; |
| | | import com.dsh.activity.feignclient.other.model.CityDataAndProvinceDataVo; |
| | | import com.dsh.activity.feignclient.other.model.Store; |
| | | import com.dsh.activity.feignclient.other.model.TOperatorCity; |
| | | import com.dsh.activity.model.CouponListVo; |
| | | import com.dsh.activity.model.CouponRecordQuery; |
| | | import com.dsh.activity.model.request.CommodityRequest; |
| | |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.checkerframework.checker.units.qual.A; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | @Autowired |
| | | private AppUserClient appUserClient; |
| | | |
| | | /** |
| | | * 查询注册赠送优惠券 判断当前优惠券限领数量 |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/coupon/queryCouponByUser/{userId}") |
| | | public List<Integer> queryCouponByUser(@PathVariable("userId") Integer userId){ |
| | | List<Coupon> list = couponService.list(new QueryWrapper<Coupon>().eq("distributionMethod", 2).eq("userPopulation",2) |
| | | .le("startTime", new Date()).ge("endTime", new Date()).eq("auditStatus", 2) |
| | | .eq("state", 1)); |
| | | |
| | | for (Coupon coupon : list) { |
| | | // 发放数量 |
| | | Integer quantityIssued = coupon.getQuantityIssued(); |
| | | // 限领数量 |
| | | Integer pickUpQuantity = coupon.getPickUpQuantity(); |
| | | // 优惠券已领取数量 |
| | | int couponId = ucService.count(new QueryWrapper<UserCoupon>().eq("couponId", coupon.getId())); |
| | | // 用户已领取该优惠券数量 |
| | | int count = ucService.count(new QueryWrapper<UserCoupon>().eq("couponId", coupon.getId() |
| | | ).eq("userId", userId)); |
| | | if (couponId>=quantityIssued){ |
| | | continue; |
| | | } |
| | | if (count>=pickUpQuantity){ |
| | | continue; |
| | | } |
| | | // 条件满足 将优惠券送给用户 |
| | | UserCoupon userCoupon = new UserCoupon(); |
| | | userCoupon.setCouponId(coupon.getId()); |
| | | userCoupon.setUserId(userId); |
| | | userCoupon.setStatus(1); |
| | | userCoupon.setInsertTime(new Date()); |
| | | ucService.save(userCoupon); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/api/coupon/queryCouponList") |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | try { |
| | | LocalDateTime currentDate = LocalDateTime.now(); |
| | | |
| | | couponList = couponService.list(new QueryWrapper<Coupon>() |
| | | .eq("auditStatus",2) |
| | | .eq("distributionMethod",1) |
| | | .eq("state",1) |
| | | .eq("status",2)); |
| | | .eq("status",1) |
| | | .le("startTime", currentDate) |
| | | .ge("endTime", currentDate)); |
| | | if (couponList.size() > 0 ){ |
| | | Iterator<Coupon> iterator = couponList.iterator(); |
| | | while (iterator.hasNext()) { |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | @Autowired |
| | | private OperatorClient operatorClient; |
| | | @ResponseBody |
| | | @PostMapping("/base/coupon/queryCouponListSearch") |
| | | public List<Map<String,Object>> getCouponListOfSearch(@RequestBody CouponListOfSearch ofSearch){ |
| | | List<Map<String, Object>> mapList = couponService.queryCouponListOfSearch(ofSearch); |
| | | List<Map<String, Object>> mapList1 = couponService.queryCouponListOfSearch(ofSearch); |
| | | List<Map<String, Object>> mapList = new ArrayList<>(); |
| | | if (ofSearch.getStoreIds()==null){ |
| | | ArrayList<Integer> list = new ArrayList<>(); |
| | | ofSearch.setStoreIds(list); |
| | | } |
| | | if(ofSearch.getStoreId()!=null || ofSearch.getStoreIds().size()!=0){ |
| | | for (Map<String, Object> map : mapList1) { |
| | | // 如果当前登陆人是运营商 只能查看平台添加的优惠券应只展示使用范围为全国通用、 |
| | | // 指定城市有运营商管辖的、指定门店有运营商旗下门店 |
| | | if (ofSearch.getObjType()== 2){ |
| | | if (Integer.parseInt(String.valueOf(map.get("useScope"))) == 1){ |
| | | mapList.add(map); |
| | | } |
| | | if (Integer.parseInt(String.valueOf(map.get("useScope"))) == 2){ |
| | | // 获取到优惠券id 查询这个优惠券指定了哪些城市 |
| | | Integer id = Integer.parseInt(String.valueOf(map.get("id"))); |
| | | // 获取到运营商管理的省和市 |
| | | List<TOperatorCity> cityByOperatorId = operatorClient.getCityByOperatorId(ofSearch.getOperatorId()); |
| | | // 拿到运营商市的code集合 |
| | | List<String> collect = cityByOperatorId.stream().filter(t -> t.getPid() != 0) |
| | | .map(tOperatorCity -> Integer.toString(tOperatorCity.getCode())) |
| | | .collect(Collectors.toList()); |
| | | List<CouponCity> couponId = cityService.list(new QueryWrapper<CouponCity>().eq("couponId", id)); |
| | | // 先判断优惠券管理的市 运营商是否有 |
| | | List<String> collect1 = couponId.stream().map(CouponCity::getCityCode) |
| | | .collect(Collectors.toList()); |
| | | // 优惠券指定的省 |
| | | List<String> collect2 = couponId.stream().map(CouponCity::getCityCode) |
| | | .collect(Collectors.toList()); |
| | | if (!Collections.disjoint(collect, collect1)){ |
| | | mapList.add(map); |
| | | }else{ |
| | | // 如果没有交集 那么还需要判断运营商是否管理了整个省 |
| | | |
| | | |
| | | } |
| | | } |
| | | if (Integer.parseInt(String.valueOf(map.get("useScope"))) == 3){ |
| | | // 获取到优惠券id 查询这个优惠券指定了哪些门店 |
| | | Integer id = Integer.parseInt(String.valueOf(map.get("id"))); |
| | | // 当前运营商管理的门店ids |
| | | List<Integer> storeIds = ofSearch.getStoreIds(); |
| | | // 优惠券指定的门店 |
| | | List<Integer> collect = couStoreService.list(new QueryWrapper<CouponStore>().eq("couponId",id) |
| | | .in("storeId", storeIds)).stream().map(CouponStore::getStoreId) |
| | | .collect(Collectors.toList()); |
| | | // 判断两个集合是否相交 |
| | | // 比较两个集合中是否有相同的元素;当两个集合中没有相同元素时返回true, |
| | | // 当有相同元素时返回false。 |
| | | if (!Collections.disjoint(collect, storeIds)){ |
| | | mapList.add(map); |
| | | } |
| | | } |
| | | }else{ |
| | | List<CouponStore> id = couStoreService.list(new LambdaQueryWrapper<CouponStore>() |
| | | .eq(CouponStore::getCouponId, map.get("id").toString())); |
| | | List<Integer> collect = id.stream().map(CouponStore::getStoreId).collect(Collectors.toList()); |
| | | if(collect.size()==0){ |
| | | collect.add(-1); |
| | | } |
| | | if(collect.contains(ofSearch.getStoreId())){ |
| | | if(collect.size()>1){ |
| | | map.put("size",1); |
| | | }else { |
| | | map.put("size",0); |
| | | } |
| | | mapList.add(map); |
| | | } |
| | | } |
| | | } |
| | | }else { |
| | | mapList = mapList1; |
| | | } |
| | | if (mapList.size() > 0){ |
| | | for (Map<String, Object> stringObjectMap : mapList) { |
| | | Integer o = (Integer) stringObjectMap.get("id"); |
| | |
| | | return mapList; |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/coupon/queryCouponListSearch1") |
| | | public List<Map<String,Object>> getCouponListOfSearch1(@RequestBody CouponListOfSearch ofSearch){ |
| | | List<Map<String, Object>> mapList = couponService.queryCouponListOfSearch1(ofSearch); |
| | | |
| | | Date currentDate = new Date(); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String currentDateStr = sdf.format(currentDate); |
| | | |
| | | // Iterate over the mapList and remove entries where endTime is less than the current date |
| | | Iterator<Map<String, Object>> iterator = mapList.iterator(); |
| | | while (iterator.hasNext()) { |
| | | Map<String, Object> map = iterator.next(); |
| | | String endTime = (String) map.get("endTime"); |
| | | if (endTime.compareTo(currentDateStr) < 0) { |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | |
| | | |
| | | 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; |
| | | } |
| | | @ResponseBody |
| | | @PostMapping("/base/coupon/couponExamineListSearch") |
| | | public List<Map<String,Object>> getCouponExamineListOfSearch(@RequestBody CouponExamineListSearch ofSearch){ |
| | |
| | | Object endTime = stringObjectMap.get("endTime"); |
| | | stringObjectMap.put("timeValue",startTime + "至"+endTime); |
| | | Integer publisherType = (Integer) stringObjectMap.get("publisherType"); |
| | | if ( publisherType == 1) { |
| | | Integer cityManagerId = (Integer) stringObjectMap.get("cityManagerId"); |
| | | TCityManager byId = citClient.getById(cityManagerId); |
| | | stringObjectMap.put("province", byId.getProvince()); |
| | | stringObjectMap.put("city", byId.getCity()); |
| | | if (publisherType!=null) { |
| | | if (publisherType == 1) { |
| | | Integer cityManagerId = (Integer) stringObjectMap.get("cityManagerId"); |
| | | TCityManager byId = citClient.getById(cityManagerId); |
| | | stringObjectMap.put("province", byId.getProvince()); |
| | | |
| | | stringObjectMap.put("city", byId.getCity()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | coupon.setAuditStatus(1); |
| | | coupon.setStatus(1); |
| | | coupon.setState(2); |
| | | coupon.setState(1); |
| | | coupon.setInsertTime(new Date()); |
| | | coupon.setCover(dataVo.getGoodImg()); |
| | | String goodImgs = dataVo.getGoodImgs(); |
| | |
| | | coupon.setPublisherType(1); |
| | | coupon.setCityManagerId(dataVo.getCityManagerId()); |
| | | } |
| | | if(dataVo.getObjType()!=1){ |
| | | coupon.setAuditStatus(1); |
| | | } |
| | | if (dataVo.getUserType()==1){ |
| | | coupon.setAuditStatus(2); |
| | | }else{ |
| | | coupon.setAuditStatus(1); |
| | | } |
| | | if(dataVo.getObjType()!=1){ |
| | | coupon.setAuditStatus(1); |
| | | } |
| | | |
| | | boolean save = couponService.save(coupon); |
| | | if (save){ |
| | | if (dataVo.getCompany() == 3){ |