From 72a98693ee9442641cd31353c9777d9b572079f7 Mon Sep 17 00:00:00 2001 From: linhw <5331581+linhw11@user.noreply.gitee.com> Date: Wed, 26 Jun 2024 16:20:29 +0800 Subject: [PATCH 1/2] ~ --- .../service/impl/AppRegisterServiceImpl.java | 73 +++++++++++++++++-- 1 file changed, 66 insertions(+), 7 deletions(-) diff --git a/gan-modules/ruoyi-gan/src/main/java/com/ruoyi/app/service/impl/AppRegisterServiceImpl.java b/gan-modules/ruoyi-gan/src/main/java/com/ruoyi/app/service/impl/AppRegisterServiceImpl.java index 402a83f..dc2f4df 100644 --- a/gan-modules/ruoyi-gan/src/main/java/com/ruoyi/app/service/impl/AppRegisterServiceImpl.java +++ b/gan-modules/ruoyi-gan/src/main/java/com/ruoyi/app/service/impl/AppRegisterServiceImpl.java @@ -1,20 +1,20 @@ package com.ruoyi.app.service.impl; +import java.util.Date; import java.util.List; import java.util.stream.Collectors; import cn.hutool.core.lang.Assert; import cn.hutool.http.HttpUtil; -import com.ruoyi.app.domain.AppSchool; -import com.ruoyi.app.domain.AppUser; +import com.ruoyi.app.domain.*; import com.ruoyi.app.domain.vo.AppRegisterVo; -import com.ruoyi.app.mapper.AppSchoolMapper; -import com.ruoyi.app.mapper.AppUserMapper; +import com.ruoyi.app.mapper.*; import com.ruoyi.app.utils.aliyun.sms.SendNoteUtil; import com.ruoyi.common.core.utils.DateUtils; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.bean.BeanUtils; import com.ruoyi.common.core.utils.mail.AliMailUtil; +import com.ruoyi.common.core.web.domain.AjaxResult; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; @@ -22,8 +22,6 @@ import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.ruoyi.app.mapper.AppRegisterMapper; -import com.ruoyi.app.domain.AppRegister; import com.ruoyi.app.service.IAppRegisterService; import javax.mail.MessagingException; @@ -48,6 +46,16 @@ public class AppRegisterServiceImpl implements IAppRegisterService { @Autowired private SendNoteUtil sendNoteUtil; + @Autowired + private AppOrderMapper appOrderMapper; + + @Autowired + private AppOrderPayMapper appOrderPayMapper; + + @Autowired + private AppExchangeCodeMapper appExchangeCodeMapper; + + /** * 查询注册审核 * @@ -138,6 +146,13 @@ public class AppRegisterServiceImpl implements IAppRegisterService { AppRegister appRegister = appRegisterMapper.selectAppRegisterById(id); Assert.isTrue(appRegister != null, "该申请不存在"); Assert.isTrue(appRegister.getStatus() != null && appRegister.getStatus() == 0, "该申请已审核"); + AppExchangeCode appExchangeCode = null; + if (org.apache.commons.lang3.StringUtils.isNotBlank(appRegister.getInvitationCode())) { + appExchangeCode = appExchangeCodeMapper.selectAppExchangeCodeByCode(appRegister.getInvitationCode()); + if (appExchangeCode == null || appExchangeCode.getUserId() != null) { + Assert.isTrue(false, "该兑换码不存在或已被使用,请检查该兑换码是否正确!"); + } + } appRegister.setStatus(1); appRegister.setUpdateTime(DateUtils.getNowDate()); int i = appRegisterMapper.updateAppRegister(appRegister); @@ -162,6 +177,10 @@ public class AppRegisterServiceImpl implements IAppRegisterService { appUser.setCityId(appRegister.getCityId() != null ? appRegister.getCityId() : null); appUser.setTownId(appRegister.getTownId() != null ? appRegister.getTownId() : null); appUserMapper.insertAppUser(appUser); + if (appExchangeCode != null && appExchangeCode.getId() != null) { + useExchange(appExchangeCode,appUser.getId()); + } + sendNoteUtil.sendMessage(appRegister.getPhone()); HttpClient httpClient = HttpClients.createDefault(); String pushId = appRegister.getPushId() != null ? appRegister.getPushId() : null; @@ -178,10 +197,50 @@ public class AppRegisterServiceImpl implements IAppRegisterService { e.printStackTrace(); } } - return i; } + private void useExchange(AppExchangeCode appExchangeCode,Long userId){ + AppExchangeCode entity = new AppExchangeCode(); + entity.setUserId(userId); + entity.setUserTime(new Date()); + entity.setId(appExchangeCode.getId()); + appExchangeCodeMapper.updateAppExchangeCode(entity); + + // 生成订单信息 + AppOrder order = new AppOrder(); + order.setOutTradeNo(appExchangeCode.getCode()); + order.setPrice("0"); + order.setUserId(userId); + order.setPayStatus(2); + order.setPaySoure(3); + order.setCreateTime(new Date()); + order.setLevel(appExchangeCode.getLevel()); + appOrderMapper.insertAppOrder(order); + + // 修改用户信息 + AppUser appUser = appUserMapper.selectAppUserById(order.getUserId()); + AppUser userEntity = new AppUser(); + userEntity.setId(appUser.getId()); + userEntity.setIsMember(0); + userEntity.setOrderId(order.getId()); + // 开始时间,结束时间 + Date startDate = appUser.getOrderStartTime(); + if (null == startDate) { + startDate = new Date(); + } + Date endDate = appUser.getOrderEndTime(); + if (endDate == null) { + endDate = startDate; + } + endDate = order.getLevel() == 1 ? DateUtils.dateAddTime(endDate,3,7) + : (order.getLevel() == 2 ? DateUtils.dateAddTime(endDate,4,31) : DateUtils.dateAddTime(endDate,5,365)); + userEntity.setOrderStartTime(startDate); + userEntity.setOrderEndTime(endDate); + userEntity.setUpdateTime(new Date()); + appUserMapper.updateAppUser(userEntity); + } + @Override public int rejectAppRegister(AppRegister appRegister) { AppRegister register = appRegisterMapper.selectAppRegisterById(appRegister.getId()); From fe7bca71eeaad975371f687eef439b4a3a5db140 Mon Sep 17 00:00:00 2001 From: linhw <5331581+linhw11@user.noreply.gitee.com> Date: Wed, 26 Jun 2024 17:29:20 +0800 Subject: [PATCH 2/2] ~ --- .../ruoyi-gan/src/main/resources/mapper/app/AppUserMapper.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gan-modules/ruoyi-gan/src/main/resources/mapper/app/AppUserMapper.xml b/gan-modules/ruoyi-gan/src/main/resources/mapper/app/AppUserMapper.xml index c089f04..ff828de 100644 --- a/gan-modules/ruoyi-gan/src/main/resources/mapper/app/AppUserMapper.xml +++ b/gan-modules/ruoyi-gan/src/main/resources/mapper/app/AppUserMapper.xml @@ -178,7 +178,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" left join app_school s on s.id = a.school left join app_user_fans f on f.user_id = a.id left join app_user_fans fa on fa.friend_id = a.id - left join app_user_friend r on r.user_id = a.id + left join app_user_friend r on r.user_id = a.id and r.status = 0 left join app_dynamic_like l on l.dynamic_user_id = a.id left join app_town t on t.id = a.address where a.id = #{id}