nili
7 months ago
7 changed files with 109 additions and 0 deletions
@ -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; |
|||
} |
|||
|
|||
} |
Loading…
Reference in new issue