|  | @@ -5,9 +5,11 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.auth.api.entity.SysUser;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.dao.UserOrderDao;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dto.ActivityPlanRewardDto;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dto.VipSubmitReq;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dto.req.OrderReq;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.dto.search.OrderSearch;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.entity.*;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.enums.*;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.entity.VipCardRecord;
 | 
	
	
		
			
				|  | @@ -31,6 +33,8 @@ import com.yonge.toolset.base.exception.BizException;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.base.string.MessageFormatter;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.utils.date.DateUtil;
 | 
	
		
			
				|  |  | +import jodd.time.TimeUtil;
 | 
	
		
			
				|  |  | +import org.joda.time.DateTime;
 | 
	
		
			
				|  |  |  import org.springframework.beans.BeanUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
	
		
			
				|  | @@ -68,6 +72,9 @@ public class MemberPriceSettingsServiceImpl extends ServiceImpl<MemberPriceSetti
 | 
	
		
			
				|  |  |      private UserOrderService userOrderService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  | +    private UserOrderDao userOrderDao;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  |      private RedisCacheService redisCacheService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
	
		
			
				|  | @@ -101,15 +108,11 @@ public class MemberPriceSettingsServiceImpl extends ServiceImpl<MemberPriceSetti
 | 
	
		
			
				|  |  |              return HttpResponseResult.failed("产品信息已更新,请重新选择");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        // 判断是否有待支付订单 如果有返回不可下单
 | 
	
		
			
				|  |  | +        checkOrder(orderReqInfo.getOrderClient(), orderReqInfo.getOrderType().name(), orderReqInfo.getUserId());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        // 判断会员剩余天数是否改变
 | 
	
		
			
				|  |  | -        if (detail.getVipType() == EVipType.SVIP) {
 | 
	
		
			
				|  |  | -            VipCardRecordWrapper.UserVip userVip = vipCardRecordService.UserVipInfo(orderReqInfo.getUserId(), orderReqInfo.getOrderClient());
 | 
	
		
			
				|  |  | -            if (!userVip.getVipEndDays().equals(orderReqInfo.getVipEndDays())) {
 | 
	
		
			
				|  |  | -                throw new BizException(998,"您当前VIP天数更新,请刷新后尝试");
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        checkVip(detail, orderReqInfo.getVipEndDays(), orderReqInfo.getUserId(), orderReqInfo.getOrderClient(), orderReqInfo.getGoodsNum());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          OrderCreateRes orderCreateRes = new OrderCreateRes();
 | 
	
		
			
				|  |  |          BigDecimal couponAmount = BigDecimal.ZERO;
 | 
	
	
		
			
				|  | @@ -142,6 +145,53 @@ public class MemberPriceSettingsServiceImpl extends ServiceImpl<MemberPriceSetti
 | 
	
		
			
				|  |  |          return HttpResponseResult.succeed(orderCreateRes);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    private void checkVip(MemberPriceSettingsVo detail, Integer vipDays, Long userId, ClientEnum client, Integer num) {
 | 
	
		
			
				|  |  | +        // 判断会员剩余天数是否改变
 | 
	
		
			
				|  |  | +        if (detail.getVipType() == EVipType.SVIP && vipDays != null && vipDays > 0) {
 | 
	
		
			
				|  |  | +            VipCardRecordWrapper.UserVip userVip = vipCardRecordService.UserVipInfo(userId, client);
 | 
	
		
			
				|  |  | +            if (!userVip.getVipEndDays().equals(vipDays)) {
 | 
	
		
			
				|  |  | +                throw new BizException(998, "您当前VIP天数更新,请刷新后尝试");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            // 判断能不能升级
 | 
	
		
			
				|  |  | +            // 按时间区分 个数
 | 
	
		
			
				|  |  | +            int days = getSvipDays(detail, num, userVip);
 | 
	
		
			
				|  |  | +            if (days < userVip.getVipEndDays()) {
 | 
	
		
			
				|  |  | +                throw new BizException(998, "您当前VIP天数更新,请刷新后尝试");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private int getSvipDays(MemberPriceSettingsVo detail, Integer num, VipCardRecordWrapper.UserVip userVip) {
 | 
	
		
			
				|  |  | +        Integer timeNum = num;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 判断当前时间 加 一段时间后,和当前天数比较
 | 
	
		
			
				|  |  | +        Date svipStartDate = new Date();
 | 
	
		
			
				|  |  | +        if (userVip.getSvipEndDate() != null) {
 | 
	
		
			
				|  |  | +            svipStartDate = userVip.getSvipEndDate();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        DateTime dateTime = DateTime.parse(DateUtil.format(svipStartDate, "yyyy-MM-dd"))
 | 
	
		
			
				|  |  | +            .withHourOfDay(23)
 | 
	
		
			
				|  |  | +            .withMinuteOfHour(59)
 | 
	
		
			
				|  |  | +            .withSecondOfMinute(59)
 | 
	
		
			
				|  |  | +            .withMillisOfSecond(0);
 | 
	
		
			
				|  |  | +        if (PeriodEnum.DAY.equals(detail.getPeriod())) {
 | 
	
		
			
				|  |  | +            dateTime=dateTime.plusDays(timeNum);
 | 
	
		
			
				|  |  | +        } else if (PeriodEnum.MONTH.equals(detail.getPeriod())) {
 | 
	
		
			
				|  |  | +            dateTime=dateTime.plusMonths(timeNum);
 | 
	
		
			
				|  |  | +        } else if (PeriodEnum.QUARTERLY.equals(detail.getPeriod())) {
 | 
	
		
			
				|  |  | +            dateTime=dateTime.plusMonths(3 * timeNum);
 | 
	
		
			
				|  |  | +        } else if (PeriodEnum.YEAR_HALF.equals(detail.getPeriod())) {
 | 
	
		
			
				|  |  | +            dateTime=dateTime.plusMonths(6 * timeNum);
 | 
	
		
			
				|  |  | +        } else if (PeriodEnum.YEAR.equals(detail.getPeriod())) {
 | 
	
		
			
				|  |  | +            dateTime=dateTime.plusYears(timeNum);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        Date date = dateTime.toDate();
 | 
	
		
			
				|  |  | +        // 比较两个时间 天数差
 | 
	
		
			
				|  |  | +        int days = DateUtil.daysBetween(svipStartDate, date);
 | 
	
		
			
				|  |  | +        return days;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public void orderSuccess(UserOrderDetailVo orderDetailVo) {
 | 
	
		
			
				|  |  |          orderSuccess(orderDetailVo,true);
 | 
	
	
		
			
				|  | @@ -158,7 +208,6 @@ public class MemberPriceSettingsServiceImpl extends ServiceImpl<MemberPriceSetti
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          VipCardRecordWrapper.AddVipCardRecord addVipCardRecord = new VipCardRecordWrapper.AddVipCardRecord();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        UserPaymentOrderWrapper.VipDays vipDays = JSON.parseObject(orderDetailVo.getBizJson(), UserPaymentOrderWrapper.VipDays.class);
 | 
	
		
			
				|  |  |          addVipCardRecord.setUserId(orderDetailVo.getUserId());
 | 
	
		
			
				|  |  |          addVipCardRecord.setClientType(orderDetailVo.getOrderClient());
 | 
	
		
			
				|  |  |          addVipCardRecord.setStatus(EVipRecordStatus.ADD);
 | 
	
	
		
			
				|  | @@ -171,8 +220,13 @@ public class MemberPriceSettingsServiceImpl extends ServiceImpl<MemberPriceSetti
 | 
	
		
			
				|  |  |          addVipCardRecord.setOrderNo(orderDetailVo.getOrderNo());
 | 
	
		
			
				|  |  |          addVipCardRecord.setSubOrderNo(orderDetailVo.getSubOrderNo());
 | 
	
		
			
				|  |  |          addVipCardRecord.setVipCardId(orderDetailVo.getBizId());
 | 
	
		
			
				|  |  | -        if (vipDays != null && vipDays.getVipEndDays() !=null && vipDays.getVipEndDays() >0) {
 | 
	
		
			
				|  |  | -            addVipCardRecord.setVipDays(vipDays.getVipEndDays());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 判断转换天数
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        VipCardRecordWrapper.UserVip userVip = vipCardRecordService.UserVipInfo(orderDetailVo.getUserId(), orderDetailVo.getOrderClient());
 | 
	
		
			
				|  |  | +        int svipDays = getSvipDays(detail, orderDetailVo.getGoodNum(), userVip);
 | 
	
		
			
				|  |  | +        if (detail.getVipType() == EVipType.SVIP &&userVip.getVipEndDays() !=null && svipDays >=userVip.getVipEndDays()) {
 | 
	
		
			
				|  |  | +            addVipCardRecord.setVipDays(userVip.getVipEndDays());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          addVipCardRecord.setReason("会员购买");
 | 
	
		
			
				|  |  |          vipCardRecordService.add(addVipCardRecord);
 | 
	
	
		
			
				|  | @@ -364,13 +418,11 @@ public class MemberPriceSettingsServiceImpl extends ServiceImpl<MemberPriceSetti
 | 
	
		
			
				|  |  |              throw new BizException("产品信息已更新,请重新选择");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        checkOrder(orderGoodsInfo.getPaymentClient(), detail.getVipType().name(), orderGoodsInfo.getUserId());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          // 判断会员剩余天数是否改变
 | 
	
		
			
				|  |  | -        if (detail.getVipType() == EVipType.SVIP) {
 | 
	
		
			
				|  |  | -            VipCardRecordWrapper.UserVip userVip = vipCardRecordService.UserVipInfo(orderGoodsInfo.getUserId(), orderGoodsInfo.getPaymentClient());
 | 
	
		
			
				|  |  | -            if (!userVip.getVipEndDays().equals(orderGoodsInfo.getVipEndDays())) {
 | 
	
		
			
				|  |  | -                throw new BizException(998, "您当前VIP天数更新,请刷新后尝试");
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        checkVip(detail, orderGoodsInfo.getVipEndDays(), orderGoodsInfo.getUserId(), orderGoodsInfo.getPaymentClient(), orderGoodsInfo.getGoodNum());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          BigDecimal couponAmount = BigDecimal.ZERO;
 | 
	
		
			
				|  |  |          ActivityPlanVo activityPlanVo = activityPlanService.detail(orderGoodsInfo.getActivityId());
 | 
	
	
		
			
				|  | @@ -409,6 +461,19 @@ public class MemberPriceSettingsServiceImpl extends ServiceImpl<MemberPriceSetti
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    private void checkOrder(ClientEnum orderGoodsInfo, String orderType, Long orderGoodsInfo1) {
 | 
	
		
			
				|  |  | +        // 判断是否有待支付订单 如果有返回不可下单
 | 
	
		
			
				|  |  | +        OrderSearch search = new OrderSearch();
 | 
	
		
			
				|  |  | +        search.setOrderClient(orderGoodsInfo.name());
 | 
	
		
			
				|  |  | +        search.setGoodType(orderType);
 | 
	
		
			
				|  |  | +        search.setUserId(orderGoodsInfo1);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        UserOrderVo userOrderVo = userOrderDao.getPendingOrder(search);
 | 
	
		
			
				|  |  | +        if (null != userOrderVo) {
 | 
	
		
			
				|  |  | +            throw new BizException(997, "您有未支付订单,请先支付");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      private void sendAddVipMessage(Long userId,String phone, ClientEnum client, Integer times, PeriodEnum type, String reason) {
 | 
	
		
			
				|  |  |          try {
 | 
	
		
			
				|  |  |              Map<Long, String> receivers = new HashMap<>();
 |