|
@@ -2,11 +2,7 @@ package com.yonge.cooleshow.biz.dal.service.impl;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.yonge.cooleshow.biz.dal.config.HuifuConfiguration;
|
|
|
|
|
-import com.yonge.cooleshow.biz.dal.dto.req.OrderRefundReq;
|
|
|
|
|
import com.yonge.cooleshow.biz.dal.enums.*;
|
|
import com.yonge.cooleshow.biz.dal.enums.*;
|
|
|
import com.yonge.cooleshow.biz.dal.support.DistributedLock;
|
|
import com.yonge.cooleshow.biz.dal.support.DistributedLock;
|
|
|
import com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo;
|
|
import com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo;
|
|
@@ -15,9 +11,6 @@ import com.yonge.cooleshow.biz.dal.dto.req.OrderPayReq;
|
|
|
import com.yonge.cooleshow.biz.dal.dto.req.OrderReq;
|
|
import com.yonge.cooleshow.biz.dal.dto.req.OrderReq;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.UserOrder;
|
|
import com.yonge.cooleshow.biz.dal.entity.UserOrder;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.UserOrderPayment;
|
|
import com.yonge.cooleshow.biz.dal.entity.UserOrderPayment;
|
|
|
-import com.yonge.cooleshow.biz.dal.sdk.PaymentSdk;
|
|
|
|
|
-import com.yonge.cooleshow.biz.dal.sdk.req.DeviceInfo;
|
|
|
|
|
-import com.yonge.cooleshow.biz.dal.sdk.req.PaymentReq;
|
|
|
|
|
import com.yonge.cooleshow.biz.dal.service.*;
|
|
import com.yonge.cooleshow.biz.dal.service.*;
|
|
|
import com.yonge.cooleshow.biz.dal.vo.res.OrderCreateRes;
|
|
import com.yonge.cooleshow.biz.dal.vo.res.OrderCreateRes;
|
|
|
import com.yonge.cooleshow.biz.dal.vo.UserOrderVo;
|
|
import com.yonge.cooleshow.biz.dal.vo.UserOrderVo;
|
|
@@ -25,25 +18,26 @@ import com.yonge.cooleshow.biz.dal.vo.res.OrderPayRes;
|
|
|
import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
import com.yonge.cooleshow.common.service.IdGeneratorService;
|
|
import com.yonge.cooleshow.common.service.IdGeneratorService;
|
|
|
|
|
+import com.yonge.toolset.base.result.BaseResult;
|
|
|
|
|
+import com.yonge.toolset.payment.base.model.Payment;
|
|
|
|
|
+import com.yonge.toolset.payment.core.props.PaymentProperties;
|
|
|
|
|
+import com.yonge.toolset.payment.core.service.PaymentClient;
|
|
|
import com.yonge.toolset.utils.string.StringUtil;
|
|
import com.yonge.toolset.utils.string.StringUtil;
|
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
|
import org.redisson.api.RedissonClient;
|
|
import org.redisson.api.RedissonClient;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.core.annotation.Order;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.yonge.cooleshow.biz.dal.dto.search.OrderSearch;
|
|
import com.yonge.cooleshow.biz.dal.dto.search.OrderSearch;
|
|
|
import com.yonge.cooleshow.biz.dal.dao.UserOrderDao;
|
|
import com.yonge.cooleshow.biz.dal.dao.UserOrderDao;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.annotation.PostConstruct;
|
|
|
-import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.Future;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.function.Consumer;
|
|
import java.util.function.Consumer;
|
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
@@ -61,9 +55,7 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private UserOrderPaymentService orderPaymentService;
|
|
private UserOrderPaymentService orderPaymentService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private UserOrderRefundsService orderRefundsService;
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private PaymentSdk paymentSdk;
|
|
|
|
|
|
|
+ private PaymentClient paymentClient;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IdGeneratorService idGeneratorService;
|
|
private IdGeneratorService idGeneratorService;
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -76,6 +68,8 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
private MusicSheetService musicSheetService;
|
|
private MusicSheetService musicSheetService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RedissonClient redissonClient;
|
|
private RedissonClient redissonClient;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private PaymentProperties paymentProperties;
|
|
|
|
|
|
|
|
//验证订单是否可以下单,获取订单金额信息
|
|
//验证订单是否可以下单,获取订单金额信息
|
|
|
private static final Map<GoodTypeEnum, Function<OrderReq.OrderReqInfo, HttpResponseResult<OrderCreateRes>>> orderCreate = new HashMap<>();
|
|
private static final Map<GoodTypeEnum, Function<OrderReq.OrderReqInfo, HttpResponseResult<OrderCreateRes>>> orderCreate = new HashMap<>();
|
|
@@ -186,58 +180,22 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!StringUtil.isEmpty(detail.getTransNo())) {
|
|
if (!StringUtil.isEmpty(detail.getTransNo())) {
|
|
|
- try {
|
|
|
|
|
- Map<String, Object> resMap = paymentSdk.queryPayment(detail.getTransNo());
|
|
|
|
|
- //支付成功
|
|
|
|
|
- if (TradeStatusEnum.succeeded.getCode().equals(resMap.get("status").toString())) {
|
|
|
|
|
- orderSuccess(detail);
|
|
|
|
|
- return HttpResponseResult.failed("订单已经交易完成");
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- log.error("轮询处理支付中订单异常,异常参数: {}", JSONObject.toJSONString(payReq));
|
|
|
|
|
- return HttpResponseResult.failed("取消订单失败");
|
|
|
|
|
|
|
+ Payment param = new Payment(detail.getOpenType(), detail.getPayChannel());
|
|
|
|
|
+ param.setId(detail.getTransNo());
|
|
|
|
|
+ BaseResult<Payment> res = paymentClient.queryPayment(param);
|
|
|
|
|
+ //支付成功
|
|
|
|
|
+ if (res.getStatus() && TradeStatusEnum.succeeded.getCode().equals(res.getData().getStatus())) {
|
|
|
|
|
+ orderSuccess(detail);
|
|
|
|
|
+ return HttpResponseResult.failed("订单已经交易完成");
|
|
|
}
|
|
}
|
|
|
|
|
+ //关闭订单付款单
|
|
|
|
|
+ orderPaymentService.closePayment(payReq.getOrderNo(), StringUtil.isEmpty(payReq.getReason()) ? "用户取消订单" : payReq.getReason());
|
|
|
}
|
|
}
|
|
|
//关闭订单
|
|
//关闭订单
|
|
|
doOrderCancel(detail, OrderStatusEnum.CLOSE, StringUtil.isEmpty(payReq.getReason()) ? "用户取消订单" : payReq.getReason());
|
|
doOrderCancel(detail, OrderStatusEnum.CLOSE, StringUtil.isEmpty(payReq.getReason()) ? "用户取消订单" : payReq.getReason());
|
|
|
- //关闭订单付款单
|
|
|
|
|
- orderPaymentService.closePayment(payReq.getOrderNo(), StringUtil.isEmpty(payReq.getReason()) ? "用户取消订单" : payReq.getReason());
|
|
|
|
|
return HttpResponseResult.succeed(true);
|
|
return HttpResponseResult.succeed(true);
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
- public HttpResponseResult<Boolean> orderRefund(OrderRefundReq refundReq) {
|
|
|
|
|
- UserOrderVo detail = detail(refundReq.getOrderNo(), refundReq.getUserId());
|
|
|
|
|
- if (null == detail || CollectionUtils.isEmpty(detail.getOrderDetailList())) {
|
|
|
|
|
- return HttpResponseResult.failed("未找到订单信息");
|
|
|
|
|
- }
|
|
|
|
|
- if (!OrderStatusEnum.PAID.equals(detail.getStatus())) {
|
|
|
|
|
- return HttpResponseResult.failed("订单状态异常");
|
|
|
|
|
- }
|
|
|
|
|
- UserOrderDetailVo orderDetail = null;
|
|
|
|
|
- for (UserOrderDetailVo vo : detail.getOrderDetailList()) {
|
|
|
|
|
- if(vo.getId().equals(refundReq.getOrderDetilId())){
|
|
|
|
|
- orderDetail = vo;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (null == orderDetail) {
|
|
|
|
|
- return HttpResponseResult.failed("未找到订单信息");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (StringUtil.isEmpty(detail.getTransNo())) {
|
|
|
|
|
- return HttpResponseResult.failed("未找到订单付款信息");
|
|
|
|
|
- }
|
|
|
|
|
- UserOrderPayment orderPayment = orderPaymentService.detailByTransNo(detail.getTransNo());
|
|
|
|
|
- if (null == orderPayment || !TradeStatusEnum.succeeded.equals(orderPayment.getStatus())) {
|
|
|
|
|
- return HttpResponseResult.failed("订单付款状态异常");
|
|
|
|
|
- }
|
|
|
|
|
- //发起退款申请
|
|
|
|
|
- return orderRefundsService.orderRefund(refundReq);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void setSuccessStatus() {
|
|
public void setSuccessStatus() {
|
|
@@ -290,6 +248,7 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public HttpResponseResult<UserOrder> executeOrder(OrderReq orderReq) throws Exception {
|
|
public HttpResponseResult<UserOrder> executeOrder(OrderReq orderReq) throws Exception {
|
|
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
log.info("订单[创建订单] Req:{}", JSONObject.toJSONString(orderReq));
|
|
log.info("订单[创建订单] Req:{}", JSONObject.toJSONString(orderReq));
|
|
|
//订单号生成
|
|
//订单号生成
|
|
|
Long orderNo = idGeneratorService.generatorId("userOrder");
|
|
Long orderNo = idGeneratorService.generatorId("userOrder");
|
|
@@ -300,6 +259,8 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
if (Objects.isNull(createFunction)) {
|
|
if (Objects.isNull(createFunction)) {
|
|
|
return HttpResponseResult.failed("订单商品信息获取失败");
|
|
return HttpResponseResult.failed("订单商品信息获取失败");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
info.setOrderNo(Long.toString(orderNo));
|
|
info.setOrderNo(Long.toString(orderNo));
|
|
|
info.setUserId(orderReq.getUserId());
|
|
info.setUserId(orderReq.getUserId());
|
|
|
HttpResponseResult<OrderCreateRes> createResult = createFunction.apply(info);
|
|
HttpResponseResult<OrderCreateRes> createResult = createFunction.apply(info);
|
|
@@ -329,6 +290,7 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
afterFunction.accept(orderDetailVo);
|
|
afterFunction.accept(orderDetailVo);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ log.info("下单请求 start is {} end is {}", start, System.currentTimeMillis());
|
|
|
return HttpResponseResult.succeed(orderVo);
|
|
return HttpResponseResult.succeed(orderVo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -345,7 +307,7 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
&& !OrderStatusEnum.PAYING.equals(detail.getStatus())) {
|
|
&& !OrderStatusEnum.PAYING.equals(detail.getStatus())) {
|
|
|
return HttpResponseResult.failed("订单状态异常");
|
|
return HttpResponseResult.failed("订单状态异常");
|
|
|
}
|
|
}
|
|
|
- return doOrderPayWaitPay(payReq, detail);
|
|
|
|
|
|
|
+ return doOrderPay(payReq, detail);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -359,7 +321,7 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void orderCallback(String data, String type) {
|
|
|
|
|
|
|
+ public void adapayCallback(String data, String type) {
|
|
|
JSONObject hfRes = JSONObject.parseObject(data);
|
|
JSONObject hfRes = JSONObject.parseObject(data);
|
|
|
if (type.equals("payment.succeeded")) {//支付成功
|
|
if (type.equals("payment.succeeded")) {//支付成功
|
|
|
paymentSucceededHandle(hfRes);
|
|
paymentSucceededHandle(hfRes);
|
|
@@ -380,7 +342,7 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
* @updateTime 2022/4/27 15:09
|
|
* @updateTime 2022/4/27 15:09
|
|
|
*/
|
|
*/
|
|
|
private void paymentSucceededHandle(JSONObject hfRes) {
|
|
private void paymentSucceededHandle(JSONObject hfRes) {
|
|
|
- UserOrderPayment orderPayment = orderPaymentService.detailByAdapayNo(hfRes.getString("order_no"));
|
|
|
|
|
|
|
+ UserOrderPayment orderPayment = orderPaymentService.detailByPaymentNo(hfRes.getString("order_no"));
|
|
|
if (null == orderPayment) {
|
|
if (null == orderPayment) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -456,25 +418,24 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
if (!StringUtil.isEmpty(detail.getTransNo())) {
|
|
if (!StringUtil.isEmpty(detail.getTransNo())) {
|
|
|
- try {
|
|
|
|
|
- Map<String, Object> resMap = paymentSdk.queryPayment(detail.getTransNo());
|
|
|
|
|
- //支付成功
|
|
|
|
|
- if (TradeStatusEnum.succeeded.getCode().equals(resMap.get("status").toString())
|
|
|
|
|
- && (OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
|
|
|
|
|
- || OrderStatusEnum.PAYING.equals(detail.getStatus()))) {
|
|
|
|
|
- orderSuccess(detail);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
|
+ Payment param = new Payment(detail.getOpenType(), detail.getPayChannel());
|
|
|
|
|
+ param.setId(detail.getTransNo());
|
|
|
|
|
+ BaseResult<Payment> res = paymentClient.queryPayment(param);
|
|
|
|
|
+ //支付成功
|
|
|
|
|
+ if (res.getStatus() && TradeStatusEnum.succeeded.getCode().equals(res.getData().getStatus())
|
|
|
|
|
+ && (OrderStatusEnum.WAIT_PAY.equals(detail.getStatus()) || OrderStatusEnum.PAYING.equals(detail.getStatus()))
|
|
|
|
|
+ ) {
|
|
|
|
|
+ orderSuccess(detail);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
//关闭订单
|
|
//关闭订单
|
|
|
doOrderCancel(detail, OrderStatusEnum.CLOSE, "订单超时");
|
|
doOrderCancel(detail, OrderStatusEnum.CLOSE, "订单超时");
|
|
|
|
|
+ //关闭订单付款单
|
|
|
|
|
+ orderPaymentService.closePayment(orderNo, "订单超时");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private HttpResponseResult<OrderPayRes> doOrderPayWaitPay(OrderPayReq payReq, UserOrderVo detail) {
|
|
|
|
|
|
|
+ private HttpResponseResult<OrderPayRes> doOrderPay(OrderPayReq payReq, UserOrderVo detail) throws Exception {
|
|
|
UserOrderPayment orderPayment = orderPaymentService.detailByOrderNo(payReq.getOrderNo(), payReq.getPayChannel(), TradeStatusEnum.pending);
|
|
UserOrderPayment orderPayment = orderPaymentService.detailByOrderNo(payReq.getOrderNo(), payReq.getPayChannel(), TradeStatusEnum.pending);
|
|
|
//当前渠道已经有创建支付请求
|
|
//当前渠道已经有创建支付请求
|
|
|
if (null != orderPayment && !StringUtil.isEmpty(orderPayment.getPayInfo())) {
|
|
if (null != orderPayment && !StringUtil.isEmpty(orderPayment.getPayInfo())) {
|
|
@@ -604,7 +565,6 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
* @updateTime 2022/3/31 16:49
|
|
* @updateTime 2022/3/31 16:49
|
|
|
* @return: java.math.BigDecimal
|
|
* @return: java.math.BigDecimal
|
|
|
*/
|
|
*/
|
|
|
-
|
|
|
|
|
private String getGoodUrlByType(GoodTypeEnum goodTypeEnum) {
|
|
private String getGoodUrlByType(GoodTypeEnum goodTypeEnum) {
|
|
|
String configValue = "";
|
|
String configValue = "";
|
|
|
if (GoodTypeEnum.VIP.equals(goodTypeEnum)) {
|
|
if (GoodTypeEnum.VIP.equals(goodTypeEnum)) {
|