优化
This commit is contained in:
@@ -8,4 +8,11 @@ public interface ShopUserService {
|
|||||||
ShopUser login(ShopUserResq shopUser);
|
ShopUser login(ShopUserResq shopUser);
|
||||||
|
|
||||||
ShopUser modifyUser(ShopUser shopUser);
|
ShopUser modifyUser(ShopUser shopUser);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新用户vip时间
|
||||||
|
* @param userId 用户id
|
||||||
|
* @param type 1 - 月 2-季 3-半年 4-年
|
||||||
|
*/
|
||||||
|
ShopUser updateShopUserVipTime(Long userId, String type);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.ruoyi.common.core.domain.entity.ShopUser;
|
|||||||
import com.ruoyi.common.core.domain.entity.ShopUserResq;
|
import com.ruoyi.common.core.domain.entity.ShopUserResq;
|
||||||
import com.ruoyi.common.core.redis.RedisCache;
|
import com.ruoyi.common.core.redis.RedisCache;
|
||||||
import com.ruoyi.common.utils.MusicUtil;
|
import com.ruoyi.common.utils.MusicUtil;
|
||||||
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.system.config.UmengConfig;
|
import com.ruoyi.system.config.UmengConfig;
|
||||||
import com.ruoyi.system.mapper.ActivityInfoMapper;
|
import com.ruoyi.system.mapper.ActivityInfoMapper;
|
||||||
@@ -18,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -129,6 +131,80 @@ public class CShopUserServiceImpl implements ShopUserService {
|
|||||||
return shopUser;
|
return shopUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ShopUser updateShopUserVipTime(Long userId, String type) {
|
||||||
|
// 更新用户vip时间
|
||||||
|
// * @param userId 用户id
|
||||||
|
// * @param type 1 - 月 2-季 3-半年 4-年
|
||||||
|
|
||||||
|
// 根据type计算天数
|
||||||
|
int days = 0;
|
||||||
|
switch (type) {
|
||||||
|
case "1":
|
||||||
|
days = 30; // 月
|
||||||
|
break;
|
||||||
|
case "2":
|
||||||
|
days = 90; // 季
|
||||||
|
break;
|
||||||
|
case "3":
|
||||||
|
days = 180; // 半年
|
||||||
|
break;
|
||||||
|
case "4":
|
||||||
|
days = 365; // 年
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ShopUser errorMsg = new ShopUser();
|
||||||
|
errorMsg.setMsg("VIP类型参数错误");
|
||||||
|
return errorMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询用户信息
|
||||||
|
ShopUser shopUser = shopUserMapper.selectShopUserByUserId(userId);
|
||||||
|
if (shopUser == null) {
|
||||||
|
ShopUser errorMsg = new ShopUser();
|
||||||
|
errorMsg.setMsg("用户不存在");
|
||||||
|
return errorMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断是否需要续期(如果VIP未过期,从结束时间开始续期)
|
||||||
|
Date startTime;
|
||||||
|
Date endTime;
|
||||||
|
Date currentDate = new Date();
|
||||||
|
|
||||||
|
if (shopUser.getVip() != null && shopUser.getVip() == 1L
|
||||||
|
&& shopUser.getVipEndTime() != null
|
||||||
|
&& shopUser.getVipEndTime().after(currentDate)) {
|
||||||
|
// VIP未过期,从结束时间开始续期
|
||||||
|
// 保持原有开始时间,如果为空则使用当前时间
|
||||||
|
startTime = (shopUser.getVipStartTime() != null)
|
||||||
|
? shopUser.getVipStartTime()
|
||||||
|
: currentDate;
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(shopUser.getVipEndTime());
|
||||||
|
calendar.add(Calendar.DAY_OF_YEAR, days);
|
||||||
|
endTime = calendar.getTime();
|
||||||
|
} else {
|
||||||
|
// VIP已过期或不是VIP,从当前时间开始计算
|
||||||
|
startTime = currentDate;
|
||||||
|
endTime = MusicUtil.getDateAfterNDays(days);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新VIP信息
|
||||||
|
shopUser.setVip(1L);
|
||||||
|
shopUser.setVipStartTime(startTime);
|
||||||
|
shopUser.setVipEndTime(endTime);
|
||||||
|
|
||||||
|
// 更新到数据库
|
||||||
|
int updateCount = shopUserMapper.updateShopUser(shopUser);
|
||||||
|
if (updateCount > 0) {
|
||||||
|
return shopUser;
|
||||||
|
} else {
|
||||||
|
ShopUser errorMsg = new ShopUser();
|
||||||
|
errorMsg.setMsg("VIP时间更新失败");
|
||||||
|
return errorMsg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ShopUser loginAndRegis(ShopUserResq shopUser) {
|
public ShopUser loginAndRegis(ShopUserResq shopUser) {
|
||||||
ShopUser member = shopUserMapper.selectShopUserByPhone(shopUser.getPhone());
|
ShopUser member = shopUserMapper.selectShopUserByPhone(shopUser.getPhone());
|
||||||
if (shopUser.getPhone() != null && StringUtils.isNull(member)) {
|
if (shopUser.getPhone() != null && StringUtils.isNull(member)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user