Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
mall
Commits
00a07370
Commit
00a07370
authored
Aug 28, 2018
by
zhh
Browse files
购物车促销信息优化
parent
5790bb64
Changes
2
Hide whitespace changes
Inline
Side-by-side
mall-portal/src/main/java/com/macro/mall/portal/domain/CartPromotionItem.java
View file @
00a07370
...
@@ -8,21 +8,12 @@ import java.math.BigDecimal;
...
@@ -8,21 +8,12 @@ import java.math.BigDecimal;
* Created by macro on 2018/8/27.
* Created by macro on 2018/8/27.
* 购物车中促销信息的封装
* 购物车中促销信息的封装
*/
*/
public
class
CartPromotionItem
{
public
class
CartPromotionItem
extends
OmsCartItem
{
private
OmsCartItem
cartItem
;
//促销活动信息
//促销活动信息
private
String
promotionMessage
;
private
String
promotionMessage
;
//促销活动减去的金额,针对每个商品
//促销活动减去的金额,针对每个商品
private
BigDecimal
reduceAmount
;
private
BigDecimal
reduceAmount
;
public
OmsCartItem
getCartItem
()
{
return
cartItem
;
}
public
void
setCartItem
(
OmsCartItem
cartItem
)
{
this
.
cartItem
=
cartItem
;
}
public
String
getPromotionMessage
()
{
public
String
getPromotionMessage
()
{
return
promotionMessage
;
return
promotionMessage
;
}
}
...
...
mall-portal/src/main/java/com/macro/mall/portal/service/impl/OmsPromotionServiceImpl.java
View file @
00a07370
...
@@ -8,10 +8,12 @@ import com.macro.mall.portal.dao.PortalProductDao;
...
@@ -8,10 +8,12 @@ import com.macro.mall.portal.dao.PortalProductDao;
import
com.macro.mall.portal.domain.CartPromotionItem
;
import
com.macro.mall.portal.domain.CartPromotionItem
;
import
com.macro.mall.portal.domain.PromotionProduct
;
import
com.macro.mall.portal.domain.PromotionProduct
;
import
com.macro.mall.portal.service.OmsPromotionService
;
import
com.macro.mall.portal.service.OmsPromotionService
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.util.*
;
import
java.util.*
;
/**
/**
...
@@ -40,7 +42,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
...
@@ -40,7 +42,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
//单品促销
//单品促销
for
(
OmsCartItem
item
:
itemList
)
{
for
(
OmsCartItem
item
:
itemList
)
{
CartPromotionItem
cartPromotionItem
=
new
CartPromotionItem
();
CartPromotionItem
cartPromotionItem
=
new
CartPromotionItem
();
cartPromotionItem
.
setCartItem
(
i
tem
);
BeanUtils
.
copyProperties
(
item
,
cartPromotionI
tem
);
cartPromotionItem
.
setPromotionMessage
(
"单品促销"
);
cartPromotionItem
.
setPromotionMessage
(
"单品促销"
);
//商品原价-促销价
//商品原价-促销价
cartPromotionItem
.
setReduceAmount
(
getOriginalPrice
(
promotionProduct
,
item
.
getProductSkuId
()).
subtract
(
getSinglePromotionPrice
(
promotionProduct
,
item
.
getProductSkuId
())));
cartPromotionItem
.
setReduceAmount
(
getOriginalPrice
(
promotionProduct
,
item
.
getProductSkuId
()).
subtract
(
getSinglePromotionPrice
(
promotionProduct
,
item
.
getProductSkuId
())));
...
@@ -53,7 +55,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
...
@@ -53,7 +55,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
if
(
ladder
!=
null
){
if
(
ladder
!=
null
){
for
(
OmsCartItem
item
:
itemList
)
{
for
(
OmsCartItem
item
:
itemList
)
{
CartPromotionItem
cartPromotionItem
=
new
CartPromotionItem
();
CartPromotionItem
cartPromotionItem
=
new
CartPromotionItem
();
cartPromotionItem
.
setCartItem
(
i
tem
);
BeanUtils
.
copyProperties
(
item
,
cartPromotionI
tem
);
String
message
=
getLadderPromotionMessage
(
ladder
);
String
message
=
getLadderPromotionMessage
(
ladder
);
cartPromotionItem
.
setPromotionMessage
(
message
);
cartPromotionItem
.
setPromotionMessage
(
message
);
//商品原价-折扣金额*商品原价
//商品原价-折扣金额*商品原价
...
@@ -72,11 +74,12 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
...
@@ -72,11 +74,12 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
if
(
fullReduction
!=
null
){
if
(
fullReduction
!=
null
){
for
(
OmsCartItem
item
:
itemList
)
{
for
(
OmsCartItem
item
:
itemList
)
{
CartPromotionItem
cartPromotionItem
=
new
CartPromotionItem
();
CartPromotionItem
cartPromotionItem
=
new
CartPromotionItem
();
cartPromotionItem
.
setCartItem
(
i
tem
);
BeanUtils
.
copyProperties
(
item
,
cartPromotionI
tem
);
String
message
=
getFullReductionPromotionMessage
(
fullReduction
);
String
message
=
getFullReductionPromotionMessage
(
fullReduction
);
cartPromotionItem
.
setPromotionMessage
(
message
);
cartPromotionItem
.
setPromotionMessage
(
message
);
//(商品原价/总价)*满减金额
//(商品原价/总价)*满减金额
BigDecimal
reduceAmount
=
(
getOriginalPrice
(
promotionProduct
,
item
.
getProductSkuId
()).
divide
(
totalAmount
)).
multiply
(
fullReduction
.
getReducePrice
());
BigDecimal
originalPrice
=
getOriginalPrice
(
promotionProduct
,
item
.
getProductSkuId
());
BigDecimal
reduceAmount
=
originalPrice
.
divide
(
totalAmount
,
RoundingMode
.
HALF_EVEN
).
multiply
(
fullReduction
.
getReducePrice
());
cartPromotionItem
.
setReduceAmount
(
reduceAmount
);
cartPromotionItem
.
setReduceAmount
(
reduceAmount
);
cartPromotionItemList
.
add
(
cartPromotionItem
);
cartPromotionItemList
.
add
(
cartPromotionItem
);
}
}
...
@@ -108,7 +111,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
...
@@ -108,7 +111,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
private
Map
<
Long
,
List
<
OmsCartItem
>>
groupCartItemBySpu
(
List
<
OmsCartItem
>
cartItemList
)
{
private
Map
<
Long
,
List
<
OmsCartItem
>>
groupCartItemBySpu
(
List
<
OmsCartItem
>
cartItemList
)
{
Map
<
Long
,
List
<
OmsCartItem
>>
productCartMap
=
new
TreeMap
<>();
Map
<
Long
,
List
<
OmsCartItem
>>
productCartMap
=
new
TreeMap
<>();
for
(
OmsCartItem
cartItem
:
cartItemList
)
{
for
(
OmsCartItem
cartItem
:
cartItemList
)
{
List
<
OmsCartItem
>
productCartItemList
=
productCartMap
.
get
(
cartItem
.
getId
());
List
<
OmsCartItem
>
productCartItemList
=
productCartMap
.
get
(
cartItem
.
get
Product
Id
());
if
(
productCartItemList
==
null
)
{
if
(
productCartItemList
==
null
)
{
productCartItemList
=
new
ArrayList
<>();
productCartItemList
=
new
ArrayList
<>();
productCartItemList
.
add
(
cartItem
);
productCartItemList
.
add
(
cartItem
);
...
@@ -141,7 +144,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
...
@@ -141,7 +144,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
private
void
handleNoReduce
(
List
<
CartPromotionItem
>
cartPromotionItemList
,
List
<
OmsCartItem
>
itemList
)
{
private
void
handleNoReduce
(
List
<
CartPromotionItem
>
cartPromotionItemList
,
List
<
OmsCartItem
>
itemList
)
{
for
(
OmsCartItem
item
:
itemList
)
{
for
(
OmsCartItem
item
:
itemList
)
{
CartPromotionItem
cartPromotionItem
=
new
CartPromotionItem
();
CartPromotionItem
cartPromotionItem
=
new
CartPromotionItem
();
cartPromotionItem
.
setCartItem
(
i
tem
);
BeanUtils
.
copyProperties
(
item
,
cartPromotionI
tem
);
cartPromotionItem
.
setPromotionMessage
(
"无优惠"
);
cartPromotionItem
.
setPromotionMessage
(
"无优惠"
);
cartPromotionItem
.
setReduceAmount
(
new
BigDecimal
(
0
));
cartPromotionItem
.
setReduceAmount
(
new
BigDecimal
(
0
));
cartPromotionItemList
.
add
(
cartPromotionItem
);
cartPromotionItemList
.
add
(
cartPromotionItem
);
...
@@ -228,7 +231,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
...
@@ -228,7 +231,7 @@ public class OmsPromotionServiceImpl implements OmsPromotionService {
*/
*/
private
BigDecimal
getSinglePromotionPrice
(
PromotionProduct
promotionProduct
,
Long
productSkuId
)
{
private
BigDecimal
getSinglePromotionPrice
(
PromotionProduct
promotionProduct
,
Long
productSkuId
)
{
for
(
PmsSkuStock
skuStock
:
promotionProduct
.
getSkuStockList
())
{
for
(
PmsSkuStock
skuStock
:
promotionProduct
.
getSkuStockList
())
{
if
(
productSkuId
==
skuStock
.
getId
())
{
if
(
productSkuId
.
equals
(
skuStock
.
getId
())
)
{
return
skuStock
.
getPromotionPrice
();
return
skuStock
.
getPromotionPrice
();
}
}
}
}
...
...
Write
Preview
Supports
Markdown
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