This commit is contained in:
dute7liang
2024-01-07 16:42:24 +08:00
parent 31af6fdc76
commit fad404fe58
52 changed files with 257 additions and 176 deletions

View File

@@ -171,5 +171,8 @@ spring:
virtual-host: /cai
agora:
app-id: app
key: key
secret: secret
key: 627b8e17b0c616c1346cba2d87e10251
secret: c47628fe2538
yunxin:
app-key: 627b8e17b0c616c1346cba2d87e10251
app-secret: c47628fe2538

View File

@@ -176,3 +176,6 @@ agora:
app-id: app
key: key
secret: secret
yunxin:
app-key: 627b8e17b0c616c1346cba2d87e10251
app-secret: c47628fe2538

View File

@@ -135,7 +135,9 @@ security:
# swagger 文档配置
- /*/api-docs
- /*/api-docs/**
- /v3/api-docs/swagger-config
- /doc.html
- /doc.html#/
- /swagger-resources/**
- /webjars/**
# actuator 监控配置

View File

@@ -140,7 +140,7 @@ public class CaiLoginManager {
}
String key = LockManager.getDealInviteLockKey(inviteId);
RLock lock = redissonClient.getLock(key);
if(!lock.isLocked()){
if(lock.isLocked()){
log.warn("点击太快了等一等dealInviteId");
return;
}
@@ -191,7 +191,7 @@ public class CaiLoginManager {
UserInfo userInfo = userInfoService.getById(user.getId());
UserInfo update = new UserInfo();
update.setUserId(user.getId());
update.setLoginCount(userInfo.getLoginCount()+1);
update.setLoginCount(userInfo.getLoginCount()==null?0:userInfo.getLoginCount()+1);
update.setLastLoginIp(ip);
update.setLastLoginTime(LocalDateTime.now());
update.setLastLocation(address);
@@ -239,7 +239,7 @@ public class CaiLoginManager {
String usercode = userCodeGenService.getCodeGen();
User add = new User();
add.setUsercode(usercode);
add.setNickname("蜜瓜"+usercode);
add.setNickname("用户"+usercode);
add.setType(0);
add.setPassword(BCrypt.hashpw(user.getPassword()));
add.setMobile(user.getUsername());

View File

@@ -3,19 +3,25 @@ package com.ruoyi.cai.auth;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
@Data
@Schema(description = "注册模型")
public class CaiRegisterUser {
@Schema(description = "手机号登录名")
@NotEmpty(message = "手机号不能为空")
private String username;
@Schema(description = "密码")
@NotEmpty(message = "密码不能为空")
private String password;
@Schema(description = "密码确认")
@NotEmpty(message = "密码确认不能为空")
private String passwordCheck;
@Schema(description = "验证码")
@NotEmpty(message = "验证码不能为空")
private String code;
@Schema(description = "邀请人ID")
private Long inviteId;
@Schema(description = "性别")
private Integer gender;
private Integer gender = 0;
}

View File

@@ -3,11 +3,15 @@ package com.ruoyi.cai.auth;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
@Data
@Schema(description = "登陆入参模型")
public class LoginCaiUser {
@Schema(description = "用户")
@NotEmpty(message = "登录名不能为空")
private String username;
@Schema(description = "密码")
@NotEmpty(message = "密码不能为空")
private String password;
}

View File

@@ -2,7 +2,10 @@ package com.ruoyi.cai.auth;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
@Data
public class RegisterCode {
@NotEmpty(message = "手机号不能为空")
private String mobile;
}

View File

@@ -8,6 +8,7 @@ public class RedisConstant {
public static final String DYNAMIC_TOTAL_CACHE_REDIS = REDIS_P + "synamicTotal:%s:%s";
public static final String CODE_REDIS = REDIS_P + "code:%s:%s";
public static final String USER_GREET_TOTAL_REDIS = REDIS_P + "userGreetTotal:%s:%s";
public static final String USER_GREET_SEND_TIME_REDIS = REDIS_P + "userGreetSendTime:%s";
public static final String BLACK_REDIS = REDIS_P + "black:%s";
}

View File

@@ -42,7 +42,7 @@ public class SmsVerifyController extends BaseController {
@SaCheckPermission("cai:smsVerify:list")
@GetMapping("/list")
public TableDataInfo<SmsVerify> list(SmsVerify bo, PageQuery pageQuery) {
Page<SmsVerify> page = smsVerifyService.page(pageQuery.build(), Wrappers.lambdaQuery(bo));
Page<SmsVerify> page = smsVerifyService.page(pageQuery.build(), Wrappers.lambdaQuery(bo).orderByDesc(SmsVerify::getCreateTime));
return TableDataInfo.build(page);
}

View File

@@ -2,13 +2,17 @@ package com.ruoyi.cai.controller.app;
import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.cai.auth.*;
import com.ruoyi.cai.domain.User;
import com.ruoyi.cai.enums.CodeEnum;
import com.ruoyi.cai.manager.CodeManager;
import com.ruoyi.cai.service.SmsVerifyService;
import com.ruoyi.cai.service.UserService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.exception.ServiceException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -21,16 +25,19 @@ import java.util.Map;
@RequestMapping("/api/auth")
@SaIgnore
@Tag(name = "权限相关接口,免鉴权")
@Validated
public class AuthAppController {
@Autowired
private CaiLoginManager caiLoginManager;
@Autowired
private SmsVerifyService smsVerifyService;
@Autowired
private UserService userService;
@PostMapping("/register")
@Operation(summary = "注册")
public R<Map<String, Object>> register(@RequestBody CaiRegisterUser caiUser){
public R<Map<String, Object>> register(@Validated @RequestBody CaiRegisterUser caiUser){
String token = caiLoginManager.register(caiUser);
Map<String, Object> ajax = new HashMap<>();
ajax.put("token",token);
@@ -39,21 +46,25 @@ public class AuthAppController {
@PostMapping("/register/code")
@Operation(summary = "获取注册验证码")
public R<Map<String,String>> registerCode(@RequestBody RegisterCode code){
public R<Map<String,String>> registerCode(@Validated @RequestBody RegisterCode code){
smsVerifyService.put(CodeEnum.REGISTER,code.getMobile());
return R.ok("发送成功");
}
@PostMapping("/resetPassword/code")
@Operation(summary = "获取重置密码验证码")
public R<Map<String,String>> resetPasswordCode(@RequestBody RegisterCode code){
public R<Map<String,String>> resetPasswordCode(@Validated @RequestBody RegisterCode code){
User user = userService.getByUsername(code.getMobile());
if(user == null){
throw new ServiceException("用户不存在");
}
smsVerifyService.put(CodeEnum.RESET_PASSWORD,code.getMobile());
return R.ok("发送成功");
}
@PostMapping("/login")
@Operation(summary = "登陆")
public R<Map<String,Object>> login(@RequestBody LoginCaiUser loginBody){
public R<Map<String,Object>> login(@Validated @RequestBody LoginCaiUser loginBody){
Map<String, Object> ajax = new HashMap<>();
String token = caiLoginManager.login(loginBody.getUsername(), loginBody.getPassword());
ajax.put("token",token);
@@ -61,10 +72,10 @@ public class AuthAppController {
}
@PostMapping("/resetPassword")
@Operation(summary = "获取充值密码验证")
@Operation(summary = "重置密")
public R<Boolean> resetPassword(@RequestBody ResetPasswordReq code){
caiLoginManager.resetPassword(code);
return R.ok("发送成功");
return R.ok(true);
}

View File

@@ -28,8 +28,6 @@ public class SettingAppController {
@Autowired
private ReportCateService reportCateService;
@Autowired
private CitysService citysService;
@Autowired
private GiftService giftService;
@GetMapping("/goods")
@@ -57,12 +55,6 @@ public class SettingAppController {
}
@GetMapping("/city")
@Operation(summary = "城市")
public R<Map<Long,String>> city(){
return R.ok(citysService.all());
}
@GetMapping("/gift")
@Operation(summary = "礼物配置")
public R<List<GiftVo>> gift(){

View File

@@ -12,6 +12,7 @@ import com.ruoyi.common.helper.LoginHelper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -33,7 +34,7 @@ public class UserAppController {
@PostMapping("/update")
@Operation(summary = "修改当前用户信息")
public R<Boolean> userUpdate(@RequestBody UserUpdateReq res){
public R<Boolean> userUpdate(@Validated @RequestBody UserUpdateReq res){
return R.ok(currentUserManager.userUpdate(res));
}

View File

@@ -29,7 +29,7 @@ public class UserBlackAppController {
}
@PostMapping("black")
@Operation(summary = "拉黑操作 如果已经给拉黑则放开")
@Operation(summary = "拉黑操作")
public R<Boolean> black(@RequestBody BlackQuery query){
Long userId = LoginHelper.getUserId();
boolean b = userBlacklistService.black(userId,query.getBlackUserId(),query.getActionType());

View File

@@ -13,6 +13,7 @@ import com.ruoyi.common.utils.BeanConvertUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -39,9 +40,10 @@ public class UserGreetAppController {
return R.ok(BeanConvertUtil.convertListTo(userGreet,UserGreetVo::new));
}
@GetMapping("/add")
@PostMapping("/add")
@Operation(summary = "新增群打招呼")
public R<Void> add(@RequestBody UserGreetAddReq req){
public R<Void> add(@Validated @RequestBody UserGreetAddReq req){
req.setUserId(LoginHelper.getUserId());
userGreetService.addUserGreet(req);
return R.ok();
}

View File

@@ -5,14 +5,16 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.cai.domain.AccountBankcard;
import com.ruoyi.cai.domain.AccountCash;
import com.ruoyi.cai.domain.AccountRecharge;
import com.ruoyi.cai.domain.RechargeOrder;
import com.ruoyi.cai.dto.app.query.AccountAliBankCardRes;
import com.ruoyi.cai.dto.app.query.WithdrawReq;
import com.ruoyi.cai.dto.app.vo.AccountCashVo;
import com.ruoyi.cai.dto.app.vo.AccountRechargeVo;
import com.ruoyi.cai.dto.app.vo.RechargeOrderVo;
import com.ruoyi.cai.dto.app.vo.user.UserAccountVo;
import com.ruoyi.cai.manager.CurrentUserManager;
import com.ruoyi.cai.pay.PayStatusEnum;
import com.ruoyi.cai.service.AccountCashService;
import com.ruoyi.cai.service.AccountRechargeService;
import com.ruoyi.cai.service.RechargeOrderService;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
@@ -32,7 +34,7 @@ public class WalletController {
@Autowired
private AccountCashService accountCashService;
@Autowired
private AccountRechargeService accountRechargeService;
private RechargeOrderService rechargeOrderService;
@GetMapping("/account")
@Operation(summary = "快速获取当前用户账号余额信息")
@@ -64,12 +66,14 @@ public class WalletController {
@GetMapping("/recharge/log")
@Operation(summary = "充值记录-分页")
public TableDataInfo<AccountRechargeVo> rechargeLog(PageQuery query){
public TableDataInfo<RechargeOrderVo> rechargeLog(PageQuery query){
Long userId = LoginHelper.getUserId();
Page<AccountRecharge> page = accountRechargeService.page(query.build(), Wrappers.lambdaQuery(AccountRecharge.class)
.eq(AccountRecharge::getUserId, userId)
.orderByDesc(AccountRecharge::getCreateTime));
return TableDataInfo.build(page,AccountRechargeVo::new);
Page<RechargeOrder> page = rechargeOrderService.page(query.build(), Wrappers.lambdaQuery(RechargeOrder.class)
.eq(RechargeOrder::getUserId, userId)
.eq(RechargeOrder::getAdmin,false)
.eq(RechargeOrder::getPayStatus, PayStatusEnum.PAY.getCode())
.orderByDesc(RechargeOrder::getCreateTime));
return TableDataInfo.build(page, RechargeOrderVo::new);
}
@GetMapping("/cash/log")

View File

@@ -1,6 +1,7 @@
package com.ruoyi.cai.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@@ -51,14 +52,17 @@ public class Gift implements Serializable {
/**
* 礼物描述
*/
@TableField("`desc`")
private String desc;
/**
* 是否隐藏 0 不隐藏,可见 1 隐藏
*/
@TableField("`hide`")
private Integer hide;
/**
* 排序
*/
@TableField("`sort`")
private Integer sort;
/**
* 状态 0 可用 1 不可用

View File

@@ -3,6 +3,8 @@ package com.ruoyi.cai.dto.app.query;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
@Schema(description = "赠送守护入参")
public class GiveGuardReq {

View File

@@ -3,8 +3,11 @@ package com.ruoyi.cai.dto.app.query;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
public class IdRes {
@Schema(description = "id")
@NotNull(message = "参数异常")
private Long id;
}

View File

@@ -3,6 +3,7 @@ package com.ruoyi.cai.dto.app.query;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDate;
import java.time.LocalDateTime;
@Data
@@ -14,7 +15,7 @@ public class UserUpdateReq {
@Schema(description = "昵称")
private String nickname;
@Schema(description = "生日")
private LocalDateTime birthday;
private LocalDate birthday;
@Schema(description = "性别")
private Integer gender;
@Schema(description = "头像")

View File

@@ -3,11 +3,15 @@ package com.ruoyi.cai.dto.app.query.user;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Data
@Schema(description = "新增群达招呼")
public class UserGreetAddReq {
@Schema(accessMode = Schema.AccessMode.READ_ONLY)
private Long userId;
@Schema(description = "内容")
@NotEmpty(message = "打招呼内容不能为空")
private String title;
}

View File

@@ -14,7 +14,7 @@ public class AccountCashVo {
*
*/
@Schema(description = "ID")
private Integer id;
private Long id;
/**
*
*/

View File

@@ -1,74 +0,0 @@
package com.ruoyi.cai.dto.app.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
@Schema(description = "充值记录")
public class AccountRechargeVo {
@Schema(description = "ID")
private Long id;
/**
*
*/
@Schema(description = "用户Id")
private Long userId;
/**
*
*/
@Schema(description = "充值ID")
private Long goodsId;
/**
*
*/
@Schema(description = "订单编号")
private String orderNo;
/**
* 订单名
*/
@Schema(description = "订单名称")
private String orderName;
/**
* 充值类型 0 手工充值 1 线上充值
*/
@Schema(description = "充值类型")
private Integer rechargeType;
/**
* 充值金额
*/
@Schema(description = "充值金额")
private BigDecimal rechargeMoney;
/**
* 充值的紫贝
*/
@Schema(description = "紫贝数量")
private Integer coinNum;
/**
* 充值平台类型
*/
@Schema(description = "平台")
private Long platformType;
/**
* 充值平台名称
*/
@Schema(description = "平台名称")
private String platformName;
/**
*
*/
private String payNo;
/**
*
*/
private String operateIp;
/**
* 类型: 0积分(默认)1会员
*/
@Schema(description = "0-充值 1-会员")
private Integer type;
@Schema(description = "充值时间")
private LocalDateTime createTime;
}

