Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ufo
/
yohoufo-fore
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
sailing-PC\sailing
7 years ago
Commit
79f5c975961a83f46313205b268517ab2945b665
1 parent
ecfdc07f
add test
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
142 additions
and
12 deletions
order/pom.xml
order/src/main/java/com/yohoufo/order/model/dto/PlatformFeeDto.java
order/src/main/java/com/yohoufo/order/service/SellerOrderService.java
order/src/test/java/com/yohoufo/order/service/SellerOrderServiceTest.java
order/yohoufo-fore-order.iml
payment/yohoufo-fore-payment.iml
order/pom.xml
View file @
79f5c97
...
...
@@ -29,6 +29,10 @@
<artifactId>
order-ufo-model
</artifactId>
</dependency>
<dependency>
<groupId>
com.yohoufo.fore
</groupId>
<artifactId>
yohoufo-fore-product
</artifactId>
</dependency>
<dependency>
<groupId>
com.yoho.core
</groupId>
...
...
order/src/main/java/com/yohoufo/order/model/dto/PlatformFeeDto.java
0 → 100644
View file @
79f5c97
package
com
.
yohoufo
.
order
.
model
.
dto
;
import
lombok.Data
;
import
java.math.BigDecimal
;
/**
* Created by chenchao on 2018/9/14.
*/
@Data
public
class
PlatformFeeDto
{
BigDecimal
total
;
BigDecimal
appraiseFee
;
BigDecimal
packageFee
;
BigDecimal
serviceFee
;
}
...
...
order/src/main/java/com/yohoufo/order/service/SellerOrderService.java
View file @
79f5c97
...
...
@@ -7,13 +7,18 @@ import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
import
com.yohobuy.ufo.model.order.req.SellerOrderComputeReq
;
import
com.yohoufo.common.exception.GatewayException
;
import
com.yohoufo.common.http.URLHolder
;
import
com.yohoufo.common.utils.BigDecimalHelper
;
import
com.yohoufo.common.utils.PriceFormater
;
import
com.yohoufo.dal.order.SellerOrderMapper
;
import
com.yohoufo.order.model.dto.PlatformFeeDto
;
import
com.yohoufo.product.response.StorageLeastPriceResp
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.math.BigDecimal
;
import
java.util.Objects
;
/**
* Created by chenchao on 2018/9/13.
...
...
@@ -31,17 +36,23 @@ public class SellerOrderService {
@Autowired
private
URLHolder
urlHolder
;
private
static
final
BigDecimal
[]
EARNESTMONEYRANGE
=
{
new
BigDecimal
(
28
),
new
BigDecimal
(
200
)};
public
SoldPrdComputeBo
computePublishPrd
(
SellerOrderComputeReq
req
)
throws
GatewayException
{
log
.
info
(
"in computePublishPrd, req {}"
,
req
);
SoldPrdComputeBo
computeBo
=
null
;
//TODO
String
baseUrl
=
urlHolder
.
getUrl
();
String
apiParam
=
"?method=ufo.product.storage.leastprice"
;
String
fullUrl
=
baseUrl
+
apiParam
;
Object
params
=
new
Object
();
AsyncFuture
<
Object
>
future
=
serviceCaller
.
post
(
"product.getFloorPrice"
,
fullUrl
,
params
,
Object
.
class
,
new
Object
());
Object
resp
=
future
.
get
();
AsyncFuture
<
StorageLeastPriceResp
.
StorageLeastPrice
>
future
=
serviceCaller
.
post
(
"product.getFloorPrice"
,
fullUrl
,
params
,
StorageLeastPriceResp
.
StorageLeastPrice
.
class
,
null
);
StorageLeastPriceResp
.
StorageLeastPrice
resp
=
future
.
get
();
BigDecimal
leastPrice
;
if
(
Objects
.
isNull
(
resp
)
||
Objects
.
isNull
(
leastPrice
=
resp
.
getLeastPrice
())
||
leastPrice
.
doubleValue
()
==
0
D
){
throw
new
GatewayException
(
501
,
"暂无商品"
);
}
/*商品鉴定费 ¥10.00
商品包装费 ¥10.00
平台服务费(5%,优惠期间0%) ¥0.00
...
...
@@ -52,19 +63,93 @@ public class SellerOrderService {
throw
new
GatewayException
(
400
,
"没有价格"
);
}
try
{
BigDecimal
prdPrice
=
new
BigDecimal
(
price
);
String
earnestMoneyStr
;
PlatformFee
platformFee
;
String
incomeStr
;
//保证金(28-200(按照卖家发布商品的货款金额5%计算,最低28,封顶200));
BigDecimal
prdPrice
=
null
;
try
{
prdPrice
=
new
BigDecimal
(
price
);
}
catch
(
Exception
e
){
log
.
warn
(
"in computePublishPrd price convert BigDecimal fail, {}"
,
req
);
return
null
;
}
if
(
prdPrice
.
subtract
(
leastPrice
).
doubleValue
()
<
0
D
){
log
.
warn
(
"in computePublishPrd,leastPrice {}, req {}"
,
leastPrice
,
req
);
throw
new
GatewayException
(
501
,
"设定的价格低于商品最低价"
);
}
return
buildSoldPrdComputeBo
(
prdPrice
);
}
public
SoldPrdComputeBo
buildSoldPrdComputeBo
(
BigDecimal
prdPrice
){
//保证金(28-200(按照卖家发布商品的货款金额5%计算,最低28,封顶200))
BigDecimal
earnestMoney
=
calEarnestMoney
(
prdPrice
);
//银行转账费(0.65%+¥1.00)
BigDecimal
bankTransferfee
=
calBankTransferFee
(
prdPrice
);
PlatformFeeDto
platformFeeDto
=
calPlatformFee
();
BigDecimal
income
=
calIncome
(
prdPrice
,
platformFeeDto
.
getTotal
(),
bankTransferfee
);
//
PlatformFee
platformFeeWrapper
=
PlatformFee
.
builder
()
.
appraiseFee
(
formatFee
(
platformFeeDto
.
getAppraiseFee
()))
.
packageFee
(
formatFee
(
platformFeeDto
.
getPackageFee
()))
.
serviceFee
(
formatFee
(
platformFeeDto
.
getServiceFee
())).
build
();
//
String
incomeStr
=
formatFee
(
income
);
String
earnestMoneyStr
=
formatFee
(
earnestMoney
);
String
bankTransferFeeStr
=
formatFee
(
bankTransferfee
);
SoldPrdComputeBo
computeBo
=
SoldPrdComputeBo
.
builder
()
.
earnestMoney
(
earnestMoneyStr
)
.
bankTransferFee
(
bankTransferFeeStr
)
.
platformFee
(
platformFeeWrapper
)
.
income
(
incomeStr
)
.
build
();
return
computeBo
;
}
private
BigDecimal
calBankTransferFee
(
BigDecimal
prdPrice
){
//银行转账费(0.65%+¥1.00)
return
prdPrice
.
multiply
(
new
BigDecimal
(
0.0065
)).
add
(
new
BigDecimal
(
1
));
}
private
BigDecimal
calIncome
(
BigDecimal
prdPrice
,
BigDecimal
platformFee
,
BigDecimal
bankTransferfee
){
return
prdPrice
.
subtract
(
platformFee
).
subtract
(
bankTransferfee
);
}
private
PlatformFeeDto
calPlatformFee
(){
BigDecimal
appraiseFee
=
new
BigDecimal
(
10
);;
BigDecimal
packageFee
=
new
BigDecimal
(
10
);
BigDecimal
serviceFee
=
new
BigDecimal
(
0
);
BigDecimal
total
=
appraiseFee
.
add
(
packageFee
).
add
(
serviceFee
);
PlatformFeeDto
platformFee
=
new
PlatformFeeDto
();
platformFee
.
setTotal
(
total
);
platformFee
.
setAppraiseFee
(
appraiseFee
);
platformFee
.
setPackageFee
(
packageFee
);
platformFee
.
setServiceFee
(
serviceFee
);
return
platformFee
;
}
private
String
formatFee
(
BigDecimal
fee
){
return
PriceFormater
.
addCnCurrencySymbol
(
BigDecimalHelper
.
formatNumber
(
fee
,
BigDecimalHelper
.
FORMAT_TWOBITAFTERPOINT
));
}
private
BigDecimal
calEarnestMoney
(
BigDecimal
prdPrice
){
BigDecimal
real
=
prdPrice
.
multiply
(
new
BigDecimal
(
0.05
));
final
BigDecimal
min
=
EARNESTMONEYRANGE
[
0
];
final
BigDecimal
max
=
EARNESTMONEYRANGE
[
1
];
if
(
real
.
subtract
(
min
).
doubleValue
()
<
0
D
){
return
min
;
}
if
(
real
.
subtract
(
max
).
doubleValue
()
>
0
D
){
return
max
;
}
return
real
;
}
}
...
...
order/src/test/java/com/yohoufo/order/service/SellerOrderServiceTest.java
0 → 100644
View file @
79f5c97
package
com
.
yohoufo
.
order
.
service
;
import
com.alibaba.fastjson.JSONObject
;
import
com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo
;
import
org.junit.Test
;
import
java.math.BigDecimal
;
/**
* Created by chenchao on 2018/9/14.
*/
public
class
SellerOrderServiceTest
{
@Test
public
void
testBuildSoldPrdComputeBo
(){
SellerOrderService
sos
=
new
SellerOrderService
();
BigDecimal
prdPrice
=
new
BigDecimal
(
123.44
);
SoldPrdComputeBo
bo
=
sos
.
buildSoldPrdComputeBo
(
prdPrice
);
System
.
out
.
println
(
"in testBuildSoldPrdComputeBo :"
+
JSONObject
.
toJSONString
(
bo
));
}
}
...
...
order/yohoufo-fore-order.iml
View file @
79f5c97
...
...
@@ -6,6 +6,7 @@
<content
url=
"file://$MODULE_DIR$"
>
<sourceFolder
url=
"file://$MODULE_DIR$/src/main/resources"
type=
"java-resource"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/main/java"
isTestSource=
"false"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/java"
isTestSource=
"true"
/>
<excludeFolder
url=
"file://$MODULE_DIR$/target"
/>
</content>
<orderEntry
type=
"inheritedJdk"
/>
...
...
@@ -118,6 +119,7 @@
<orderEntry
type=
"library"
name=
"Maven: org.mybatis:mybatis:3.2.6"
level=
"project"
/>
<orderEntry
type=
"library"
name=
"Maven: mysql:mysql-connector-java:5.1.30"
level=
"project"
/>
<orderEntry
type=
"module"
module-name=
"order-ufo-model"
/>
<orderEntry
type=
"module"
module-name=
"yohoufo-fore-product"
/>
<orderEntry
type=
"module"
module-name=
"yoho-core-rest-client-simple"
/>
<orderEntry
type=
"library"
name=
"Maven: org.springframework:spring-context:4.3.8.RELEASE"
level=
"project"
/>
<orderEntry
type=
"library"
name=
"Maven: org.yaml:snakeyaml:1.14"
level=
"project"
/>
...
...
payment/yohoufo-fore-payment.iml
View file @
79f5c97
...
...
@@ -150,6 +150,7 @@
<orderEntry
type=
"library"
name=
"Maven: org.mybatis:mybatis:3.2.6"
level=
"project"
/>
<orderEntry
type=
"library"
name=
"Maven: mysql:mysql-connector-java:5.1.30"
level=
"project"
/>
<orderEntry
type=
"module"
module-name=
"order-ufo-model"
/>
<orderEntry
type=
"module"
module-name=
"yohoufo-fore-product"
/>
<orderEntry
type=
"library"
scope=
"PROVIDED"
name=
"Maven: javax.servlet:javax.servlet-api:3.1.0"
level=
"project"
/>
<orderEntry
type=
"library"
scope=
"TEST"
name=
"Maven: junit:junit:4.12"
level=
"project"
/>
<orderEntry
type=
"library"
scope=
"TEST"
name=
"Maven: org.hamcrest:hamcrest-core:1.3"
level=
"project"
/>
...
...
Please
register
or
login
to post a comment