|
@@ -2,6 +2,8 @@ package com.fdage.controller.app;
|
|
|
|
|
|
import com.fdage.base.dto.WechatRefundApiResult;
|
|
|
import com.fdage.base.entity.TmOrder;
|
|
|
+import com.fdage.base.enums.OrderPayStatusEnum;
|
|
|
+import com.fdage.base.enums.OrderStatusEnum;
|
|
|
import com.fdage.base.service.impl.TmOrderServiceImpl;
|
|
|
import com.fdage.base.utils.DataUtils;
|
|
|
import com.fdage.base.utils.MapUtils;
|
|
@@ -26,6 +28,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.TreeMap;
|
|
@@ -58,23 +61,17 @@ public class AppPayController extends BaseController {
|
|
|
if(null == orderId){
|
|
|
return Result.failure("缺失订单id");
|
|
|
}
|
|
|
-
|
|
|
- //
|
|
|
TmOrder orderInfo = tmOrderService.getById(orderId);
|
|
|
-
|
|
|
if (null == orderInfo) {
|
|
|
return Result.failure("订单不存在");
|
|
|
}
|
|
|
-
|
|
|
- if (orderInfo.getPayStatus() != 0 && orderInfo.getPayStatus() != 1) {
|
|
|
- return Result.failure("订单已支付,请不要重复操作");
|
|
|
+ if(OrderPayStatusEnum.PAY_SUCCESS.getStatus().compareTo(orderInfo.getPayStatus()) == 0){
|
|
|
+ return Result.failure("订单已经支付过了,无需重复支付");
|
|
|
}
|
|
|
-
|
|
|
String nonceStr = DataUtils.getRandomString(32);
|
|
|
|
|
|
//https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=7_7&index=3
|
|
|
Map<Object, Object> resultObj = new TreeMap();
|
|
|
-
|
|
|
try {
|
|
|
Map<Object, Object> parame = new TreeMap<Object, Object>();
|
|
|
parame.put("appid", ResourceUtil.getConfigByName("wx.appId"));
|
|
@@ -86,7 +83,7 @@ public class AppPayController extends BaseController {
|
|
|
// 商户订单编号
|
|
|
parame.put("out_trade_no", orderInfo.getOrderNo());
|
|
|
log.info("out_trade_no:" + orderInfo.getOrderNo());
|
|
|
- Map orderGoodsParam = new HashMap();
|
|
|
+ Map<String , Object> orderGoodsParam = new HashMap();
|
|
|
orderGoodsParam.put("order_id", orderId);
|
|
|
// 商品描述
|
|
|
parame.put("body", "电商-支付");
|
|
@@ -120,8 +117,10 @@ public class AppPayController extends BaseController {
|
|
|
if (result_code.equalsIgnoreCase("FAIL")) {
|
|
|
String err_code = MapUtils.getString("err_code", resultUn);
|
|
|
if(StringUtils.equals(err_code , "ORDERPAID")){
|
|
|
- //已经支付成功,则
|
|
|
- orderInfo.setPayStatus(2);
|
|
|
+ //之前已经支付成功,但是这次支付失败,则更新订单的支付状态
|
|
|
+ orderInfo.setPayStatus(OrderPayStatusEnum.PAY_SUCCESS.getStatus());
|
|
|
+ orderInfo.setUpdateTime(LocalDateTime.now());
|
|
|
+ orderInfo.setPayTime(LocalDateTime.now());
|
|
|
tmOrderService.updateById(orderInfo);
|
|
|
}
|
|
|
return Result.failure("支付失败," + err_code_des);
|
|
@@ -138,7 +137,8 @@ public class AppPayController extends BaseController {
|
|
|
// 业务处理
|
|
|
orderInfo.setPayId(prepay_id);
|
|
|
// 付款中
|
|
|
- orderInfo.setPayStatus(0);
|
|
|
+ orderInfo.setPayStatus(OrderPayStatusEnum.PAYING.getStatus());
|
|
|
+ orderInfo.setUpdateTime(LocalDateTime.now());
|
|
|
tmOrderService.updateById(orderInfo);
|
|
|
return Result.success(resultObj);
|
|
|
}
|