|
@@ -5,20 +5,21 @@ import cn.binarywang.wx.miniapp.api.WxMaUserService;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import com.atguigu.tingshu.album.AlbumFeignClient;
|
|
|
import com.atguigu.tingshu.common.constant.RedisConstant;
|
|
|
-import com.atguigu.tingshu.common.constant.SystemConstant;
|
|
|
import com.atguigu.tingshu.common.rabbit.constant.MqConst;
|
|
|
import com.atguigu.tingshu.common.rabbit.service.RabbitService;
|
|
|
import com.atguigu.tingshu.common.util.AuthContextHolder;
|
|
|
-import com.atguigu.tingshu.model.album.TrackInfo;
|
|
|
-import com.atguigu.tingshu.model.user.*;
|
|
|
+import com.atguigu.tingshu.model.user.UserInfo;
|
|
|
+import com.atguigu.tingshu.model.user.UserPaidAlbum;
|
|
|
+import com.atguigu.tingshu.model.user.UserPaidTrack;
|
|
|
import com.atguigu.tingshu.user.mapper.*;
|
|
|
import com.atguigu.tingshu.user.service.UserInfoService;
|
|
|
import com.atguigu.tingshu.user.service.UserPaidTrackService;
|
|
|
+import com.atguigu.tingshu.user.strategy.PaidRecordStrategy;
|
|
|
+import com.atguigu.tingshu.user.strategy.factory.StrategyFactory;
|
|
|
import com.atguigu.tingshu.vo.user.UserInfoVo;
|
|
|
import com.atguigu.tingshu.vo.user.UserPaidRecordVo;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
@@ -30,7 +31,6 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -249,6 +249,9 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> i
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private StrategyFactory strategyFactory;
|
|
|
+
|
|
|
/**
|
|
|
* 虚拟物品发货,保存购买记录(声音、专辑、VIP会员)
|
|
|
*
|
|
@@ -259,93 +262,10 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> i
|
|
|
public void savePaidRecord(UserPaidRecordVo userPaidRecordVo) {
|
|
|
//1.获取付款项目类型 付款项目类型: 1001-专辑 1002-声音 1003-vip会员
|
|
|
String itemType = userPaidRecordVo.getItemType();
|
|
|
- //2.处理付款项目类型为:声音 新增声音购买记录
|
|
|
- if (SystemConstant.ORDER_ITEM_TYPE_TRACK.equals(itemType)) {
|
|
|
- //2.1 判断订单编号是否已处理
|
|
|
- Long count = userPaidTrackMapper.selectCount(
|
|
|
- new LambdaQueryWrapper<UserPaidTrack>()
|
|
|
- .eq(UserPaidTrack::getOrderNo, userPaidRecordVo.getOrderNo())
|
|
|
- );
|
|
|
- if (count > 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
- //2.2 未处理 构建声音购买记录(可能存在多条) 完成新增
|
|
|
- List<Long> trackIdList = userPaidRecordVo.getItemIdList();
|
|
|
- if (CollUtil.isNotEmpty(trackIdList)) {
|
|
|
- //2.2.1 根据声音ID远程调用"专辑服务"查询声音信息
|
|
|
- TrackInfo trackInfo = albumFeignClient.getTrackInfo(trackIdList.get(0)).getData();
|
|
|
- //2.2.2 批量保存声音购买记录
|
|
|
- List<UserPaidTrack> userPaidTrackList = trackIdList
|
|
|
- .stream()
|
|
|
- .map(trackId -> {
|
|
|
- UserPaidTrack userPaidTrack = new UserPaidTrack();
|
|
|
- userPaidTrack.setOrderNo(userPaidRecordVo.getOrderNo());
|
|
|
- userPaidTrack.setUserId(userPaidRecordVo.getUserId());
|
|
|
- userPaidTrack.setAlbumId(trackInfo.getAlbumId());
|
|
|
- userPaidTrack.setTrackId(trackId);
|
|
|
- return userPaidTrack;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- userPaidTrackService.saveBatch(userPaidTrackList);
|
|
|
- }
|
|
|
- } else if (SystemConstant.ORDER_ITEM_TYPE_ALBUM.equals(itemType)) {
|
|
|
- //3.处理付款项目类型为:专辑 新增专辑购买记录
|
|
|
- //3.1 判断订单编号是否已处理
|
|
|
- Long count = userPaidAlbumMapper.selectCount(
|
|
|
- new LambdaQueryWrapper<UserPaidAlbum>().eq(UserPaidAlbum::getOrderNo, userPaidRecordVo.getOrderNo())
|
|
|
- );
|
|
|
- if (count > 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
- //3.2 创建专辑购买记录对象 新增
|
|
|
- UserPaidAlbum userPaidAlbum = new UserPaidAlbum();
|
|
|
- userPaidAlbum.setOrderNo(userPaidRecordVo.getOrderNo());
|
|
|
- userPaidAlbum.setUserId(userPaidRecordVo.getUserId());
|
|
|
- userPaidAlbum.setAlbumId(userPaidRecordVo.getItemIdList().get(0));
|
|
|
- userPaidAlbumMapper.insert(userPaidAlbum);
|
|
|
- } else if (SystemConstant.ORDER_ITEM_TYPE_VIP.equals(itemType)) {
|
|
|
- //4.处理付款项目类型为:VIP套餐 新增套餐购买记录 更新 会员标识及过期时间
|
|
|
- //4.1 判断订单编号是否已处理
|
|
|
- Long count = userVipServiceMapper.selectCount(
|
|
|
- new LambdaQueryWrapper<UserVipService>()
|
|
|
- .eq(UserVipService::getOrderNo, userPaidRecordVo.getOrderNo())
|
|
|
- );
|
|
|
- if (count > 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
- //4.2 根据用户ID查询用户信息 判断是否为VIP
|
|
|
- UserInfoVo userInfoVo = this.getUserInfo(userPaidRecordVo.getUserId());
|
|
|
- Boolean isVIP = false;
|
|
|
- if (userInfoVo.getIsVip().intValue() == 1 && userInfoVo.getVipExpireTime().after(new Date())) {
|
|
|
- isVIP = true;
|
|
|
- }
|
|
|
-
|
|
|
- //4.3 根据套餐ID查询套餐信息 得到套餐服务月数
|
|
|
- VipServiceConfig vipServiceConfig = vipServiceConfigMapper.selectById(userPaidRecordVo.getItemIdList().get(0));
|
|
|
- Integer serviceMonth = vipServiceConfig.getServiceMonth();
|
|
|
-
|
|
|
- //4.4 封装会员购买套餐记录并且保存 计算会员生效时间跟过期时间
|
|
|
- UserVipService userVipService = new UserVipService();
|
|
|
- //4.4.1 如果是新开会员,本次会员购买记录生效时间=当前系统时间,过期时间=当前系统时间+套餐服务月数
|
|
|
- if (!isVIP) {
|
|
|
- userVipService.setStartTime(new Date());
|
|
|
- DateTime expireTime = DateUtil.offsetMonth(new Date(), serviceMonth);
|
|
|
- userVipService.setExpireTime(expireTime);
|
|
|
- } else {
|
|
|
- //4.4.2 如果是续费会员,本次会员购买记录生效时间=现有会员过期时间+1天 过期时间:现有会员过期时间+1天+服务月数
|
|
|
- userVipService.setStartTime(DateUtil.offsetDay(userInfoVo.getVipExpireTime(), 1));
|
|
|
- userVipService.setExpireTime(DateUtil.offsetMonth(userVipService.getStartTime(), serviceMonth));
|
|
|
- }
|
|
|
- //4.4.3 设置其他属性
|
|
|
- userVipService.setOrderNo(userPaidRecordVo.getOrderNo());
|
|
|
- userVipService.setUserId(userPaidRecordVo.getUserId());
|
|
|
- userVipServiceMapper.insert(userVipService);
|
|
|
|
|
|
- //4.5 更新用户表中会员标识以及过期时间
|
|
|
- userInfoVo.setIsVip(1);
|
|
|
- userInfoVo.setVipExpireTime(userVipService.getExpireTime());
|
|
|
- UserInfo userInfo = BeanUtil.copyProperties(userInfoVo, UserInfo.class);
|
|
|
- baseMapper.updateById(userInfo);
|
|
|
- }
|
|
|
+ //2.从策略工厂中获取付款项目类型对应的策略实现类对象
|
|
|
+ PaidRecordStrategy strategy = strategyFactory.getStrategy(itemType);
|
|
|
+ strategy.handlerPaidRecord(userPaidRecordVo);
|
|
|
}
|
|
|
|
|
|
}
|