|
|
@@ -8,8 +8,13 @@ import com.fs.common.constant.LiveKeysConstant;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
+import com.fs.his.domain.FsUserIntegralLogs;
|
|
|
+import com.fs.his.enums.FsUserIntegralLogTypeEnum;
|
|
|
+import com.fs.his.mapper.FsUserIntegralLogsMapper;
|
|
|
import com.fs.his.mapper.FsUserMapper;
|
|
|
import com.fs.his.service.IFsUserService;
|
|
|
+import com.fs.hisStore.mapper.FsUserIntegralLogsScrmMapper;
|
|
|
+import com.fs.hisStore.mapper.FsUserScrmMapper;
|
|
|
import com.fs.live.domain.*;
|
|
|
import com.fs.live.mapper.LiveMapper;
|
|
|
import com.fs.live.mapper.LiveRedConfMapper;
|
|
|
@@ -57,6 +62,11 @@ public class LiveRedConfServiceImpl implements ILiveRedConfService {
|
|
|
private LiveRewardRecordMapper liveRewardRecordMapper;
|
|
|
@Autowired
|
|
|
private ILiveAutoTaskService liveAutoTaskService;
|
|
|
+ @Autowired
|
|
|
+ private FsUserScrmMapper fsUserScrmMapper;
|
|
|
+ @Autowired
|
|
|
+ private FsUserIntegralLogsMapper fsUserIntegralLogsMapper;
|
|
|
+
|
|
|
|
|
|
private static final String REDPACKET_REMAININGLOTS_KEY = "live:red:remainingLots:";
|
|
|
private static final String REDPACKET_REMAININGNUM_KEY = "live:red:remainingNum:";
|
|
|
@@ -223,7 +233,7 @@ public class LiveRedConfServiceImpl implements ILiveRedConfService {
|
|
|
@Transactional
|
|
|
public R claimRedPacket(RedPO red) {
|
|
|
// String claimKey = REDPACKET_CLAIM_KEY + red.getRedId();
|
|
|
- Object o = redisCache.hashGet(String.format(LiveKeysConstant.LIVE_HOME_PAGE_CONFIG_RED, red.getLiveId(), red.getRedId()), String.valueOf(red.getUserId()));
|
|
|
+ Object o = redisCache.hashGet(String.format(LiveKeysConstant. LIVE_HOME_PAGE_CONFIG_RED, red.getLiveId(), red.getRedId()), String.valueOf(red.getUserId()));
|
|
|
if (ObjectUtil.isNotEmpty(o)) {
|
|
|
return R.error("您已经领取过红包了!");
|
|
|
}
|
|
|
@@ -270,6 +280,31 @@ public class LiveRedConfServiceImpl implements ILiveRedConfService {
|
|
|
record.setUserId(red.getUserId());
|
|
|
record.setIntegral(integral);
|
|
|
record.setCreateTime(new Date());
|
|
|
+ // 更新用户余额
|
|
|
+ BigDecimal balanceAmount = BigDecimal.valueOf(integral);
|
|
|
+ int updateResult = fsUserScrmMapper.incrIntegral(red.getUserId(), balanceAmount);
|
|
|
+ if (updateResult <= 0) {
|
|
|
+ log.error("更新用户余额失败,userId: {}, balance: {}", red.getUserId(), balanceAmount);
|
|
|
+ return R.error("更新用户余额失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询用户当前余额
|
|
|
+ com.fs.hisStore.domain.FsUserScrm user = fsUserScrmMapper.selectFsUserById(red.getUserId());
|
|
|
+ Long currentIntegral = user.getIntegral() != null ? user.getIntegral() : 0L;
|
|
|
+ Long newIntegral = currentIntegral + integral;
|
|
|
+
|
|
|
+ // 添加余额变动记录
|
|
|
+ FsUserIntegralLogs integralLogs = new FsUserIntegralLogs();
|
|
|
+ integralLogs.setUserId(red.getUserId());
|
|
|
+ integralLogs.setIntegral(integral);
|
|
|
+ integralLogs.setBalance(newIntegral);
|
|
|
+ integralLogs.setLogType(FsUserIntegralLogTypeEnum.TYPE_26.getValue()); // 3表示分享获得积分,可根据实际情况调整
|
|
|
+ integralLogs.setBusinessId(String.valueOf(red.getRedId()));
|
|
|
+ integralLogs.setBusinessType(Math.toIntExact(conf.getRedId())); // 1表示直播红包
|
|
|
+ integralLogs.setStatus(0);
|
|
|
+ integralLogs.setCreateTime(new Date());
|
|
|
+ fsUserIntegralLogsMapper.insertFsUserIntegralLogs(integralLogs);
|
|
|
+
|
|
|
// WebSocket 通知
|
|
|
//String msg = String.format("用户 %d 抢到了红包 %d,获得 %d 芳华币", userId, redId, integral);
|
|
|
//WebSocketServer.notifyUsers(msg);
|