View File

@@ -8,6 +8,9 @@ import java.math.BigDecimal;
@Data
@Schema(description = "主播列表信息")
public class AnchorListVo {
@Schema(description = "用户ID")
private String userId;
/**
* 头像
*/

View File

@@ -37,16 +37,9 @@ public class DynamicVo {
*/
@Schema(description = "是否有附件 0 没有 1 有")
private Integer isAttach;
/**
* 状态 0 审核中 1可用 2 不可用
*/
@Schema(description = "状态 0 审核中 1可用 2 不可用")
private Integer status;
/**
* 排序字段
*/
@Schema(description = "排序字段")
private Long sort;
@Schema(description = "审核状态")
private Integer auditStatus;
@Schema(description = "创建时间")
private LocalDateTime createTime;

View File

@@ -1,30 +1,38 @@
package com.ruoyi.cai.dto.app.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.print.attribute.standard.Media;
import java.io.Serializable;
@Data
public class GiftVo implements Serializable {
private Integer id;
@Schema(description = "礼物ID")
private Long id;
/**
* 类型 0 普通礼物 1svga礼物
*/
@Schema(hidden = true)
private Integer type;
/**
* 礼物名称
*/
@Schema(description = "礼物名称")
private String name;
/**
* 礼物价格
*/
@Schema(description = "礼物价格")
private Long price;
/**
* 礼物图片地址
*/
@Schema(description = "图片")
private String img;
/**
* svga地址
*/
@Schema(description = "礼物SVGA")
private String svga;
}

View File

@@ -0,0 +1,50 @@
package com.ruoyi.cai.dto.app.vo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
@Schema(description = "充值记录")
public class RechargeOrderVo {
/**
* 用户ID
*/
private Long userId;
/**
* 商品ID
*/
@Schema(description = "商品ID")
private Long rechargeId;
/**
* 商品名称
*/
@Schema(description = "商品名称")
private String rechargeName;
/**
* 充值紫贝
*/
@Schema(description = "充值紫贝")
private Long rechargeCoin;
/**
* 价格
*/
@Schema(description = "价格")
private BigDecimal price;
/**
* 订单号
*/
@Schema(description = "订单号")
private String orderNo;
@Schema(description = "状态 0-待支付 1-已支付 2-已退款 10-无需支付")
private Integer payStatus;
@Schema(description = "充值时间")
private LocalDateTime createTime;
}

View File

@@ -19,6 +19,6 @@ public class UserGiftIndexVo {
@Schema(description = "礼物价格")
private String price;
@Schema(description = "礼物数量")
private Long count;
private Long giftCount;
}

View File

@@ -22,6 +22,4 @@ public class UserAccountVo {
@Schema(description = "收益的紫贝")
private Long incomeCoin;
@Schema(description = "总数量")
private Long totalCoin;
}

View File

@@ -7,6 +7,8 @@ import lombok.Data;
@Data
public class UserBaseVo {
@Schema(description = "用户Id")
private Long userId;
/**
* 头像
*/
@@ -24,7 +26,7 @@ public class UserBaseVo {
@Schema(description = "城市ID")
private Integer cityId;
@Schema(description = "城市")
private Integer city;
private String city;
/**
* 昵称
*/

View File

@@ -17,12 +17,12 @@ public class UserGreetVo {
/**
* 标题
*/
@Schema(description = "标题")
@Schema(description = "内容")
private String title;
/**
* 审核状态
*/
@Schema(description = "审核状态 1 审核中, 2 审核通过, 3 审核不通过")
private Integer status;
private Integer auditStatus;
}

View File

@@ -9,6 +9,6 @@ import java.time.LocalDateTime;
@Data
@Schema(description = "用户列表返回")
public class UserListVo extends UserBaseVo {
@Schema(description = "绑定时间")
@Schema(description = "最后活跃时间")
private LocalDateTime bindTime;
}

View File

@@ -5,7 +5,7 @@ import lombok.Data;
import java.time.LocalDateTime;
@Data
public class UserStarOrVisitorList {
public class UserStarOrVisitorList extends UserBaseVo {
private LocalDateTime happenTime;

View File

@@ -52,8 +52,9 @@ public class CurrentUserManager {
Long userId = LoginHelper.getUserId();
User user = userService.getById(userId);
CurrentUserInfoVo res = BeanConvertUtil.convertTo(user, CurrentUserInfoVo::new);
res.setUserId(userId);
Anchor anchor = anchorService.getByUserId(userId);
res.setOpenVideoStatus(anchor.getOpenVideoStatus());
res.setOpenVideoStatus(anchor == null ? 1 : anchor.getOpenVideoStatus());
UserCount userCount = userCountService.getByUserId(userId);
res.setUserCount(BeanConvertUtil.convertTo(userCount, UserCountVo::new));
Account account = accountService.getByUserId(userId);

View File

@@ -14,12 +14,12 @@ import org.apache.ibatis.annotations.Param;
*/
public interface AccountMapper extends BaseMapper<Account> {
long decrCoin(@Param("userId") Long userId, @Param("coin") Long coin);
boolean decrCoin(@Param("userId") Long userId, @Param("coin") Long coin);
long incsCoin(@Param("userId") Long userId, @Param("coin") Long coin);
boolean 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);
boolean incsIncomeCoin(@Param("userId") Long userId, @Param("incomeCoin") Long incomeCoin);
boolean decrIncomeCoin(@Param("userId") Long userId, @Param("incomeCoin") Long incomeCoin);
Page<AccountAdminVo> pageAdmin(@Param("build") Page<Object> build, @Param("bo") AccountAdminVo bo);
}

View File

@@ -15,6 +15,7 @@ import com.ruoyi.cai.util.NumCaUtil;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -55,18 +56,18 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
throw new ServiceException("余额不足");
}
boolean flag = false;
long coin = account.getCoin();
long incomeCoin = 0;
long coin = -amount; // 消费余额
long incomeCoin = 0; // 消费收益
long diff = account.getCoin() - amount;
// 充值币够用
if(diff > 0){
long l = baseMapper.decrCoin(userId, coin);
flag = l > 0;
flag = baseMapper.decrCoin(userId, -coin);
} else { // 充值币不够用
coin = -account.getCoin();
incomeCoin = diff;
long decrCoin = baseMapper.decrCoin(userId, account.getCoin());
long decrIncomeCoin = baseMapper.decrIncomeCoin(userId, -diff);
if(decrCoin > 0 && decrIncomeCoin > 0){
boolean decrCoin = baseMapper.decrCoin(userId, -coin);
boolean decrIncomeCoin = baseMapper.decrIncomeCoin(userId, -diff);
if(decrCoin && decrIncomeCoin){
flag = true;
}
}
@@ -88,8 +89,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
if(incomeCoin != 0){
accountChangeLogService.saveLogNoAdmin(userId,consumeLog.getSourceUsercode(), RechargeTypeEnum.COIN_INCOME,businessEnum.getSourceEnum(),incomeCoin,consumeLog.getTraceId());
}
// 记录接收方的流水
if(targetUserId != null){
accountChangeLogService.saveLogNoAdmin(targetUserId,consumeLog.getTargetUsercode(), RechargeTypeEnum.COIN_INCOME,businessEnum.getTargetEnum(),incomeCoin,consumeLog.getTraceId());
accountChangeLogService.saveLogNoAdmin(targetUserId,consumeLog.getTargetUsercode(), RechargeTypeEnum.COIN_INCOME,businessEnum.getTargetEnum(),consumeLog.getAnchorAmount(),consumeLog.getTraceId());
}
// 获取分销的比例和用户
consumeLogService.calculateInitFenxiao(consumeLog);
@@ -108,8 +110,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
if(account.getIncomeCoin() < incomeCoin){
throw new ServiceException(""+incomeCoin+"紫贝才可提现");
}
long incs = baseMapper.decrIncomeCoin(userId, incomeCoin);
if(incs <= 0){
boolean incs = baseMapper.decrIncomeCoin(userId, incomeCoin);
if(!incs){
throw new ServiceException(""+incomeCoin+"紫贝才可提现");
}
accountChangeLogService.saveLogNoAdmin(user.getId(),user.getUsercode(), RechargeTypeEnum.COIN_INCOME,AccountBusinessEnum.WITHDRAW.getSourceEnum(),incomeCoin,traceId);

View File

@@ -114,6 +114,7 @@ public class ConsumeLogServiceImpl extends ServiceImpl<ConsumeLogMapper, Consume
consumeLog.setOneAmount(NumCaUtil.coin(consumeLog.getAmount(),consumeLog.getOneRate()));
}
}
consumeLog.setCalculateStatus(true);
return consumeLog;
}
Long targetUserId = consumeLog.getTargetUserId();
@@ -166,6 +167,7 @@ public class ConsumeLogServiceImpl extends ServiceImpl<ConsumeLogMapper, Consume
}
}
}
consumeLog.setCalculateStatus(true);
return consumeLog;
}

