Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
soss
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hooloo
ms
soss
Commits
c356a5a0
Commit
c356a5a0
authored
May 16, 2023
by
weijiguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix coupon bug
parent
a7139be8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
27 deletions
+11
-27
soss-system/src/main/java/com/soss/system/domain/GoodsSku.java
+2
-0
soss-system/src/main/java/com/soss/system/service/impl/CouponUserServiceImpl.java
+6
-26
soss-system/src/main/resources/mapper/system/GoodsSkuMapper.xml
+3
-1
No files found.
soss-system/src/main/java/com/soss/system/domain/GoodsSku.java
View file @
c356a5a0
...
...
@@ -52,6 +52,8 @@ public class GoodsSku extends BaseEntity
private
BigDecimal
discount
;
private
BigDecimal
origDiscount
;
@Override
public
String
toString
()
{
return
new
ToStringBuilder
(
this
,
ToStringStyle
.
MULTI_LINE_STYLE
)
...
...
soss-system/src/main/java/com/soss/system/service/impl/CouponUserServiceImpl.java
View file @
c356a5a0
package
com
.
soss
.
system
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.soss.common.enums.CouponCategoryType
;
import
com.soss.common.enums.CouponState
;
import
com.soss.common.enums.CouponUserType
;
...
...
@@ -23,7 +22,6 @@ import org.springframework.util.CollectionUtils;
import
java.math.BigDecimal
;
import
java.time.LocalDateTime
;
import
java.util.*
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
...
...
@@ -189,12 +187,9 @@ public class CouponUserServiceImpl implements ICouponUserService {
List
<
Goods
>
goods
=
goodsMapper
.
selectGoodsByIds
(
goodsIds
);
Assert
.
notEmpty
(
goods
,
"未查询到匹配的商品信息[id="
+
goodsIds
+
"]"
);
// 订单总额
BigDecimal
orderTotalAmount
=
orderDetails
.
stream
().
map
(
x
->
x
.
getAmountShould
().
multiply
(
new
BigDecimal
(
x
.
getNum
()))
).
reduce
(
BigDecimal
.
ZERO
,
BigDecimal:
:
add
);
BigDecimal
orderTotalOrigDiscount
=
orderDetails
.
stream
().
map
(
x
->
x
.
getOrigDiscount
().
multiply
(
new
BigDecimal
(
x
.
getNum
()))
).
reduce
(
BigDecimal
.
ZERO
,
BigDecimal:
:
add
);
BigDecimal
orderTotalAmount
=
orderDetails
.
stream
().
map
(
OrderDetail:
:
getAmountShould
).
reduce
(
BigDecimal
.
ZERO
,
BigDecimal:
:
add
);
BigDecimal
orderTotalOrigDiscount
=
orderDetails
.
stream
().
map
(
OrderDetail:
:
getOrigDiscount
).
reduce
(
BigDecimal
.
ZERO
,
BigDecimal:
:
add
);
log
.
info
(
"orderTotalAmount:{}, orderTotalOrigDiscount:{}"
,
orderTotalAmount
,
orderTotalOrigDiscount
);
if
(!
CollectionUtils
.
isEmpty
(
couponVos
))
{
orderDetails
.
forEach
(
x
->
x
.
setAmountShould
(
x
.
getOrigDiscount
().
multiply
(
new
BigDecimal
(
x
.
getNum
()))));
}
couponVos
.
stream
().
filter
(
couponVo
->
StringUtils
.
isEmpty
(
couponVo
.
getNotFitableDesc
())).
forEach
(
couponVo
->
{
/** 可用饮品范围的判断 */
List
<
Long
>
fitCouponGoodsIdList
=
goods
.
stream
().
filter
(
good
->
...
...
@@ -211,31 +206,15 @@ public class CouponUserServiceImpl implements ICouponUserService {
}
/** 券价值的判断 */
if
(
couponVo
.
getType
().
equals
(
CouponCategoryType
.
DEDUCTION
.
getType
()))
{
// 抵扣
if
(
couponVo
.
getPriceLimit
()
!=
null
&&
couponVo
.
getPriceLimit
().
compareTo
(
BigDecimal
.
ZERO
)
!=
0
&&
couponVo
.
getPriceLimit
().
compareTo
(
orderTotal
OrigDisc
ount
)
>
0
)
{
if
(
couponVo
.
getPriceLimit
()
!=
null
&&
couponVo
.
getPriceLimit
().
compareTo
(
BigDecimal
.
ZERO
)
!=
0
&&
couponVo
.
getPriceLimit
().
compareTo
(
orderTotal
Am
ount
)
>
0
)
{
couponVo
.
setNotFitableDesc
(
"未达到满减要求"
);
return
;
}
couponVo
.
setCouponAmount
(
couponVo
.
getPriceDiscount
().
min
(
orderTotalOrigDiscount
));
AtomicReference
<
Integer
>
nums
=
new
AtomicReference
<>(
0
);
orderDetails
.
forEach
(
x
->
nums
.
updateAndGet
(
v
->
v
+
x
.
getNum
()));
log
.
info
(
"nums:{}"
,
nums
);
if
(
nums
.
get
()
<=
1
)
{
OrderDetail
orderDetail
=
orderDetails
.
get
(
0
);
orderDetail
.
setCouponAmount
(
couponVo
.
getCouponAmount
().
negate
());
orderDetail
.
setRealAmount
(
orderDetail
.
getAmountShould
().
add
(
orderDetail
.
getCouponAmount
()));
}
else
{
orderDetails
.
forEach
(
orderDetail
->
{
BigDecimal
rate
=
orderDetail
.
getAmountShould
().
divide
(
orderTotalOrigDiscount
);
orderDetail
.
setCouponAmount
(
couponVo
.
getCouponAmount
().
negate
().
multiply
(
rate
));
orderDetail
.
setRealAmount
(
orderDetail
.
getAmountShould
().
add
(
orderDetail
.
getCouponAmount
()));
log
.
info
(
"rate:{},detail:{}"
,
rate
,
JSON
.
toJSON
(
orderDetail
));
});
}
}
else
{
List
<
OrderDetail
>
fitOrderDetails
=
orderDetails
.
stream
().
filter
(
orderDetail
->
fitCouponGoodsIdList
.
contains
(
orderDetail
.
getGoodsId
())).
collect
(
Collectors
.
toList
());
BigDecimal
fitGoodsAmount
=
fitOrderDetails
.
stream
().
map
(
x
->
x
.
getAmountShould
().
multiply
(
new
BigDecimal
(
x
.
getNum
()))
).
reduce
(
BigDecimal
.
ZERO
,
BigDecimal:
:
add
);
BigDecimal
fitGoodsOrigDiscount
=
fitOrderDetails
.
stream
().
map
(
x
->
x
.
getOrigDiscount
().
multiply
(
new
BigDecimal
(
x
.
getNum
()))
).
reduce
(
BigDecimal
.
ZERO
,
BigDecimal:
:
add
);
BigDecimal
fitGoodsAmount
=
fitOrderDetails
.
stream
().
map
(
OrderDetail:
:
getAmountShould
).
reduce
(
BigDecimal
.
ZERO
,
BigDecimal:
:
add
);
BigDecimal
fitGoodsOrigDiscount
=
fitOrderDetails
.
stream
().
map
(
OrderDetail:
:
getOrigDiscount
).
reduce
(
BigDecimal
.
ZERO
,
BigDecimal:
:
add
);
log
.
info
(
"fitGoodsOrigDiscount:{}, fitGoodsAmount:{}"
,
fitGoodsOrigDiscount
,
fitGoodsAmount
);
if
(
couponVo
.
getPriceLimit
()
!=
null
&&
couponVo
.
getPriceLimit
().
compareTo
(
BigDecimal
.
ZERO
)
!=
0
&&
couponVo
.
getPriceLimit
().
compareTo
(
fitGoodsAmount
)
>
0
)
{
if
(
couponVo
.
getType
().
equals
(
CouponCategoryType
.
DISCOUNT
.
getType
()))
{
// 折扣
...
...
@@ -282,6 +261,7 @@ public class CouponUserServiceImpl implements ICouponUserService {
orderDetail
.
setOriAmount
(
skuNum
.
multiply
(
sku
.
getPrice
()));
orderDetail
.
setUnitPrice
(
sku
.
getDiscount
());
orderDetail
.
setAmountShould
(
skuNum
.
multiply
(
sku
.
getDiscount
()));
orderDetail
.
setOrigDiscount
(
sku
.
getOrigDiscount
());
});
return
goodsSkus
;
}
...
...
soss-system/src/main/resources/mapper/system/GoodsSkuMapper.xml
View file @
c356a5a0
...
...
@@ -21,7 +21,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select
id=
"selectSkuListForOrder"
resultMap=
"GoodsSkuResult"
>
select gs.id, gs.goods_id, gs.price,
case when sgs.discount>=0 then sgs.discount else gs.discount end as discount, gs.is_deleted
case when sgs.discount>=0 then sgs.discount else gs.discount end as discount,
case when sgs.orig_discount>0 then sgs.orig_discount else gs.discount end orig_discount,
gs.is_deleted
from goods_sku gs
left join shop_goods_sku sgs on gs.goods_id = sgs.goods_id and gs.id = sgs.sku_id
where sgs.shop_id = #{shopId}
...
...
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