Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
order-group
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
order-group-application
order-group
Commits
f852f9a9
Commit
f852f9a9
authored
Aug 09, 2020
by
xiaoer.li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加料均摊
parent
a4888c28
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
17 deletions
+28
-17
shopping-cart-application-service/src/main/java/cn/freemud/adapter/ShoppingCartConvertAdapter.java
+15
-7
shopping-cart-application-service/src/main/java/cn/freemud/service/impl/DefaultPromotionService.java
+1
-1
shopping-cart-application-service/src/main/java/cn/freemud/service/impl/MaterialPromotionService.java
+12
-9
No files found.
shopping-cart-application-service/src/main/java/cn/freemud/adapter/ShoppingCartConvertAdapter.java
View file @
f852f9a9
...
...
@@ -134,7 +134,8 @@ public class ShoppingCartConvertAdapter {
||
ObjectUtils
.
equals
(
ActivityTypeEnum
.
TYPE_62
.
getCode
(),
cartGoods
.
getActivityType
()))
{
cartGoodsDetailDto
.
setTotalDiscountAmount
(
cartGoods
.
getOriginalAmount
().
intValue
()
-
cartGoods
.
getAmount
().
intValue
());
}
else
{
List
<
ActivityCalculationDiscountResponseDto
.
CalculationDiscountResult
.
ApportionGoods
>
collect
=
apportionGoodsList
.
stream
().
filter
(
a
->
ObjectUtils
.
equals
(
cartGoods
.
getSkuId
(),
a
.
getGoodsId
())
||
ObjectUtils
.
equals
(
cartGoods
.
getSpuId
(),
a
.
getGoodsId
())).
collect
(
Collectors
.
toList
());
List
<
ActivityCalculationDiscountResponseDto
.
CalculationDiscountResult
.
ApportionGoods
>
collect
=
apportionGoodsList
.
stream
().
filter
(
a
->
ObjectUtils
.
equals
(
cartGoods
.
getCartGoodsUid
(),
a
.
getCartGoodsUid
())).
collect
(
Collectors
.
toList
());
//List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods> collect = apportionGoodsList.stream().filter(a -> ObjectUtils.equals(cartGoods.getSkuId(), a.getGoodsId()) || ObjectUtils.equals(cartGoods.getSpuId(), a.getGoodsId())).collect(Collectors.toList());
if
(
CollectionUtils
.
isNotEmpty
(
collect
))
{
setTotalDiscountAndSalePrice
(
collect
,
cartGoodsDetailDto
,
duplicateGoodsMap
);
// 设置商品行,优惠活动均摊
...
...
@@ -172,6 +173,7 @@ public class ShoppingCartConvertAdapter {
}
/**
* 活动级别的促销均摊
* 获取当前商品的售后价格
*
* @param apportionGoodsList 促销均摊列表
...
...
@@ -187,19 +189,19 @@ public class ShoppingCartConvertAdapter {
for
(
ActivityCalculationDiscountResponseDto
.
CalculationDiscountResult
.
ApportionGoods
apportionGoods
:
apportionGoodsList
)
{
//折扣=所有折扣和*百分比(当前行商品数量/购物车总商品数量)
discountPrice
+=
apportionGoods
.
getApportionDetails
().
stream
().
filter
(
d
->
ObjectUtils
.
notEqual
(
ActivityTypeEnum
.
TYPE_32
.
getCode
(),
d
.
getActivityType
())
&&
ObjectUtils
.
notEqual
(
ActivityTypeEnum
.
TYPE_104
.
getCode
(),
d
.
getActivityType
())
&&
ObjectUtils
.
notEqual
(
ActivityTypeEnum
.
TYPE_2
.
getCode
(),
d
.
getActivityType
())
&&
ObjectUtils
.
notEqual
(
ActivityTypeEnum
.
TYPE_21
.
getCode
(),
d
.
getActivityType
())
&&
ObjectUtils
.
notEqual
(
ActivityTypeEnum
.
TYPE_104
.
getCode
(),
d
.
getActivityType
())
//X件Y折
&&
ObjectUtils
.
notEqual
(
ActivityTypeEnum
.
TYPE_2
.
getCode
(),
d
.
getActivityType
())
//单品特价
&&
ObjectUtils
.
notEqual
(
ActivityTypeEnum
.
TYPE_21
.
getCode
(),
d
.
getActivityType
())
//单品折扣
).
mapToLong
(
t
->
t
.
getActivityApportionAmount
()
*
apportionGoods
.
getGoodsQuantity
()).
sum
()
*
cartGoodsDetailDto
.
getQty
()
/
goodsTotalQty
;
}
String
currentGoodsIdMap
=
duplicateGoodsMap
.
get
(
cartGoodsDetailDto
.
get
SkuI
d
());
String
currentGoodsIdMap
=
duplicateGoodsMap
.
get
(
cartGoodsDetailDto
.
get
CartGoodsUi
d
());
if
(
currentGoodsIdMap
!=
null
)
{
String
[]
value
=
currentGoodsIdMap
.
split
(
","
);
//不是最后一行商品,折扣为discountPrice
if
(
Integer
.
parseInt
(
value
[
0
])
>
1
)
{
int
totalDiscountPrice
=
Integer
.
parseInt
(
value
[
1
])
+
discountPrice
.
intValue
();
int
index
=
Integer
.
parseInt
(
value
[
0
])
-
1
;
duplicateGoodsMap
.
put
(
cartGoodsDetailDto
.
get
SkuI
d
(),
String
.
format
(
"%s,%s"
,
index
,
totalDiscountPrice
));
duplicateGoodsMap
.
put
(
cartGoodsDetailDto
.
get
CartGoodsUi
d
(),
String
.
format
(
"%s,%s"
,
index
,
totalDiscountPrice
));
}
else
{
//最后一行
Long
totalDiscountAmount
=
0L
;
...
...
@@ -443,4 +445,9 @@ public class ShoppingCartConvertAdapter {
String
skuId
=
StringUtils
.
isNotBlank
(
addShoppingCartGoodsRequestVo
.
getSkuId
())
?
addShoppingCartGoodsRequestVo
.
getSkuId
()
:
""
;
addShoppingCartGoodsRequestVo
.
setSkuId
(
skuId
);
}
}
public
String
jointPk
(
String
a
,
String
b
)
{
StringBuffer
stringBuffer
=
new
StringBuffer
();
return
stringBuffer
.
append
(
a
).
append
(
b
).
toString
();
}
}
\ No newline at end of file
shopping-cart-application-service/src/main/java/cn/freemud/service/impl/DefaultPromotionService.java
View file @
f852f9a9
...
...
@@ -86,7 +86,7 @@ public class DefaultPromotionService implements IPromotionService {
calculationDiscountResult
==
null
?
new
ArrayList
<>()
:
calculationDiscountResult
.
getApportionGoods
();
Map
<
String
,
String
>
duplicateGoodsMap
=
new
HashMap
<>();
cartGoodsList
.
stream
().
collect
(
Collectors
.
groupingBy
(
CartGoods:
:
get
GoodsI
d
,
Collectors
.
counting
())).
forEach
((
goodsId
,
count
)
->
{
cartGoodsList
.
stream
().
collect
(
Collectors
.
groupingBy
(
CartGoods:
:
get
CartGoodsUi
d
,
Collectors
.
counting
())).
forEach
((
goodsId
,
count
)
->
{
duplicateGoodsMap
.
put
(
goodsId
,
String
.
format
(
"%s,0"
,
count
));
});
for
(
int
i
=
0
,
len
=
cartGoodsList
.
size
();
i
<
len
;
i
++)
{
...
...
shopping-cart-application-service/src/main/java/cn/freemud/service/impl/MaterialPromotionService.java
View file @
f852f9a9
package
cn
.
freemud
.
service
.
impl
;
import
cn.freemud.adapter.ShoppingCartConvertAdapter
;
import
cn.freemud.entities.dto.ActivityCalculationDiscountResponseDto
;
import
cn.freemud.entities.dto.UserLoginInfoDto
;
import
cn.freemud.entities.dto.activity.ActivityDiscountsDto
;
...
...
@@ -10,6 +11,7 @@ import cn.freemud.enums.GoodsTypeEnum;
import
cn.freemud.service.IPromotionService
;
import
lombok.Data
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
...
...
@@ -28,7 +30,8 @@ import java.util.List;
*/
@Service
(
"MaterialPromotionService"
)
public
class
MaterialPromotionService
implements
IPromotionService
{
@Autowired
private
ShoppingCartConvertAdapter
shoppingCartConvertAdapter
;
/**
* 总优惠和总原价促进已经计算过了,这里只需要累积行记录
* 加料优惠金额
...
...
@@ -96,7 +99,7 @@ public class MaterialPromotionService implements IPromotionService {
for
(
ShoppingCartGoodsDto
.
CartGoodsDetailDto
product
:
products
)
{
if
(
CollectionUtils
.
isEmpty
(
product
.
getMaterialList
()))
continue
;
for
(
ShoppingCartGoodsDto
.
CartGoodsDetailDto
.
MaterialGoods
materialGoods
:
product
.
getMaterialList
())
{
pk
=
this
.
jointPk
(
product
.
getCartGoodsUid
(),
materialGoods
.
getSpuId
());
pk
=
shoppingCartConvertAdapter
.
jointPk
(
product
.
getCartGoodsUid
(),
materialGoods
.
getSpuId
());
MaterialApportion
material
=
map
.
get
(
pk
);
if
(
material
!=
null
&&
material
.
getApportionAmount
().
intValue
()
==
0
)
continue
;
//设置行记录参加的活动及总优惠
...
...
@@ -109,7 +112,8 @@ public class MaterialPromotionService implements IPromotionService {
activityDiscountsDtoList
.
add
(
activityDiscountsDto
);
materialGoods
.
setActivityDiscountsDtos
(
activityDiscountsDtoList
);
materialGoods
.
setTotalDiscountAmount
((
materialGoods
.
getOriginalPrice
().
intValue
()
-
materialGoods
.
getSalePrice
().
intValue
())
*
product
.
getQty
());
//materialGoods.setTotalDiscountAmount((materialGoods.getOriginalPrice().intValue() - materialGoods.getSalePrice().intValue()) * product.getQty());
materialGoods
.
setTotalDiscountAmount
(
material
.
getTotalDiscountAmount
());
product
.
setProductType
(
GoodsTypeEnum
.
MATERIAL
.
getGoodsType
());
}
}
...
...
@@ -144,13 +148,14 @@ public class MaterialPromotionService implements IPromotionService {
for
(
ActivityCalculationDiscountResponseDto
.
CalculationDiscountResult
.
ApportionGoods
.
Material
material
:
apportionGood
.
getSmallMaterial
())
{
if
(
material
.
getApportionAmount
()
==
0
)
continue
;
pk
=
this
.
jointPk
(
material
.
getCartGoodsUid
(),
material
.
getGoodsId
());
pk
=
shoppingCartConvertAdapter
.
jointPk
(
material
.
getCartGoodsUid
(),
material
.
getGoodsId
());
if
(
mApportion
.
get
(
pk
)
==
null
)
{
MaterialApportion
materialApportion
=
new
MaterialApportion
();
materialApportion
.
setSalePrice
(
material
.
getNowPrice
());
materialApportion
.
setAmount
(
material
.
getNowPrice
()
*
material
.
getGoodsQuantity
());
materialApportion
.
setApportionAmount
(
material
.
getApportionAmount
()
*
material
.
getGoodsQuantity
());
materialApportion
.
setGoodsId
(
material
.
getGoodsId
());
materialApportion
.
setTotalDiscountAmount
(
material
.
getApportionAmount
()*
material
.
getGoodsQuantity
());
materialApportion
.
setPk
(
pk
);
ApportionDetails
apportionDetails
=
new
ApportionDetails
();
if
(
CollectionUtils
.
isNotEmpty
(
material
.
getApportionDetails
()))
{
...
...
@@ -166,23 +171,21 @@ public class MaterialPromotionService implements IPromotionService {
apportion
.
setSalePrice
(
apportion
.
getSalePrice
()
+
material
.
getNowPrice
());
apportion
.
setAmount
(
apportion
.
getAmount
()
+
material
.
getNowPrice
()
*
material
.
getGoodsQuantity
());
apportion
.
setApportionAmount
(
apportion
.
getApportionAmount
()
+
material
.
getApportionAmount
()
*
material
.
getGoodsQuantity
());
apportion
.
setTotalDiscountAmount
(
apportion
.
getTotalDiscountAmount
()+
material
.
getApportionAmount
()*
material
.
getGoodsQuantity
());
mApportion
.
put
(
pk
,
apportion
);
}
}
return
mApportion
;
}
private
String
jointPk
(
String
a
,
String
b
)
{
StringBuffer
stringBuffer
=
new
StringBuffer
();
return
stringBuffer
.
append
(
a
).
append
(
b
).
toString
();
}
@Data
private
class
MaterialApportion
{
private
String
goodsId
;
private
Long
salePrice
;
private
Long
amount
;
private
Integer
apportionAmount
;
//优惠金额
private
Integer
totalDiscountAmount
;
private
ApportionDetails
details
;
private
String
pk
;
}
...
...
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