View File

@@ -153,11 +153,11 @@ public class RechargeOrderServiceImpl extends ServiceImpl<RechargeOrderMapper,Re
if(account.getCoin() < -dto.getRechargeCoin()){
throw new ServiceException("调整后余额为负数,无法调整");
}
long l = accountMapper.decrCoin(userId, -dto.getRechargeCoin());
accountChangeLogService.saveLogAdmin(user.getId(),user.getUsercode(),RechargeTypeEnum.COIN, AccountChangeEnum.SYSTEM_COIN_DECR,dto.getRechargeCoin(),traceId);
if(l == 0){
throw new ServiceException("调整后余额为负数,无法调整");
boolean l = accountMapper.decrCoin(userId, -dto.getRechargeCoin());
if(!l){
throw new ServiceException("调整后收益为负数,无法调整");
}
accountChangeLogService.saveLogAdmin(user.getId(),user.getUsercode(),RechargeTypeEnum.COIN, AccountChangeEnum.SYSTEM_COIN_DECR,dto.getRechargeCoin(),traceId);
}
}else{
if(dto.getRechargeCoin() > 0){
@@ -167,11 +167,11 @@ public class RechargeOrderServiceImpl extends ServiceImpl<RechargeOrderMapper,Re
if(account.getIncomeCoin() < -dto.getRechargeCoin()){
throw new ServiceException("调整后收益为负数,无法调整");
}
long l = accountMapper.decrIncomeCoin(userId, -dto.getRechargeCoin());
accountChangeLogService.saveLogAdmin(user.getId(),user.getUsercode(),RechargeTypeEnum.COIN_INCOME, AccountChangeEnum.SYSTEM_INCOME_COIN_DECR,dto.getRechargeCoin(),traceId);
if(l == 0){
boolean l = accountMapper.decrIncomeCoin(userId, -dto.getRechargeCoin());
if(!l){
throw new ServiceException("调整后收益为负数,无法调整");
}
accountChangeLogService.saveLogAdmin(user.getId(),user.getUsercode(),RechargeTypeEnum.COIN_INCOME, AccountChangeEnum.SYSTEM_INCOME_COIN_DECR,dto.getRechargeCoin(),traceId);
}
}
return order;

View File

@@ -11,6 +11,7 @@ import com.ruoyi.cai.domain.User;
import com.ruoyi.cai.domain.UserGreet;
import com.ruoyi.cai.dto.admin.vo.UserGreetAdminVo;
import com.ruoyi.cai.dto.app.query.user.UserGreetAddReq;
import com.ruoyi.cai.enums.AuditStatusEnum;
import com.ruoyi.cai.enums.SystemConfigEnum;
import com.ruoyi.cai.manager.LockManager;
import com.ruoyi.cai.manager.SystemConfigManager;
@@ -102,12 +103,12 @@ public class UserGreetServiceImpl extends ServiceImpl<UserGreetMapper,UserGreet>
if(userGreet == null || !userGreet.getUserId().equals(userId)){
throw new ServiceException("请选择打招呼内容");
}
if(userGreet.getAuditStatus() != 1){
if(AuditStatusEnum.SUCCESS.getCode().equals(userGreet.getAuditStatus())){
throw new ServiceException("内容未通过审核");
}
String lockKey = LockManager.getSendGreetLock(userId);
RLock lock = redissonClient.getLock(lockKey);
if(!lock.isLocked()){
if(lock.isLocked()){
throw new ServiceException("操作太频繁");
}
try {
@@ -118,8 +119,8 @@ public class UserGreetServiceImpl extends ServiceImpl<UserGreetMapper,UserGreet>
if(val != null && Long.parseLong(val) > max){
throw new ServiceException("您今天打招呼的次数已经用完了");
}
String sendGreetLock = LockManager.getSendGreetLock(userId);
String lastTime = stringRedisTemplate.opsForValue().getAndExpire(sendGreetLock, 1, TimeUnit.DAYS);
String sendGreetCount = String.format(RedisConstant.USER_GREET_SEND_TIME_REDIS,userId);
String lastTime = stringRedisTemplate.opsForValue().get(sendGreetCount);
if(StringUtils.isNotBlank(lastTime)){
Integer inter = systemConfigManager.getSystemConfigOfInt(SystemConfigEnum.GREET_INTERVAL_MIN);
long jiange = Long.parseLong(lastTime) - DateUtil.currentSeconds();
@@ -140,7 +141,7 @@ public class UserGreetServiceImpl extends ServiceImpl<UserGreetMapper,UserGreet>
if(!r.isSuccess()){
throw new ServiceException("发送失败");
}
stringRedisTemplate.opsForValue().set(sendGreetLock,DateUtil.currentSeconds()+"",1,TimeUnit.DAYS);
stringRedisTemplate.opsForValue().set(sendGreetCount,DateUtil.currentSeconds()+"",1,TimeUnit.DAYS);
stringRedisTemplate.opsForValue().increment(numKey);
stringRedisTemplate.expire(numKey,1,TimeUnit.DAYS);
}finally {

View File

@@ -44,7 +44,7 @@ public class UserInviteServiceImpl extends ServiceImpl<UserInviteMapper, UserInv
InviteCountDTO inviteCount = baseMapper.countInviteAndReward(userId);
vo.setTotalInvite(inviteCount.getTotalInvite());
vo.setTotalReward(inviteCount.getTotalReward());
return null;
return vo;
}
/**

View File

@@ -3,14 +3,17 @@ package com.ruoyi.cai.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.cai.domain.User;
import com.ruoyi.cai.domain.UserVisitor;
import com.ruoyi.cai.dto.app.query.StarOrVisitorReq;
import com.ruoyi.cai.dto.app.query.VisitorQuery;
import com.ruoyi.cai.dto.app.vo.user.UserStarOrVisitorList;
import com.ruoyi.cai.mapper.UserVisitorMapper;
import com.ruoyi.cai.service.UserCountService;
import com.ruoyi.cai.service.UserService;
import com.ruoyi.cai.service.UserVisitorService;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.helper.LoginHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,8 +32,15 @@ import java.time.LocalDateTime;
public class UserVisitorServiceImpl extends ServiceImpl<UserVisitorMapper, UserVisitor> implements UserVisitorService {
@Autowired
private UserCountService userCountService;
@Autowired
private UserService userService;
@Override
public boolean visitor(StarOrVisitorReq starOrVisitorReq) {
User user = userService.getById(starOrVisitorReq.getToUserId());
if(user == null){
log.error("用户不存在");
return false;
}
Long fromUserId = LoginHelper.getUserId();
UserVisitor userVisitor = this.getOne(Wrappers.lambdaQuery(UserVisitor.class)
.eq(UserVisitor::getVisitorId, fromUserId)
@@ -49,6 +59,9 @@ public class UserVisitorServiceImpl extends ServiceImpl<UserVisitorMapper, UserV
@Override
public Page<UserStarOrVisitorList> pageApp(PageQuery pageQuery, VisitorQuery query) {
if(query.getType() == null || (query.getType() != 1 && query.getType() != 2)){
throw new ServiceException("参数异常");
}
query.setUserId(LoginHelper.getUserId());
return baseMapper.pageApp(pageQuery.build(),query);
}

View File

@@ -22,13 +22,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="decrCoin">
update cai_account
set coin = coin - #{coin}
where user_id = #{userId} and (coin - #{coin}) > 0
where user_id = #{userId} and (coin - #{coin}) >= 0
</update>
<update id="decrIncomeCoin">
update cai_account
set income_coin = income_coin - #{incomeCoin}
where user_id = #{userId} and (income_coin - #{incomeCoin}) > 0
where user_id = #{userId} and (income_coin - #{incomeCoin}) >= 0
</update>
<update id="incsIncomeCoin">

View File

@@ -28,7 +28,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by t1.create_time desc
</select>
<select id="pageApp" resultType="com.ruoyi.cai.dto.app.vo.AnchorListVo">
select t1.avatar,t1.gender,t1.city,t1.nickname,t1.usercode,t1.city_id,t1.city,t2.give_score
select t1.id as user_id,t1.avatar,t1.gender,t1.city,t1.nickname,t1.usercode,t1.city_id,t1.city,t2.give_score
from cai_user t1
join cai_anchor t2 on t1.id = t2.user_id
join cai_user_online t3 on t1.id = t3.user_id

View File

@@ -28,7 +28,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and t3.id is not null
</if>
<if test="query.type != null and query.type == 3">
and t1.city_id = #{query.city}
and t1.city_id = #{query.cityId}
</if>
order by t1.create_time desc
</select>

View File

@@ -11,7 +11,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="createTime" column="create_time"/>
</resultMap>
<select id="pageApp" resultType="com.ruoyi.cai.dto.app.vo.user.UserListVo">
select t2.avatar,t2.gender,t2.city,t2.nickname,t2.usercode,t2.age
select t2.id as user_id,t2.avatar,t2.gender,t2.city_id,t2.city,t2.nickname,t2.usercode,t2.age
from cai_user_blacklist t1
join cai_user t2 on t1.user_id = t2.id
where t1.user_id = #{userId}

View File

@@ -17,7 +17,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where invite_id = #{userId}
</select>
<select id="inviteUserPage" resultType="com.ruoyi.cai.dto.app.vo.user.UserListVo">
select t2.avatar,t2.gender,t2.city,t2.nickname,t2.usercode,t2.age, t1.create_time as bind_time
select t1.user_id,t2.avatar,t2.gender,t2.city,t2.nickname,t2.usercode,t2.age, t1.create_time as bind_time
from cai_user_invite t1
join cai_user t2 on t1.user_id = t2.id
where t1.invite_id = #{inviteId}

View File

@@ -19,7 +19,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and t1.mobile = #{query.mobile}
</if>
<if test="query.usercode != null and query.usercode != ''">
and t1.usercode like concat('%',#{query.usercode},'%')
and t1.usercode = #{query.usercode}
</if>
<if test="query.gender != null">
and t1.gender = #{query.gender}
@@ -31,7 +31,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by t2.last_login_time desc
</select>
<select id="pageApp" resultType="com.ruoyi.cai.dto.app.vo.user.UserListVo">
select t1.avatar,t1.gender,t1.city,t1.city_id,t1.nickname,t1.usercode,t1.age,t2.last_live_time
select t1.avatar,t1.id as user_id,t1.gender,t1.city,t1.city_id,t1.nickname,t1.usercode,t1.age,t2.last_live_time as bind_time
from cai_user t1
join cai_user_online t2 on t1.id = t2.user_id
where t1.status = 0
@@ -47,7 +47,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by t2.last_live_time desc
</select>
<select id="greetPageApp" resultType="com.ruoyi.cai.dto.app.vo.user.UserListVo">
select t1.avatar,t1.gender,t1.city,t1.city_id,t1.nickname,t1.usercode,t1.age,t2.last_live_time
select t1.avatar,t1.id as user_id,t1.gender,t1.city,t1.city_id,t1.nickname,t1.usercode,t1.age,t2.last_live_time as bind_time
from cai_user t1
join cai_user_online t2 on t1.id = t2.user_id
where t1.status = 0

View File

@@ -14,7 +14,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="pageApp" resultType="com.ruoyi.cai.dto.app.vo.user.UserStarOrVisitorList">
select
t1.create_time as happen_time,t1.is_watch,
t2.avatar,t2.gender,t2.city,t2.nickname,t2.usercode,t2.age
t2.id as user_id,
t2.avatar,t2.gender,t2.city_id,t2.city,t2.nickname,t2.usercode,t2.age
from cai_user_visitor t1
join cai_user t2 on t1.user_id = t2.id
<where>
@@ -25,7 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and t1.user_id = #{query.userId}
</if>
</where>
order by create_time desc
order by t1.create_time desc
</select>

View File

@@ -151,7 +151,7 @@
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-spring-boot-starter</artifactId>
<version>4.1.0</version>
<version>4.2.0</version>
</dependency>
<!-- 离线IP地址定位库 -->

View File

@@ -30,7 +30,7 @@ public class PageQuery implements Serializable {
* 分页大小
*/
@Schema(description = "分页大小")
private Integer pageSize;
private Integer pageSize = 20;
/**
* 当前页数
@@ -58,7 +58,8 @@ public class PageQuery implements Serializable {
/**
* 每页显示记录数 默认值 默认查全部
*/
public static final int DEFAULT_PAGE_SIZE = Integer.MAX_VALUE;
// public static final int DEFAULT_PAGE_SIZE = Integer.MAX_VALUE;
public static final int DEFAULT_PAGE_SIZE = 20;
public <T> Page<T> build() {
Integer pageNum = ObjectUtil.defaultIfNull(getPageNum(), DEFAULT_PAGE_NUM);

View File

@@ -62,7 +62,7 @@ public class GlobalExceptionHandler {
public R<Void> handleNotLoginException(NotLoginException e, HttpServletRequest request) {
String requestURI = request.getRequestURI();
log.error("请求地址'{}',认证失败'{}',无法访问系统资源", requestURI, e.getMessage());
return R.fail(HttpStatus.HTTP_UNAUTHORIZED, "认证失败,无法访问系统资源");
return R.fail(HttpStatus.HTTP_UNAUTHORIZED, "认证失败,请登录");
}
/**
@@ -147,7 +147,7 @@ public class GlobalExceptionHandler {
public R<Void> handleRuntimeException(RuntimeException e, HttpServletRequest request) {
String requestURI = request.getRequestURI();
log.error("请求地址'{}',发生未知异常.", requestURI, e);
return R.fail(e.getMessage());
return R.fail("系统异常");
}
/**
@@ -157,7 +157,7 @@ public class GlobalExceptionHandler {
public R<Void> handleException(Exception e, HttpServletRequest request) {
String requestURI = request.getRequestURI();
log.error("请求地址'{}',发生系统异常.", requestURI, e);
return R.fail(e.getMessage());
return R.fail("系统异常");
}
/**

View File

@@ -8,7 +8,7 @@ import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "yunxin")
public class YunxinProperties {
private String baseUrl = "https://api.netease.im/nimserver";
private String baseUrl = "https://api.netease.im";
private String appKey;
private String appSecret;

View File

@@ -13,6 +13,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.security.MessageDigest;
@Slf4j
@Component
public class GlodonTokenInterceptor implements Interceptor {
@@ -27,7 +29,7 @@ public class GlodonTokenInterceptor implements Interceptor {
request.addHeader("AppKey",yunxinProperties.getAppKey());
request.addHeader("Nonce", nonce);
request.addHeader("CurTime", curTime);
request.addHeader("CheckSum", yunxinProperties.getAppSecret()+nonce+curTime);
request.addHeader("CheckSum", getCheckSum(yunxinProperties.getAppSecret(),nonce,curTime));
return true;
}
@@ -53,4 +55,36 @@ public class GlodonTokenInterceptor implements Interceptor {
response.getContent());
}
// 计算并获取CheckSum
public static String getCheckSum(String appSecret, String nonce, String curTime) {
return encode("sha1", appSecret + nonce + curTime);
}
private static String encode(String algorithm, String value) {
if (value == null) {
return null;
}
try {
MessageDigest messageDigest
= MessageDigest.getInstance(algorithm);
messageDigest.update(value.getBytes());
return getFormattedText(messageDigest.digest());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static String getFormattedText(byte[] bytes) {
int len = bytes.length;
StringBuilder buf = new StringBuilder(len * 2);
for (int j = 0; j < len; j++) {
buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);
buf.append(HEX_DIGITS[bytes[j] & 0x0f]);
}
return buf.toString();
}
private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
}