Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gxpt_ht
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pseer
gxpt_ht
Commits
78f5a43c
Commit
78f5a43c
authored
Jan 21, 2024
by
hayden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.团购验证完毕直接核销对应美团券,已经团购验证的券无法再重新验证
2.定时访问美团api验证所有未使用的团购券,失效者删除 3.去除下单时的券核销逻辑
parent
ee78c786
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
89 deletions
+79
-89
RedisTask.java
share-quartz/src/main/java/share/quartz/task/RedisTask.java
+34
-35
QPServiceImpl.java
...rc/main/java/share/system/service/impl/QPServiceImpl.java
+24
-45
SOrderServiceImpl.java
...ain/java/share/system/service/impl/SOrderServiceImpl.java
+21
-9
No files found.
share-quartz/src/main/java/share/quartz/task/RedisTask.java
View file @
78f5a43c
...
...
@@ -7,11 +7,17 @@ import cn.hutool.json.JSONException;
import
cn.hutool.json.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.dianping.openapi.sdk.api.oauth.entity.CustomerRefreshTokenResponse
;
import
com.dianping.openapi.sdk.api.tuangou.TuangouReceiptPrepare
;
import
com.dianping.openapi.sdk.api.tuangou.entity.TuangouReceiptPrepareRequest
;
import
com.dianping.openapi.sdk.api.tuangou.entity.TuangouReceiptPrepareResponse
;
import
com.dianping.openapi.sdk.httpclient.DefaultOpenAPIClient
;
import
com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
...
...
@@ -83,47 +89,40 @@ public class RedisTask {
final
long
FOUR_MINUTES
=
60
*
4
;
//3分钟的常量
final
long
THREE_MINUTES
=
60
*
3
;
@Value
(
"${dianping.appKey}"
)
private
String
APP_KEY
;
@Value
(
"${dianping.appSecret}"
)
private
String
APP_SECRET
;
public
void
AuToReceiptCode
()
{
//获取redis中所有以tuangou.receipt.prepare开头的key
Set
<
String
>
keys
=
redisTemplate
.
keys
(
ReceiptRdeisEnum
.
PREPARE
.
getValue
()
+
"*"
);
if
(
keys
.
size
()
==
0
)
{
return
;
}
//获取所有待使用的优惠卷
LambdaQueryWrapper
<
SConsumerCoupon
>
queryWrapper
=
new
LambdaQueryWrapper
<>();
queryWrapper
.
eq
(
SConsumerCoupon:
:
getUseStatus
,
CouponStatusEnum
.
NORMAL
.
getValue
());
List
<
SConsumerCoupon
>
list
=
isConsumerCouponService
.
list
(
queryWrapper
);
//遍历key
keys
.
stream
().
forEach
(
o
->
{
//获取key对应的value
String
value
=
redisUtil
.
get
(
String
.
valueOf
(
o
));
JSONObject
jsonObject
=
new
JSONObject
(
value
);
Date
expirationTime
=
jsonObject
.
getDate
(
"expirationTime"
);
//判断是否过期
if
(
expirationTime
.
getTime
()
<
new
Date
().
getTime
())
{
//获取redis中的券码id
Long
consumerCouponId
=
jsonObject
.
getLong
(
"consumerCouponId"
);
if
(
CollectionUtils
.
isEmpty
(
list
))
{
//删除redis中的值
redisUtil
.
delete
(
o
);
//删除数据库中的值
isConsumerCouponService
.
deleteSConsumerCouponById
(
consumerCouponId
);
//跳过循环
return
;
}
if
(
ObjectUtil
.
isEmpty
(
list
.
stream
().
filter
(
item
->
item
.
getId
().
equals
(
consumerCouponId
)).
findFirst
().
orElse
(
null
)))
{
//删除redis中的值
redisUtil
.
delete
(
o
);
//删除数据库中的值
isConsumerCouponService
.
deleteSConsumerCouponById
(
consumerCouponId
);
}
else
{
//删除redis中的值
redisUtil
.
delete
(
o
);
LambdaQueryWrapper
<
SConsumerCoupon
>
wrapper
=
Wrappers
.
lambdaQuery
();
wrapper
.
eq
(
SConsumerCoupon:
:
getUseStatus
,
CouponStatusEnum
.
NORMAL
.
getValue
());
wrapper
.
isNotNull
(
SConsumerCoupon:
:
getCouponCode
);
List
<
SConsumerCoupon
>
coupons
=
isConsumerCouponService
.
list
(
wrapper
);
List
<
SStore
>
stores
=
storeService
.
list
();
List
<
Long
>
expiredCoupons
=
new
ArrayList
<>();
if
(!
CollectionUtils
.
isEmpty
(
coupons
))
{
for
(
SConsumerCoupon
coupon
:
coupons
)
{
//验券
String
o
=
redisUtil
.
get
(
ReceiptRdeisEnum
.
MT_SESSION_KEY
.
getValue
());
JSONObject
sessionKey
=
new
JSONObject
(
o
);
String
session
=
(
String
)
sessionKey
.
get
(
"access_token"
);
TuangouReceiptPrepareRequest
request
=
new
TuangouReceiptPrepareRequest
(
APP_KEY
,
APP_SECRET
,
session
,
coupon
.
getCouponCode
(),
""
,
stores
.
stream
().
filter
(
store
->
store
.
getId
().
equals
(
coupon
.
getStoreId
())).
findFirst
().
get
().
getOpenShopUuid
());
TuangouReceiptPrepare
tuangouReceiptPrepare
=
new
TuangouReceiptPrepare
(
request
);
DefaultOpenAPIClient
client
=
new
DefaultOpenAPIClient
();
TuangouReceiptPrepareResponse
invoke
=
client
.
invoke
(
tuangouReceiptPrepare
);
if
(
invoke
.
getCode
()
!=
200
)
{
expiredCoupons
.
add
(
coupon
.
getId
());
}
logger
.
info
(
"券码:{}->查询结束:{}"
,
coupon
.
getCouponCode
(),
invoke
.
getData
());
}
});
//逻辑删除所有异常优惠券
isConsumerCouponService
.
removeByIds
(
expiredCoupons
);
}
}
public
void
processAutoReceiptCode
()
{
...
...
share-system/src/main/java/share/system/service/impl/QPServiceImpl.java
View file @
78f5a43c
package
share
.
system
.
service
.
impl
;
import
cn.hutool.core.date.DatePattern
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.json.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.dianping.openapi.sdk.api.customerauth.session.CustomerKeyShopScopeQuery
;
...
...
@@ -90,35 +92,24 @@ public class QPServiceImpl implements QPService {
*/
@Override
public
TuangouReceiptPrepareResponseEntityVo
consumeByUser
(
String
code
,
String
openShopUuid
,
String
status
)
{
LambdaQueryWrapper
<
SStore
>
sStoreLambdaQueryWrapper
=
new
LambdaQueryWrapper
<>();
sStoreLambdaQueryWrapper
.
eq
(
SStore:
:
getOpenShopUuid
,
openShopUuid
);
SStore
sStore
=
storeService
.
getOne
(
sStoreLambdaQueryWrapper
);
if
(
ObjectUtils
.
isEmpty
(
sStore
)
||
StoreStatusEnum
.
STOP
.
getIndex
().
equals
(
sStore
.
getStatus
()))
{
throw
new
RuntimeException
(
"门店状态异常,请联系管理员"
);
}
//验券准备
TuangouReceiptPrepareResponseEntity
prepare
=
prepare
(
code
.
trim
(),
openShopUuid
,
status
);
//获取用户信息
SConsumer
user
=
FrontTokenComponent
.
getWxSConsumerEntry
();
//查询领取记录表
LambdaQueryWrapper
<
SConsumerCoupon
>
queryWrapper
=
new
LambdaQueryWrapper
<>();
queryWrapper
.
eq
(
SConsumerCoupon:
:
getDealId
,
prepare
.
getDeal_id
());
queryWrapper
.
eq
(
SConsumerCoupon:
:
getCouponCode
,
code
);
queryWrapper
.
eq
(
SConsumerCoupon:
:
getUseStatus
,
UserStatusEnum
.
UNUSED
.
getCode
());
SConsumerCoupon
couponTwo
=
isConsumerCouponService
.
getOne
(
queryWrapper
);
LambdaQueryWrapper
<
SStore
>
sStoreLambdaQueryWrapper
=
new
LambdaQueryWrapper
<>();
sStoreLambdaQueryWrapper
.
eq
(
SStore:
:
getOpenShopUuid
,
openShopUuid
);
SStore
sStore
=
storeService
.
getOne
(
sStoreLambdaQueryWrapper
);
if
(
ObjectUtils
.
isEmpty
(
sStore
))
{
throw
new
RuntimeException
(
"门店不存在"
);
}
if
(
sStore
.
getStatus
().
equals
(
StoreStatusEnum
.
STOP
.
getIndex
()))
{
throw
new
RuntimeException
(
"门店已停止"
);
}
if
(
ObjectUtils
.
isNotEmpty
(
couponTwo
))
{
//判断是否本人领取过
if
(
couponTwo
.
getConsumerId
().
equals
(
user
.
getId
()))
{
//领取删除原来的
isConsumerCouponService
.
deleteSConsumerCouponById
(
couponTwo
.
getId
());
//删除redis
redisUtil
.
delete
(
ReceiptRdeisEnum
.
PREPARE
.
getValue
()
+
prepare
.
getReceipt_code
());
}
else
{
return
null
;
}
SConsumerCoupon
unUsedCoupon
=
isConsumerCouponService
.
getOne
(
queryWrapper
);
if
(
ObjectUtils
.
isNotEmpty
(
unUsedCoupon
))
{
throw
new
RuntimeException
(
"该券已被领取"
);
}
//根据优惠卷名称查询优惠劵配置 查询list,取第一个
TuangouReceiptPrepareResponseEntityVo
response
=
new
TuangouReceiptPrepareResponseEntityVo
();
...
...
@@ -134,20 +125,15 @@ public class QPServiceImpl implements QPService {
sConsumerCoupon
.
setCreateBy
(
String
.
valueOf
(
user
.
getId
()));
sConsumerCoupon
.
setCreateTime
(
new
Date
());
sConsumerCoupon
.
setSubPrice
(
BigDecimal
.
valueOf
(
prepare
.
getDeal_marketprice
()));
//
根据门店id查询门店
信息
List
<
TuangouDealQueryShopDealResponseEntity
>
queryshopdeal
=
queryshopdeal
(
openShopUuid
);
queryshopdeal
.
stream
()
.
forEach
(
o
->
{
//
查询美团团购
信息
List
<
TuangouDealQueryShopDealResponseEntity
>
groupActivities
=
queryshopdeal
(
openShopUuid
);
groupActivities
.
forEach
(
o
->
{
//套餐名称相同并且在售卖中
if
(
prepare
.
getDeal_title
().
equals
(
o
.
getTitle
())
&&
o
.
getSale_status
().
equals
(
saleStatusEnum
.
SELLING
.
getCode
()))
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
);
try
{
Date
receiptEndDate
=
sdf
.
parse
(
o
.
getReceipt_end_date
());
Date
receiptBeginDate
=
sdf
.
parse
(
o
.
getReceipt_begin_date
());
sConsumerCoupon
.
setStartDate
(
receiptBeginDate
);
sConsumerCoupon
.
setEndDate
(
receiptEndDate
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(
prepare
.
getDeal_title
().
equals
(
o
.
getTitle
())
&&
saleStatusEnum
.
SELLING
.
getCode
().
equals
(
o
.
getSale_status
()))
{
Date
receiptEndDate
=
DateUtil
.
parse
(
o
.
getReceipt_end_date
(),
DatePattern
.
NORM_DATETIME_MINUTE_PATTERN
);
Date
receiptBeginDate
=
DateUtil
.
parse
(
o
.
getReceipt_begin_date
(),
DatePattern
.
NORM_DATETIME_MINUTE_PATTERN
);
sConsumerCoupon
.
setStartDate
(
receiptBeginDate
);
sConsumerCoupon
.
setEndDate
(
receiptEndDate
);
}
});
...
...
@@ -187,19 +173,12 @@ public class QPServiceImpl implements QPService {
}
isConsumerCouponService
.
insertSConsumerCoupon
(
sConsumerCoupon
);
response
.
setConsumerCouponId
(
sConsumerCoupon
.
getId
());
//设置过期时间30分钟
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"receipt_code"
,
prepare
.
getReceipt_code
());
map
.
put
(
"consumerCouponId"
,
String
.
valueOf
(
response
.
getConsumerCouponId
()));
//设置30分钟后的时间
Date
date
=
DateUtils
.
addMinutes
(
new
Date
(),
30
);
map
.
put
(
"expirationTime"
,
String
.
valueOf
(
date
));
JSONObject
jsonObject
=
new
JSONObject
(
map
);
redisUtil
.
set
(
ReceiptRdeisEnum
.
PREPARE
.
getValue
()
+
prepare
.
getReceipt_code
(),
jsonObject
.
toString
());
SimpleDateFormat
format2
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
output1
=
format2
.
format
(
prepare
.
getReceiptEndDate
());
String
output1
=
DateUtil
.
format
(
prepare
.
getReceiptEndDate
(),
DatePattern
.
NORM_DATETIME_PATTERN
);
BeanUtils
.
copyProperties
(
prepare
,
response
);
response
.
setExpirationTime
(
output1
);
//核销美团券
consume
(
code
.
trim
(),
1
,
openShopUuid
,
ConsumerCouponStatusEnum
.
ORDER
.
getCode
());
return
response
;
}
...
...
share-system/src/main/java/share/system/service/impl/SOrderServiceImpl.java
View file @
78f5a43c
...
...
@@ -14,6 +14,10 @@ import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.dianping.openapi.sdk.api.tuangou.TuangouReceiptGetConsumed
;
import
com.dianping.openapi.sdk.api.tuangou.entity.TuangouReceiptGetConsumedReponse
;
import
com.dianping.openapi.sdk.api.tuangou.entity.TuangouReceiptGetConsumedRequest
;
import
com.dianping.openapi.sdk.httpclient.DefaultOpenAPIClient
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
...
...
@@ -50,6 +54,10 @@ import share.system.service.*;
public
class
SOrderServiceImpl
extends
ServiceImpl
<
SOrderMapper
,
SOrder
>
implements
ISOrderService
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SOrderServiceImpl
.
class
);
@Value
(
"${dianping.appKey}"
)
private
String
APP_KEY
;
@Value
(
"${dianping.appSecret}"
)
private
String
APP_SECRET
;
@Value
(
"${order.allow-refund-time}"
)
private
Long
allowRefundTime
;
...
...
@@ -323,7 +331,19 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
if
(
Objects
.
nonNull
(
byId
))
{
if
(
byId
.
getUseStatus
().
equals
(
UserStatusEnum
.
UNUSED
.
getCode
()))
{
if
(
StringUtils
.
isNotEmpty
(
byId
.
getCouponCode
()))
{
qpService
.
prepare
(
byId
.
getCouponCode
(),
sStore
.
getOpenShopUuid
(),
ConsumerCouponStatusEnum
.
ORDER
.
getCode
());
String
o
=
redisUtil
.
get
(
ReceiptRdeisEnum
.
MT_SESSION_KEY
.
getValue
());
JSONObject
sessionKey
=
new
JSONObject
(
o
);
String
session
=
(
String
)
sessionKey
.
get
(
"access_token"
);
TuangouReceiptGetConsumedRequest
getConsumedRequest
=
new
TuangouReceiptGetConsumedRequest
(
APP_KEY
,
APP_SECRET
,
session
,
byId
.
getCouponCode
(),
""
,
sStore
.
getOpenShopUuid
());
TuangouReceiptGetConsumed
getConsumed
=
new
TuangouReceiptGetConsumed
(
getConsumedRequest
);
DefaultOpenAPIClient
client
=
new
DefaultOpenAPIClient
();
TuangouReceiptGetConsumedReponse
invoke
=
client
.
invoke
(
getConsumed
);
if
(
invoke
.
getCode
()
==
200
)
{
if
(
invoke
.
getData
()
==
null
)
{
logger
.
error
(
"验卷准备失败:{}"
,
invoke
.
getMsg
());
throw
new
RuntimeException
(
"优惠券异常,请稍后再试"
);
}
}
}
}
else
{
throw
new
BaseException
(
"优惠券已使用!"
);
...
...
@@ -349,10 +369,6 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
save
(
sOrder
);
if
(
response
.
getStatus
().
equals
(
YesNoEnum
.
yes
.
getFlag
()))
{
if
(
Objects
.
nonNull
(
byId
))
{
if
(
StringUtils
.
isNotEmpty
(
byId
.
getCouponCode
()))
{
//验劵
qpService
.
consume
(
byId
.
getCouponCode
(),
1
,
sStore
.
getOpenShopUuid
(),
ConsumerCouponStatusEnum
.
ORDER
.
getCode
());
}
SConsumerCoupon
consumerCoupon
=
new
SConsumerCoupon
();
consumerCoupon
.
setId
(
request
.
getCouponId
());
consumerCoupon
.
setUseDate
(
new
Date
());
...
...
@@ -795,10 +811,6 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
SConsumerCoupon
consumerCoupon
=
consumerCouponService
.
getById
(
couponId
);
if
(
ObjectUtil
.
isNotEmpty
(
consumerCoupon
))
{
if
(
consumerCoupon
.
getUseStatus
().
equals
(
UserStatusEnum
.
UNUSED
.
getCode
()))
{
if
(
StringUtils
.
isNotEmpty
(
consumerCoupon
.
getCouponCode
()))
{
//验劵
qpService
.
consume
(
consumerCoupon
.
getCouponCode
(),
1
,
sStore
.
getOpenShopUuid
(),
ConsumerCouponStatusEnum
.
WECHAT
.
getCode
());
}
consumerCoupon
.
setUseDate
(
new
Date
());
consumerCoupon
.
setUseStatus
(
UserStatusEnum
.
USED
.
getCode
());
consumerCouponService
.
updateById
(
consumerCoupon
);
...
...
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