Commit 1939c414 authored by renjie's avatar renjie

admin接口

parent 4cdeb0e2
......@@ -369,7 +369,25 @@ public class AdministratorController {
return resultDto;
}
//添加推广码
//添加白名单
@PreAuthorize(Securitys.ADMIN_EL)
@RequestMapping(path = "/0xadministrator/whitelist/add", method = RequestMethod.PUT)
public ResultDto addWhiteList(Principal principal, @RequestParam("website") String website) {
ResultDto resultDto = new ResultDto();
try {
administratorService.addWhiteList(website);
resultDto.setStatus(0);
}catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
//统计ip数量
@PreAuthorize(Securitys.ADMIN_EL)
@RequestMapping(path = "/0xadministrator/ip/count", method = RequestMethod.GET)
public ResultDto getIpCount(Principal principal, @RequestParam(value = "username", defaultValue = "") String username) {
......
......@@ -11,6 +11,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
public class Promotion {
private String code;
private int invitedUsers;
//好友总消费
private int totalCommission;
//好友当月消费
private int commission;
//好友上月总消费
......@@ -85,4 +87,12 @@ public class Promotion {
public void setWithdrawn(double withdrawn) {
this.withdrawn = withdrawn;
}
public int getTotalCommission() {
return totalCommission;
}
public void setTotalCommission(int totalCommission) {
this.totalCommission = totalCommission;
}
}
......@@ -8,6 +8,7 @@ import com.edgec.browserbackend.browser.dto.IpResourceDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.HashMap;
import java.util.List;
public interface AdministratorService {
......@@ -54,4 +55,8 @@ public interface AdministratorService {
void addPromotionCode(String username, String promotionCode);
IpCountQueryResultDto queyrIpCount(String username);
HashMap queryGift(String username);
void addWhiteList(String website);
}
......@@ -402,7 +402,7 @@ public class AccountServiceImpl implements AccountService {
for (Account promote : promotes) {
List<UserPrePaidBilling> userPrePaidBillings = prePaidBillingRepository.findByUsernameAndYearAndMonthAndPayMethodIn(promote.getName(),
YearMonth.now().getYear(),
YearMonth.now().getMonthValue(), Arrays.asList(1,2));
YearMonth.now().getMonthValue(), Arrays.asList(1,2,3));
totalCommission += userPrePaidBillings.stream().mapToDouble(UserPrePaidBilling::getTotal).sum();
}
......
......@@ -55,6 +55,9 @@ public class AdministratorServiceImpl implements AdministratorService {
@Autowired
private IpResourceRepository ipResourceRepository;
@Autowired
private WhiteSiteRepository whiteSiteRepository;
@Override
public Administrator createAdministrator(Administrator administrator) {
Administrator administrator1 = new Administrator();
......@@ -358,6 +361,18 @@ public class AdministratorServiceImpl implements AdministratorService {
}
return ipCountQueryResultDto;
}
@Override
public HashMap queryGift(String username) {
return null;
}
@Override
public void addWhiteList(String website) {
WhiteSite whiteSite = new WhiteSite();
whiteSite.setWhite(website);
whiteSiteRepository.save(whiteSite);
}
}
......
......@@ -102,6 +102,8 @@ public class PaymentServiceImpl implements PaymentService {
try {
UserPayment byTradeNo = userPaymentRepository.findByTradeNo(tradeno);
if (byTradeNo == null)
return result;
if (PaymentMethod.ALIPAY.equals(byTradeNo.getPaymentMethod()))
return aliCheckOrderStatus(tradeno, chargeType);
......@@ -203,6 +205,15 @@ public class PaymentServiceImpl implements PaymentService {
balance.setBalanced(balance.getBalanced() + byTradeNo.getAmount() + payBack.getBack());
userBalanceRepository.save(balance);
if (byName.getPromotionCode() != null) {
Account account = accountRepository.findByPromotion(byName.getPromotionCode());
if (account != null) {
byName.getPromotion().setCommission(byName.getPromotion().getCommission() + byTradeNo.getAmount());
accountRepository.save(byName);
}
}
}
result.setBalance(Math.round(balance.getBalanced()));
......@@ -326,6 +337,14 @@ public class PaymentServiceImpl implements PaymentService {
balance.setBalanced(balance.getBalanced() + byTradeNo.getAmount() + payBack.getBack());
userBalanceRepository.save(balance);
if (byName.getPromotionCode() != null) {
Account account = accountRepository.findByPromotion(byName.getPromotionCode());
if (account != null) {
byName.getPromotion().setCommission(byName.getPromotion().getCommission() + byTradeNo.getAmount());
accountRepository.save(byName);
}
}
}
result.setBalance(Math.round(balance.getBalanced()));
......
......@@ -31,7 +31,7 @@ public class PromotionTask {
@SchedulerLock(name = "transferExpiredScalingGroups", lockAtLeastForString = "PT1H", lockAtMostForString = "PT2H")
@Scheduled(cron = "0 0 1 1 * ?")
public void countCommission() {
public void countGift() {
List<Account> accounts = accountRepository.findByParentIsNull();
for (Account account : accounts) {
String code = account.getPromotion().getCode();
......@@ -48,12 +48,13 @@ public class PromotionTask {
for (Account secondPromote : secondPromotes) {
List<UserPrePaidBilling> userPrePaidBillings1 = userPrePaidBillingRepository.findByUsernameAndYearAndMonthAndPayMethodIn(promote.getName(),
YearMonth.now().minusMonths(1).getYear(),
YearMonth.now().minusMonths(1).getMonthValue(), Arrays.asList(1,2));
YearMonth.now().minusMonths(1).getMonthValue(), Arrays.asList(1,2,3));
secondCommission += userPrePaidBillings.stream().mapToDouble(UserPrePaidBilling::getTotal).sum();
}
}
}
Promotion promotion = account.getPromotion();
promotion.setTotalCommission((int)(promotion.getTotalCommission() + totalCommission));
promotion.setCommissionLastMonth((int)totalCommission);
promotion.setGift(totalCommission * 0.08);
if (account.getPromotion().isSale()) {
......@@ -63,4 +64,33 @@ public class PromotionTask {
accountRepository.save(account);
}
}
@SchedulerLock(name = "transferExpiredScalingGroups", lockAtLeastForString = "PT1H", lockAtMostForString = "PT2H")
@Scheduled(cron = "0 0 1 * * ?")
public void countCommission() {
List<Account> accounts = accountRepository.findByParentIsNull();
for (Account account : accounts) {
String code = account.getPromotion().getCode();
List<Account> promotes = accountRepository.findByPromotionCode(code);
double totalCommission = 0;
double secondCommission = 0;
for (Account promote : promotes) {
List<UserPrePaidBilling> userPrePaidBillings = userPrePaidBillingRepository.findByUsernameAndYearAndMonthAndPayMethodIn(promote.getName(),
YearMonth.now().getYear(),
YearMonth.now().getMonthValue(), Arrays.asList(1,2,3));
totalCommission += userPrePaidBillings.stream().mapToDouble(UserPrePaidBilling::getTotal).sum();
if (account.getPromotion().isSale() && promote.getParent() == null) {
List<Account> secondPromotes = accountRepository.findByPromotionCode(promote.getPromotion().getCode());
for (Account secondPromote : secondPromotes) {
List<UserPrePaidBilling> userPrePaidBillings1 = userPrePaidBillingRepository.findByUsernameAndYearAndMonthAndPayMethodIn(promote.getName(),
YearMonth.now().getYear(),
YearMonth.now().getMonthValue(), Arrays.asList(1,2,3));
secondCommission += userPrePaidBillings.stream().mapToDouble(UserPrePaidBilling::getTotal).sum();
}
}
}
account.getPromotion().setCommission((int)totalCommission);
accountRepository.save(account);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment