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
a780b5c7
Commit
a780b5c7
authored
Dec 13, 2020
by
刘鹏飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coco结算页拆行
parent
59749faf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
121 additions
and
66 deletions
+121
-66
shopping-cart-application-service/src/main/java/cn/freemud/service/shoppingCart/impl/CocoShoppingCartRelationServiceImpl.java
+121
-66
No files found.
shopping-cart-application-service/src/main/java/cn/freemud/service/shoppingCart/impl/CocoShoppingCartRelationServiceImpl.java
View file @
a780b5c7
...
@@ -93,88 +93,44 @@ public class CocoShoppingCartRelationServiceImpl implements ShoppingCartRelation
...
@@ -93,88 +93,44 @@ public class CocoShoppingCartRelationServiceImpl implements ShoppingCartRelation
});
});
});
});
List
<
CartGoods
>
newProducts
=
new
ArrayList
<>();
if
(!
Objects
.
equals
(
flag
,
1
)){
// 非结算页
if
(!
Objects
.
equals
(
flag
,
1
)){
// 非结算页
orderingFoodPage
(
products
,
halfDiscountsMap
,
goodsDiscountsMap
,
gifeProductIds
,
shoppingCartGoodsResponseVo
);
}
else
{
// 结算页
// 第二件优惠活动(单品优惠)要把一行商品分成多行,且每行商品数量是1,同时要有两行是打活动标的
List
<
CartGoods
>
newProducts
=
new
ArrayList
<>();
if
(
products
==
null
||
products
.
isEmpty
()){
if
(
products
==
null
||
products
.
isEmpty
()){
return
;
return
;
}
}
List
<
CartGoods
>
halfProduct
=
new
ArrayList
<>();
List
<
CartGoods
>
halfProduct
=
new
ArrayList
<>();
for
(
int
x
=
0
;
x
<
products
.
size
()
;
x
++){
for
(
int
x
=
0
;
x
<
products
.
size
()
;
x
++){
CartGoods
product
=
products
.
get
(
x
);
CartGoods
product
=
products
.
get
(
x
);
// 要添加的半价行数量,该字段从促销返回
// 这一行的商品参加了第二件优惠活动(单品优惠)
Integer
num
=
0
;
if
(
halfDiscountsMap
.
get
(
product
.
getCartGoodsUid
()
+
"-"
+
product
.
getGoodsId
())
!=
null
){
// 商品优惠的金额
// 行商品数量
Long
discountAmount
=
0L
;
Integer
num
=
product
.
getQty
();
if
(
halfDiscountsMap
.
get
(
product
.
getCartGoodsUid
()
+
"-"
+
product
.
getGoodsId
())
!=
null
){
CalculationSharingDiscountResponseDto
.
CalculationDiscountResult
.
Goods
.
GoodsDiscount
discount
=
halfDiscountsMap
.
get
(
product
.
getCartGoodsUid
()
+
"-"
+
product
.
getGoodsId
());
if
(
discount
==
null
){
return
;
}
num
=
discount
.
getActualGoodsNumber
();
for
(
int
i
=
0
;
i
<
num
;
i
++){
for
(
int
i
=
0
;
i
<
num
;
i
++){
// 第二件优惠活动,在点餐页需要给优惠商品单独显示一行
// 复制商品加到购物车
discountAmount
=
discount
.
getDiscount
();
Long
newPrice
=
product
.
getOriginalPrice
()
-
discountAmount
;
// 构建半价行
// 构建半价行
CartGoods
cartGoods
=
buildNewLine
(
product
,
ActivityTypeEnum
.
TYPE_53
.
getCode
(),
1
,
newPrice
);
CartGoods
cartGoods
=
new
CartGoods
();
halfProduct
.
add
(
cartGoods
);
if
(
i
<
2
){
}
cartGoods
=
buildNewLine
(
product
,
ActivityTypeEnum
.
TYPE_53
.
getCode
(),
1
,
product
.
getFinalPrice
(),
product
.
getGoodsId
());
}
}
else
{
Integer
newQty
=
product
.
getQty
()
-
num
;
cartGoods
=
buildNewLine
(
product
,
ActivityTypeEnum
.
TYPE_53
.
getCode
(),
1
,
product
.
getFinalPrice
(),
null
);
// 数量减去购物车行之后如果为0就不加入购物车
// 主商品行要数量,价格
if
(!
Objects
.
equals
(
newQty
,
0
)){
product
.
setAmount
(
product
.
getAmount
()
-
discountAmount
*
num
);
product
.
setOriginalAmount
(
product
.
getOriginalAmount
()
-
product
.
getOriginalPrice
()
*
num
);
product
.
setQty
(
newQty
);
// 商品是否参加特价
boolean
cutFlag
=
false
;
if
(
goodsDiscountsMap
.
get
(
product
.
getCartGoodsUid
())
!=
null
){
CalculationSharingDiscountResponseDto
.
CalculationDiscountResult
.
Goods
goods
=
goodsDiscountsMap
.
get
(
product
.
getCartGoodsUid
());
List
<
CalculationSharingDiscountResponseDto
.
CalculationDiscountResult
.
Goods
.
GoodsDiscount
>
goodsDiscountsList
=
goods
.
getDiscounts
();
if
(
goodsDiscountsList
!=
null
&&
!
goodsDiscountsList
.
isEmpty
()){
for
(
CalculationSharingDiscountResponseDto
.
CalculationDiscountResult
.
Goods
.
GoodsDiscount
gd
:
goodsDiscountsList
){
if
(
ObjectUtils
.
equals
(
gd
.
getType
(),
ActivityTypeEnum
.
TYPE_2
.
getCode
())){
cutFlag
=
true
;
break
;
}
}
}
}
}
if
(
cutFlag
){
newProducts
.
add
(
cartGoods
);
product
.
setFinalPrice
(
goodsDiscountsMap
.
get
(
product
.
getCartGoodsUid
()).
getNowPrice
());
}
// num代表拆出来的半价行数量
// 所以只要不等于0就需要把ActivityType设置为空
// 因为前端用这个判断是否能加减
if
(!
Objects
.
equals
(
num
,
0
)){
product
.
setActivityType
(
null
);
}
}
continue
;
// num代表拆出来的半价行数量,gifeProductIds代表赠品
// 只要符合条件就需要设置为空
// 因为前端指挥在半价行、赠品行上打标
// 前端是从商品活动信息中查找活动,在商品列表中找商品
if
((
gifeProductIds
.
contains
(
product
.
getGoodsId
())
&&
product
.
getActivityType
()
==
null
)
||
!
Objects
.
equals
(
num
,
0
)){
product
.
setGoodsId
(
null
);
}
newProducts
.
add
(
product
);
}
}
}
// 半价商品加到购物车
newProducts
.
addAll
(
halfProduct
);
newProducts
.
add
(
product
);
}
shoppingCartGoodsResponseVo
.
setProducts
(
newProducts
);
shoppingCartGoodsResponseVo
.
setProducts
(
newProducts
);
}
}
}
}
...
@@ -217,7 +173,7 @@ public class CocoShoppingCartRelationServiceImpl implements ShoppingCartRelation
...
@@ -217,7 +173,7 @@ public class CocoShoppingCartRelationServiceImpl implements ShoppingCartRelation
}
}
public
CartGoods
buildNewLine
(
CartGoods
cgs
,
Integer
activityType
,
Integer
qty
,
Long
newPrice
){
public
CartGoods
buildNewLine
(
CartGoods
cgs
,
Integer
activityType
,
Integer
qty
,
Long
newPrice
,
String
goodsId
){
CartGoods
newCartGoods
=
new
CartGoods
();
CartGoods
newCartGoods
=
new
CartGoods
();
// 购物车的行设置和原来的行一致,便于前端在更新商品数量的时候。能够根据购物车行聚合商品数量
// 购物车的行设置和原来的行一致,便于前端在更新商品数量的时候。能够根据购物车行聚合商品数量
// 因为半价行是从主行中拆出来的
// 因为半价行是从主行中拆出来的
...
@@ -225,7 +181,7 @@ public class CocoShoppingCartRelationServiceImpl implements ShoppingCartRelation
...
@@ -225,7 +181,7 @@ public class CocoShoppingCartRelationServiceImpl implements ShoppingCartRelation
// 这个地方不要放置商品id,因为半价行的商品不打活动标签
// 这个地方不要放置商品id,因为半价行的商品不打活动标签
// 前端会根据这个活动检索
// 前端会根据这个活动检索
newCartGoods
.
setGoodsType
(
cgs
.
getGoodsType
());
newCartGoods
.
setGoodsType
(
cgs
.
getGoodsType
());
newCartGoods
.
setGoodsId
(
cgs
.
getGoodsId
()
);
newCartGoods
.
setGoodsId
(
goodsId
);
newCartGoods
.
setSpuId
(
cgs
.
getSpuId
());
newCartGoods
.
setSpuId
(
cgs
.
getSpuId
());
newCartGoods
.
setSkuId
(
cgs
.
getSkuId
());
newCartGoods
.
setSkuId
(
cgs
.
getSkuId
());
newCartGoods
.
setSpecProductId
(
cgs
.
getSpecProductId
());
newCartGoods
.
setSpecProductId
(
cgs
.
getSpecProductId
());
...
@@ -267,4 +223,103 @@ public class CocoShoppingCartRelationServiceImpl implements ShoppingCartRelation
...
@@ -267,4 +223,103 @@ public class CocoShoppingCartRelationServiceImpl implements ShoppingCartRelation
return
newCartGoods
;
return
newCartGoods
;
}
}
public
void
settlementPage
(){
}
/**
* 点餐页
* @param products
* @param halfDiscountsMap
* @param goodsDiscountsMap
* @param gifeProductIds
* @param shoppingCartGoodsResponseVo
*/
public
void
orderingFoodPage
(
List
<
CartGoods
>
products
,
Map
<
String
,
CalculationSharingDiscountResponseDto
.
CalculationDiscountResult
.
Goods
.
GoodsDiscount
>
halfDiscountsMap
,
Map
<
String
,
CalculationSharingDiscountResponseDto
.
CalculationDiscountResult
.
Goods
>
goodsDiscountsMap
,
List
<
String
>
gifeProductIds
,
ShoppingCartGoodsResponseVo
shoppingCartGoodsResponseVo
){
List
<
CartGoods
>
newProducts
=
new
ArrayList
<>();
if
(
products
==
null
||
products
.
isEmpty
()){
return
;
}
List
<
CartGoods
>
halfProduct
=
new
ArrayList
<>();
for
(
int
x
=
0
;
x
<
products
.
size
()
;
x
++){
CartGoods
product
=
products
.
get
(
x
);
// 要添加的半价行数量,该字段从促销返回
Integer
num
=
0
;
// 商品优惠的金额
Long
discountAmount
=
0L
;
if
(
halfDiscountsMap
.
get
(
product
.
getCartGoodsUid
()
+
"-"
+
product
.
getGoodsId
())
!=
null
){
CalculationSharingDiscountResponseDto
.
CalculationDiscountResult
.
Goods
.
GoodsDiscount
discount
=
halfDiscountsMap
.
get
(
product
.
getCartGoodsUid
()
+
"-"
+
product
.
getGoodsId
());
if
(
discount
==
null
){
return
;
}
num
=
discount
.
getActualGoodsNumber
();
for
(
int
i
=
0
;
i
<
num
;
i
++){
// 第二件优惠活动,在点餐页需要给优惠商品单独显示一行
// 复制商品加到购物车
discountAmount
=
discount
.
getDiscount
();
Long
newPrice
=
product
.
getOriginalPrice
()
-
discountAmount
;
// 构建半价行
CartGoods
cartGoods
=
buildNewLine
(
product
,
ActivityTypeEnum
.
TYPE_53
.
getCode
(),
1
,
newPrice
,
product
.
getGoodsId
());
halfProduct
.
add
(
cartGoods
);
}
}
Integer
newQty
=
product
.
getQty
()
-
num
;
// 数量减去购物车行之后如果为0就不加入购物车
// 主商品行要数量,价格
if
(!
Objects
.
equals
(
newQty
,
0
)){
product
.
setAmount
(
product
.
getAmount
()
-
discountAmount
*
num
);
product
.
setOriginalAmount
(
product
.
getOriginalAmount
()
-
product
.
getOriginalPrice
()
*
num
);
product
.
setQty
(
newQty
);
// 商品是否参加特价
boolean
cutFlag
=
false
;
if
(
goodsDiscountsMap
.
get
(
product
.
getCartGoodsUid
())
!=
null
){
CalculationSharingDiscountResponseDto
.
CalculationDiscountResult
.
Goods
goods
=
goodsDiscountsMap
.
get
(
product
.
getCartGoodsUid
());
List
<
CalculationSharingDiscountResponseDto
.
CalculationDiscountResult
.
Goods
.
GoodsDiscount
>
goodsDiscountsList
=
goods
.
getDiscounts
();
if
(
goodsDiscountsList
!=
null
&&
!
goodsDiscountsList
.
isEmpty
()){
for
(
CalculationSharingDiscountResponseDto
.
CalculationDiscountResult
.
Goods
.
GoodsDiscount
gd
:
goodsDiscountsList
){
if
(
ObjectUtils
.
equals
(
gd
.
getType
(),
ActivityTypeEnum
.
TYPE_2
.
getCode
())){
cutFlag
=
true
;
break
;
}
}
}
}
if
(
cutFlag
){
product
.
setFinalPrice
(
goodsDiscountsMap
.
get
(
product
.
getCartGoodsUid
()).
getNowPrice
());
}
// num代表拆出来的半价行数量
// 所以只要不等于0就需要把ActivityType设置为空
// 因为前端用这个判断是否能加减
if
(!
Objects
.
equals
(
num
,
0
)){
product
.
setActivityType
(
null
);
}
// num代表拆出来的半价行数量,gifeProductIds代表赠品
// 只要符合条件就需要设置为空
// 因为前端指挥在半价行、赠品行上打标
// 前端是从商品活动信息中查找活动,在商品列表中找商品
if
((
gifeProductIds
.
contains
(
product
.
getGoodsId
())
&&
product
.
getActivityType
()
==
null
)
||
!
Objects
.
equals
(
num
,
0
)){
product
.
setGoodsId
(
null
);
}
newProducts
.
add
(
product
);
}
}
// 半价商品加到购物车
newProducts
.
addAll
(
halfProduct
);
shoppingCartGoodsResponseVo
.
setProducts
(
newProducts
);
}
}
}
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