Commit 7b3cdbd9 authored by renjie's avatar renjie

推广礼金

parent f08caa40
......@@ -48,6 +48,8 @@ public class Account {
private Promotion promotion;
private String promotionCode;
private String comment;
private List<String> whiteList = new ArrayList<>();
......@@ -275,4 +277,12 @@ public class Account {
public void setPassword(String password) {
this.password = password;
}
public String getPromotionCode() {
return promotionCode;
}
public void setPromotionCode(String promotionCode) {
this.promotionCode = promotionCode;
}
}
......@@ -6,7 +6,7 @@ package com.edgec.browserbackend.account.domain;
* @CreateTime 2020/3/12 3:14 下午
**/
public class Promotion {
private String link;
private String code;
private int invitedUsers;
private int commission;
......@@ -26,11 +26,11 @@ public class Promotion {
this.invitedUsers = invitedUsers;
}
public String getLink() {
return link;
public String getCode() {
return code;
}
public void setLink(String link) {
this.link = link;
public void setCode(String code) {
this.code = code;
}
}
......@@ -22,6 +22,8 @@ public class User {
private String authCode;
private String promotionCode;
private boolean enabled = false;
private String lockReason;
......@@ -122,4 +124,12 @@ public class User {
public void setWhiteList(List<String> whiteList) {
this.whiteList = whiteList;
}
public String getPromotionCode() {
return promotionCode;
}
public void setPromotionCode(String promotionCode) {
this.promotionCode = promotionCode;
}
}
package com.edgec.browserbackend.account.domain;
import com.edgec.browserbackend.account.service.SmsUtils;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.text.SimpleDateFormat;
import java.util.Date;
@Document(collection = "userwithdraw")
public class UserWithdraw {
@Id
private String id;
private String tradeNo = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())+ SmsUtils.createRandom(true, 4);
private String username;
private int amount;
private boolean succeed;
private Date withdrawDate = new Date();
private PaymentMethod withdrawMethod;
private String transId;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTradeNo() {
return tradeNo;
}
public void setTradeNo(String tradeNo) {
this.tradeNo = tradeNo;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
public boolean isSucceed() {
return succeed;
}
public void setSucceed(boolean succeed) {
this.succeed = succeed;
}
public Date getWithdrawDate() {
return withdrawDate;
}
public void setWithdrawDate(Date withdrawDate) {
this.withdrawDate = withdrawDate;
}
public PaymentMethod getWithdrawMethod() {
return withdrawMethod;
}
public void setWithdrawMethod(PaymentMethod withdrawMethod) {
this.withdrawMethod = withdrawMethod;
}
public String getTransId() {
return transId;
}
public void setTransId(String transId) {
this.transId = transId;
}
}
......@@ -20,6 +20,8 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc
List<Account> findByParent(String parent);
List<Account> findByParentIsNull();
Page<Account> findByParent(String parent, Pageable pageable);
Page<Account> findAllBySignupDateBetween(Pageable pageable, Date startDate, Date endDate);
......@@ -27,4 +29,7 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc
Page<Account> findAll(Pageable pageable);
List<Account> findByNameIn(List<String> names);
List<Account> findByPromotionCode(String code);
}
package com.edgec.browserbackend.account.repository;
import com.edgec.browserbackend.account.domain.Account;
import java.util.List;
public interface AccountRepositoryCustom {
......@@ -8,4 +10,6 @@ public interface AccountRepositoryCustom {
void updateRealNameAndIdCard(String username, String realName, String idCard);
Account findByPromotion(String code);
}
......@@ -51,4 +51,16 @@ public class AccountRepositoryCustomImpl implements AccountRepositoryCustom {
update.set("realName", realName).set("idCard", idCard);
mongoTemplate.upsert(basicQuery, update, Account.class);
}
@Override
public Account findByPromotion(String code) {
Document doc = new Document();
BasicQuery basicQuery = new BasicQuery(doc);
basicQuery.addCriteria(where("promotion.code").is(code));
Account account = mongoTemplate.findOne(basicQuery, Account.class);
if (account == null)
return null;
return account;
}
}
......@@ -20,6 +20,8 @@ public interface UserPrePaidBillingRepository extends MongoRepository<UserPrePai
Page<UserPrePaidBilling> findAllByYearBetweenAndMonthBetween(Pageable pageable, int year1, int year2, int month1, int month2);
List<UserPrePaidBilling> findByUsernameAndYearAndMonthAndPayMethodIsNot(String username, int year, int month, int payMethod);
List<UserPrePaidBilling> findByYearAndMonth(int year, int month);
List<UserPrePaidBilling> findByStatus(BillStatus status);
......
......@@ -22,4 +22,6 @@ public interface PaymentService {
UserPaymentDto h5wxPayOrder(String ip, String username, int amount);
boolean alipayWithdraw(String username, String account, String realName);
}
......@@ -452,7 +452,27 @@ public class AccountServiceImpl implements AccountService {
account.setEmail(user.getEmail());
account.setPhoneNumber(user.getUsername());
account.setPermission(15);
account.setPromotion(new Promotion());
if (user.getPromotionCode() != null)
account.setPromotionCode(user.getPromotionCode());
Account inviter = repository.findByPromotion(user.getPromotionCode());
if (inviter != null) {
inviter.getPromotion().setInvitedUsers(inviter.getPromotion().getInvitedUsers() + 1);
repository.save(inviter);
}
Account pExisting = null;
String random = null;
do {
random = String.valueOf((int)((Math.random()*9+1)*100000));
pExisting = repository.findByPromotion(random);
} while (pExisting != null);
Promotion promotion = new Promotion();
promotion.setCode(random);
promotion.setInvitedUsers(0);
promotion.setCommission(0);
account.setPromotion(promotion);
account.setAllowedToCreateSubUser(true);
List<String> whiteList = new ArrayList<>();
......@@ -711,6 +731,9 @@ public class AccountServiceImpl implements AccountService {
account.setPermission(subUsersRequestDto.getPermission());
else
account.setPermission(0);
if (existing.getPromotionCode() != null) {
account.setPromotionCode(existing.getPromotionCode());
}
List<String> whiteList = new ArrayList<>();
if (user.getWhiteList() != null && user.getWhiteList().size() > 0)
whiteList.addAll(user.getWhiteList());
......
......@@ -3,8 +3,10 @@ package com.edgec.browserbackend.account.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayFundTransToaccountTransferRequest;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.request.AlipayTradeQueryRequest;
import com.alipay.api.response.AlipayFundTransToaccountTransferResponse;
import com.alipay.api.response.AlipayTradePagePayResponse;
import com.alipay.api.response.AlipayTradeQueryResponse;
import com.edgec.browserbackend.account.exception.AccountErrorCode;
......@@ -509,4 +511,61 @@ public class PaymentServiceImpl implements PaymentService {
}
}
@Override
public boolean alipayWithdraw(String username, String account, String realName) {
Account byName = accountService.findByName(username);
if (byName == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST, "account does not exist: " + username);
boolean isVpsClient = true;
UserWithdraw internalOrder = new UserWithdraw();
internalOrder.setAmount(byName.getPromotion().getCommission());
internalOrder.setWithdrawMethod(PaymentMethod.ALIPAY);
internalOrder.setSucceed(false);
internalOrder.setUsername(username);
try {
AlipayConfig alipayConfig = isVpsClient ? new VpsAlipayConfig() : new CloudamAlipayConfig();
AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig.getURL(), alipayConfig.getAPPID(), alipayConfig.getAPP_PRIVATE_KEY(),
"json", alipayConfig.getCHARSET(), alipayConfig.getALIPAY_PUBLIC_KEY(), alipayConfig.getSIGN_TYPE());
AlipayFundTransToaccountTransferRequest alipayRequest = new AlipayFundTransToaccountTransferRequest();
// String out_biz_no = internalOrder.getTradeNo();
// String product_code = "TRANS_ACCOUNT_NO_PWD";
// String trans_amount = "" + byName.getPromotion().getCommission() + ".00";
// String subject = "订单" + out_trade_no;
// String body = "";
//
// alipayRequest.setBizContent(""
// + "{"
// + "\"out_biz_no\":\"" + out_biz_no + "\","
// + "\"product_code\":\"" + product_code + "\","
// + "\"trans_amount\":\"" + trans_amount + "\","
// + "\"subject\":\"" + subject + "\","
// + "\"body\":\"" + body + "\""
// + "}"
// );
// AlipayFundTransToaccountTransferResponse response = alipayClient.pageExecute(alipayRequest);
// if("10000".equals(response.getCode())){
// resultMap.put("success", "true");
// resultMap.put("des", "转账成功");
// }else{
// resultMap.put("success", "false");
// resultMap.put("des", response.getSubMsg());
// }
// userPaymentRepository.save(internalOrder);
//
// String form = response.getBody();
// return form;
} catch (Exception e) {
log.error("Alypay payment order generation fails", e);
throw new ClientRequestException(AccountErrorCode.ALIPAYERROR, "Alypay payment order error");
}
return false;
}
}
......@@ -43,17 +43,10 @@ public class BrowserTask {
private static String CLOUDAMURL = "https://www.cloudam.cn";
private static String TESTURL = "http://112.74.13.2";
private static String USERNAME = "fangguanlianbrowser";
@Autowired
private AccountRepository accountRepository;
@Autowired
private IpResourceRepository ipResourceRepository;
@Autowired
private IpTransactionRepository ipTransactionRepository;
@Autowired
private AccountService accountService;
......
......@@ -25,7 +25,7 @@ public class ExpireSoonWarn {
@Autowired
private IpResourceRepository ipResourceRepository;
@Scheduled(cron = "0 0 1 * * ?")
@Scheduled(cron = "0 0 9 * * ?")
public void sendMessages() {
this.sendExpiredIpAccount(0);
this.sendExpiredIpAccount(7);
......
package com.edgec.browserbackend.browser.task;
import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.domain.UserPrePaidBilling;
import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.account.repository.UserPrePaidBillingRepository;
import net.javacrumbs.shedlock.core.SchedulerLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.Instant;
import java.time.YearMonth;
import java.time.ZoneOffset;
import java.util.List;
@Component
public class PromotionTask {
private static final Logger log = LoggerFactory.getLogger(PromotionTask.class);
@Autowired
private AccountRepository accountRepository;
@Autowired
private UserPrePaidBillingRepository userPrePaidBillingRepository;
@SchedulerLock(name = "transferExpiredScalingGroups", lockAtLeastForString = "PT1H", lockAtMostForString = "PT2H")
@Scheduled(cron = "0 0 1 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;
for (Account promote : promotes) {
List<UserPrePaidBilling> userPrePaidBillings = userPrePaidBillingRepository.findByUsernameAndYearAndMonthAndPayMethodIsNot(promote.getName(),
YearMonth.now().minusMonths(1).getYear(),
YearMonth.now().minusMonths(1).getMonthValue(), 0);
totalCommission += 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