Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
order-group
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
order-group-application
order-group
Commits
6f25594b
Commit
6f25594b
authored
Oct 26, 2021
by
周晓航
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
核销 支持一单多券
Signed-off-by: 周晓航 <xiaohang.zhou@freemud.com>
parent
f8b6a2d0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
175 additions
and
45 deletions
+175
-45
assortment-ordercenter-sdk/src/main/java/com/freemud/sdk/api/assortment/order/adapter/OrderSdkAdapter.java
+23
-26
order-application-service/src/main/java/cn/freemud/adapter/CouponAdapter.java
+89
-0
order-application-service/src/main/java/cn/freemud/service/coupon/impl/PlatformCouponRelationServiceImpl.java
+63
-19
No files found.
assortment-ordercenter-sdk/src/main/java/com/freemud/sdk/api/assortment/order/adapter/OrderSdkAdapter.java
View file @
6f25594b
...
...
@@ -3803,26 +3803,29 @@ public class OrderSdkAdapter {
||
account
.
getAccountType
().
equals
(
QueryOrderAccountType
.
DISCOUNT_COUPON
)
||
account
.
getAccountType
().
equals
(
QueryOrderAccountType
.
FREIGHT_COUPON
)
).
collect
(
Collectors
.
toList
());
AssortOrderLogUtil
.
info
(
"优惠券转换,用于锁券操作 orderbean : accounts"
,
orderBean
,
accounts
);
if
(
CollectionUtils
.
isEmpty
(
couponList
))
{
return
null
;
}
// fisherman end
if
(
couponList
.
size
()
>
1
)
{
// 找出 配送券
CreateOrderAccountRequest
freightCouponAccountBean
=
couponList
.
stream
().
filter
(
account
->
account
.
getAccountType
().
equals
(
QueryOrderAccountType
.
FREIGHT_COUPON
)).
findFirst
().
orElse
(
null
);
TransactionVO
couponCodeVerificationTransDto
=
null
;
if
(!
Objects
.
isNull
(
freightCouponAccountBean
))
{
couponCodeVerificationTransDto
=
new
TransactionVO
();
couponCodeVerificationTransDto
.
setCode
(
freightCouponAccountBean
.
getAccountId
());
couponCodeVerificationTransDto
.
setTotalAmount
(
freightCouponAccountBean
.
getPrice
());
}
// 过滤出 配送券
List
<
CreateOrderAccountRequest
>
collect
=
couponList
.
stream
().
filter
(
account
->
!
account
.
getAccountType
().
equals
(
QueryOrderAccountType
.
FREIGHT_COUPON
)).
collect
(
Collectors
.
toList
());
return
commonMethodVerification
(
couponCodeVerificationTransDto
,
collect
,
orderBean
,
openId
);
}
else
{
return
commonMethodVerification
(
null
,
couponList
,
orderBean
,
openId
);
}
//fisherman 【01测16灰18全,【华莱士】【疑难专项】一个订单多张优惠券使用场景】 https://www.tapd.cn/43862731/prong/stories/view/1143862731001037477
return
this
.
commonMethodVerificationNew
(
couponList
,
orderBean
,
openId
);
// // fisherman end
// if (couponList.size() > 1) {
// // 找出 配送券
// CreateOrderAccountRequest freightCouponAccountBean = couponList.stream().filter(account -> account.getAccountType().equals(QueryOrderAccountType.FREIGHT_COUPON)).findFirst().orElse(null);
// TransactionVO couponCodeVerificationTransDto = null;
// if (!Objects.isNull(freightCouponAccountBean)) {
// couponCodeVerificationTransDto = new TransactionVO();
// couponCodeVerificationTransDto.setCode(freightCouponAccountBean.getAccountId());
// couponCodeVerificationTransDto.setTotalAmount(freightCouponAccountBean.getPrice());
// }
// // 过滤出 配送券
// List<CreateOrderAccountRequest> collect = couponList.stream().filter(account -> !account.getAccountType().equals(QueryOrderAccountType.FREIGHT_COUPON)).collect(Collectors.toList());
// return commonMethodVerification(couponCodeVerificationTransDto, collect, orderBean, openId);
// } else {
// return commonMethodVerification(null, couponList, orderBean, openId);
// }
}
private
CouponRequest
commonMethodVerification
(
TransactionVO
freightCouponAccountBean
,
...
...
@@ -3889,8 +3892,7 @@ public class OrderSdkAdapter {
return
couponRequest
;
}
private
CouponRequest
commonMethodVerificationNew
(
TransactionVO
freightCouponAccountBean
,
List
<
CreateOrderAccountRequest
>
collect
,
private
CouponRequest
commonMethodVerificationNew
(
List
<
CreateOrderAccountRequest
>
collect
,
OrderBeanV1
orderBean
,
String
openId
)
{
CouponRequest
couponRequest
=
new
CouponRequest
();
...
...
@@ -3910,14 +3912,13 @@ public class OrderSdkAdapter {
// 订单号 替换成唯一序号
couponRequest
.
setTrans_id
(
orderBean
.
getOid
());
couponRequest
.
setBusiness_date
(
DateUtil
.
convert2String
(
new
Date
(),
DateUtil
.
FORMAT_yyyyMMdd
));
List
<
TransactionVO
>
transactions
=
this
.
getTransactionList
(
freightCouponAccountBean
,
collect
,
orderBean
,
openId
);
List
<
TransactionVO
>
transactions
=
this
.
getTransactionList
(
collect
,
orderBean
,
openId
);
// 配送券逻辑 end
couponRequest
.
setTransactions
(
transactions
);
return
couponRequest
;
}
private
List
<
TransactionVO
>
getTransactionList
(
TransactionVO
freightCouponAccountBean
,
List
<
CreateOrderAccountRequest
>
collect
,
private
List
<
TransactionVO
>
getTransactionList
(
List
<
CreateOrderAccountRequest
>
collect
,
OrderBeanV1
orderBean
,
String
openId
)
{
List
<
TransactionVO
>
transactions
=
new
ArrayList
<>();
...
...
@@ -3955,10 +3956,6 @@ public class OrderSdkAdapter {
}
transactions
.
add
(
couponCodeVerificationTransDto
);
});
// 配送券逻辑加入
if
(
freightCouponAccountBean
!=
null
)
{
transactions
.
add
(
freightCouponAccountBean
);
}
return
transactions
;
}
...
...
order-application-service/src/main/java/cn/freemud/adapter/CouponAdapter.java
View file @
6f25594b
...
...
@@ -32,8 +32,10 @@ import cn.freemud.management.entities.dto.request.order.MCCafeProductRedeemVo;
import
cn.freemud.management.entities.dto.request.order.MCCafeTransactionVo
;
import
cn.freemud.management.entities.dto.response.coupon.McdNetBatchQueryResponse
;
import
cn.freemud.management.entities.dto.response.coupon.McdNetCouponProductRespDto
;
import
cn.freemud.management.enums.OrderSource
;
import
cn.freemud.service.mccafe.CouponClientService
;
import
cn.freemud.utils.BeanUtil
;
import
cn.freemud.utils.PropertyConvertUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.freemud.application.sdk.api.ordercenter.entities.v1.AccountBeanV1
;
import
com.freemud.application.sdk.api.ordercenter.entities.v1.OrderBeanV1
;
...
...
@@ -787,4 +789,91 @@ public class CouponAdapter {
return
mcCafeCouponLockRequest
;
}
/**
* 新版本 支持多券 批量核销操作
* @param orderBean
* @param couponReqType
* @return
*/
public
CouponCodeVerificationDto
convert2CouponCodeVerificationDto
(
OrderBeanV1
orderBean
,
CouponReqType
couponReqType
)
{
CouponCodeVerificationDto
couponCodeVerificationDto
=
new
CouponCodeVerificationDto
();
couponCodeVerificationDto
.
setVer
(
Integer
.
valueOf
(
Version
.
VERSION_1
));
couponCodeVerificationDto
.
setReqtype
(
couponReqType
.
getCode
());
couponCodeVerificationDto
.
setPartnerId
(
orderBean
.
getCompanyId
());
Integer
orderType
=
orderBean
.
getType
();
//商城单子用NewOrderType
if
(
Objects
.
equals
(
OrderSource
.
MALL
.
getSource
(),
orderBean
.
getSource
()))
{
orderType
=
orderBean
.
getNewOrderType
();
}
ActivityChannelEnum
activityChannelEnum
=
PropertyConvertUtil
.
orderTypeEnumConvert2ActivityChannel
(
orderType
);
if
(
activityChannelEnum
==
null
)
{
activityChannelEnum
=
ActivityChannelEnum
.
pickup
;
}
couponCodeVerificationDto
.
setChannel
(
activityChannelEnum
.
getCode
());
couponCodeVerificationDto
.
setStation_id
(
"-1"
);
couponCodeVerificationDto
.
setOperator_id
(
"-1"
);
couponCodeVerificationDto
.
setStore_id
(
orderBean
.
getShopId
());
couponCodeVerificationDto
.
setMemberId
(
orderBean
.
getUserId
());
// 订单号 替换成唯一序号
couponCodeVerificationDto
.
setTrans_id
(
orderBean
.
getOid
());
couponCodeVerificationDto
.
setBusiness_date
(
DateUtil
.
convert2Str
(
new
Date
(),
DateUtil
.
FORMAT_yyyyMMdd
));
List
<
CouponCodeVerificationTransDto
>
transactions
=
this
.
getTransactions
(
orderBean
,
couponCodeVerificationDto
);
couponCodeVerificationDto
.
setTransactions
(
transactions
);
return
couponCodeVerificationDto
;
}
/**
* 组装核销 参数
* @param orderBean
* @return
*/
private
List
<
CouponCodeVerificationTransDto
>
getTransactions
(
OrderBeanV1
orderBean
,
CouponCodeVerificationDto
couponCodeVerificationDto
)
{
List
<
AccountBeanV1
>
accountList
=
orderBean
.
getAccountList
();
List
<
CouponCodeVerificationTransDto
>
transactions
=
new
ArrayList
<>();
long
price
=
0L
;
for
(
AccountBeanV1
accountBean
:
accountList
)
{
if
(
OrderAccountType
.
verificationCoupon
.
contains
(
accountBean
.
getType
()))
{
List
<
CouponCodeVerificationProductDto
>
products
=
new
ArrayList
<>();
if
(
OrderAccountType
.
PRODUCT_COUPON
.
getCode
().
equals
(
accountBean
.
getType
()))
{
for
(
int
i
=
0
;
i
<
orderBean
.
getProductList
().
size
();
i
++)
{
ProductBeanV1
productBean
=
orderBean
.
getProductList
().
get
(
i
);
String
pid
=
StringUtils
.
isNotBlank
(
productBean
.
getSpecification
())
?
productBean
.
getSpecification
()
:
productBean
.
getProductId
();
if
(!
org
.
springframework
.
util
.
CollectionUtils
.
isEmpty
(
orderBean
.
getProductList
().
get
(
i
).
getDiscountList
()))
{
List
<
ProductDiscountV1
>
discounts
=
orderBean
.
getProductList
().
get
(
i
).
getDiscountList
().
stream
().
filter
(
productDiscount
->
productDiscount
.
getDiscountId
().
equals
(
accountBean
.
getAccountId
())).
collect
(
Collectors
.
toList
());
for
(
ProductDiscountV1
productDiscount
:
discounts
)
{
if
(
productDiscount
.
getDiscountType
()
==
null
||
productDiscount
.
getDiscountType
()
==
0
)
{
continue
;
}
CouponCodeVerificationProductDto
couponCodeVerificationProductDto
=
new
CouponCodeVerificationProductDto
();
couponCodeVerificationProductDto
.
setPID
(
pid
);
couponCodeVerificationProductDto
.
setConsume_num
(
productDiscount
.
getDiscountQty
());
couponCodeVerificationProductDto
.
setSeq
(
i
+
1
);
couponCodeVerificationProductDto
.
setRedeem_price
(
new
BigDecimal
(
productBean
.
getPrice
()));
products
.
add
(
couponCodeVerificationProductDto
);
}
}
}
}
CouponCodeVerificationTransDto
couponCodeVerificationTransDto
=
new
CouponCodeVerificationTransDto
();
if
(!
products
.
isEmpty
())
{
couponCodeVerificationTransDto
.
setProducts
(
products
);
}
couponCodeVerificationTransDto
.
setCode
(
accountBean
.
getAccountId
());
Long
discountPriceL
=
accountBean
.
getPrice
();
if
(
discountPriceL
!=
null
)
{
int
abs
=
Math
.
abs
(
discountPriceL
.
intValue
());
couponCodeVerificationTransDto
.
setTotalAmount
(
abs
);
price
+=
abs
;
}
transactions
.
add
(
couponCodeVerificationTransDto
);
}
}
// KA 【ID1032412】【订单聚合层】核销传入优惠金额之传劵优惠只设置券的优惠金额进行上报
couponCodeVerificationDto
.
setOrderDiscountAmount
(
price
);
return
transactions
;
}
}
order-application-service/src/main/java/cn/freemud/service/coupon/impl/PlatformCouponRelationServiceImpl.java
View file @
6f25594b
...
...
@@ -13,6 +13,7 @@
package
cn
.
freemud
.
service
.
coupon
.
impl
;
import
cn.freemud.adapter.CouponAdapter
;
import
cn.freemud.amp.body.OrderBody
;
import
cn.freemud.amqp.Header
;
import
cn.freemud.amqp.MQAction
;
import
cn.freemud.amqp.MQMessage
;
...
...
@@ -80,28 +81,30 @@ public class PlatformCouponRelationServiceImpl implements CouponRelationService
@Override
public
BaseResponse
verificationCoupon
(
List
<
AccountBeanV1
>
accountList
,
OrderBeanV1
orderBean
,
CouponReqType
couponReqType
)
{
// AppLogUtil.infoLog("fiserhman 券码核销 begin", JSON.toJSONString(accountList), JSON.toJSONString(orderBean));
if
(
CollectionUtils
.
isEmpty
(
accountList
))
{
return
ResponseUtil
.
success
();
}
// 需要判断 accountList 里面 是都 同时包含 配送券+ other券
boolean
isDoubleCoupon
=
checkAccountList
(
accountList
);
if
(
isDoubleCoupon
)
{
Integer
code
=
OrderAccountType
.
FREIGHT_COUPON
.
getCode
();
// 运费券 塞进 核销接口里面, 这里真的是贼恶心 逻辑不敢动
AccountBeanV1
freightCouponAccountBean
=
accountList
.
stream
().
filter
(
accountBean
->
code
.
equals
(
accountBean
.
getType
())).
findFirst
().
orElse
(
null
);
CouponCodeVerificationTransDto
couponCodeVerificationTransDto
=
null
;
if
(!
Objects
.
isNull
(
freightCouponAccountBean
))
{
couponCodeVerificationTransDto
=
new
CouponCodeVerificationTransDto
();
couponCodeVerificationTransDto
.
setCode
(
freightCouponAccountBean
.
getAccountId
());
couponCodeVerificationTransDto
.
setTotalAmount
(
freightCouponAccountBean
.
getPrice
().
intValue
());
}
// 过滤出配送券
List
<
AccountBeanV1
>
collect
=
accountList
.
stream
().
filter
(
accountBean
->
!
code
.
equals
(
accountBean
.
getType
())).
collect
(
Collectors
.
toList
());
return
commonMethodVerification
(
couponCodeVerificationTransDto
,
collect
,
orderBean
,
couponReqType
);
}
else
{
return
commonMethodVerification
(
null
,
accountList
,
orderBean
,
couponReqType
);
}
// fisherman 【01测16灰18全,【华莱士】【疑难专项】一个订单多张优惠券使用场景】 https://www.tapd.cn/43862731/prong/stories/view/1143862731001037477
BaseResponse
baseResponse
=
this
.
batchCouponHandle
(
orderBean
,
couponReqType
);
return
baseResponse
;
// // 需要判断 accountList 里面 是都 同时包含 配送券+ other券
// boolean isDoubleCoupon = checkAccountList(accountList);
// if (isDoubleCoupon) {
// Integer code = OrderAccountType.FREIGHT_COUPON.getCode();
// // 运费券 塞进 核销接口里面, 这里真的是贼恶心 逻辑不敢动
// AccountBeanV1 freightCouponAccountBean = accountList.stream().filter(accountBean -> code.equals(accountBean.getType())).findFirst().orElse(null);
// CouponCodeVerificationTransDto couponCodeVerificationTransDto = null;
// if (!Objects.isNull(freightCouponAccountBean)) {
// couponCodeVerificationTransDto = new CouponCodeVerificationTransDto();
// couponCodeVerificationTransDto.setCode(freightCouponAccountBean.getAccountId());
// couponCodeVerificationTransDto.setTotalAmount(freightCouponAccountBean.getPrice().intValue());
// }
// // 过滤出配送券
// List<AccountBeanV1> collect = accountList.stream().filter(accountBean -> !code.equals(accountBean.getType())).collect(Collectors.toList());
// return commonMethodVerification(couponCodeVerificationTransDto, collect, orderBean, couponReqType);
// } else {
// return commonMethodVerification(null, accountList, orderBean, couponReqType);
// }
}
/**
...
...
@@ -231,6 +234,47 @@ public class PlatformCouponRelationServiceImpl implements CouponRelationService
return
ResponseUtil
.
success
();
}
/**
* 单笔订单 多券核销
* @param orderBean
* @param couponReqType
* @return
*/
private
BaseResponse
batchCouponHandle
(
OrderBeanV1
orderBean
,
CouponReqType
couponReqType
)
{
CouponCodeVerificationDto
couponCodeVerificationDto
=
couponAdapter
.
convert2CouponCodeVerificationDto
(
orderBean
,
couponReqType
);
if
(
Objects
.
isNull
(
couponCodeVerificationDto
)
||
couponCodeVerificationDto
.
getTransactions
().
isEmpty
())
{
return
ResponseUtil
.
success
();
}
couponCodeVerificationDto
.
setOrderTotalAmount
(
orderBean
.
getOriginalAmount
()
==
null
?
0L
:
orderBean
.
getOriginalAmount
().
longValue
());
couponCodeVerificationDto
.
setOrderPaymentAmount
(
orderBean
.
getAmount
());
// 核销券新增参数:组织机构ID
couponCodeVerificationDto
.
setChannel_ids
(
storeService
.
getOrgIdsArr
(
orderBean
.
getCompanyId
(),
orderBean
.
getShopId
()));
boolean
ok
=
false
;
Exception
lastException
=
null
;
CouponCodeResponseDto
couponCodeResponseDto
=
null
;
try
{
couponCodeResponseDto
=
couponOfflineClient
.
verification
(
couponCodeVerificationDto
);
ThirdPartyLog
.
infoConvertJson
(
System
.
currentTimeMillis
(),
System
.
currentTimeMillis
(),
"/api"
,
couponCodeVerificationDto
,
couponCodeResponseDto
);
if
(
Objects
.
nonNull
(
couponCodeResponseDto
)
&&
Objects
.
equals
(
couponCodeResponseDto
.
getStatusCode
(),
ResponseResult
.
SUCCESS
.
getCode
()))
{
ok
=
true
;
}
}
catch
(
Exception
ex
)
{
lastException
=
ex
;
ErrorLog
.
printErrorLog
(
"verification_error"
,
"/api"
,
couponCodeVerificationDto
,
ex
);
}
if
(
lastException
!=
null
)
{
sendMessage
(
orderBean
,
LogThreadLocal
.
getTrackingNo
(),
couponCodeVerificationDto
,
lastException
);
}
else
if
(!
ok
||
Objects
.
equals
(
baffleOpen
,
true
))
{
sendMessage
(
orderBean
,
LogThreadLocal
.
getTrackingNo
(),
couponCodeVerificationDto
,
ok
?
"模拟券核销失败"
:
couponCodeResponseDto
);
}
if
(!
ok
)
{
emailAlertService
.
sendEmailAlert
(
"核销券码失败"
,
String
.
format
(
"request:%s \r\nresponse:%s"
,
JSONObject
.
toJSONString
(
couponCodeVerificationDto
),
JSONObject
.
toJSONString
(
lastException
==
null
?
couponCodeResponseDto
:
lastException
)));
return
ResponseUtil
.
error
(
ResponseResult
.
COUPON_VERIFICATION_FAIL
);
}
return
ResponseUtil
.
success
();
}
/**
* 发送消息
...
...
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