|
|
|
@ -1,13 +1,18 @@
|
|
|
|
package com.flossom.miniProgram.service.impl;
|
|
|
|
package com.flossom.miniProgram.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.flossom.common.core.constant.CacheConstants;
|
|
|
|
import com.flossom.common.core.constant.CacheConstants;
|
|
|
|
import com.flossom.common.core.constant.HttpStatus;
|
|
|
|
import com.flossom.common.core.constant.HttpStatus;
|
|
|
|
|
|
|
|
import com.flossom.common.core.constant.ShuYunConstants;
|
|
|
|
import com.flossom.common.core.constant.UserConstants;
|
|
|
|
import com.flossom.common.core.constant.UserConstants;
|
|
|
|
import com.flossom.common.core.domain.R;
|
|
|
|
import com.flossom.common.core.domain.R;
|
|
|
|
import com.flossom.common.core.domain.entity.*;
|
|
|
|
import com.flossom.common.core.domain.entity.*;
|
|
|
|
|
|
|
|
import com.flossom.common.core.domain.shuyun.ShuYunMember;
|
|
|
|
|
|
|
|
import com.flossom.common.core.domain.shuyun.ShuYunPointChange;
|
|
|
|
import com.flossom.common.core.enums.IntegralChangeTypeEnum;
|
|
|
|
import com.flossom.common.core.enums.IntegralChangeTypeEnum;
|
|
|
|
import com.flossom.common.core.enums.MessageTypeEnum;
|
|
|
|
import com.flossom.common.core.enums.MessageTypeEnum;
|
|
|
|
|
|
|
|
import com.flossom.common.core.enums.ShuYunPointSourceEnum;
|
|
|
|
import com.flossom.common.core.enums.WxUserIntegralMessageTypeEnum;
|
|
|
|
import com.flossom.common.core.enums.WxUserIntegralMessageTypeEnum;
|
|
|
|
import com.flossom.common.core.exception.ServiceException;
|
|
|
|
import com.flossom.common.core.exception.ServiceException;
|
|
|
|
import com.flossom.common.core.mapper.*;
|
|
|
|
import com.flossom.common.core.mapper.*;
|
|
|
|
@ -18,6 +23,8 @@ import com.flossom.common.security.utils.SecurityUtils;
|
|
|
|
import com.flossom.miniProgram.domain.vo.*;
|
|
|
|
import com.flossom.miniProgram.domain.vo.*;
|
|
|
|
import com.flossom.miniProgram.service.IWxUserMemberService;
|
|
|
|
import com.flossom.miniProgram.service.IWxUserMemberService;
|
|
|
|
import com.flossom.miniProgram.utils.MiniProgramUtils;
|
|
|
|
import com.flossom.miniProgram.utils.MiniProgramUtils;
|
|
|
|
|
|
|
|
import com.flossom.miniProgram.utils.shuyun.ShuYunApiUtils;
|
|
|
|
|
|
|
|
import com.flossom.miniProgram.utils.shuyun.ShuYunConfig;
|
|
|
|
import com.flossom.system.api.RemoteAuthService;
|
|
|
|
import com.flossom.system.api.RemoteAuthService;
|
|
|
|
import com.flossom.system.api.model.LoginUser;
|
|
|
|
import com.flossom.system.api.model.LoginUser;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
@ -28,6 +35,10 @@ import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
|
|
|
import java.time.LocalTime;
|
|
|
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
|
|
|
import java.time.temporal.TemporalAdjusters;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
@ -61,6 +72,9 @@ public class WxUserMemberServiceImpl implements IWxUserMemberService {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private WxUserIntegralLogMapper wxUserIntegralLogMapper;
|
|
|
|
private WxUserIntegralLogMapper wxUserIntegralLogMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private ShuYunConfig shuYunConfig;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
@ -176,8 +190,11 @@ public class WxUserMemberServiceImpl implements IWxUserMemberService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* TODO: 新用户注册,需要对接数云,将用户信息传给数云
|
|
|
|
* TODO: 1、新用户注册,需要对接数云,将用户信息传给数云(已完成,待添加操作日志)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
WxUserMember wxUserMember = wxUserMemberMapper.selectWxUserMemberById(SecurityUtils.getLoginUser().getWxUserMember().getId());
|
|
|
|
|
|
|
|
ShuYunApiUtils.registerMember(new ShuYunMember(wxUserMember.getUnionid(), shuYunConfig.getPlatCode(), shuYunConfig.getShopId(),
|
|
|
|
|
|
|
|
"用户" + wxUserMember.getId(), wxUserMember.getMobile(), DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, wxUserMember.getCreateTime())));
|
|
|
|
return wxCode2PhoneRet.getPhoneInfo().getPhoneNumber();
|
|
|
|
return wxCode2PhoneRet.getPhoneInfo().getPhoneNumber();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -189,15 +206,13 @@ public class WxUserMemberServiceImpl implements IWxUserMemberService {
|
|
|
|
if (wxUserMember == null) {
|
|
|
|
if (wxUserMember == null) {
|
|
|
|
throw new ServiceException("用户不存在");
|
|
|
|
throw new ServiceException("用户不存在");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int floatScore = 0;
|
|
|
|
List<IntegralGlobal> integralGlobalList = integralGlobalMapper.selectIntegralGlobalList(new IntegralGlobal());
|
|
|
|
|
|
|
|
IntegralGlobal integralGlobal = integralGlobalList.get(0);
|
|
|
|
Boolean isCompleteInformation = false;
|
|
|
|
Boolean isCompleteInformation = false;
|
|
|
|
if (wxUserMember.getIsCompleteInformation() == null || wxUserMember.getIsCompleteInformation() == 0) {
|
|
|
|
if (wxUserMember.getIsCompleteInformation() == null || wxUserMember.getIsCompleteInformation() == 0) {
|
|
|
|
isCompleteInformation = true;
|
|
|
|
isCompleteInformation = true;
|
|
|
|
// 修改完善状态
|
|
|
|
// 修改完善状态
|
|
|
|
wxUserMember.setIsCompleteInformation(1);
|
|
|
|
wxUserMember.setIsCompleteInformation(1);
|
|
|
|
List<IntegralGlobal> integralGlobalList = integralGlobalMapper.selectIntegralGlobalList(new IntegralGlobal());
|
|
|
|
|
|
|
|
IntegralGlobal integralGlobal = integralGlobalList.get(0);
|
|
|
|
|
|
|
|
floatScore = integralGlobal.getIntegral().intValue();
|
|
|
|
|
|
|
|
wxUserMember.setCredit(wxUserMember.getCredit() + integralGlobal.getIntegral().intValue());
|
|
|
|
wxUserMember.setCredit(wxUserMember.getCredit() + integralGlobal.getIntegral().intValue());
|
|
|
|
|
|
|
|
|
|
|
|
// 保存积分详情
|
|
|
|
// 保存积分详情
|
|
|
|
@ -212,7 +227,7 @@ public class WxUserMemberServiceImpl implements IWxUserMemberService {
|
|
|
|
wxUserIntegralLog.setCreateTime(DateUtils.getNowDate());
|
|
|
|
wxUserIntegralLog.setCreateTime(DateUtils.getNowDate());
|
|
|
|
wxUserIntegralLogMapper.insertWxUserIntegralLog(wxUserIntegralLog);
|
|
|
|
wxUserIntegralLogMapper.insertWxUserIntegralLog(wxUserIntegralLog);
|
|
|
|
|
|
|
|
|
|
|
|
// 2.4、用户注册成功发送消息
|
|
|
|
// 2.4、用户升级会员成功发送消息
|
|
|
|
WxScriptMessage wxScriptMessage = wxScriptMessageMapper.selectOneByMessageType(MessageTypeEnum.COMPLETE_USER_INFORMATION.getCode());
|
|
|
|
WxScriptMessage wxScriptMessage = wxScriptMessageMapper.selectOneByMessageType(MessageTypeEnum.COMPLETE_USER_INFORMATION.getCode());
|
|
|
|
if (wxScriptMessage != null) {
|
|
|
|
if (wxScriptMessage != null) {
|
|
|
|
WxUserScriptLog wxUserScriptLog = new WxUserScriptLog();
|
|
|
|
WxUserScriptLog wxUserScriptLog = new WxUserScriptLog();
|
|
|
|
@ -229,17 +244,32 @@ public class WxUserMemberServiceImpl implements IWxUserMemberService {
|
|
|
|
wxUserScriptLog.setUpdateBy(null);
|
|
|
|
wxUserScriptLog.setUpdateBy(null);
|
|
|
|
wxUserScriptLogMapper.insertWxUserScriptLog(wxUserScriptLog);
|
|
|
|
wxUserScriptLogMapper.insertWxUserScriptLog(wxUserScriptLog);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: 首次完善,增加加分 (对接数云未完成)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BeanUtils.copyProperties(userMemberUpdateVo, wxUserMember);
|
|
|
|
BeanUtils.copyProperties(userMemberUpdateVo, wxUserMember);
|
|
|
|
wxUserMember.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
wxUserMember.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
wxUserMemberMapper.updateWxUserMember(wxUserMember);
|
|
|
|
wxUserMemberMapper.updateWxUserMember(wxUserMember);
|
|
|
|
|
|
|
|
|
|
|
|
// 刷新用户信息
|
|
|
|
// 首次完善用户信息,增加积分,刷新了缓存
|
|
|
|
LoginUserVo loginUserVo = refreshWxUserInfo();
|
|
|
|
LoginUserVo loginUserVo = refreshWxUserInfo();
|
|
|
|
|
|
|
|
// TODO: 2、更新用户信息,同步到数云 (已完成,未保存记录)
|
|
|
|
|
|
|
|
// 1、完善用户信息
|
|
|
|
|
|
|
|
ShuYunMember member = new ShuYunMember();
|
|
|
|
|
|
|
|
member.setId(wxUserMember.getUnionid());
|
|
|
|
|
|
|
|
member.setPlatCode(shuYunConfig.getPlatCode());
|
|
|
|
|
|
|
|
member.setShopId(shuYunConfig.getShopId());
|
|
|
|
|
|
|
|
member.setName(userMemberUpdateVo.getNickname());
|
|
|
|
|
|
|
|
member.setBirthday(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, userMemberUpdateVo.getBirthday()));
|
|
|
|
|
|
|
|
ShuYunApiUtils.modifyMember(member);
|
|
|
|
|
|
|
|
|
|
|
|
if (isCompleteInformation) {
|
|
|
|
if (isCompleteInformation) {
|
|
|
|
loginUserVo.setIntegralText("您已完善个人信息,获得" + floatScore + "积分");
|
|
|
|
loginUserVo.setIntegralText("您已完善个人信息,获得" + integralGlobal.getIntegral().intValue() + "积分");
|
|
|
|
|
|
|
|
// TODO: 3、首次完善,通知数云增加积分 (已完成,未保存记录)
|
|
|
|
|
|
|
|
// 2、完善会员信息增加积分
|
|
|
|
|
|
|
|
String sequence = ShuYunConstants.POINT_SERIAL_NUMBER_PREFIX + LocalDateTime.now().format(DateTimeFormatter.ofPattern(DateUtils.YYYYMMDDHHMMSSS)) + RandomUtil.randomInt(1000, 9999);
|
|
|
|
|
|
|
|
ShuYunPointChange shuYunPointChange = new ShuYunPointChange(wxUserMember.getUnionid(), shuYunConfig.getPlatCode(), shuYunConfig.getShopId(),
|
|
|
|
|
|
|
|
sequence, ShuYunPointSourceEnum.OTHER.getSource(), integralGlobal.getIntegral().intValue(),
|
|
|
|
|
|
|
|
LocalDateTime.now().format(DateTimeFormatter.ofPattern(DateUtils.YYYY_MM_DD_HH_MM_SS)), "首次完善用户信息");
|
|
|
|
|
|
|
|
ShuYunApiUtils.pointChange(shuYunPointChange);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return loginUserVo;
|
|
|
|
return loginUserVo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -250,7 +280,7 @@ public class WxUserMemberServiceImpl implements IWxUserMemberService {
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Transactional(propagation = Propagation.SUPPORTS)
|
|
|
|
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
|
|
|
public LoginUserVo refreshWxUserInfo() {
|
|
|
|
public LoginUserVo refreshWxUserInfo() {
|
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
|
|
|
|
|
|
|
|
|
@ -266,6 +296,16 @@ public class WxUserMemberServiceImpl implements IWxUserMemberService {
|
|
|
|
BeanUtils.copyProperties(wxUserMember, loginUserVo);
|
|
|
|
BeanUtils.copyProperties(wxUserMember, loginUserVo);
|
|
|
|
loginUserVo.setToken(null);
|
|
|
|
loginUserVo.setToken(null);
|
|
|
|
loginUserVo.setIntegralText(null);
|
|
|
|
loginUserVo.setIntegralText(null);
|
|
|
|
|
|
|
|
// TODO:调用数云接口获取最新的积分值(已完成,未保存操作记录)
|
|
|
|
|
|
|
|
ShuYunMember shuYunMember = ShuYunApiUtils.queryMember(wxUserMember.getUnionid(), shuYunConfig.getPlatCode(), shuYunConfig.getShopId());
|
|
|
|
|
|
|
|
loginUserVo.setCredit(Integer.valueOf(shuYunMember.getPoint()));
|
|
|
|
|
|
|
|
// TODO: 调用数云接口获取即将过期的积分值(未完成。。。。)
|
|
|
|
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
|
|
|
String startTime = now.plusHours(1).format(DateTimeFormatter.ofPattern(DateUtils.YYYY_MM_DD_HH_MM_SS));
|
|
|
|
|
|
|
|
String endTime = now.with(TemporalAdjusters.lastDayOfYear()).with(LocalTime.MAX).format(DateTimeFormatter.ofPattern(DateUtils.YYYY_MM_DD_HH_MM_SS));
|
|
|
|
|
|
|
|
// tenant 租户名称 数云说写死
|
|
|
|
|
|
|
|
Integer expireCredit = ShuYunApiUtils.pointWillDueSearch("zzsstest", wxUserMember.getUnionid(), "100000184001", "RELATIVE", startTime, endTime);
|
|
|
|
|
|
|
|
loginUserVo.setExpireCredit(expireCredit);
|
|
|
|
|
|
|
|
|
|
|
|
// 刷新缓存信息
|
|
|
|
// 刷新缓存信息
|
|
|
|
String userKey = CacheConstants.LOGIN_TOKEN_KEY + loginUser.getToken();
|
|
|
|
String userKey = CacheConstants.LOGIN_TOKEN_KEY + loginUser.getToken();
|
|
|
|
|