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
b5800856
Commit
b5800856
authored
Apr 20, 2019
by
macro
Browse files
项目结构改造
parent
cdd332a6
Changes
33
Hide whitespace changes
Inline
Side-by-side
mall-portal/src/main/java/com/macro/mall/portal/controller/UmsMemberCouponController.java
View file @
b5800856
package
com.macro.mall.portal.controller
;
import
com.macro.mall.common.api.CommonResult
;
import
com.macro.mall.model.SmsCouponHistory
;
import
com.macro.mall.portal.domain.CartPromotionItem
;
import
com.macro.mall.portal.domain.CommonResult
;
import
com.macro.mall.portal.domain.SmsCouponHistoryDetail
;
import
com.macro.mall.portal.service.OmsCartItemService
;
import
com.macro.mall.portal.service.UmsMemberCouponService
;
...
...
@@ -34,7 +34,7 @@ public class UmsMemberCouponController {
@ApiOperation
(
"领取指定优惠券"
)
@RequestMapping
(
value
=
"/add/{couponId}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Objec
t
add
(
@PathVariable
Long
couponId
)
{
public
CommonResul
t
add
(
@PathVariable
Long
couponId
)
{
return
memberCouponService
.
add
(
couponId
);
}
...
...
@@ -43,9 +43,9 @@ public class UmsMemberCouponController {
allowableValues
=
"0,1,2"
,
paramType
=
"query"
,
dataType
=
"integer"
)
@RequestMapping
(
value
=
"/list"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
Object
list
(
@RequestParam
(
value
=
"useStatus"
,
required
=
false
)
Integer
useStatus
)
{
public
CommonResult
<
List
<
SmsCouponHistory
>>
list
(
@RequestParam
(
value
=
"useStatus"
,
required
=
false
)
Integer
useStatus
)
{
List
<
SmsCouponHistory
>
couponHistoryList
=
memberCouponService
.
list
(
useStatus
);
return
new
CommonResult
()
.
success
(
couponHistoryList
);
return
CommonResult
.
success
(
couponHistoryList
);
}
@ApiOperation
(
"获取登录会员购物车的相关优惠券"
)
...
...
@@ -53,9 +53,9 @@ public class UmsMemberCouponController {
defaultValue
=
"1"
,
allowableValues
=
"0,1"
,
paramType
=
"query"
,
dataType
=
"integer"
)
@RequestMapping
(
value
=
"/list/cart/{type}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
Object
listCart
(
@PathVariable
Integer
type
)
{
public
CommonResult
<
List
<
SmsCouponHistoryDetail
>>
listCart
(
@PathVariable
Integer
type
)
{
List
<
CartPromotionItem
>
cartPromotionItemList
=
cartItemService
.
listPromotion
(
memberService
.
getCurrentMember
().
getId
());
List
<
SmsCouponHistoryDetail
>
couponHistoryList
=
memberCouponService
.
listCart
(
cartPromotionItemList
,
type
);
return
new
CommonResult
()
.
success
(
couponHistoryList
);
return
CommonResult
.
success
(
couponHistoryList
);
}
}
mall-portal/src/main/java/com/macro/mall/portal/controller/UmsMemberReceiveAddressController.java
View file @
b5800856
package
com.macro.mall.portal.controller
;
import
com.macro.mall.common.api.CommonResult
;
import
com.macro.mall.model.UmsMemberReceiveAddress
;
import
com.macro.mall.portal.domain.CommonResult
;
import
com.macro.mall.portal.service.UmsMemberReceiveAddressService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
...
...
@@ -21,52 +21,53 @@ import java.util.List;
public
class
UmsMemberReceiveAddressController
{
@Autowired
private
UmsMemberReceiveAddressService
memberReceiveAddressService
;
@ApiOperation
(
"添加收货地址"
)
@RequestMapping
(
value
=
"/add"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Objec
t
add
(
@RequestBody
UmsMemberReceiveAddress
address
)
{
public
CommonResul
t
add
(
@RequestBody
UmsMemberReceiveAddress
address
)
{
int
count
=
memberReceiveAddressService
.
add
(
address
);
if
(
count
>
0
){
return
new
CommonResult
()
.
success
(
count
);
if
(
count
>
0
)
{
return
CommonResult
.
success
(
count
);
}
return
new
CommonResult
()
.
failed
();
return
CommonResult
.
failed
();
}
@ApiOperation
(
"删除收货地址"
)
@RequestMapping
(
value
=
"/delete/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Objec
t
delete
(
@PathVariable
Long
id
)
{
public
CommonResul
t
delete
(
@PathVariable
Long
id
)
{
int
count
=
memberReceiveAddressService
.
delete
(
id
);
if
(
count
>
0
){
return
new
CommonResult
()
.
success
(
count
);
if
(
count
>
0
)
{
return
CommonResult
.
success
(
count
);
}
return
new
CommonResult
()
.
failed
();
return
CommonResult
.
failed
();
}
@ApiOperation
(
"修改收货地址"
)
@RequestMapping
(
value
=
"/update/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Objec
t
update
(
@PathVariable
Long
id
,
@RequestBody
UmsMemberReceiveAddress
address
)
{
int
count
=
memberReceiveAddressService
.
update
(
id
,
address
);
if
(
count
>
0
){
return
new
CommonResult
()
.
success
(
count
);
public
CommonResul
t
update
(
@PathVariable
Long
id
,
@RequestBody
UmsMemberReceiveAddress
address
)
{
int
count
=
memberReceiveAddressService
.
update
(
id
,
address
);
if
(
count
>
0
)
{
return
CommonResult
.
success
(
count
);
}
return
new
CommonResult
()
.
failed
();
return
CommonResult
.
failed
();
}
@ApiOperation
(
"显示所有收货地址"
)
@RequestMapping
(
value
=
"/list"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
Object
list
()
{
public
CommonResult
<
List
<
UmsMemberReceiveAddress
>>
list
()
{
List
<
UmsMemberReceiveAddress
>
addressList
=
memberReceiveAddressService
.
list
();
return
new
CommonResult
()
.
success
(
addressList
);
return
CommonResult
.
success
(
addressList
);
}
@ApiOperation
(
"显示所有收货地址"
)
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
Object
getItem
(
@PathVariable
Long
id
)
{
public
CommonResult
<
UmsMemberReceiveAddress
>
getItem
(
@PathVariable
Long
id
)
{
UmsMemberReceiveAddress
address
=
memberReceiveAddressService
.
getItem
(
id
);
return
new
CommonResult
()
.
success
(
address
);
return
CommonResult
.
success
(
address
);
}
}
mall-portal/src/main/java/com/macro/mall/portal/domain/CommonResult.java
deleted
100644 → 0
View file @
cdd332a6
package
com.macro.mall.portal.domain
;
import
org.springframework.data.domain.Page
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 通用返回对象
* Created by macro on 2018/4/26.
*/
public
class
CommonResult
{
//操作成功
public
static
final
int
SUCCESS
=
200
;
//操作失败
public
static
final
int
FAILED
=
500
;
private
int
code
;
private
String
message
;
private
Object
data
;
/**
* 普通成功返回
*
* @param data 获取的数据
*/
public
CommonResult
success
(
Object
data
)
{
this
.
code
=
SUCCESS
;
this
.
message
=
"操作成功"
;
this
.
data
=
data
;
return
this
;
}
/**
* 普通成功返回
*/
public
CommonResult
success
(
String
message
,
Object
data
)
{
this
.
code
=
SUCCESS
;
this
.
message
=
message
;
this
.
data
=
data
;
return
this
;
}
/**
* 返回分页成功数据
*/
public
CommonResult
pageSuccess
(
Page
pageInfo
)
{
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
result
.
put
(
"pageSize"
,
pageInfo
.
getSize
());
result
.
put
(
"totalPage"
,
pageInfo
.
getTotalPages
());
result
.
put
(
"total"
,
pageInfo
.
getTotalElements
());
result
.
put
(
"pageNum"
,
pageInfo
.
getNumber
());
result
.
put
(
"list"
,
pageInfo
.
getContent
());
this
.
code
=
SUCCESS
;
this
.
message
=
"操作成功"
;
this
.
data
=
result
;
return
this
;
}
/**
* 普通失败提示信息
*/
public
CommonResult
failed
()
{
this
.
code
=
FAILED
;
this
.
message
=
"操作失败"
;
return
this
;
}
public
CommonResult
failed
(
String
message
){
this
.
code
=
FAILED
;
this
.
message
=
message
;
return
this
;
}
public
int
getCode
()
{
return
code
;
}
public
void
setCode
(
int
code
)
{
this
.
code
=
code
;
}
public
String
getMessage
()
{
return
message
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
public
Object
getData
()
{
return
data
;
}
public
void
setData
(
Object
data
)
{
this
.
data
=
data
;
}
}
mall-portal/src/main/java/com/macro/mall/portal/service/OmsPortalOrderService.java
View file @
b5800856
package
com.macro.mall.portal.service
;
import
com.macro.mall.
portal.domain
.CommonResult
;
import
com.macro.mall.
common.api
.CommonResult
;
import
com.macro.mall.portal.domain.ConfirmOrderResult
;
import
com.macro.mall.portal.domain.OrderParam
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
mall-portal/src/main/java/com/macro/mall/portal/service/UmsMemberCouponService.java
View file @
b5800856
package
com.macro.mall.portal.service
;
import
com.macro.mall.common.api.CommonResult
;
import
com.macro.mall.model.SmsCouponHistory
;
import
com.macro.mall.portal.domain.CartPromotionItem
;
import
com.macro.mall.portal.domain.CommonResult
;
import
com.macro.mall.portal.domain.SmsCouponHistoryDetail
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
mall-portal/src/main/java/com/macro/mall/portal/service/UmsMemberService.java
View file @
b5800856
package
com.macro.mall.portal.service
;
import
com.macro.mall.common.api.CommonResult
;
import
com.macro.mall.model.UmsMember
;
import
com.macro.mall.portal.domain.CommonResult
;
import
org.springframework.transaction.annotation.Transactional
;
/**
...
...
mall-portal/src/main/java/com/macro/mall/portal/service/impl/OmsPortalOrderServiceImpl.java
View file @
b5800856
package
com.macro.mall.portal.service.impl
;
import
com.macro.mall.common.api.CommonResult
;
import
com.macro.mall.mapper.*
;
import
com.macro.mall.model.*
;
import
com.macro.mall.portal.component.CancelOrderSender
;
...
...
@@ -109,7 +110,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
}
//判断购物车中商品是否都有库存
if
(!
hasStock
(
cartPromotionItemList
))
{
return
new
CommonResult
()
.
failed
(
"库存不足,无法下单"
);
return
CommonResult
.
failed
(
"库存不足,无法下单"
);
}
//判断使用使用了优惠券
if
(
orderParam
.
getCouponId
()
==
null
)
{
...
...
@@ -121,7 +122,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
//使用优惠券
SmsCouponHistoryDetail
couponHistoryDetail
=
getUseCoupon
(
cartPromotionItemList
,
orderParam
.
getCouponId
());
if
(
couponHistoryDetail
==
null
)
{
return
new
CommonResult
()
.
failed
(
"该优惠券不可用"
);
return
CommonResult
.
failed
(
"该优惠券不可用"
);
}
//对下单商品的优惠券进行处理
handleCouponAmount
(
orderItemList
,
couponHistoryDetail
);
...
...
@@ -137,11 +138,11 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
BigDecimal
totalAmount
=
calcTotalAmount
(
orderItemList
);
BigDecimal
integrationAmount
=
getUseIntegrationAmount
(
orderParam
.
getUseIntegration
(),
totalAmount
,
currentMember
,
orderParam
.
getCouponId
()
!=
null
);
if
(
integrationAmount
.
compareTo
(
new
BigDecimal
(
0
))
==
0
)
{
return
new
CommonResult
()
.
failed
(
"积分不可用"
);
return
CommonResult
.
failed
(
"积分不可用"
);
}
else
{
//可用情况下分摊到可用商品中
for
(
OmsOrderItem
orderItem
:
orderItemList
)
{
BigDecimal
perAmount
=
orderItem
.
getProductPrice
().
divide
(
totalAmount
,
3
,
RoundingMode
.
HALF_EVEN
).
multiply
(
integrationAmount
);
BigDecimal
perAmount
=
orderItem
.
getProductPrice
().
divide
(
totalAmount
,
3
,
RoundingMode
.
HALF_EVEN
).
multiply
(
integrationAmount
);
orderItem
.
setIntegrationAmount
(
perAmount
);
}
}
...
...
@@ -210,20 +211,20 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
}
orderItemDao
.
insertList
(
orderItemList
);
//如使用优惠券更新优惠券使用状态
if
(
orderParam
.
getCouponId
()!=
null
){
updateCouponStatus
(
orderParam
.
getCouponId
(),
currentMember
.
getId
(),
1
);
if
(
orderParam
.
getCouponId
()
!=
null
)
{
updateCouponStatus
(
orderParam
.
getCouponId
(),
currentMember
.
getId
(),
1
);
}
//如使用积分需要扣除积分
if
(
orderParam
.
getUseIntegration
()!=
null
){
if
(
orderParam
.
getUseIntegration
()
!=
null
)
{
order
.
setUseIntegration
(
orderParam
.
getUseIntegration
());
memberService
.
updateIntegration
(
currentMember
.
getId
(),
currentMember
.
getIntegration
()
-
orderParam
.
getUseIntegration
());
memberService
.
updateIntegration
(
currentMember
.
getId
(),
currentMember
.
getIntegration
()
-
orderParam
.
getUseIntegration
());
}
//删除购物车中的下单商品
deleteCartItemList
(
cartPromotionItemList
,
currentMember
);
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
result
.
put
(
"order"
,
order
);
result
.
put
(
"orderItemList"
,
orderItemList
);
return
new
CommonResult
()
.
success
(
"下单成功"
,
result
);
deleteCartItemList
(
cartPromotionItemList
,
currentMember
);
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
result
.
put
(
"order"
,
order
);
result
.
put
(
"orderItemList"
,
orderItemList
);
return
CommonResult
.
success
(
result
,
"下单成功"
);
}
@Override
...
...
@@ -237,7 +238,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
//恢复所有下单商品的锁定库存,扣减真实库存
OmsOrderDetail
orderDetail
=
portalOrderDao
.
getDetail
(
orderId
);
int
count
=
portalOrderDao
.
updateSkuStock
(
orderDetail
.
getOrderItemList
());
return
new
CommonResult
()
.
success
(
"支付成功"
,
count
);
return
CommonResult
.
success
(
count
,
"支付成功"
);
}
@Override
...
...
@@ -245,27 +246,27 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
OmsOrderSetting
orderSetting
=
orderSettingMapper
.
selectByPrimaryKey
(
1L
);
//查询超时、未支付的订单及订单详情
List
<
OmsOrderDetail
>
timeOutOrders
=
portalOrderDao
.
getTimeOutOrders
(
orderSetting
.
getNormalOrderOvertime
());
if
(
CollectionUtils
.
isEmpty
(
timeOutOrders
)){
return
new
CommonResult
()
.
failed
(
"暂无超时订单"
);
if
(
CollectionUtils
.
isEmpty
(
timeOutOrders
))
{
return
CommonResult
.
failed
(
"暂无超时订单"
);
}
//修改订单状态为交易取消
List
<
Long
>
ids
=
new
ArrayList
<>();
for
(
OmsOrderDetail
timeOutOrder
:
timeOutOrders
)
{
ids
.
add
(
timeOutOrder
.
getId
());
}
portalOrderDao
.
updateOrderStatus
(
ids
,
4
);
portalOrderDao
.
updateOrderStatus
(
ids
,
4
);
for
(
OmsOrderDetail
timeOutOrder
:
timeOutOrders
)
{
//解除订单商品库存锁定
portalOrderDao
.
releaseSkuStockLock
(
timeOutOrder
.
getOrderItemList
());
//修改优惠券使用状态
updateCouponStatus
(
timeOutOrder
.
getCouponId
(),
timeOutOrder
.
getMemberId
(),
0
);
updateCouponStatus
(
timeOutOrder
.
getCouponId
(),
timeOutOrder
.
getMemberId
(),
0
);
//返还使用积分
if
(
timeOutOrder
.
getUseIntegration
()!=
null
){
if
(
timeOutOrder
.
getUseIntegration
()
!=
null
)
{
UmsMember
member
=
memberService
.
getById
(
timeOutOrder
.
getMemberId
());
memberService
.
updateIntegration
(
timeOutOrder
.
getMemberId
(),
member
.
getIntegration
()
+
timeOutOrder
.
getUseIntegration
());
memberService
.
updateIntegration
(
timeOutOrder
.
getMemberId
(),
member
.
getIntegration
()
+
timeOutOrder
.
getUseIntegration
());
}
}
return
new
CommonResult
()
.
success
(
null
);
return
CommonResult
.
success
(
null
);
}
@Override
...
...
@@ -274,27 +275,27 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
OmsOrderExample
example
=
new
OmsOrderExample
();
example
.
createCriteria
().
andIdEqualTo
(
orderId
).
andStatusEqualTo
(
0
).
andDeleteStatusEqualTo
(
0
);
List
<
OmsOrder
>
cancelOrderList
=
orderMapper
.
selectByExample
(
example
);
if
(
CollectionUtils
.
isEmpty
(
cancelOrderList
)){
if
(
CollectionUtils
.
isEmpty
(
cancelOrderList
))
{
return
;
}
OmsOrder
cancelOrder
=
cancelOrderList
.
get
(
0
);
if
(
cancelOrder
!=
null
){
if
(
cancelOrder
!=
null
)
{
//修改订单状态为取消
cancelOrder
.
setStatus
(
4
);
orderMapper
.
updateByPrimaryKeySelective
(
cancelOrder
);
OmsOrderItemExample
orderItemExample
=
new
OmsOrderItemExample
();
OmsOrderItemExample
orderItemExample
=
new
OmsOrderItemExample
();
orderItemExample
.
createCriteria
().
andOrderIdEqualTo
(
orderId
);
List
<
OmsOrderItem
>
orderItemList
=
orderItemMapper
.
selectByExample
(
orderItemExample
);
//解除订单商品库存锁定
if
(!
CollectionUtils
.
isEmpty
(
orderItemList
)){
if
(!
CollectionUtils
.
isEmpty
(
orderItemList
))
{
portalOrderDao
.
releaseSkuStockLock
(
orderItemList
);
}
//修改优惠券使用状态
updateCouponStatus
(
cancelOrder
.
getCouponId
(),
cancelOrder
.
getMemberId
(),
0
);
updateCouponStatus
(
cancelOrder
.
getCouponId
(),
cancelOrder
.
getMemberId
(),
0
);
//返还使用积分
if
(
cancelOrder
.
getUseIntegration
()!=
null
){
if
(
cancelOrder
.
getUseIntegration
()
!=
null
)
{
UmsMember
member
=
memberService
.
getById
(
cancelOrder
.
getMemberId
());
memberService
.
updateIntegration
(
cancelOrder
.
getMemberId
(),
member
.
getIntegration
()
+
cancelOrder
.
getUseIntegration
());
memberService
.
updateIntegration
(
cancelOrder
.
getMemberId
(),
member
.
getIntegration
()
+
cancelOrder
.
getUseIntegration
());
}
}
}
...
...
@@ -303,9 +304,9 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
public
void
sendDelayMessageCancelOrder
(
Long
orderId
)
{
//获取订单超时时间
OmsOrderSetting
orderSetting
=
orderSettingMapper
.
selectByPrimaryKey
(
1L
);
long
delayTimes
=
orderSetting
.
getNormalOrderOvertime
()
*
60
*
1000
;
long
delayTimes
=
orderSetting
.
getNormalOrderOvertime
()
*
60
*
1000
;
//发送延迟消息
cancelOrderSender
.
sendMessage
(
orderId
,
delayTimes
);
cancelOrderSender
.
sendMessage
(
orderId
,
delayTimes
);
}
/**
...
...
@@ -317,12 +318,12 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
String
key
=
REDIS_KEY_PREFIX_ORDER_ID
+
date
;
Long
increment
=
redisService
.
increment
(
key
,
1
);
sb
.
append
(
date
);
sb
.
append
(
String
.
format
(
"%02d"
,
order
.
getSourceType
()));
sb
.
append
(
String
.
format
(
"%02d"
,
order
.
getPayType
()));
sb
.
append
(
String
.
format
(
"%02d"
,
order
.
getSourceType
()));
sb
.
append
(
String
.
format
(
"%02d"
,
order
.
getPayType
()));
String
incrementStr
=
increment
.
toString
();
if
(
incrementStr
.
length
()<=
6
){
sb
.
append
(
String
.
format
(
"%06d"
,
increment
));
}
else
{
if
(
incrementStr
.
length
()
<=
6
)
{
sb
.
append
(
String
.
format
(
"%06d"
,
increment
));
}
else
{
sb
.
append
(
incrementStr
);
}
return
sb
.
toString
();
...
...
@@ -336,16 +337,16 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
for
(
CartPromotionItem
cartPromotionItem
:
cartPromotionItemList
)
{
ids
.
add
(
cartPromotionItem
.
getId
());
}
cartItemService
.
delete
(
currentMember
.
getId
(),
ids
);
cartItemService
.
delete
(
currentMember
.
getId
(),
ids
);
}
/**
* 计算该订单赠送的成长值
*/
private
Integer
calcGiftGrowth
(
List
<
OmsOrderItem
>
orderItemList
)
{
Integer
sum
=
0
;
Integer
sum
=
0
;
for
(
OmsOrderItem
orderItem
:
orderItemList
)
{
sum
=
sum
+
orderItem
.
getGiftGrowth
()
*
orderItem
.
getProductQuantity
();
sum
=
sum
+
orderItem
.
getGiftGrowth
()
*
orderItem
.
getProductQuantity
();
}
return
sum
;
}
...
...
@@ -354,27 +355,28 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
* 计算该订单赠送的积分
*/
private
Integer
calcGifIntegration
(
List
<
OmsOrderItem
>
orderItemList
)
{
int
sum
=
0
;
int
sum
=
0
;
for
(
OmsOrderItem
orderItem
:
orderItemList
)
{
sum
+=
orderItem
.
getGiftIntegration
()
*
orderItem
.
getProductQuantity
();
sum
+=
orderItem
.
getGiftIntegration
()
*
orderItem
.
getProductQuantity
();
}
return
sum
;
}
/**
* 将优惠券信息更改为指定状态
* @param couponId 优惠券id
* @param memberId 会员id
*
* @param couponId 优惠券id
* @param memberId 会员id
* @param useStatus 0->未使用;1->已使用
*/
private
void
updateCouponStatus
(
Long
couponId
,
Long
memberId
,
Integer
useStatus
)
{
if
(
couponId
==
null
)
return
;
private
void
updateCouponStatus
(
Long
couponId
,
Long
memberId
,
Integer
useStatus
)
{
if
(
couponId
==
null
)
return
;
//查询第一张优惠券
SmsCouponHistoryExample
example
=
new
SmsCouponHistoryExample
();
example
.
createCriteria
().
andMemberIdEqualTo
(
memberId
)
.
andCouponIdEqualTo
(
couponId
).
andUseStatusEqualTo
(
useStatus
==
0
?
1
:
0
);
.
andCouponIdEqualTo
(
couponId
).
andUseStatusEqualTo
(
useStatus
==
0
?
1
:
0
);
List
<
SmsCouponHistory
>
couponHistoryList
=
couponHistoryMapper
.
selectByExample
(
example
);
if
(!
CollectionUtils
.
isEmpty
(
couponHistoryList
)){
if
(!
CollectionUtils
.
isEmpty
(
couponHistoryList
))
{
SmsCouponHistory
couponHistory
=
couponHistoryList
.
get
(
0
);
couponHistory
.
setUseTime
(
new
Date
());
couponHistory
.
setUseStatus
(
useStatus
);
...
...
@@ -487,7 +489,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
return
zeroAmount
;
}
//是否超过订单抵用最高百分比
BigDecimal
integrationAmount
=
new
BigDecimal
(
useIntegration
).
divide
(
new
BigDecimal
(
integrationConsumeSetting
.
getUseUnit
()),
2
,
RoundingMode
.
HALF_EVEN
);
BigDecimal
integrationAmount
=
new
BigDecimal
(
useIntegration
).
divide
(
new
BigDecimal
(
integrationConsumeSetting
.
getUseUnit
()),
2
,
RoundingMode
.
HALF_EVEN
);
BigDecimal
maxPercent
=
new
BigDecimal
(
integrationConsumeSetting
.
getMaxPercentPerOrder
()).
divide
(
new
BigDecimal
(
100
),
2
,
RoundingMode
.
HALF_EVEN
);
if
(
integrationAmount
.
compareTo
(
totalAmount
.
multiply
(
maxPercent
))
>
0
)
{
return
zeroAmount
;
...
...
mall-portal/src/main/java/com/macro/mall/portal/service/impl/UmsMemberCouponServiceImpl.java
View file @
b5800856
package
com.macro.mall.portal.service.impl
;
import
com.macro.mall.common.api.CommonResult
;
import
com.macro.mall.mapper.SmsCouponHistoryMapper
;
import
com.macro.mall.mapper.SmsCouponMapper
;
import
com.macro.mall.model.*
;
import
com.macro.mall.portal.dao.SmsCouponHistoryDao
;
import
com.macro.mall.portal.domain.CartPromotionItem
;
import
com.macro.mall.portal.domain.CommonResult
;
import
com.macro.mall.portal.domain.SmsCouponHistoryDetail
;
import
com.macro.mall.portal.service.UmsMemberCouponService
;
import
com.macro.mall.portal.service.UmsMemberService
;
...
...
@@ -35,21 +35,21 @@ public class UmsMemberCouponServiceImpl implements UmsMemberCouponService {
//获取优惠券信息,判断数量
SmsCoupon
coupon
=
couponMapper
.
selectByPrimaryKey
(
couponId
);
if
(
coupon
==
null
){
return
new
CommonResult
()
.
failed
(
"优惠券不存在"
);
return
CommonResult
.
failed
(
"优惠券不存在"
);
}
if
(
coupon
.
getCount
()<=
0
){
return
new
CommonResult
()
.
failed
(
"优惠券已经领完了"
);
return
CommonResult
.
failed
(
"优惠券已经领完了"
);
}
Date
now
=
new
Date
();
if
(
now
.
before
(
coupon
.
getEnableTime
())){
return
new
CommonResult
()
.
failed
(
"优惠券还没到领取时间"
);
return
CommonResult
.
failed
(
"优惠券还没到领取时间"
);
}
//判断用户领取的优惠券数量是否超过限制
SmsCouponHistoryExample
couponHistoryExample
=
new
SmsCouponHistoryExample
();
couponHistoryExample
.
createCriteria
().
andCouponIdEqualTo
(
couponId
).
andMemberIdEqualTo
(
currentMember
.
getId
());
int
count
=
couponHistoryMapper
.
countByExample
(
couponHistoryExample
);
if
(
count
>=
coupon
.
getPerLimit
()){
return
new
CommonResult
()
.
failed
(
"您已经领取过该优惠券"
);
return
CommonResult
.
failed
(
"您已经领取过该优惠券"
);
}
//生成领取优惠券历史
SmsCouponHistory
couponHistory
=
new
SmsCouponHistory
();
...
...
@@ -67,7 +67,7 @@ public class UmsMemberCouponServiceImpl implements UmsMemberCouponService {
coupon
.
setCount
(
coupon
.
getCount
()-
1
);
coupon
.
setReceiveCount
(
coupon
.
getReceiveCount
()==
null
?
1
:
coupon
.
getReceiveCount
()+
1
);
couponMapper
.
updateByPrimaryKey
(
coupon
);
return
new
CommonResult
()
.
success
(
"领取成功"
,
null
);
return
CommonResult
.
success
(
null
,
"领取成功"
);
}
/**
...
...
mall-portal/src/main/java/com/macro/mall/portal/service/impl/UmsMemberServiceImpl.java
View file @
b5800856
package
com.macro.mall.portal.service.impl
;
import
com.macro.mall.common.api.CommonResult
;
import
com.macro.mall.mapper.UmsMemberLevelMapper
;
import
com.macro.mall.mapper.UmsMemberMapper
;
import
com.macro.mall.model.UmsMember
;
import
com.macro.mall.model.UmsMemberExample
;
import
com.macro.mall.model.UmsMemberLevel
;
import
com.macro.mall.model.UmsMemberLevelExample
;
import
com.macro.mall.portal.domain.CommonResult
;
import
com.macro.mall.portal.domain.MemberDetails
;
import
com.macro.mall.portal.service.RedisService
;
import
com.macro.mall.portal.service.UmsMemberService
;
...
...
@@ -63,7 +63,7 @@ public class UmsMemberServiceImpl implements UmsMemberService {
public
CommonResult
register
(
String
username
,
String
password
,
String
telephone
,
String
authCode
)
{
//验证验证码
if
(!
verifyAuthCode
(
authCode
,
telephone
)){
return
new
CommonResult
()
.
failed
(
"验证码错误"
);
return
CommonResult
.
failed
(
"验证码错误"
);
}
//查询是否已有该用户
UmsMemberExample
example
=
new
UmsMemberExample
();
...
...
@@ -71,7 +71,7 @@ public class UmsMemberServiceImpl implements UmsMemberService {
example
.
or
(
example
.
createCriteria
().
andPhoneEqualTo
(
telephone
));
List
<
UmsMember
>
umsMembers
=
memberMapper
.
selectByExample
(
example
);
if
(!
CollectionUtils
.
isEmpty
(
umsMembers
))
{
return
new
CommonResult
()
.
failed
(
"该用户已经存在"
);
return
CommonResult
.
failed
(
"该用户已经存在"
);
}
//没有该用户进行添加操作
UmsMember
umsMember
=
new
UmsMember
();
...
...
@@ -89,7 +89,7 @@ public class UmsMemberServiceImpl implements UmsMemberService {
}
memberMapper
.
insert
(
umsMember
);
umsMember
.
setPassword
(
null
);
return
new
CommonResult
()
.
success
(
"注册成功"
,
null
);
return
CommonResult
.
success
(
null
,
"注册成功"
);
}
@Override
...
...
@@ -102,7 +102,7 @@ public class UmsMemberServiceImpl implements UmsMemberService {
//验证码绑定手机号并存储到redis
redisService
.
set
(
REDIS_KEY_PREFIX_AUTH_CODE
+
telephone
,
sb
.
toString
());
redisService
.
expire
(
REDIS_KEY_PREFIX_AUTH_CODE
+
telephone
,
AUTH_CODE_EXPIRE_SECONDS
);
return
new
CommonResult
()
.
success
(
"获取验证码成功"
,
sb
.
toString
());
return
CommonResult
.
success
(
sb
.
toString
()
,
"获取验证码成功"
);
}
@Override
...
...
@@ -111,16 +111,16 @@ public class UmsMemberServiceImpl implements UmsMemberService {
example
.
createCriteria
().
andPhoneEqualTo
(
telephone
);
List
<
UmsMember
>
memberList
=
memberMapper
.
selectByExample
(
example
);
if
(
CollectionUtils
.
isEmpty
(
memberList
)){
return
new
CommonResult
()
.
failed
(
"该账号不存在"
);
return
CommonResult
.
failed
(
"该账号不存在"
);
}
//验证验证码
if
(!
verifyAuthCode
(
authCode
,
telephone
)){
return
new
CommonResult
()
.
failed
(
"验证码错误"
);
return
CommonResult
.
failed
(
"验证码错误"
);
}
UmsMember
umsMember
=
memberList
.
get
(
0
);
umsMember
.
setPassword
(
passwordEncoder
.
encode
(
password
));
memberMapper
.
updateByPrimaryKeySelective
(
umsMember
);
return
new
CommonResult
()
.
success
(
"密码修改成功"
,
null
);
return
CommonResult
.
success
(
null
,
"密码修改成功"
);
}
@Override
...
...
mall-search/pom.xml
View file @
b5800856
...
...
@@ -5,17 +5,16 @@
<groupId>
com.macro.mall
</groupId>
<artifactId>
mall-search
</artifactId>
<version>
0
.0
.1
-SNAPSHOT
</version>
<version>
1
.0-SNAPSHOT
</version>
<packaging>
jar
</packaging>
<name>
mall-search
</name>
<description>
mall-search project for mall
</description>
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
2.1.3.RELEASE
</version>
<relativePath/>
<!-- lookup parent from repository -->
<groupId>
com.macro.mall
</groupId>
<artifactId>
mall
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<properties>
...
...
@@ -35,38 +34,6 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-elasticsearch
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<!--MyBatis分页插件-->
<dependency>
<groupId>
com.github.pagehelper
</groupId>
<artifactId>
pagehelper-spring-boot-starter
</artifactId>
<version>
1.2.10
</version>
</dependency>
<!--Swagger-UI API文档生产工具-->
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
<version>
2.6.1
</version>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
<version>
2.6.1
</version>
</dependency>
<!--集成druid连接池-->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid-spring-boot-starter
</artifactId>
<version>
1.1.10
</version>
</dependency>
</dependencies>
<build>
...
...
mall-search/src/main/java/com/macro/mall/search/controller/EsProductController.java
View file @
b5800856
package
com.macro.mall.search.controller
;
import
com.macro.mall.search.domain.CommonResult
;
import
com.macro.mall.common.api.CommonPage
;
import
com.macro.mall.common.api.CommonResult
;
import
com.macro.mall.search.domain.EsProduct
;
import
com.macro.mall.search.domain.EsProductRelatedInfo
;
import
com.macro.mall.search.service.EsProductService
;
...
...
@@ -28,47 +29,47 @@ public class EsProductController {
@ApiOperation
(
value
=
"导入所有数据库中商品到ES"
)
@RequestMapping
(
value
=
"/importAll"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Object
importAllList
()
{
public
CommonResult
<
Integer
>
importAllList
()
{
int
count
=
esProductService
.
importAll
();
return
new
CommonResult
()
.
success
(
count
);
return
CommonResult
.
success
(
count
);
}
@ApiOperation
(
value
=
"根据id删除商品"
)
@RequestMapping
(
value
=
"/delete/{id}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
Object
delete
(
@PathVariable
Long
id
)
{
public
CommonResult
<
Object
>
delete
(
@PathVariable
Long
id
)
{
esProductService
.
delete
(
id
);
return
new
CommonResult
()
.
success
(
null
);
return
CommonResult
.
success
(
null
);
}
@ApiOperation
(
value
=
"根据id批量删除商品"
)
@RequestMapping
(
value
=
"/delete/batch"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Object
delete
(
@RequestParam
(
"ids"
)
List
<
Long
>
ids
)
{
public
CommonResult
<
Object
>
delete
(
@RequestParam
(
"ids"
)
List
<
Long
>
ids
)
{
esProductService
.
delete
(
ids
);
return
new
CommonResult
()
.
success
(
null
);
return
CommonResult
.
success
(
null
);
}
@ApiOperation
(
value
=
"根据id创建商品"
)
@RequestMapping
(
value
=
"/create/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Obje
ct
create
(
@PathVariable
Long
id
)
{
public
CommonResult
<
EsProdu
ct
>
create
(
@PathVariable
Long
id
)
{
EsProduct
esProduct
=
esProductService
.
create
(
id
);
if
(
esProduct
!=
null
)
{
return
new
CommonResult
()
.
success
(
esProduct
);
return
CommonResult
.
success
(
esProduct
);
}
else
{
return
new
CommonResult
()
.
failed
();
return
CommonResult
.
failed
();
}
}
@ApiOperation
(
value
=
"简单搜索"
)
@RequestMapping
(
value
=
"/search/simple"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
Object
search
(
@RequestParam
(
required
=
false
)
String
keyword
,
@RequestParam
(
required
=
false
,
defaultValue
=
"0"
)
Integer
pageNum
,
@RequestParam
(
required
=
false
,
defaultValue
=
"5"
)
Integer
pageSize
)
{
public
CommonResult
<
CommonPage
<
EsProduct
>>
search
(
@RequestParam
(
required
=
false
)
String
keyword
,
@RequestParam
(
required
=
false
,
defaultValue
=
"0"
)
Integer
pageNum
,
@RequestParam
(
required
=
false
,
defaultValue
=
"5"
)
Integer
pageSize
)
{
Page
<
EsProduct
>
esProductPage
=
esProductService
.
search
(
keyword
,
pageNum
,
pageSize
);
return
new
CommonResult
().
pageSuccess
(
esProductPage
);
return
CommonResult
.
success
(
CommonPage
.
restPage
(
esProductPage
)
)
;
}
@ApiOperation
(
value
=
"综合搜索、筛选、排序"
)
...
...
@@ -76,31 +77,31 @@ public class EsProductController {
defaultValue
=
"0"
,
allowableValues
=
"0,1,2,3,4"
,
paramType
=
"query"
,
dataType
=
"integer"
)
@RequestMapping
(
value
=
"/search"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
Object
search
(
@RequestParam
(
required
=
false
)
String
keyword
,
@RequestParam
(
required
=
false
)
Long
brandId
,
@RequestParam
(
required
=
false
)
Long
productCategoryId
,
@RequestParam
(
required
=
false
,
defaultValue
=
"0"
)
Integer
pageNum
,
@RequestParam
(
required
=
false
,
defaultValue
=
"5"
)
Integer
pageSize
,
@RequestParam
(
required
=
false
,
defaultValue
=
"0"
)
Integer
sort
)
{
public
CommonResult
<
CommonPage
<
EsProduct
>>
search
(
@RequestParam
(
required
=
false
)
String
keyword
,
@RequestParam
(
required
=
false
)
Long
brandId
,
@RequestParam
(
required
=
false
)
Long
productCategoryId
,
@RequestParam
(
required
=
false
,
defaultValue
=
"0"
)
Integer
pageNum
,
@RequestParam
(
required
=
false
,
defaultValue
=
"5"
)
Integer
pageSize
,
@RequestParam
(
required
=
false
,
defaultValue
=
"0"
)
Integer
sort
)
{
Page
<
EsProduct
>
esProductPage
=
esProductService
.
search
(
keyword
,
brandId
,
productCategoryId
,
pageNum
,
pageSize
,
sort
);
return
new
CommonResult
().
pageSuccess
(
esProductPage
);
return
CommonResult
.
success
(
CommonPage
.
restPage
(
esProductPage
)
)
;
}
@ApiOperation
(
value
=
"根据商品id推荐商品"
)
@RequestMapping
(
value
=
"/recommend/{id}"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/recommend/{id}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
Object
recommend
(
@PathVariable
Long
id
,
@RequestParam
(
required
=
false
,
defaultValue
=
"0"
)
Integer
pageNum
,
@RequestParam
(
required
=
false
,
defaultValue
=
"5"
)
Integer
pageSize
){
public
CommonResult
<
CommonPage
<
EsProduct
>>
recommend
(
@PathVariable
Long
id
,
@RequestParam
(
required
=
false
,
defaultValue
=
"0"
)
Integer
pageNum
,
@RequestParam
(
required
=
false
,
defaultValue
=
"5"
)
Integer
pageSize
)
{
Page
<
EsProduct
>
esProductPage
=
esProductService
.
recommend
(
id
,
pageNum
,
pageSize
);
return
new
CommonResult
().
pageSuccess
(
esProductPage
);
return
CommonResult
.
success
(
CommonPage
.
restPage
(
esProductPage
)
)
;
}
@ApiOperation
(
value
=
"获取搜索的相关品牌、分类及筛选属性"
)
@RequestMapping
(
value
=
"/search/relate"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/search/relate"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
Object
searchRelatedInfo
(
@RequestParam
(
required
=
false
)
String
keyword
){
public
CommonResult
<
EsProductRelatedInfo
>
searchRelatedInfo
(
@RequestParam
(
required
=
false
)
String
keyword
)
{
EsProductRelatedInfo
productRelatedInfo
=
esProductService
.
searchRelatedInfo
(
keyword
);
return
new
CommonResult
()
.
success
(
productRelatedInfo
);
return
CommonResult
.
success
(
productRelatedInfo
);
}
}
mall-search/src/main/java/com/macro/mall/search/domain/CommonResult.java
deleted
100644 → 0
View file @
cdd332a6
package
com.macro.mall.search.domain
;
import
org.springframework.data.domain.Page
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 通用返回对象
* Created by macro on 2018/4/26.
*/
public
class
CommonResult
{
//操作成功
public
static
final
int
SUCCESS
=
200
;
//操作失败
public
static
final
int
FAILED
=
500
;
private
int
code
;
private
String
message
;
private
Object
data
;
/**
* 普通成功返回
*
* @param data 获取的数据
*/
public
CommonResult
success
(
Object
data
)
{
this
.
code
=
SUCCESS
;
this
.
message
=
"操作成功"
;
this
.
data
=
data
;
return
this
;
}
/**
* 返回分页成功数据
*/
public
CommonResult
pageSuccess
(
Page
pageInfo
)
{
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
result
.
put
(
"pageSize"
,
pageInfo
.
getSize
());
result
.
put
(
"totalPage"
,
pageInfo
.
getTotalPages
());
result
.
put
(
"total"
,
pageInfo
.
getTotalElements
());
result
.
put
(
"pageNum"
,
pageInfo
.
getNumber
());
result
.
put
(
"list"
,
pageInfo
.
getContent
());
this
.
code
=
SUCCESS
;
this
.
message
=
"操作成功"
;
this
.
data
=
result
;
return
this
;
}
/**
* 普通失败提示信息
*/
public
CommonResult
failed
()
{
this
.
code
=
FAILED
;
this
.
message
=
"操作失败"
;
return
this
;
}
public
int
getCode
()
{
return
code
;
}
public
void
setCode
(
int
code
)
{
this
.
code
=
code
;
}
public
String
getMessage
()
{
return
message
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
public
Object
getData
()
{
return
data
;
}
public
void
setData
(
Object
data
)
{
this
.
data
=
data
;
}
}
pom.xml
View file @
b5800856
...
...
@@ -10,11 +10,50 @@
<packaging>
pom
</packaging>
<modules>
<module>
mall-common
</module>
<module>
mall-mbg
</module>
<module>
mall-demo
</module>
<module>
mall-admin
</module>
<module>
mall-search
</module>
<module>
mall-portal
</module>
<module>
mall-demo
</module>
</modules>
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
2.1.3.RELEASE
</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-aop
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<!--MyBatis分页插件-->
<dependency>
<groupId>
com.github.pagehelper
</groupId>
<artifactId>
pagehelper-spring-boot-starter
</artifactId>
<version>
1.2.10
</version>
</dependency>
<!--集成druid连接池-->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid-spring-boot-starter
</artifactId>
<version>
1.1.10
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
Prev
1
2
Next
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