935090232@qq.com
2021-04-03 00efd2e4db8157ece4116c956c314803ed073042
zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysVipInfoServiceImpl.java
@@ -3,7 +3,10 @@
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.*;
import com.matrix.core.tools.DateUtil;
import com.matrix.core.tools.EncrypUtil;
import com.matrix.core.tools.StringUtils;
import com.matrix.core.tools.WebUtil;
import com.matrix.core.tools.excl.ExcelSheetPO;
import com.matrix.core.tools.excl.ExcelUtil;
import com.matrix.system.app.dto.AddVipDto;
@@ -11,17 +14,24 @@
import com.matrix.system.app.dto.VipInfoListDto;
import com.matrix.system.app.vo.VipInfoDetailVo;
import com.matrix.system.app.vo.VipInfoListVo;
import com.matrix.system.common.bean.BusParameterSettings;
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.common.dao.BusParameterSettingsDao;
import com.matrix.system.common.tools.DataAuthUtil;
import com.matrix.system.common.tools.ServiceUtil;
import com.matrix.system.constance.Dictionary;
import com.matrix.system.constance.TableMapping;
import com.matrix.system.hive.action.util.QueryUtil;
import com.matrix.system.hive.bean.*;
import com.matrix.system.hive.dao.*;
import com.matrix.system.hive.plugin.util.CollectionUtils;
import com.matrix.system.hive.pojo.VipInfoVo;
import com.matrix.system.hive.service.SysVipInfoService;
import com.matrix.system.score.constant.ScoreSettingConstant;
import com.matrix.system.score.entity.ScoreVipDetail;
import com.matrix.system.score.service.ScoreVipDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -58,13 +68,25 @@
   @Autowired
   private SysVipLabelDao sysVipLabelDao;
   @Value("${default.vip.photo.woman}")
   String defaultWoman;
   @Value("${default.vip.photo.man}")
   String defaultMan;
   @Autowired
   BusParameterSettingsDao busParameterSettingsDao;
   @Autowired
   ScoreVipDetailService scoreVipDetailService;
   /**
    * 新增会员储值卡
    * @param vipId
    * @return
    */
   @Override
   public  int addVipDefaultCard(Long vipId){
   public MoneyCardUse addVipDefaultCard(Long vipId){
      MoneyCardUse defaultCardUse=new MoneyCardUse();
      defaultCardUse.setVipId(vipId);
      defaultCardUse.setCardName("储值卡");
@@ -73,7 +95,8 @@
      defaultCardUse.setGiftMoney(0D);
      defaultCardUse.setSource("-");
      defaultCardUse.setStatus(Dictionary.MONEYCARD_STATUS_YX);
      return  moneyCardUseDao.insert(defaultCardUse);
      moneyCardUseDao.insert(defaultCardUse);
      return  defaultCardUse;
   }
@@ -104,6 +127,11 @@
      sysVipInfo.setPointAll(0);
      sysVipInfo.setIsDeal(SysVipInfo.UNDEAL_VIP);
      sysVipInfo.setZjm(StringUtils.toHanyuPinyin(sysVipInfo.getVipName())+","+StringUtils.toHeadWordHanyuPinyin(sysVipInfo.getVipName()));
      if(sysVipInfo.getSex().equals(Dictionary.SEX_MAN)){
         sysVipInfo.setPhoto(defaultMan);
      }else{
         sysVipInfo.setPhoto(defaultWoman);
      }
      int i=sysVipInfoDao.insert(sysVipInfo);
      modifyVipWithOtherInfo(sysVipInfo);
      //创建用户默认储值卡
@@ -197,8 +225,7 @@
   @Override
   public List<SysVipInfo> findByVipNoOrTel(String key) {
      SysUsers users = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
      return sysVipInfoDao.selectByVipNoOrTel(key, users.getShopId());
      return sysVipInfoDao.selectByVipNoOrTel(key);
   }
@@ -279,8 +306,8 @@
   @Override
   public List<SysVipInfo> findUserByKey(String keyWord) {
      SysUsers users = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
      return sysVipInfoDao.selectUserByKey(keyWord, users.getShopId());
      SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
      return sysVipInfoDao.selectUserByKey(keyWord,user.getCompanyId());
   }
   
@@ -336,6 +363,11 @@
      SysUsers users = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY);
      sysVipInfo.setCompanyId(users.getCompanyId());
      sysVipInfo.setShopId(users.getShopId());
      if(sysVipInfo.getSex().equals(Dictionary.SEX_MAN)){
         sysVipInfo.setPhoto(defaultMan);
      }else{
         sysVipInfo.setPhoto(defaultWoman);
      }
      int i=sysVipInfoDao.insert(sysVipInfo);
      modifyVipWithOtherInfo(sysVipInfo);
      return i;
