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
8cabd289
Commit
8cabd289
authored
Jul 07, 2020
by
xuxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
从stage合并部分代码到 upgrade
parent
6b58cfba
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
286 additions
and
388 deletions
+286
-388
AccountController.java
.../browserbackend/account/controller/AccountController.java
+52
-51
Account.java
...java/com/edgec/browserbackend/account/domain/Account.java
+6
-0
Otp.java
...ain/java/com/edgec/browserbackend/account/domain/Otp.java
+12
-0
Promotion.java
...va/com/edgec/browserbackend/account/domain/Promotion.java
+34
-8
User.java
...in/java/com/edgec/browserbackend/account/domain/User.java
+6
-100
UserPrePaidBilling.java
...gec/browserbackend/account/domain/UserPrePaidBilling.java
+17
-164
PaymentServiceImpl.java
...owserbackend/account/service/impl/PaymentServiceImpl.java
+0
-0
UserServiceImpl.java
...gec/browserbackend/auth/service/Impl/UserServiceImpl.java
+5
-7
BrowserErrorCode.java
...ec/browserbackend/browser/ErrorCode/BrowserErrorCode.java
+1
-0
ShopController.java
...gec/browserbackend/browser/controller/ShopController.java
+28
-0
IpResourceRequestDto.java
...dgec/browserbackend/browser/dto/IpResourceRequestDto.java
+35
-4
IpResourceRepositoryCustomImpl.java
...nd/browser/repository/IpResourceRepositoryCustomImpl.java
+1
-4
ShopRepository.java
...gec/browserbackend/browser/repository/ShopRepository.java
+5
-0
IpResourceServiceImpl.java
...erbackend/browser/service/Impl/IpResourceServiceImpl.java
+0
-0
ShopServiceImpl.java
.../browserbackend/browser/service/Impl/ShopServiceImpl.java
+0
-0
ShopService.java
...com/edgec/browserbackend/browser/service/ShopService.java
+5
-2
BrowserTask.java
...va/com/edgec/browserbackend/browser/task/BrowserTask.java
+18
-16
PaymentTask.java
...va/com/edgec/browserbackend/browser/task/PaymentTask.java
+26
-16
PromotionTask.java
.../com/edgec/browserbackend/browser/task/PromotionTask.java
+35
-16
No files found.
src/main/java/com/edgec/browserbackend/account/controller/AccountController.java
View file @
8cabd289
...
...
@@ -80,11 +80,7 @@ public class AccountController {
resultDto
.
setStatus
(
0
);
resultDto
.
setData
(
userDtos
);
}
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
);
dealClientRequestException
(
resultDto
,
e
);
}
return
resultDto
;
}
...
...
@@ -102,11 +98,7 @@ public class AccountController {
resultDto
.
setStatus
(
0
);
resultDto
.
setData
(
account1
);
}
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
);
dealClientRequestException
(
resultDto
,
e
);
}
return
resultDto
;
}
...
...
@@ -119,32 +111,29 @@ public class AccountController {
resultDto
.
setStatus
(
0
);
}
catch
(
ClientRequestException
e
)
{
logger
.
error
(
"fail to send sms"
,
e
);
resultDto
.
setStatus
(-
1
);
Map
<
String
,
Object
>
statusInfo
=
new
HashMap
<>();
statusInfo
.
put
(
"code"
,
e
.
getErrorCode
());
statusInfo
.
put
(
"message"
,
e
.
getMessage
());
resultDto
.
setStatusInfo
(
statusInfo
);
dealClientRequestException
(
resultDto
,
e
);
}
return
resultDto
;
}
/**
* 用户注册
*/
@RequestMapping
(
path
=
"/signUp"
,
method
=
RequestMethod
.
POST
)
public
ResultDto
createNewAccount
(
@Valid
@RequestBody
User
user
)
{
ResultDto
resultDto
=
new
ResultDto
();
try
{
Account
account
=
new
Account
();
if
(!
StringUtils
.
isEmpty
(
user
.
getEmail
()))
if
(!
StringUtils
.
isEmpty
(
user
.
getEmail
()))
{
account
=
accountService
.
create
(
user
);
else
}
else
{
account
=
accountService
.
createWithSms
(
user
);
}
resultDto
.
setStatus
(
0
);
resultDto
.
setData
(
account
);
}
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
);
dealClientRequestException
(
resultDto
,
e
);
}
return
resultDto
;
}
...
...
@@ -162,7 +151,10 @@ public class AccountController {
emailService
.
sendHtmlMail
(
"sales@cloudam.io"
,
"客户联系:"
+
contactUs
.
getName
(),
sb
.
toString
());
}
// 消费总览
/**
* 费用明细
*/
@RequestMapping
(
path
=
"/userbilling"
,
method
=
RequestMethod
.
POST
)
public
ResultDto
getUserBills0
(
Principal
principal
,
@RequestBody
UserPrePaidBillingRequestDto
userPrePaidBillingRequestDto
)
{
ResultDto
resultDto
=
new
ResultDto
();
...
...
@@ -170,11 +162,7 @@ public class AccountController {
resultDto
.
setData
(
accountService
.
getUserPrePaidBills
(
principal
.
getName
(),
userPrePaidBillingRequestDto
));
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
);
dealClientRequestException
(
resultDto
,
e
);
}
return
resultDto
;
}
...
...
@@ -214,11 +202,7 @@ public class AccountController {
accountService
.
resetPassword
(
principal
.
getName
(),
user
);
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
);
dealClientRequestException
(
resultDto
,
e
);
}
return
resultDto
;
}
...
...
@@ -235,25 +219,30 @@ public class AccountController {
accountService
.
resetPasswordWithOtp
(
user
);
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
);
dealClientRequestException
(
resultDto
,
e
);
}
return
resultDto
;
}
/**
* 使用微信进行账户充值
*/
@RequestMapping
(
path
=
"/0xwxpayputorder/{amount}"
,
method
=
RequestMethod
.
GET
)
public
UserPaymentDto
wechatPayCallback
(
Principal
principal
,
@PathVariable
int
amount
)
{
return
paymentService
.
wxPutPayOrder
(
principal
.
getName
(),
amount
);
}
/**
* 使用微信进行账户充值成功后,微信会调用该接口
*/
@RequestMapping
(
path
=
"/0xwxpaycallback/{tradno}"
,
method
=
RequestMethod
.
GET
)
public
String
wechatPayCallback
(
@PathVariable
String
tradno
)
{
return
paymentService
.
wechatPayCallback
(
tradno
);
}
/**
* 使用微信进行账户充值成功后,微信会调用该接口
*/
@RequestMapping
(
path
=
"/0xwxcheckorderstatus/{tradno}/{chargeType}"
,
method
=
RequestMethod
.
GET
)
public
UserPaymentDto
wechatCheckOrderStatus
(
Principal
principal
,
@PathVariable
String
tradno
,
@PathVariable
int
chargeType
)
{
return
paymentService
.
wxCheckOrderStatus
(
tradno
,
chargeType
);
...
...
@@ -264,19 +253,28 @@ public class AccountController {
return
paymentService
.
wxCheckOrderStatus
(
tradno
,
chargeType
);
}
/**
* 使用 支付宝 充值 成功后回调
*/
@RequestMapping
(
path
=
"/0xalipaycallback/{tradno}"
,
method
=
RequestMethod
.
GET
)
public
void
alipayPayCallback
(
@PathVariable
String
tradno
)
{
paymentService
.
alipaCallback
(
tradno
);
}
/**
* 使用 支付宝 充值 成功后回调
*/
@RequestMapping
(
path
=
"/0xalicheckorderstatus/{tradno}/{chargeType}"
,
method
=
RequestMethod
.
GET
)
public
UserPaymentDto
alipayCheckOrderStatus
(
Principal
principal
,
@PathVariable
(
required
=
false
)
String
tradno
,
@PathVariable
int
chargeType
)
{
return
paymentService
.
aliCheckOrderStatus
(
tradno
,
chargeType
);
}
/**
* 使用 支付宝 充值
*/
@RequestMapping
(
path
=
"/0xalipay/{amount}"
,
method
=
RequestMethod
.
GET
)
public
void
alipayPutOrder
(
HttpServletRequest
request
,
HttpServletResponse
response
,
@PathVariable
int
amount
)
throws
Exception
{
String
by
=
request
.
getParameter
(
"by"
);
String
form
=
paymentService
.
alipayPutPayOrder
(
request
.
getUserPrincipal
().
getName
(),
amount
,
by
);
response
.
setContentType
(
"text/html;charset=utf-8"
);
...
...
@@ -428,11 +426,7 @@ public class AccountController {
accountService
.
authorizeCompany
(
principal
.
getName
(),
companyAuthorizeDto
);
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
);
dealClientRequestException
(
resultDto
,
e
);
}
return
resultDto
;
}
...
...
@@ -472,17 +466,24 @@ public class AccountController {
ResultDto
resultDto
=
new
ResultDto
();
try
{
if
(
paymentService
.
alipayWithdraw
(
principal
.
getName
(),
account
,
realName
,
amount
))
if
(
paymentService
.
alipayWithdraw
(
principal
.
getName
(),
account
,
realName
,
amount
))
{
resultDto
.
setStatus
(
0
);
else
}
else
{
resultDto
.
setStatus
(-
1
);
}
}
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
);
dealClientRequestException
(
resultDto
,
e
);
}
return
resultDto
;
}
private
void
dealClientRequestException
(
ResultDto
resultDto
,
ClientRequestException
e
)
{
resultDto
.
setStatus
(-
1
);
Map
<
String
,
Object
>
statusInfo
=
new
HashMap
<>();
statusInfo
.
put
(
"code"
,
e
.
getErrorCode
());
statusInfo
.
put
(
"message"
,
e
.
getMessage
());
resultDto
.
setStatusInfo
(
statusInfo
);
}
}
src/main/java/com/edgec/browserbackend/account/domain/Account.java
View file @
8cabd289
...
...
@@ -67,8 +67,14 @@ public class Account {
*/
private
int
permission
=
-
1
;
/**
* 注册成功后,当前用户的邀请码相关信息,用于邀请别人获取佣金
*/
private
Promotion
promotion
;
/**
* 注册时,其他用户给当前用户的邀请码
*/
private
String
promotionCode
;
private
String
comment
;
...
...
src/main/java/com/edgec/browserbackend/account/domain/Otp.java
View file @
8cabd289
...
...
@@ -7,9 +7,21 @@ import org.springframework.data.mongodb.core.mapping.Document;
@Document
(
collection
=
"phoneotp"
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
Otp
{
/**
* 手机号
*/
@Id
private
String
phone
;
/**
* 发送给用户的短信验证码
*/
private
String
otp
;
/**
* 短信验证码的发送时间
*/
private
long
createdAt
;
public
String
getPhone
()
{
...
...
src/main/java/com/edgec/browserbackend/account/domain/Promotion.java
View file @
8cabd289
...
...
@@ -9,22 +9,48 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
**/
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
Promotion
{
/**
* 邀请码(用户邀请好友使用本产品)
*/
private
String
code
;
//邀请人数
/**
* 邀请人数
*/
private
int
invitedUsers
;
//好友本月以前总消费
/**
* 好友本月以前总消费
*/
private
int
totalCommission
;
//好友当月消费
/**
* 好友当月消费
*/
private
int
commission
;
//好友上月总消费
/**
* 好友上月总消费
*/
private
int
commissionLastMonth
;
//是否是本公司的销售
/**
* 是否是本公司的销售
*/
private
boolean
isSale
;
//当月礼金
/**
* 当月礼金
*/
private
double
gift
;
//所有未提现金额
/**
* 所有未提现金额
*/
private
double
allGift
;
//已提现金额
/**
* 已提现金额
*/
private
double
withdrawn
;
public
int
getCommission
()
{
...
...
src/main/java/com/edgec/browserbackend/account/domain/User.java
View file @
8cabd289
package
com
.
edgec
.
browserbackend
.
account
.
domain
;
import
lombok.Data
;
import
org.hibernate.validator.constraints.Length
;
import
javax.validation.constraints.Email
;
...
...
@@ -7,15 +8,16 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.UUID
;
@Data
public
class
User
{
@Length
(
min
=
3
,
max
=
20
,
message
=
"Name length should be between 3 - 20"
)
@Length
(
min
=
3
,
max
=
20
,
message
=
"Name length should be between 3 - 20"
)
private
String
username
;
@Length
(
min
=
6
,
max
=
40
,
message
=
"Password length should be between 6 - 40"
)
@Length
(
min
=
6
,
max
=
40
,
message
=
"Password length should be between 6 - 40"
)
private
String
password
;
@Email
(
message
=
"Invalid email address"
)
@Email
(
message
=
"Invalid email address"
)
private
String
email
;
private
String
phone
;
...
...
@@ -28,108 +30,12 @@ public class User {
private
String
lockReason
;
public
String
getAuthCode
()
{
return
authCode
;
}
public
void
setAuthCode
(
String
authCode
)
{
this
.
authCode
=
authCode
;
}
public
String
getPhone
()
{
return
phone
;
}
public
void
setPhone
(
String
phone
)
{
this
.
phone
=
phone
;
}
private
boolean
allowedToCreateSubUser
=
true
;
private
int
permission
;
private
List
<
String
>
whiteList
=
new
ArrayList
<>();
private
String
verificationCode
=
UUID
.
randomUUID
().
toString
();
public
boolean
isEnabled
()
{
return
enabled
;
}
public
void
setEnabled
(
boolean
enabled
)
{
this
.
enabled
=
enabled
;
}
public
String
getVerificationCode
()
{
return
verificationCode
;
}
public
void
setVerificationCode
(
String
verificationCode
)
{
this
.
verificationCode
=
verificationCode
;
}
public
String
getEmail
()
{
return
email
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
boolean
isAllowedToCreateSubUser
()
{
return
allowedToCreateSubUser
;
}
public
void
setAllowedToCreateSubUser
(
boolean
allowedToCreateSubUser
)
{
allowedToCreateSubUser
=
allowedToCreateSubUser
;
}
public
int
getPermission
()
{
return
permission
;
}
public
void
setPermission
(
int
permission
)
{
this
.
permission
=
permission
;
}
public
String
getLockReason
()
{
return
lockReason
;
}
public
void
setLockReason
(
String
lockReason
)
{
this
.
lockReason
=
lockReason
;
}
public
List
<
String
>
getWhiteList
()
{
return
whiteList
;
}
public
void
setWhiteList
(
List
<
String
>
whiteList
)
{
this
.
whiteList
=
whiteList
;
}
public
String
getPromotionCode
()
{
return
promotionCode
;
}
private
String
verificationCode
=
UUID
.
randomUUID
().
toString
();
public
void
setPromotionCode
(
String
promotionCode
)
{
this
.
promotionCode
=
promotionCode
;
}
}
src/main/java/com/edgec/browserbackend/account/domain/UserPrePaidBilling.java
View file @
8cabd289
package
com
.
edgec
.
browserbackend
.
account
.
domain
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.index.CompoundIndex
;
import
org.springframework.data.mongodb.core.mapping.Document
;
...
...
@@ -8,6 +10,8 @@ import org.springframework.data.mongodb.core.mapping.Document;
import
java.util.ArrayList
;
import
java.util.List
;
@Getter
@Setter
@Document
(
collection
=
"userprepaidbilling"
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@CompoundIndex
(
name
=
"idx_username_timestamp"
,
def
=
"{'username': 1, 'timestamp': 1}"
)
...
...
@@ -36,19 +40,22 @@ public class UserPrePaidBilling {
private
BillStatus
status
;
//0 -- 余额, 1 -- 支付宝, 2 -- 微信, 3 -- 银行转账
/**
* 0 -- 余额, 1 -- 支付宝, 2 -- 微信, 3 -- 银行转账
*/
private
int
payMethod
;
private
boolean
isPrepaid
;
/**
* 本次消费金额
*/
private
float
total
;
//0 -- 充值, 1 -- newip, 2 -- renew, 3 -- return, 4 -- 礼金提现
private
int
chargeType
;
/**
*
购买或者续费的ip 号
*
0 -- 充值, 1 -- newip, 2 -- renew, 3 -- return, 4 -- 礼金提现
*/
private
String
chargeIp
;
private
int
chargeType
;
private
String
unit
=
"month"
;
...
...
@@ -56,169 +63,15 @@ public class UserPrePaidBilling {
private
float
balanced
;
private
List
<
DeductionRecord
>
deductionRecords
=
new
ArrayList
<>();
public
float
getRate
()
{
return
rate
;
}
public
float
getTotal
()
{
return
total
;
}
public
void
setRate
(
float
rate
)
{
this
.
rate
=
rate
;
}
public
void
setTotal
(
float
total
)
{
this
.
total
=
total
;
}
public
int
getChargeType
()
{
return
chargeType
;
}
public
void
setChargeType
(
int
chargeType
)
{
this
.
chargeType
=
chargeType
;
}
public
String
getUnit
()
{
return
unit
;
}
public
void
setUnit
(
String
unit
)
{
this
.
unit
=
unit
;
}
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
int
getYear
()
{
return
year
;
}
public
void
setYear
(
int
year
)
{
this
.
year
=
year
;
}
public
int
getMonth
()
{
return
month
;
}
public
void
setMonth
(
int
month
)
{
this
.
month
=
month
;
}
public
long
getTimestamp
()
{
return
timestamp
;
}
public
void
setTimestamp
(
long
timestamp
)
{
this
.
timestamp
=
timestamp
;
}
public
Services
getServices
()
{
return
services
;
}
public
void
setServices
(
Services
services
)
{
this
.
services
=
services
;
}
public
BillStatus
getStatus
()
{
return
status
;
}
public
void
setStatus
(
BillStatus
status
)
{
this
.
status
=
status
;
}
public
boolean
isPrepaid
()
{
return
isPrepaid
;
}
public
void
setPrepaid
(
boolean
prepaid
)
{
this
.
isPrepaid
=
prepaid
;
}
public
List
<
DeductionRecord
>
getDeductionRecords
()
{
return
deductionRecords
;
}
/**
* 购买或者续费的ip 号
*/
private
String
chargeIp
;
public
void
setDeductionRecords
(
List
<
DeductionRecord
>
deductionRecords
)
{
this
.
deductionRecords
=
deductionRecords
;
}
private
List
<
DeductionRecord
>
deductionRecords
=
new
ArrayList
<>();
public
void
addDeductionRecord
(
DeductionRecord
record
)
{
this
.
deductionRecords
.
add
(
record
);
}
public
int
getAmount
()
{
return
amount
;
}
public
void
setAmount
(
int
amount
)
{
this
.
amount
=
amount
;
}
public
int
getPeriod
()
{
return
period
;
}
public
void
setPeriod
(
int
period
)
{
this
.
period
=
period
;
}
public
int
getPayMethod
()
{
return
payMethod
;
}
public
void
setPayMethod
(
int
payMethod
)
{
this
.
payMethod
=
payMethod
;
}
public
String
getTradeNo
()
{
return
tradeNo
;
}
public
void
setTradeNo
(
String
tradeNo
)
{
this
.
tradeNo
=
tradeNo
;
}
public
String
getAdministrator
()
{
return
administrator
;
}
public
void
setAdministrator
(
String
administrator
)
{
this
.
administrator
=
administrator
;
}
public
float
getBalanced
()
{
return
balanced
;
}
public
void
setBalanced
(
float
balanced
)
{
this
.
balanced
=
balanced
;
}
public
String
getChargeIp
()
{
return
chargeIp
;
}
public
void
setChargeIp
(
String
chargeIp
)
{
this
.
chargeIp
=
chargeIp
;
}
}
src/main/java/com/edgec/browserbackend/account/service/impl/PaymentServiceImpl.java
View file @
8cabd289
This diff is collapsed.
Click to expand it.
src/main/java/com/edgec/browserbackend/auth/service/Impl/UserServiceImpl.java
View file @
8cabd289
...
...
@@ -17,8 +17,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.stereotype.Service
;
import
java.util.Optional
;
@Service
public
class
UserServiceImpl
implements
UserService
{
...
...
@@ -103,11 +101,11 @@ public class UserServiceImpl implements UserService {
@Override
public
void
create
(
User
user
)
{
Optional
<
User
>
existing
=
repository
.
findById
(
user
.
getUsername
());
existing
.
ifPresent
(
it
->
{
throw
new
ClientRequestException
(
AuthErrorCode
.
NAMEEXIST
,
"user already exists: "
+
it
.
getUsername
());
}
);
repository
.
findById
(
user
.
getUsername
()).
ifPresent
(
it
->
{
throw
new
ClientRequestException
(
AuthErrorCode
.
NAMEEXIST
,
"user already exists: "
+
it
.
getUsername
());
}
);
String
hash
=
encoder
.
encode
(
user
.
getPassword
());
user
.
setPassword
(
hash
);
...
...
src/main/java/com/edgec/browserbackend/browser/ErrorCode/BrowserErrorCode.java
View file @
8cabd289
...
...
@@ -14,6 +14,7 @@ public enum BrowserErrorCode implements ErrorCode {
IPNOTEXIST
(
BROWSER_BASE
+
201
,
"The ip do not exist"
),
IPNOTBINDTOSHOP
(
BROWSER_BASE
+
202
,
"The ip does not bind this shop."
),
USER_NOT_BIND_SHOP
(
BROWSER_BASE
+
203
,
"The shop does not bind this user."
),
GROUPNOTEXIST
(
BROWSER_BASE
+
301
,
"The group does not exist"
),
...
...
src/main/java/com/edgec/browserbackend/browser/controller/ShopController.java
View file @
8cabd289
...
...
@@ -138,6 +138,9 @@ public class ShopController {
return
resultDto
;
}
/**
* 店铺分配
*/
@RequestMapping
(
value
=
"/assign"
,
method
=
RequestMethod
.
POST
)
public
ResultDto
assignShop
(
Principal
principal
,
@RequestBody
ShopRequestDto
shopRequestDto
)
{
ResultDto
resultDto
=
new
ResultDto
();
...
...
@@ -150,6 +153,9 @@ public class ShopController {
return
resultDto
;
}
/**
* 获取带有 ip 资源信息的 shop
*/
@RequestMapping
(
value
=
"/list"
,
method
=
RequestMethod
.
POST
)
public
ResultDto
getShopList
(
Principal
principal
,
@RequestBody
ShopRequestDto
shopRequestDto
)
{
logger
.
info
(
"shop list params {}"
,
JSONObject
.
toJSONString
(
shopRequestDto
));
...
...
@@ -165,6 +171,9 @@ public class ShopController {
return
resultDto
;
}
/**
* 获取当前登录用户已经绑定了当前商铺的 所有子用户名
*/
@RequestMapping
(
value
=
"/subusers"
,
method
=
RequestMethod
.
POST
)
public
ResultDto
getShopSubUsers
(
Principal
principal
,
@RequestBody
ShopRequestDto
shopRequestDto
)
{
ResultDto
resultDto
=
new
ResultDto
();
...
...
@@ -191,6 +200,9 @@ public class ShopController {
return
resultDto
;
}
/**
* 查询店铺信息
*/
@RequestMapping
(
value
=
"/query"
,
method
=
RequestMethod
.
POST
)
public
ResultDto
queryShop
(
Principal
principal
,
@RequestBody
ShopRequestDto
shopRequestDto
)
{
ResultDto
resultDto
=
new
ResultDto
();
...
...
@@ -204,6 +216,22 @@ public class ShopController {
return
resultDto
;
}
/**
* 恢复部分缺失数据,仅仅调用一次就好了
*/
@GetMapping
(
value
=
"/deal_dirtydata"
)
public
ResultDto
dealDirtydata
()
{
Integer
num
=
shopService
.
dealDirtyData
();
ResultDto
resultDto
=
new
ResultDto
();
resultDto
.
setStatus
(
0
);
resultDto
.
setData
(
"修复脏数据"
+
num
+
"条"
);
return
resultDto
;
}
private
void
dealClientRequestException
(
ResultDto
resultDto
,
ClientRequestException
e
)
{
resultDto
.
setStatus
(-
1
);
Map
<
String
,
Object
>
statusInfo
=
new
HashMap
<>();
...
...
src/main/java/com/edgec/browserbackend/browser/dto/IpResourceRequestDto.java
View file @
8cabd289
...
...
@@ -10,27 +10,57 @@ import java.util.List;
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
IpResourceRequestDto
{
private
String
name
;
/**
* ip 所在地域(英文)
*/
private
String
region
;
/**
* ip 所在地域(中文)
*/
private
String
regionCn
;
private
String
vendor
=
"aliyun"
;
/**
* ip 厂商
*/
private
String
vendor
=
"aliyun"
;
private
String
logintype
=
"password"
;
private
String
shopId
;
//0 -- 余额, 1 -- 支付宝, 2 -- 微信
/**
* 0:余额, 1:支付宝, 2:微信
*/
private
int
payMethod
=
0
;
@Max
(
12
)
@Min
(
1
)
private
int
period
=
1
;
private
String
unit
=
"month"
;
/**
* 例如 period :2,unit = month
* 代表:购买 ip 2 个 月
*/
private
String
unit
=
"month"
;
/**
* 购买的ip数量(用户可以一次购买多个ip)
*/
private
int
amount
=
1
;
private
boolean
autorenew
=
false
;
private
int
ipkeptperiod
=
7
;
private
String
startscript
=
""
;
/**
* ip 是否需要使用专线
*/
private
boolean
specialLine
;
//自有IP需要传proxy的账号
/**
* 自有IP需要传proxy的账号
*/
private
String
username
;
private
String
password
;
private
String
instanceSpecKey
;
...
...
@@ -44,6 +74,7 @@ public class IpResourceRequestDto {
private
List
<
String
>
ipId
=
new
ArrayList
<>();
public
String
getName
()
{
return
name
;
}
...
...
src/main/java/com/edgec/browserbackend/browser/repository/IpResourceRepositoryCustomImpl.java
View file @
8cabd289
...
...
@@ -35,10 +35,7 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
update
.
set
(
"isLocked"
,
true
).
set
(
"lockTimestamp"
,
Instant
.
now
().
toEpochMilli
());
UpdateResult
result
=
mongoTemplate
.
updateFirst
(
basicQuery
,
update
,
IpResource
.
class
);
if
(
result
.
getModifiedCount
()
<
1
)
return
false
;
else
return
true
;
return
result
.
getModifiedCount
()
>=
1
;
}
@Override
...
...
src/main/java/com/edgec/browserbackend/browser/repository/ShopRepository.java
View file @
8cabd289
...
...
@@ -9,7 +9,12 @@ import java.util.List;
public
interface
ShopRepository
extends
MongoRepository
<
Shop
,
String
>
{
Page
<
Shop
>
findByShopIdInAndShopAccountLikeOrderByCreateTimeDesc
(
List
<
String
>
shopIds
,
String
shopAccount
,
Pageable
pageable
);
Page
<
Shop
>
findByShopIdInAndShopNameLikeOrderByCreateTimeDesc
(
List
<
String
>
shopIds
,
String
shopName
,
Pageable
pageable
);
Page
<
Shop
>
findByShopIdInOrderByCreateTimeDesc
(
List
<
String
>
shopIds
,
Pageable
pageable
);
List
<
Shop
>
findByShopIdIn
(
List
<
String
>
shopIds
);
List
<
Shop
>
findByOwnerIn
(
List
<
String
>
owners
);
}
src/main/java/com/edgec/browserbackend/browser/service/Impl/IpResourceServiceImpl.java
View file @
8cabd289
This diff is collapsed.
Click to expand it.
src/main/java/com/edgec/browserbackend/browser/service/Impl/ShopServiceImpl.java
View file @
8cabd289
This diff is collapsed.
Click to expand it.
src/main/java/com/edgec/browserbackend/browser/service/ShopService.java
View file @
8cabd289
package
com
.
edgec
.
browserbackend
.
browser
.
service
;
import
com.edgec.browserbackend.browser.domain.Shop
;
import
com.edgec.browserbackend.browser.domain.ShopSummary
;
import
com.edgec.browserbackend.browser.dto.*
;
import
com.edgec.browserbackend.browser.dto.ShopFilterDto
;
import
com.edgec.browserbackend.browser.dto.ShopPageResultDto
;
import
com.edgec.browserbackend.browser.dto.ShopResultDto
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
...
...
@@ -31,4 +32,6 @@ public interface ShopService {
List
<
String
>
getShopUsers
(
String
username
,
String
shopId
);
List
<
String
>
getBatchShopUsers
(
String
username
,
List
<
String
>
shopIds
);
Integer
dealDirtyData
();
}
src/main/java/com/edgec/browserbackend/browser/task/BrowserTask.java
View file @
8cabd289
...
...
@@ -101,12 +101,15 @@ public class BrowserTask {
}
/**
* 购买ip的定时任务,每分钟一次
*/
@Scheduled
(
cron
=
"0 0/1 * * * ?"
)
public
void
buyIpTasks
()
{
String
URL
=
(
profiles
.
equals
(
"dev"
)
||
profiles
.
equals
(
"staging"
))
?
TESTURL
:
CLOUDAMURL
;
long
time
=
Instant
.
now
().
minusSeconds
(
300
).
toEpochMilli
();
List
<
IpResource
>
ipResources
=
ipResourceRepository
.
sampleTasks
(
6
,
time
);
log
.
error
(
"buyIpTasks sample {} tasks"
,
ipResources
.
size
());
log
.
info
(
"buyIpTasks sample {} tasks"
,
ipResources
.
size
());
List
<
CompletableFuture
>
futureList
=
new
ArrayList
<>();
for
(
IpResource
ipResource
:
ipResources
)
{
long
start
=
System
.
currentTimeMillis
();
...
...
@@ -139,22 +142,21 @@ public class BrowserTask {
}
if
(
ipBuyResultDto
!=
null
&&
ipBuyResultDto
.
getIplist
()
!=
null
&&
ipBuyResultDto
.
getIplist
().
size
()
>=
1
)
{
AtomicInteger
index
=
new
AtomicInteger
();
ipBuyResultDto
.
getIplist
().
forEach
(
x
->
{
if
(
ipResource
!=
null
)
{
ipResource
.
setAddr
(
x
.
getIp
());
ipResource
.
setStatus
(
3
);
ipResource
.
setValidTime
(
Instant
.
parse
(
x
.
getValidTill
()).
toEpochMilli
());
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getRegion
())
&&
region
.
contains
(
ipResource
.
getRegion
()))
{
ipResource
.
setProxyUsername
(
ipResource
.
getAddr
());
ipResource
.
setProxyPassword
(
genRandom
(
3
,
12
));
ipResource
.
setSpecialLine
(
true
);
ipBuyResultDto
.
getIplist
().
forEach
(
x
->
{
ipResource
.
setAddr
(
x
.
getIp
());
ipResource
.
setStatus
(
3
);
ipResource
.
setValidTime
(
Instant
.
parse
(
x
.
getValidTill
()).
toEpochMilli
());
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getRegion
())
&&
region
.
contains
(
ipResource
.
getRegion
()))
{
ipResource
.
setProxyUsername
(
ipResource
.
getAddr
());
ipResource
.
setProxyPassword
(
genRandom
(
3
,
12
));
ipResource
.
setSpecialLine
(
true
);
}
ipResourceRepository
.
save
(
ipResource
);
index
.
getAndIncrement
();
}
ipResourceRepository
.
save
(
ipResource
);
}
else
{
log
.
error
(
"no ipResource"
);
}
index
.
getAndIncrement
();
});
);
result
=
true
;
}
}
catch
(
Exception
e
)
{
...
...
src/main/java/com/edgec/browserbackend/browser/task/PaymentTask.java
View file @
8cabd289
...
...
@@ -32,25 +32,34 @@ public class PaymentTask {
long
now
=
System
.
currentTimeMillis
();
Date
date_5min
=
new
Date
(
now
-
5
*
60
*
1000
);
Date
date_10min
=
new
Date
(
now
-
10
*
60
*
1000
);
// 查找 5-10 分钟内 支付状态为 false 的订单
List
<
UserPayment
>
unfinishedPayments
=
userPaymentRepository
.
findAllByPaymentDateBetweenAndSucceed
(
ZonedDateTime
.
ofInstant
(
date_10min
.
toInstant
(),
ZoneId
.
systemDefault
())
,
ZonedDateTime
.
ofInstant
(
date_5min
.
toInstant
(),
ZoneId
.
systemDefault
()),
false
);
ZonedDateTime
.
ofInstant
(
date_10min
.
toInstant
(),
ZoneId
.
systemDefault
()),
ZonedDateTime
.
ofInstant
(
date_5min
.
toInstant
(),
ZoneId
.
systemDefault
()),
false
);
if
(
unfinishedPayments
!=
null
&&
unfinishedPayments
.
size
()
>
0
)
{
if
(
unfinishedPayments
!=
null
&&
!
unfinishedPayments
.
isEmpty
())
{
unfinishedPayments
.
forEach
(
payment
->
{
PaymentMethod
paymentMethod
=
payment
.
getPaymentMethod
();
try
{
/*
* 自动调用 微信或者支付宝的支付接口来确认 支付状态
* chargeType 取值范围为 0-4
* 此处设置为 100 仅仅只是为了避免 wxCheckOrderStatus() 方法中 chargeType == 0 相关代码块
*/
if
(
PaymentMethod
.
WECHAT
.
equals
(
paymentMethod
))
{
paymentService
.
wxCheckOrderStatus
(
payment
.
getTradeNo
(),
100
);
}
unfinishedPayments
.
stream
().
forEach
(
payment
->
{
PaymentMethod
paymentMethod
=
payment
.
getPaymentMethod
();
try
{
if
(
PaymentMethod
.
WECHAT
.
equals
(
paymentMethod
))
{
paymentService
.
wxCheckOrderStatus
(
payment
.
getTradeNo
());
}
else
if
(
PaymentMethod
.
ALIPAY
.
equals
(
paymentMethod
))
{
paymentService
.
aliCheckOrderStatus
(
payment
.
getTradeNo
());
if
(
PaymentMethod
.
ALIPAY
.
equals
(
paymentMethod
))
{
paymentService
.
aliCheckOrderStatus
(
payment
.
getTradeNo
(),
100
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"checkPayments"
,
e
);
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"checkPayments"
,
e
);
}
});
);
}
}
}
}
\ No newline at end of file
src/main/java/com/edgec/browserbackend/browser/task/PromotionTask.java
View file @
8cabd289
...
...
@@ -34,30 +34,40 @@ public class PromotionTask {
public
void
countGift
()
{
List
<
Account
>
accounts
=
accountRepository
.
findByParentIsNull
();
for
(
Account
account
:
accounts
)
{
// 1. 获取当前账户的邀请码信息
String
code
=
account
.
getPromotion
().
getCode
();
// 2. 获取被当前账户邀请的所有账户
List
<
Account
>
promotes
=
accountRepository
.
findByPromotionCodeAndParentIsNull
(
code
);
double
totalCommission
=
0
;
double
secondCommission
=
0
;
// 3. 计算所有被当前账户邀请的账户上个月的消费信息,以及如果当前账户是销售账户则还需要计算销售账户的下下级账户的上个月消费信息
for
(
Account
promote
:
promotes
)
{
List
<
UserPrePaidBilling
>
userPrePaidBillings
=
userPrePaidBillingRepository
.
findByAdministratorAndYearAndMonthAndPayMethodIn
(
promote
.
getName
(),
YearMonth
.
now
().
minusMonths
(
1
).
getYear
(),
YearMonth
.
now
().
minusMonths
(
1
).
getMonthValue
(),
Arrays
.
asList
(
1
,
2
,
3
));
// 3.1 获取被邀请的用户上个月的消费信息,todo 感觉这个地方最好加上支付状态
List
<
UserPrePaidBilling
>
userPrePaidBillings
=
userPrePaidBillingRepository
.
findByAdministratorAndYearAndMonthAndPayMethodIn
(
promote
.
getName
(),
YearMonth
.
now
().
minusMonths
(
1
).
getYear
(),
YearMonth
.
now
().
minusMonths
(
1
).
getMonthValue
(),
Arrays
.
asList
(
1
,
2
,
3
)
);
// 3.2. 计算被邀请的用户上个月的总消费金额
totalCommission
+=
userPrePaidBillings
.
stream
().
mapToDouble
(
UserPrePaidBilling:
:
getTotal
).
sum
();
// 3.3. 如果当前账户是本公司销售,则计算下下级用户(例如:销售人员A 邀请了 用户B,用户B 邀请了 其他用户,其他用户就是A的下下级用户)上个月总消费金额
if
(
account
.
getPromotion
().
isSale
()
&&
promote
.
getParent
()
==
null
)
{
// 获取下下级账户
List
<
Account
>
secondPromotes
=
accountRepository
.
findByPromotionCodeAndParentIsNull
(
promote
.
getPromotion
().
getCode
());
if
(
secondPromotes
!=
null
&&
secondPromotes
.
size
()
>
0
)
{
if
(
secondPromotes
!=
null
&&
!
secondPromotes
.
isEmpty
()
)
{
for
(
Account
secondPromote
:
secondPromotes
)
{
List
<
UserPrePaidBilling
>
userPrePaidBillings1
=
userPrePaidBillingRepository
.
findByAdministratorAndYearAndMonthAndPayMethodIn
(
secondPromote
.
getName
(),
YearMonth
.
now
().
minusMonths
(
1
).
getYear
(),
YearMonth
.
now
().
minusMonths
(
1
).
getMonthValue
(),
Arrays
.
asList
(
1
,
2
,
3
)
);
List
<
UserPrePaidBilling
>
userPrePaidBillings1
=
userPrePaidBillingRepository
.
findByAdministratorAndYearAndMonthAndPayMethodIn
(
secondPromote
.
getName
(),
YearMonth
.
now
().
minusMonths
(
1
).
getYear
(),
YearMonth
.
now
().
minusMonths
(
1
).
getMonthValue
(),
Arrays
.
asList
(
1
,
2
,
3
)
);
secondCommission
+=
userPrePaidBillings1
.
stream
().
mapToDouble
(
UserPrePaidBilling:
:
getTotal
).
sum
();
}
}
}
}
// 4. 封装当前账户的返佣相关信息(总消费、上月消费、当月礼金、总共未体现礼金)并保存
Promotion
promotion
=
account
.
getPromotion
();
promotion
.
setTotalCommission
((
int
)(
promotion
.
getTotalCommission
()
+
totalCommission
));
promotion
.
setCommissionLastMonth
((
int
)
totalCommission
);
promotion
.
setTotalCommission
((
int
)
(
promotion
.
getTotalCommission
()
+
totalCommission
));
promotion
.
setCommissionLastMonth
((
int
)
totalCommission
);
promotion
.
setGift
(
totalCommission
*
0.08
);
if
(
account
.
getPromotion
().
isSale
())
{
promotion
.
setGift
(
totalCommission
*
0.1
+
secondCommission
*
0.02
);
...
...
@@ -65,41 +75,50 @@ public class PromotionTask {
promotion
.
setAllGift
(
promotion
.
getAllGift
()
+
promotion
.
getGift
());
accountRepository
.
save
(
account
);
}
log
.
info
(
"End scheduled task:Scheduled.countGift..."
);
}
@SchedulerLock
(
name
=
"countCommission"
,
lockAtLeastForString
=
"PT1H"
,
lockAtMostForString
=
"PT2H"
)
@Scheduled
(
cron
=
"0 0 3 * * ?"
)
public
void
countCommission
()
{
log
.
info
(
"Start scheduled task:Scheduled.countCommission..."
);
List
<
Account
>
accounts
=
accountRepository
.
findByParentIsNull
();
for
(
Account
account
:
accounts
)
{
// 1. 获取被当前账户邀请的所有账户
String
code
=
account
.
getPromotion
().
getCode
();
List
<
Account
>
promotes
=
accountRepository
.
findByPromotionCodeAndParentIsNull
(
code
);
double
totalCommission
=
0
;
double
secondCommission
=
0
;
// 2. 计算所有被当前账户邀请的账户当月当前的消费信息,以及如果当前账户是销售账户则还需要计算销售账户的下下级账户的当月当前消费信息
for
(
Account
promote
:
promotes
)
{
List
<
UserPrePaidBilling
>
userPrePaidBillings
=
userPrePaidBillingRepository
.
findByAdministratorAndYearAndMonthAndPayMethodIn
(
promote
.
getName
(),
YearMonth
.
now
().
getYear
(),
YearMonth
.
now
().
getMonthValue
(),
Arrays
.
asList
(
1
,
2
,
3
)
);
List
<
UserPrePaidBilling
>
userPrePaidBillings
=
userPrePaidBillingRepository
.
findByAdministratorAndYearAndMonthAndPayMethodIn
(
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
.
findByPromotionCodeAndParentIsNull
(
promote
.
getPromotion
().
getCode
());
if
(
secondPromotes
!=
null
&&
secondPromotes
.
size
()
>
0
)
{
for
(
Account
secondPromote
:
secondPromotes
)
{
List
<
UserPrePaidBilling
>
userPrePaidBillings1
=
userPrePaidBillingRepository
.
findByAdministratorAndYearAndMonthAndPayMethodIn
(
secondPromote
.
getName
(),
YearMonth
.
now
().
getYear
(),
YearMonth
.
now
().
getMonthValue
(),
Arrays
.
asList
(
1
,
2
,
3
)
);
List
<
UserPrePaidBilling
>
userPrePaidBillings1
=
userPrePaidBillingRepository
.
findByAdministratorAndYearAndMonthAndPayMethodIn
(
secondPromote
.
getName
(),
YearMonth
.
now
().
getYear
(),
YearMonth
.
now
().
getMonthValue
(),
Arrays
.
asList
(
1
,
2
,
3
)
);
secondCommission
+=
userPrePaidBillings1
.
stream
().
mapToDouble
(
UserPrePaidBilling:
:
getTotal
).
sum
();
}
}
}
}
// 3. 封装当前账户的返佣相关信息(当月当前的消费、当月当前的返佣)并保存
Promotion
promotion
=
account
.
getPromotion
();
promotion
.
setCommission
((
int
)
totalCommission
);
promotion
.
setCommission
((
int
)
totalCommission
);
promotion
.
setGift
(
totalCommission
*
0.08
);
if
(
account
.
getPromotion
().
isSale
())
{
promotion
.
setGift
(
totalCommission
*
0.1
+
secondCommission
*
0.02
);
}
accountRepository
.
save
(
account
);
}
log
.
info
(
"End scheduled task:Scheduled.countCommission..."
);
}
}
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