package com.dsh.account.service.impl;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeOrderSettleModel;
import com.alipay.api.domain.OpenApiRoyaltyDetailInfoPojo;
import com.alipay.api.domain.RoyaltyDetailInfos;
import com.alipay.api.request.AlipayTradeOrderSettleRequest;
import com.alipay.api.request.AlipayTradeRoyaltyRelationBindRequest;
import com.alipay.api.response.AlipayTradeOrderSettleResponse;
import com.alipay.api.response.AlipayTradeQueryResponse;
import com.alipay.api.response.AlipayTradeRoyaltyRelationBindResponse;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsh.account.dto.*;
import com.dsh.account.entity.*;
import com.dsh.account.enums.RechargeRecordEnum;
import com.dsh.account.feignclient.activity.*;
import com.dsh.account.feignclient.activity.model.*;
import com.dsh.account.feignclient.communityWorldCup.WorldCupPaymentClinet;
import com.dsh.account.feignclient.communityWorldCup.model.GetWorldCupPayment;
import com.dsh.account.feignclient.competition.DeductionCompetitionsClient;
import com.dsh.account.feignclient.competition.model.BillingDataRequestVo;
import com.dsh.account.feignclient.course.CoursePackageClient;
import com.dsh.account.feignclient.course.CoursePackageConfigClient;
import com.dsh.account.feignclient.course.CoursePaymentClient;
import com.dsh.account.feignclient.course.VideoOfCourseListClient;
import com.dsh.account.feignclient.course.model.*;
import com.dsh.account.feignclient.other.*;
import com.dsh.account.feignclient.other.model.*;
import com.dsh.account.mapper.*;
import com.dsh.account.model.*;
import com.dsh.account.model.AppUserByNameAndPhoneDTO;
import com.dsh.account.model.dto.Coupon;
import com.dsh.account.model.query.appUserQuery.QueryAppUser;
import com.dsh.account.model.vo.QueryAppUserVO;
import com.dsh.account.model.vo.classDetails.CourseVenue;
import com.dsh.account.model.vo.classDetails.ExerciseVideo;
import com.dsh.account.model.vo.classDetails.RegisteredCourse;
import com.dsh.account.model.vo.classDetails.classInsVo.ClassInfoVo;
import com.dsh.account.model.vo.userBenefitDetail.*;
import com.dsh.account.service.IRefereeService;
import com.dsh.account.service.TAppGiftService;
import com.dsh.account.service.TAppUserService;
import com.dsh.account.service.UserIntegralChangesService;
import com.dsh.account.util.*;
import com.dsh.account.util.akeylogin.Md5Util;
import com.dsh.account.vo.GroupCityInfoVO;
import com.dsh.account.vo.entity.DayData;
import com.dsh.account.vo.entity.MonthData;
import com.dsh.account.vo.entity.WeekData;
import com.dsh.account.vo.entity.YearData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
/**
*
* 用户信息 服务实现类
*
*
* @author administrator
* @since 2023-06-14
*/
@Service
public class TAppUserServiceImpl extends ServiceImpl implements TAppUserService {
@Resource
private TStudentMapper tsmapper;
@Resource
private ImgConfigClient configClient;
@Autowired
private ALiSendSms aLiSendSms;
@Autowired
private RedisUtil redisUtil;
@Autowired
private GDMapGeocodingUtil gdMapGeocodingUtil;
@Autowired
private JwtTokenUtil jwtTokenUtil;
@Resource
private CoursePaymentClient paymentClient;
@Resource
private StoreClient storeClient;
@Resource
private MerChandiseClient mcClient;
@Resource
private ImgConfigClient icfgClient;
@Resource
private VideoOfCourseListClient voclClient;
@Resource
private VipPaymentMapper vipPaymentMapper;
@Resource
private RechargeRecordsMapper rrMapper;
@Resource
private RechargeConfigClient reconMapper;
@Resource
private UserConponClient ucponClient;
@Resource
private CoursePackageClient cpageClient;
@Resource
private DeductionCompetitionsClient deducClient;
@Resource
private UserIntegralChangesMapper uicMapper;
@Resource
private MerChandiseStoreClient mcsClient;
@Resource
private CoursePackageConfigClient cpconClient;
@Resource
private SiteClient stClient;
@Resource
private TAppUserMapper appUserMapper;
@Autowired
private TAppGiftService appGiftService;
@Resource
private IntroduceRewardsClient introduceRewardsClient;
private String aliAppid = "2021004105665036";//支付宝appid
private String appPrivateKey = "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCi5i9nW/hGLJ3A06cZxTQdviFC7THpdSihoTYGLr9q006hu0V26ecBMY/o4w5bvIX0Ok/yofmZsVcCJpAPvbXL/uqVrIjnRRxXiaeBFThlxoBUTdunvbUSDYfzlEhJr5NvUKI6H6lz2niXlQGx4qy8Hau4ccWit9kM8jwUvsBVQoFgJA+xrjMvooA7YLopQtpOD+UJr5thApTSf1xrnr1W12yolTLEH15JmNV372cqXrYUuqnY0QsaPtxeqJUGAOcGdVLllQ7easEznP8DFBvDdHATcmp2SHNQDUEWN6MCVPbMgY06NQVqAXxqjTAYSVh+6TRu6bofPmpYC3TZB003AgMBAAECggEBAJAcR2+PA3NBYUYHeFrqBRMS8uX8ZR19kjZ7IgoSLTFaQsP9opRylPSPXhrPVBKAE5leRQAHn4MCSlESwHvMfxo7KFjFTFAc6dffZZpipYQUOc9bGampwJh58/3e/pyBgVMG6J23CPf/HJQtNFSkjd/V9+ayb/9l2dUEL3bC0fAZ/dbx8HsxdLw8wn3fLlWLj68hOMqa2deCZe3JdSVsPbeWqkh56FFsMLug0Nd+Ar4TgRl9/jnhXF0JWiD0LmPUYLhboY7EfUBzN4w1iYbDi1P+3zvoOYsiVKAXox9GMhQ2VzOO2UcSTuizSza2e98mGpabl/GpKmCz+RDFjtkX6eECgYEA2MyCij65eO3aGIm3FUe93DULRBYTfX8qJQSJq2WOWA3mmQlEW6L3O2B5/lG2h+8WmN6iLEs9eHpgycGYp7vAqgrANEn16ACVcuyx0scFtrZfZ+kmHMzFfiUWxJjVYk/6YngsGVBLdw6ueM42C8TTP67X9tU5TdVGoGWuqEj4W98CgYEAwFqwprXOch5Pqk/RPbb49r0Ou03K/UbciWnWWKzUhFFNS8MdlQPoDvQZbMwHLeWsa2VhaKITK3x5biLQb3U+0GLOn6lTvEyrEUH+ucREyLgVYTRAvwBPtnvlrzpyxPk2HnslQjju8WrvvLLBMKWUjlTrTOzhaHT21gz3pHMiOakCgYEAhLmfaXdBITGshb054sNLDtdCkGpbgEcrzAHdLps769iGxkYQHXHFngpQZUwtTUcoNGqIKknd1jZFrv7gsD+XkgKG7PwimehRlkwmCX5ilxtLiVgJRzRt6+5U5AMVD90a0tHzXYP0z2yjj73fBJF5KtGl0a10KZxaYrQdm1UhB00CgYBZZgzx/k9rtHC8LAqIj1CYhHejT92G53c6Gkl3vyOqN4sgKhfGmSEySfrDGPRBPZxr8ZtbIPCd5mUdberH0osWGMYFaJI1UsCy7aQwvGpniz7MhZeN7dweaOjwDs8mgtjHQ96mL4XGCDhR0BZ/wIURvZ/6iaGdhbbu9unlsWj3uQKBgQCmZYdsbbZkd3ev6f8rwyvMz+DrCQyYpY44cegBYuJgrZiQnL2fJioeN7ixX0UM48SfwsZEIrzshP/LGAwnc2MdjxKUl4jLN8SEe0NAjXOnz9Zaw740+aOmLpXcLWdP4uM2gIhWsvW1tEkQZCXmm7c9s/RsU8Pmzv+YL3+fSijOzA==";//支付宝开发者应用私钥
private String alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAouYvZ1v4RiydwNOnGcU0Hb4hQu0x6XUooaE2Bi6/atNOobtFdunnATGP6OMOW7yF9DpP8qH5mbFXAiaQD721y/7qlayI50UcV4mngRU4ZcaAVE3bp721Eg2H85RISa+Tb1CiOh+pc9p4l5UBseKsvB2ruHHForfZDPI8FL7AVUKBYCQPsa4zL6KAO2C6KULaTg/lCa+bYQKU0n9ca569VtdsqJUyxB9eSZjVd+9nKl62FLqp2NELGj7cXqiVBgDnBnVS5ZUO3mrBM5z/AxQbw3RwE3JqdkhzUA1BFjejAlT2zIGNOjUFagF8ao0wGElYfuk0bum6Hz5qWAt02QdNNwIDAQAB";//支付宝应用公钥
private String alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmu8n/4yTHWbn7VOrNc9OsLtDL1bEQ8gC1dHkj8Wy5z0mkaOsjJRIG/28ze12M0V8jdCKuuDr5Z1OPKiqf+XO3ypguEh+mYUVMBM/cZodDFQfTY1TKLWjvQCuaqlA+QUTCK6f7T7stsgyQ1o9Jj0rXZDz6PM4QHSTzjrLIBaeqM5WIBvH+fy/X+QG5Utd+/UT0kc0JyvuKhZ65yVUd/C9VcwJJAPliRsAQNrqYterwAJ9zvw9tF11wj9W0XgJ8Ccu4x3gR1vrlLRJJo/OA97RmxPQ+5hSacWQZCUd1dwiBq+YCrKVHGTj14izRHXrLc0yBlRXo7tBOIqcy3IsvKVthQIDAQAB";//支付宝支付公钥
@Resource
private UserConponClient userConponClient;
@Autowired
private TAppUserService appUserService;
@Resource
private MerChandiseClient merChandiseClient;
@Autowired
private PayMoneyUtil payMoneyUtil;
@Resource
private UserCouponPaymentClient userCouponPaymentClient;
@Autowired
private IRefereeService refereeService;
@Resource
private WorldCupPaymentClinet worldCupPaymentClinet;
@Autowired
private UserIntegralChangesService userIntegralChangesService;
@Resource
private GameRecordClient gameRecordClient;
// 对数据进行分页处理的方法
private static Page getPage(List dataList, Pageable pageable) {
int start = (int) pageable.getOffset();
int end = Math.min((start + pageable.getPageSize()), dataList.size());
return new PageImpl<>(dataList.subList(start, end), pageable, dataList.size());
}
@Override
public List listAll(QueryAppUser query) {
return appUserMapper.listAll(query);
}
@Override
public HashMap weeksOfCourseDetailsList(Integer appUserId, Integer stuId, String time, Integer storeId, String lon, String lat) {
// 门店id 查出所有课程
HashMap map = paymentClient.weeksOfCourseDetailsList(new CourseDetailReq(appUserId, stuId, time, storeId, lon, lat));
return map;
}
@Override
public List getSelects(List studentIds) {
return this.baseMapper.getSelects(studentIds);
}
@Override
public Object changeState(AdvertisementChangeStateDTO dto) {
return appUserMapper.changeState(dto.getIds(), dto.getState());
}
@Override
public List queryAPPUserByNameAndPhone(AppUserByNameAndPhoneDTO dto) {
return appUserMapper.queryAPPUserByNameAndPhone(dto);
}
@Override
public List getYearUserCount(UserInfoQueryDTO dto) {
return appUserMapper.getYearUserCount(dto);
}
@Override
public List getMonthUserCount(UserInfoQueryDTO dto) {
List monthUserCount = appUserMapper.getMonthUserCount(dto);
for (int i = 1; i <= 12; i++) {
String time = String.valueOf(i);
if (i < 10) {
time = "0" + time;
}
monthUserCount.add(Optional.ofNullable(monthUserCount.get(i)).orElse(new MonthData(time, 0)));
}
return monthUserCount.stream().sorted(Comparator.comparing(MonthData::getMonth)).collect(Collectors.toList());
}
@Override
public WeekData getWeekUserCount4(UserInfoQueryDTO dto) {
return appUserMapper.getWeekUserCount4(dto);
}
@Override
public WeekData getWeekUserCount3(UserInfoQueryDTO dto) {
return appUserMapper.getWeekUserCount3(dto);
}
@Override
public WeekData getWeekUserCount2(UserInfoQueryDTO dto) {
return appUserMapper.getWeekUserCount2(dto);
}
@Override
public WeekData getWeekUserCount1(UserInfoQueryDTO dto) {
return appUserMapper.getWeekUserCount1(dto);
}
@Override
public List getDayUserCount(UserInfoQueryDTO dto) {
List dayUserCount = appUserMapper.getDayUserCount(dto);
if (dayUserCount.size() < 7) {
for (int i = 1; i <= 6; i++) {
String time = LocalDate.now().minusDays(i).toString();
for (DayData dayData : dayUserCount) {
if (!time.equals(dayData.getDay())) {
dayUserCount.add(new DayData(time, 0));
}
}
}
}
dayUserCount.forEach(dayData -> dayData.setDay(dayData.getDay().split("-")[2]));
return dayUserCount.stream().sorted(Comparator.comparing(DayData::getDay)).collect(Collectors.toList());
}
@Override
public List groupCityInfo(UserInfoQueryDTO dto) {
return appUserMapper.groupCityInfo(dto);
}
@Override
public ClassInfoVo queryUserOfStus(Integer id, Integer uid) {
TAppUser tAppUser = this.baseMapper.selectById(uid);
ClassInfoVo classInfoVo = new ClassInfoVo();
List tStudents = new ArrayList<>();
if (id != null) {
tStudents = tsmapper.selectList(new QueryWrapper()
.eq("id", id).eq("state", 1));
if (tStudents.size() == 0) {
tStudents = tsmapper.selectList(new QueryWrapper()
.eq("appUserId", tAppUser.getId())
.eq("state", 1));
}
} else {
tStudents = tsmapper.selectList(new QueryWrapper()
.eq("appUserId", tAppUser.getId())
.eq("state", 1)
.eq("isDefault", 1));
if (tStudents.isEmpty()) {
tStudents = tsmapper.selectList(new QueryWrapper()
.eq("appUserId", tAppUser.getId())
.eq("state", 1))
;
}
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
if (tStudents.size() > 0) {
TStudent tStudent = tStudents.get(0);
classInfoVo.setStuId(tStudent.getId());
classInfoVo.setIsThere(1);
classInfoVo.setStuImg(tStudent.getHeadImg());
classInfoVo.setStuSex(tStudent.getSex());
classInfoVo.setStuAge(DateUtil.age(tStudent.getBirthday()));
classInfoVo.setStuName(tStudent.getName());
classInfoVo.setHeight(tStudent.getHeight());
classInfoVo.setWeight(tStudent.getWeight());
classInfoVo.setBmi(tStudent.getBmi());
if (tStudent.getBmi() != null) {
classInfoVo.setBodyStatus(BMIBodyUtil.getBodyStatus(tStudent.getBmi()));
}
List courseList = new ArrayList<>();
List stuCoursePayment = paymentClient.getStuCoursePayment(tStudent.getId());
if (stuCoursePayment.size() > 0) {
for (StuCourseResp tCoursePackagePayment : stuCoursePayment) {
RegisteredCourse course = new RegisteredCourse();
course.setId(tCoursePackagePayment.getId());
course.setCourseId(tCoursePackagePayment.getCourseId());
course.setCourseName(tCoursePackagePayment.getCourseName());
course.setTotalNums(ToolUtil.isEmpty(tCoursePackagePayment.getTotalCourseNums()) ? 0 : tCoursePackagePayment.getTotalCourseNums());
course.setDeductedNums(ToolUtil.isEmpty(tCoursePackagePayment.getDeductionNums()) ? 0 : tCoursePackagePayment.getDeductionNums());
course.setRemainingNums(ToolUtil.isEmpty(tCoursePackagePayment.getResidueNums()) ? 0 : tCoursePackagePayment.getResidueNums());
course.setPeriodOfValidity(sdf.format(tStudent.getValidity()));
course.setIsAble(tCoursePackagePayment.getIsAble());
course.setCourseType(tCoursePackagePayment.getCourseType());
courseList.add(course);
}
}
classInfoVo.setCourseList(courseList);
List query = voclClient.query(tStudent.getId());
classInfoVo.setExerciseVideoList(query);
} else {
classInfoVo.setIsThere(2);
List tImgConfigs = configClient.getNoneStuImgs();
if (tImgConfigs.size() > 0) {
classInfoVo.setImgs(tImgConfigs.get(0).getContent());
}
}
return classInfoVo;
}
/**
* 处理数据
*
* @param storeOfCourses
* @param longitude
* @param latitude
* @return
*/
public List dealDatas(List storeOfCourses, String longitude, String latitude) {
List courseVenues = new ArrayList<>();
Map> map = storeOfCourses.stream().collect(Collectors.groupingBy(CourseOfStoreVo::getStoreId));
for (Map.Entry> integerListEntry : map.entrySet()) {
Integer storeId = integerListEntry.getKey();
List value = integerListEntry.getValue();
CourseVenue courseVenue = new CourseVenue();
courseVenue.setStoreId(storeId);
courseVenue.setAreaName(value.get(0).getCourseName());
if (ToolUtil.isEmpty(longitude) && ToolUtil.isEmpty(latitude)) {
courseVenue.setSiteDistance(0 + "");
} else {
courseVenue.setSiteDistance(LonlatUtils.distance(Double.parseDouble(longitude), Double.parseDouble(latitude),
Double.parseDouble(value.get(0).getLon()), Double.parseDouble(value.get(0).getLat())) + "");
}
List courses = new ArrayList<>();
for (CourseOfStoreVo courseOfStoreVo : value) {
CourseVenue.CouList couList = new CourseVenue.CouList();
couList.setCourseID(courseOfStoreVo.getCourseId());
couList.setCourseName(courseOfStoreVo.getCourseName());
couList.setTimeStr(courseOfStoreVo.getClassStartTime() + "-" + courseOfStoreVo.getClassEndTime());
couList.setDetail("¥" + courseOfStoreVo.getCoursePrice() + "/会员扣2学时");
couList.setStatus(courseOfStoreVo.getStatus());
couList.setAllNum(courseOfStoreVo.getAllNum());
couList.setUseNum(courseOfStoreVo.getUseNum());
couList.setLastNum(courseOfStoreVo.getLastNum());
courses.add(couList);
}
courseVenue.setCourses(courses);
courseVenues.add(courseVenue);
}
return courseVenues;
}
/**
* 获取短信验证码
*
* @param type 1:登录,2:注册,3:修改密码,4:忘记密码
* @param phone
* @return
* @throws Exception
*/
@Override
public ResultUtil getSMSCode(Integer type, String phone) throws Exception {
if (type == 2) {
TAppUser tAppUser = this.baseMapper.selectOne(new QueryWrapper().eq("phone", phone).ne("state", 3));
if (null != tAppUser) {
return ResultUtil.error("账号已存在");
}
}
String numberRandom = UUIDUtil.getNumberRandom(6);
String templateCode = "";
if (type == 1 || type == 2) {
templateCode = "SMS_161275250";
}
if (type == 3 || type == 4) {
templateCode = "SMS_160960014";
}
aLiSendSms.sendSms(phone, templateCode, "{\"code\":\"" + numberRandom + "\"}");
redisUtil.setStrValue(phone, numberRandom, 300);
return ResultUtil.success();
}
/**
* 注册用户
*
* @return
* @throws Exception
*/
@Override
public ResultUtil addAppUser(AddAppUserVo addAppUserVo) throws Exception {
TAppUser tAppUser = this.baseMapper.selectOne(new QueryWrapper()
.eq("phone", addAppUserVo.getPhone())
.ne("state", 3));
if (null != tAppUser) {
return ResultUtil.error("账号已存在");
}
String value = redisUtil.getValue(addAppUserVo.getPhone());
if (!"123456".equals(addAppUserVo.getCode()) && (ToolUtil.isEmpty(value) || !value.equals(addAppUserVo.getCode()))) {
return ResultUtil.error("验证码无效");
}
tAppUser = new TAppUser();
tAppUser.setCode(UUIDUtil.getNumberRandom(16));
tAppUser.setPhone(addAppUserVo.getPhone());
tAppUser.setPassword(addAppUserVo.getPassword());
tAppUser.setIsVip(0);
tAppUser.setState(1);
tAppUser.setInsertTime(new Date());
tAppUser.setProvince("");
tAppUser.setProvinceCode("");
tAppUser.setCity("");
tAppUser.setCityCode("");
// 注册用户
int insert = this.baseMapper.insert(tAppUser);
// 介绍有礼
if (addAppUserVo.getReferralUserId() != null || ToolUtil.isNotEmpty(addAppUserVo.getInvitePhone())) {
if (ToolUtil.isEmpty(addAppUserVo.getLat()) || ToolUtil.isEmpty(addAppUserVo.getLon())) {
return ResultUtil.error("请先开启定位", "");
}
Map geocode = gdMapGeocodingUtil.geocode(addAppUserVo.getLon(), addAppUserVo.getLat());
if (null != geocode) {
String cityCode = geocode.get("cityCode");
// 根据所在市code 查询是否有介绍有礼活动
List res = introduceRewardsClient.getGiftList(cityCode);
if (res != null) {
for (IntroduceRewards re : res) {
Integer num = re.getGiveClass();
Integer activityId = re.getId();
if (ToolUtil.isNotEmpty(addAppUserVo.getInvitePhone())) {
List tAppUsers = this.baseMapper.selectList(new LambdaQueryWrapper()
.eq(TAppUser::getPhone, addAppUserVo.getInvitePhone()));
if (tAppUsers.size() > 0) {
addAppUserVo.setReferralUserId(tAppUsers.get(0).getId());
}
}
if (num != 0) {
TAppGift tAppGift = new TAppGift();
TAppUser phone = appUserService.getOne(new QueryWrapper()
.eq("phone", addAppUserVo.getInvitePhone()));
if (phone == null) {
return ResultUtil.error("推荐人手机号未注册玩湃会员!");
} else {
tAppGift.setUserName(phone.getName());
tAppGift.setUserPhone(phone.getPhone());
}
tAppGift.setUserId(addAppUserVo.getReferralUserId());
tAppGift.setNum(num);
tAppGift.setShareUserId(tAppUser.getId());
tAppGift.setShareUserName(tAppUser.getPhone());
tAppGift.setShareUserPhone(tAppUser.getPhone());
tAppGift.setActivityId(activityId);
tAppGift.setInsertTime(new Date());
appGiftService.save(tAppGift);
}
}
}
}
}
return ResultUtil.success();
}
/**
* 账号密码登录
*
* @param phone
* @param password
* @return
* @throws Exception
*/
@Override
public ResultUtil loginPassword(String phone, String password) throws Exception {
TAppUser tAppUser = this.baseMapper.selectOne(new QueryWrapper().eq("phone", phone).ne("state", 3));
if (null == tAppUser) {
return ResultUtil.error("请先注册", "");
}
if (tAppUser.getState() == 2) {
return ResultUtil.errorCode("您的账号已被冻结", "");
}
// password = Md5Util.MD5Encode(password, null);
if (!tAppUser.getPassword().equals(password)) {
return ResultUtil.error("账号密码错误", "");
}
String token = getToken(tAppUser);
return ResultUtil.success(token);
}
/**
* 验证码登录
*
* @return
* @throws Exception
*/
@Override
public ResultUtil loginSMSCode(LoginSMSCodeVo loginSMSCodeVo) throws Exception {
String value = redisUtil.getValue(loginSMSCodeVo.getPhone());
if (!"123456".equals(loginSMSCodeVo.getCode()) && (ToolUtil.isEmpty(value) || !value.equals(loginSMSCodeVo.getCode()))) {
return ResultUtil.error("验证码无效", "");
}
TAppUser tAppUser = this.baseMapper.selectOne(new QueryWrapper().eq("phone", loginSMSCodeVo.getPhone()).ne("state", 3));
if (null == tAppUser) {
tAppUser = new TAppUser();
tAppUser.setCode(UUIDUtil.getNumberRandom(16));
tAppUser.setPhone(loginSMSCodeVo.getPhone());
tAppUser.setPassword(Md5Util.MD5Encode("111111", null));
tAppUser.setIsVip(0);
tAppUser.setState(1);
tAppUser.setInsertTime(new Date());
this.baseMapper.insert(tAppUser);
}
if (tAppUser.getState() == 2) {
return ResultUtil.error("您的账号已被冻结", "");
}
String token = getToken(tAppUser);
return ResultUtil.success(token);
}
/**
* 微信登录
*
* @return
* @throws Exception
*/
@Override
public ResultUtil loginWechat(LoginWeChatVo loginWechatVo) throws Exception {
TAppUser tAppUser = this.baseMapper.selectOne(new QueryWrapper().eq("openid", loginWechatVo.getOpenId()).ne("state", 3));
if (null == tAppUser) {
tAppUser = this.baseMapper.selectOne(new QueryWrapper().eq("phone", loginWechatVo.getPhone()).ne("state", 3));
if (null == tAppUser) {
tAppUser = new TAppUser();
tAppUser.setCode(UUIDUtil.getNumberRandom(16));
tAppUser.setOpenid(loginWechatVo.getOpenId());
tAppUser.setPhone(loginWechatVo.getPhone());
tAppUser.setPassword(Md5Util.MD5Encode("111111", null));
tAppUser.setIsVip(0);
tAppUser.setName(loginWechatVo.getNickname());
tAppUser.setHeadImg(loginWechatVo.getHeadimgurl());
tAppUser.setGender(loginWechatVo.getSex());
tAppUser.setState(1);
tAppUser.setInsertTime(new Date());
tAppUser.setProvince("");
tAppUser.setProvinceCode("");
tAppUser.setCity("");
tAppUser.setCityCode("");
this.baseMapper.insert(tAppUser);
}
}
if (tAppUser.getState() == 2) {
return ResultUtil.error("您的账号已被冻结", "");
}
if (ToolUtil.isEmpty(tAppUser.getOpenid())) {
tAppUser.setOpenid(loginWechatVo.getOpenId());
}
if (ToolUtil.isEmpty(tAppUser.getPhone())) {
tAppUser.setPhone(loginWechatVo.getPhone());
}
this.updateById(tAppUser);
String token = getToken(tAppUser);
HashMap map = new HashMap<>();
map.put("token", token);
if (ToolUtil.isEmpty(tAppUser.getPhone())) {
map.put("isBind", "0");
} else {
map.put("isBind", "1");
}
return ResultUtil.success(map);
}
/**
* 获取JWT token和存储个人信息
*
* @param appUser
* @return
*/
private String getToken(TAppUser appUser) {
String randomKey = jwtTokenUtil.getRandomKey();
String token = jwtTokenUtil.generateToken(appUser.getId().toString(), randomKey);
redisUtil.setStrValue(token.substring(token.length() - 32), String.valueOf(appUser.getId()), 7 * 24 * 60 * 60);
redisUtil.setStrValue("USER_" + appUser.getPhone(), token.substring(token.length() - 32));
redisUtil.setStrValue("USER_" + appUser.getId(), token);
return token;
}
/**
* 修改密码
*
* @param phone
* @param code
* @param password
* @return
* @throws Exception
*/
@Override
public ResultUtil updatePassword(String phone, String code, String password) throws Exception {
String value = redisUtil.getValue(phone);
if (!"123456".equals(code) && (ToolUtil.isEmpty(value) || !value.equals(code))) {
return ResultUtil.error("验证码无效");
}
TAppUser tAppUser = this.baseMapper.selectOne(new QueryWrapper().eq("phone", phone).ne("state", 3));
if (tAppUser == null) {
return ResultUtil.error("该账号未注册", "");
}
if (tAppUser.getState() == 2) {
return ResultUtil.error("您的账号已被冻结", "");
}
if (tAppUser.getCode() == null) {
tAppUser.setCode(UUIDUtil.getNumberRandom(16));
}
tAppUser.setPassword(password);
this.updateById(tAppUser);
return ResultUtil.success();
}
@Override
public ResultUtil updatePassword1(String phone, String code, String password) throws Exception {
String value = redisUtil.getValue(phone);
if (!"123456".equals(code) && (ToolUtil.isEmpty(value) || !value.equals(code))) {
return ResultUtil.error("验证码无效");
}
TAppUser tAppUser = this.baseMapper.selectOne(new QueryWrapper().eq("phone", phone).ne("state", 3));
if (tAppUser == null) {
return ResultUtil.error("该账号未注册", "");
}
if (tAppUser.getState() == 2) {
return ResultUtil.error("您的账号已被冻结", "");
}
if (tAppUser.getCode() == null) {
tAppUser.setCode(UUIDUtil.getNumberRandom(16));
}
tAppUser.setPassword(password);
this.updateById(tAppUser);
return ResultUtil.success();
}
/**
* 定时任务修改到期会员的状态
*/
@Override
public void membershipEnd() {
this.baseMapper.membershipEnd();
}
/**
* 获取加入玩湃首页数据
*
* @param lon
* @param lat
* @return
* @throws Exception
*/
@Override
public JoinPlayPaiVo queryJoinPlayPai(Integer uid, String lon, String lat) throws Exception {
TAppUser appUser = this.getById(uid);
if (ToolUtil.isEmpty(appUser.getProvince()) && ToolUtil.isNotEmpty(lon)) {
Map geocode = gdMapGeocodingUtil.geocode(lon, lat);
if (null != geocode) {
String province = geocode.get("province");
String provinceCode = geocode.get("provinceCode");
String city = geocode.get("city");
String cityCode = geocode.get("cityCode");
appUser.setProvince(province);
appUser.setProvinceCode(provinceCode);
appUser.setCity(city);
appUser.setCityCode(cityCode);
this.updateById(appUser);
}
}
JoinPlayPaiVo joinPlayPaiVo = new JoinPlayPaiVo();
joinPlayPaiVo.setIsVip(appUser.getIsVip());
if (ToolUtil.isEmpty(lon) || ToolUtil.isEmpty(lat)) {
return joinPlayPaiVo;
}
Map geocode = gdMapGeocodingUtil.geocode(lon, lat);
if (null != geocode) {
String provinceCode = geocode.get("provinceCode");
String cityCode = geocode.get("cityCode");
List stores = storeClient.queryStoreList(new QueryStoreList(provinceCode, cityCode));
Store s = null;
Double d = 0D;
for (Store store : stores) {
Map distance = GeodesyUtil.getDistance(lon + "," + lat, store.getLon() + "," + store.getLat());
Double wgs84 = distance.get("WGS84");
if (s == null || d > wgs84) {
s = store;
d = wgs84;
}
}
joinPlayPaiVo.setName(s.getName());
joinPlayPaiVo.setLon(s.getLon());
joinPlayPaiVo.setLat(s.getLat());
joinPlayPaiVo.setStoreId(s.getId());
joinPlayPaiVo.setPhone(s.getPhone());
joinPlayPaiVo.setProvince(s.getProvince());
joinPlayPaiVo.setProvinceCode(s.getProvinceCode());
joinPlayPaiVo.setCity(s.getCity());
joinPlayPaiVo.setCityCode(s.getCityCode());
}
return joinPlayPaiVo;
}
@Override
public IndexOfUserBenefirVo queryBenefitDetails(Integer appUserId, String lon, String lat) {
IndexOfUserBenefirVo benefirVo = new IndexOfUserBenefirVo();
TAppUser appUser = this.getById(appUserId);
if (appUser.getHeadImg() != null) {
benefirVo.setUserHeadImg(appUser.getHeadImg());
} else {
benefirVo.setUserHeadImg("https://we-park-life.oss-cn-beijing.aliyuncs.com/img/630864764d3c4e98822ff976a2389559.jpg");
}
benefirVo.setUserName(appUser.getName());
benefirVo.setWpCoin(ToolUtil.isEmpty(appUser.getPlayPaiCoins()) ? 0 : appUser.getPlayPaiCoins());
benefirVo.setUserIntegral(ToolUtil.isEmpty(appUser.getIntegral()) ? 0 : appUser.getIntegral());
if (appUser.getIsVip() == 1) {
benefirVo.setIsMember("年度会员");
} else {
benefirVo.setIsMember("普通用户");
}
Location location = new Location();
location.setLat(lat);
location.setLon(lon);
List convertibleGoods = mcClient.getConvertibleGoods(location);
benefirVo.setCommodities(convertibleGoods);
benefirVo.setImage(icfgClient.getImageConfig());
Referee referee = refereeService.getOne(new QueryWrapper().eq("phone", appUser.getPhone()).eq("state", 1));
benefirVo.setReferee(null == referee ? 0 : 1);
return benefirVo;
}
@Override
public List queryUserBillingDetails(String yearMonth, Integer recordId, Integer appUserId) {
List details = new ArrayList<>();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd HH:mm");
SimpleDateFormat result = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date monthStart = null;
Date monthEnd = null;
if (StringUtils.hasText(yearMonth)) {
monthStart = DateTimeHelper.getCurrentIdetMouthStart(yearMonth);
monthEnd = DateTimeHelper.getCurrentIdeaMouthEnd(yearMonth);
} else {
monthStart = DateTimeHelper.getCurrentMouthStart();
monthEnd = DateTimeHelper.getCurrentMouthEnd();
}
BillingDataRequestVo requestVo = new BillingDataRequestVo();
requestVo.setMonthStart(result.format(monthStart));
requestVo.setMonthEnd(result.format(monthEnd));
requestVo.setAppUserId(appUserId);
// 1.赛事报名
BillingRequestVo allCompetitionPayRecord = deducClient.getAllCompetitionPayRecord(requestVo);
if (ToolUtil.isNotEmpty(allCompetitionPayRecord.getRequests())) {
for (BillingRequest paymentCompetition : allCompetitionPayRecord.getRequests()) {
ConsumeDetail consumeDetail = new ConsumeDetail();
consumeDetail.setConsumeName(RechargeRecordEnum.EVENT_REGISTRATION.getMsg());
consumeDetail.setConsumeTime(paymentCompetition.getTime());
consumeDetail.setConsumeAmount("-" + paymentCompetition.getAmount());
consumeDetail.setType(2);
consumeDetail.setDateTime(paymentCompetition.getDateTime());
details.add(consumeDetail);
}
}
// 2.取消赛事报名
BillingRequestVo cancelOrderOfUserPayRecord = deducClient.getCancelOrderOfUserPayRecord(requestVo);
if (ToolUtil.isNotEmpty(cancelOrderOfUserPayRecord.getRequests())) {
for (BillingRequest paymentCompetition : cancelOrderOfUserPayRecord.getRequests()) {
ConsumeDetail consumeDetail = new ConsumeDetail();
consumeDetail.setConsumeName(RechargeRecordEnum.CANCEL_EVENT_REGISTRATION.getMsg());
consumeDetail.setConsumeTime(paymentCompetition.getTime());
consumeDetail.setConsumeAmount("+" + paymentCompetition.getAmount());
consumeDetail.setType(1);
consumeDetail.setDateTime(paymentCompetition.getDateTime());
details.add(consumeDetail);
}
}
//3.课包购买
List coursePackageOrder = paymentClient.getCoursePackageOrder(requestVo);
for (CoursePackageOrder order : coursePackageOrder) {
ConsumeDetail consumeDetail = new ConsumeDetail();
consumeDetail.setConsumeName("课程报名");
consumeDetail.setConsumeTime(simpleDateFormat.format(order.getInsertTime()));
consumeDetail.setConsumeAmount("-" + order.getCashPayment());
consumeDetail.setType(2);
consumeDetail.setDateTime(order.getInsertTime().getTime());
details.add(consumeDetail);
}
// 4.场地预约
RequestOfTypeVo allSiteBookingList = stClient.getAllSiteBookingList(requestVo);
if (ToolUtil.isNotEmpty(allSiteBookingList.getRequest())) {
for (BillingRequestOfType booking : allSiteBookingList.getRequest()) {
ConsumeDetail consumeDetail = new ConsumeDetail();
if (booking.getStatus() != 5) {
consumeDetail.setConsumeName(RechargeRecordEnum.VENUE_RESERVATION.getMsg());
consumeDetail.setConsumeAmount("-" + booking.getAmount());
consumeDetail.setConsumeTime(booking.getTime());
consumeDetail.setType(2);
consumeDetail.setDateTime(booking.getDateTime());
details.add(consumeDetail);
} else {
ConsumeDetail consumeDetail1 = new ConsumeDetail();
consumeDetail1.setConsumeName(RechargeRecordEnum.CANCEL_VENUE_RESERVATION.getMsg());
consumeDetail1.setConsumeAmount("+" + booking.getAmount());
consumeDetail1.setConsumeTime(booking.getTime());
consumeDetail1.setDateTime(booking.getDateTime());
consumeDetail1.setType(1);
details.add(consumeDetail1);
ConsumeDetail consumeDetail2 = new ConsumeDetail();
consumeDetail2.setConsumeName(RechargeRecordEnum.VENUE_RESERVATION.getMsg());
consumeDetail2.setConsumeAmount("-" + booking.getAmount());
consumeDetail2.setConsumeTime(booking.getTime1());
consumeDetail2.setType(2);
consumeDetail2.setDateTime(booking.getDateTime());
details.add(consumeDetail2);
}
}
}
// 5.智慧球场
GetTGameRecord getTGameRecord = new GetTGameRecord();
getTGameRecord.setAppUserId(appUserId);
getTGameRecord.setStartTiem(monthStart);
getTGameRecord.setEndTime(monthEnd);
List tGameRecord = gameRecordClient.getTGameRecord(getTGameRecord);
for (TGameRecord gameRecord : tGameRecord) {
ConsumeDetail consumeDetail = new ConsumeDetail();
consumeDetail.setConsumeName(RechargeRecordEnum.SMART_STADIUM.getMsg());
consumeDetail.setConsumeTime(simpleDateFormat.format(gameRecord.getTime()));
consumeDetail.setConsumeAmount("-" + gameRecord.getMoney());
consumeDetail.setType(2);
consumeDetail.setDateTime(gameRecord.getTime().getTime());
details.add(consumeDetail);
}
// 6.年度会员
List vipPayments = vipPaymentMapper.selectList(new QueryWrapper()
.eq("payStatus", 2)
.eq("appUserId", appUserId)
.between("insertTime", monthStart, monthEnd));
if (vipPayments.size() > 0) {
for (VipPayment vipPayment : vipPayments) {
ConsumeDetail consumeDetail = new ConsumeDetail();
consumeDetail.setConsumeName(RechargeRecordEnum.ANNUAL_MEMBERSHIP.getMsg());
consumeDetail.setConsumeTime(simpleDateFormat.format(vipPayment.getInsertTime()));
consumeDetail.setConsumeAmount("-" + vipPayment.getAmount());
consumeDetail.setType(2);
consumeDetail.setDateTime(vipPayment.getPayTime().getTime());
details.add(consumeDetail);
}
}
// 7.充值
List rechargeRecords = rrMapper.selectList(new QueryWrapper()
.eq("payStatus", 2)
.eq("appUserId", appUserId)
.between("insertTime", monthStart, monthEnd));
if (rechargeRecords.size() > 0) {
for (RechargeRecords rechargeRecord : rechargeRecords) {
ConsumeDetail consumeDetail = new ConsumeDetail();
consumeDetail.setConsumeName(RechargeRecordEnum.RECHARGE.getMsg() + ":" + rechargeRecord.getPlayPaiCoins() + "币");
consumeDetail.setConsumeTime(simpleDateFormat.format(rechargeRecord.getInsertTime()));
consumeDetail.setConsumeAmount("-" + rechargeRecord.getAmount());
consumeDetail.setType(2);
consumeDetail.setDateTime(rechargeRecord.getPayTime().getTime());
details.add(consumeDetail);
}
}
//8.积分商场
List consumeDetails = mcClient.getConsumeDetails(requestVo);
details.addAll(consumeDetails);
//世界杯
GetWorldCupPayment getWorldCupPayment = new GetWorldCupPayment();
getWorldCupPayment.setAppUserId(appUserId);
getWorldCupPayment.setPayType("1,2");
getWorldCupPayment.setStartTime(monthStart);
getWorldCupPayment.setEndTime(monthEnd);
List worldCupPayment = worldCupPaymentClinet.getWorldCupPayment(getWorldCupPayment);
for (WorldCupPayment cupPayment : worldCupPayment) {
ConsumeDetail consumeDetail = new ConsumeDetail();
if(cupPayment.getPayStatus() != 3){
consumeDetail.setConsumeName(RechargeRecordEnum.WORLD_CIP_PAYMENT.getMsg());
consumeDetail.setConsumeTime(simpleDateFormat.format(cupPayment.getCreateTime()));
consumeDetail.setConsumeAmount("-" + cupPayment.getAmount());
consumeDetail.setType(2);
consumeDetail.setDateTime(cupPayment.getPayTime().getTime());
details.add(consumeDetail);
}else{
consumeDetail = new ConsumeDetail();
consumeDetail.setConsumeName(RechargeRecordEnum.WORLD_CIP_PAYMENT.getMsg());
consumeDetail.setConsumeTime(simpleDateFormat.format(cupPayment.getCreateTime()));
consumeDetail.setConsumeAmount("-" + cupPayment.getAmount());
consumeDetail.setType(2);
consumeDetail.setDateTime(cupPayment.getPayTime().getTime());
details.add(consumeDetail);
consumeDetail = new ConsumeDetail();
consumeDetail.setConsumeName(RechargeRecordEnum.CANCEL_WORLD_CIP_PAYMENT.getMsg());
consumeDetail.setConsumeTime(simpleDateFormat.format(cupPayment.getCreateTime()));
consumeDetail.setConsumeAmount("+" + cupPayment.getRefundAmount());
consumeDetail.setType(1);
consumeDetail.setDateTime(cupPayment.getRefundTime().getTime());
details.add(consumeDetail);
}
}
if (details.size() > 0) {
Collections.sort(details, new Comparator() {
@Override
public int compare(ConsumeDetail record1, ConsumeDetail record2) {
return record1.getDateTime().compareTo(record2.getDateTime()) * -1;
}
});
if (ToolUtil.isNotEmpty(recordId)) {
details = details.stream()
.filter(response -> Objects.equals(response.getType(), recordId))
.collect(Collectors.toList());
}
}
return details;
}
@Override
public void cancellation(Integer appUserId) {
TAppUser tAppUser = this.baseMapper.selectById(appUserId);
if (null != tAppUser) {
tAppUser.setState(3);
this.baseMapper.updateById(tAppUser);
}
}
@Override
public List getSysRechargeConfig(Integer appUserId) {
List centVos = new ArrayList<>();
TAppUser tAppUser = this.baseMapper.selectById(appUserId);
List