@@ -424,6 +456,7 @@
      if (!DataAuthUtil.hasAllShopAuth()) {
         vipInfoListDto.setShopId(sysUsers.getShopId());
      }
      QueryUtil.setQueryLimitCom(vipInfoListDto);
      return sysVipInfoDao.selectVipAddressBookByList(vipInfoListDto);
   }
@@ -433,12 +466,15 @@
   }
   @Override
   @Transactional
   public int apiAddVip(AddVipDto addVipDto) {
      SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
      if (serviceUtil.addCheckRepeatTowColumn(TableMapping.SYS_VIP_INFO, "VIP_NO", addVipDto.getVipNo(),
            "company_id",user.getCompanyId())) {
         throw new GlobleException("编号已存在!");
      if (StringUtils.isNotBlank(addVipDto.getVipNo())) {
         if (serviceUtil.addCheckRepeatTowColumn(TableMapping.SYS_VIP_INFO, "VIP_NO", addVipDto.getVipNo(),
               "company_id", user.getCompanyId())) {
            throw new GlobleException("编号已存在!");
         }
      }
      if (serviceUtil.addCheckRepeatTowColumn(TableMapping.SYS_VIP_INFO, "PHONE", addVipDto.getPhone(),
@@ -447,6 +483,8 @@
      }
      SysVipInfo vipInfo = new SysVipInfo();
      vipInfo.setPhoto(addVipDto.getPhoto());
      vipInfo.setVipName(addVipDto.getVipName());
      vipInfo.setVipNo(addVipDto.getVipNo());
      vipInfo.setSex(addVipDto.getSex());
@@ -455,6 +493,7 @@
      vipInfo.setAddr(addVipDto.getAddress());
      vipInfo.setRemark(addVipDto.getRemark());
      vipInfo.setBirthday1(addVipDto.getBirthday());
      vipInfo.setPassWord(addVipDto.getPassword());
      vipInfo.setRecommendId(addVipDto.getRecommendId());
      if (StringUtils.isNotBlank(addVipDto.getAreas())) {
@@ -476,15 +515,69 @@
      vipInfo.setPointAll(0);
      vipInfo.setIsDeal(SysVipInfo.UNDEAL_VIP);
      vipInfo.setZjm(StringUtils.toHanyuPinyin(vipInfo.getVipName())+","+StringUtils.toHeadWordHanyuPinyin(vipInfo.getVipName()));
      if(vipInfo.getSex().equals(Dictionary.SEX_MAN)){
         vipInfo.setPhoto(defaultMan);
      }else{
         vipInfo.setPhoto(defaultWoman);
      }
      int i=sysVipInfoDao.insert(vipInfo);
      if (CollectionUtils.isNotEmpty(addVipDto.getLabels())) {
         batchInsertLabel(addVipDto.getLabels(), user.getSuName(), vipInfo.getId());
         batchInsertLabel(addVipDto.getLabels(), vipInfo.getId());
      }
      //添加推荐人积分
      addReferrerVipScore(vipInfo);
      //创建用户默认储值卡
      addVipDefaultCard(vipInfo.getId());
      return i;
   }
   /**
    * 添加推荐人积分
    * @param vipInfo
    */
   public void addReferrerVipScore(SysVipInfo vipInfo) {
      if(vipInfo.getRecommendId()!=null){
         SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
         BusParameterSettings referrerScoreSetting = busParameterSettingsDao.selectCompanyParamByCode(ScoreSettingConstant.REFERRALS_CONSUMPTION, user.getCompanyId());
         //推荐注册老带新积分奖励
         SysVipInfo referrerVip = sysVipInfoDao.selectById(vipInfo.getRecommendId());
         if(StringUtils.isNotBlank(referrerScoreSetting.getParamValue())){
            scoreVipDetailService.addScore(referrerVip.getOpenId(),
                  referrerVip.getId(),
                  user.getSuId(),
                  vipInfo.getShopId(),
                  Integer.parseInt(referrerScoreSetting.getParamValue()),
                  vipInfo.getId(),
                  ScoreVipDetail.SCORE_VIP_TYPE_REFERRER,
                  "推荐会员"
                  );
         }
         //推荐注册二级带新积分奖励
         if(referrerVip.getRecommendId()!=null){
            SysVipInfo topVipInfo = sysVipInfoDao.selectById(referrerVip.getRecommendId());
            if(StringUtils.isNotBlank(referrerScoreSetting.getParamValue1())){
               scoreVipDetailService.addScore(topVipInfo.getOpenId(),
                     topVipInfo.getId(),
                     user.getSuId(),
                     vipInfo.getShopId(),
                     Integer.parseInt(referrerScoreSetting.getParamValue1()),
                     vipInfo.getId(),
                     ScoreVipDetail.SCORE_VIP_TYPE_REFERRER,
                     "间接推荐会员"
               );
            }
         }
      }
   }
   @Override
@@ -494,6 +587,15 @@
      SysVipInfo vipInfo = sysVipInfoDao.selectById(modifyVipDto.getVipId());
      if (vipInfo == null) {
         throw new GlobleException("用户不存在");
      }
      if (StringUtils.isNotBlank(modifyVipDto.getVipNo())) {
         if (!modifyVipDto.getVipNo().equals(vipInfo.getVipNo())) {
            if (serviceUtil.addCheckRepeatTowColumn(TableMapping.SYS_VIP_INFO, "VIP_NO", modifyVipDto.getVipNo(),
                  "company_id", user.getCompanyId())) {
               throw new GlobleException("编号已存在!");
            }
         }
      }
      if (!vipInfo.getPhone().equals(modifyVipDto.getPhone())) {
@@ -516,28 +618,27 @@
      vipInfo.setPhone(modifyVipDto.getPhone());
      vipInfo.setAddr(modifyVipDto.getAddress());
      vipInfo.setRemark(modifyVipDto.getRemark());
      vipInfo.setPassWord(modifyVipDto.getPassword());
      vipInfo.setBirthday1(modifyVipDto.getBirthday());
      vipInfo.setRecommendId(modifyVipDto.getRecommendId());
      vipInfo.setPhoto(modifyVipDto.getPhoto());
      int i = sysVipInfoDao.update(vipInfo);
      if (CollectionUtils.isNotEmpty(modifyVipDto.getLabels())) {
         sysVipLabelDao.deleteByVipId(modifyVipDto.getVipId());
         batchInsertLabel(modifyVipDto.getLabels(), user.getSuName(), vipInfo.getId());
         sysVipLabelDao.deleteRelateByVipId(modifyVipDto.getVipId());
         batchInsertLabel(modifyVipDto.getLabels(), vipInfo.getId());
      }
      return i;
   }
   private void batchInsertLabel(List<String> labelList, String suName, Long id) {
   private void batchInsertLabel(List<String> labelList, Long id) {
      Set<String> labels = new HashSet<>(labelList);
      Iterator<String> iterator = labels.iterator();
      if (iterator.hasNext()) {
         SysVipLabel sysVipLabel = new SysVipLabel();
         sysVipLabel.setCreateTime(new Date());
         sysVipLabel.setCreateBy(suName);
         sysVipLabel.setLabel(iterator.next());
         sysVipLabel.setVipId(id);
         sysVipLabelDao.insert(sysVipLabel);
      while (iterator.hasNext()) {
         SysVipLabelRelate relate = new SysVipLabelRelate();
         relate.setLabelId(Long.parseLong(iterator.next()));
         relate.setVipId(id);
         sysVipLabelDao.insertRelate(relate);
      }
   }
@@ -561,6 +662,9 @@
      vipInfoDetailVo.setArea(sysVipInfo.getArea());
      vipInfoDetailVo.setRemark(sysVipInfo.getRemark());
      vipInfoDetailVo.setBirthday(sysVipInfo.getBirthday1());
      vipInfoDetailVo.setPassword(sysVipInfo.getPassWord());
      vipInfoDetailVo.setPhoto(sysVipInfo.getPhoto());
      vipInfoDetailVo.setVipNo(sysVipInfo.getVipNo());
      List<SysVipLabel> labels = sysVipLabelDao.selectByVipId(sysVipInfo.getId());
      vipInfoDetailVo.setLabels(labels);