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
8e410187
Commit
8e410187
authored
Dec 22, 2020
by
刘鹏飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coco定制核销优惠券
parent
7fcff535
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
668 additions
and
66 deletions
+668
-66
assortment-ordercenter-sdk/src/main/java/com/freemud/sdk/api/assortment/order/adapter/OrderSdkAdapter.java
+1
-1
order-application-service/src/main/java/cn/freemud/entities/dto/CouponCodeBaseDto.java
+24
-1
order-application-service/src/main/java/cn/freemud/entities/dto/CouponCodeVerificationDto.java
+19
-0
order-application-service/src/main/java/cn/freemud/entities/dto/CouponCodeVerificationProductDto.java
+40
-2
order-application-service/src/main/java/cn/freemud/entities/dto/CouponCodeVerificationTransDto.java
+35
-2
order-application-service/src/main/java/cn/freemud/entities/dto/QueryOrdersResponseDto.java
+3
-0
order-application-service/src/main/java/cn/freemud/service/coupon/CouponRelationFactory.java
+25
-0
order-application-service/src/main/java/cn/freemud/service/coupon/CouponRelationService.java
+35
-0
order-application-service/src/main/java/cn/freemud/service/coupon/impl/CocoCouponRelationServiceImpl.java
+285
-0
order-application-service/src/main/java/cn/freemud/service/coupon/impl/CounponRelationFactoryImpl.java
+55
-0
order-application-service/src/main/java/cn/freemud/service/coupon/impl/PlatformCouponRelationServiceImpl.java
+129
-0
order-application-service/src/main/java/cn/freemud/service/impl/CouponActivityServiceImpl.java
+15
-60
order-application-service/src/main/java/cn/freemud/service/impl/OrderServiceImpl.java
+2
-0
No files found.
assortment-ordercenter-sdk/src/main/java/com/freemud/sdk/api/assortment/order/adapter/OrderSdkAdapter.java
View file @
8e410187
...
...
@@ -1935,7 +1935,7 @@ public class OrderSdkAdapter {
*
* @return
*/
p
rivate
Integer
getOldOrderAccountType
(
int
newOrderAccountType
)
{
p
ublic
Integer
getOldOrderAccountType
(
int
newOrderAccountType
)
{
// 新订单服务枚举 OrderSettlementType
switch
(
newOrderAccountType
)
{
case
1
:
...
...
order-application-service/src/main/java/cn/freemud/entities/dto/CouponCodeBaseDto.java
View file @
8e410187
...
...
@@ -17,12 +17,35 @@ import lombok.Data;
*/
@Data
public
class
CouponCodeBaseDto
{
/**
* 版本号
*/
private
Integer
ver
;
// 71代表核销
/**
* 操作类型:71核销,0查询,3冲正
*/
private
Integer
reqtype
;
/**
* 商户号
*/
private
String
partnerId
;
/**
* 门店号
*/
private
String
store_id
;
/**
* 线下pos编号, 除coco外,其他商户必填
*/
private
String
station_id
;
/**
* 操作员编号,除coco外,其他商户必填
*/
private
String
operator_id
;
// 组织机构ID,(String 类型的集合)
...
...
order-application-service/src/main/java/cn/freemud/entities/dto/CouponCodeVerificationDto.java
View file @
8e410187
...
...
@@ -18,11 +18,30 @@ import java.util.List;
*/
@Data
public
class
CouponCodeVerificationDto
extends
CouponCodeBaseDto
{
/**
* 流水号
*/
private
String
trans_id
;
/**
* 核销时间:yyyy-MM-dd
*/
private
String
business_date
;
/**
* 渠道,例如:pickup,delivery
*/
private
String
channel
;
/**
* 会员编号
*/
private
String
memberId
;
/**
* 核销交易信息
*/
private
List
<
CouponCodeVerificationTransDto
>
transactions
;
}
order-application-service/src/main/java/cn/freemud/entities/dto/CouponCodeVerificationProductDto.java
View file @
8e410187
...
...
@@ -2,6 +2,8 @@ package cn.freemud.entities.dto;
import
lombok.Data
;
import
java.math.BigDecimal
;
/**
* All rights Reserved, Designed By www.freemud.cn
*
...
...
@@ -16,8 +18,44 @@ import lombok.Data;
*/
@Data
public
class
CouponCodeVerificationProductDto
{
private
Integer
seq
;
private
String
pID
;
/**
* 核销数量
*/
private
Integer
consume_num
;
/**
* 商品编号
*/
private
String
pID
;
/**
* BigDecimal, 暂未使用
*/
private
BigDecimal
redeem_price
;
/**
* 商品序号或者行数
*/
private
Integer
seq
;
/**
* 商品名称
*/
private
String
productName
;
/**
* 线下原价,单位:分
*/
private
Integer
initPrice
;
/**
* 优惠后价格,单位:分
*/
private
Integer
nowPrice
;
/**
* 应收金额,单位:分
*/
private
Integer
payMoney
;
}
order-application-service/src/main/java/cn/freemud/entities/dto/CouponCodeVerificationTransDto.java
View file @
8e410187
...
...
@@ -19,8 +19,41 @@ import java.util.List;
*/
@Data
public
class
CouponCodeVerificationTransDto
{
/**
* 券号
*/
private
String
code
;
private
String
ebcode
;
private
Integer
totalAmount
;
//private String ebcode;
/**
* 实收金额单位:分
*/
private
Integer
pay_amount
;
/**
* 商品信息
*/
private
List
<
CouponCodeVerificationProductDto
>
products
;
/**
* 总优惠金额单位:分
*/
private
Integer
totalAmount
;
/**
* 订单号,coco核销使用
*/
private
String
orderNumber
;
/**
* 应收金额,单位:分,coco核销使用
*/
private
Integer
amountRec
;
/**
* 实收金额,单位:分
*/
private
Integer
amountPaid
;
}
order-application-service/src/main/java/cn/freemud/entities/dto/QueryOrdersResponseDto.java
View file @
8e410187
...
...
@@ -13,6 +13,7 @@
package
cn
.
freemud
.
entities
.
dto
;
import
com.freemud.application.sdk.api.ordercenter.response.orderInfo.OrderCostResp
;
import
com.freemud.application.sdk.api.ordercenter.response.orderInfo.OrderSettlementResp
;
import
com.freemud.sdk.api.assortment.order.response.order.QueryOrdersResponse
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
...
...
@@ -196,6 +197,8 @@ public class QueryOrdersResponseDto {
private
List
<
ProductBean
>
productList
;
private
List
<
RefundBean
>
refundList
;
private
List
<
OrderSettlementResp
>
orderSettlementDetailList
;
private
AddDeliveryInfo
addInfo
;
private
List
<
OrderCostResp
>
orderCostDetailList
;
...
...
order-application-service/src/main/java/cn/freemud/service/coupon/CouponRelationFactory.java
0 → 100644
View file @
8e410187
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: OrderRelationFactory
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package
cn
.
freemud
.
service
.
coupon
;
public
interface
CouponRelationFactory
{
/**
* 获取优惠券核销参数构建实现类
* @param partnerId
* @return
*/
CouponRelationService
getVerificationCouponService
(
String
partnerId
);
}
order-application-service/src/main/java/cn/freemud/service/coupon/CouponRelationService.java
0 → 100644
View file @
8e410187
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: OrderRelationService
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package
cn
.
freemud
.
service
.
coupon
;
import
cn.freemud.base.entity.BaseResponse
;
import
cn.freemud.entities.dto.QueryOrdersResponseDto
;
import
cn.freemud.entities.vo.CreateOrderVo
;
import
cn.freemud.entities.vo.QueryOrderResponseVo
;
import
cn.freemud.enums.CouponReqType
;
import
com.freemud.application.sdk.api.storecenter.response.StoreResponse
;
import
com.freemud.sdk.api.assortment.order.response.order.QueryOrderByIdResponse
;
import
java.util.List
;
public
interface
CouponRelationService
{
/**
* 获取优惠券核销参数构建实现类
* @param
*/
BaseResponse
verificationCoupon
(
List
<
QueryOrdersResponseDto
.
DataBean
.
OrderBean
.
AccountBean
>
accountList
,
QueryOrdersResponseDto
.
DataBean
.
OrderBean
orderBean
,
CouponReqType
couponReqType
);
}
order-application-service/src/main/java/cn/freemud/service/coupon/impl/CocoCouponRelationServiceImpl.java
0 → 100644
View file @
8e410187
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: CocoOrderRelationServiceImpl
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package
cn
.
freemud
.
service
.
coupon
.
impl
;
import
cn.freemud.adapter.CouponAdapter
;
import
cn.freemud.base.constant.Version
;
import
cn.freemud.base.entity.BaseResponse
;
import
cn.freemud.base.util.DateUtil
;
import
cn.freemud.entities.dto.*
;
import
cn.freemud.enums.ActivityChannelEnum
;
import
cn.freemud.enums.CouponReqType
;
import
cn.freemud.enums.OrderAccountType
;
import
cn.freemud.enums.ResponseResult
;
import
cn.freemud.service.coupon.CouponRelationService
;
import
cn.freemud.service.impl.StoreServiceImpl
;
import
cn.freemud.service.thirdparty.CouponOfflineClient
;
import
cn.freemud.utils.LogUtil
;
import
cn.freemud.utils.PropertyConvertUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.freemud.application.sdk.api.log.ApiLog
;
import
com.freemud.application.sdk.api.log.ErrorLog
;
import
com.freemud.application.sdk.api.log.ThirdPartyLog
;
import
com.freemud.application.sdk.api.ordercenter.response.orderInfo.OrderSettlementResp
;
import
com.freemud.application.sdk.api.service.EmailAlertService
;
import
com.freemud.sdk.api.assortment.order.adapter.OrderSdkAdapter
;
import
com.google.common.base.Throwables
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
cn.freemud.utils.ResponseUtil
;
import
java.math.BigDecimal
;
import
java.util.*
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
@Service
(
"cocoCouponRelationService"
)
public
class
CocoCouponRelationServiceImpl
implements
CouponRelationService
{
@Autowired
private
CouponAdapter
couponAdapter
;
@Autowired
private
CouponOfflineClient
couponOfflineClient
;
@Autowired
private
EmailAlertService
emailAlertService
;
@Autowired
private
StoreServiceImpl
storeService
;
@Autowired
private
OrderSdkAdapter
orderSdkAdapter
;
@Override
public
BaseResponse
verificationCoupon
(
List
<
QueryOrdersResponseDto
.
DataBean
.
OrderBean
.
AccountBean
>
accountList
,
QueryOrdersResponseDto
.
DataBean
.
OrderBean
orderBean
,
CouponReqType
couponReqType
)
{
// 订单商品信息
List
<
QueryOrdersResponseDto
.
DataBean
.
OrderBean
.
ProductBean
>
productList
=
orderBean
.
getProductList
();
if
(
CollectionUtils
.
isEmpty
(
orderBean
.
getProductList
())){
ApiLog
.
info
(
"coco订单没有商品信息不用核销优惠券"
,
orderBean
.
getOid
(),
""
);
return
ResponseUtil
.
success
();
}
// 订单促销信息
List
<
OrderSettlementResp
>
orderSettlementList
=
orderBean
.
getOrderSettlementDetailList
();
if
(
CollectionUtils
.
isEmpty
(
orderSettlementList
))
{
ApiLog
.
info
(
"coco订单没有促销信息不用核销优惠券"
,
orderBean
.
getOid
(),
""
);
return
ResponseUtil
.
success
();
}
// 根据商品id转map
Map
<
String
,
QueryOrdersResponseDto
.
DataBean
.
OrderBean
.
ProductBean
>
productMap
=
productList
.
stream
().
collect
(
Collectors
.
toMap
(
QueryOrdersResponseDto
.
DataBean
.
OrderBean
.
ProductBean
::
getProductId
,
Function
.
identity
(),
(
oldValue
,
newValue
)
->
newValue
));
// 根据活动号分组,没有活动号的直接筛选掉
Map
<
String
,
List
<
OrderSettlementResp
>>
orderSettlementMap
=
orderSettlementList
.
stream
().
filter
(
os
->
StringUtils
.
isNotEmpty
(
os
.
getExternalObjectId
()))
.
collect
(
Collectors
.
groupingBy
(
OrderSettlementResp:
:
getExternalObjectId
));
Integer
orderType
=
orderBean
.
getType
();
ActivityChannelEnum
activityChannelEnum
=
PropertyConvertUtil
.
orderTypeEnumConvert2ActivityChannel
(
orderType
);
if
(
activityChannelEnum
==
null
)
{
activityChannelEnum
=
ActivityChannelEnum
.
pickup
;
}
// 核销主体信息
CouponCodeVerificationDto
couponCodeVerificationDto
=
new
CouponCodeVerificationDto
();
couponCodeVerificationDto
.
setVer
(
Integer
.
valueOf
(
Version
.
VERSION_1
));
couponCodeVerificationDto
.
setReqtype
(
couponReqType
.
getCode
());
couponCodeVerificationDto
.
setPartnerId
(
orderBean
.
getCompanyId
());
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
));
// 核销券新增参数:组织机构ID
couponCodeVerificationDto
.
setChannel_codes
(
storeService
.
getOrgIdsArr
(
orderBean
.
getCompanyId
(),
orderBean
.
getShopId
()));
// 核销交易信息
List
<
CouponCodeVerificationTransDto
>
transactions
=
new
ArrayList
<>();
// 保存没有商品code的用券信息,主要是整单代金券
List
<
OrderSettlementResp
>
orderSettlementRemain
=
new
ArrayList
<>();
// 已经计算过的促销商品优惠信息
List
<
OrderSettlementResp
>
orderSettlementAlready
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
String
,
List
<
OrderSettlementResp
>>
m
:
orderSettlementMap
.
entrySet
())
{
// 活动相应的促销明细
List
<
OrderSettlementResp
>
orderSettlementInfo
=
m
.
getValue
();
if
(
orderSettlementInfo
==
null
||
orderSettlementInfo
.
isEmpty
()){
continue
;
}
// 活动类型
Integer
settlementType
=
orderSettlementInfo
.
get
(
0
).
getSettlementType
();
// 券号
String
couponCode
=
orderSettlementInfo
.
get
(
0
).
getExternalObjectId
();
// 根据活动号转类型
Integer
orderAccountType
=
orderSdkAdapter
.
getOldOrderAccountType
(
settlementType
);
// 不是商品券、代金券、折扣券不处理
if
(!
OrderAccountType
.
COUPON
.
getCode
().
equals
(
orderAccountType
)
&&
!
OrderAccountType
.
PRODUCT_COUPON
.
getCode
().
equals
(
orderAccountType
)
&&
!
OrderAccountType
.
DISCOUNT_COUPON
.
getCode
().
equals
(
orderAccountType
)){
continue
;
}
if
(
OrderAccountType
.
COUPON
.
getCode
().
equals
(
orderAccountType
)
&&
Objects
.
equals
(
orderSettlementInfo
.
get
(
0
).
getProductId
(),
0
)){
// 整单代金券,最后在计算
orderSettlementRemain
.
add
(
orderSettlementInfo
.
get
(
0
));
}
CouponCodeVerificationTransDto
couponCodeVerificationTransDto
=
new
CouponCodeVerificationTransDto
();
// 券号
couponCodeVerificationTransDto
.
setCode
(
couponCode
);
Integer
totalAmount
=
0
;
Integer
oriAmount
=
0
;
List
<
CouponCodeVerificationProductDto
>
products
=
new
ArrayList
<>();
for
(
OrderSettlementResp
osr
:
orderSettlementInfo
){
// 优惠金额大于0,此时取得是具体的商品优惠信息
if
(
osr
.
getSettlementAmount
()
!=
null
&&
osr
.
getSettlementAmount
().
compareTo
(
new
BigDecimal
(
0
))
==
1
){
totalAmount
=
totalAmount
+
(
osr
.
getSettlementAmount
()
==
null
?
0
:
osr
.
getSettlementAmount
().
intValue
());
}
// 商品code不为0,此时取得是具体的商品
if
(!
Objects
.
equals
(
osr
.
getProductId
(),
0
)){
// 计算商品原价
Integer
num
=
osr
.
getNumber
();
String
productId
=
osr
.
getProductId
();
QueryOrdersResponseDto
.
DataBean
.
OrderBean
.
ProductBean
pb
=
productMap
.
get
(
productId
);
if
(
pb
!=
null
){
oriAmount
=
oriAmount
+
(
pb
.
getPrice
()
==
null
?
0
:
pb
.
getPrice
().
intValue
())
*
(
num
==
null
?
0
:
num
);
}
orderSettlementAlready
.
add
(
osr
);
// 统计商品
CouponCodeVerificationProductDto
couponCodeVerificationProductDto
=
new
CouponCodeVerificationProductDto
();
couponCodeVerificationProductDto
.
setConsume_num
(
num
);
couponCodeVerificationProductDto
.
setPID
(
osr
.
getProductId
());
couponCodeVerificationProductDto
.
setSeq
(
osr
.
getProductSeq
());
couponCodeVerificationProductDto
.
setProductName
(
pb
.
getProductName
());
Integer
price
=
pb
.
getPrice
()
==
null
?
0
:
pb
.
getPrice
().
intValue
();
couponCodeVerificationProductDto
.
setInitPrice
(
price
);
couponCodeVerificationProductDto
.
setNowPrice
(
price
);
couponCodeVerificationProductDto
.
setPayMoney
(
price
);
products
.
add
(
couponCodeVerificationProductDto
);
}
}
couponCodeVerificationTransDto
.
setProducts
(
products
);
//处理第三方外卖单优惠金额信息
if
(
totalAmount
!=
null
&&
totalAmount
.
intValue
()
>
0
){
totalAmount
=
0
-
Math
.
abs
(
totalAmount
);
}
// 总优惠金额单位:分
couponCodeVerificationTransDto
.
setTotalAmount
(
totalAmount
);
// 订单号
couponCodeVerificationTransDto
.
setOrderNumber
(
orderBean
.
getOid
());
// 应收金额
couponCodeVerificationTransDto
.
setAmountRec
(
oriAmount
);
// 实收金额
couponCodeVerificationTransDto
.
setAmountPaid
(
oriAmount
);
transactions
.
add
(
couponCodeVerificationTransDto
);
}
// 带有商品的券,计算完之后,要计算整单的优惠券,
// 整单的商品减掉单品优惠后的剩下的就都是整单券的商品
if
(!
orderSettlementRemain
.
isEmpty
()){
Map
<
String
,
IntSummaryStatistics
>
collect
=
orderSettlementAlready
.
stream
().
collect
(
Collectors
.
groupingBy
(
OrderSettlementResp:
:
getProductId
,
Collectors
.
summarizingInt
(
OrderSettlementResp:
:
getNumber
)));
for
(
OrderSettlementResp
osr:
orderSettlementRemain
){
CouponCodeVerificationTransDto
couponCodeVerificationTransFull
=
new
CouponCodeVerificationTransDto
();
// 券号
couponCodeVerificationTransFull
.
setCode
(
osr
.
getExternalObjectId
());
// 总优惠金额单位:分
couponCodeVerificationTransFull
.
setTotalAmount
(
osr
.
getSettlementAmount
().
intValue
());
// 订单号
couponCodeVerificationTransFull
.
setOrderNumber
(
orderBean
.
getOid
());
List
<
CouponCodeVerificationProductDto
>
productsFull
=
new
ArrayList
<>();
Integer
totalAmountFull
=
0
;
for
(
QueryOrdersResponseDto
.
DataBean
.
OrderBean
.
ProductBean
pb
:
productList
){
Long
alreadyNum
=
collect
.
get
(
osr
.
getProductId
())
==
null
?
0L
:
collect
.
get
(
osr
.
getProductId
()).
getSum
();
Integer
num
=
pb
.
getNumber
();
Integer
remainNum
=
num
-
alreadyNum
.
intValue
();
if
(
Objects
.
equals
(
remainNum
,
0
)){
continue
;
}
// 统计商品
CouponCodeVerificationProductDto
couponCodeVerificationProductFull
=
new
CouponCodeVerificationProductDto
();
couponCodeVerificationProductFull
.
setConsume_num
(
remainNum
);
couponCodeVerificationProductFull
.
setPID
(
osr
.
getProductId
());
couponCodeVerificationProductFull
.
setSeq
(
osr
.
getProductSeq
());
couponCodeVerificationProductFull
.
setProductName
(
pb
.
getProductName
());
Integer
price
=
pb
.
getPrice
()
==
null
?
0
:
pb
.
getPrice
().
intValue
();
couponCodeVerificationProductFull
.
setInitPrice
(
price
);
couponCodeVerificationProductFull
.
setNowPrice
(
price
);
couponCodeVerificationProductFull
.
setPayMoney
(
price
);
productsFull
.
add
(
couponCodeVerificationProductFull
);
totalAmountFull
=
totalAmountFull
+
price
*
remainNum
;
}
couponCodeVerificationTransFull
.
setProducts
(
productsFull
);
couponCodeVerificationTransFull
.
setAmountPaid
(
totalAmountFull
);
couponCodeVerificationTransFull
.
setAmountRec
(
totalAmountFull
);
transactions
.
add
(
couponCodeVerificationTransFull
);
}
}
couponCodeVerificationDto
.
setTransactions
(
transactions
);
try
{
//71.券核销
for
(
int
i
=
2
;
i
>=
0
;
i
--)
{
LogUtil
.
info
(
"coco核销券码开始=="
,
JSON
.
toJSONString
(
couponCodeVerificationDto
),
null
);
CouponCodeResponseDto
couponCodeResponseDto
=
couponOfflineClient
.
verification
(
couponCodeVerificationDto
);
LogUtil
.
info
(
"coco核销券码返回=="
,
JSON
.
toJSONString
(
couponCodeVerificationDto
),
null
);
ThirdPartyLog
.
infoConvertJson
(
System
.
currentTimeMillis
(),
System
.
currentTimeMillis
(),
"/api"
,
couponCodeVerificationDto
,
couponCodeResponseDto
);
if
(
Objects
.
equals
(
couponCodeResponseDto
.
getStatusCode
(),
ResponseResult
.
SUCCESS
.
getCode
()))
{
LogUtil
.
info
(
"coco CocoCouponRelationServiceImpl"
,
JSON
.
toJSONString
(
couponCodeVerificationDto
),
JSON
.
toJSONString
(
couponCodeResponseDto
));
break
;
}
if
(!
Objects
.
equals
(
couponCodeResponseDto
.
getStatusCode
(),
ResponseResult
.
SUCCESS
.
getCode
()))
{
emailAlertService
.
sendEmailAlert
(
"cooc核销券码失败"
,
String
.
format
(
"request:%s \r\nresponse:%s"
,
JSONObject
.
toJSONString
(
couponCodeVerificationDto
),
JSONObject
.
toJSONString
(
couponCodeResponseDto
)));
return
ResponseUtil
.
error
(
ResponseResult
.
COUPON_VERIFICATION_FAIL
);
}
}
}
catch
(
Exception
ex
)
{
emailAlertService
.
sendEmailAlert
(
"coco核销券码异常"
,
String
.
format
(
"request:%s \r\nexception:%s"
,
JSONObject
.
toJSONString
(
couponCodeVerificationDto
),
Throwables
.
getStackTraceAsString
(
ex
)));
ErrorLog
.
printErrorLog
(
"coco verification_error"
,
"/api"
,
couponCodeVerificationDto
,
ex
);
return
ResponseUtil
.
error
(
ResponseResult
.
COUPON_VERIFICATION_FAIL
);
}
return
ResponseUtil
.
success
();
}
}
order-application-service/src/main/java/cn/freemud/service/coupon/impl/CounponRelationFactoryImpl.java
0 → 100644
View file @
8e410187
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: OrderRelationFactoryImpl
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package
cn
.
freemud
.
service
.
coupon
.
impl
;
import
cn.freemud.service.coupon.CouponRelationFactory
;
import
cn.freemud.service.coupon.CouponRelationService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
@Service
public
class
CounponRelationFactoryImpl
implements
CouponRelationFactory
{
/**
* coco商户
*/
@Value
(
"#{'${coco.partnerId}'.split(',')}"
)
private
List
<
String
>
cocoPartnerId
;
/**
* coco的订单相关
*/
@Autowired
@Qualifier
(
"cocoCouponRelationService"
)
CouponRelationService
cocoCouponRelationService
;
/**
* 平台的订单相关
*/
@Autowired
@Qualifier
(
"platformCouponRelationService"
)
CouponRelationService
platformCouponRelationService
;
@Override
public
CouponRelationService
getVerificationCouponService
(
String
partnerId
)
{
if
(
cocoPartnerId
.
contains
(
partnerId
)){
return
cocoCouponRelationService
;
}
else
{
return
platformCouponRelationService
;
}
}
}
order-application-service/src/main/java/cn/freemud/service/coupon/impl/PlatformCouponRelationServiceImpl.java
0 → 100644
View file @
8e410187
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: PlatformOrderRelationServiceImpl
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package
cn
.
freemud
.
service
.
coupon
.
impl
;
import
cn.freemud.adapter.CouponAdapter
;
import
cn.freemud.base.entity.BaseResponse
;
import
cn.freemud.entities.dto.CouponCodeResponseDto
;
import
cn.freemud.entities.dto.CouponCodeVerificationDto
;
import
cn.freemud.entities.dto.CouponCodeVerificationProductDto
;
import
cn.freemud.entities.dto.QueryOrdersResponseDto
;
import
cn.freemud.entities.vo.CreateOrderVo
;
import
cn.freemud.entities.vo.QueryOrderResponseVo
;
import
cn.freemud.enums.ActivityChannelEnum
;
import
cn.freemud.enums.CouponReqType
;
import
cn.freemud.enums.OrderAccountType
;
import
cn.freemud.enums.ResponseResult
;
import
cn.freemud.service.coupon.CouponRelationFactory
;
import
cn.freemud.service.coupon.CouponRelationService
;
import
cn.freemud.service.impl.StoreServiceImpl
;
import
cn.freemud.service.order.OrderRelationService
;
import
cn.freemud.service.thirdparty.CouponOfflineClient
;
import
cn.freemud.utils.LogUtil
;
import
cn.freemud.utils.PropertyConvertUtil
;
import
cn.freemud.utils.ResponseUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.freemud.application.sdk.api.couponcenter.offline.service.OfflineCouponSdkService
;
import
com.freemud.application.sdk.api.log.ErrorLog
;
import
com.freemud.application.sdk.api.log.ThirdPartyLog
;
import
com.freemud.application.sdk.api.service.EmailAlertService
;
import
com.freemud.application.sdk.api.storecenter.response.StoreResponse
;
import
com.freemud.sdk.api.assortment.order.response.order.QueryOrderByIdResponse
;
import
com.google.common.base.Throwables
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.stream.Collectors
;
@Service
(
"platformCouponRelationService"
)
public
class
PlatformCouponRelationServiceImpl
implements
CouponRelationService
{
@Autowired
private
CouponAdapter
couponAdapter
;
@Autowired
private
CouponOfflineClient
couponOfflineClient
;
@Autowired
private
EmailAlertService
emailAlertService
;
@Autowired
private
StoreServiceImpl
storeService
;
@Override
public
BaseResponse
verificationCoupon
(
List
<
QueryOrdersResponseDto
.
DataBean
.
OrderBean
.
AccountBean
>
accountList
,
QueryOrdersResponseDto
.
DataBean
.
OrderBean
orderBean
,
CouponReqType
couponReqType
)
{
for
(
QueryOrdersResponseDto
.
DataBean
.
OrderBean
.
AccountBean
accountBean
:
accountList
)
{
List
<
CouponCodeVerificationProductDto
>
products
=
new
ArrayList
<>();
//商品券核销核销参数
if
(
OrderAccountType
.
PRODUCT_COUPON
.
getCode
().
equals
(
accountBean
.
getType
()))
{
for
(
int
i
=
0
;
i
<
orderBean
.
getProductList
().
size
();
i
++)
{
QueryOrdersResponseDto
.
DataBean
.
OrderBean
.
ProductBean
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
<
QueryOrdersResponseDto
.
DataBean
.
OrderBean
.
ProductBean
.
ProductDiscount
>
discounts
=
orderBean
.
getProductList
().
get
(
i
).
getDiscountList
().
stream
().
filter
(
productDiscount
->
productDiscount
.
getDiscountId
().
equals
(
accountBean
.
getAccountId
())).
collect
(
Collectors
.
toList
());
for
(
QueryOrdersResponseDto
.
DataBean
.
OrderBean
.
ProductBean
.
ProductDiscount
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
);
products
.
add
(
couponCodeVerificationProductDto
);
}
}
}
}
Integer
orderType
=
orderBean
.
getType
();
ActivityChannelEnum
activityChannelEnum
=
PropertyConvertUtil
.
orderTypeEnumConvert2ActivityChannel
(
orderType
);
if
(
activityChannelEnum
==
null
)
{
activityChannelEnum
=
ActivityChannelEnum
.
pickup
;
}
if
(
OrderAccountType
.
COUPON
.
getCode
().
equals
(
accountBean
.
getType
())
||
OrderAccountType
.
PRODUCT_COUPON
.
getCode
().
equals
(
accountBean
.
getType
())
||
OrderAccountType
.
DISCOUNT_COUPON
.
getCode
().
equals
(
accountBean
.
getType
()))
{
CouponCodeVerificationDto
couponCodeVerificationDto
=
couponAdapter
.
convert2CouponCodeVerificationDto
(
activityChannelEnum
,
accountBean
.
getAccountId
(),
orderBean
.
getOid
(),
orderBean
.
getCompanyId
(),
orderBean
.
getShopId
(),
orderBean
.
getUserId
(),
products
,
accountBean
.
getPrice
().
intValue
(),
couponReqType
);
// 核销券新增参数:组织机构ID
couponCodeVerificationDto
.
setChannel_codes
(
storeService
.
getOrgIdsArr
(
orderBean
.
getCompanyId
(),
orderBean
.
getShopId
()));
try
{
//71.券核销
for
(
int
i
=
2
;
i
>=
0
;
i
--)
{
LogUtil
.
info
(
"核销券码开始=="
,
JSON
.
toJSONString
(
couponCodeVerificationDto
),
null
);
CouponCodeResponseDto
couponCodeResponseDto
=
couponOfflineClient
.
verification
(
couponCodeVerificationDto
);
LogUtil
.
info
(
"核销券码返回=="
,
JSON
.
toJSONString
(
couponCodeVerificationDto
),
null
);
ThirdPartyLog
.
infoConvertJson
(
System
.
currentTimeMillis
(),
System
.
currentTimeMillis
(),
"/api"
,
couponCodeVerificationDto
,
couponCodeResponseDto
);
if
(
Objects
.
equals
(
couponCodeResponseDto
.
getStatusCode
(),
ResponseResult
.
SUCCESS
.
getCode
()))
{
LogUtil
.
info
(
"CouponReverseServiceImpl"
,
JSON
.
toJSONString
(
couponCodeVerificationDto
),
JSON
.
toJSONString
(
couponCodeResponseDto
));
break
;
}
if
(!
Objects
.
equals
(
couponCodeResponseDto
.
getStatusCode
(),
ResponseResult
.
SUCCESS
.
getCode
()))
{
emailAlertService
.
sendEmailAlert
(
"核销券码失败"
,
String
.
format
(
"request:%s \r\nresponse:%s"
,
JSONObject
.
toJSONString
(
couponCodeVerificationDto
),
JSONObject
.
toJSONString
(
couponCodeResponseDto
)));
return
ResponseUtil
.
error
(
ResponseResult
.
COUPON_VERIFICATION_FAIL
);
}
}
}
catch
(
Exception
ex
)
{
emailAlertService
.
sendEmailAlert
(
"核销券码异常"
,
String
.
format
(
"request:%s \r\nexception:%s"
,
JSONObject
.
toJSONString
(
couponCodeVerificationDto
),
Throwables
.
getStackTraceAsString
(
ex
)));
ErrorLog
.
printErrorLog
(
"verification_error"
,
"/api"
,
couponCodeVerificationDto
,
ex
);
return
ResponseUtil
.
error
(
ResponseResult
.
COUPON_VERIFICATION_FAIL
);
}
}
}
return
ResponseUtil
.
success
();
}
}
order-application-service/src/main/java/cn/freemud/service/impl/CouponActivityServiceImpl.java
View file @
8e410187
...
...
@@ -9,6 +9,8 @@ import cn.freemud.entities.vo.ActivityCouponBean;
import
cn.freemud.enums.*
;
import
cn.freemud.service.CouponActivityService
;
import
cn.freemud.service.StoreService
;
import
cn.freemud.service.coupon.CouponRelationFactory
;
import
cn.freemud.service.coupon.CouponRelationService
;
import
cn.freemud.service.thirdparty.CouponClient
;
import
cn.freemud.service.thirdparty.CouponOfflineClient
;
import
cn.freemud.utils.LogUtil
;
...
...
@@ -29,6 +31,7 @@ import com.google.gson.Gson;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
java.util.*
;
...
...
@@ -41,6 +44,12 @@ import java.util.stream.Collectors;
@Service
public
class
CouponActivityServiceImpl
implements
CouponActivityService
{
/**
* coco商户
*/
@Value
(
"#{'${coco.partnerId}'.split(',')}"
)
private
List
<
String
>
cocoPartnerId
;
@Autowired
private
CouponAdapter
couponAdapter
;
@Autowired
...
...
@@ -52,6 +61,9 @@ public class CouponActivityServiceImpl implements CouponActivityService {
@Autowired
private
StoreServiceImpl
storeService
;
@Autowired
private
CouponRelationFactory
couponRelationFactory
;
/**
* 核销优惠券
*
...
...
@@ -63,67 +75,10 @@ public class CouponActivityServiceImpl implements CouponActivityService {
if
(
CollectionUtils
.
isEmpty
(
accountList
)
||
CollectionUtils
.
isEmpty
(
orderBean
.
getProductList
()))
{
return
ResponseUtil
.
success
();
}
for
(
QueryOrdersResponseDto
.
DataBean
.
OrderBean
.
AccountBean
accountBean
:
accountList
)
{
List
<
CouponCodeVerificationProductDto
>
products
=
new
ArrayList
<>();
//商品券核销核销参数
if
(
OrderAccountType
.
PRODUCT_COUPON
.
getCode
().
equals
(
accountBean
.
getType
()))
{
for
(
int
i
=
0
;
i
<
orderBean
.
getProductList
().
size
();
i
++)
{
QueryOrdersResponseDto
.
DataBean
.
OrderBean
.
ProductBean
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
<
QueryOrdersResponseDto
.
DataBean
.
OrderBean
.
ProductBean
.
ProductDiscount
>
discounts
=
orderBean
.
getProductList
().
get
(
i
).
getDiscountList
().
stream
().
filter
(
productDiscount
->
productDiscount
.
getDiscountId
().
equals
(
accountBean
.
getAccountId
())).
collect
(
Collectors
.
toList
());
for
(
QueryOrdersResponseDto
.
DataBean
.
OrderBean
.
ProductBean
.
ProductDiscount
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
);
products
.
add
(
couponCodeVerificationProductDto
);
}
}
}
}
Integer
orderType
=
orderBean
.
getType
();
ActivityChannelEnum
activityChannelEnum
=
PropertyConvertUtil
.
orderTypeEnumConvert2ActivityChannel
(
orderType
);
if
(
activityChannelEnum
==
null
)
{
activityChannelEnum
=
ActivityChannelEnum
.
pickup
;
}
if
(
OrderAccountType
.
COUPON
.
getCode
().
equals
(
accountBean
.
getType
())
||
OrderAccountType
.
PRODUCT_COUPON
.
getCode
().
equals
(
accountBean
.
getType
())
||
OrderAccountType
.
DISCOUNT_COUPON
.
getCode
().
equals
(
accountBean
.
getType
()))
{
CouponCodeVerificationDto
couponCodeVerificationDto
=
couponAdapter
.
convert2CouponCodeVerificationDto
(
activityChannelEnum
,
accountBean
.
getAccountId
(),
orderBean
.
getOid
(),
orderBean
.
getCompanyId
(),
orderBean
.
getShopId
(),
orderBean
.
getUserId
(),
products
,
accountBean
.
getPrice
().
intValue
(),
couponReqType
);
// 核销券新增参数:组织机构ID
couponCodeVerificationDto
.
setChannel_codes
(
storeService
.
getOrgIdsArr
(
orderBean
.
getCompanyId
(),
orderBean
.
getShopId
()));
try
{
//71.券核销
for
(
int
i
=
2
;
i
>=
0
;
i
--)
{
LogUtil
.
info
(
"核销券码开始=="
,
JSON
.
toJSONString
(
couponCodeVerificationDto
),
null
);
CouponCodeResponseDto
couponCodeResponseDto
=
couponOfflineClient
.
verification
(
couponCodeVerificationDto
);
LogUtil
.
info
(
"核销券码返回=="
,
JSON
.
toJSONString
(
couponCodeVerificationDto
),
null
);
ThirdPartyLog
.
infoConvertJson
(
System
.
currentTimeMillis
(),
System
.
currentTimeMillis
(),
"/api"
,
couponCodeVerificationDto
,
couponCodeResponseDto
);
if
(
Objects
.
equals
(
couponCodeResponseDto
.
getStatusCode
(),
ResponseResult
.
SUCCESS
.
getCode
()))
{
LogUtil
.
info
(
"CouponReverseServiceImpl"
,
JSON
.
toJSONString
(
couponCodeVerificationDto
),
JSON
.
toJSONString
(
couponCodeResponseDto
));
break
;
}
if
(!
Objects
.
equals
(
couponCodeResponseDto
.
getStatusCode
(),
ResponseResult
.
SUCCESS
.
getCode
()))
{
emailAlertService
.
sendEmailAlert
(
"核销券码失败"
,
String
.
format
(
"request:%s \r\nresponse:%s"
,
JSONObject
.
toJSONString
(
couponCodeVerificationDto
),
JSONObject
.
toJSONString
(
couponCodeResponseDto
)));
return
ResponseUtil
.
error
(
ResponseResult
.
COUPON_VERIFICATION_FAIL
);
}
}
}
catch
(
Exception
ex
)
{
emailAlertService
.
sendEmailAlert
(
"核销券码异常"
,
String
.
format
(
"request:%s \r\nexception:%s"
,
JSONObject
.
toJSONString
(
couponCodeVerificationDto
),
Throwables
.
getStackTraceAsString
(
ex
)));
ErrorLog
.
printErrorLog
(
"verification_error"
,
"/api"
,
couponCodeVerificationDto
,
ex
);
return
ResponseUtil
.
error
(
ResponseResult
.
COUPON_VERIFICATION_FAIL
);
}
}
}
return
ResponseUtil
.
success
();
// 平台走老的逻辑,cooc定制参数
CouponRelationService
couponRelationService
=
couponRelationFactory
.
getVerificationCouponService
(
orderBean
.
getCompanyId
());
return
couponRelationService
.
verificationCoupon
(
accountList
,
orderBean
,
couponReqType
);
}
@Override
...
...
order-application-service/src/main/java/cn/freemud/service/impl/OrderServiceImpl.java
View file @
8e410187
...
...
@@ -57,6 +57,8 @@ import cn.freemud.interceptor.ServiceException;
import
cn.freemud.management.thirdparty.MulitiPaymentClient
;
import
cn.freemud.redis.RedisCache
;
import
cn.freemud.service.*
;
import
cn.freemud.service.coupon.CouponRelationFactory
;
import
cn.freemud.service.coupon.CouponRelationService
;
import
cn.freemud.service.order.OrderRelationFactory
;
import
cn.freemud.service.order.OrderRelationService
;
import
cn.freemud.service.thirdparty.*
;
...
...
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