|
|
|
@ -2,14 +2,17 @@ package com.bnyer.img.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.bnyer.common.core.utils.StringUtils; |
|
|
|
import com.bnyer.common.redis.service.RedisService; |
|
|
|
import com.bnyer.img.constants.ProfitOrderConstant; |
|
|
|
import com.bnyer.img.constants.RedisKeyConstant; |
|
|
|
import com.bnyer.img.domain.CreatorProfit; |
|
|
|
import com.bnyer.img.domain.ProfitVerifyOrder; |
|
|
|
import com.bnyer.img.dto.ProfitVerifyOrderDto; |
|
|
|
import com.bnyer.img.dto.ProfitVerifyOrderInsertDto; |
|
|
|
import com.bnyer.img.dto.ProfitVerifyOrderPageDto; |
|
|
|
import com.bnyer.img.dto.ProfitVerifyOrderUpdateDto; |
|
|
|
import com.bnyer.img.mapper.ProfitVerifyOrderMapper; |
|
|
|
import com.bnyer.img.service.CreatorProfitService; |
|
|
|
import com.bnyer.img.service.ProfitVerifyOrderService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
@ -28,6 +31,12 @@ public class ProfitVerifyOrderServiceImpl implements ProfitVerifyOrderService { |
|
|
|
@Autowired |
|
|
|
private ProfitVerifyOrderMapper profitVerifyOrderMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RedisService redisService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CreatorProfitService creatorProfitService; |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public int insert(ProfitVerifyOrderInsertDto params) { |
|
|
|
@ -84,18 +93,81 @@ public class ProfitVerifyOrderServiceImpl implements ProfitVerifyOrderService { |
|
|
|
public boolean verify(ProfitVerifyOrderDto params) { |
|
|
|
if(params.getVerifyStatus().equals(ProfitOrderConstant.PASS)){ |
|
|
|
//审核通过计算收益
|
|
|
|
//昨日总收益的80%
|
|
|
|
BigDecimal yesterdayTotalProfit = params.getAmt().multiply(BigDecimal.valueOf(0.8)); |
|
|
|
//昨日总收益的80%作为广告收益
|
|
|
|
BigDecimal yesterdayTotalAdProfit = params.getAmt().multiply(BigDecimal.valueOf(0.8)); |
|
|
|
//昨日总收益的10%作为邀请收益
|
|
|
|
BigDecimal yesterdayTotalInviteProfit = params.getAmt().multiply(BigDecimal.valueOf(0.1)); |
|
|
|
//获取昨日日期
|
|
|
|
Date today = new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24); |
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
String date = simpleDateFormat.format(today); |
|
|
|
String tiktokKey = RedisKeyConstant.TIKTOK_IMG_TOTAL_DOWNLOAD_NUM_KEY + date; |
|
|
|
String hashKey = params.getAppType()+":"+ params.getPlatform(); |
|
|
|
if(params.getPlatform().equals(ProfitOrderConstant.TIKTOK) && params.getAppType().equals(ProfitOrderConstant.BNYER_IMG)){ |
|
|
|
//昨日抖音平台总下载量
|
|
|
|
//获取昨日日期
|
|
|
|
Date today = new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24); |
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
String date = simpleDateFormat.format(today); |
|
|
|
String tiktokKey = RedisKeyConstant.TIKTOK_IMG_TOTAL_DOWNLOAD_NUM_KEY + date; |
|
|
|
if(redisService.hasHashKey(tiktokKey, hashKey)){ |
|
|
|
//存在昨日平台下载数量
|
|
|
|
Integer platformDownloadNum = (Integer) redisService.getCacheMapValue(tiktokKey, hashKey); |
|
|
|
//广告单价
|
|
|
|
BigDecimal adPrice = yesterdayTotalAdProfit.divide(BigDecimal.valueOf(platformDownloadNum), 3, BigDecimal.ROUND_DOWN); |
|
|
|
//邀请单价
|
|
|
|
BigDecimal invitePrice = yesterdayTotalInviteProfit.divide(BigDecimal.valueOf(platformDownloadNum), 3, BigDecimal.ROUND_DOWN); |
|
|
|
//查出昨日对应平台的所有广告待入账信息
|
|
|
|
List<CreatorProfit> adProfits = creatorProfitService.queryPreProfit(params.getPlatform(), params.getAppType(), "0"); |
|
|
|
if(adProfits.size() > 0){ |
|
|
|
for (CreatorProfit adProfit : adProfits) { |
|
|
|
//设置广告收益
|
|
|
|
adProfit.setProfit(BigDecimal.valueOf(adProfit.getDownloadNum()).multiply(adPrice)); |
|
|
|
adProfit.setConfirmStatus("0"); |
|
|
|
adProfit.setIncomeTime(new Date()); |
|
|
|
adProfit.setUpdateTime(new Date()); |
|
|
|
} |
|
|
|
} |
|
|
|
//查出昨日对应平台的所有邀请待入账信息
|
|
|
|
List<CreatorProfit> inviteProfits = creatorProfitService.queryPreProfit(params.getPlatform(), params.getAppType(), "1"); |
|
|
|
if(inviteProfits.size() > 0){ |
|
|
|
//设置邀请收益
|
|
|
|
for (CreatorProfit inviteProfit : inviteProfits) { |
|
|
|
inviteProfit.setProfit(BigDecimal.valueOf(inviteProfit.getDownloadNum()).multiply(invitePrice)); |
|
|
|
inviteProfit.setConfirmStatus("0"); |
|
|
|
inviteProfit.setIncomeTime(new Date()); |
|
|
|
inviteProfit.setUpdateTime(new Date()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}else if(params.getPlatform().equals(ProfitOrderConstant.FAST_HAND) && params.getAppType().equals(ProfitOrderConstant.BNYER_IMG)){ |
|
|
|
//昨日快手平台总下载量
|
|
|
|
if(redisService.hasHashKey(tiktokKey, hashKey)){ |
|
|
|
//存在昨日平台下载数量
|
|
|
|
Integer platformDownloadNum = (Integer) redisService.getCacheMapValue(tiktokKey, hashKey); |
|
|
|
//广告单价
|
|
|
|
BigDecimal adPrice = yesterdayTotalAdProfit.divide(BigDecimal.valueOf(platformDownloadNum), 3, BigDecimal.ROUND_DOWN); |
|
|
|
//邀请单价
|
|
|
|
BigDecimal invitePrice = yesterdayTotalInviteProfit.divide(BigDecimal.valueOf(platformDownloadNum), 3, BigDecimal.ROUND_DOWN); |
|
|
|
//查出昨日对应平台的所有广告待入账信息
|
|
|
|
List<CreatorProfit> adProfits = creatorProfitService.queryPreProfit(params.getPlatform(), params.getAppType(), "0"); |
|
|
|
if(adProfits.size() > 0){ |
|
|
|
for (CreatorProfit adProfit : adProfits) { |
|
|
|
//设置广告收益
|
|
|
|
adProfit.setProfit(BigDecimal.valueOf(adProfit.getDownloadNum()).multiply(adPrice)); |
|
|
|
adProfit.setConfirmStatus("0"); |
|
|
|
adProfit.setIncomeTime(new Date()); |
|
|
|
adProfit.setUpdateTime(new Date()); |
|
|
|
} |
|
|
|
} |
|
|
|
//查出昨日对应平台的所有邀请待入账信息
|
|
|
|
List<CreatorProfit> inviteProfits = creatorProfitService.queryPreProfit(params.getPlatform(), params.getAppType(), "1"); |
|
|
|
if(inviteProfits.size() > 0){ |
|
|
|
//设置邀请收益
|
|
|
|
for (CreatorProfit inviteProfit : inviteProfits) { |
|
|
|
inviteProfit.setProfit(BigDecimal.valueOf(inviteProfit.getDownloadNum()).multiply(invitePrice)); |
|
|
|
inviteProfit.setConfirmStatus("0"); |
|
|
|
inviteProfit.setIncomeTime(new Date()); |
|
|
|
inviteProfit.setUpdateTime(new Date()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//TODO 待补充完善结算方法
|
|
|
|
}else{ |
|
|
|
//审核不通过,流程结束
|
|
|
|
} |
|
|
|
|