Browse Source

代理部分功能

master
nili 6 months ago
parent
commit
1b3905ab59
  1. 1
      game-dao/src/main/java/awesome/group/game/dao/bean/MatrixAdmin.java
  2. 3
      game-dao/src/main/java/awesome/group/game/dao/bean/MatrixAdvRecord.java
  3. 1
      game-dao/src/main/java/awesome/group/game/dao/bean/MatrixUser.java
  4. 3
      game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixAdminMapper.java
  5. 12
      game-service/src/main/java/awesome/group/game/service/MatrixService.java
  6. 2
      game-service/src/main/java/awesome/group/game/service/bo/MatrixAdminBo.java
  7. 22
      game-service/src/main/java/awesome/group/game/service/citrus/AdvRecordService.java
  8. 2
      game-service/src/main/java/awesome/group/game/service/citrus/UserService.java
  9. 43
      game-service/src/main/java/awesome/group/game/service/matrix/AdminService.java
  10. 9
      game-service/src/main/java/awesome/group/game/service/matrix/MatrixUserService.java
  11. 19
      game-web/src/main/java/awesome/group/game/web/rest/matrix/AdminController.java
  12. 7
      game-web/src/main/java/awesome/group/game/web/rest/matrix/MatrixUserController.java

1
game-dao/src/main/java/awesome/group/game/dao/bean/MatrixAdmin.java

@ -15,6 +15,7 @@ public class MatrixAdmin {
private String channel;//fanmiyou,qiji
private Integer parentAdminId;
private Integer deviceCnt;
private String userIds;//绑定代理账号的用户id
private Integer incomeRate;
private Integer hide;
}

3
game-dao/src/main/java/awesome/group/game/dao/bean/MatrixAdvRecord.java

