123
This commit is contained in:
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.ruoyi.cai.domain.Account;
|
||||
import com.ruoyi.cai.domain.ConsumeLog;
|
||||
import com.ruoyi.cai.domain.User;
|
||||
import com.ruoyi.cai.dto.admin.vo.AccountAdminVo;
|
||||
import com.ruoyi.cai.enums.AccountBusinessEnum;
|
||||
import com.ruoyi.cai.enums.AccountChangeEnum;
|
||||
@@ -22,6 +23,8 @@ public interface AccountService extends IService<Account> {
|
||||
|
||||
ConsumeLog decr(ConsumeLog log, AccountBusinessEnum businessEnum);
|
||||
|
||||
Long imDesc(User fromUser, User toUser, Long price);
|
||||
|
||||
void withdraw(Long userId, Long incomeCoin, Long traceId);
|
||||
|
||||
void recharge(ConsumeLog consumeLog);
|
||||
|
||||
@@ -14,6 +14,8 @@ import com.ruoyi.common.core.domain.PageQuery;
|
||||
*/
|
||||
public interface UserBlacklistService extends IService<UserBlacklist> {
|
||||
|
||||
boolean existsBlack(Long userId, Long blackUserId);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param actionType 1-拉黑 2-取消拉黑
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.ruoyi.cai.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.ruoyi.cai.domain.UserChatFilter;
|
||||
|
||||
/**
|
||||
* 聊天过滤Service接口
|
||||
*
|
||||
* @author 77
|
||||
* @date 2024-01-09
|
||||
*/
|
||||
public interface UserChatFilterService extends IService<UserChatFilter> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.ruoyi.cai.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.ruoyi.cai.domain.User;
|
||||
import com.ruoyi.cai.domain.UserChatRecord;
|
||||
import com.ruoyi.cai.dto.app.dto.ImMessageDTO;
|
||||
|
||||
/**
|
||||
* 聊天记录Service接口
|
||||
*
|
||||
* @author 77
|
||||
* @date 2024-01-09
|
||||
*/
|
||||
public interface UserChatRecordService extends IService<UserChatRecord> {
|
||||
|
||||
void saveRecord(User fromUser, User toUser,Long traceId, ImMessageDTO message);
|
||||
}
|
||||
@@ -18,5 +18,7 @@ public interface UserMemberService extends IService<UserMember> {
|
||||
|
||||
UserMember getByUserId(Long userId);
|
||||
|
||||
UserMember getNormalMember(Long userId);
|
||||
|
||||
void relieveMember(Long id);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ import com.ruoyi.cai.domain.*;
|
||||
import com.ruoyi.cai.dto.admin.vo.AccountAdminVo;
|
||||
import com.ruoyi.cai.enums.AccountBusinessEnum;
|
||||
import com.ruoyi.cai.enums.AccountChangeEnum;
|
||||
import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||
import com.ruoyi.cai.manager.IdManager;
|
||||
import com.ruoyi.cai.manager.SystemConfigManager;
|
||||
import com.ruoyi.cai.mapper.AccountMapper;
|
||||
import com.ruoyi.cai.pay.RechargeTypeEnum;
|
||||
import com.ruoyi.cai.service.*;
|
||||
@@ -20,6 +23,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 用户账户Service业务层处理
|
||||
*
|
||||
@@ -36,6 +42,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private AccountChangeLogService accountChangeLogService;
|
||||
@Autowired
|
||||
private SystemConfigManager systemConfigManager;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -99,6 +107,54 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
return consumeLog;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long imDesc(User fromUser, User toUser, Long price) {
|
||||
Long fromUserId = fromUser.getId();
|
||||
Account account = this.getByUserId(fromUserId);
|
||||
long totalCoin = account.getIncomeCoin() + account.getCoin();
|
||||
if(totalCoin < price){
|
||||
throw new ServiceException("余额不足");
|
||||
}
|
||||
boolean flag = false;
|
||||
long coin = -price; // 消费余额
|
||||
long incomeCoin = 0; // 消费收益
|
||||
long diff = account.getCoin() - price;
|
||||
// 充值币够用
|
||||
if(diff > 0){
|
||||
flag = baseMapper.decrCoin(fromUserId, -coin);
|
||||
} else { // 充值币不够用
|
||||
coin = -account.getCoin();
|
||||
incomeCoin = diff;
|
||||
boolean decrCoin = baseMapper.decrCoin(fromUserId, -coin);
|
||||
boolean decrIncomeCoin = baseMapper.decrIncomeCoin(fromUserId, -diff);
|
||||
if(decrCoin && decrIncomeCoin){
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
// 扣费不成功
|
||||
if(!flag){
|
||||
throw new ServiceException("扣费失败,请重新购买");
|
||||
}
|
||||
// 开始处理 接收方的费用
|
||||
BigDecimal imRate = systemConfigManager.getSystemConfigOfBigDecimal(SystemConfigEnum.DAY_MAX_DYNAMIC);
|
||||
Long anchorAmount = NumCaUtil.coin(price,imRate);
|
||||
baseMapper.incsIncomeCoin(toUser.getId(),anchorAmount);
|
||||
Long tractId = IdManager.nextId();
|
||||
// 记录消费方的流水
|
||||
if(coin != 0){
|
||||
accountChangeLogService.saveLogNoAdmin(fromUserId,fromUser.getUsercode(), RechargeTypeEnum.COIN, AccountChangeEnum.USER_IM, coin, tractId);
|
||||
}
|
||||
if(incomeCoin != 0){
|
||||
accountChangeLogService.saveLogNoAdmin(fromUserId,fromUser.getUsercode(), RechargeTypeEnum.COIN_INCOME,AccountChangeEnum.USER_IM,incomeCoin,tractId);
|
||||
}
|
||||
// 记录接收方的流水
|
||||
if(anchorAmount != 0){
|
||||
accountChangeLogService.saveLogNoAdmin(toUser.getId(),toUser.getUsercode(), RechargeTypeEnum.COIN_INCOME,AccountChangeEnum.ANCHOR_IM,anchorAmount,tractId);
|
||||
}
|
||||
return tractId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void withdraw(Long userId, Long incomeCoin,Long traceId){
|
||||
|
||||
@@ -18,6 +18,14 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@Service
|
||||
public class UserBlacklistServiceImpl extends ServiceImpl<UserBlacklistMapper, UserBlacklist> implements UserBlacklistService {
|
||||
|
||||
@Override
|
||||
public boolean existsBlack(Long userId,Long blackUserId){
|
||||
return this.exists(Wrappers.lambdaQuery(UserBlacklist.class)
|
||||
.eq(UserBlacklist::getUserId,userId)
|
||||
.eq(UserBlacklist::getBlackUid,blackUserId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean black(Long userId, Long blackUserId,Integer actionType) {
|
||||
if(userId.equals(blackUserId)){
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.ruoyi.cai.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.cai.domain.UserChatFilter;
|
||||
import com.ruoyi.cai.mapper.UserChatFilterMapper;
|
||||
import com.ruoyi.cai.service.UserChatFilterService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 聊天过滤Service业务层处理
|
||||
*
|
||||
* @author 77
|
||||
* @date 2024-01-09
|
||||
*/
|
||||
@Service
|
||||
public class UserChatFilterServiceImpl extends ServiceImpl<UserChatFilterMapper,UserChatFilter> implements UserChatFilterService {
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.ruoyi.cai.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.cai.domain.User;
|
||||
import com.ruoyi.cai.domain.UserChatRecord;
|
||||
import com.ruoyi.cai.dto.app.dto.ImMessageDTO;
|
||||
import com.ruoyi.cai.mapper.UserChatRecordMapper;
|
||||
import com.ruoyi.cai.service.UserChatRecordService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 聊天记录Service业务层处理
|
||||
*
|
||||
* @author 77
|
||||
* @date 2024-01-09
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class UserChatRecordServiceImpl extends ServiceImpl<UserChatRecordMapper,UserChatRecord> implements UserChatRecordService {
|
||||
|
||||
@Override
|
||||
public void saveRecord(User fromUser, User toUser,Long traceId, ImMessageDTO message) {
|
||||
UserChatRecord userChatRecord = new UserChatRecord();
|
||||
userChatRecord.setFromUid(fromUser.getId());
|
||||
userChatRecord.setToUid(toUser.getId());
|
||||
userChatRecord.setContent(message.getMessage());
|
||||
userChatRecord.setType(message.getType());
|
||||
userChatRecord.setCreateTime(LocalDateTime.now());
|
||||
userChatRecord.setTraceId(traceId);
|
||||
this.save(userChatRecord);
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,13 @@ public class UserMemberServiceImpl extends ServiceImpl<UserMemberMapper, UserMem
|
||||
return this.getOne(Wrappers.lambdaQuery(UserMember.class).eq(UserMember::getUserId,userId).last("limit 1"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserMember getNormalMember(Long userId){
|
||||
return this.getOne(Wrappers.lambdaQuery(UserMember.class).eq(UserMember::getUserId,userId)
|
||||
.eq(UserMember::getMemberStatus, MemberStatusEnum.NORMAL.getCode())
|
||||
.last("limit 1"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void relieveMember(Long id) {
|
||||
this.update(Wrappers.lambdaUpdate(UserMember.class)
|
||||
|
||||
Reference in New Issue
Block a user