Browse Source

上报v3

master
nili 7 months ago
parent
commit
256df2df4d
  1. 2
      game-dao/src/main/java/awesome/group/game/dao/bean/MatrixAdvRecord.java
  2. 3
      game-dao/src/main/java/awesome/group/game/dao/bean/MatrixUser.java
  3. 3
      game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixUserMapper.java
  4. 16
      game-service/src/main/java/awesome/group/game/service/bo/matrix/AppNormalConfig.java
  5. 67
      game-service/src/main/java/awesome/group/game/service/citrus/AdvRecordService.java
  6. 4
      game-service/src/main/java/awesome/group/game/service/util/DateUtil.java
  7. 14
      game-web/src/main/java/awesome/group/game/web/rest/citrus/UserController.java

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

@ -16,6 +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 Integer userId;
private String deviceBrand;
private String deviceName;
private String ip;

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

@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import java.sql.Timestamp;
@Data
public class MatrixUser {
@TableId(value = "id", type = IdType.AUTO)
@ -19,4 +21,5 @@ public class MatrixUser {
private String inviteCode;
private Integer upUid;
private Long income;//分,累计收益
private Timestamp createdAt;
}

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

@ -16,6 +16,9 @@ public interface MatrixUserMapper extends BaseMapper<MatrixUser> {
@Update("update matrix_user set money = money + #{cent} where id = #{userId}")
int incMoney(int userId, int cent);
@Update("update matrix_user set income = income + #{ecpmReal} where id = #{userId}")
int incIncome(int userId, long ecpmReal);
@Update("update matrix_user set ali_pay_account = #{aliPayAccount}, name = #{name} where id = #{userId}")
int updateAliPayAccount(int userId, String aliPayAccount, String name);
}

16
game-service/src/main/java/awesome/group/game/service/bo/matrix/AppNormalConfig.java

@ -1,9 +1,12 @@
package awesome.group.game.service.bo.matrix;
import awesome.group.game.dao.bean.MatrixApp;
import awesome.group.game.dao.bean.MatrixUser;
import awesome.group.game.service.bo.citrus.AppCashConfig;
import awesome.group.game.service.util.DateUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.List;
@ -31,4 +34,17 @@ public class AppNormalConfig extends AppCashConfig {
public Integer day;
public Integer rate;
}
public Integer getRate(MatrixUser u) {
if (CollectionUtils.isEmpty(dayRates)) {
return defaultRate;
}
long day = DateUtil.dayCntBetween(u.getCreatedAt().getTime(), System.currentTimeMillis());
for (DayRate dayRate : dayRates) {
if (day <= dayRate.day) {
return dayRate.rate;
}
}
return defaultRate;
}
}

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

@ -0,0 +1,67 @@
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.mapper.MatrixAdvRecordMapper;
import awesome.group.game.dao.mapper.MatrixAppMapper;
import awesome.group.game.dao.mapper.MatrixUserMapper;
import awesome.group.game.service.bo.MatrixAdvRecordEditBo;
import awesome.group.game.service.bo.matrix.AppNormalConfig;
import awesome.group.game.service.common.exception.PaganiException;
import awesome.group.game.service.common.exception.PaganiExceptionCode;
import awesome.group.game.service.common.log.L;
import awesome.group.game.service.util.EncryptUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@Service
public class AdvRecordService {
@Autowired
private MatrixAdvRecordMapper mapper;
@Autowired
private MatrixAppMapper appMapper;
@Autowired
private MatrixUserMapper userMapper;
public long saveRecordV3(Integer uid, MatrixAdvRecordEditBo bo, String ip) {
Assert.isTrue(StringUtils.hasText(bo.appCode) && StringUtils.hasText(bo.sign), "非法请求");
MatrixApp app = appMapper.queryByCode(bo.appCode);
Assert.isTrue(app != null, "非法请求");
String secret = app.getSecret();
String str = bo.getSignStr(secret);
if (!bo.sign.equalsIgnoreCase(EncryptUtil.sha1(str))) {
L.trace("signError", "sign:" + bo.sign + ",str:" + str + ",secret:" + secret);
throw new PaganiException(PaganiExceptionCode.GENERAL_ERROR, "非法请求");
}
long ecpm = bo.advType > 1000 ? 0 : bo.ecpm;
AppNormalConfig config = new AppNormalConfig(app);
MatrixUser u = userMapper.selectById(uid);
Assert.isTrue(u.getAppId().equals(app.getId()), "非法请求");
long ecpmReal = ecpm * config.getRate(u) / 100;
ecpmReal = Math.min(config.maxIncomeEachVideo * 1000L, ecpmReal);
MatrixAdvRecord record = new MatrixAdvRecord();
record.setDeviceId(bo.deviceId);
record.setAppId(u.getAppId());
record.setPlatform(bo.platform);
record.setAdvType(bo.advType);
record.setEcpm(ecpm);
record.setEcpmReal(ecpmReal);
record.setUserId(uid);
record.setDeviceBrand(bo.deviceBrand);
record.setDeviceName(bo.deviceName);
record.setIp(ip);
record.setAdvId(bo.advId);
mapper.insert(record);
userMapper.incIncome(uid, ecpmReal);
return ecpmReal;
}
}

4
game-service/src/main/java/awesome/group/game/service/util/DateUtil.java

@ -119,4 +119,8 @@ public class DateUtil {
return (int) (localDate2.toEpochDay() - localDate1.toEpochDay());
}
public static long dayCntBetween(long timestamp1, long timestamp2) {
return 1 + (timestamp2 - timestamp1) / 86400_000;
}
}

14
game-web/src/main/java/awesome/group/game/web/rest/citrus/UserController.java

@ -1,7 +1,9 @@
package awesome.group.game.web.rest.citrus;
import awesome.group.game.service.bo.MatrixAdvRecordEditBo;
import awesome.group.game.service.bo.citrus.CashRecord;
import awesome.group.game.service.bo.citrus.UserBo;
import awesome.group.game.service.citrus.AdvRecordService;
import awesome.group.game.service.citrus.UserService;
import awesome.group.game.service.common.response.R;
import awesome.group.game.web.RequestContext;
@ -18,6 +20,11 @@ public class UserController {
@Autowired
private UserService userService;
@Autowired
private AdvRecordService advRecordService;
@GetMapping("/current")
@RestApi
public R<UserBo> currentUser() {
@ -43,4 +50,11 @@ public class UserController {
userService.applyMoney(RequestContext.getCitrusUid(), money);
return new R<>(null);
}
@PostMapping("/saveAdvRecordV3")
@RestApi
public R<Long> saveAdvRecordV3(@RequestBody MatrixAdvRecordEditBo bo) {
Long res = advRecordService.saveRecordV3(RequestContext.getCitrusUid(), bo, RequestContext.getIpAddr(RequestContext.getRequest()));
return new R<>(res);
}
}

Loading…
Cancel
Save