Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
A
Afrishop refactored project
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Whispa
Afrishop refactored project
Commits
27a516a0
提交
27a516a0
authored
12月 15, 2020
作者:
wudepeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
full activity
上级
3d70b703
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
50 行增加
和
103 行删除
+50
-103
ActivityController.java
...m/example/afrishop_v3/controllers/ActivityController.java
+50
-103
没有找到文件。
src/main/java/com/example/afrishop_v3/controllers/ActivityController.java
浏览文件 @
27a516a0
...
@@ -15,10 +15,10 @@ import org.springframework.web.bind.annotation.*;
...
@@ -15,10 +15,10 @@ import org.springframework.web.bind.annotation.*;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.text.DateFormat
;
import
java.text.DateFormat
;
import
java.text.NumberFormat
;
import
java.text.ParseException
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.*
;
import
java.util.stream.Stream
;
/**
/**
* @Auther: wudepeng
* @Auther: wudepeng
...
@@ -137,78 +137,8 @@ public class ActivityController {
...
@@ -137,78 +137,8 @@ public class ActivityController {
return
t
;
return
t
;
}
}
@PostMapping
(
"/caculateCartDiscount"
)
public
Result
caculateCartDiscount
(
@RequestBody
String
[]
cartIds
)
{
// Activity activity = null;
// List<Activity> activityList = new ArrayList<>();
BigDecimal
itemPrice
=
BigDecimal
.
ZERO
;
BigDecimal
lessAmount
=
BigDecimal
.
ZERO
;
String
discount
=
null
;
int
itemCount
=
0
;
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
for
(
String
cartId
:
cartIds
)
{
Optional
<
TbCfCartRecordR
>
byId
=
cartRecordRRepository
.
findById
(
cartId
);
if
(
byId
.
isPresent
())
{
TbCfCartRecordR
cart
=
byId
.
get
();
itemPrice
=
itemPrice
.
add
(
cart
.
getItemPrice
().
multiply
(
new
BigDecimal
(
cart
.
getItemNum
())));
itemCount
+=
cart
.
getItemNum
();
// String itemId = cart.getItemId();
// activity = checkActivity(itemId);
// activityList.add(activity);
}
}
if
(
activityRepository
.
existsByUseType
(
1
))
{
List
<
Activity
>
fullList
=
activityRepository
.
findAllByUseType
(
1
);
if
(
fullList
.
size
()
==
0
||
fullList
==
null
)
{
return
new
Result
(
ResultCodeEnum
.
SERVICE_ERROR
.
getCode
(),
"There is no online activity"
);
}
Activity
activity
=
fullList
.
get
(
0
);
String
type
=
activity
.
getType
().
toString
();
List
<
Condition
>
conList
=
JSONObject
.
parseArray
(
activity
.
getCondition
(),
Condition
.
class
);
Collections
.
sort
(
conList
,
Comparator
.
comparing
(
Condition:
:
getKey
));
map
.
put
(
"activity"
,
activity
);
if
(
"1"
.
equals
(
type
)
||
"2"
.
equals
(
type
))
{
for
(
Condition
con
:
conList
)
{
double
key
=
con
.
getKey
();
BigDecimal
threshold
=
new
BigDecimal
(
key
);
double
value
=
con
.
getValue
();
discount
=
String
.
valueOf
(
value
);
String
msg
=
""
;
if
(
"1"
.
equals
(
type
))
{
msg
=
"$"
+
discount
;
}
else
{
msg
=
discount
+
"%"
;
}
if
(
itemPrice
.
compareTo
(
threshold
)
<
0
)
{
lessAmount
=
threshold
.
subtract
(
itemPrice
);
map
.
put
(
"message"
,
"Spend "
+
lessAmount
+
" more to Enjoy "
+
msg
+
" off !"
);
break
;
}
else
{
map
.
put
(
"message"
,
"Congrats, you've got "
+
msg
+
" off !"
);
}
}
}
else
if
(
"3"
.
equals
(
type
))
{
for
(
Condition
con
:
conList
)
{
int
key
=
(
int
)
con
.
getKey
();
double
value
=
con
.
getValue
();
discount
=
String
.
valueOf
(
value
);
if
(
itemCount
<
key
)
{
map
.
put
(
"message"
,
"Buy "
+
(
key
-
itemCount
)
+
" more item to Enjoy "
+
discount
+
"% off !"
);
break
;
}
else
{
map
.
put
(
"message"
,
"Congrats, you've got "
+
discount
+
"% off !"
);
}
}
}
}
return
new
Result
(
map
);
}
public
Activity
checkActivity
(
String
itemId
)
{
public
Activity
checkActivity
(
String
itemId
)
{
Result
result
=
new
Result
();
Result
result
=
new
Result
();
Activity
activity
=
null
;
Activity
activity
=
null
;
...
@@ -256,12 +186,14 @@ public class ActivityController {
...
@@ -256,12 +186,14 @@ public class ActivityController {
}
}
@PostMapping
(
"/caculateCartDiscount"
)
@PostMapping
(
"/caculateCartDiscount"
)
public
Result
caculateCartDiscount
1
(
@RequestBody
String
[]
cartIds
)
{
public
Result
caculateCartDiscount
(
@RequestBody
String
[]
cartIds
)
{
BigDecimal
itemPrice
=
BigDecimal
.
ZERO
;
BigDecimal
itemPrice
=
BigDecimal
.
ZERO
;
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
NumberFormat
nf
=
NumberFormat
.
getInstance
();
List
<
Activity
>
fullList
=
activityRepository
.
findAllByUseType
(
1
);
List
<
Activity
>
fullList
=
activityRepository
.
findAllByUseType
(
1
);
if
(
fullList
.
size
()
==
0
||
fullList
==
null
)
if
(
fullList
.
size
()
==
0
||
fullList
==
null
)
...
@@ -275,14 +207,12 @@ public class ActivityController {
...
@@ -275,14 +207,12 @@ public class ActivityController {
StringBuffer
msg
=
new
StringBuffer
();
StringBuffer
msg
=
new
StringBuffer
();
map
.
put
(
"activity"
,
activity
);
map
.
put
(
"activity"
,
activity
);
if
(
cartIds
==
null
)
{
boolean
exist
=
false
;
msg
.
append
(
activity
.
getContent
());
}
int
itemCount
=
0
;
int
itemCount
=
0
;
for
(
String
cartId
:
cartIds
)
{
for
(
String
cartId
:
cartIds
)
{
Optional
<
TbCfCartRecordR
>
byId
=
cartRecordRRepository
.
findById
(
cartId
);
Optional
<
TbCfCartRecordR
>
byId
=
cartRecordRRepository
.
findById
(
cartId
);
if
(
byId
.
isPresent
())
{
if
(
byId
.
isPresent
())
{
exist
=
true
;
TbCfCartRecordR
cart
=
byId
.
get
();
TbCfCartRecordR
cart
=
byId
.
get
();
itemCount
+=
cart
.
getItemNum
();
itemCount
+=
cart
.
getItemNum
();
itemPrice
=
itemPrice
.
add
(
cart
.
getItemPrice
()
itemPrice
=
itemPrice
.
add
(
cart
.
getItemPrice
()
...
@@ -293,46 +223,63 @@ public class ActivityController {
...
@@ -293,46 +223,63 @@ public class ActivityController {
BigDecimal
lessAmount
;
BigDecimal
lessAmount
;
String
discount
;
String
discount
;
for
(
Condition
con
:
conList
)
{
for
(
Condition
con
:
conList
)
{
if
(
"1"
.
equals
(
type
)
||
"2"
.
equals
(
type
))
{
double
key
=
con
.
getKey
();
BigDecimal
threshold
=
new
BigDecimal
(
key
);
double
value
=
con
.
getValue
();
double
value
=
con
.
getValue
();
discount
=
String
.
valueOf
(
value
);
double
key
=
con
.
getKey
();
discount
=
nf
.
format
(
value
);
if
(
"1"
.
equals
(
type
))
{
if
(
"1"
.
equals
(
type
))
{
discount
=
"$"
+
discount
;
discount
=
"$"
+
discount
;
}
else
{
}
else
{
discount
=
discount
+
"%"
;
discount
=
discount
+
"%"
;
}
}
while
(
itemPrice
.
compareTo
(
threshold
)
>=
0
)
{
msg
.
append
(
"Congrats, you've got "
+
discount
+
" off "
);
}
if
(
itemPrice
.
compareTo
(
threshold
)
<
0
)
{
if
(
"1"
.
equals
(
type
)
||
"2"
.
equals
(
type
))
{
BigDecimal
threshold
=
new
BigDecimal
(
key
);
if
(
itemPrice
.
compareTo
(
threshold
)
>=
0
)
{
msg
.
delete
(
0
,
msg
.
length
());
msg
.
append
(
"Congrats, you've got "
+
discount
+
" off! "
);
}
else
{
lessAmount
=
threshold
.
subtract
(
itemPrice
);
lessAmount
=
threshold
.
subtract
(
itemPrice
);
msg
.
append
(
"Spend "
+
lessAmount
+
" more to Enjoy "
+
discount
+
" off !"
);
String
less
=
nf
.
format
(
lessAmount
);
msg
.
append
(
"Spend "
+
less
+
" more to Enjoy "
+
discount
+
" off !"
);
break
;
break
;
}
/*else {
}
msg.delete(0, msg.length());
msg.append("Congrats, you've got " + discount + " off !");
}*/
}
else
if
(
"3"
.
equals
(
type
))
{
}
else
if
(
"3"
.
equals
(
type
))
{
int
key
=
(
int
)
con
.
getKey
();
double
value
=
con
.
getValue
();
/**
/**
* 2
*
* 2==9
* 2件9折
* 3==8
* 3件8折
* 5件7折
*
* 如果用户购买1件商品,提示:Buy 1 more item to Enjoy 10% off !
* 如果用户购买2件商品,提示:Congrats, you've got 30% off ! Buy 1 more item to Enjoy 20% off !
* .
* .
* .
* 如果用户购大于或者等于5件商品,提示:Congrats, you've got 30% off !
*
*/
*/
int
num
=
(
int
)
con
.
getKey
();
if
(
itemCount
>=
key
)
{
if
(
itemCount
>=
num
)
{
msg
.
append
(
"Congrats, you've got "
+
value
+
"% off !"
);
msg
.
delete
(
0
,
msg
.
length
());
}
else
{
msg
.
append
(
"Congrats, you've got "
+
discount
+
" off ! "
);
msg
.
append
(
"Buy "
+
(
key
-
itemCount
)
+
" more item to Enjoy "
+
value
+
"% off !"
);
}
}
else
{
msg
.
append
(
"Buy "
+
(
num
-
itemCount
)
+
" more item to Enjoy "
+
discount
+
" off !"
);
break
;
}
}
}
}
}
if
(!
exist
){
msg
.
delete
(
0
,
msg
.
length
());
msg
.
append
(
activity
.
getContent
());
}
map
.
put
(
"message"
,
msg
);
map
.
put
(
"message"
,
msg
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论