You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
473 lines
18 KiB
473 lines
18 KiB
package com.hai.service.impl;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.hai.common.exception.ErrorCode;
|
|
import com.hai.common.exception.ErrorHelp;
|
|
import com.hai.common.exception.SysCode;
|
|
import com.hai.common.security.AESEncodeUtil;
|
|
import com.hai.common.security.SessionObject;
|
|
import com.hai.common.security.UserCenter;
|
|
import com.hai.common.utils.BaiduUtils;
|
|
import com.hai.common.utils.DateUtil;
|
|
import com.hai.common.utils.HttpsUtils;
|
|
import com.hai.common.utils.RequestUtils;
|
|
import com.hai.dao.HighGoldRecMapper;
|
|
import com.hai.dao.HighUserLevelMapper;
|
|
import com.hai.dao.HighUserLoginLogMapper;
|
|
import com.hai.dao.HighUserMapper;
|
|
import com.hai.entity.*;
|
|
import com.hai.enum_type.LoginPlatform;
|
|
import com.hai.enum_type.OilCardBindStatusEnum;
|
|
import com.hai.enum_type.UserCardType;
|
|
import com.hai.model.HighUserModel;
|
|
import com.hai.service.*;
|
|
import org.apache.commons.collections4.MapUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.text.DateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* @author Sum1Dream
|
|
*/
|
|
@Service("highUserServiceImpl")
|
|
public class HighUserServiceImpl implements HighUserService {
|
|
|
|
@Resource
|
|
private HighUserMapper highUserMapper;
|
|
|
|
@Resource
|
|
private HighGoldRecService highGoldRecService;
|
|
|
|
@Resource
|
|
private HighUserCouponService highUserCouponService;
|
|
|
|
@Resource
|
|
private HighUserLevelMapper highUserLevelMapper;
|
|
|
|
@Resource
|
|
private HighUserCardService highUserCardService;
|
|
|
|
@Resource
|
|
private HighOrderService highOrderService;
|
|
|
|
@Resource
|
|
private HighUserPayPasswordService highUserPayPasswordService;
|
|
|
|
@Resource
|
|
private UserCenter userCenter;
|
|
|
|
@Resource
|
|
private HighGoldRecMapper highGoldRecMapper;
|
|
|
|
@Resource
|
|
private HighOilCardService oilCardService;
|
|
|
|
@Resource
|
|
private BsDistributionUserRelService distributionUserRelService;
|
|
|
|
@Resource
|
|
private CommonService commonService;
|
|
|
|
@Resource
|
|
private HighUserLoginLogMapper userLoginLogMapper;
|
|
|
|
@Override
|
|
@Transactional(propagation = Propagation.REQUIRES_NEW, timeout = 30, rollbackFor = Exception.class)
|
|
public SessionObject loginAndRegister(LoginPlatform platform,String phone, Long popularizeUserId, Map<String, Object> other,HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
// 记录登录信息
|
|
String requestIp = RequestUtils.getRequestIp();
|
|
System.out.println(requestIp);
|
|
HighUserLoginLog loginLog = new HighUserLoginLog();
|
|
loginLog.setUserPhone(phone);
|
|
loginLog.setPlatformCode(platform.getCode());
|
|
loginLog.setPlatformName(platform.getName());
|
|
loginLog.setIp(requestIp);
|
|
loginLog.setProvinceName("未知");
|
|
loginLog.setCityName("未知");
|
|
loginLog.setStatus(1);
|
|
loginLog.setCreateTime(new Date());
|
|
JSONObject ipResponse = BaiduUtils.ipLocation(requestIp);
|
|
if (ipResponse != null && ipResponse.getInteger("status").equals(0)) {
|
|
JSONObject ipAddressDetail = ipResponse.getJSONObject("content").getJSONObject("address_detail");
|
|
loginLog.setProvinceName(StringUtils.isBlank(ipAddressDetail.getString("province"))?"未知":ipAddressDetail.getString("province"));
|
|
loginLog.setCityName(StringUtils.isBlank(ipAddressDetail.getString("city"))?"未知":ipAddressDetail.getString("city"));
|
|
}
|
|
|
|
HighUser user = findByPhone(phone);
|
|
if (user == null) {
|
|
user = new HighUser();
|
|
user.setName("嗨用户");
|
|
user.setPhone(phone);
|
|
user.setRegTime(new Date());
|
|
user.setGold(0);
|
|
user.setStatus(1);
|
|
user.setInfoCompleteStatus(1); // 用户信息完整状态 0:完整 1:需要填写用户信息 2:需要填写手机号
|
|
user.setOpenId(MapUtils.getString(other, "openId"));
|
|
user.setUnionId(MapUtils.getString(other, "unionId"));
|
|
user.setOpenIdH5(MapUtils.getString(other, "openIdH5"));
|
|
user.setUnionUnionId(MapUtils.getString(other, "unionUnionId"));
|
|
highUserMapper.insert(user);
|
|
|
|
// 检查是否有的预留油卡
|
|
HighOilCard oilCard = oilCardService.getOilCardByPhone(user.getPhone());
|
|
if (oilCard != null && oilCard.getBindStatus().equals(OilCardBindStatusEnum.status0.getStatus())) {
|
|
highUserCardService.bindCard(UserCardType.type2.getType(), oilCard.getCardNo(), user.getId());
|
|
}
|
|
|
|
SecRegion region = commonService.getRegionsByName(loginLog.getProvinceName());
|
|
// distributionUserRelService.insertDistributionRebate(user.getId(), popularizeUserId, "500000");
|
|
if (region != null) {
|
|
// 绑定推广关联关系
|
|
distributionUserRelService.insertDistributionUserRel(user.getId(), popularizeUserId, region.getRegionId().toString());
|
|
}
|
|
}
|
|
user.setOpenIdH5(MapUtils.getString(other, "openIdH5"));
|
|
user.setOpenId(MapUtils.getString(other, "openId"));
|
|
loginLog.setUserId(user.getId());
|
|
userLoginLogMapper.insert(loginLog);
|
|
|
|
// 缓存登录信息
|
|
HighUserModel highUserModel = new HighUserModel();
|
|
highUserModel.setHighUser(getDetailDataByUser(user.getId()));
|
|
SessionObject so = new SessionObject(AESEncodeUtil.base64Encode(AESEncodeUtil.aesEncryptToBytes(user.getPhone(), "123")), 1 , highUserModel);
|
|
userCenter.save(request,response,so);
|
|
|
|
return so;
|
|
}
|
|
|
|
@Override
|
|
public List<HighUser> getUserList(Map<String, Object> param) {
|
|
HighUserExample example = new HighUserExample();
|
|
HighUserExample.Criteria criteria = example.createCriteria().andStatusNotEqualTo(0);
|
|
|
|
if (StringUtils.isNotBlank(MapUtils.getString(param, "openId"))) {
|
|
criteria.andOpenIdEqualTo(MapUtils.getString(param, "openId"));
|
|
}
|
|
|
|
if (StringUtils.isNotBlank(MapUtils.getString(param, "openIdH5"))) {
|
|
criteria.andOpenIdH5EqualTo(MapUtils.getString(param, "openIdH5"));
|
|
}
|
|
|
|
return highUserMapper.selectByExample(example);
|
|
}
|
|
|
|
@Override
|
|
public List<HighUser> getListUser(Map<String, Object> map) {
|
|
HighUserExample example = new HighUserExample();
|
|
HighUserExample.Criteria criteria = example.createCriteria();
|
|
|
|
if (StringUtils.isNotBlank(MapUtils.getString(map , "phone"))) {
|
|
criteria.andPhoneLike("%" + MapUtils.getString(map , "phone") + "%");
|
|
}
|
|
if (StringUtils.isNotBlank(MapUtils.getString(map , "name"))) {
|
|
criteria.andNameLike("%" + MapUtils.getString(map , "name") + "%");
|
|
}
|
|
|
|
if (MapUtils.getInteger(map , "status") != null) {
|
|
criteria.andStatusEqualTo(MapUtils.getInteger(map , "status"));
|
|
}
|
|
if (MapUtils.getBoolean(map , "isAgent") != null) {
|
|
criteria.andIsAgentEqualTo(MapUtils.getBoolean(map , "isAgent"));
|
|
}
|
|
if (StringUtils.isNotBlank(MapUtils.getString(map , "ext4"))) {
|
|
criteria.andExt4EqualTo(String.valueOf(map.get("ext4")));
|
|
}
|
|
if (StringUtils.isNotBlank(MapUtils.getString(map , "regTimeStart")) && StringUtils.isNotBlank(MapUtils.getString(map , "regTimeEnd"))) {
|
|
criteria.andRegTimeBetween(
|
|
DateUtil.format(MapUtils.getString(map , "regTimeStart") , "yyyy-MM-dd HH:mm:ss") ,
|
|
DateUtil.format(MapUtils.getString(map , "regTimeEnd") , "yyyy-MM-dd HH:mm:ss"));
|
|
}
|
|
if (MapUtils.getLong(map, "regTimeStart") != null) {
|
|
criteria.andRegTimeGreaterThanOrEqualTo(new Date(MapUtils.getLong(map, "regTimeStart")));
|
|
}
|
|
if (MapUtils.getLong(map, "regTimeEnd") != null) {
|
|
criteria.andRegTimeLessThan(new Date(MapUtils.getLong(map, "regTimeEnd")));
|
|
}
|
|
|
|
return highUserMapper.selectByExample(example);
|
|
|
|
}
|
|
|
|
@Override
|
|
public HighUser findByUserId(Long userId) {
|
|
return highUserMapper.selectByPrimaryKey(userId);
|
|
}
|
|
|
|
@Override
|
|
public HighUser getDetailDataByUser(Long userId) {
|
|
HighUser user = highUserMapper.selectByPrimaryKey(userId);
|
|
if (user == null) {
|
|
return null;
|
|
}
|
|
user.setUnusedCouponNum(highUserCouponService.getCouponList(userId, 1).size()); //未使用卡卷数量
|
|
user.setUnpaid(highOrderService.countOrderByUserId(userId , 1));
|
|
user.setOrderPayNum(highOrderService.countOrderByUserId(userId , 2));
|
|
user.setWhetherCheckNum(highOrderService.whetherCheck(userId , 3));
|
|
user.setUnusedDiscount(highOrderService.countUnusedDiscountByUserId(userId , 1));
|
|
user.setIsSetPayPwd(highUserPayPasswordService.isSetPayPwd(userId));
|
|
user.setIsSetHltCard(highUserCardService.isBindHtlCard(userId));
|
|
user.setHltCardNo(highUserCardService.getUserHtlCardNo(userId));
|
|
user.setBlxCouponBalance(highUserCardService.getBlxCouponBalance(user.getPhone()).getInteger("num"));
|
|
|
|
// 查询油卡
|
|
List<HighUserCard> oilCardList = highUserCardService.getListByUser(userId, UserCardType.type2.getType());
|
|
List<HighUserCard> carOilCardList = highUserCardService.getListByUser(userId, UserCardType.type3.getType());
|
|
if (oilCardList.size() > 0) {
|
|
user.setIsSetOilCard(true);
|
|
// 查询油卡
|
|
HighOilCard oilCard = oilCardService.getOilCardByCardNo(oilCardList.get(0).getCardNo());
|
|
if (oilCard != null) {
|
|
Map<String, Object> oilCardMap = new HashMap<>();
|
|
oilCardMap.put("cardNo", oilCard.getCardNo());
|
|
oilCardMap.put("amount", oilCard.getAmount());
|
|
user.setOilCard(oilCardMap);
|
|
}
|
|
} else {
|
|
user.setIsSetOilCard(false);
|
|
}
|
|
|
|
if (carOilCardList.size() > 0) {
|
|
user.setSetOilCarCard(true);
|
|
// 查询油卡
|
|
HighOilCard CarOilCard = oilCardService.getOilCardByCardNo(carOilCardList.get(0).getCardNo());
|
|
if (CarOilCard != null) {
|
|
Map<String, Object> CarOilCardMap = new HashMap<>();
|
|
CarOilCardMap.put("cardNo", CarOilCard.getCardNo());
|
|
CarOilCardMap.put("amount", CarOilCard.getAmount());
|
|
user.setOilCarCard(CarOilCardMap);
|
|
}
|
|
} else {
|
|
user.setSetOilCarCard(false);
|
|
}
|
|
|
|
return user;
|
|
}
|
|
|
|
@Override
|
|
public HighUser findByOpenId(String openId) {
|
|
HighUserExample example = new HighUserExample();
|
|
example.createCriteria().andOpenIdEqualTo(openId).andStatusEqualTo(1);
|
|
List<HighUser> list = highUserMapper.selectByExample(example);
|
|
if (list != null && list.size() > 0) {
|
|
return list.get(0);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public HighUser findByOpenIdH5(String openId) {
|
|
HighUserExample example = new HighUserExample();
|
|
example.createCriteria().andOpenIdH5EqualTo(openId).andStatusEqualTo(1);
|
|
List<HighUser> list = highUserMapper.selectByExample(example);
|
|
if (list != null && list.size() > 0) {
|
|
return list.get(0);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public HighUser findByUnionId(String unionId) {
|
|
HighUserExample example = new HighUserExample();
|
|
example.createCriteria().andUnionIdEqualTo(unionId).andStatusEqualTo(1);
|
|
List<HighUser> list = highUserMapper.selectByExample(example);
|
|
if (list != null && list.size() > 0) {
|
|
return list.get(0);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public HighUser findByPhone(String phone) {
|
|
HighUserExample example = new HighUserExample();
|
|
example.createCriteria().andPhoneEqualTo(phone).andStatusEqualTo(1);
|
|
List<HighUser> list = highUserMapper.selectByExample(example);
|
|
if (list != null && list.size() > 0) {
|
|
return list.get(0);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
@Transactional(propagation= Propagation.REQUIRES_NEW)
|
|
public HighUser bindUserPhone(String phone, HttpServletRequest request) throws Exception {
|
|
// 用户
|
|
SessionObject sessionObject = userCenter.getSessionObject(request);
|
|
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject();
|
|
HighUser highUser = findByUserId(userInfoModel.getHighUser().getId());
|
|
if (highUser == null) {
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "未找到用户");
|
|
}
|
|
if (StringUtils.isNotBlank(highUser.getPhone())) {
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "已绑定手机号,请勿重复绑定");
|
|
}
|
|
|
|
// 查询手机号是否被绑定
|
|
HighUser user = findByPhone(phone);
|
|
if (user != null) {
|
|
if (StringUtils.isNotBlank(user.getOpenId())) {
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "手机号已被绑定");
|
|
}
|
|
highUser.setStatus(0);
|
|
highUserMapper.updateByPrimaryKey(highUser);
|
|
|
|
user.setGold(user.getGold() + highUser.getGold());
|
|
user.setHeaderImg(highUser.getHeaderImg());
|
|
user.setName(highUser.getName());
|
|
user.setOpenId(highUser.getOpenId());
|
|
user.setUnionId(highUser.getUnionId());
|
|
|
|
// 用户信息完整状态
|
|
// 0:完整
|
|
// 1:需要填写用户信息
|
|
// 2:需要填写手机
|
|
if (user.getInfoCompleteStatus() == 2) {
|
|
user.setInfoCompleteStatus(0);
|
|
}
|
|
highUserMapper.updateByPrimaryKey(user);
|
|
return user;
|
|
}
|
|
highUser.setPhone(phone);
|
|
highUserMapper.updateByPrimaryKey(highUser);
|
|
return highUser;
|
|
}
|
|
|
|
@Override
|
|
public void updateUser(HighUser highUser) {
|
|
highUserMapper.updateByPrimaryKeySelective(highUser);
|
|
}
|
|
|
|
@Override
|
|
@Transactional(propagation= Propagation.REQUIRES_NEW)
|
|
public void insertUser(HighUser highUser , Long popularizeUserId) {
|
|
highUserMapper.insert(highUser);
|
|
|
|
if (highUser.getPhone() != null) {
|
|
HighOilCard oilCard = oilCardService.getOilCardByPhone(highUser.getPhone());
|
|
if (oilCard != null && oilCard.getBindStatus().equals(OilCardBindStatusEnum.status0.getStatus())) {
|
|
highUserCardService.bindCard(UserCardType.type2.getType(), oilCard.getCardNo(), highUser.getId());
|
|
}
|
|
}
|
|
// 记录登录信息
|
|
String requestIp = RequestUtils.getRequestIp();
|
|
// 绑定推广关联关系
|
|
distributionUserRelService.insertDistributionUserRel(highUser.getId() , popularizeUserId , requestIp);
|
|
}
|
|
|
|
@Override
|
|
@Transactional(propagation= Propagation.REQUIRED)
|
|
public void goldHandle(Long userId, Integer goldNum, Integer goldType, Integer resType, Long resId , String remark , String orderNo) {
|
|
// 查询用户信息
|
|
HighUser user = highUserMapper.selectByPrimaryKey(userId);
|
|
if (user == null) {
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "");
|
|
}
|
|
|
|
// 金币类型:1收入,2支出
|
|
if (goldType == 1) {
|
|
user.setGold(user.getGold() + goldNum);
|
|
|
|
} else if (goldType == 2) {
|
|
if (goldNum > user.getGold()) {
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "积分数量不足");
|
|
}
|
|
user.setGold(user.getGold() - goldNum);
|
|
|
|
} else {
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "用户积分处理异常");
|
|
}
|
|
highUserMapper.updateByPrimaryKey(user);
|
|
|
|
HighGoldRec highGoldRec = new HighGoldRec();
|
|
highGoldRec.setUserId(user.getId());
|
|
highGoldRec.setGoldType(goldType.longValue());
|
|
highGoldRec.setGold(goldNum);
|
|
highGoldRec.setCreateTime(new Date());
|
|
highGoldRec.setResType(resType);
|
|
highGoldRec.setResId(resId);
|
|
highGoldRec.setStatus(1);
|
|
highGoldRec.setResOrderNo(orderNo);
|
|
highGoldRec.setRemark(remark);
|
|
if (goldNum > 0) {
|
|
highGoldRecService.insertGoldRec(highGoldRec);
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public Long countUser() {
|
|
HighUserExample example = new HighUserExample();
|
|
return highUserMapper.countByExample(example);
|
|
}
|
|
|
|
@Override
|
|
public Boolean findGoldRepeat(Integer resType, Long resId) {
|
|
HighGoldRecExample example = new HighGoldRecExample();
|
|
example.createCriteria().andResIdEqualTo(resId).andResTypeEqualTo(resType);
|
|
return highGoldRecMapper.selectByExample(example).size() == 0;
|
|
}
|
|
|
|
@Override
|
|
public JSONObject userDistributionStatistics(Long userId) {
|
|
|
|
JSONObject object = new JSONObject();
|
|
|
|
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public void insertLevelUp(HighUserLevel highUserLevel) {
|
|
highUserLevelMapper.insert(highUserLevel);
|
|
}
|
|
|
|
@Override
|
|
public void editLevelUp(HighUserLevel highUserLevel) {
|
|
highUserLevelMapper.updateByPrimaryKeySelective(highUserLevel);
|
|
}
|
|
|
|
@Override
|
|
public HighUserLevel findUserLevel(Long userId) throws Exception {
|
|
|
|
HighUser user = highUserMapper.selectByPrimaryKey(userId);
|
|
|
|
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
Date targetTime = dateFormat.parse("2023-11-08 00:00:00");
|
|
|
|
|
|
HighUserLevelExample example = new HighUserLevelExample();
|
|
HighUserLevelExample.Criteria criteria = example.createCriteria();
|
|
|
|
criteria.andUserIdEqualTo(userId).andStatusEqualTo(1);
|
|
|
|
List<HighUserLevel> list = highUserLevelMapper.selectByExample(example);
|
|
|
|
if (list.size() > 0) {
|
|
return list.get(0);
|
|
}
|
|
|
|
if (user != null && user.getRegTime().compareTo(targetTime) < 0) {
|
|
HighUserLevel highUserLevel = new HighUserLevel();
|
|
highUserLevel.setCreateTime(new Date());
|
|
highUserLevel.setUpdateTime(new Date());
|
|
highUserLevel.setLevel("1");
|
|
highUserLevel.setStatus(1);
|
|
highUserLevel.setUserId(userId);
|
|
insertLevelUp(highUserLevel);
|
|
return highUserLevel;
|
|
}
|
|
|
|
|
|
return null;
|
|
}
|
|
}
|
|
|