|
|
@@ -54,6 +54,7 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import static beilv.competition.domain.Constant.ORDER_QUEUE;
|
|
|
+import static beilv.wx.pay.service.IWxPayService.yuanToFen;
|
|
|
|
|
|
@RestController
|
|
|
@Slf4j
|
|
|
@@ -125,6 +126,9 @@ public class CardAppController extends BaseController {
|
|
|
@PostMapping("/addOrderLog")
|
|
|
@ResponseBody
|
|
|
public AjaxResult addOrderLog(@RequestBody VipCardLog vipCardLog) {
|
|
|
+ if (yuanToFen(vipCardLog.getPracticalMoney()) <= 0) {
|
|
|
+ return AjaxResult.error("支付金额无效!");
|
|
|
+ }
|
|
|
String uuid = IdUtils.fastSimpleUUID();
|
|
|
//设置订单编号
|
|
|
vipCardLog.setId(uuid);
|
|
|
@@ -172,13 +176,10 @@ public class CardAppController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //写入订单表
|
|
|
- AjaxResult result = insertVipCardLog(vipCardLog, uuid);
|
|
|
-
|
|
|
- // 如果是微信支付,自动调用微信统一下单接口
|
|
|
- if ("weChart".equals(vipCardLog.getPaymentType()) && result.isSuccess()) {
|
|
|
+ // 如果是微信支付,先调用微信统一下单接口
|
|
|
+ if ("weChart".equals(vipCardLog.getPaymentType())) {
|
|
|
try {
|
|
|
- log.info("订单创建成功,开始调用微信统一下单,订单号: {}", uuid);
|
|
|
+ log.info("开始调用微信统一下单,订单号: {}", uuid);
|
|
|
AppPayParam appPayParam = new AppPayParam();
|
|
|
appPayParam.setOrderId(uuid);
|
|
|
appPayParam.setUserId(Long.valueOf(vipCardLog.getUserId()));
|
|
|
@@ -189,6 +190,9 @@ public class CardAppController extends BaseController {
|
|
|
// 调用微信统一下单
|
|
|
AjaxResult payResult = payController.unifiedOrder(appPayParam);
|
|
|
if (payResult.isSuccess()) {
|
|
|
+ // 微信支付成功后再写入订单表
|
|
|
+ AjaxResult result = insertVipCardLog(vipCardLog, uuid);
|
|
|
+
|
|
|
// 返回订单ID和支付参数
|
|
|
Map<String, Object> data = new HashMap<>();
|
|
|
data.put("orderId", uuid);
|
|
|
@@ -196,7 +200,7 @@ public class CardAppController extends BaseController {
|
|
|
return AjaxResult.success("订单创建成功", data);
|
|
|
} else {
|
|
|
log.error("微信统一下单失败,订单号: {}", uuid);
|
|
|
- return AjaxResult.error("微信统一下单失败");
|
|
|
+ return AjaxResult.error("微信统一下单失败: " + payResult.get("msg"));
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.error("调用微信统一下单异常,订单号: {}", uuid, e);
|
|
|
@@ -204,8 +208,8 @@ public class CardAppController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 非微信支付直接返回订单创建结果
|
|
|
- return result;
|
|
|
+ // 非微信支付直接写入订单表并返回订单创建结果
|
|
|
+ return insertVipCardLog(vipCardLog, uuid);
|
|
|
}
|
|
|
|
|
|
/**
|