Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
A
Afrishop refactored project
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Whispa
Afrishop refactored project
Commits
788ec253
提交
788ec253
authored
12月 09, 2020
作者:
吴德鹏
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
活动
上级
62642346
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
129 行增加
和
16 行删除
+129
-16
OrderController.java
.../com/example/afrishop_v3/controllers/OrderController.java
+6
-4
TbCfOrder.java
src/main/java/com/example/afrishop_v3/models/TbCfOrder.java
+97
-12
ActivityRepository.java
...om/example/afrishop_v3/repository/ActivityRepository.java
+6
-0
Condition.java
src/main/java/com/example/afrishop_v3/vo/Condition.java
+20
-0
没有找到文件。
src/main/java/com/example/afrishop_v3/controllers/OrderController.java
浏览文件 @
788ec253
...
...
@@ -45,10 +45,11 @@ public class OrderController extends Controller {
private
final
TbCfItemCommentRepository
commentRepository
;
private
final
TbCfExpressTemplateRepository
templateRepository
;
private
final
TbCfExchangeRepository
exchangeRepository
;
private
final
ActivityRepository
activityRepository
;
private
final
AuthenticationUser
user
;
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
OrderController
.
class
);
public
OrderController
(
TbCfToicouponRepository
couponRepository
,
TbCfOrderRepository
repository
,
TbCfCartRecordRRepository
cartRepository
,
TbCfAddressRepository
addressRepository
,
TbCfToicouponRepository
toicouponRepository
,
TbCfStationItemRepository
itemRepository
,
TbCfItemSkuRepository
itemSkuRepository
,
TbCfItemCommentRepository
commentRepository
,
TbCfExpressTemplateRepository
templateRepository
,
@Qualifier
(
"tbCfExchangeRepository"
)
TbCfExchangeRepository
exchangeRepository
,
AuthenticationUser
user
)
{
public
OrderController
(
TbCfToicouponRepository
couponRepository
,
TbCfOrderRepository
repository
,
TbCfCartRecordRRepository
cartRepository
,
TbCfAddressRepository
addressRepository
,
TbCfToicouponRepository
toicouponRepository
,
TbCfStationItemRepository
itemRepository
,
TbCfItemSkuRepository
itemSkuRepository
,
TbCfItemCommentRepository
commentRepository
,
TbCfExpressTemplateRepository
templateRepository
,
@Qualifier
(
"tbCfExchangeRepository"
)
TbCfExchangeRepository
exchangeRepository
,
A
ctivityRepository
activityRepository
,
A
uthenticationUser
user
)
{
this
.
couponRepository
=
couponRepository
;
this
.
repository
=
repository
;
this
.
cartRepository
=
cartRepository
;
...
...
@@ -59,6 +60,7 @@ public class OrderController extends Controller {
this
.
commentRepository
=
commentRepository
;
this
.
templateRepository
=
templateRepository
;
this
.
exchangeRepository
=
exchangeRepository
;
this
.
activityRepository
=
activityRepository
;
this
.
user
=
user
;
}
...
...
@@ -140,7 +142,7 @@ public class OrderController extends Controller {
}
order
.
setCouponMap
(
map
);
order
.
getItemOrderListFromCartList
(
list
,
itemRepository
);
order
.
getItemOrderListFromCartList
(
list
,
itemRepository
,
activityRepository
);
return
new
Result
<>(
order
);
}
...
...
@@ -179,7 +181,7 @@ public class OrderController extends Controller {
}
order
.
getItemOrderListFromCartList
(
allByUserId
,
itemRepository
);
order
.
getItemOrderListFromCartList
(
allByUserId
,
itemRepository
,
activityRepository
);
return
new
Result
<>(
order
);
...
...
@@ -321,7 +323,7 @@ public class OrderController extends Controller {
}
order
.
getItemOrderListFromCartList
(
allByUserId
,
itemRepository
);
order
.
getItemOrderListFromCartList
(
allByUserId
,
itemRepository
,
activityRepository
);
TbCfOrder
save
=
repository
.
save
(
order
);
...
...
src/main/java/com/example/afrishop_v3/models/TbCfOrder.java
浏览文件 @
788ec253
package
com
.
example
.
afrishop_v3
.
models
;
import
com.alibaba.fastjson.JSONObject
;
import
com.example.afrishop_v3.base.StateConstant
;
import
com.example.afrishop_v3.enums.OrderStatusEnum
;
import
com.example.afrishop_v3.repository.ActivityRepository
;
import
com.example.afrishop_v3.repository.TbCfStationItemRepository
;
import
com.example.afrishop_v3.util.IdUtil
;
import
com.example.afrishop_v3.vo.Condition
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.Data
;
import
net.sf.json.JSONArray
;
import
org.hibernate.annotations.Where
;
import
org.springframework.data.relational.core.sql.In
;
import
javax.persistence.*
;
import
java.math.BigDecimal
;
...
...
@@ -156,7 +161,10 @@ public class TbCfOrder {
private
String
remarkInfo
;
@Transient
private
Map
<
String
,
Object
>
couponMap
;
private
BigDecimal
reduceAmount
;
@Transient
private
Map
<
String
,
Object
>
couponMap
;
public
Map
<
String
,
Object
>
getCouponMap
()
{
return
couponMap
;
...
...
@@ -193,7 +201,7 @@ public class TbCfOrder {
this
.
commentCount
=
commentCount
;
}
@OneToMany
(
mappedBy
=
"orderId"
,
cascade
=
CascadeType
.
ALL
,
fetch
=
FetchType
.
EAGER
)
@OneToMany
(
mappedBy
=
"orderId"
,
cascade
=
CascadeType
.
ALL
,
fetch
=
FetchType
.
EAGER
)
private
List
<
TbCfItemOrderR
>
itemOrderList
=
new
ArrayList
<>();
...
...
@@ -235,9 +243,9 @@ public class TbCfOrder {
return
itemOrderList
;
}
public
void
getItemOrderListFromCartList
(
List
<
TbCfCartRecordR
>
cartList
,
TbCfStationItemRepository
itemRepository
)
{
public
void
getItemOrderListFromCartList
(
List
<
TbCfCartRecordR
>
cartList
,
TbCfStationItemRepository
itemRepository
,
ActivityRepository
activityRepository
)
{
itemOrderList
=
cartList
.
stream
().
map
(
f
->
f
.
getOrderItem
(
orderId
)).
collect
(
Collectors
.
toList
());
doSomeCalculations
(
itemRepository
);
doSomeCalculations
(
itemRepository
,
activityRepository
);
setOrderTime
(
new
Date
());
setDealTime
(
new
Date
());
setOrderNo
(
String
.
valueOf
(
IdUtil
.
createLongIdByDate
()));
...
...
@@ -248,26 +256,27 @@ public class TbCfOrder {
this
.
defaultTemplate
=
defaultTemplate
;
}
private
void
doSomeCalculations
(
TbCfStationItemRepository
itemRepository
)
{
private
void
doSomeCalculations
(
TbCfStationItemRepository
itemRepository
,
ActivityRepository
activityRepository
)
{
itemsPrice
=
itemsPrice
==
null
?
new
BigDecimal
(
0.0
)
:
itemsPrice
;
expressCost
=
expressCost
==
null
?
new
BigDecimal
(
0.0
)
:
expressCost
;
fee
=
fee
==
null
?
new
BigDecimal
(
0.0
)
:
fee
;
tax
=
tax
==
null
?
new
BigDecimal
(
0.0
)
:
tax
;
reduceAmount
=
reduceAmount
==
null
?
new
BigDecimal
(
0.0
)
:
reduceAmount
;
List
<
TemplateVo
>
templateList
=
new
ArrayList
<>();
itemOrderList
.
forEach
(
item
->
{
BigDecimal
itemPrice
=
item
.
getItemPriceTotal
();
TbCfExpressTemplate
template
=
item
.
getTemplate
();
if
(
template
!=
null
)
{
if
(
template
!=
null
)
{
System
.
out
.
println
(
template
.
getHandlingFee
());
System
.
out
.
println
(
template
.
getTariff
());
}
Optional
<
TbCfStationItem
>
optionalTbCfStationItem
=
itemRepository
.
findById
(
item
.
getItemId
());
if
(
optionalTbCfStationItem
.
isPresent
()
)
{
if
(
optionalTbCfStationItem
.
isPresent
())
{
TbCfStationItem
stationItem
=
optionalTbCfStationItem
.
get
();
if
(
stationItem
.
getExpress
()
!=
null
)
{
if
(
stationItem
.
getExpress
()
!=
null
)
{
template
=
stationItem
.
getExpress
();
}
}
...
...
@@ -318,13 +327,89 @@ public class TbCfOrder {
expressCost
=
expressCost
.
add
(
express
.
getExpressFee
().
add
(
express
.
getContinuationFee
().
multiply
(
new
BigDecimal
(
extralNum
))));
}
}
/**
* 活动模块:活动类型 1:满减 2:满折 3:满件打折(type)
* 使用类型 1:全场 2:分类商品 3:特定商品(use_type)
*/
boolean
act1
=
activityRepository
.
existsByUseType
(
1
);
if
(
act1
)
{
Optional
<
Activity
>
allAct
=
activityRepository
.
findFirstByUseType
(
1
);
if
(
allAct
.
isPresent
())
{
Activity
activity
=
allAct
.
get
();
String
type
=
String
.
valueOf
(
activity
.
getType
());
if
(
"1"
.
equals
(
type
))
{
// reduceAmount = caculateFullReduction(activity, itemsPrice);
caculateActFee
(
false
,
false
,
activity
,
itemsPrice
,
null
);
}
else
if
(
"2"
.
equals
(
type
))
{
// BigDecimal discount = caculateFullReduction(activity, itemsPrice);
// BigDecimal rate = new BigDecimal(1).subtract(discount.divide(new BigDecimal(100)));
BigDecimal
rate
=
caculateActFee
(
false
,
true
,
activity
,
itemsPrice
,
null
);
itemsPrice
=
rate
.
multiply
(
itemsPrice
);
}
else
if
(
"3"
.
equals
(
type
))
{
// BigDecimal discount = caculateFullCount(activity, itemOrderList.size());
// BigDecimal rate = new BigDecimal(1).subtract(discount.divide(new BigDecimal(100)));
BigDecimal
rate
=
caculateActFee
(
true
,
true
,
activity
,
itemsPrice
,
itemOrderList
.
size
());
itemsPrice
=
rate
.
multiply
(
itemsPrice
);
}
}
}
totalPrice
=
itemsPrice
.
add
(
fee
).
add
(
tax
).
add
(
expressCost
);
totalPrice
=
itemsPrice
.
add
(
fee
).
add
(
tax
).
add
(
expressCost
).
subtract
(
reduceAmount
);
countRealityPay
();
}
public
BigDecimal
caculateActFee
(
Boolean
isCount
,
Boolean
discount
,
Activity
activity
,
BigDecimal
itemsPrice
,
Integer
itemCount
)
{
List
<
Condition
>
conList
=
JSONObject
.
parseArray
(
activity
.
getCondition
(),
Condition
.
class
);
Collections
.
sort
(
conList
,
Comparator
.
comparing
(
Condition:
:
getKey
));
BigDecimal
result
=
new
BigDecimal
(
"0.0"
);
for
(
int
i
=
0
;
i
<
conList
.
size
();
i
++)
{
if
(
isCount
)
{
if
(
itemCount
>=
Integer
.
parseInt
(
conList
.
get
(
i
).
getKey
()))
{
result
=
new
BigDecimal
(
conList
.
get
(
i
).
getValue
());
}
}
else
{
if
(
itemsPrice
.
compareTo
(
new
BigDecimal
(
conList
.
get
(
i
).
getKey
()))
>=
0
)
{
result
=
new
BigDecimal
(
conList
.
get
(
i
).
getValue
());
}
}
}
if
(
discount
)
{
result
=
new
BigDecimal
(
1
).
subtract
(
result
.
divide
(
new
BigDecimal
(
100
)));
}
return
result
;
}
// //计算活动减免费用
// public BigDecimal caculateFullReduction(Activity activity, BigDecimal itemsPrice) {
//
// List<Condition> conList = JSONObject.parseArray(activity.getCondition(), Condition.class);
// Collections.sort(conList, Comparator.comparing(Condition::getKey));
// BigDecimal result = new BigDecimal("0.0");
// for (Condition con : conList) {
// if (itemsPrice.compareTo(new BigDecimal(con.getKey())) >= 0) {
// result = new BigDecimal(con.getValue());
// }
// }
//
// return result;
// }
//
// public BigDecimal caculateFullCount(Activity activity, Integer itemCount) {
// List<Condition> conList = JSONObject.parseArray(activity.getCondition(), Condition.class);
// Collections.sort(conList, Comparator.comparing(Condition::getKey));
// BigDecimal result = new BigDecimal("0.0");
//
// for (int i = 0; i < conList.size(); i++) {
// if (itemCount >= Integer.parseInt(conList.get(i).getKey())) {
// result = new BigDecimal(conList.get(i).getValue());
// }
// }
// return result;
// }
@Transient
private
TbCfCoupon
coupon
;
...
...
@@ -336,7 +421,7 @@ public class TbCfOrder {
private
void
countRealityPay
()
{
if
(
coupon
!=
null
)
{
setCouponPrice
(
coupon
.
getDeductAmount
());
// setCouponId(coupon.getCouponId());
// setCouponId(coupon.getCouponId());
}
BigDecimal
couponPrice
=
this
.
getCouponPrice
();
//实际需要支付款项
...
...
@@ -747,7 +832,7 @@ public class TbCfOrder {
* 获取:手续费
*/
public
BigDecimal
getFee
()
{
return
fee
==
null
?
BigDecimal
.
ZERO
:
fee
.
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
);
return
fee
==
null
?
BigDecimal
.
ZERO
:
fee
.
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
);
}
/**
...
...
src/main/java/com/example/afrishop_v3/repository/ActivityRepository.java
浏览文件 @
788ec253
...
...
@@ -5,8 +5,10 @@ import org.springframework.data.domain.Page;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.relational.core.sql.In
;
import
java.util.List
;
import
java.util.Optional
;
/**
* @Auther: wudepeng
...
...
@@ -17,4 +19,8 @@ public interface ActivityRepository extends JpaRepository<Activity,String> {
@Query
(
value
=
"select a from Activity a where CURRENT_TIMESTAMP between startTime and endTime and status=1 order by a.createTime desc"
)
Page
<
Activity
>
getAllActivity
(
Pageable
pageable
);
boolean
existsByUseType
(
Integer
useType
);
Optional
<
Activity
>
findFirstByUseType
(
Integer
useType
);
}
src/main/java/com/example/afrishop_v3/vo/Condition.java
0 → 100644
浏览文件 @
788ec253
package
com
.
example
.
afrishop_v3
.
vo
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
java.math.BigDecimal
;
/**
* @Auther: wudepeng
* @Date: 2020/12/09
* @Description:活动条件
*/
@Data
@AllArgsConstructor
public
class
Condition
{
private
String
key
;
private
String
value
;
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论