|
|
|
@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.hai.common.exception.ErrorCode; |
|
|
|
|
import com.hai.common.exception.ErrorHelp; |
|
|
|
|
import com.hai.common.exception.SysCode; |
|
|
|
|
import com.hai.common.pay.util.XmlUtil; |
|
|
|
|
import com.hai.common.pay.util.sdk.WXPayConstants; |
|
|
|
|
import com.hai.common.utils.DateUtil; |
|
|
|
|
import com.hai.common.utils.HttpsUtils; |
|
|
|
@ -13,21 +14,26 @@ import com.hai.common.utils.WxUtils; |
|
|
|
|
import com.hai.config.CommonSysConfig; |
|
|
|
|
import com.hai.config.CommonSysConst; |
|
|
|
|
import com.hai.config.HuiLianTongUnionCardConfig; |
|
|
|
|
import com.hai.config.UnionPayConfig; |
|
|
|
|
import com.hai.dao.HighGasOrderPushMapper; |
|
|
|
|
import com.hai.dao.OutRechargeOrderMapper; |
|
|
|
|
import com.hai.dao.OutRechargeOrderMapperExt; |
|
|
|
|
import com.hai.entity.*; |
|
|
|
|
import com.hai.enum_type.OrderPushType; |
|
|
|
|
import com.hai.model.OrderCountModel; |
|
|
|
|
import com.hai.model.OutOrderModel; |
|
|
|
|
import com.hai.model.OutRechargeOrderModel; |
|
|
|
|
import com.hai.model.OutUserOrderModel; |
|
|
|
|
import com.hai.model.*; |
|
|
|
|
import com.hai.service.HighUserCardService; |
|
|
|
|
import com.hai.service.HighUserService; |
|
|
|
|
import com.hai.service.OutRechargeOrderService; |
|
|
|
|
import com.hai.service.pay.impl.GoodsOrderServiceImpl; |
|
|
|
|
import io.swagger.models.auth.In; |
|
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.apache.http.HttpEntity; |
|
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse; |
|
|
|
|
import org.apache.http.client.methods.HttpPost; |
|
|
|
|
import org.apache.http.entity.StringEntity; |
|
|
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
|
|
import org.apache.http.util.EntityUtils; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
@ -59,6 +65,9 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { |
|
|
|
|
@Resource |
|
|
|
|
private OutRechargeOrderService outRechargeOrderService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private GoodsOrderServiceImpl goodsOrderService; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<OutRechargeOrder> getListRechargeOrder(Map<String, String> map) { |
|
|
|
|
OutRechargeOrderExample example = new OutRechargeOrderExample(); |
|
|
|
@ -94,6 +103,9 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { |
|
|
|
|
if (MapUtils.getString(map, "rechargeContent") != null) { |
|
|
|
|
criteria.andRechargeContentLike("%" + MapUtils.getString(map, "rechargeContent") + "%"); |
|
|
|
|
} |
|
|
|
|
if (MapUtils.getString(map, "rechargeType") != null) { |
|
|
|
|
criteria.andRechargeTypeEqualTo(MapUtils.getInteger(map, "rechargeType")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (MapUtils.getString(map, "phone") != null) { |
|
|
|
|
criteria.andUserPhoneEqualTo(MapUtils.getString(map, "phone")); |
|
|
|
@ -142,6 +154,19 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { |
|
|
|
|
outRechargeOrderMapper.updateByPrimaryKey(outRechargeOrder); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional(propagation= Propagation.REQUIRES_NEW) |
|
|
|
|
public void updateOrderList(List<OutRechargeOrder> rechargeOrders) throws Exception { |
|
|
|
|
for (OutRechargeOrder list:rechargeOrders) { |
|
|
|
|
if (list.getStatus() == 3) { |
|
|
|
|
outRechargeOrderMapper.updateByPrimaryKey(list); |
|
|
|
|
} else if (list.getStatus() == 6) { |
|
|
|
|
rechargeOrderToRefund(list.getId()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional(propagation= Propagation.REQUIRES_NEW) |
|
|
|
|
public void cancelOrder(Long orderId) { |
|
|
|
@ -383,4 +408,118 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { |
|
|
|
|
|
|
|
|
|
return HttpsUtils.doPost(CommonSysConst.getSysConfig().getCzUrl() , map); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void rechargeOrderToRefund(Long orderId) throws Exception { |
|
|
|
|
OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 订单状态 : 1.待支付 2.已支付 3.已完成 4.已取消 5.已退款 6:退款中
|
|
|
|
|
if (order.getStatus() != 2) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法退款,订单不处于已支付状态"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 微信退款
|
|
|
|
|
if (order.getPayType() == 1) { |
|
|
|
|
Map<String,String> param = new HashMap<>(); |
|
|
|
|
param.put("appid", "wx637bd6f7314daa46"); |
|
|
|
|
param.put("mch_id", "1289663601"); |
|
|
|
|
param.put("sub_mch_id" , "1614670195"); |
|
|
|
|
param.put("nonce_str", WxUtils.makeNonStr()); |
|
|
|
|
param.put("transaction_id", order.getPaySerialNo()); |
|
|
|
|
param.put("out_refund_no", "HFR"+new Date().getTime()); |
|
|
|
|
param.put("total_fee", String.valueOf(order.getPayRealPrice().multiply(new BigDecimal("100")).intValue())); |
|
|
|
|
param.put("refund_fee", String.valueOf(order.getPayRealPrice().multiply(new BigDecimal("100")).intValue())); |
|
|
|
|
param.put("sign_type", "HMAC-SHA256"); |
|
|
|
|
|
|
|
|
|
String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); |
|
|
|
|
param.put("sign", signStr); |
|
|
|
|
|
|
|
|
|
String resultXmL = doRefundRequest(param.get("mch_id"), WxUtils.mapToXml(param)); |
|
|
|
|
OrderRefundModel orderRefundModel = XmlUtil.getObjectFromXML(resultXmL, OrderRefundModel.class); |
|
|
|
|
if(orderRefundModel.getResult_code().equals("SUCCESS")) { |
|
|
|
|
order.setStatus(5); |
|
|
|
|
order.setRefundTime(new Date()); |
|
|
|
|
order.setOutRefundNo(orderRefundModel.getOut_refund_no()); |
|
|
|
|
order.setRefundId(orderRefundModel.getRefund_id()); |
|
|
|
|
order.setRefundFee(new BigDecimal(orderRefundModel.getRefund_fee()).divide(new BigDecimal("100"))); |
|
|
|
|
outRechargeOrderService.updateOrder(order); |
|
|
|
|
} else { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "退款失败!错误代码:"+orderRefundModel.getErr_code()+",错误描述"+orderRefundModel.getErr_code_des()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 工会卡退款
|
|
|
|
|
if (order.getPayType() == 2) { |
|
|
|
|
JSONObject jsonObject = HuiLianTongUnionCardConfig.refund( "HFR"+new Date().getTime() , order.getOrderNo()); |
|
|
|
|
|
|
|
|
|
if (jsonObject == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请求超时,请重新点击"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JSONObject dataObject = HuiLianTongUnionCardConfig.resolveResponse(jsonObject.getString("data")); |
|
|
|
|
|
|
|
|
|
if (dataObject.getBoolean("success") || Objects.equals(dataObject.getString("message"), "原交易已撤销,不可再次操作")) { |
|
|
|
|
order.setStatus(5); |
|
|
|
|
order.setRefundTime(new Date()); |
|
|
|
|
order.setOutRefundNo("HFR"+new Date().getTime() ); |
|
|
|
|
order.setRefundFee(order.getPayRealPrice()); |
|
|
|
|
order.setRefundId(dataObject.getString("orderId")); |
|
|
|
|
outRechargeOrderService.updateOrder(order); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, dataObject.getString("message")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 金币退款
|
|
|
|
|
if (order.getPayType() == 3) { |
|
|
|
|
highUserService.goldHandle(order.getUserId(), order.getPayRealPrice().intValue() * 100, 1, 3, order.getId()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 银联退款
|
|
|
|
|
if (order.getPayType() == 4) { |
|
|
|
|
// 订单退款
|
|
|
|
|
JSONObject refund = UnionPayConfig.zwrefund(order.getOrderNo(), order.getPaySerialNo(), order.getPayRealPrice().multiply(new BigDecimal("100")).longValue()); |
|
|
|
|
if (!refund.getString("resultcode").equals("W6")) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, refund.getString("returnmsg")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
order.setStatus(5); |
|
|
|
|
order.setRefundTime(new Date()); |
|
|
|
|
order.setOutRefundNo(refund.getString("oriwtorderid")); |
|
|
|
|
order.setRefundFee(order.getPayRealPrice()); |
|
|
|
|
outRechargeOrderService.updateOrder(order); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String doRefundRequest(String mchId,String data) throws Exception { |
|
|
|
|
|
|
|
|
|
//小程序退款需要调用双向证书的认证
|
|
|
|
|
CloseableHttpClient httpClient = goodsOrderService.readCertificate(mchId); |
|
|
|
|
try { |
|
|
|
|
HttpPost httpost = new HttpPost("https://api.mch.weixin.qq.com/secapi/pay/refund"); // 设置响应头信息
|
|
|
|
|
httpost.addHeader("Connection", "keep-alive"); |
|
|
|
|
httpost.addHeader("Accept", "*/*"); |
|
|
|
|
httpost.addHeader("Content-Type", "text/xml"); |
|
|
|
|
httpost.addHeader("Host", "api.mch.weixin.qq.com"); |
|
|
|
|
httpost.addHeader("X-Requested-With", "XMLHttpRequest"); |
|
|
|
|
httpost.addHeader("Cache-Control", "max-age=0"); |
|
|
|
|
httpost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) "); |
|
|
|
|
httpost.setEntity(new StringEntity(data, "UTF-8")); |
|
|
|
|
CloseableHttpResponse response = httpClient.execute(httpost); |
|
|
|
|
try { |
|
|
|
|
HttpEntity entity = response.getEntity(); |
|
|
|
|
String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8"); |
|
|
|
|
EntityUtils.consume(entity); |
|
|
|
|
return jsonStr; |
|
|
|
|
} finally { |
|
|
|
|
response.close(); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e){ |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} finally { |
|
|
|
|
httpClient.close(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|