|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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.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; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${default.vip.photo.man}") | 
|---|
|  |  |  | String defaultMan; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | BusParameterSettingsDao busParameterSettingsDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | ScoreVipDetailService scoreVipDetailService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public  int addVipDefaultCard(Long vipId){ | 
|---|
|  |  |  | public MoneyCardUse addVipDefaultCard(Long vipId){ | 
|---|
|  |  |  | MoneyCardUse defaultCardUse=new MoneyCardUse(); | 
|---|
|  |  |  | defaultCardUse.setVipId(vipId); | 
|---|
|  |  |  | defaultCardUse.setCardName("储值卡"); | 
|---|
|  |  |  | 
|---|
|  |  |  | defaultCardUse.setGiftMoney(0D); | 
|---|
|  |  |  | defaultCardUse.setSource("-"); | 
|---|
|  |  |  | defaultCardUse.setStatus(Dictionary.MONEYCARD_STATUS_YX); | 
|---|
|  |  |  | return  moneyCardUseDao.insert(defaultCardUse); | 
|---|
|  |  |  | moneyCardUseDao.insert(defaultCardUse); | 
|---|
|  |  |  | return  defaultCardUse; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public int add(SysVipInfo sysVipInfo) { | 
|---|
|  |  |  | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (sysVipInfo.getVipNo() != null && (!sysVipInfo.getVipNo().equals(""))) { | 
|---|
|  |  |  | if (serviceUtil.addCheckRepeatTowColumn(TableMapping.SYS_VIP_INFO, "VIP_NO", sysVipInfo.getVipNo(), | 
|---|
|  |  |  | "company_id",user.getCompanyId())) { | 
|---|
|  |  |  | "company_id",sysVipInfo.getCompanyId())) { | 
|---|
|  |  |  | throw new GlobleException("编号已存在!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new GlobleException("请输入手机号!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (serviceUtil.addCheckRepeatTowColumn(TableMapping.SYS_VIP_INFO, "PHONE", sysVipInfo.getPhone(), | 
|---|
|  |  |  | "company_id",user.getCompanyId() )) { | 
|---|
|  |  |  | throw new GlobleException("手机已被注册!"); | 
|---|
|  |  |  | "company_id",sysVipInfo.getCompanyId() )) { | 
|---|
|  |  |  | throw new GlobleException(sysVipInfo.getPhone()+"手机已被注册!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | sysVipInfo.setShopId(user.getShopId()); | 
|---|
|  |  |  | sysVipInfo.setCompanyId(user.getCompanyId()); | 
|---|
|  |  |  | sysVipInfo.setCreateTime(new Date()); | 
|---|
|  |  |  | 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)){ | 
|---|
|  |  |  | if(StringUtils.isNotBlank(sysVipInfo.getVipName())){ | 
|---|
|  |  |  | sysVipInfo.setZjm(StringUtils.toHanyuPinyin(sysVipInfo.getVipName())+","+StringUtils.toHeadWordHanyuPinyin(sysVipInfo.getVipName())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(Dictionary.SEX_MAN.equals(sysVipInfo.getSex())){ | 
|---|
|  |  |  | sysVipInfo.setPhoto(defaultMan); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | sysVipInfo.setPhoto(defaultWoman); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int i=sysVipInfoDao.insert(sysVipInfo); | 
|---|
|  |  |  | modifyVipWithOtherInfo(sysVipInfo); | 
|---|
|  |  |  | //创建用户默认储值卡 | 
|---|
|  |  |  | addVipDefaultCard(sysVipInfo.getId()); | 
|---|
|  |  |  | return i; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //如果会员id不为空则表示是修改,删除原有的绑定关系,建立新的关系 | 
|---|
|  |  |  | if(vipInfo.getId()!=null && !vipInfo.getId().equals("")){ | 
|---|
|  |  |  | MyBeatician query=new MyBeatician(); | 
|---|
|  |  |  | query.setVipId(vipInfo.getId()); | 
|---|
|  |  |  | List<MyBeatician> listDel= myBeaticianDao.selectByModel(query); | 
|---|
|  |  |  | if(listDel!=null && listDel.size()>0){ | 
|---|
|  |  |  | List<Long> delIds=new ArrayList<>(); | 
|---|
|  |  |  | for (int i = 0; i < listDel.size(); i++) { | 
|---|
|  |  |  | delIds.add(listDel.get(i).getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | myBeaticianDao.deleteByIds(delIds); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //添加客户的美疗师 | 
|---|
|  |  |  | List<MyBeatician> list=vipInfo.getBeauticains(); | 
|---|
|  |  |  | if(list!=null && list.size()>0){ | 
|---|
|  |  |  | List<MyBeatician> saveList=new ArrayList<>(); | 
|---|
|  |  |  | //此处由于前台传递过来list中的下标可能是不连续的。因此要过滤掉空的,即要过滤掉美疗师的id为空的数据 | 
|---|
|  |  |  | for (MyBeatician temp:list) { | 
|---|
|  |  |  | if(temp.getBeauticainId()!=null && !temp.getBeauticainId().equals("")){ | 
|---|
|  |  |  | saveList.add(temp); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | myBeaticianDao.insertAll(saveList,vipInfo.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | SysVipInfo vipInfo = new SysVipInfo(); | 
|---|
|  |  |  | vipInfo.setVipNo(objects.get(0).toString()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SysVipInfo exist = sysVipInfoDao.selectByPhone(objects.get(3).toString()); | 
|---|
|  |  |  | SysVipInfo exist = sysVipInfoDao.selectByPhone(objects.get(3).toString(),sysUsers.getCompanyId()); | 
|---|
|  |  |  | if (exist != null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public int apiAddVip(AddVipDto addVipDto) { | 
|---|
|  |  |  | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | if (CollectionUtils.isNotEmpty(addVipDto.getLabels())) { | 
|---|
|  |  |  | 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.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.getId(), | 
|---|
|  |  |  | user.getSuId(), | 
|---|
|  |  |  | vipInfo.getShopId(), | 
|---|
|  |  |  | Integer.parseInt(referrerScoreSetting.getParamValue1()), | 
|---|
|  |  |  | vipInfo.getId(), | 
|---|
|  |  |  | ScoreVipDetail.SCORE_VIP_TYPE_REFERRER, | 
|---|
|  |  |  | "间接推荐会员" | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | vipInfoDetailVo.setLabels(labels); | 
|---|
|  |  |  | return vipInfoDetailVo; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public SysVipInfo findByOpenId(String openId) { | 
|---|
|  |  |  | return sysVipInfoDao.findByOpenId(openId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 设置成为推广员 | 
|---|
|  |  |  | * @param invitationId | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public int setToBeAnSalesman(Long userId,Long invitationId,long gradeId) { | 
|---|
|  |  |  | SysVipInfo sysVipInfo=sysVipInfoDao.selectById(userId); | 
|---|
|  |  |  | sysVipInfo.setIsSales(SysVipInfo.IS_SALES); | 
|---|
|  |  |  | sysVipInfo.setRecommendId(invitationId); | 
|---|
|  |  |  | sysVipInfo.setBindingParentTime(new Date()); | 
|---|
|  |  |  | sysVipInfo.setSalesmanGrade(gradeId); | 
|---|
|  |  |  | return sysVipInfoDao.update(sysVipInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|