@ -16,7 +16,8 @@ public class MatrixAdvRecord {
private Integer platform;//1穿山甲,2腾讯,3百度联盟,4 Mintegral,5 快手,6游可赢,7 Sigmob,8 Admob
private Integer advType;//1横幅,2插页,3激励视频
private Long ecpm;//单位:分
private Long ecpmReal;
private Long ecpmReal;//用户金币,即被抽成后的数据
private Long ecpmAdmin;//抽成后代理的钱
private Integer userId;
private String deviceBrand;
private String deviceName;

1
game-dao/src/main/java/awesome/group/game/dao/bean/MatrixUser.java

@ -22,6 +22,7 @@ public class MatrixUser {
private String pwd;
private String inviteCode;
private Integer upUid;
private Integer adminId;//代理id
private Long income;//分,累计收益
private Long contributeIncome;//贡献给上级的收益,分,ecpm
private Integer env;//用户设备环境检测

3
game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixAdminMapper.java

@ -14,4 +14,7 @@ public interface MatrixAdminMapper extends BaseMapper<MatrixAdmin> {
@Update("update matrix_admin set hide = #{hide} where id = #{id}")
int updateHide(Integer id, Integer hide);
@Update("update matrix_admin set user_ids = #{str} where id = #{id}")
int updateUids(Integer id, String str);
}

12
game-service/src/main/java/awesome/group/game/service/MatrixService.java

@ -1,13 +1,16 @@
package awesome.group.game.service;
import awesome.group.game.dao.bean.MatrixAdmin;
import awesome.group.game.dao.bean.MatrixAdvRecord;
import awesome.group.game.dao.bean.MatrixApp;
import awesome.group.game.dao.mapper.MatrixAdminMapper;
import awesome.group.game.dao.mapper.MatrixAdvRecordMapper;
import awesome.group.game.dao.mapper.MatrixAppMapper;
import awesome.group.game.service.bo.MatrixAdvRecordEditBo;
import awesome.group.game.service.bo.MatrixAdvRecordSimple;
import awesome.group.game.service.common.log.L;
import awesome.group.game.service.matrix.AdminDeviceService;
import awesome.group.game.service.util.Constants;
import awesome.group.game.service.util.EncryptUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -34,6 +37,9 @@ public class MatrixService {
@Resource
private AdminDeviceService adminDeviceService;
@Resource
private MatrixAdminMapper adminMapper;
public void saveRecord(MatrixAdvRecordEditBo bo, String ip) {
Assert.isTrue(StringUtils.hasText(bo.appCode), "appCode不能为空");
MatrixApp app = mapper.queryApp(bo.appCode);
@ -54,6 +60,12 @@ public class MatrixService {
Integer adminId = adminDeviceService.getAdminId(bo.deviceId);
record.setAdminId(adminId);
if (bo.advType == Constants.VIDEO && adminId != null) {
MatrixAdmin admin = adminMapper.selectById(adminId);
if (admin.getIncomeRate() != null ) {
record.setEcpmAdmin(bo.ecpm * admin.getIncomeRate() / 100);
}
}
mapper.insert(record);
}

2
game-service/src/main/java/awesome/group/game/service/bo/MatrixAdminBo.java

@ -15,7 +15,7 @@ public class MatrixAdminBo {
public String password;
public List<Integer> appIds;
public Integer hide;
public Integer role;//1超级管理员,2管理员,3普通账号
public Integer role;//1超级管理员,2管理员,3游戏主,4设备主,5代理
public Integer deviceCnt;
public Integer incomeRate;
public OverviewBo overview;

22
game-service/src/main/java/awesome/group/game/service/citrus/AdvRecordService.java

@ -1,13 +1,7 @@
package awesome.group.game.service.citrus;
import awesome.group.game.dao.bean.MatrixAdvRecord;
import awesome.group.game.dao.bean.MatrixApp;
import awesome.group.game.dao.bean.MatrixUser;
import awesome.group.game.dao.bean.MatrixWhiteUser;
import awesome.group.game.dao.mapper.MatrixAdvRecordMapper;
import awesome.group.game.dao.mapper.MatrixAppMapper;
import awesome.group.game.dao.mapper.MatrixUserMapper;
import awesome.group.game.dao.mapper.MatrixWhiteUserMapper;
import awesome.group.game.dao.bean.*;
import awesome.group.game.dao.mapper.*;
import awesome.group.game.service.bo.MatrixAdvRecordEditBo;
import awesome.group.game.service.bo.citrus.AdvResponse;
import awesome.group.game.service.bo.matrix.AppNormalConfig;
@ -37,6 +31,9 @@ public class AdvRecordService {
@Autowired
private MatrixWhiteUserMapper whiteUserMapper;
@Autowired
private MatrixAdminMapper adminMapper;
public AdvResponse saveRecordV3(Integer uid, MatrixAdvRecordEditBo bo, String ip) {
Assert.isTrue((System.currentTimeMillis() / 1000) - bo.timestamp < 30, "非法请求");
Assert.isTrue(StringUtils.hasText(bo.appCode) && StringUtils.hasText(bo.sign), "非法请求");
@ -63,7 +60,7 @@ public class AdvRecordService {
long ecpmReal = ecpm * config.getRate(u) / 100;
ecpmReal = Math.min(config.maxIncomeEachVideo * 1000L, ecpmReal);
long contribute = 0;
if (bo.advType != 3) {
if (bo.advType != Constants.VIDEO) {
ecpmReal = 0; //只有激励视频算钱
}
if (u.getUpUid() != null) {
@ -83,6 +80,13 @@ public class AdvRecordService {
record.setDeviceName(bo.deviceName);
record.setIp(ip);
record.setAdvId(bo.advId);
if (bo.advType == Constants.VIDEO && u.getAdminId() != null) {
long gap = ecpm - ecpmReal - contribute;
MatrixAdmin admin = adminMapper.selectById(u.getAdminId());
if (admin.getIncomeRate() != null) {
record.setEcpmAdmin(gap * admin.getIncomeRate() / 100);
}
}
mapper.insert(record);
if (ecpmReal > 0) {

2
game-service/src/main/java/awesome/group/game/service/citrus/UserService.java

@ -124,6 +124,7 @@ public class UserService {
user.setAppId(app.getId());
user.setMobile(mobile);
user.setUpUid(upUser == null ? null : upUser.getId());
user.setAdminId(upUser != null ? upUser.getAdminId() : null);
user.setInviteCode(RandomStringUtils.randomAlphabetic(12));
userMapper.insert(user);
}
@ -152,6 +153,7 @@ public class UserService {
user.setNickname(info.nickname);
user.setAvatar(info.headimgurl);
user.setUpUid(upUser == null ? null : upUser.getId());
user.setAdminId(upUser != null ? upUser.getAdminId() : null);
user.setInviteCode(RandomStringUtils.randomAlphabetic(12));
userMapper.insert(user);
} else {

43
game-service/src/main/java/awesome/group/game/service/matrix/AdminService.java

@ -3,6 +3,7 @@ package awesome.group.game.service.matrix;
import awesome.group.game.dao.bean.*;
import awesome.group.game.dao.mapper.*;
import awesome.group.game.service.bo.*;
import awesome.group.game.service.bo.citrus.UserBo;
import awesome.group.game.service.bo.matrix.MatrixAppBo;
import awesome.group.game.service.common.exception.PaganiException;
import awesome.group.game.service.common.exception.PaganiExceptionCode;
@ -16,6 +17,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -73,8 +76,9 @@ public class AdminService {
public static final int SUPER_ADMIN = 1;//超级管理员
public static final int NORMAL_ADMIN = 2;//普通管理员
public static final int OTHER = 3;//普通账号
public static final int OTHER = 3;//普通账号,游戏主
public static final int DEVICE_OWNER = 4; //设备主
public static final int PROXY = 5; //代理
public MatrixAdmin login(String name, String pwd, String channel) {
MatrixAdmin admin = adminMapper.query(name);
@ -119,7 +123,7 @@ public class AdminService {
if (StringUtils.hasText(param.deviceId)) {
wrapper.eq("device_id", param.deviceId);
}
if(param.userId != null) {
if (param.userId != null) {
wrapper.eq("user_id", param.userId);
}
if (!CollectionUtils.isEmpty(param.createdAt)) {
@ -212,6 +216,41 @@ public class AdminService {
return data;
}
public List<UserBo> getGrantUser(Integer adminId) {
MatrixAdmin admin = adminMapper.selectById(adminId);
if (!StringUtils.hasText(admin.getUserIds())) {
return null;
}
Gson gson = new Gson();
List<Integer> uids = gson.fromJson(admin.getUserIds(), new TypeToken<List<Integer>>() {
}.getType());
if (CollectionUtils.isEmpty(uids)) {
return null;
}
List<MatrixUser> list = userMapper.selectBatchIds(uids);
return list.stream().map(x -> new UserBo(x, true)).toList();
}
public void saveGrantUser(Integer adminId, List<Integer> userIds) {
if (CollectionUtils.isEmpty(userIds)) {
return;
}
List<Integer> appIds = getAdminAppIds(adminId);
List<MatrixUser> users = userMapper.selectBatchIds(userIds);
for (MatrixUser u : users) {
if (!appIds.contains(u.getAppId())) {
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "非法请求,有应用未授权");
}
}
Gson gson = new Gson();
adminMapper.updateUids(adminId, gson.toJson(userIds));
MatrixUser update = new MatrixUser();
update.setAdminId(adminId);
LambdaQueryWrapper<MatrixUser> query = Wrappers.lambdaQuery();
query.in(MatrixUser::getId, userIds);
userMapper.update(update, query);
}
public void saveAdmin(int adminId, MatrixAdminBo bo, String channel) {
MatrixAdmin admin = new MatrixAdmin();
BeanUtils.copyProperties(bo, admin);

9
game-service/src/main/java/awesome/group/game/service/matrix/MatrixUserService.java

@ -48,6 +48,15 @@ public class MatrixUserService {
return res;
}
public UserBo getUser(Integer adminId, Integer userId) {
MatrixUser u = userMapper.selectById(userId);
List<Integer> appIds = adminService.getAdminAppIds(adminId);
if (u == null || !appIds.contains(u.getAppId())) {
return null;
}
return new UserBo(u, true);
}
public Map<Integer, MatrixUser> getUser(List<Integer> uidList) {
if (CollectionUtils.isEmpty(uidList)) {
return new HashMap<>();

19
game-web/src/main/java/awesome/group/game/web/rest/matrix/AdminController.java

@ -4,16 +4,16 @@ import awesome.group.game.dao.bean.MatrixAdmin;
import awesome.group.game.dao.bean.MatrixApp;
import awesome.group.game.dao.bean.MatrixMockSchedule;
import awesome.group.game.dao.bean.MatrixWhiteDevice;
import awesome.group.game.service.matrix.AdminService;
import awesome.group.game.service.MatrixService;
import awesome.group.game.service.matrix.OSSService;
import awesome.group.game.service.bo.*;
import awesome.group.game.service.bo.citrus.UserBo;
import awesome.group.game.service.bo.matrix.MatrixAppBo;
import awesome.group.game.service.common.response.R;
import awesome.group.game.service.matrix.AdminService;
import awesome.group.game.service.matrix.OSSService;
import awesome.group.game.service.util.JwtUtils;
import awesome.group.game.web.RequestContext;
import awesome.group.game.web.aop.RestApi;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.Cookie;
@ -87,6 +87,19 @@ public class AdminController {
return new R<>(R.CODE_SUCCESS, "ok", null);
}
@GetMapping("/grantUser")
@RestApi
public R<List<UserBo>> getGrantUser(@RequestParam Integer adminId) {
return new R<>(adminService.getGrantUser(adminId));
}
@PostMapping("/grantUser")
@RestApi
public R<Void> saveGrantUser(@RequestParam Integer adminId, @RequestBody List<Integer> uids) {
adminService.saveGrantUser(adminId, uids);
return new R<>(null);
}
@PostMapping("/changeAdminHide")
@RestApi
public R<Void> changeAdminHide(@RequestParam Integer adminId, @RequestParam Integer hide) {

7
game-web/src/main/java/awesome/group/game/web/rest/matrix/MatrixUserController.java

@ -7,7 +7,6 @@ import awesome.group.game.service.common.response.R;
import awesome.group.game.service.matrix.MatrixUserService;
import awesome.group.game.web.RequestContext;
import awesome.group.game.web.aop.RestApi;
import io.swagger.v3.oas.annotations.Hidden;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -30,4 +29,10 @@ public class MatrixUserController {
userService.changeStatus(RequestContext.getAdminID(), userId, status);
return new R<>(null);
}
@GetMapping("/queryById")
@RestApi
public R<UserBo> queryById(@RequestParam Integer adminId, @RequestParam Integer userId) {
return new R<>(userService.getUser(adminId, userId));
}
}

Loading…
Cancel
Save