Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
browser-backend
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
browser-backend
Commits
7b3cdbd9
Commit
7b3cdbd9
authored
Mar 30, 2020
by
renjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
推广礼金
parent
f08caa40
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
274 additions
and
14 deletions
+274
-14
Account.java
...java/com/edgec/browserbackend/account/domain/Account.java
+10
-0
Promotion.java
...va/com/edgec/browserbackend/account/domain/Promotion.java
+5
-5
User.java
...in/java/com/edgec/browserbackend/account/domain/User.java
+10
-0
UserWithdraw.java
...com/edgec/browserbackend/account/domain/UserWithdraw.java
+92
-0
AccountRepository.java
.../browserbackend/account/repository/AccountRepository.java
+5
-0
AccountRepositoryCustom.java
...erbackend/account/repository/AccountRepositoryCustom.java
+4
-0
AccountRepositoryCustomImpl.java
...ckend/account/repository/AccountRepositoryCustomImpl.java
+12
-0
UserPrePaidBillingRepository.java
...kend/account/repository/UserPrePaidBillingRepository.java
+2
-0
PaymentService.java
.../edgec/browserbackend/account/service/PaymentService.java
+2
-0
AccountServiceImpl.java
...owserbackend/account/service/impl/AccountServiceImpl.java
+24
-1
PaymentServiceImpl.java
...owserbackend/account/service/impl/PaymentServiceImpl.java
+59
-0
BrowserTask.java
...va/com/edgec/browserbackend/browser/task/BrowserTask.java
+0
-7
ExpireSoonWarn.java
...com/edgec/browserbackend/browser/task/ExpireSoonWarn.java
+1
-1
PromotionTask.java
.../com/edgec/browserbackend/browser/task/PromotionTask.java
+48
-0
No files found.
src/main/java/com/edgec/browserbackend/account/domain/Account.java
View file @
7b3cdbd9
...
...
@@ -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
;
}
}
src/main/java/com/edgec/browserbackend/account/domain/Promotion.java
View file @
7b3cdbd9
...
...
@@ -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
get
Link
()
{
return
link
;
public
String
get
Code
()
{
return
code
;
}
public
void
set
Link
(
String
link
)
{
this
.
link
=
link
;
public
void
set
Code
(
String
code
)
{
this
.
code
=
code
;
}
}
src/main/java/com/edgec/browserbackend/account/domain/User.java
View file @
7b3cdbd9
...
...
@@ -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
;
}
}
src/main/java/com/edgec/browserbackend/account/domain/UserWithdraw.java
0 → 100644
View file @
7b3cdbd9
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
;
}
}
src/main/java/com/edgec/browserbackend/account/repository/AccountRepository.java
View file @
7b3cdbd9
...
...
@@ -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
);
}
src/main/java/com/edgec/browserbackend/account/repository/AccountRepositoryCustom.java
View file @
7b3cdbd9
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
);
}
src/main/java/com/edgec/browserbackend/account/repository/AccountRepositoryCustomImpl.java
View file @
7b3cdbd9
...
...
@@ -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
;
}
}
src/main/java/com/edgec/browserbackend/account/repository/UserPrePaidBillingRepository.java
View file @
7b3cdbd9
...
...
@@ -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
);
...
...
src/main/java/com/edgec/browserbackend/account/service/PaymentService.java
View file @
7b3cdbd9
...
...
@@ -22,4 +22,6 @@ public interface PaymentService {
UserPaymentDto
h5wxPayOrder
(
String
ip
,
String
username
,
int
amount
);
boolean
alipayWithdraw
(
String
username
,
String
account
,
String
realName
);
}
src/main/java/com/edgec/browserbackend/account/service/impl/AccountServiceImpl.java
View file @
7b3cdbd9
...
...
@@ -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
());
...
...
src/main/java/com/edgec/browserbackend/account/service/impl/PaymentServiceImpl.java
View file @
7b3cdbd9
...
...
@@ -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
;
}
}
src/main/java/com/edgec/browserbackend/browser/task/BrowserTask.java
View file @
7b3cdbd9
...
...
@@ -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
;
...
...
src/main/java/com/edgec/browserbackend/browser/task/ExpireSoonWarn.java
View file @
7b3cdbd9
...
...
@@ -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
);
...
...
src/main/java/com/edgec/browserbackend/browser/task/PromotionTask.java
0 → 100644
View file @
7b3cdbd9
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
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment