123
This commit is contained in:
@@ -0,0 +1,95 @@
|
|||||||
|
package com.ruoyi.cai.controller;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.ruoyi.cai.domain.UserChatFilter;
|
||||||
|
import com.ruoyi.cai.service.UserChatFilterService;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.annotation.RepeatSubmit;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.core.validate.AddGroup;
|
||||||
|
import com.ruoyi.common.core.validate.EditGroup;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天过滤
|
||||||
|
*
|
||||||
|
* @author 77
|
||||||
|
* @date 2024-01-09
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/cai/userChatFilter")
|
||||||
|
public class UserChatFilterController extends BaseController {
|
||||||
|
|
||||||
|
private final UserChatFilterService userChatFilterService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询聊天过滤列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("cai:userChatFilter:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo<UserChatFilter> list(UserChatFilter bo, PageQuery pageQuery) {
|
||||||
|
Page<UserChatFilter> page = userChatFilterService.page(pageQuery.build(), Wrappers.lambdaQuery(bo));
|
||||||
|
return TableDataInfo.build(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取聊天过滤详细信息
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("cai:userChatFilter:query")
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public R<UserChatFilter> getInfo(@NotNull(message = "主键不能为空")
|
||||||
|
@PathVariable Long id) {
|
||||||
|
return R.ok(userChatFilterService.getById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增聊天过滤
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("cai:userChatFilter:add")
|
||||||
|
@Log(title = "聊天过滤", businessType = BusinessType.INSERT)
|
||||||
|
@RepeatSubmit()
|
||||||
|
@PostMapping()
|
||||||
|
public R<Void> add(@Validated(AddGroup.class) @RequestBody UserChatFilter bo) {
|
||||||
|
return toAjax(userChatFilterService.save(bo));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改聊天过滤
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("cai:userChatFilter:edit")
|
||||||
|
@Log(title = "聊天过滤", businessType = BusinessType.UPDATE)
|
||||||
|
@RepeatSubmit()
|
||||||
|
@PutMapping()
|
||||||
|
public R<Void> edit(@Validated(EditGroup.class) @RequestBody UserChatFilter bo) {
|
||||||
|
return toAjax(userChatFilterService.updateById(bo));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除聊天过滤
|
||||||
|
*
|
||||||
|
* @param ids 主键串
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("cai:userChatFilter:remove")
|
||||||
|
@Log(title = "聊天过滤", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{ids}")
|
||||||
|
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||||
|
@PathVariable Long[] ids) {
|
||||||
|
return toAjax(userChatFilterService.removeBatchByIds(Arrays.asList(ids)));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package com.ruoyi.cai.controller;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.ruoyi.cai.domain.UserChatRecord;
|
||||||
|
import com.ruoyi.cai.service.UserChatRecordService;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.annotation.RepeatSubmit;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
import com.ruoyi.common.core.validate.AddGroup;
|
||||||
|
import com.ruoyi.common.core.validate.EditGroup;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天记录
|
||||||
|
*
|
||||||
|
* @author 77
|
||||||
|
* @date 2024-01-09
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/cai/userChatRecord")
|
||||||
|
public class UserChatRecordController extends BaseController {
|
||||||
|
|
||||||
|
private final UserChatRecordService userChatRecordService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询聊天记录列表
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("cai:userChatRecord:list")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo<UserChatRecord> list(UserChatRecord bo, PageQuery pageQuery) {
|
||||||
|
Page<UserChatRecord> page = userChatRecordService.page(pageQuery.build(), Wrappers.lambdaQuery(bo));
|
||||||
|
return TableDataInfo.build(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取聊天记录详细信息
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("cai:userChatRecord:query")
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public R<UserChatRecord> getInfo(@NotNull(message = "主键不能为空")
|
||||||
|
@PathVariable Long id) {
|
||||||
|
return R.ok(userChatRecordService.getById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增聊天记录
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("cai:userChatRecord:add")
|
||||||
|
@Log(title = "聊天记录", businessType = BusinessType.INSERT)
|
||||||
|
@RepeatSubmit()
|
||||||
|
@PostMapping()
|
||||||
|
public R<Void> add(@Validated(AddGroup.class) @RequestBody UserChatRecord bo) {
|
||||||
|
return toAjax(userChatRecordService.save(bo));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改聊天记录
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("cai:userChatRecord:edit")
|
||||||
|
@Log(title = "聊天记录", businessType = BusinessType.UPDATE)
|
||||||
|
@RepeatSubmit()
|
||||||
|
@PutMapping()
|
||||||
|
public R<Void> edit(@Validated(EditGroup.class) @RequestBody UserChatRecord bo) {
|
||||||
|
return toAjax(userChatRecordService.updateById(bo));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除聊天记录
|
||||||
|
*
|
||||||
|
* @param ids 主键串
|
||||||
|
*/
|
||||||
|
@SaCheckPermission("cai:userChatRecord:remove")
|
||||||
|
@Log(title = "聊天记录", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{ids}")
|
||||||
|
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||||
|
@PathVariable Long[] ids) {
|
||||||
|
return toAjax(userChatRecordService.removeBatchByIds(Arrays.asList(ids)));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.ruoyi.cai.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天过滤对象 cai_user_chat_filter
|
||||||
|
*
|
||||||
|
* @author 77
|
||||||
|
* @date 2024-01-09
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("cai_user_chat_filter")
|
||||||
|
public class UserChatFilter implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID=1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@TableId(value = "id")
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Long fromUid;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Long toUid;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package com.ruoyi.cai.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天记录对象 cai_user_chat_record
|
||||||
|
*
|
||||||
|
* @author 77
|
||||||
|
* @date 2024-01-09
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("cai_user_chat_record")
|
||||||
|
public class UserChatRecord implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID=1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@TableId(value = "id")
|
||||||
|
private Long id;
|
||||||
|
private Long traceId;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Long fromUid;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Long toUid;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private String content;
|
||||||
|
/**
|
||||||
|
* 消息类型:0=文本消息,1=图片消息,2=语音消息,3=视频消息,4=发送地理位置消息,6=发送文件消息,10=发送提示消息,100=发送第三方自定义消息
|
||||||
|
*/
|
||||||
|
private Integer type;
|
||||||
|
/**
|
||||||
|
* 图片下载状态:0=未更新,1=已更新,2=已下载,3=下载失败
|
||||||
|
*/
|
||||||
|
private Integer imgStatus;
|
||||||
|
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -12,13 +12,14 @@ public enum AccountChangeEnum {
|
|||||||
USER_GIFT(104,"送出礼物","送出礼物","GIFT",""),
|
USER_GIFT(104,"送出礼物","送出礼物","GIFT",""),
|
||||||
USER_GUARD(105,"送出守护","送出守护","GUARD",""),
|
USER_GUARD(105,"送出守护","送出守护","GUARD",""),
|
||||||
USER_VIDEO(106,"视频支出","视频支出","VIDEO",""),
|
USER_VIDEO(106,"视频支出","视频支出","VIDEO",""),
|
||||||
A7(107,"聊天支出","聊天支出","",""),
|
USER_IM(107,"聊天支出","聊天支出","IM",""),
|
||||||
WITHDRAW(108,"提现","提现","","WITHDRAW"),
|
WITHDRAW(108,"提现","提现","","WITHDRAW"),
|
||||||
|
|
||||||
// 主播端
|
// 主播端
|
||||||
ANCHOR_GIFT(201,"收到礼物","收到礼物","GIFT",""),
|
ANCHOR_GIFT(201,"收到礼物","收到礼物","GIFT",""),
|
||||||
ANCHOR_GUARD(202,"收到守护","收到守护","GUARD",""),
|
ANCHOR_GUARD(202,"收到守护","收到守护","GUARD",""),
|
||||||
ANCHOR_VIDEO(203,"视频收入","视频收入","VIDEO",""),
|
ANCHOR_VIDEO(203,"视频收入","视频收入","VIDEO",""),
|
||||||
|
ANCHOR_IM(204,"聊天收入","视频收入","IM",""),
|
||||||
|
|
||||||
// 分销
|
// 分销
|
||||||
ONE_RECHARGE(301,"充值分成","邀请奖励","RECHARGE",""),
|
ONE_RECHARGE(301,"充值分成","邀请奖励","RECHARGE",""),
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.ruoyi.cai.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum UserMemberTypeEnum {
|
||||||
|
NORMAL_VIP(0,"普通会员"),
|
||||||
|
SUPER_VIP(1,"超级会员"),
|
||||||
|
;
|
||||||
|
private final Integer code;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
UserMemberTypeEnum(Integer code, String name) {
|
||||||
|
this.code = code;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,21 +2,21 @@ package com.ruoyi.cai.manager;
|
|||||||
|
|
||||||
import com.ruoyi.cai.domain.Account;
|
import com.ruoyi.cai.domain.Account;
|
||||||
import com.ruoyi.cai.domain.User;
|
import com.ruoyi.cai.domain.User;
|
||||||
import com.ruoyi.cai.domain.UserVisitor;
|
import com.ruoyi.cai.domain.UserChatRecord;
|
||||||
|
import com.ruoyi.cai.domain.UserMember;
|
||||||
import com.ruoyi.cai.dto.app.dto.ImMessageDTO;
|
import com.ruoyi.cai.dto.app.dto.ImMessageDTO;
|
||||||
import com.ruoyi.cai.dto.app.vo.ImResp;
|
import com.ruoyi.cai.dto.app.vo.ImResp;
|
||||||
import com.ruoyi.cai.dto.app.vo.user.UserStarOrVisitorList;
|
import com.ruoyi.cai.enums.GenderEnum;
|
||||||
import com.ruoyi.cai.enums.ImTypeEnum;
|
import com.ruoyi.cai.enums.ImTypeEnum;
|
||||||
import com.ruoyi.cai.enums.SystemConfigEnum;
|
import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||||
import com.ruoyi.cai.service.AccountService;
|
import com.ruoyi.cai.enums.UserMemberTypeEnum;
|
||||||
import com.ruoyi.cai.service.UserFollowService;
|
import com.ruoyi.cai.mapper.AccountMapper;
|
||||||
import com.ruoyi.cai.service.UserService;
|
import com.ruoyi.cai.service.*;
|
||||||
import com.ruoyi.cai.service.UserVisitorService;
|
|
||||||
import com.ruoyi.common.exception.ServiceException;
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
|
import org.apache.xmlbeans.impl.xb.xsdschema.UnionDocument;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@@ -30,6 +30,10 @@ public class ImService {
|
|||||||
private AccountService accountService;
|
private AccountService accountService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserFollowService userFollowService;
|
private UserFollowService userFollowService;
|
||||||
|
@Autowired
|
||||||
|
private UserMemberService userMemberService;
|
||||||
|
@Autowired
|
||||||
|
private UserChatRecordService userChatRecordService;
|
||||||
|
|
||||||
public ImResp sendMessage(Long fromUserId, ImMessageDTO message) {
|
public ImResp sendMessage(Long fromUserId, ImMessageDTO message) {
|
||||||
ImTypeEnum typeEnum = ImTypeEnum.getByType(message.getType());
|
ImTypeEnum typeEnum = ImTypeEnum.getByType(message.getType());
|
||||||
@@ -37,9 +41,20 @@ public class ImService {
|
|||||||
throw new ServiceException("参数异常");
|
throw new ServiceException("参数异常");
|
||||||
}
|
}
|
||||||
// 检测用户是否被封号
|
// 检测用户是否被封号
|
||||||
User user = userService.getById(fromUserId);
|
User fromUser = userService.getById(fromUserId);
|
||||||
if(user.getStatus() == 1){
|
if(fromUser == null){
|
||||||
throw new ServiceException("该账户已被封禁,无法发送消息");
|
throw new ServiceException("发送人不存在!");
|
||||||
|
}
|
||||||
|
if(fromUser.getStatus() == 1){
|
||||||
|
throw new ServiceException("发送人账号不可用!");
|
||||||
|
}
|
||||||
|
Long toUserId = message.getToUserId();
|
||||||
|
User toUser = userService.getById(toUserId);
|
||||||
|
if(toUser == null){
|
||||||
|
throw new ServiceException("接收人不存在!");
|
||||||
|
}
|
||||||
|
if(toUser.getStatus() == 1){
|
||||||
|
throw new ServiceException("接收人账号不可用!");
|
||||||
}
|
}
|
||||||
// 自定义消息跳过所有流程
|
// 自定义消息跳过所有流程
|
||||||
if(typeEnum == ImTypeEnum.CUSTOM){
|
if(typeEnum == ImTypeEnum.CUSTOM){
|
||||||
@@ -48,8 +63,14 @@ public class ImService {
|
|||||||
resp.setCoin(account.getCoin()+ account.getIncomeCoin());
|
resp.setCoin(account.getCoin()+ account.getIncomeCoin());
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
Long toUserId = message.getToUserId();
|
|
||||||
Set<Long> systemCustomerService = systemConfigManager.getSystemConfigOfLongSet(SystemConfigEnum.SYSTEM_CUSTOMER_SERVICE);
|
Set<Long> systemCustomerService = systemConfigManager.getSystemConfigOfLongSet(SystemConfigEnum.SYSTEM_CUSTOMER_SERVICE);
|
||||||
|
// 有内部用户参与的 跳过所有校验
|
||||||
|
if(systemCustomerService.contains(fromUserId) || systemCustomerService.contains(toUserId)){
|
||||||
|
Account account = accountService.getByUserId(fromUserId);
|
||||||
|
ImResp resp = new ImResp();
|
||||||
|
resp.setCoin(account.getCoin()+ account.getIncomeCoin());
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
boolean fileType = typeEnum.isFileType();
|
boolean fileType = typeEnum.isFileType();
|
||||||
if(fileType){
|
if(fileType){
|
||||||
if(!systemCustomerService.contains(fromUserId) && !systemCustomerService.contains(toUserId)){
|
if(!systemCustomerService.contains(fromUserId) && !systemCustomerService.contains(toUserId)){
|
||||||
@@ -63,7 +84,69 @@ public class ImService {
|
|||||||
if(typeEnum == ImTypeEnum.MESSAGE && !systemCustomerService.contains(fromUserId) && !systemCustomerService.contains(toUserId)){
|
if(typeEnum == ImTypeEnum.MESSAGE && !systemCustomerService.contains(fromUserId) && !systemCustomerService.contains(toUserId)){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if(fromUserId.equals(toUserId)){
|
||||||
|
throw new ServiceException("不能给自己发送哦!");
|
||||||
|
}
|
||||||
|
// 更新活跃时间
|
||||||
|
// 检查拉黑
|
||||||
|
boolean isBlack = userBlacklistService.existsBlack(fromUserId, toUserId);
|
||||||
|
if(isBlack){
|
||||||
|
throw new ServiceException("您已经将对方拉黑!");
|
||||||
|
}
|
||||||
|
isBlack = userBlacklistService.existsBlack(toUserId, fromUserId);
|
||||||
|
if(isBlack){
|
||||||
|
throw new ServiceException("对方已经将您拉黑!");
|
||||||
|
}
|
||||||
|
if (fromUser.getGender().equals(GenderEnum.WOMEN.getCode()) && toUser.getGender().equals(GenderEnum.WOMEN.getCode())) {
|
||||||
|
throw new ServiceException("女生之间暂不支持私信!");
|
||||||
|
}
|
||||||
|
if (fromUser.getGender().equals(GenderEnum.MAN.getCode()) && toUser.getGender().equals(GenderEnum.MAN.getCode())) {
|
||||||
|
throw new ServiceException("男生之间暂不支持私信!");
|
||||||
|
}
|
||||||
|
if (fromUser.getGender().equals(GenderEnum.MAN.getCode()) && toUser.getIsAnchor().equals(0)) {
|
||||||
|
throw new ServiceException("只能给女神私信!");
|
||||||
|
}
|
||||||
|
if (fromUser.getGender().equals(GenderEnum.WOMEN.getCode()) && toUser.getIsAnchor().equals(0)) {
|
||||||
|
throw new ServiceException("成为女神才能私信!");
|
||||||
|
}
|
||||||
|
if (fromUser.getIsAnchor().equals(1) && toUser.getIsAnchor().equals(1)) {
|
||||||
|
throw new ServiceException("女神之间暂不支持私信!");
|
||||||
|
}
|
||||||
|
if (fromUser.getIsAnchor().equals(0) && toUser.getIsAnchor().equals(0)) {
|
||||||
|
throw new ServiceException("目前只能和女神私信!");
|
||||||
|
}
|
||||||
|
if(){
|
||||||
|
Account account = accountService.getByUserId(fromUserId);
|
||||||
|
ImResp resp = new ImResp();
|
||||||
|
resp.setCoin(account.getCoin()+ account.getIncomeCoin());
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
// 判断VIP获取价格
|
||||||
|
Long imPrice = getByImPrice(fromUserId);
|
||||||
|
Long traceId = null;
|
||||||
|
if(imPrice > 0){
|
||||||
|
// 扣费
|
||||||
|
traceId = accountService.imDesc(fromUser, toUser, imPrice);
|
||||||
|
}
|
||||||
|
// 存储聊天记录
|
||||||
|
userChatRecordService.saveRecord(fromUser,toUser,traceId,message);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserBlacklistService userBlacklistService;
|
||||||
|
|
||||||
|
private Long getByImPrice(Long userId){
|
||||||
|
UserMember userMember = userMemberService.getNormalMember(userId);
|
||||||
|
if(userMember == null){
|
||||||
|
return 10L;
|
||||||
|
}
|
||||||
|
if(userMember.getMemberType().equals(UserMemberTypeEnum.NORMAL_VIP.getCode())){
|
||||||
|
return 5L;
|
||||||
|
}
|
||||||
|
if(userMember.getMemberType().equals(UserMemberTypeEnum.SUPER_VIP.getCode())){
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
return 10L;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.ruoyi.cai.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.ruoyi.cai.domain.UserChatFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天过滤Mapper接口
|
||||||
|
*
|
||||||
|
* @author 77
|
||||||
|
* @date 2024-01-09
|
||||||
|
*/
|
||||||
|
public interface UserChatFilterMapper extends BaseMapper<UserChatFilter> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.ruoyi.cai.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.ruoyi.cai.domain.UserChatRecord;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天记录Mapper接口
|
||||||
|
*
|
||||||
|
* @author 77
|
||||||
|
* @date 2024-01-09
|
||||||
|
*/
|
||||||
|
public interface UserChatRecordMapper extends BaseMapper<UserChatRecord> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.ruoyi.cai.domain.Account;
|
import com.ruoyi.cai.domain.Account;
|
||||||
import com.ruoyi.cai.domain.ConsumeLog;
|
import com.ruoyi.cai.domain.ConsumeLog;
|
||||||
|
import com.ruoyi.cai.domain.User;
|
||||||
import com.ruoyi.cai.dto.admin.vo.AccountAdminVo;
|
import com.ruoyi.cai.dto.admin.vo.AccountAdminVo;
|
||||||
import com.ruoyi.cai.enums.AccountBusinessEnum;
|
import com.ruoyi.cai.enums.AccountBusinessEnum;
|
||||||
import com.ruoyi.cai.enums.AccountChangeEnum;
|
import com.ruoyi.cai.enums.AccountChangeEnum;
|
||||||
@@ -22,6 +23,8 @@ public interface AccountService extends IService<Account> {
|
|||||||
|
|
||||||
ConsumeLog decr(ConsumeLog log, AccountBusinessEnum businessEnum);
|
ConsumeLog decr(ConsumeLog log, AccountBusinessEnum businessEnum);
|
||||||
|
|
||||||
|
Long imDesc(User fromUser, User toUser, Long price);
|
||||||
|
|
||||||
void withdraw(Long userId, Long incomeCoin, Long traceId);
|
void withdraw(Long userId, Long incomeCoin, Long traceId);
|
||||||
|
|
||||||
void recharge(ConsumeLog consumeLog);
|
void recharge(ConsumeLog consumeLog);
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import com.ruoyi.common.core.domain.PageQuery;
|
|||||||
*/
|
*/
|
||||||
public interface UserBlacklistService extends IService<UserBlacklist> {
|
public interface UserBlacklistService extends IService<UserBlacklist> {
|
||||||
|
|
||||||
|
boolean existsBlack(Long userId, Long blackUserId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param actionType 1-拉黑 2-取消拉黑
|
* @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 getByUserId(Long userId);
|
||||||
|
|
||||||
|
UserMember getNormalMember(Long userId);
|
||||||
|
|
||||||
void relieveMember(Long id);
|
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.dto.admin.vo.AccountAdminVo;
|
||||||
import com.ruoyi.cai.enums.AccountBusinessEnum;
|
import com.ruoyi.cai.enums.AccountBusinessEnum;
|
||||||
import com.ruoyi.cai.enums.AccountChangeEnum;
|
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.mapper.AccountMapper;
|
||||||
import com.ruoyi.cai.pay.RechargeTypeEnum;
|
import com.ruoyi.cai.pay.RechargeTypeEnum;
|
||||||
import com.ruoyi.cai.service.*;
|
import com.ruoyi.cai.service.*;
|
||||||
@@ -20,6 +23,9 @@ 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 javax.xml.transform.Source;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户账户Service业务层处理
|
* 用户账户Service业务层处理
|
||||||
*
|
*
|
||||||
@@ -36,6 +42,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
private UserService userService;
|
private UserService userService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private AccountChangeLogService accountChangeLogService;
|
private AccountChangeLogService accountChangeLogService;
|
||||||
|
@Autowired
|
||||||
|
private SystemConfigManager systemConfigManager;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -99,6 +107,54 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
return consumeLog;
|
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
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void withdraw(Long userId, Long incomeCoin,Long traceId){
|
public void withdraw(Long userId, Long incomeCoin,Long traceId){
|
||||||
|
|||||||
@@ -18,6 +18,14 @@ import org.springframework.stereotype.Service;
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class UserBlacklistServiceImpl extends ServiceImpl<UserBlacklistMapper, UserBlacklist> implements UserBlacklistService {
|
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
|
@Override
|
||||||
public boolean black(Long userId, Long blackUserId,Integer actionType) {
|
public boolean black(Long userId, Long blackUserId,Integer actionType) {
|
||||||
if(userId.equals(blackUserId)){
|
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"));
|
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
|
@Override
|
||||||
public void relieveMember(Long id) {
|
public void relieveMember(Long id) {
|
||||||
this.update(Wrappers.lambdaUpdate(UserMember.class)
|
this.update(Wrappers.lambdaUpdate(UserMember.class)
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.ruoyi.cai.mapper.UserChatFilterMapper">
|
||||||
|
|
||||||
|
<resultMap type="com.ruoyi.cai.domain.UserChatFilter" id="UserChatFilterResult">
|
||||||
|
<result property="id" column="id"/>
|
||||||
|
<result property="fromUid" column="from_uid"/>
|
||||||
|
<result property="toUid" column="to_uid"/>
|
||||||
|
<result property="content" column="content"/>
|
||||||
|
<result property="createTime" column="create_time"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.ruoyi.cai.mapper.UserChatRecordMapper">
|
||||||
|
|
||||||
|
<resultMap type="com.ruoyi.cai.domain.UserChatRecord" id="UserChatRecordResult">
|
||||||
|
<result property="id" column="id"/>
|
||||||
|
<result property="fromUid" column="from_uid"/>
|
||||||
|
<result property="toUid" column="to_uid"/>
|
||||||
|
<result property="content" column="content"/>
|
||||||
|
<result property="type" column="type"/>
|
||||||
|
<result property="imgStatus" column="img_status"/>
|
||||||
|
<result property="createTime" column="create_time"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user