Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lingxi-lxy-yanshou
Project
Project
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
后端-黄柯铭
lingxi-lxy-yanshou
Commits
d5b815b6
Commit
d5b815b6
authored
Sep 11, 2021
by
技术总监-万宁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成售后退货修改未支付次数的支付金额
parent
dad5ce1c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
67 additions
and
100 deletions
+67
-100
AfterSaleReturnProductDetailDTO.java
...ngxi/order/model/dto/AfterSaleReturnProductDetailDTO.java
+0
-66
OrderReturnAmountDTO.java
.../com/ssy/lingxi/order/model/dto/OrderReturnAmountDTO.java
+19
-11
OrderPaymentRepository.java
...m/ssy/lingxi/order/repository/OrderPaymentRepository.java
+1
-1
IBaseOrderPaymentService.java
...y/lingxi/order/service/base/IBaseOrderPaymentService.java
+4
-3
BaseOrderPaymentServiceImpl.java
...i/order/serviceimpl/base/BaseOrderPaymentServiceImpl.java
+33
-17
OrderFeignServiceImpl.java
...lingxi/order/serviceimpl/feign/OrderFeignServiceImpl.java
+10
-2
No files found.
order-service/src/main/java/com/ssy/lingxi/order/model/dto/AfterSaleReturnProductDetailDTO.java
deleted
100644 → 0
View file @
dad5ce1c
package
com
.
ssy
.
lingxi
.
order
.
model
.
dto
;
import
java.io.Serializable
;
import
java.math.BigDecimal
;
/**
* 售后服务 - 退货 - 重新计算支付金额接口 - 退货商品信息
* @author 万宁
* @version 2.0.0
* @date 2021-09-03
*/
public
class
AfterSaleReturnProductDetailDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
6908551587670303260L
;
/**
* 订单商品Id
*/
private
Long
orderProductId
;
/**
* 购买数量
*/
private
BigDecimal
quantity
;
/**
* 到手价格
*/
private
BigDecimal
refPrice
;
/**
* 退货数量
*/
private
BigDecimal
returnCount
;
public
Long
getOrderProductId
()
{
return
orderProductId
;
}
public
void
setOrderProductId
(
Long
orderProductId
)
{
this
.
orderProductId
=
orderProductId
;
}
public
BigDecimal
getQuantity
()
{
return
quantity
;
}
public
void
setQuantity
(
BigDecimal
quantity
)
{
this
.
quantity
=
quantity
;
}
public
BigDecimal
getRefPrice
()
{
return
refPrice
;
}
public
void
setRefPrice
(
BigDecimal
refPrice
)
{
this
.
refPrice
=
refPrice
;
}
public
BigDecimal
getReturnCount
()
{
return
returnCount
;
}
public
void
setReturnCount
(
BigDecimal
returnCount
)
{
this
.
returnCount
=
returnCount
;
}
}
order-service/src/main/java/com/ssy/lingxi/order/model/dto/
AfterSaleReturnProduc
tDTO.java
→
order-service/src/main/java/com/ssy/lingxi/order/model/dto/
OrderReturnAmoun
tDTO.java
View file @
d5b815b6
package
com
.
ssy
.
lingxi
.
order
.
model
.
dto
;
import
java.io.Serializable
;
import
java.
util.List
;
import
java.
math.BigDecimal
;
/**
* 售后服务 -
退货 - 重新计算支付金额接口DTO
* 售后服务 -
订单退货退款 - 修改剩余支付次数支付金额
* @author 万宁
* @version 2.0.0
* @date 2021-09-
03
* @date 2021-09-
11
*/
public
class
AfterSaleReturnProductDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
3325664129030062311L
;
public
class
OrderReturnAmountDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
7230468219971330004L
;
public
OrderReturnAmountDTO
()
{
}
public
OrderReturnAmountDTO
(
Long
orderId
,
BigDecimal
leftAmount
)
{
this
.
orderId
=
orderId
;
this
.
leftAmount
=
leftAmount
;
}
/**
* 订单Id
...
...
@@ -18,9 +26,9 @@ public class AfterSaleReturnProductDTO implements Serializable {
private
Long
orderId
;
/**
* 退货
商品信息
* 退货
后的商品总金额
*/
private
List
<
AfterSaleReturnProductDetailDTO
>
products
;
private
BigDecimal
leftAmount
;
public
Long
getOrderId
()
{
return
orderId
;
...
...
@@ -30,11 +38,11 @@ public class AfterSaleReturnProductDTO implements Serializable {
this
.
orderId
=
orderId
;
}
public
List
<
AfterSaleReturnProductDetailDTO
>
getProducts
()
{
return
products
;
public
BigDecimal
getLeftAmount
()
{
return
leftAmount
;
}
public
void
set
Products
(
List
<
AfterSaleReturnProductDetailDTO
>
products
)
{
this
.
products
=
products
;
public
void
set
LeftAmount
(
BigDecimal
leftAmount
)
{
this
.
leftAmount
=
leftAmount
;
}
}
order-service/src/main/java/com/ssy/lingxi/order/repository/OrderPaymentRepository.java
View file @
d5b815b6
...
...
@@ -25,7 +25,7 @@ public interface OrderPaymentRepository extends JpaRepository<OrderPaymentDO, Lo
List
<
OrderPaymentDO
>
findByOrderAndPayAmountGreaterThan
(
OrderDO
order
,
BigDecimal
payAmount
,
Sort
sort
);
List
<
OrderPaymentDO
>
findByOrderInAndPayAmountGreaterThanAndOuterStatusIn
(
List
<
Long
>
orderId
s
,
BigDecimal
payAmount
,
List
<
Integer
>
outerStatus
);
List
<
OrderPaymentDO
>
findByOrderInAndPayAmountGreaterThanAndOuterStatusIn
(
List
<
OrderDO
>
order
s
,
BigDecimal
payAmount
,
List
<
Integer
>
outerStatus
);
@Transactional
void
deleteByOrder
(
OrderDO
order
);
...
...
order-service/src/main/java/com/ssy/lingxi/order/service/base/IBaseOrderPaymentService.java
View file @
d5b815b6
...
...
@@ -6,7 +6,7 @@ import com.ssy.lingxi.order.entity.OrderPaymentDO;
import
com.ssy.lingxi.order.model.bo.OrderPayResultBO
;
import
com.ssy.lingxi.order.model.bo.OrderPaymentBO
;
import
com.ssy.lingxi.order.model.bo.PayNodeBO
;
import
com.ssy.lingxi.order.model.dto.
AfterSaleReturnProduc
tDTO
;
import
com.ssy.lingxi.order.model.dto.
OrderReturnAmoun
tDTO
;
import
com.ssy.lingxi.order.model.vo.basic.request.OrderPaymentVO
;
import
com.ssy.lingxi.order.model.vo.buyer.response.BuyerOrderPayNodeQueryVO
;
import
com.ssy.lingxi.order.model.vo.buyer.response.BuyerOrderPaymentDetailVO
;
...
...
@@ -130,8 +130,9 @@ public interface IBaseOrderPaymentService {
/**
* 售后服务 - 退货 - 修改支付次数的金额
* @param afterSaleReturnProducts 售后退货商品
* @param orders 订单列表
* @param returnAmounts 订单Id及退款金额
* @return 操作结果
*/
Wrapper
<
Void
>
batchUpdateOrderPayments
(
List
<
AfterSaleReturnProductDTO
>
afterSaleReturnProduc
ts
);
Wrapper
<
Void
>
batchUpdateOrderPayments
(
List
<
OrderDO
>
orders
,
List
<
OrderReturnAmountDTO
>
returnAmoun
ts
);
}
order-service/src/main/java/com/ssy/lingxi/order/serviceimpl/base/BaseOrderPaymentServiceImpl.java
View file @
d5b815b6
...
...
@@ -13,7 +13,7 @@ import com.ssy.lingxi.order.model.constant.BuyerInnerStatusEnum;
import
com.ssy.lingxi.order.model.constant.OrderOuterStatusEnum
;
import
com.ssy.lingxi.order.model.constant.OrderServiceContants
;
import
com.ssy.lingxi.order.model.constant.VendorInnerStatusEnum
;
import
com.ssy.lingxi.order.model.dto.
AfterSaleReturnProduc
tDTO
;
import
com.ssy.lingxi.order.model.dto.
OrderReturnAmoun
tDTO
;
import
com.ssy.lingxi.order.model.dto.PayResultDTO
;
import
com.ssy.lingxi.order.model.vo.basic.request.OrderPaymentVO
;
import
com.ssy.lingxi.order.model.vo.buyer.response.BuyerOrderPayNodeQueryVO
;
...
...
@@ -780,29 +780,45 @@ public class BaseOrderPaymentServiceImpl implements IBaseOrderPaymentService {
/**
* 售后服务 - 退货 - 修改支付次数的金额
*
* @param afterSaleReturnProducts 售后退货商品
* @param orders 订单列表
* @param returnAmounts 订单Id及退款金额
* @return 操作结果
*/
@Override
public
Wrapper
<
Void
>
batchUpdateOrderPayments
(
List
<
AfterSaleReturnProductDTO
>
afterSaleReturnProduc
ts
)
{
if
(
CollectionUtils
.
isEmpty
(
afterSaleReturnProduc
ts
))
{
public
Wrapper
<
Void
>
batchUpdateOrderPayments
(
List
<
OrderDO
>
orders
,
List
<
OrderReturnAmountDTO
>
returnAmoun
ts
)
{
if
(
CollectionUtils
.
isEmpty
(
returnAmoun
ts
))
{
return
Wrapper
.
success
();
}
// //Step 1: 如果没有退货,返回
// List<Long> orderIds = afterSaleReturnProducts.stream().filter(afterSale -> afterSale.getProducts().stream().anyMatch(afterSaleProduct -> afterSaleProduct.getReturnCount().compareTo(BigDecimal.ZERO) > 0)).map(OrderAfterSaleVO::getOrderId).collect(Collectors.toList());
// if(CollectionUtils.isEmpty(orderIds)) {
// return Wrapper.success();
// }
//
// //Step 2: 如果没有支付记录,返回
// List<OrderPaymentDO> orderPaymentList = orderPaymentRepository.findByOrderInAndPayAmountGreaterThanAndOuterStatusIn(orderIds, BigDecimal.ZERO, Stream.of(OrderOuterStatusEnum.TO_PAY.getCode(), OrderOuterStatusEnum.PAYMENT_NOT_ACCOMPLISH.getCode()).collect(Collectors.toList()));
// if(CollectionUtils.isEmpty(orderPaymentList)) {
// return Wrapper.success();
// }
//查询支付金额大于0,且外部状态为“待支付”和“确认未到账”的支付记录
List
<
Integer
>
outerStatus
=
Stream
.
of
(
OrderOuterStatusEnum
.
TO_PAY
.
getCode
(),
OrderOuterStatusEnum
.
PAYMENT_NOT_ACCOMPLISH
.
getCode
()).
collect
(
Collectors
.
toList
());
List
<
OrderPaymentDO
>
orderPaymentList
=
orderPaymentRepository
.
findByOrderInAndPayAmountGreaterThanAndOuterStatusIn
(
orders
,
BigDecimal
.
ZERO
,
outerStatus
);
return
null
;
}
for
(
OrderReturnAmountDTO
returnAmount
:
returnAmounts
)
{
List
<
OrderPaymentDO
>
orderPayments
=
orderPaymentList
.
stream
().
filter
(
payment
->
payment
.
getOrder
().
getId
().
equals
(
returnAmount
.
getOrderId
())).
collect
(
Collectors
.
toList
());
if
(
CollectionUtils
.
isEmpty
(
orderPayments
))
{
continue
;
}
Map
<
Integer
,
BigDecimal
>
payAmountMap
=
averageLeftPayAmount
(
returnAmount
.
getLeftAmount
(),
orderPayments
);
orderPayments
.
forEach
(
payment
->
payment
.
setPayAmount
(
payAmountMap
.
getOrDefault
(
payment
.
getBatchNo
(),
payment
.
getPayAmount
())));
}
orderPaymentRepository
.
saveAll
(
orderPaymentList
);
return
Wrapper
.
success
();
}
/**
* 退货后,计算剩余支付次数的支付金额
* @param leftAmount (退货后的)商品总额
* @param orderPayments 支付次数,支付比例保留4位小数
* @return 每批次支付的金额
*/
private
Map
<
Integer
,
BigDecimal
>
averageLeftPayAmount
(
BigDecimal
leftAmount
,
List
<
OrderPaymentDO
>
orderPayments
)
{
Integer
maxBatch
=
orderPayments
.
stream
().
map
(
OrderPaymentDO:
:
getBatchNo
).
max
(
Comparator
.
comparingInt
(
Integer:
:
intValue
)).
orElse
(
0
);
Map
<
Integer
,
BigDecimal
>
map
=
orderPayments
.
stream
().
filter
(
payment
->
payment
.
getBatchNo
().
compareTo
(
maxBatch
)
<
0
).
collect
(
Collectors
.
toMap
(
OrderPaymentDO:
:
getBatchNo
,
payment
->
leftAmount
.
multiply
(
payment
.
getPayRate
()).
setScale
(
2
,
RoundingMode
.
HALF_UP
)));
map
.
put
(
maxBatch
,
leftAmount
.
subtract
(
map
.
values
().
stream
().
reduce
(
BigDecimal:
:
add
).
orElse
(
BigDecimal
.
ZERO
)));
return
map
;
}
}
order-service/src/main/java/com/ssy/lingxi/order/serviceimpl/feign/OrderFeignServiceImpl.java
View file @
d5b815b6
...
...
@@ -17,8 +17,10 @@ import com.ssy.lingxi.order.api.model.vo.response.*;
import
com.ssy.lingxi.order.entity.*
;
import
com.ssy.lingxi.order.model.bo.*
;
import
com.ssy.lingxi.order.model.constant.OrderOuterStatusEnum
;
import
com.ssy.lingxi.order.model.dto.OrderReturnAmountDTO
;
import
com.ssy.lingxi.order.repository.OrderProductRepository
;
import
com.ssy.lingxi.order.repository.OrderRepository
;
import
com.ssy.lingxi.order.service.base.IBaseOrderPaymentService
;
import
com.ssy.lingxi.order.service.base.IBaseOrderProcessService
;
import
com.ssy.lingxi.order.service.feign.IOrderFeignService
;
import
com.ssy.lingxi.order.service.web.IBuyerOrderService
;
...
...
@@ -48,6 +50,9 @@ public class OrderFeignServiceImpl implements IOrderFeignService {
private
OrderProductRepository
orderProductRepository
;
@Resource
private
IBaseOrderPaymentService
baseOrderPaymentService
;
@Resource
private
IBuyerOrderService
buyerOrderService
;
@Resource
...
...
@@ -202,7 +207,7 @@ public class OrderFeignServiceImpl implements IOrderFeignService {
}
List
<
Long
>
orderProductIds
=
afterSales
.
stream
().
flatMap
(
a
->
a
.
getProducts
().
stream
().
map
(
OrderProductAfterSaleVO:
:
getProductId
)).
collect
(
Collectors
.
toList
());
List
<
OrderProductDO
>
orderProducts
=
orderProductRepository
.
find
AllById
(
orderProductId
s
);
List
<
OrderProductDO
>
orderProducts
=
orderProductRepository
.
find
ByOrderIn
(
order
s
);
if
(
CollectionUtils
.
isEmpty
(
orderProducts
)
||
orderProducts
.
size
()
!=
orderProductIds
.
stream
().
distinct
().
count
())
{
return
Wrapper
.
fail
(
ResponseCode
.
ORDER_PRODUCT_DOES_NOT_EXIST
);
}
...
...
@@ -216,7 +221,10 @@ public class OrderFeignServiceImpl implements IOrderFeignService {
}));
orderProductRepository
.
saveAll
(
orderProducts
);
return
Wrapper
.
success
();
return
baseOrderPaymentService
.
batchUpdateOrderPayments
(
orders
,
orderProducts
.
stream
().
collect
(
Collectors
.
groupingBy
(
p
->
p
.
getOrder
().
getId
())).
entrySet
().
stream
().
map
(
entry
->
new
OrderReturnAmountDTO
(
entry
.
getKey
(),
entry
.
getValue
().
stream
().
map
(
p
->
p
.
getQuantity
().
subtract
(
p
.
getReturnCount
()).
multiply
(
p
.
getRefPrice
())).
reduce
(
BigDecimal
.
ZERO
,
BigDecimal:
:
add
))
).
collect
(
Collectors
.
toList
()));
}
/**
...
...
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