|  | @@ -2,10 +2,15 @@ package com.yonge.cooleshow.biz.dal.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.dao.MemberPriceSettingsDao;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.entity.MemberPriceSettings;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.enums.MessageTypeEnum;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.biz.dal.service.MemberPriceSettingsService;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.biz.dal.service.SysMessageService;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.enums.PeriodEnum;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.service.*;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.vo.MemberPriceSettingsVo;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.vo.StudentVo;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
 | 
	
		
			
				|  |  |  import org.slf4j.Logger;
 | 
	
		
			
				|  |  |  import org.slf4j.LoggerFactory;
 | 
	
	
		
			
				|  | @@ -16,12 +21,8 @@ import com.yonge.cooleshow.biz.dal.entity.VipCardRecord;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.vo.VipCardRecordVo;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dto.search.VipCardRecordSearch;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dao.VipCardRecordDao;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.biz.dal.service.VipCardRecordService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -import java.util.Date;
 | 
	
		
			
				|  |  | -import java.util.HashMap;
 | 
	
		
			
				|  |  | -import java.util.List;
 | 
	
		
			
				|  |  | -import java.util.Map;
 | 
	
		
			
				|  |  | +import java.util.*;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  @Service
 | 
	
	
		
			
				|  | @@ -30,6 +31,14 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private SysMessageService sysMessageService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private MemberPriceSettingsDao memberPriceSettingsDao;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private StudentService studentService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private MemberPriceSettingsService memberPriceSettingsService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private UserOrderDetailService orderDetailService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public VipCardRecordVo detail(Long orderDetilId) {
 | 
	
	
		
			
				|  | @@ -38,7 +47,69 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public VipCardRecordVo detail(Long orderDetilId, Long userId) {
 | 
	
		
			
				|  |  | -        return baseMapper.detail(orderDetilId, userId);
 | 
	
		
			
				|  |  | +        VipCardRecordVo detail = baseMapper.detail(orderDetilId, userId);
 | 
	
		
			
				|  |  | +        if (null == detail && null != userId) {
 | 
	
		
			
				|  |  | +            detail = new VipCardRecordVo();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            UserOrderDetailVo orderDetailVo = orderDetailService.detail(orderDetilId);
 | 
	
		
			
				|  |  | +            VipCardRecord vipCardRecord = buildVipCardRecordByOrderDetail(orderDetailVo);
 | 
	
		
			
				|  |  | +            if (null == vipCardRecord) {
 | 
	
		
			
				|  |  | +                return detail;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            BeanUtils.copyProperties(vipCardRecord, detail);
 | 
	
		
			
				|  |  | +            MemberPriceSettings memberPrice = memberPriceSettingsDao.getMemberPriceByOrderDetilId(orderDetilId);
 | 
	
		
			
				|  |  | +            detail.setOriginalPrice(memberPrice.getOriginalPrice());
 | 
	
		
			
				|  |  | +            detail.setSalePrice(memberPrice.getSalePrice());
 | 
	
		
			
				|  |  | +            detail.setPeriod(memberPrice.getPeriod());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return detail;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public VipCardRecord buildVipCardRecordByOrderDetail(UserOrderDetailVo orderDetailVo) {
 | 
	
		
			
				|  |  | +        if (null == orderDetailVo) {
 | 
	
		
			
				|  |  | +            return null;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        MemberPriceSettingsVo detail = memberPriceSettingsService.detail(orderDetailVo.getBizId());
 | 
	
		
			
				|  |  | +        if (null == detail) {
 | 
	
		
			
				|  |  | +            return null;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        StudentVo studentVo = studentService.detail(orderDetailVo.getUserId());
 | 
	
		
			
				|  |  | +        if (null == studentVo) {
 | 
	
		
			
				|  |  | +            return null;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //修改用户会员时长
 | 
	
		
			
				|  |  | +        Date membershipEndTime = studentVo.getMembershipEndTime();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        VipCardRecord vipCardRecord = new VipCardRecord();
 | 
	
		
			
				|  |  | +        vipCardRecord.setUserId(orderDetailVo.getUserId());
 | 
	
		
			
				|  |  | +        vipCardRecord.setOrderNo(orderDetailVo.getOrderNo());
 | 
	
		
			
				|  |  | +        vipCardRecord.setSubOrderNo(orderDetailVo.getSubOrderNo());
 | 
	
		
			
				|  |  | +        vipCardRecord.setVipCardId(detail.getId());
 | 
	
		
			
				|  |  | +        vipCardRecord.setMsgStatus(0);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (null == membershipEndTime || membershipEndTime.before(new Date())) {
 | 
	
		
			
				|  |  | +            //没有会员、会员已过期 会员卡生效时间为当前时间
 | 
	
		
			
				|  |  | +            vipCardRecord.setStartTime(new Date());
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            vipCardRecord.setStartTime(membershipEndTime);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        Calendar cal = Calendar.getInstance();
 | 
	
		
			
				|  |  | +        cal.setTime(vipCardRecord.getStartTime());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (PeriodEnum.DAY.equals(detail.getPeriod())) {
 | 
	
		
			
				|  |  | +            cal.add(Calendar.DAY_OF_MONTH, 1);
 | 
	
		
			
				|  |  | +        } else if (PeriodEnum.MONTH.equals(detail.getPeriod())) {
 | 
	
		
			
				|  |  | +            cal.add(Calendar.MONTH, 1);
 | 
	
		
			
				|  |  | +        } else if (PeriodEnum.QUARTERLY.equals(detail.getPeriod())) {
 | 
	
		
			
				|  |  | +            cal.add(Calendar.MONTH, 3);
 | 
	
		
			
				|  |  | +        } else if (PeriodEnum.YEAR_HALF.equals(detail.getPeriod())) {
 | 
	
		
			
				|  |  | +            cal.add(Calendar.MONTH, 6);
 | 
	
		
			
				|  |  | +        } else if (PeriodEnum.YEAR.equals(detail.getPeriod())) {
 | 
	
		
			
				|  |  | +            cal.add(Calendar.YEAR, 1);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        vipCardRecord.setEndTime(cal.getTime());
 | 
	
		
			
				|  |  | +        return vipCardRecord;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
	
		
			
				|  | @@ -88,7 +159,6 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      // 发送会员到期3天消息推送
 | 
	
		
			
				|  |  |      private void temporary3DaysSend(Long userId, String phone) {
 | 
	
		
			
				|  |  |          Map<Long, String> receivers = new HashMap<>();
 |