|
@@ -14,6 +14,9 @@ import com.kmall.common.utils.wechat.WechatMicropayApiResult;
|
|
|
import com.kmall.common.utils.wechat.WechatRefundApiResult;
|
|
|
import com.kmall.common.utils.wechat.WechatReverseApiResult;
|
|
|
import com.kmall.common.utils.wechat.WechatUtil;
|
|
|
+import com.kmall.common.utils.wechat.wxglobal.WechatGlobalUtil;
|
|
|
+import com.kmall.common.utils.wechat.wxglobal.dto.WechatGlobalRefundApiResult;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -300,45 +303,92 @@ public class OrderController {
|
|
|
if (totalActualPrice == null) {
|
|
|
totalActualPrice = 0d;
|
|
|
}
|
|
|
-
|
|
|
- if (orderInfo.getOrderStatus() != 0) {
|
|
|
- // todo 退款
|
|
|
- // WechatRefundApiResult result = WechatUtil.wxRefund(orderInfo.getOrderSn().toString(),
|
|
|
- // orderInfo.getActualPrice().doubleValue(), refundMoney.doubleValue());
|
|
|
- WechatRefundApiResult result = WechatUtil.wxRefund(orderInfo.getMerchOrderSn().toString(), totalActualPrice,
|
|
|
- orderInfo.getActualPrice().doubleValue());
|
|
|
- if (result.getResult_code().equals("SUCCESS")) {
|
|
|
- orderService.refund(orderInfo, result);
|
|
|
- } else {
|
|
|
- OrderRefundEntity mallOrderRefund = orderRefundService.queryObjectByOrderId(orderInfo.getId());
|
|
|
- OrderRefundEntity orderRefund = new OrderRefundEntity();
|
|
|
- orderRefund.setRefundType(Integer.parseInt(Dict.RefundType.item_1.getItem()));
|
|
|
- orderRefund.setRefundMoney(BigDecimal.valueOf(orderInfo.getActualPrice().doubleValue()));
|
|
|
- orderRefund.setRefundStatus(Integer.parseInt(Dict.RefundStatus.item_4.getItem()));
|
|
|
- orderRefund.setModTime(new Date());
|
|
|
- orderRefund.setOutRefundNo(result.getOut_refund_no());
|
|
|
- if (mallOrderRefund != null) {
|
|
|
- orderRefund.setId(mallOrderRefund.getId());
|
|
|
- orderRefundService.update(orderRefund);//退款记录
|
|
|
+ String refundResult = "";
|
|
|
+ if (orderInfo.getOrderStatus() != Integer.parseInt(Dict.orderStatus.item_0.getItem())) {
|
|
|
+ if(orderInfo.getPayFlag().equalsIgnoreCase(Dict.payFlag.item_wxglobalpay.getItem())){
|
|
|
+ refundResult = wxGlobalRefund(orderInfo,totalActualPrice);
|
|
|
+ if(StringUtils.isNotBlank(refundResult)){
|
|
|
+ return R.error(refundResult);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ refundResult = wxRefund(orderInfo,totalActualPrice);
|
|
|
+ if(StringUtils.isNotBlank(refundResult)){
|
|
|
+ return R.error(refundResult);
|
|
|
}
|
|
|
-
|
|
|
- OrderExceptionRecordEntity mallOrderExceptionRecord = new OrderExceptionRecordEntity();
|
|
|
- mallOrderExceptionRecord.setUserId(Integer.parseInt(orderInfo.getUserId() + ""));
|
|
|
- mallOrderExceptionRecord.setOrderSn(orderInfo.getOrderSn());
|
|
|
- mallOrderExceptionRecord.setExceptionStatus(Dict.exceptionStatus.item_03.getItem());
|
|
|
- mallOrderExceptionRecord.setExceptionContent("退款失败" + result.getErr_code_des());
|
|
|
- mallOrderExceptionRecord.setCreateTime(new Date());
|
|
|
- orderExceptionRecordService.save(mallOrderExceptionRecord);
|
|
|
-
|
|
|
- return R.error(result.getErr_code_des());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
return R.ok("退款成功");
|
|
|
}
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 微信申请退款
|
|
|
+ * @param orderInfo
|
|
|
+ * @param totalActualPrice
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String wxRefund(OrderEntity orderInfo,Double totalActualPrice){
|
|
|
+ WechatRefundApiResult result = WechatUtil.wxRefund(orderInfo.getMerchOrderSn().toString(), totalActualPrice,
|
|
|
+ orderInfo.getActualPrice().doubleValue());
|
|
|
+ if (result.getResult_code().equals(WechatUtil.WXTradeState.SUCCESS.getCode())) {
|
|
|
+ orderService.refund(orderInfo, result);
|
|
|
+ } else {
|
|
|
+ OrderRefundEntity mallOrderRefund = orderRefundService.queryObjectByOrderId(orderInfo.getId());
|
|
|
+ OrderRefundEntity orderRefund = new OrderRefundEntity();
|
|
|
+ orderRefund.setRefundType(Integer.parseInt(Dict.RefundType.item_1.getItem()));
|
|
|
+ orderRefund.setRefundMoney(BigDecimal.valueOf(orderInfo.getActualPrice().doubleValue()));
|
|
|
+ orderRefund.setRefundStatus(Integer.parseInt(Dict.RefundStatus.item_4.getItem()));
|
|
|
+ orderRefund.setModTime(new Date());
|
|
|
+ orderRefund.setOutRefundNo(result.getOut_refund_no());
|
|
|
+ if (mallOrderRefund != null) {
|
|
|
+ orderRefund.setId(mallOrderRefund.getId());
|
|
|
+ orderRefundService.update(orderRefund);//退款记录
|
|
|
+ }
|
|
|
+ OrderExceptionRecordEntity mallOrderExceptionRecord = new OrderExceptionRecordEntity();
|
|
|
+ mallOrderExceptionRecord.setUserId(Integer.parseInt(orderInfo.getUserId() + ""));
|
|
|
+ mallOrderExceptionRecord.setOrderSn(orderInfo.getOrderSn());
|
|
|
+ mallOrderExceptionRecord.setExceptionStatus(Dict.exceptionStatus.item_03.getItem());
|
|
|
+ mallOrderExceptionRecord.setExceptionContent("退款失败" + result.getErr_code_des());
|
|
|
+ mallOrderExceptionRecord.setCreateTime(new Date());
|
|
|
+ orderExceptionRecordService.save(mallOrderExceptionRecord);
|
|
|
+ return result.getErr_code_des();
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
+ * 微信国际申请退款
|
|
|
+ * @param orderInfo
|
|
|
+ * @param totalActualPrice
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String wxGlobalRefund(OrderEntity orderInfo,Double totalActualPrice){
|
|
|
+ WechatGlobalRefundApiResult result = WechatGlobalUtil.wxRefund(orderInfo.getMerchOrderSn().toString(), totalActualPrice,
|
|
|
+ orderInfo.getActualPrice().doubleValue());
|
|
|
+ if (result.getResult_code().equals(WechatUtil.WXTradeState.SUCCESS.getCode())) {
|
|
|
+ orderService.globalRefund(orderInfo, result);
|
|
|
+ } else {
|
|
|
+ OrderRefundEntity mallOrderRefund = orderRefundService.queryObjectByOrderId(orderInfo.getId());
|
|
|
+ OrderRefundEntity orderRefund = new OrderRefundEntity();
|
|
|
+ orderRefund.setRefundType(Integer.parseInt(Dict.RefundType.item_1.getItem()));
|
|
|
+ orderRefund.setRefundMoney(BigDecimal.valueOf(orderInfo.getActualPrice().doubleValue()));
|
|
|
+ orderRefund.setRefundStatus(Integer.parseInt(Dict.RefundStatus.item_4.getItem()));
|
|
|
+ orderRefund.setOutRefundNo(result.getOut_refund_no());
|
|
|
+ orderRefund.setModTime(new Date());
|
|
|
+ if (mallOrderRefund != null) {
|
|
|
+ orderRefund.setId(mallOrderRefund.getId());
|
|
|
+ orderRefundService.update(orderRefund);//退款记录
|
|
|
+ }
|
|
|
+ OrderExceptionRecordEntity mallOrderExceptionRecord = new OrderExceptionRecordEntity();
|
|
|
+ mallOrderExceptionRecord.setUserId(Integer.parseInt(orderInfo.getUserId() + ""));
|
|
|
+ mallOrderExceptionRecord.setOrderSn(orderInfo.getOrderSn());
|
|
|
+ mallOrderExceptionRecord.setExceptionStatus(Dict.exceptionStatus.item_03.getItem());
|
|
|
+ mallOrderExceptionRecord.setExceptionContent("退款失败" + result.getErr_code_des());
|
|
|
+ mallOrderExceptionRecord.setCreateTime(new Date());
|
|
|
+ orderExceptionRecordService.save(mallOrderExceptionRecord);
|
|
|
+ return result.getErr_code_des();
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ /**
|
|
|
* 订单退款请求
|
|
|
*/
|
|
|
@RequiresPermissions(value = {"order:offilineRefund"})
|
|
@@ -353,17 +403,16 @@ public class OrderController {
|
|
|
return R.error("订单已退款");
|
|
|
}
|
|
|
|
|
|
- if (orderInfo.getOrderStatus() != 0) {
|
|
|
- //现金支付
|
|
|
+ if (orderInfo.getOrderStatus() != Integer.parseInt(Dict.orderStatus.item_0.getItem())) {
|
|
|
if (Dict.payFlag.item_cash.getItem().equals(orderInfo.getPayFlag())) {
|
|
|
+ //现金支付,直接修改订单状态
|
|
|
orderService.refund(orderInfo, null);
|
|
|
- //微信支付
|
|
|
} else if (Dict.payFlag.item_weixin.getItem().equals(orderInfo.getPayFlag())) {
|
|
|
- // todo 退款
|
|
|
+ //微信线下扫码支付
|
|
|
WechatRefundApiResult result = WechatUtil
|
|
|
.wxRefund(orderInfo.getOrderSnWx(), orderInfo.getActualPrice().doubleValue(),
|
|
|
orderInfo.getActualPrice().doubleValue());
|
|
|
- if (result.getResult_code().equals("SUCCESS")) {
|
|
|
+ if (result.getResult_code().equals(WechatUtil.WXTradeState.SUCCESS.getCode())) {
|
|
|
orderService.refund(orderInfo, result);
|
|
|
} else {
|
|
|
OrderRefundEntity mallOrderRefund = orderRefundService.queryObjectByOrderId(orderInfo.getId());
|
|
@@ -371,8 +420,8 @@ public class OrderController {
|
|
|
orderRefund.setRefundType(Integer.parseInt(Dict.RefundType.item_1.getItem()));
|
|
|
orderRefund.setRefundMoney(BigDecimal.valueOf(orderInfo.getActualPrice().doubleValue()));
|
|
|
orderRefund.setRefundStatus(Integer.parseInt(Dict.RefundStatus.item_4.getItem()));
|
|
|
- orderRefund.setModTime(new Date());
|
|
|
orderRefund.setOutRefundNo(result.getOut_refund_no());
|
|
|
+ orderRefund.setModTime(new Date());
|
|
|
if (mallOrderRefund != null) {
|
|
|
orderRefund.setId(mallOrderRefund.getId());
|
|
|
orderRefundService.update(orderRefund);//退款记录
|
|
@@ -434,7 +483,7 @@ public class OrderController {
|
|
|
@RequestMapping("/confirmPay")
|
|
|
@RequiresPermissions("order:confirmPay")
|
|
|
public R confirmPay(@RequestBody Long id) {
|
|
|
- orderService.confirmPay(id, Dict.payFlag.item_cash, null);
|
|
|
+ orderService.confirmPay(id, Dict.payFlag.item_cash.getItem(), null);
|
|
|
|
|
|
return R.ok();
|
|
|
}
|
|
@@ -512,13 +561,13 @@ public class OrderController {
|
|
|
WechatReverseApiResult wechatReverseApiResult =
|
|
|
WechatUtil.wxReverse(orderWXPayRecordTemp.getOutTradeNoWX());
|
|
|
//撤销订单成功
|
|
|
- if ("SUCCESS".equals(wechatReverseApiResult.getReturn_code()) &&
|
|
|
- "SUCCESS".equals(wechatReverseApiResult.getResult_code())) {
|
|
|
+ if (WechatUtil.WXTradeState.SUCCESS.getCode().equals(wechatReverseApiResult.getReturn_code()) &&
|
|
|
+ WechatUtil.WXTradeState.SUCCESS.getCode().equals(wechatReverseApiResult.getResult_code())) {
|
|
|
//调用订单查询接口
|
|
|
WechatRefundApiResult wechatRefundApiResult =
|
|
|
WechatUtil.wxOrderQuery(orderWXPayRecordTemp.getOutTradeNoWX());
|
|
|
- if ("SUCCESS".equals(wechatRefundApiResult.getReturn_code()) &&
|
|
|
- "SUCCESS".equals(wechatRefundApiResult.getResult_code())) {
|
|
|
+ if (WechatUtil.WXTradeState.SUCCESS.getCode().equals(wechatRefundApiResult.getReturn_code()) &&
|
|
|
+ WechatUtil.WXTradeState.SUCCESS.getCode().equals(wechatRefundApiResult.getResult_code())) {
|
|
|
// 修改订单支付记录
|
|
|
orderWXPayRecordService
|
|
|
.updateWXPayRecordTradeState(orderWXPayRecordTemp.getId(), wechatRefundApiResult);
|
|
@@ -526,7 +575,7 @@ public class OrderController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- orderService.confirmPay(id, Dict.payFlag.item_weixin, orderWXPayRecordCurrent.getOutTradeNoWX());
|
|
|
+ orderService.confirmPay(id, Dict.payFlag.item_weixin.getItem(), orderWXPayRecordCurrent.getOutTradeNoWX());
|
|
|
r = R.ok();
|
|
|
//用户支付中
|
|
|
} else if (WechatUtil.WXTradeState.USERPAYING.getCode().equals(wechatMicropayApiResult.getTrade_state())) {
|
|
@@ -536,13 +585,13 @@ public class OrderController {
|
|
|
WechatReverseApiResult wechatReverseApiResult =
|
|
|
WechatUtil.wxReverse(orderWXPayRecordCurrent.getOutTradeNoWX());
|
|
|
//撤销订单成功
|
|
|
- if ("SUCCESS".equals(wechatReverseApiResult.getReturn_code()) &&
|
|
|
- "SUCCESS".equals(wechatReverseApiResult.getResult_code())) {
|
|
|
+ if (WechatUtil.WXTradeState.SUCCESS.getCode().equals(wechatReverseApiResult.getReturn_code()) &&
|
|
|
+ WechatUtil.WXTradeState.SUCCESS.getCode().equals(wechatReverseApiResult.getResult_code())) {
|
|
|
//调用订单查询接口
|
|
|
WechatRefundApiResult wechatRefundApiResult =
|
|
|
WechatUtil.wxOrderQuery(orderWXPayRecordCurrent.getOutTradeNoWX());
|
|
|
- if ("SUCCESS".equals(wechatRefundApiResult.getReturn_code()) &&
|
|
|
- "SUCCESS".equals(wechatRefundApiResult.getResult_code())) {
|
|
|
+ if (WechatUtil.WXTradeState.SUCCESS.getCode().equals(wechatRefundApiResult.getReturn_code()) &&
|
|
|
+ WechatUtil.WXTradeState.SUCCESS.getCode().equals(wechatRefundApiResult.getResult_code())) {
|
|
|
// 修改订单支付记录
|
|
|
orderWXPayRecordService
|
|
|
.updateWXPayRecordTradeState(orderWXPayRecordCurrent.getId(), wechatRefundApiResult);
|