| | |
| | | package com.xiaopeng.operation.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xiaopeng.api.dto.account.UcUserInfo; |
| | | import com.xiaopeng.api.dto.operation.XpActivityDto; |
| | | import com.xiaopeng.api.feignClient.account.UserResourcesClient; |
| | | import com.xiaopeng.api.feignClient.account.XpAppUserCouponClient; |
| | | import com.xiaopeng.api.feignClient.order.XpOrderClient; |
| | | import com.xiaopeng.api.model.account.XpAppUserCoupon; |
| | | import com.xiaopeng.api.model.operation.*; |
| | | import com.xiaopeng.api.query.operation.XpActivityPageListQuery; |
| | | import com.xiaopeng.api.vo.account.AppUserCouponSaveBatchVo; |
| | | import com.xiaopeng.common.core.utils.bean.BeanUtils; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | import com.xiaopeng.operation.mapper.XpActicityMapper; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.function.Function; |
| | |
| | | private IXpActicityUserService userService; |
| | | |
| | | @Resource |
| | | private IXpActivityNoticeService activityNotice; |
| | | |
| | | @Resource |
| | | private XpOrderClient xpOrderClient; |
| | | |
| | | @Resource |
| | | private IXpActicityStrategyService xpActicityStrategyService; |
| | | |
| | | @Resource |
| | | private IXpActicityService xpActicityService; |
| | | |
| | | @Resource |
| | | private IXpActicityUserService xpActicityUserService; |
| | | |
| | | @Resource |
| | | private IXpWhitelistService xpWhitelistService; |
| | | |
| | | @Resource |
| | | private IXpActicityCouponService xpActicityCouponService; |
| | | |
| | | @Resource |
| | | private IXpCouponService xpCouponService; |
| | | |
| | | @Resource |
| | | private XpAppUserCouponClient xpAppUserCouponClient; |
| | | |
| | | @Resource |
| | | private UserResourcesClient userResourcesClient; |
| | | |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public XpActivity activiting(Long uid) { |
| | | public List<XpActivity> activiting(Long uid) { |
| | | //获取当前用户可参与的活动 |
| | | List<Integer> actitctiyIds = new ArrayList<>(); |
| | | //全部用户 |
| | |
| | | .last(" and JSON_CONTAINS(user_list, '" + uid + "', '$')")); |
| | | actitctiyIds.addAll(list.stream().map(XpActicityUser::getActitcityId).collect(Collectors.toList())); |
| | | |
| | | XpActivity one = this.getOne(new QueryWrapper<XpActivity>().eq("status", 2).eq("is_deleted", 0) |
| | | List<XpActivity> one = this.list(new QueryWrapper<XpActivity>().eq("status", 2).eq("is_deleted", 0) |
| | | .eq("mini_program_notification", 1).in(!actitctiyIds.isEmpty(), "id", actitctiyIds) |
| | | .last(" and now() between start_time and end_time order by float_window_priority desc limit 1")); |
| | | .last(" and now() between start_time and end_time")); |
| | | return one; |
| | | } |
| | | |
| | |
| | | xpActicityUser.setActitcityStrategeId(strategyMap.get(xpActicityUser.getStrategyName()).getId()); |
| | | userService.save(xpActicityUser); |
| | | } |
| | | |
| | | //执行修改活动状态 |
| | | updateStatus(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | .last(" and now() between start_time and end_time order by float_window_priority desc limit 1")); |
| | | return one; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void updateStatus() { |
| | | List<XpActivity> list = xpActicityService.list(new QueryWrapper<XpActivity>().in("status", Arrays.asList(1, 2)).eq("is_deleted", 0)); |
| | | for (XpActivity xpActivity : list) { |
| | | Integer status = xpActivity.getStatus(); |
| | | if(1 == status && LocalDateTime.now().isAfter(xpActivity.getStartTime()) && LocalDateTime.now().isBefore(xpActivity.getEndTime())){ |
| | | xpActivity.setStatus(2); |
| | | //发放优惠券-发放一次的优惠券 |
| | | List<XpActicityStrategy> list1 = xpActicityStrategyService.list(new QueryWrapper<XpActicityStrategy>().eq("actitcity_id", xpActivity.getId()) |
| | | .eq("distribution_rules", 2)); |
| | | for (XpActicityStrategy xpActicityStrategy : list1) { |
| | | List<XpActicityCoupon> acticityCoupons = xpActicityCouponService.list(new QueryWrapper<XpActicityCoupon>().eq("acticity_strategy_id", xpActicityStrategy.getId())); |
| | | List<XpCoupon> xpCoupons = xpCouponService.listByIds(acticityCoupons.stream().map(XpActicityCoupon::getCouponId).collect(Collectors.toList())); |
| | | //总发放数量 |
| | | Integer distributionsTotal = xpActicityStrategy.getDistributionsTotal(); |
| | | //没人限量数量 |
| | | Integer limitNumber = xpActicityStrategy.getLimitNumber(); |
| | | List<XpActicityUser> list2 = xpActicityUserService.list(new QueryWrapper<XpActicityUser>().eq("actitcity_stratege_id", xpActicityStrategy.getId())); |
| | | for (XpActicityUser xpActicityUser : list2) { |
| | | Integer userType = xpActicityUser.getUserType(); |
| | | //全部白名单用户 |
| | | if(1 == userType){ |
| | | List<XpWhitelist> list3 = xpWhitelistService.list(new QueryWrapper<XpWhitelist>().eq("is_deleted", 0).eq("status", 1)); |
| | | List<XpAppUserCoupon> xpAppUserCoupons = new ArrayList<>(); |
| | | for (XpWhitelist xpWhitelist : list3) { |
| | | for (XpActicityCoupon acticityCoupon : acticityCoupons) { |
| | | XpCoupon xpCoupon = xpCoupons.stream().filter(s -> s.getId().equals(acticityCoupon.getCouponId())).findFirst().orElse(null); |
| | | if(null != xpCoupon){ |
| | | for (Integer i = 0; i < limitNumber; i++) { |
| | | XpAppUserCoupon xpAppUserCoupon = new XpAppUserCoupon(); |
| | | xpAppUserCoupon.setFullMoney(xpCoupon.getConditionalAmount()); |
| | | xpAppUserCoupon.setMoney(xpCoupon.getAmount()); |
| | | |
| | | Integer expireRules = xpActicityStrategy.getExpireRules(); |
| | | //次日0点失效 |
| | | if(1 == expireRules){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime localDateTime = now.plusDays(1); |
| | | LocalDateTime localDateTime1 = localDateTime.withHour(0).withMinute(0).withSecond(0); |
| | | xpAppUserCoupon.setExpirationTime(localDateTime1); |
| | | } |
| | | //指定有效天数 |
| | | if(2 == expireRules){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | xpAppUserCoupon.setExpirationTime(now.plusDays(xpActicityStrategy.getExpireDays())); |
| | | } |
| | | //指定日期失效 |
| | | if(3 == expireRules){ |
| | | String format = xpActicityStrategy.getExpireDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | LocalDateTime localDateTime = LocalDateTime.parse(format + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | xpAppUserCoupon.setExpirationTime(localDateTime); |
| | | } |
| | | |
| | | xpAppUserCoupon.setCouponId(acticityCoupon.getCouponId()); |
| | | xpAppUserCoupon.setAppUserId(xpWhitelist.getAppUserId()); |
| | | xpAppUserCoupon.setStatus(1); |
| | | xpAppUserCoupon.setActivityId(xpActivity.getId()); |
| | | xpAppUserCoupon.setCouponName(xpCoupon.getCouponName()); |
| | | xpAppUserCoupon.setDeleted(false); |
| | | xpAppUserCoupon.setCreateTime(LocalDateTime.now()); |
| | | xpAppUserCoupon.setUpdateTime(LocalDateTime.now()); |
| | | xpAppUserCoupon.setPhone(xpWhitelist.getAccount()); |
| | | xpAppUserCoupon.setTimeJson(JSON.toJSONString(xpActicityStrategy.getUsagePeriod())); |
| | | xpAppUserCoupons.add(xpAppUserCoupon); |
| | | if(null == distributionsTotal){ |
| | | continue; |
| | | } |
| | | distributionsTotal--; |
| | | if(distributionsTotal <= 0){ |
| | | break; |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | if(null == distributionsTotal){ |
| | | continue; |
| | | } |
| | | if(distributionsTotal <= 0){ |
| | | break; |
| | | } |
| | | } |
| | | if(!xpAppUserCoupons.isEmpty()){ |
| | | AppUserCouponSaveBatchVo vo = new AppUserCouponSaveBatchVo(); |
| | | vo.setXpAppUserCoupons(xpAppUserCoupons); |
| | | xpAppUserCouponClient.saveBatch(vo); |
| | | } |
| | | if(null == distributionsTotal){ |
| | | continue; |
| | | } |
| | | if(distributionsTotal <= 0){ |
| | | break; |
| | | } |
| | | } |
| | | //老用户 |
| | | if(2 == userType || 3 == userType || 4 == userType){ |
| | | List<Long> longList = xpOrderClient.getUserTypeIdList(userType).getData(); |
| | | List<XpAppUserCoupon> xpAppUserCoupons = new ArrayList<>(); |
| | | for (Long userId : longList) { |
| | | UcUserInfo baseUserByUid = userResourcesClient.getBaseUserByUid(userId.toString()); |
| | | for (XpActicityCoupon acticityCoupon : acticityCoupons) { |
| | | XpCoupon xpCoupon = xpCoupons.stream().filter(s -> s.getId().equals(acticityCoupon.getCouponId())).findFirst().orElse(null); |
| | | if(null != xpCoupon){ |
| | | for (Integer i = 0; i < limitNumber; i++) { |
| | | XpAppUserCoupon xpAppUserCoupon = new XpAppUserCoupon(); |
| | | xpAppUserCoupon.setFullMoney(xpCoupon.getConditionalAmount()); |
| | | xpAppUserCoupon.setMoney(xpCoupon.getAmount()); |
| | | |
| | | Integer expireRules = xpActicityStrategy.getExpireRules(); |
| | | //次日0点失效 |
| | | if(1 == expireRules){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime localDateTime = now.plusDays(1); |
| | | LocalDateTime localDateTime1 = localDateTime.withHour(0).withMinute(0).withSecond(0); |
| | | xpAppUserCoupon.setExpirationTime(localDateTime1); |
| | | } |
| | | //指定有效天数 |
| | | if(2 == expireRules){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | xpAppUserCoupon.setExpirationTime(now.plusDays(xpActicityStrategy.getExpireDays())); |
| | | } |
| | | //指定日期失效 |
| | | if(3 == expireRules){ |
| | | String format = xpActicityStrategy.getExpireDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | LocalDateTime localDateTime = LocalDateTime.parse(format + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | xpAppUserCoupon.setExpirationTime(localDateTime); |
| | | } |
| | | |
| | | xpAppUserCoupon.setCouponId(acticityCoupon.getCouponId()); |
| | | xpAppUserCoupon.setAppUserId(userId); |
| | | xpAppUserCoupon.setStatus(1); |
| | | xpAppUserCoupon.setActivityId(xpActivity.getId()); |
| | | xpAppUserCoupon.setCouponName(xpCoupon.getCouponName()); |
| | | xpAppUserCoupon.setDeleted(false); |
| | | xpAppUserCoupon.setCreateTime(LocalDateTime.now()); |
| | | xpAppUserCoupon.setUpdateTime(LocalDateTime.now()); |
| | | xpAppUserCoupon.setPhone(baseUserByUid.getMobile()); |
| | | xpAppUserCoupon.setTimeJson(JSON.toJSONString(xpActicityStrategy.getUsagePeriod())); |
| | | xpAppUserCoupons.add(xpAppUserCoupon); |
| | | if(null == distributionsTotal){ |
| | | continue; |
| | | } |
| | | distributionsTotal--; |
| | | if(distributionsTotal <= 0){ |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if(null == distributionsTotal){ |
| | | continue; |
| | | } |
| | | if(distributionsTotal <= 0){ |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if(!xpAppUserCoupons.isEmpty()){ |
| | | AppUserCouponSaveBatchVo vo = new AppUserCouponSaveBatchVo(); |
| | | vo.setXpAppUserCoupons(xpAppUserCoupons); |
| | | xpAppUserCouponClient.saveBatch(vo); |
| | | } |
| | | if(null == distributionsTotal){ |
| | | continue; |
| | | } |
| | | if(distributionsTotal <= 0){ |
| | | break; |
| | | } |
| | | } |
| | | //指定用户 |
| | | if(5 == userType){ |
| | | List<Long> userList = xpActicityUser.getUserList(); |
| | | List<XpAppUserCoupon> xpAppUserCoupons = new ArrayList<>(); |
| | | for (Long userId : userList) { |
| | | UcUserInfo baseUserByUid = userResourcesClient.getBaseUserByUid(userId.toString()); |
| | | for (XpActicityCoupon acticityCoupon : acticityCoupons) { |
| | | XpCoupon xpCoupon = xpCoupons.stream().filter(s -> s.getId().equals(acticityCoupon.getCouponId())).findFirst().orElse(null); |
| | | if(null != xpCoupon){ |
| | | for (Integer i = 0; i < limitNumber; i++) { |
| | | XpAppUserCoupon xpAppUserCoupon = new XpAppUserCoupon(); |
| | | xpAppUserCoupon.setFullMoney(xpCoupon.getConditionalAmount()); |
| | | xpAppUserCoupon.setMoney(xpCoupon.getAmount()); |
| | | |
| | | Integer expireRules = xpActicityStrategy.getExpireRules(); |
| | | //次日0点失效 |
| | | if(1 == expireRules){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime localDateTime = now.plusDays(1); |
| | | LocalDateTime localDateTime1 = localDateTime.withHour(0).withMinute(0).withSecond(0); |
| | | xpAppUserCoupon.setExpirationTime(localDateTime1); |
| | | } |
| | | //指定有效天数 |
| | | if(2 == expireRules){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | xpAppUserCoupon.setExpirationTime(now.plusDays(xpActicityStrategy.getExpireDays())); |
| | | } |
| | | //指定日期失效 |
| | | if(3 == expireRules){ |
| | | String format = xpActicityStrategy.getExpireDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | LocalDateTime localDateTime = LocalDateTime.parse(format + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | xpAppUserCoupon.setExpirationTime(localDateTime); |
| | | } |
| | | |
| | | xpAppUserCoupon.setCouponId(acticityCoupon.getCouponId()); |
| | | xpAppUserCoupon.setAppUserId(userId); |
| | | xpAppUserCoupon.setStatus(1); |
| | | xpAppUserCoupon.setActivityId(xpActivity.getId()); |
| | | xpAppUserCoupon.setCouponName(xpCoupon.getCouponName()); |
| | | xpAppUserCoupon.setDeleted(false); |
| | | xpAppUserCoupon.setCreateTime(LocalDateTime.now()); |
| | | xpAppUserCoupon.setUpdateTime(LocalDateTime.now()); |
| | | xpAppUserCoupon.setPhone(baseUserByUid.getMobile()); |
| | | xpAppUserCoupon.setTimeJson(JSON.toJSONString(xpActicityStrategy.getUsagePeriod())); |
| | | xpAppUserCoupons.add(xpAppUserCoupon); |
| | | if(null == distributionsTotal){ |
| | | continue; |
| | | } |
| | | distributionsTotal--; |
| | | if(distributionsTotal <= 0){ |
| | | break; |
| | | } |
| | | } |
| | | |
| | | } |
| | | if(null == distributionsTotal){ |
| | | continue; |
| | | } |
| | | if(distributionsTotal <= 0){ |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if(null == distributionsTotal){ |
| | | continue; |
| | | } |
| | | if(distributionsTotal <= 0){ |
| | | break; |
| | | } |
| | | } |
| | | if(!xpAppUserCoupons.isEmpty()){ |
| | | AppUserCouponSaveBatchVo vo = new AppUserCouponSaveBatchVo(); |
| | | vo.setXpAppUserCoupons(xpAppUserCoupons); |
| | | xpAppUserCouponClient.saveBatch(vo); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | }else if(2 == status & LocalDateTime.now().isAfter(xpActivity.getEndTime())){ |
| | | xpActivity.setStatus(3); |
| | | } |
| | | xpActicityService.updateById(xpActivity); |
| | | } |
| | | } |
| | | } |