|
@@ -1,6 +1,7 @@
|
|
|
package com.szwl.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alipay.api.AlipayApiException;
|
|
@@ -13,20 +14,24 @@ import com.alipay.api.response.AlipayTradePrecreateResponse;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.google.gson.Gson;
|
|
|
-import com.szwl.constant.ConfigConsts;
|
|
|
-import com.szwl.constant.HuifuConstant;
|
|
|
-import com.szwl.constant.JoinpayConstant;
|
|
|
+import com.szwl.constant.*;
|
|
|
import com.szwl.feign.bean.OrderFeign;
|
|
|
import com.szwl.feign.bean.SzwlFeign;
|
|
|
import com.szwl.model.bean.WeChatTemplateMsg;
|
|
|
+import com.szwl.model.bo.JsonMessage;
|
|
|
import com.szwl.model.bo.R;
|
|
|
+import com.szwl.model.bo.ResponseModel;
|
|
|
import com.szwl.model.entity.*;
|
|
|
import com.szwl.mapper.TOrderMapper;
|
|
|
import com.szwl.model.utils.HttpClientUtils;
|
|
|
import com.szwl.model.utils.PushUtils;
|
|
|
+import com.szwl.model.utils.RSAUtil;
|
|
|
import com.szwl.service.*;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.szwl.service.es.EsTOrderService;
|
|
|
+import com.szwl.utils.HuifuUtils;
|
|
|
+import com.szwl.utils.IDGenerator;
|
|
|
+import com.szwl.utils.shouqianba.HttpProxy;
|
|
|
import com.szwl.weixin.util.HttpUtils;
|
|
|
import com.wechat.pay.java.core.Config;
|
|
|
import com.wechat.pay.java.service.payments.nativepay.model.Amount;
|
|
@@ -58,6 +63,7 @@ import java.net.URLConnection;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import static com.szwl.service.impl.TJoinpayMchServiceImpl.createHmacSign;
|
|
@@ -347,83 +353,98 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
|
|
|
@Override
|
|
|
public String huifuNotifyRefund(HttpServletRequest request) {
|
|
|
String respData = request.getParameter("resp_data");
|
|
|
- JSONObject data = JSONObject.parseObject(respData);
|
|
|
- String transStat = data.getString("trans_stat");
|
|
|
- // 订单号
|
|
|
- String sn = data.getString("org_req_seq_id");
|
|
|
- if(StrUtil.hasEmpty(sn)) {
|
|
|
- return "订单号为空!";
|
|
|
- }
|
|
|
- LambdaQueryWrapper<TOrder> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(TOrder::getSn,sn);
|
|
|
- TOrder order = orderService.getOne(wrapper);
|
|
|
- if(order == null) {
|
|
|
- return "订单不存在";
|
|
|
- }
|
|
|
- if(HuifuConstant.TRANS_STAT_S.equals(transStat)) {
|
|
|
- if(order.getRefundQuantity() < order.getProductNumber()) {
|
|
|
- order.setStatus(1);
|
|
|
- } else {
|
|
|
- order.setStatus(3);
|
|
|
+ try {
|
|
|
+
|
|
|
+ // 验签请参sign
|
|
|
+ String sign = request.getParameter("sign");
|
|
|
+ if (!RSAUtil.verify(respData, HuifuConstant.HUIFU_PUBLIC_KEY, sign)) {
|
|
|
+ // 验签失败处理
|
|
|
+ log.info("验签失败");
|
|
|
+ return "";
|
|
|
}
|
|
|
- String refundOrderNo = data.getString("req_seq_id");
|
|
|
- String ordAmt = data.getString("ord_amt");
|
|
|
- String refundTrxNo = data.getString("hf_seq_id");
|
|
|
- order.setRefundOrderNo(refundOrderNo);
|
|
|
- order.setRefundDate(new Date());
|
|
|
- order.setRefundTrxNo(refundTrxNo);
|
|
|
- // 更改订单明细表
|
|
|
- LambdaQueryWrapper<TOrderDetails> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(TOrderDetails::getOrderSn, sn);
|
|
|
- // 处理退款中状态的明细
|
|
|
- queryWrapper.eq(TOrderDetails::getRefundStatus, "4");
|
|
|
- List<TOrderDetails> tOrderDetails = orderDetailsService.list(queryWrapper);
|
|
|
- for (TOrderDetails tOrderDetail : tOrderDetails) {
|
|
|
- Integer refundQuantity = tOrderDetail.getRefundQuantity();
|
|
|
- Integer productNumber = tOrderDetail.getProductNumber();
|
|
|
- if(refundQuantity < productNumber) {
|
|
|
- // 部分退款
|
|
|
- tOrderDetail.setRefundStatus("2");
|
|
|
- orderDetailsService.updateById(tOrderDetail);
|
|
|
- } else {
|
|
|
- // 全部退款
|
|
|
- tOrderDetail.setRefundStatus("3");
|
|
|
- orderDetailsService.updateById(tOrderDetail);
|
|
|
- }
|
|
|
+
|
|
|
+ JSONObject data = JSONObject.parseObject(respData);
|
|
|
+ String transStat = data.getString("trans_stat");
|
|
|
+ // 订单号
|
|
|
+ String sn = data.getString("org_req_seq_id");
|
|
|
+ if(StrUtil.hasEmpty(sn)) {
|
|
|
+ log.info("返回参数订单编号为空");
|
|
|
+ return "订单号为空!";
|
|
|
}
|
|
|
- String acctSplitBunch = "";
|
|
|
- // 部分退款或全部退款
|
|
|
- TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(order.getEquipmentId())));
|
|
|
- if(order.getRefundAmount() != null) {
|
|
|
- // 退款总额
|
|
|
- BigDecimal newRefundAmount = order.getRefundAmount().add(new BigDecimal(ordAmt).setScale(2, RoundingMode.HALF_UP));
|
|
|
- order.setRefundAmount(newRefundAmount);
|
|
|
- // 如果小于订单金额
|
|
|
- if(newRefundAmount.compareTo(order.getPrice()) < 0) {
|
|
|
- acctSplitBunch = getAcctSplitBunch(proportion,order.getPrice().subtract(newRefundAmount), order.getCompanyType()).toString();
|
|
|
- order.setAcctSplitBunch(acctSplitBunch);
|
|
|
+ LambdaQueryWrapper<TOrder> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(TOrder::getSn,sn);
|
|
|
+ TOrder order = orderService.getOne(wrapper);
|
|
|
+ if(order == null) {
|
|
|
+ log.info("找不到订单");
|
|
|
+ return "订单不存在";
|
|
|
+ }
|
|
|
+ if(HuifuConstant.TRANS_STAT_S.equals(transStat)) {
|
|
|
+ if(order.getRefundQuantity() < order.getProductNumber()) {
|
|
|
+ order.setStatus(1);
|
|
|
} else {
|
|
|
- acctSplitBunch = getAcctSplitBunch(proportion,order.getPrice(), order.getCompanyType()).toString();
|
|
|
- order.setAcctSplitBunch(acctSplitBunch);
|
|
|
+ order.setStatus(3);
|
|
|
}
|
|
|
- } else {
|
|
|
- order.setRefundAmount(new BigDecimal(ordAmt).setScale(2,RoundingMode.HALF_UP));
|
|
|
- if(new BigDecimal(ordAmt).setScale(2, RoundingMode.HALF_UP).compareTo(order.getPrice()) < 0) {
|
|
|
- // 重新设置分销
|
|
|
- acctSplitBunch = getAcctSplitBunch(proportion,order.getPrice()
|
|
|
- .subtract(new BigDecimal(ordAmt).setScale(2,RoundingMode.HALF_UP)), order.getCompanyType()).toString();
|
|
|
- order.setAcctSplitBunch(acctSplitBunch);
|
|
|
+ String refundOrderNo = data.getString("req_seq_id");
|
|
|
+ String ordAmt = data.getString("ord_amt");
|
|
|
+ String refundTrxNo = data.getString("hf_seq_id");
|
|
|
+ order.setRefundOrderNo(refundOrderNo);
|
|
|
+ order.setRefundDate(new Date());
|
|
|
+ order.setRefundTrxNo(refundTrxNo);
|
|
|
+ // 更改订单明细表
|
|
|
+ LambdaQueryWrapper<TOrderDetails> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(TOrderDetails::getOrderSn, sn);
|
|
|
+ // 处理退款中状态的明细
|
|
|
+ queryWrapper.eq(TOrderDetails::getRefundStatus, "4");
|
|
|
+ List<TOrderDetails> tOrderDetails = orderDetailsService.list(queryWrapper);
|
|
|
+ for (TOrderDetails tOrderDetail : tOrderDetails) {
|
|
|
+ Integer refundQuantity = tOrderDetail.getRefundQuantity();
|
|
|
+ Integer productNumber = tOrderDetail.getProductNumber();
|
|
|
+ if(refundQuantity < productNumber) {
|
|
|
+ // 部分退款
|
|
|
+ tOrderDetail.setRefundStatus("2");
|
|
|
+ orderDetailsService.updateById(tOrderDetail);
|
|
|
+ } else {
|
|
|
+ // 全部退款
|
|
|
+ tOrderDetail.setRefundStatus("3");
|
|
|
+ orderDetailsService.updateById(tOrderDetail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String acctSplitBunch = "";
|
|
|
+ // 部分退款或全部退款
|
|
|
+ TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(order.getEquipmentId())));
|
|
|
+ if(order.getRefundAmount() != null) {
|
|
|
+ // 退款总额
|
|
|
+ BigDecimal newRefundAmount = order.getRefundAmount().add(new BigDecimal(ordAmt).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ order.setRefundAmount(newRefundAmount);
|
|
|
+ // 如果小于订单金额
|
|
|
+ if(newRefundAmount.compareTo(order.getPrice()) < 0) {
|
|
|
+ acctSplitBunch = getAcctSplitBunch(proportion,order.getPrice().subtract(newRefundAmount), order.getCompanyType()).toString();
|
|
|
+ order.setAcctSplitBunch(acctSplitBunch);
|
|
|
+ } else {
|
|
|
+ acctSplitBunch = getAcctSplitBunch(proportion,order.getPrice(), order.getCompanyType()).toString();
|
|
|
+ order.setAcctSplitBunch(acctSplitBunch);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ order.setRefundAmount(new BigDecimal(ordAmt).setScale(2,RoundingMode.HALF_UP));
|
|
|
+ if(new BigDecimal(ordAmt).setScale(2, RoundingMode.HALF_UP).compareTo(order.getPrice()) < 0) {
|
|
|
+ // 重新设置分销
|
|
|
+ acctSplitBunch = getAcctSplitBunch(proportion,order.getPrice()
|
|
|
+ .subtract(new BigDecimal(ordAmt).setScale(2,RoundingMode.HALF_UP)), order.getCompanyType()).toString();
|
|
|
+ order.setAcctSplitBunch(acctSplitBunch);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- try {
|
|
|
- esTOrderService.updateDataById(order);
|
|
|
- }catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }finally {
|
|
|
- orderService.updateById(order);
|
|
|
+ try {
|
|
|
+ esTOrderService.updateDataById(order);
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ orderService.updateById(order);
|
|
|
+ }
|
|
|
+ return "RECV_ORD_ID_" + refundOrderNo;
|
|
|
}
|
|
|
- return "退款成功";
|
|
|
+ } catch (Exception e){
|
|
|
+ log.info("异步回调开始,参数,request={}", respData, e);
|
|
|
}
|
|
|
return "退款失败";
|
|
|
}
|
|
@@ -548,7 +569,8 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
|
|
|
sendMag.put("thing15", new WeChatTemplateMsg(equipment.getName()));
|
|
|
}
|
|
|
} else {
|
|
|
- sendMag.put("thing15", new WeChatTemplateMsg(equipment.getClientId().substring(-6)));
|
|
|
+ String clientId = equipment.getClientId();
|
|
|
+ sendMag.put("thing15", new WeChatTemplateMsg(clientId.substring(clientId.length() - 6)));
|
|
|
}
|
|
|
if(order.getProductName().length() > 20) {
|
|
|
sendMag.put("thing37", new WeChatTemplateMsg(order.getProductName().substring(0, 15) + "..."));
|
|
@@ -595,76 +617,6 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
|
|
|
return messageCode;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 获取accessToken
|
|
|
- * @param companyType
|
|
|
- * @return
|
|
|
- */
|
|
|
-// private String getAccessToken(String companyType) {
|
|
|
-// String accessToken = "";
|
|
|
-// String url = "";
|
|
|
-// if(StringUtils.isEmpty(companyType) || companyType.equals("0")) {
|
|
|
-// url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="
|
|
|
-// + HuifuConstant.SZ_WX_SUB_APP_ID + "&secret=" + HuifuConstant.SZ_WX_APP_SECRET;
|
|
|
-// } else {
|
|
|
-// url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="
|
|
|
-// + HuifuConstant.SC_WX_SUB_APP_ID + "&secret=" + HuifuConstant.SC_WX_APP_SECRET;
|
|
|
-// }
|
|
|
-// PrintWriter out = null;
|
|
|
-// BufferedReader in = null;
|
|
|
-// String line;
|
|
|
-// StringBuffer stringBuffer = new StringBuffer();
|
|
|
-// try {
|
|
|
-// URL realUrl = new URL(url);
|
|
|
-// // 打开和URL之间的连接
|
|
|
-// URLConnection conn = realUrl.openConnection();
|
|
|
-//
|
|
|
-// // 设置通用的请求属性 设置请求格式
|
|
|
-// //设置返回类型
|
|
|
-// conn.setRequestProperty("contentType", "text/plain");
|
|
|
-// //设置请求类型
|
|
|
-// conn.setRequestProperty("content-type", "application/x-www-form-urlencoded");
|
|
|
-// //设置超时时间
|
|
|
-// conn.setConnectTimeout(1000);
|
|
|
-// conn.setReadTimeout(1000);
|
|
|
-// conn.setDoOutput(true);
|
|
|
-// conn.connect();
|
|
|
-// // 获取URLConnection对象对应的输出流
|
|
|
-// out = new PrintWriter(conn.getOutputStream());
|
|
|
-// // flush输出流的缓冲
|
|
|
-// out.flush();
|
|
|
-// // 定义BufferedReader输入流来读取URL的响应 设置接收格式
|
|
|
-// in = new BufferedReader(
|
|
|
-// new InputStreamReader(conn.getInputStream(), "UTF-8"));
|
|
|
-// while ((line = in.readLine()) != null) {
|
|
|
-// stringBuffer.append(line);
|
|
|
-// }
|
|
|
-// JSONObject jsonObject = JSONObject.parseObject(stringBuffer.toString());
|
|
|
-// log.info("获取token:{}",jsonObject.toString());
|
|
|
-// accessToken = jsonObject.getString("access_token");
|
|
|
-// if(StringUtils.isEmpty(companyType) || companyType.equals("0")) {
|
|
|
-// redisTemplate.opsForValue().set(SZ_ACCESS_TOKEN_KEY, accessToken, EXPIRATION_TIME, TimeUnit.SECONDS);
|
|
|
-// } else {
|
|
|
-// redisTemplate.opsForValue().set(SZ_ACCESS_TOKEN_KEY, accessToken, EXPIRATION_TIME, TimeUnit.SECONDS);
|
|
|
-// }
|
|
|
-// } catch (Exception e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// } finally {
|
|
|
-// //使用finally块来关闭输出流、输入流
|
|
|
-// try {
|
|
|
-// if (out != null) {
|
|
|
-// out.close();
|
|
|
-// }
|
|
|
-// if (in != null) {
|
|
|
-// in.close();
|
|
|
-// }
|
|
|
-// } catch (IOException ex) {
|
|
|
-// ex.printStackTrace();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return accessToken;
|
|
|
-// }
|
|
|
-
|
|
|
public void processRefund(Map<String, Object> bodyMap) {
|
|
|
String decrypt = wechatPayConfigService.decryptFromResource(bodyMap);
|
|
|
Gson gson = new Gson();
|