Commit b5d443a3 authored by renjie's avatar renjie

admin更新

parent 93e35613
...@@ -10,11 +10,13 @@ public class BillQueryResultDto { ...@@ -10,11 +10,13 @@ public class BillQueryResultDto {
double parentWithdrawn; double parentWithdrawn;
double parentBalanced; double parentBalanced;
double parentBankTransfer; double parentBankTransfer;
double parentBalanceUsed;
double childExpense; double childExpense;
double childWithdraw; double childWithdraw;
double childBalanced; double childBalanced;
double childBankTransfer; double childBankTransfer;
double childBalanceUsed;
public double getParentExpense() { public double getParentExpense() {
return parentExpense; return parentExpense;
...@@ -79,4 +81,20 @@ public class BillQueryResultDto { ...@@ -79,4 +81,20 @@ public class BillQueryResultDto {
public void setChildWithdraw(double childWithdraw) { public void setChildWithdraw(double childWithdraw) {
this.childWithdraw = childWithdraw; this.childWithdraw = childWithdraw;
} }
public double getChildBalanceUsed() {
return childBalanceUsed;
}
public void setChildBalanceUsed(double childBalanceUsed) {
this.childBalanceUsed = childBalanceUsed;
}
public double getParentBalanceUsed() {
return parentBalanceUsed;
}
public void setParentBalanceUsed(double parentBalanceUsed) {
this.parentBalanceUsed = parentBalanceUsed;
}
} }
...@@ -2,6 +2,7 @@ package com.edgec.browserbackend.account.repository; ...@@ -2,6 +2,7 @@ package com.edgec.browserbackend.account.repository;
import com.edgec.browserbackend.account.domain.BillStatus; import com.edgec.browserbackend.account.domain.BillStatus;
import com.edgec.browserbackend.account.domain.UserPrePaidBilling; import com.edgec.browserbackend.account.domain.UserPrePaidBilling;
import org.omg.PortableServer.LIFESPAN_POLICY_ID;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
...@@ -35,6 +36,10 @@ public interface UserPrePaidBillingRepository extends MongoRepository<UserPrePai ...@@ -35,6 +36,10 @@ public interface UserPrePaidBillingRepository extends MongoRepository<UserPrePai
List<UserPrePaidBilling> findByStatus(BillStatus status); List<UserPrePaidBilling> findByStatus(BillStatus status);
List<UserPrePaidBilling> findByUsernameAndPayMethodInAndTimestampGreaterThanAndTimestampLessThan(String username, List<Integer> payMehtods, long time1, long time2);
List<UserPrePaidBilling> findByUsernameAndChargeTypeAndTimestampGreaterThanAndTimestampLessThan(String username, int chargeType, long time1, long time2);
Page<UserPrePaidBilling> findByUsernameAndTimestampGreaterThanOrderByTimestampDesc(String username, long time, Pageable pageable); Page<UserPrePaidBilling> findByUsernameAndTimestampGreaterThanOrderByTimestampDesc(String username, long time, Pageable pageable);
Page<UserPrePaidBilling> findByAdministratorAndTimestampGreaterThanOrderByTimestampDesc(String administrator, long time, Pageable pageable); Page<UserPrePaidBilling> findByAdministratorAndTimestampGreaterThanOrderByTimestampDesc(String administrator, long time, Pageable pageable);
......
...@@ -1199,11 +1199,28 @@ public class AccountServiceImpl implements AccountService { ...@@ -1199,11 +1199,28 @@ public class AccountServiceImpl implements AccountService {
Account account = repository.findByName(username); Account account = repository.findByName(username);
if (account == null) if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST); throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
if (isAgree) if (isAgree) {
account.setAuthorized(2); account.setAuthorized(2);
else repository.save(account);
}
else {
account.setAuthorized(3); account.setAuthorized(3);
repository.save(account); repository.save(account);
CompanyAuthorize companyAuthorize = companyAuthorizeRepository.findByUsername(username);
if (companyAuthorize != null) {
if (companyAuthorize.getCompanyLicenseId() != null)
companyAuthorizeRepository.deleteFile(companyAuthorize.getCompanyLicenseId());
if (companyAuthorize.getCoporationLicenseFront() != null)
companyAuthorizeRepository.deleteFile(companyAuthorize.getCoporationLicenseFront());
if (companyAuthorize.getCoporationLicenseBack() != null)
companyAuthorizeRepository.deleteFile(companyAuthorize.getCoporationLicenseBack());
if (companyAuthorize.getAgencyFront() != null)
companyAuthorizeRepository.deleteFile(companyAuthorize.getAgencyFront());
if (companyAuthorize.getAgencyBack() != null)
companyAuthorizeRepository.deleteFile(companyAuthorize.getAgencyBack());
companyAuthorizeRepository.delete(companyAuthorize);
}
}
return true; return true;
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage()); log.error(e.getMessage());
......
...@@ -11,6 +11,7 @@ import com.edgec.browserbackend.account.service.AdministratorService; ...@@ -11,6 +11,7 @@ import com.edgec.browserbackend.account.service.AdministratorService;
import com.edgec.browserbackend.auth.service.UserAuthService; import com.edgec.browserbackend.auth.service.UserAuthService;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode; import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.browser.repository.IpResourceRepository; import com.edgec.browserbackend.browser.repository.IpResourceRepository;
import com.edgec.browserbackend.common.charge.ChargeType;
import com.edgec.browserbackend.common.commons.error.ClientRequestException; import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -25,6 +26,7 @@ import org.springframework.stereotype.Service; ...@@ -25,6 +26,7 @@ import org.springframework.stereotype.Service;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.YearMonth;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.*; import java.util.*;
...@@ -123,8 +125,11 @@ public class AdministratorServiceImpl implements AdministratorService { ...@@ -123,8 +125,11 @@ public class AdministratorServiceImpl implements AdministratorService {
double parentwithdrawn = account.getPromotion().getWithdrawn(); double parentwithdrawn = account.getPromotion().getWithdrawn();
UserBalance userBalance = userBalanceRepository.findById(name).orElse(null); UserBalance userBalance = userBalanceRepository.findById(name).orElse(null);
double parentbalanced = 0; double parentbalanced = 0;
if (userBalance != null) double parentbalanceused = 0;
if (userBalance != null) {
parentbalanced = userBalance.getBalanced(); parentbalanced = userBalance.getBalanced();
parentbalanceused = userBalance.getUsed();
}
List<UserPrePaidBilling> userPrePaidBillings1 = userPrePaidBillingRepository.findByUsernameAndPayMethod(name, 3); List<UserPrePaidBilling> userPrePaidBillings1 = userPrePaidBillingRepository.findByUsernameAndPayMethod(name, 3);
double parentbanktransfer = 0; double parentbanktransfer = 0;
if (userPrePaidBillings1 != null) if (userPrePaidBillings1 != null)
...@@ -134,6 +139,7 @@ public class AdministratorServiceImpl implements AdministratorService { ...@@ -134,6 +139,7 @@ public class AdministratorServiceImpl implements AdministratorService {
double childwithdrawn = 0; double childwithdrawn = 0;
double childbalanced = 0; double childbalanced = 0;
double childbanktransfer = 0; double childbanktransfer = 0;
double childbalanceused = 0;
if (account.getParent() == null) { if (account.getParent() == null) {
List<Account> children = accountRepository.findByParent(account.getName()); List<Account> children = accountRepository.findByParent(account.getName());
for (Account child : children) { for (Account child : children) {
...@@ -142,8 +148,10 @@ public class AdministratorServiceImpl implements AdministratorService { ...@@ -142,8 +148,10 @@ public class AdministratorServiceImpl implements AdministratorService {
childexpense += userPrePaidBillings_child.stream().mapToDouble(UserPrePaidBilling::getTotal).sum(); childexpense += userPrePaidBillings_child.stream().mapToDouble(UserPrePaidBilling::getTotal).sum();
childwithdrawn += child.getPromotion().getWithdrawn(); childwithdrawn += child.getPromotion().getWithdrawn();
UserBalance userBalance_child = userBalanceRepository.findById(child.getName()).orElse(null); UserBalance userBalance_child = userBalanceRepository.findById(child.getName()).orElse(null);
if (userBalance_child != null) if (userBalance_child != null) {
childbalanced += userBalance_child.getBalanced(); childbalanced += userBalance_child.getBalanced();
childbalanceused += userBalance_child.getUsed();
}
List<UserPrePaidBilling> userPrePaidBillings1_child = userPrePaidBillingRepository.findByUsernameAndPayMethod(child.getName(), 3); List<UserPrePaidBilling> userPrePaidBillings1_child = userPrePaidBillingRepository.findByUsernameAndPayMethod(child.getName(), 3);
if (userPrePaidBillings1_child != null) if (userPrePaidBillings1_child != null)
childbanktransfer += userPrePaidBillings1_child.stream().mapToDouble(UserPrePaidBilling::getTotal).sum(); childbanktransfer += userPrePaidBillings1_child.stream().mapToDouble(UserPrePaidBilling::getTotal).sum();
...@@ -155,11 +163,13 @@ public class AdministratorServiceImpl implements AdministratorService { ...@@ -155,11 +163,13 @@ public class AdministratorServiceImpl implements AdministratorService {
billQueryResultDto.setChildBankTransfer(childbanktransfer); billQueryResultDto.setChildBankTransfer(childbanktransfer);
billQueryResultDto.setChildBalanced(childbalanced); billQueryResultDto.setChildBalanced(childbalanced);
billQueryResultDto.setChildWithdraw(childwithdrawn); billQueryResultDto.setChildWithdraw(childwithdrawn);
billQueryResultDto.setChildBalanceUsed(childbalanceused);
billQueryResultDto.setParentExpense(parentexpense); billQueryResultDto.setParentExpense(parentexpense);
billQueryResultDto.setParentBalanced(parentbalanced); billQueryResultDto.setParentBalanced(parentbalanced);
billQueryResultDto.setParentBankTransfer(parentbanktransfer); billQueryResultDto.setParentBankTransfer(parentbanktransfer);
billQueryResultDto.setParentWithdrawn(parentwithdrawn); billQueryResultDto.setParentWithdrawn(parentwithdrawn);
billQueryResultDto.setParentBalanceUsed(parentbalanceused);
return billQueryResultDto; return billQueryResultDto;
} }
...@@ -392,13 +402,29 @@ public class AdministratorServiceImpl implements AdministratorService { ...@@ -392,13 +402,29 @@ public class AdministratorServiceImpl implements AdministratorService {
List<Account> accounts = accountRepository.findAllBySignupDateBetweenAndPromotionCode(dateTime1, dateTime2, account.getPromotion().getCode()); List<Account> accounts = accountRepository.findAllBySignupDateBetweenAndPromotionCode(dateTime1, dateTime2, account.getPromotion().getCode());
Promotion promotion = new Promotion(); Promotion promotion = new Promotion();
Account finalAccount = account;
accounts.forEach(x -> { accounts.forEach(x -> {
promotion.setInvitedUsers(promotion.getInvitedUsers() + 1); promotion.setInvitedUsers(promotion.getInvitedUsers() + 1);
double totalCommission = userPrePaidBillingRepository.findByUsernameAndPayMethodInAndTimestampGreaterThanAndTimestampLessThan(x.getName(), Arrays.asList(1,2,3), dateTime1.getTime(), dateTime2.getTime())
promotion.setTotalCommission(promotion.getTotalCommission() + x.getPromotion().getTotalCommission()); .stream().mapToDouble(UserPrePaidBilling::getTotal).sum();
promotion.setTotalCommission(promotion.getTotalCommission() + (int)totalCommission);
promotion.setCommission(promotion.getCommission() + x.getPromotion().getCommission()); promotion.setCommission(promotion.getCommission() + x.getPromotion().getCommission());
promotion.setWithdrawn(promotion.getWithdrawn() + x.getPromotion().getWithdrawn()); double totalwithdrawn = userPrePaidBillingRepository.findByUsernameAndChargeTypeAndTimestampGreaterThanAndTimestampLessThan(x.getName(), ChargeType.gift, dateTime1.getTime(), dateTime2.getTime())
promotion.setAllGift(promotion.getAllGift() + x.getPromotion().getAllGift()); .stream().mapToDouble(UserPrePaidBilling::getTotal).sum();
promotion.setWithdrawn(promotion.getWithdrawn() + totalwithdrawn);
double secondCommission = 0;
if (finalAccount.getPromotion().isSale() && x.getParent() == null) {
List<Account> secondPromotes = accountRepository.findByPromotionCode(x.getPromotion().getCode());
if (secondPromotes != null && secondPromotes.size() > 0) {
for (Account secondPromote : secondPromotes) {
List<UserPrePaidBilling> userPrePaidBillings1 = userPrePaidBillingRepository.findByUsernameAndYearAndMonthAndPayMethodIn(secondPromote.getName(),
YearMonth.now().minusMonths(1).getYear(),
YearMonth.now().minusMonths(1).getMonthValue(), Arrays.asList(1,2,3));
secondCommission += userPrePaidBillings1.stream().mapToDouble(UserPrePaidBilling::getTotal).sum();
}
}
}
promotion.setAllGift(promotion.getAllGift() + totalCommission * 0.1 + secondCommission * 0.02);
promotion.setGift(promotion.getGift() + x.getPromotion().getGift()); promotion.setGift(promotion.getGift() + x.getPromotion().getGift());
promotion.setCommissionLastMonth(promotion.getCommissionLastMonth() + x.getPromotion().getCommissionLastMonth()); promotion.setCommissionLastMonth(promotion.getCommissionLastMonth() + x.getPromotion().getCommissionLastMonth());
}); });
......
...@@ -41,15 +41,17 @@ public class PromotionTask { ...@@ -41,15 +41,17 @@ public class PromotionTask {
for (Account promote : promotes) { for (Account promote : promotes) {
List<UserPrePaidBilling> userPrePaidBillings = userPrePaidBillingRepository.findByUsernameAndYearAndMonthAndPayMethodIn(promote.getName(), List<UserPrePaidBilling> userPrePaidBillings = userPrePaidBillingRepository.findByUsernameAndYearAndMonthAndPayMethodIn(promote.getName(),
YearMonth.now().minusMonths(1).getYear(), YearMonth.now().minusMonths(1).getYear(),
YearMonth.now().minusMonths(1).getMonthValue(), Arrays.asList(1,2)); YearMonth.now().minusMonths(1).getMonthValue(), Arrays.asList(1,2,3));
totalCommission += userPrePaidBillings.stream().mapToDouble(UserPrePaidBilling::getTotal).sum(); totalCommission += userPrePaidBillings.stream().mapToDouble(UserPrePaidBilling::getTotal).sum();
if (account.getPromotion().isSale() && promote.getParent() == null) { if (account.getPromotion().isSale() && promote.getParent() == null) {
List<Account> secondPromotes = accountRepository.findByPromotionCode(promote.getPromotion().getCode()); List<Account> secondPromotes = accountRepository.findByPromotionCode(promote.getPromotion().getCode());
if (secondPromotes != null && secondPromotes.size() > 0) {
for (Account secondPromote : secondPromotes) { for (Account secondPromote : secondPromotes) {
List<UserPrePaidBilling> userPrePaidBillings1 = userPrePaidBillingRepository.findByUsernameAndYearAndMonthAndPayMethodIn(promote.getName(), List<UserPrePaidBilling> userPrePaidBillings1 = userPrePaidBillingRepository.findByUsernameAndYearAndMonthAndPayMethodIn(secondPromote.getName(),
YearMonth.now().minusMonths(1).getYear(), YearMonth.now().minusMonths(1).getYear(),
YearMonth.now().minusMonths(1).getMonthValue(), Arrays.asList(1,2,3)); YearMonth.now().minusMonths(1).getMonthValue(), Arrays.asList(1,2,3));
secondCommission += userPrePaidBillings.stream().mapToDouble(UserPrePaidBilling::getTotal).sum(); secondCommission += userPrePaidBillings1.stream().mapToDouble(UserPrePaidBilling::getTotal).sum();
}
} }
} }
} }
...@@ -81,15 +83,22 @@ public class PromotionTask { ...@@ -81,15 +83,22 @@ public class PromotionTask {
totalCommission += userPrePaidBillings.stream().mapToDouble(UserPrePaidBilling::getTotal).sum(); totalCommission += userPrePaidBillings.stream().mapToDouble(UserPrePaidBilling::getTotal).sum();
if (account.getPromotion().isSale() && promote.getParent() == null) { if (account.getPromotion().isSale() && promote.getParent() == null) {
List<Account> secondPromotes = accountRepository.findByPromotionCode(promote.getPromotion().getCode()); List<Account> secondPromotes = accountRepository.findByPromotionCode(promote.getPromotion().getCode());
if (secondPromotes != null && secondPromotes.size() > 0) {
for (Account secondPromote : secondPromotes) { for (Account secondPromote : secondPromotes) {
List<UserPrePaidBilling> userPrePaidBillings1 = userPrePaidBillingRepository.findByUsernameAndYearAndMonthAndPayMethodIn(promote.getName(), List<UserPrePaidBilling> userPrePaidBillings1 = userPrePaidBillingRepository.findByUsernameAndYearAndMonthAndPayMethodIn(secondPromote.getName(),
YearMonth.now().getYear(), YearMonth.now().getYear(),
YearMonth.now().getMonthValue(), Arrays.asList(1,2,3)); YearMonth.now().getMonthValue(), Arrays.asList(1,2,3));
secondCommission += userPrePaidBillings.stream().mapToDouble(UserPrePaidBilling::getTotal).sum(); secondCommission += userPrePaidBillings1.stream().mapToDouble(UserPrePaidBilling::getTotal).sum();
}
}
} }
} }
Promotion promotion = account.getPromotion();
promotion.setCommission((int)totalCommission);
promotion.setGift(totalCommission * 0.08);
if (account.getPromotion().isSale()) {
promotion.setGift(totalCommission * 0.1 + secondCommission * 0.02);
} }
account.getPromotion().setCommission((int)totalCommission);
accountRepository.save(account); 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