|
@@ -1,9 +1,12 @@
|
|
package com.qs.mp.pay.service.impl;
|
|
package com.qs.mp.pay.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.qs.mp.channel.service.IChannelOrderService;
|
|
import com.qs.mp.channel.service.IChannelOrderService;
|
|
import com.qs.mp.common.enums.BizTypeEnum;
|
|
import com.qs.mp.common.enums.BizTypeEnum;
|
|
import com.qs.mp.common.enums.MqTopicType;
|
|
import com.qs.mp.common.enums.MqTopicType;
|
|
|
|
+import com.qs.mp.common.enums.PayOrderStatusEnum;
|
|
import com.qs.mp.common.exception.ServiceException;
|
|
import com.qs.mp.common.exception.ServiceException;
|
|
import com.qs.mp.common.pulsar.PulsarClientService;
|
|
import com.qs.mp.common.pulsar.PulsarClientService;
|
|
import com.qs.mp.common.utils.DateUtils;
|
|
import com.qs.mp.common.utils.DateUtils;
|
|
@@ -23,6 +26,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @auther duota
|
|
* @auther duota
|
|
* @create 2021 2021/9/4 1:59 下午
|
|
* @create 2021 2021/9/4 1:59 下午
|
|
@@ -122,52 +127,51 @@ public class WalletServiceImpl implements IWalletService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public boolean refundByUser(String orderNo, Integer refundAmount, String remark) {
|
|
|
|
|
|
+ public boolean refund(String bizId, Integer refundAmount, String remark) {
|
|
|
|
+ // 获取支付成功的订单号
|
|
|
|
+ PayOrder payOrder = payOrderService.getOne(new LambdaQueryWrapper<PayOrder>()
|
|
|
|
+ .eq(PayOrder::getBizId, bizId)
|
|
|
|
+ .eq(PayOrder::getOrderStatus, PayOrderStatusEnum.SUCCESS));
|
|
|
|
+ if (Objects.isNull(payOrder)) {
|
|
|
|
+ throw new ServiceException("支付订单不存在");
|
|
|
|
+ }
|
|
|
|
|
|
String reqUrl = baseUrl + "/pay/refundOrder";
|
|
String reqUrl = baseUrl + "/pay/refundOrder";
|
|
-
|
|
|
|
JSONObject sendData = new JSONObject();
|
|
JSONObject sendData = new JSONObject();
|
|
- sendData.put("shop_no", userPayShopNo);
|
|
|
|
|
|
+
|
|
|
|
+ if (BizTypeEnum.CHANNEL_ORDER.equals(payOrder.getBizType())) {
|
|
|
|
+ sendData.put("shop_no", channelPayShopNo);
|
|
|
|
+ sendData.put("sign",channelPaySign);
|
|
|
|
+ } else {
|
|
|
|
+ sendData.put("shop_no", userPayShopNo);
|
|
|
|
+ sendData.put("sign",userPaySign);
|
|
|
|
+ }
|
|
sendData.put("timestamp",System.currentTimeMillis());
|
|
sendData.put("timestamp",System.currentTimeMillis());
|
|
- sendData.put("order_no",orderNo);
|
|
|
|
|
|
+ sendData.put("order_no",payOrder.getOrderId());
|
|
sendData.put("refund_amount", refundAmount);
|
|
sendData.put("refund_amount", refundAmount);
|
|
sendData.put("order_remark", remark);
|
|
sendData.put("order_remark", remark);
|
|
sendData.put("type","sno");
|
|
sendData.put("type","sno");
|
|
- sendData.put("sign",userPaySign);
|
|
|
|
String result = OkHttpUtil.postJsonParams(reqUrl, sendData.toJSONString());
|
|
String result = OkHttpUtil.postJsonParams(reqUrl, sendData.toJSONString());
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
String code = jsonObject.getString("code");
|
|
String code = jsonObject.getString("code");
|
|
logger.info("用户订单退款 -> request params:" + sendData.toJSONString() + " result:" + result);
|
|
logger.info("用户订单退款 -> request params:" + sendData.toJSONString() + " result:" + result);
|
|
|
|
+ // 退款成功,更新订单状态
|
|
if ("R0001".equals(code)) {
|
|
if ("R0001".equals(code)) {
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- throw new ServiceException(jsonObject.getString("result"));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ boolean ret = payOrderService.update(new LambdaUpdateWrapper<PayOrder>()
|
|
|
|
+ .set(PayOrder::getOrderStatus, PayOrderStatusEnum.REFUND.getValue())
|
|
|
|
+ .eq(PayOrder::getOrderId, payOrder.getOrderId())
|
|
|
|
+ .eq(PayOrder::getOrderStatus, PayOrderStatusEnum.SUCCESS.getValue()));
|
|
|
|
|
|
- @Override
|
|
|
|
- public boolean refundByChannel(String orderNo, Integer refundAmount, String remark) {
|
|
|
|
-
|
|
|
|
- String reqUrl = baseUrl + "/pay/refundOrder";
|
|
|
|
-
|
|
|
|
- JSONObject sendData = new JSONObject();
|
|
|
|
- sendData.put("shop_no", channelPayShopNo);
|
|
|
|
- sendData.put("timestamp",System.currentTimeMillis());
|
|
|
|
- sendData.put("order_no",orderNo);
|
|
|
|
- sendData.put("refund_amount", refundAmount);
|
|
|
|
- sendData.put("order_remark", remark);
|
|
|
|
- sendData.put("type","sno");
|
|
|
|
- sendData.put("sign",channelPaySign);
|
|
|
|
- String result = OkHttpUtil.postJsonParams(reqUrl, sendData.toJSONString());
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
|
- String code = jsonObject.getString("code");
|
|
|
|
- logger.info("经销商订单退款 -> request params:" + sendData.toJSONString() + " result:" + result);
|
|
|
|
- if ("R0001".equals(code)) {
|
|
|
|
|
|
+ if (!ret) {
|
|
|
|
+ LogUtil.error(logger, "订单退款状态数据库更新失败, BizId:" + bizId);
|
|
|
|
+ }
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
- throw new ServiceException(jsonObject.getString("result"));
|
|
|
|
|
|
+ LogUtil.error(logger, "订单退款失败,code:" + code);
|
|
|
|
+ throw new ServiceException("订单退款失败");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void payOrderStatusHandle(PayOrder payOrder) {
|
|
public void payOrderStatusHandle(PayOrder payOrder) {
|
|
String orderNo = payOrder.getOrderId();
|
|
String orderNo = payOrder.getOrderId();
|