Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fzm-joying
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
lei
fzm-joying
Commits
8f56bd20
Commit
8f56bd20
authored
May 10, 2022
by
33
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新日志
parent
920cc093
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
17 deletions
+28
-17
OrderServiceImpl.java
...in/java/com/fzm/common/service/impl/OrderServiceImpl.java
+2
-1
WxPayServiceImpl.java
...in/java/com/fzm/common/service/impl/WxPayServiceImpl.java
+17
-8
NftListener.java
...al/src/main/java/com/fzm/portal/listener/NftListener.java
+3
-3
OrderListener.java
.../src/main/java/com/fzm/portal/listener/OrderListener.java
+6
-5
No files found.
joying-common/src/main/java/com/fzm/common/service/impl/OrderServiceImpl.java
View file @
8f56bd20
...
...
@@ -32,7 +32,6 @@ import java.util.List;
* @date 2022/1/19 15:42
*/
@Service
@Transactional
(
rollbackFor
=
RuntimeException
.
class
)
public
class
OrderServiceImpl
extends
ServiceImpl
<
OrderMapper
,
Order
>
implements
OrderService
{
@Resource
private
NftService
nftService
;
...
...
@@ -67,6 +66,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
}
@Override
@Transactional
(
rollbackFor
=
RuntimeException
.
class
)
public
Order
createOrder
(
OrderDto
orderDto
)
{
Charge
charge
=
chargeService
.
getByType
(
orderDto
.
getPayScene
());
if
(!
orderDto
.
getFee
().
equals
(
charge
.
getFee
()))
{
...
...
@@ -121,6 +121,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
}
@Override
@Transactional
(
rollbackFor
=
RuntimeException
.
class
)
public
Boolean
cancel
(
Long
orderId
,
OrderStatus
orderStatus
)
{
Order
order
=
this
.
getById
(
orderId
);
Integer
productId
=
order
.
getProductId
();
...
...
joying-common/src/main/java/com/fzm/common/service/impl/WxPayServiceImpl.java
View file @
8f56bd20
...
...
@@ -52,7 +52,6 @@ import java.util.concurrent.TimeUnit;
*/
@Slf4j
@Service
@Transactional
(
rollbackFor
=
RuntimeException
.
class
)
public
class
WxPayServiceImpl
implements
WxPayService
{
@Resource
private
CloseableHttpClient
httpClient
;
...
...
@@ -75,6 +74,8 @@ public class WxPayServiceImpl implements WxPayService {
@Resource
private
RefundService
refundService
;
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Map
<
String
,
Object
>
payJsapi
(
JsapiPayDto
jsapiPayDto
)
throws
Exception
{
RLock
lock
=
redisson
.
getLock
(
"pay-"
+
jsapiPayDto
.
getOrderId
());
if
(!
lock
.
tryLock
(
10
,
TimeUnit
.
SECONDS
))
{
...
...
@@ -155,6 +156,7 @@ public class WxPayServiceImpl implements WxPayService {
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Boolean
notifyH5
(
HttpServletRequest
request
)
{
try
{
String
requestBodyData
=
this
.
getRequestBodyData
(
request
);
...
...
@@ -175,6 +177,7 @@ public class WxPayServiceImpl implements WxPayService {
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
processOrder
(
JSONObject
jsonObject
)
throws
InterruptedException
{
// 获取订单号
Long
out_trade_no
=
jsonObject
.
getLong
(
"out_trade_no"
);
...
...
@@ -189,10 +192,7 @@ public class WxPayServiceImpl implements WxPayService {
log
.
warn
(
"当前订单已处理完成, 订单号:==> {}"
,
out_trade_no
);
return
;
}
Integer
productId
=
order
.
getProductId
();
// 订单支付成功后,给mq发送一条消息,处理nft发行或版权申请的状态
OrderProcessMsg
orderProcessMsg
=
new
OrderProcessMsg
(
out_trade_no
,
productId
,
order
.
getPayScene
());
rabbitTemplate
.
convertAndSend
(
"order-exchange"
,
"order.process"
,
orderProcessMsg
);
// 修改订单状态
orderService
.
updateOrderStatus
(
out_trade_no
,
OrderStatus
.
PAYED
);
// 插入支付流水记录
...
...
@@ -204,6 +204,11 @@ public class WxPayServiceImpl implements WxPayService {
payment
.
setSuccessTime
(
jsonObject
.
getStr
(
"success_time"
));
payment
.
setContent
(
JSONUtil
.
toJsonStr
(
jsonObject
));
paymentService
.
save
(
payment
);
// 订单支付成功后,给mq发送一条消息,处理nft发行或版权申请的状态
Integer
productId
=
order
.
getProductId
();
OrderProcessMsg
orderProcessMsg
=
new
OrderProcessMsg
(
out_trade_no
,
productId
,
order
.
getPayScene
());
rabbitTemplate
.
convertAndSend
(
"order-exchange"
,
"order.process"
,
orderProcessMsg
);
}
}
finally
{
lock
.
unlock
();
...
...
@@ -212,6 +217,7 @@ public class WxPayServiceImpl implements WxPayService {
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
String
queryOrder
(
Long
orderId
)
throws
IOException
,
InterruptedException
{
String
url
=
String
.
format
(
"https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/%s?mchid=%s"
,
orderId
,
wxPayProperties
.
getMchId
());
HttpGet
httpGet
=
new
HttpGet
(
url
);
...
...
@@ -229,6 +235,7 @@ public class WxPayServiceImpl implements WxPayService {
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Boolean
refund
(
Long
orderId
,
Integer
channel
)
throws
IOException
,
InterruptedException
{
boolean
result
;
RLock
lock
=
redisson
.
getLock
(
"refund-"
+
orderId
);
...
...
@@ -238,7 +245,7 @@ public class WxPayServiceImpl implements WxPayService {
try
{
Order
order
=
orderService
.
getById
(
orderId
);
if
(
order
==
null
||
!
order
.
getOrderStatus
().
equals
(
OrderStatus
.
PAYED
.
getStatus
()))
{
throw
GlobalException
.
newException
(
ResultCode
.
REFUND_FAILED
,
"当前订单未支付成功
"
);
throw
GlobalException
.
newException
(
ResultCode
.
REFUND_FAILED
,
"当前订单未支付成功
:"
+
orderId
);
}
// 订单金额=0的时候,直接返回
if
(
order
.
getFee
()
<=
0
)
{
...
...
@@ -282,7 +289,7 @@ public class WxPayServiceImpl implements WxPayService {
refund
.
setRefundId
(
jsonObject
.
getStr
(
"refund_id"
));
refund
.
setTransactionId
(
jsonObject
.
getStr
(
"transaction_id"
));
refund
.
setUserReceivedAccount
(
jsonObject
.
getStr
(
"user_received_account"
));
refund
.
setRefundStatus
(
channel
);
refund
.
setRefundStatus
(
RefundStatus
.
REFUNDING
.
getStatus
()
);
// 修改订单状态为退款中
orderService
.
updateOrderStatus
(
orderId
,
OrderStatus
.
REFUNDING
);
result
=
true
;
...
...
@@ -295,7 +302,7 @@ public class WxPayServiceImpl implements WxPayService {
refund
.
setId
(
out_refund_no
);
refund
.
setFee
(
order
.
getFee
());
refund
.
setOrderId
(
orderId
);
refund
.
setChannel
(
RefundLaunchChannel
.
USER
.
getCode
()
);
refund
.
setChannel
(
channel
);
refundService
.
saveOrUpdate
(
refund
);
// 如果是用户端发起的退款, 失败时则需抛出异常,告知系统管理员退款失败
if
(
RefundLaunchChannel
.
USER
.
getCode
().
equals
(
channel
))
{
...
...
@@ -309,6 +316,7 @@ public class WxPayServiceImpl implements WxPayService {
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Boolean
notifyRefund
(
HttpServletRequest
request
)
{
try
{
String
requestBodyData
=
this
.
getRequestBodyData
(
request
);
...
...
@@ -327,6 +335,7 @@ public class WxPayServiceImpl implements WxPayService {
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
processRefund
(
JSONObject
obj
)
throws
InterruptedException
{
Long
out_trade_no
=
obj
.
getLong
(
"out_trade_no"
);
Long
out_refund_no
=
obj
.
getLong
(
"out_refund_no"
);
...
...
joying-portal/src/main/java/com/fzm/portal/listener/NftListener.java
View file @
8f56bd20
...
...
@@ -22,6 +22,7 @@ import org.apache.commons.lang3.StringUtils;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.transaction.annotation.Transactional
;
/**
* @author tangtuo
...
...
@@ -46,10 +47,9 @@ public class NftListener {
* @param msg
*/
@RabbitListener
(
queues
=
"nft.publish.queue"
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
listenNftPublish
(
NftPublishMsg
msg
)
throws
Exception
{
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"收到确认nft发行结果的消息: {}"
,
msg
);
}
log
.
info
(
"收到确认nft发行结果的消息: {}"
,
msg
);
Nft
nft
=
nftService
.
getById
(
msg
.
getId
());
User
user
=
userService
.
getUserByWallet
(
nft
.
getPublishAddress
());
...
...
joying-portal/src/main/java/com/fzm/portal/listener/OrderListener.java
View file @
8f56bd20
...
...
@@ -14,6 +14,7 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.transaction.annotation.Transactional
;
/**
* @author tangtuo
...
...
@@ -29,10 +30,9 @@ public class OrderListener {
private
final
WxPayService
wxPayService
;
@RabbitListener
(
queues
=
"order.process.queue"
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
listenProcessOrder
(
OrderProcessMsg
msg
)
throws
Exception
{
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"收到处理订单的消息: {}"
,
msg
);
}
log
.
info
(
"收到处理订单的消息: {}"
,
msg
);
try
{
if
(
PayScene
.
NFT
.
getCode
().
equals
(
msg
.
getPayScene
()))
{
...
...
@@ -43,8 +43,7 @@ public class OrderListener {
copyrightApplyService
.
updateRegisterState
(
msg
.
getProductId
(),
CopyrightApplyState
.
TO_BE_REVIEWED
.
getCode
());
}
}
catch
(
Exception
e
)
{
// 处理失败,需要主动发起退款
wxPayService
.
refund
(
msg
.
getOrderId
(),
RefundLaunchChannel
.
USER
.
getCode
());
log
.
error
(
"nft发行时发生异常"
,
e
);
// nft发行时发生异常,则需要把nft的状态改成发行失败
if
(
msg
.
getPayScene
().
equals
(
PayScene
.
NFT
.
getCode
()))
{
Nft
nft
=
new
Nft
();
...
...
@@ -52,6 +51,8 @@ public class OrderListener {
nft
.
setPublishStatus
(
PublishStatus
.
FAILED
.
getCode
());
nftService
.
updateById
(
nft
);
}
// 处理失败,需要主动发起退款
wxPayService
.
refund
(
msg
.
getOrderId
(),
RefundLaunchChannel
.
USER
.
getCode
());
}
}
...
...
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