init
This commit is contained in:
@@ -32,14 +32,6 @@ public class CaiAccount implements Serializable {
|
|||||||
* 用户ID
|
* 用户ID
|
||||||
*/
|
*/
|
||||||
private Long userId;
|
private Long userId;
|
||||||
/**
|
|
||||||
* 充值的可用余额
|
|
||||||
*/
|
|
||||||
private BigDecimal money;
|
|
||||||
/**
|
|
||||||
* 收益的金额
|
|
||||||
*/
|
|
||||||
private BigDecimal incomeMoney;
|
|
||||||
/**
|
/**
|
||||||
* 当前彩币数量
|
* 当前彩币数量
|
||||||
*/
|
*/
|
||||||
@@ -48,11 +40,6 @@ public class CaiAccount implements Serializable {
|
|||||||
* 收益的彩币数量
|
* 收益的彩币数量
|
||||||
*/
|
*/
|
||||||
private Long incomeCoin;
|
private Long incomeCoin;
|
||||||
private Long totalCoin;
|
|
||||||
/**
|
|
||||||
* 当前魅力值
|
|
||||||
*/
|
|
||||||
private Long loveValue;
|
|
||||||
/**
|
/**
|
||||||
* 充值总额
|
* 充值总额
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -71,6 +71,10 @@ public class CaiAnchor implements Serializable{
|
|||||||
* 视频分成比例
|
* 视频分成比例
|
||||||
*/
|
*/
|
||||||
private BigDecimal videoRate;
|
private BigDecimal videoRate;
|
||||||
|
/**
|
||||||
|
* 守护分成比例
|
||||||
|
*/
|
||||||
|
private BigDecimal guardRate;
|
||||||
/**
|
/**
|
||||||
* 礼物分成比列
|
* 礼物分成比列
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,17 +1,12 @@
|
|||||||
package com.ruoyi.cai.domain;
|
package com.ruoyi.cai.domain;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.time.LocalDateTime;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import com.ruoyi.common.core.domain.BaseEntity;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消费记录对象 cai_consume_log
|
* 消费记录对象 cai_consume_log
|
||||||
@@ -41,27 +36,27 @@ public class CaiConsumeLog implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 发生金额
|
* 发生金额
|
||||||
*/
|
*/
|
||||||
private BigDecimal amount;
|
private Long amount;
|
||||||
/**
|
/**
|
||||||
* 主播金额
|
* 主播金额
|
||||||
*/
|
*/
|
||||||
private BigDecimal anchorAmount;
|
private Long anchorAmount;
|
||||||
/**
|
/**
|
||||||
* 一级金额
|
* 一级金额
|
||||||
*/
|
*/
|
||||||
private BigDecimal oneAmount;
|
private Long oneAmount;
|
||||||
/**
|
/**
|
||||||
* 二级金额
|
* 二级金额
|
||||||
*/
|
*/
|
||||||
private BigDecimal twoAmount;
|
private Long twoAmount;
|
||||||
/**
|
/**
|
||||||
* 平台金额
|
* 平台金额
|
||||||
*/
|
*/
|
||||||
private BigDecimal platformAmount;
|
private Long platformAmount;
|
||||||
/**
|
/**
|
||||||
* 消费方用户
|
* 消费方用户
|
||||||
*/
|
*/
|
||||||
private Integer sourceUserId;
|
private Long sourceUserId;
|
||||||
/**
|
/**
|
||||||
* 消费方用户
|
* 消费方用户
|
||||||
*/
|
*/
|
||||||
@@ -73,7 +68,7 @@ public class CaiConsumeLog implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 接收方用户
|
* 接收方用户
|
||||||
*/
|
*/
|
||||||
private Integer targetUserId;
|
private Long targetUserId;
|
||||||
/**
|
/**
|
||||||
* 接收方用户
|
* 接收方用户
|
||||||
*/
|
*/
|
||||||
@@ -82,11 +77,14 @@ public class CaiConsumeLog implements Serializable {
|
|||||||
* 接收方用户
|
* 接收方用户
|
||||||
*/
|
*/
|
||||||
private String targetPhone;
|
private String targetPhone;
|
||||||
|
/**
|
||||||
|
* 接收方的费率
|
||||||
|
*/
|
||||||
private BigDecimal targetRate;
|
private BigDecimal targetRate;
|
||||||
/**
|
/**
|
||||||
* 一级分销方
|
* 一级分销方
|
||||||
*/
|
*/
|
||||||
private Integer oneUserId;
|
private Long oneUserId;
|
||||||
/**
|
/**
|
||||||
* 一级分销方
|
* 一级分销方
|
||||||
*/
|
*/
|
||||||
@@ -99,6 +97,9 @@ public class CaiConsumeLog implements Serializable {
|
|||||||
* 一级分销方抽成比例
|
* 一级分销方抽成比例
|
||||||
*/
|
*/
|
||||||
private BigDecimal oneRate;
|
private BigDecimal oneRate;
|
||||||
|
/**
|
||||||
|
* 是否有效
|
||||||
|
*/
|
||||||
private Boolean oneJoin;
|
private Boolean oneJoin;
|
||||||
/**
|
/**
|
||||||
* 是否为工会管理员 0=否 1=是
|
* 是否为工会管理员 0=否 1=是
|
||||||
@@ -107,7 +108,7 @@ public class CaiConsumeLog implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 工会提成
|
* 工会提成
|
||||||
*/
|
*/
|
||||||
private Integer unionUserId;
|
private Long unionUserId;
|
||||||
/**
|
/**
|
||||||
* 工会提成
|
* 工会提成
|
||||||
*/
|
*/
|
||||||
@@ -157,4 +158,13 @@ public class CaiConsumeLog implements Serializable {
|
|||||||
|
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
public void init(CaiUser fromUser,CaiUser toUser){
|
||||||
|
this.setSourceUserId(fromUser.getId());
|
||||||
|
this.setSourcePhone(fromUser.getMobile());
|
||||||
|
this.setSourceUsercode(fromUser.getUsercode());
|
||||||
|
this.setTargetUserId(toUser.getId());
|
||||||
|
this.setTargetUsercode(toUser.getUsercode());
|
||||||
|
this.setTargetPhone(toUser.getMobile());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,17 +34,13 @@ public class CaiUnion implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
/**
|
/**
|
||||||
* 0=可用 1=不可用
|
* 是否开启提成
|
||||||
*/
|
*/
|
||||||
private Integer status;
|
private Boolean enableRate;
|
||||||
/**
|
/**
|
||||||
* 工会默认二级支付奖励比例
|
* 工会默认二级支付奖励比例
|
||||||
*/
|
*/
|
||||||
private BigDecimal unionPayRate;
|
private BigDecimal defaultIncomeRate;
|
||||||
/**
|
|
||||||
* 工会默认二级收益奖励比例
|
|
||||||
*/
|
|
||||||
private BigDecimal unionIncomeRate;
|
|
||||||
/**
|
/**
|
||||||
* 全部人数
|
* 全部人数
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -46,9 +46,9 @@ public class CaiUnionUser implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private BigDecimal vipDivide;
|
private BigDecimal vipDivide;
|
||||||
/**
|
/**
|
||||||
* 0=不分成 1=分成
|
* 是否开启提成
|
||||||
*/
|
*/
|
||||||
private Integer type;
|
private Boolean enableRate;
|
||||||
/**
|
/**
|
||||||
* 收益
|
* 收益
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ public class CaiUserGift implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Long giftAmount;
|
private Long giftAmount;
|
||||||
|
|
||||||
|
private Long consumerLogId;
|
||||||
|
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,21 +34,29 @@ public class CaiUserInvite implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Long inviteId;
|
private Long inviteId;
|
||||||
/**
|
/**
|
||||||
* 奖励好友收入的比率
|
* 奖励好友收入视频提成比率
|
||||||
*/
|
*/
|
||||||
private BigDecimal rewardIncomeRate;
|
private BigDecimal videoIncomeRate;
|
||||||
|
/**
|
||||||
|
* 奖励好友守护的比例
|
||||||
|
*/
|
||||||
|
private BigDecimal guardIncomeRate;
|
||||||
|
/**
|
||||||
|
* 奖励好友礼物的比例
|
||||||
|
*/
|
||||||
|
private BigDecimal giftIncomeRate;
|
||||||
/**
|
/**
|
||||||
* 奖励好友充值的比率
|
* 奖励好友充值的比率
|
||||||
*/
|
*/
|
||||||
private BigDecimal rewardRechargeRate;
|
private BigDecimal payIncomeRate;
|
||||||
/**
|
/**
|
||||||
* 邀请奖励汇总
|
* 邀请奖励汇总
|
||||||
*/
|
*/
|
||||||
private BigDecimal rewardMoneyTotal;
|
private Long rewardCoinTotal;
|
||||||
/**
|
/**
|
||||||
* 是否有效 0=无效 1=有效
|
* 是否有效 0=无效 1=有效
|
||||||
*/
|
*/
|
||||||
private Integer isValid;
|
private Boolean enableRate;
|
||||||
|
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.ruoyi.cai.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型 1-充值 2-礼物 3-守护 4-通话
|
||||||
|
* <p>created on 2023/12/29 20:39</p>
|
||||||
|
* @author duet
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum ConsumeLogType {
|
||||||
|
PAY(1),
|
||||||
|
GIFT(2),
|
||||||
|
GUARD(3),
|
||||||
|
VIDEO(4),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final Integer code;
|
||||||
|
|
||||||
|
ConsumeLogType(Integer code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,9 +12,11 @@ import org.apache.ibatis.annotations.Param;
|
|||||||
*/
|
*/
|
||||||
public interface CaiAccountMapper extends BaseMapper<CaiAccount> {
|
public interface CaiAccountMapper extends BaseMapper<CaiAccount> {
|
||||||
|
|
||||||
long incs(@Param("userId") Long userId, @Param("value") Long value);
|
long decrCoin(@Param("userId") Long userId, @Param("coin") Long coin);
|
||||||
|
|
||||||
void incsCoin(@Param("userId") Long userId, @Param("coin") Long coin, @Param("incomeCoin") Long incomeCoin);
|
long incsCoin(@Param("userId") Long userId, @Param("coin") Long coin);
|
||||||
|
|
||||||
|
void incsIncomeCoin(@Param("userId") Long userId, @Param("incomeCoin") Long incomeCoin);
|
||||||
|
|
||||||
|
|
||||||
long decrIncomeCoin(@Param("userId") Long userId, @Param("incomeCoin") Long incomeCoin);
|
long decrIncomeCoin(@Param("userId") Long userId, @Param("incomeCoin") Long incomeCoin);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.ruoyi.cai.service;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.ruoyi.cai.domain.CaiAccount;
|
import com.ruoyi.cai.domain.CaiAccount;
|
||||||
|
import com.ruoyi.cai.domain.CaiConsumeLog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户账户Service接口
|
* 用户账户Service接口
|
||||||
@@ -13,9 +14,7 @@ public interface CaiAccountService extends IService<CaiAccount> {
|
|||||||
|
|
||||||
CaiAccount getByUserId(Long userId);
|
CaiAccount getByUserId(Long userId);
|
||||||
|
|
||||||
boolean incs(Long userId, Long value);
|
CaiConsumeLog decr(CaiConsumeLog log);
|
||||||
|
|
||||||
boolean decr(Long userId, Long value);
|
|
||||||
|
|
||||||
boolean withdraw(Long userId, Long incomeCoin);
|
boolean withdraw(Long userId, Long incomeCoin);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,21 @@
|
|||||||
package com.ruoyi.cai.service.impl;
|
package com.ruoyi.cai.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.ruoyi.cai.domain.CaiAccount;
|
import com.ruoyi.cai.domain.*;
|
||||||
|
import com.ruoyi.cai.enums.ConsumeLogType;
|
||||||
import com.ruoyi.cai.mapper.CaiAccountMapper;
|
import com.ruoyi.cai.mapper.CaiAccountMapper;
|
||||||
import com.ruoyi.cai.service.CaiAccountService;
|
import com.ruoyi.cai.service.*;
|
||||||
|
import com.ruoyi.cai.util.NumCaUtil;
|
||||||
import com.ruoyi.common.exception.ServiceException;
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
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 java.math.BigDecimal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户账户Service业务层处理
|
* 用户账户Service业务层处理
|
||||||
*
|
*
|
||||||
@@ -16,38 +23,134 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
* @date 2023-12-23
|
* @date 2023-12-23
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
public class CaiAccountServiceImpl extends ServiceImpl<CaiAccountMapper,CaiAccount> implements CaiAccountService {
|
public class CaiAccountServiceImpl extends ServiceImpl<CaiAccountMapper,CaiAccount> implements CaiAccountService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CaiConsumeLogService consumeLogService;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CaiAccount getByUserId(Long userId) {
|
public CaiAccount getByUserId(Long userId) {
|
||||||
return this.getOne(Wrappers.lambdaQuery(CaiAccount.class).eq(CaiAccount::getUserId,userId).last("limit 1"));
|
return this.getOne(Wrappers.lambdaQuery(CaiAccount.class).eq(CaiAccount::getUserId,userId).last("limit 1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean incs(Long userId, Long value) {
|
|
||||||
return baseMapper.incs(userId,value) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean decr(Long userId, Long value) {
|
public CaiConsumeLog decr(CaiConsumeLog consumeLog) {
|
||||||
|
log.info("开始扣费 consumeLog={}", JSON.toJSONString(consumeLog));
|
||||||
|
Long userId = consumeLog.getSourceUserId();
|
||||||
|
Long amount = consumeLog.getAmount();
|
||||||
|
|
||||||
CaiAccount account = this.getByUserId(userId);
|
CaiAccount account = this.getByUserId(userId);
|
||||||
if(account.getTotalCoin() < value){
|
long totalCoin = account.getIncomeCoin() + account.getCoin();
|
||||||
|
if(totalCoin < amount){
|
||||||
throw new ServiceException("余额不足");
|
throw new ServiceException("余额不足");
|
||||||
}
|
}
|
||||||
long incs = baseMapper.incs(userId, -value);
|
boolean flag = false;
|
||||||
if(incs <= 0){
|
long diff = account.getCoin() - amount;
|
||||||
return false;
|
// 充值币够用
|
||||||
|
if(diff > 0){
|
||||||
|
long l = baseMapper.decrCoin(userId, amount);
|
||||||
|
flag = l > 0;
|
||||||
|
} else { // 充值币不够用
|
||||||
|
long decrCoin = baseMapper.decrCoin(userId, account.getCoin());
|
||||||
|
long decrIncomeCoin = baseMapper.decrIncomeCoin(userId, -diff);
|
||||||
|
if(decrCoin > 0 && decrIncomeCoin > 0){
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
CaiAccount newAccount = this.getByUserId(userId);
|
// 扣费不成功
|
||||||
Long decrCoinFlag = newAccount.getCoin() - value;
|
if(!flag){
|
||||||
if(decrCoinFlag >= 0){
|
throw new ServiceException("扣费失败,请重新购买");
|
||||||
baseMapper.incsCoin(userId, -value,0L);
|
|
||||||
}else{
|
|
||||||
baseMapper.incsCoin(userId, -newAccount.getCoin(), decrCoinFlag);
|
|
||||||
}
|
}
|
||||||
return true;
|
// 开始处理 接收方的费用
|
||||||
|
Long targetUserId = consumeLog.getTargetUserId();
|
||||||
|
if(targetUserId != null){
|
||||||
|
Long anchorAmount = NumCaUtil.coin(amount,consumeLog.getTargetRate());
|
||||||
|
consumeLog.setAnchorAmount(anchorAmount);
|
||||||
|
baseMapper.incsCoin(targetUserId,anchorAmount);
|
||||||
|
}
|
||||||
|
// 获取分销的比例和用户
|
||||||
|
fenxiao(consumeLog);
|
||||||
|
consumeLogService.save(consumeLog);
|
||||||
|
return consumeLog;
|
||||||
|
}
|
||||||
|
@Autowired
|
||||||
|
private CaiUserInviteService userInviteService;
|
||||||
|
@Autowired
|
||||||
|
private CaiUserService userService;
|
||||||
|
@Autowired
|
||||||
|
private CaiUnionUserService unionUserService;
|
||||||
|
@Autowired
|
||||||
|
private CaiUnionService unionService;
|
||||||
|
|
||||||
|
|
||||||
|
private void fenxiao(CaiConsumeLog consumeLog){
|
||||||
|
if(ConsumeLogType.PAY.getCode().equals(consumeLog.getType())){
|
||||||
|
Long sourceUserId = consumeLog.getSourceUserId();
|
||||||
|
CaiUserInvite userInvite = userInviteService.getByUserId(sourceUserId);
|
||||||
|
if(userInvite != null){
|
||||||
|
CaiUser oneUser = userService.getById(userInvite.getInviteId());
|
||||||
|
if(oneUser != null && oneUser.getStatus() == 0){
|
||||||
|
consumeLog.setOneRate(userInvite.getPayIncomeRate());
|
||||||
|
consumeLog.setOneUserId(userInvite.getInviteId());
|
||||||
|
consumeLog.setOneUsercode(oneUser.getUsercode());
|
||||||
|
consumeLog.setOnePhone(oneUser.getMobile());
|
||||||
|
consumeLog.setOneJoin(userInvite.getEnableRate());
|
||||||
|
consumeLog.setOneIsUnion(oneUser.getIsUnion());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Long targetUserId = consumeLog.getTargetUserId();
|
||||||
|
if(targetUserId != null){
|
||||||
|
// 获取一级分销
|
||||||
|
CaiUserInvite userInvite = userInviteService.getByUserId(targetUserId);
|
||||||
|
if(userInvite != null){
|
||||||
|
CaiUser oneUser = userService.getById(userInvite.getInviteId());
|
||||||
|
if(oneUser != null && oneUser.getStatus() == 0){
|
||||||
|
if(ConsumeLogType.GUARD.getCode().equals(consumeLog.getType())){
|
||||||
|
consumeLog.setOneRate(userInvite.getGuardIncomeRate());
|
||||||
|
}else if(ConsumeLogType.GIFT.getCode().equals(consumeLog.getType())){
|
||||||
|
consumeLog.setOneRate(userInvite.getGiftIncomeRate());
|
||||||
|
}else if(ConsumeLogType.VIDEO.getCode().equals(consumeLog.getType())){
|
||||||
|
consumeLog.setOneRate(userInvite.getVideoIncomeRate());
|
||||||
|
}
|
||||||
|
consumeLog.setOneUserId(userInvite.getInviteId());
|
||||||
|
consumeLog.setOneUsercode(oneUser.getUsercode());
|
||||||
|
consumeLog.setOnePhone(oneUser.getMobile());
|
||||||
|
consumeLog.setOneJoin(userInvite.getEnableRate());
|
||||||
|
consumeLog.setOneIsUnion(oneUser.getIsUnion());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 工会分销 只有通话和礼物才有
|
||||||
|
if(ConsumeLogType.GIFT.getCode().equals(consumeLog.getType())
|
||||||
|
|| ConsumeLogType.VIDEO.getCode().equals(consumeLog.getType())){
|
||||||
|
CaiUnionUser unionUser = unionUserService.getByUserId(targetUserId);
|
||||||
|
if(unionUser != null){
|
||||||
|
CaiUser user = userService.getById(unionUser.getId());
|
||||||
|
if(user != null && user.getIsUnion() == 1 && user.getStatus() == 0){
|
||||||
|
CaiUnion union = unionService.getById(unionUser.getUnionId());
|
||||||
|
if(union != null){
|
||||||
|
consumeLog.setUnionUsercode(user.getUsercode());
|
||||||
|
consumeLog.setUnionPhone(user.getMobile());
|
||||||
|
consumeLog.setUnionUserId(user.getId());
|
||||||
|
consumeLog.setUnionJoin(false);
|
||||||
|
if(unionUser.getEnableRate() && union.getEnableRate()){
|
||||||
|
consumeLog.setUnionJoin(true);
|
||||||
|
}
|
||||||
|
if(ConsumeLogType.GIFT.getCode().equals(consumeLog.getType())){
|
||||||
|
consumeLog.setUnionRate(unionUser.getGiftDivide());
|
||||||
|
}else if(ConsumeLogType.VIDEO.getCode().equals(consumeLog.getType())){
|
||||||
|
consumeLog.setUnionRate(unionUser.getVideoDivide());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -2,13 +2,17 @@ package com.ruoyi.cai.service.impl;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.ruoyi.cai.domain.CaiAnchor;
|
||||||
|
import com.ruoyi.cai.domain.CaiConsumeLog;
|
||||||
import com.ruoyi.cai.domain.CaiGuardTotal;
|
import com.ruoyi.cai.domain.CaiGuardTotal;
|
||||||
import com.ruoyi.cai.domain.CaiUser;
|
import com.ruoyi.cai.domain.CaiUser;
|
||||||
import com.ruoyi.cai.dto.app.dto.GuardNum;
|
import com.ruoyi.cai.dto.app.dto.GuardNum;
|
||||||
import com.ruoyi.cai.dto.app.query.GiveGuardReq;
|
import com.ruoyi.cai.dto.app.query.GiveGuardReq;
|
||||||
import com.ruoyi.cai.dto.app.vo.GuardTotalVo;
|
import com.ruoyi.cai.dto.app.vo.GuardTotalVo;
|
||||||
|
import com.ruoyi.cai.enums.ConsumeLogType;
|
||||||
import com.ruoyi.cai.mapper.CaiGuardTotalMapper;
|
import com.ruoyi.cai.mapper.CaiGuardTotalMapper;
|
||||||
import com.ruoyi.cai.service.CaiAccountService;
|
import com.ruoyi.cai.service.CaiAccountService;
|
||||||
|
import com.ruoyi.cai.service.CaiAnchorService;
|
||||||
import com.ruoyi.cai.service.CaiGuardTotalService;
|
import com.ruoyi.cai.service.CaiGuardTotalService;
|
||||||
import com.ruoyi.cai.service.CaiUserService;
|
import com.ruoyi.cai.service.CaiUserService;
|
||||||
import com.ruoyi.common.exception.ServiceException;
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
@@ -33,6 +37,8 @@ public class CaiGuardTotalServiceImpl extends ServiceImpl<CaiGuardTotalMapper,Ca
|
|||||||
private CaiUserService userService;
|
private CaiUserService userService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private CaiAccountService accountService;
|
private CaiAccountService accountService;
|
||||||
|
@Autowired
|
||||||
|
private CaiAnchorService anchorService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GuardTotalVo> selectGuardTotalLimit(Long fromUserId,Integer limit) {
|
public List<GuardTotalVo> selectGuardTotalLimit(Long fromUserId,Integer limit) {
|
||||||
@@ -43,18 +49,25 @@ public class CaiGuardTotalServiceImpl extends ServiceImpl<CaiGuardTotalMapper,Ca
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean giveGuard(GiveGuardReq query) {
|
public boolean giveGuard(GiveGuardReq query) {
|
||||||
Long fromUserId = LoginHelper.getUserId();
|
Long fromUserId = LoginHelper.getUserId();
|
||||||
CaiUser user = userService.getById(query.getToUserId());
|
CaiUser fromUser = userService.getById(fromUserId);
|
||||||
if(user == null){
|
CaiUser toUser = userService.getById(query.getToUserId());
|
||||||
|
if(toUser == null){
|
||||||
throw new ServiceException("女神不存在");
|
throw new ServiceException("女神不存在");
|
||||||
}
|
}
|
||||||
if(user.getIsAnchor() != 1){
|
if(toUser.getIsAnchor() != 1){
|
||||||
throw new ServiceException("只能给女神送守护");
|
throw new ServiceException("只能给女神送守护");
|
||||||
}
|
}
|
||||||
Long guardValue = query.getGuardNum() * GUARD_UNIT_PRICE;
|
CaiAnchor anchor = anchorService.getByUserId(toUser.getId());
|
||||||
boolean boo = accountService.decr(fromUserId, -guardValue);
|
if(anchor == null){
|
||||||
if(!boo){
|
throw new ServiceException("女神不存在");
|
||||||
throw new ServiceException("余额不足");
|
|
||||||
}
|
}
|
||||||
|
Long guardValue = query.getGuardNum() * GUARD_UNIT_PRICE;
|
||||||
|
CaiConsumeLog consumeLog = new CaiConsumeLog();
|
||||||
|
consumeLog.init(fromUser,toUser);
|
||||||
|
consumeLog.setType(ConsumeLogType.GUARD.getCode());
|
||||||
|
consumeLog.setAmount(guardValue);
|
||||||
|
consumeLog.setTargetRate(anchor.getGuardRate());
|
||||||
|
consumeLog = accountService.decr(consumeLog);
|
||||||
// TODO 增加守护流水
|
// TODO 增加守护流水
|
||||||
CaiGuardTotal one = this.getOne(Wrappers.lambdaQuery(CaiGuardTotal.class)
|
CaiGuardTotal one = this.getOne(Wrappers.lambdaQuery(CaiGuardTotal.class)
|
||||||
.eq(CaiGuardTotal::getToUserId, query.getToUserId())
|
.eq(CaiGuardTotal::getToUserId, query.getToUserId())
|
||||||
|
|||||||
@@ -51,14 +51,14 @@ public class CaiUserCallServiceImpl extends ServiceImpl<CaiUserCallMapper,CaiUse
|
|||||||
caiUserCall.setCallPrice(anchor.getPrice());
|
caiUserCall.setCallPrice(anchor.getPrice());
|
||||||
caiUserCall.setReceiverVideoDivide(anchor.getVideoRate());
|
caiUserCall.setReceiverVideoDivide(anchor.getVideoRate());
|
||||||
CaiUnionUser unionUser = unionUserService.getByUserId(toUser.getId());
|
CaiUnionUser unionUser = unionUserService.getByUserId(toUser.getId());
|
||||||
if(unionUser != null && unionUser.getType() == 1){
|
if(unionUser != null && unionUser.getEnableRate()){
|
||||||
caiUserCall.setReceiverUnionUserId(unionUser.getUserId());
|
caiUserCall.setReceiverUnionUserId(unionUser.getUserId());
|
||||||
caiUserCall.setReceiverUnionVideoDivide(unionUser.getVideoDivide());
|
caiUserCall.setReceiverUnionVideoDivide(unionUser.getVideoDivide());
|
||||||
}
|
}
|
||||||
CaiUserInvite invite = inviteService.getByUserId(toUser.getId());
|
CaiUserInvite invite = inviteService.getByUserId(toUser.getId());
|
||||||
if(invite != null){
|
if(invite != null){
|
||||||
caiUserCall.setReceiverInviteUserId(invite.getInviteId());
|
caiUserCall.setReceiverInviteUserId(invite.getInviteId());
|
||||||
caiUserCall.setReceiverIncomeDivide(invite.getRewardIncomeRate());
|
caiUserCall.setReceiverIncomeDivide(invite.getVideoIncomeRate());
|
||||||
}
|
}
|
||||||
boolean save = this.save(caiUserCall);
|
boolean save = this.save(caiUserCall);
|
||||||
if(!save){
|
if(!save){
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
package com.ruoyi.cai.service.impl;
|
package com.ruoyi.cai.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.ruoyi.cai.domain.CaiAccount;
|
import com.ruoyi.cai.domain.*;
|
||||||
import com.ruoyi.cai.domain.CaiGift;
|
|
||||||
import com.ruoyi.cai.domain.CaiUserGift;
|
|
||||||
import com.ruoyi.cai.dto.app.query.GiveGiftRes;
|
import com.ruoyi.cai.dto.app.query.GiveGiftRes;
|
||||||
import com.ruoyi.cai.dto.app.vo.UserGiftVo;
|
import com.ruoyi.cai.dto.app.vo.UserGiftVo;
|
||||||
|
import com.ruoyi.cai.enums.ConsumeLogType;
|
||||||
import com.ruoyi.cai.mapper.CaiUserGiftMapper;
|
import com.ruoyi.cai.mapper.CaiUserGiftMapper;
|
||||||
import com.ruoyi.cai.service.CaiAccountService;
|
import com.ruoyi.cai.service.*;
|
||||||
import com.ruoyi.cai.service.CaiGiftService;
|
|
||||||
import com.ruoyi.cai.service.CaiUserGiftService;
|
|
||||||
import com.ruoyi.common.exception.ServiceException;
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
import com.ruoyi.common.helper.LoginHelper;
|
import com.ruoyi.common.helper.LoginHelper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -32,6 +29,11 @@ public class CaiUserGiftServiceImpl extends ServiceImpl<CaiUserGiftMapper,CaiUse
|
|||||||
private CaiGiftService giftService;
|
private CaiGiftService giftService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private CaiAccountService accountService;
|
private CaiAccountService accountService;
|
||||||
|
@Autowired
|
||||||
|
private CaiUserService userService;
|
||||||
|
@Autowired
|
||||||
|
private CaiAnchorService anchorService;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserGiftVo> selectGiftList(Long userId) {
|
public List<UserGiftVo> selectGiftList(Long userId) {
|
||||||
@@ -45,12 +47,17 @@ public class CaiUserGiftServiceImpl extends ServiceImpl<CaiUserGiftMapper,CaiUse
|
|||||||
if(gift == null){
|
if(gift == null){
|
||||||
throw new ServiceException("礼物不存在");
|
throw new ServiceException("礼物不存在");
|
||||||
}
|
}
|
||||||
|
CaiUser fromUser = userService.getById(fromUserId);
|
||||||
|
CaiUser toUser = userService.getById(query.getToUserId());
|
||||||
|
CaiAnchor anchor = anchorService.getByUserId(query.getToUserId());
|
||||||
Long price = gift.getPrice();
|
Long price = gift.getPrice();
|
||||||
Long giftAmount = query.getGiftCount() * price;
|
Long giftAmount = query.getGiftCount() * price;
|
||||||
boolean boo = accountService.decr(fromUserId, -giftAmount);
|
CaiConsumeLog consumeLog = new CaiConsumeLog();
|
||||||
if(!boo){
|
consumeLog.init(fromUser,toUser);
|
||||||
throw new ServiceException("余额不足");
|
consumeLog.setType(ConsumeLogType.GIFT.getCode());
|
||||||
}
|
consumeLog.setAmount(giftAmount);
|
||||||
|
consumeLog.setTargetRate(anchor.getGiftRate());
|
||||||
|
consumeLog = accountService.decr(consumeLog);
|
||||||
CaiUserGift userGift = new CaiUserGift();
|
CaiUserGift userGift = new CaiUserGift();
|
||||||
userGift.setType(query.getType());
|
userGift.setType(query.getType());
|
||||||
userGift.setFromUid(fromUserId);
|
userGift.setFromUid(fromUserId);
|
||||||
@@ -58,6 +65,7 @@ public class CaiUserGiftServiceImpl extends ServiceImpl<CaiUserGiftMapper,CaiUse
|
|||||||
userGift.setGiftId(query.getGiftId());
|
userGift.setGiftId(query.getGiftId());
|
||||||
userGift.setGiftCount(query.getGiftCount());
|
userGift.setGiftCount(query.getGiftCount());
|
||||||
userGift.setGiftAmount(giftAmount);
|
userGift.setGiftAmount(giftAmount);
|
||||||
|
userGift.setConsumerLogId(consumeLog.getId());
|
||||||
this.save(userGift);
|
this.save(userGift);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
20
ruoyi-cai/src/main/java/com/ruoyi/cai/util/NumCaUtil.java
Normal file
20
ruoyi-cai/src/main/java/com/ruoyi/cai/util/NumCaUtil.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package com.ruoyi.cai.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.NumberUtil;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
|
||||||
|
public class NumCaUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向下取整计算金额
|
||||||
|
* @param value
|
||||||
|
* @param rate
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Long coin(Long value, BigDecimal rate){
|
||||||
|
BigDecimal decimal = NumberUtil.mul(value, rate);
|
||||||
|
return decimal.setScale(0, RoundingMode.DOWN).longValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -97,6 +97,8 @@ public class WebSocketManager {
|
|||||||
// 检查女神在线状态 TODO
|
// 检查女神在线状态 TODO
|
||||||
|
|
||||||
// 关闭发起的其他房间
|
// 关闭发起的其他房间
|
||||||
|
|
||||||
|
|
||||||
roomService.closeAllRoom(call.getFromUid());
|
roomService.closeAllRoom(call.getFromUid());
|
||||||
// 删除旧房间记录
|
// 删除旧房间记录
|
||||||
roomService.delCallRoom(call.getFromUid());
|
roomService.delCallRoom(call.getFromUid());
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ public class RoomService {
|
|||||||
}
|
}
|
||||||
RoomData roomData = room.getRoomData();
|
RoomData roomData = room.getRoomData();
|
||||||
long blockAmount = roomData.getPayCoin() + roomData.getPayIncome();
|
long blockAmount = roomData.getPayCoin() + roomData.getPayIncome();
|
||||||
long totalAmount = account.getTotalCoin()+account.getIncomeCoin() + blockAmount;
|
long totalAmount = account.getCoin()+account.getIncomeCoin() + blockAmount;
|
||||||
long totalSecond = (totalAmount / roomData.getCallPrice()) / 60;
|
long totalSecond = (totalAmount / roomData.getCallPrice()) / 60;
|
||||||
long useTime = 0;
|
long useTime = 0;
|
||||||
if(roomData.getBeginTime() != null){
|
if(roomData.getBeginTime() != null){
|
||||||
|
|||||||
@@ -7,30 +7,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<resultMap type="com.ruoyi.cai.domain.CaiAccount" id="CaiAccountResult">
|
<resultMap type="com.ruoyi.cai.domain.CaiAccount" id="CaiAccountResult">
|
||||||
<result property="id" column="id"/>
|
<result property="id" column="id"/>
|
||||||
<result property="userId" column="user_id"/>
|
<result property="userId" column="user_id"/>
|
||||||
<result property="money" column="money"/>
|
|
||||||
<result property="incomeMoney" column="income_money"/>
|
|
||||||
<result property="coin" column="coin"/>
|
<result property="coin" column="coin"/>
|
||||||
<result property="incomeCoin" column="income_coin"/>
|
<result property="incomeCoin" column="income_coin"/>
|
||||||
<result property="loveValue" column="love_value"/>
|
|
||||||
<result property="totalBuyMoney" column="total_buy_money"/>
|
<result property="totalBuyMoney" column="total_buy_money"/>
|
||||||
<result property="totalBuyCoin" column="total_buy_coin"/>
|
<result property="totalBuyCoin" column="total_buy_coin"/>
|
||||||
<result property="status" column="status"/>
|
<result property="status" column="status"/>
|
||||||
<result property="createTime" column="create_time"/>
|
<result property="createTime" column="create_time"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<update id="incs">
|
|
||||||
update cai_account
|
|
||||||
set total_coin = total_coin + #{value}
|
|
||||||
where user_id = #{userId} and (total_coin + #{value}) > 0
|
|
||||||
</update>
|
|
||||||
<update id="incsCoin">
|
<update id="incsCoin">
|
||||||
update cai_account
|
update cai_account
|
||||||
set coin = coin + #{coin}, income_coin = income_coin + #{incomeCoin}
|
set coin = coin + #{coin}
|
||||||
where user_id = #{userId}
|
where user_id = #{userId}
|
||||||
</update>
|
</update>
|
||||||
|
<update id="decrCoin">
|
||||||
|
update cai_account
|
||||||
|
set coin = coin - #{coin}
|
||||||
|
where user_id = #{userId} and (coin - #{coin}) > 0
|
||||||
|
</update>
|
||||||
|
|
||||||
<update id="decrIncomeCoin">
|
<update id="decrIncomeCoin">
|
||||||
update cai_account
|
update cai_account
|
||||||
set income_coin = income_coin - #{value}
|
set income_coin = income_coin - #{incomeCoin}
|
||||||
where user_id = #{userId} and (income_coin - #{value}) > 0
|
where user_id = #{userId} and (income_coin - #{incomeCoin}) > 0
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="incsIncomeCoin">
|
||||||
|
update cai_account
|
||||||
|
set income_coin = income_coin + #{incomeCoin}
|
||||||
|
where user_id = #{userId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user