|
@@ -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) {
|
|
|
|
|
|
String itemType = userPaidRecordVo.getItemType();
|
|
|
-
|
|
|
- if (SystemConstant.ORDER_ITEM_TYPE_TRACK.equals(itemType)) {
|
|
|
-
|
|
|
- Long count = userPaidTrackMapper.selectCount(
|
|
|
- new LambdaQueryWrapper<UserPaidTrack>()
|
|
|
- .eq(UserPaidTrack::getOrderNo, userPaidRecordVo.getOrderNo())
|
|
|
- );
|
|
|
- if (count > 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- List<Long> trackIdList = userPaidRecordVo.getItemIdList();
|
|
|
- if (CollUtil.isNotEmpty(trackIdList)) {
|
|
|
-
|
|
|
- TrackInfo trackInfo = albumFeignClient.getTrackInfo(trackIdList.get(0)).getData();
|
|
|
-
|
|
|
- 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)) {
|
|
|
-
|
|
|
-
|
|
|
- Long count = userPaidAlbumMapper.selectCount(
|
|
|
- new LambdaQueryWrapper<UserPaidAlbum>().eq(UserPaidAlbum::getOrderNo, userPaidRecordVo.getOrderNo())
|
|
|
- );
|
|
|
- if (count > 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- 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)) {
|
|
|
-
|
|
|
-
|
|
|
- Long count = userVipServiceMapper.selectCount(
|
|
|
- new LambdaQueryWrapper<UserVipService>()
|
|
|
- .eq(UserVipService::getOrderNo, userPaidRecordVo.getOrderNo())
|
|
|
- );
|
|
|
- if (count > 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- UserInfoVo userInfoVo = this.getUserInfo(userPaidRecordVo.getUserId());
|
|
|
- Boolean isVIP = false;
|
|
|
- if (userInfoVo.getIsVip().intValue() == 1 && userInfoVo.getVipExpireTime().after(new Date())) {
|
|
|
- isVIP = true;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- VipServiceConfig vipServiceConfig = vipServiceConfigMapper.selectById(userPaidRecordVo.getItemIdList().get(0));
|
|
|
- Integer serviceMonth = vipServiceConfig.getServiceMonth();
|
|
|
-
|
|
|
-
|
|
|
- UserVipService userVipService = new UserVipService();
|
|
|
-
|
|
|
- if (!isVIP) {
|
|
|
- userVipService.setStartTime(new Date());
|
|
|
- DateTime expireTime = DateUtil.offsetMonth(new Date(), serviceMonth);
|
|
|
- userVipService.setExpireTime(expireTime);
|
|
|
- } else {
|
|
|
-
|
|
|
- userVipService.setStartTime(DateUtil.offsetDay(userInfoVo.getVipExpireTime(), 1));
|
|
|
- userVipService.setExpireTime(DateUtil.offsetMonth(userVipService.getStartTime(), serviceMonth));
|
|
|
- }
|
|
|
-
|
|
|
- userVipService.setOrderNo(userPaidRecordVo.getOrderNo());
|
|
|
- userVipService.setUserId(userPaidRecordVo.getUserId());
|
|
|
- userVipServiceMapper.insert(userVipService);
|
|
|
|
|
|
-
|
|
|
- userInfoVo.setIsVip(1);
|
|
|
- userInfoVo.setVipExpireTime(userVipService.getExpireTime());
|
|
|
- UserInfo userInfo = BeanUtil.copyProperties(userInfoVo, UserInfo.class);
|
|
|
- baseMapper.updateById(userInfo);
|
|
|
- }
|
|
|
+
|
|
|
+ PaidRecordStrategy strategy = strategyFactory.getStrategy(itemType);
|
|
|
+ strategy.handlerPaidRecord(userPaidRecordVo);
|
|
|
}
|
|
|
|
|
|
}
|