15044148858 2 주 전
부모
커밋
b1e8de9e9c

+ 108 - 42
qmjszx-admin/src/main/java/beilv/web/controller/carinformation/CardAppController.java

@@ -31,6 +31,7 @@ import beilv.vipCardLog.service.IVipCardLogService;
 import beilv.voucher.domain.BeilvVoucherMember;
 import beilv.voucher.service.IBeilvVoucherMemberService;
 import beilv.wx.pay.controller.WxPayController;
+import beilv.wx.pay.domain.vo.AppPayParam;
 import beilv.wx.pay.domain.vo.AppRefundParam;
 import cn.hutool.core.lang.Dict;
 import com.github.pagehelper.PageHelper;
@@ -95,43 +96,29 @@ public class CardAppController extends BaseController {
     private IBeilvVoucherMemberService voucherMemberService;
 
     /**
-     * 新增充值记录
+     * 新增充值记录(已废弃,请使用 addOrderLog)
+     * @deprecated 使用 addOrderLog 替代
      */
+    @Deprecated
     @PostMapping("/addVipCardLog")
     @ResponseBody
     public AjaxResult addSave(@RequestBody VipCardLog vipCardLog) {
-        String uuid = IdUtils.fastSimpleUUID();
-        //设置订单编号
-        vipCardLog.setId(uuid);
-        //设置业务id
-        vipCardLog.setBusId(IdUtils.fastSimpleUUID());
-        //设置订单类型
+        // 兼容旧接口,设置订单类型为充值
         vipCardLog.setOrderType("chongzhi");
-        //设置支付状态为待支付
-        vipCardLog.setPaymentStatus("payment_status_to_be_paid");
-        //设置下单时间
-        vipCardLog.setCreateTime(DateUtils.getNowDate());
-        //设置支付方式
-        vipCardLog.setPaymentType("weChart");
-        //设置原价信息为实际支付价格
-        vipCardLog.setOriginalPrice(vipCardLog.getPracticalMoney());
-        //开启订单定时任务
-        createOrderTaskQueue(uuid, "chongzhi", "");
-
-        //判断订单是否使用代金券
-        if (StringUtils.isNotEmpty(vipCardLog.getVoucherId())) {
-            //修改代金券状态为已使用
-            voucherMemberService.updateBeilvVoucherMember(new BeilvVoucherMember(Long.parseLong(vipCardLog.getVoucherId()), "2"));
-            //当使用了代金券, 原价为, 实际支付金额+代金券金额
-            vipCardLog.setOriginalPrice(vipCardLog.getOriginalPrice().add(vipCardLog.getVoucherPrice()));
-        }
-
-        //写入订单信息
-        return insertVipCardLog(vipCardLog, uuid);
+        return addOrderLog(vipCardLog);
     }
 
     /**
-     * 新增其他订单记录
+     * 新增订单记录(统一接口)
+     * 根据 orderType 类型处理不同的订单逻辑
+     * - orderType="chongzhi": 充值订单
+     * - orderType="yueqiu": 约球订单
+     * - orderType="gouka": 购卡订单
+     * - orderType="cansai": 参赛订单
+     * - orderType="menpiao": 门票订单
+     * - 其他类型...
+     * 
+     * 如果是微信支付,会自动调用微信统一下单接口并返回支付参数
      */
     @PostMapping("/addOrderLog")
     @ResponseBody
@@ -141,23 +128,102 @@ public class CardAppController extends BaseController {
         vipCardLog.setId(uuid);
         //设置下单时间
         vipCardLog.setCreateTime(DateUtils.getNowDate());
-        //订单信息验证
-        if (!validateOrder(vipCardLog)) {
-            return AjaxResult.error("订单验证失败");
-        }
-        if ("weChart".equals(vipCardLog.getPaymentType())) {
-            //开启订单的定时任务, 超过设定的时间则设置为取消订单.
-            createOrderTaskQueue(uuid, vipCardLog.getOrderType(), vipCardLog.getBusId());
-        }
 
-        //判断订单是否使用代金券
-        if (StringUtils.isNotEmpty(vipCardLog.getVoucherId())) {
-            //修改代金券状态为已使用
-            voucherMemberService.updateBeilvVoucherMember(new BeilvVoucherMember(Long.parseLong(vipCardLog.getVoucherId()), "2"));
+        // 根据订单类型进行不同处理
+        if ("chongzhi".equals(vipCardLog.getOrderType())) {
+            // ========== 充值订单特有逻辑 ==========
+            //设置业务id
+            vipCardLog.setBusId(IdUtils.fastSimpleUUID());
+            //设置支付状态为待支付
+            vipCardLog.setPaymentStatus("payment_status_to_be_paid");
+            //设置支付方式为微信支付
+            vipCardLog.setPaymentType("weChart");
+            //设置原价信息为实际支付价格
+            vipCardLog.setOriginalPrice(vipCardLog.getPracticalMoney());
+            //开启订单定时任务
+            createOrderTaskQueue(uuid, "chongzhi", "");
+
+            //判断订单是否使用代金券
+            if (StringUtils.isNotEmpty(vipCardLog.getVoucherId())) {
+                //修改代金券状态为已使用
+                voucherMemberService.updateBeilvVoucherMember(new BeilvVoucherMember(Long.parseLong(vipCardLog.getVoucherId()), "2"));
+                //当使用了代金券, 原价为, 实际支付金额+代金券金额
+                vipCardLog.setOriginalPrice(vipCardLog.getOriginalPrice().add(vipCardLog.getVoucherPrice()));
+            }
+        } else {
+            // ========== 其他订单类型特有逻辑 ==========
+            //订单信息验证
+            if (!validateOrder(vipCardLog)) {
+                return AjaxResult.error("订单验证失败");
+            }
+            
+            //只有微信支付才开启订单定时任务
+            if ("weChart".equals(vipCardLog.getPaymentType())) {
+                //开启订单的定时任务, 超过设定的时间则设置为取消订单
+                createOrderTaskQueue(uuid, vipCardLog.getOrderType(), vipCardLog.getBusId());
+            }
+
+            //判断订单是否使用代金券
+            if (StringUtils.isNotEmpty(vipCardLog.getVoucherId())) {
+                //修改代金券状态为已使用
+                voucherMemberService.updateBeilvVoucherMember(new BeilvVoucherMember(Long.parseLong(vipCardLog.getVoucherId()), "2"));
+            }
         }
 
         //写入订单表
-        return insertVipCardLog(vipCardLog, uuid);
+        AjaxResult result = insertVipCardLog(vipCardLog, uuid);
+        
+        // 如果是微信支付,自动调用微信统一下单接口
+        if ("weChart".equals(vipCardLog.getPaymentType()) && result.isSuccess()) {
+            try {
+                log.info("订单创建成功,开始调用微信统一下单,订单号: {}", uuid);
+                AppPayParam appPayParam = new AppPayParam();
+                appPayParam.setOrderId(uuid);
+                appPayParam.setUserId(Long.valueOf(vipCardLog.getUserId()));
+                appPayParam.setTotalPrice(vipCardLog.getOriginalPrice());
+                appPayParam.setPayPrice(vipCardLog.getPracticalMoney());
+                appPayParam.setDescription(getOrderDescription(vipCardLog.getOrderType()));
+                
+                // 调用微信统一下单
+                AjaxResult payResult = payController.unifiedOrder(appPayParam);
+                if (payResult.isSuccess()) {
+                    // 返回订单ID和支付参数
+                    Map<String, Object> data = new HashMap<>();
+                    data.put("orderId", uuid);
+                    data.put("payParams", payResult.get("data"));
+                    return AjaxResult.success("订单创建成功", data);
+                } else {
+                    log.error("微信统一下单失败,订单号: {}", uuid);
+                    return AjaxResult.error("微信统一下单失败");
+                }
+            } catch (Exception e) {
+                log.error("调用微信统一下单异常,订单号: {}", uuid, e);
+                return AjaxResult.error("调用微信统一下单异常: " + e.getMessage());
+            }
+        }
+        
+        // 非微信支付直接返回订单创建结果
+        return result;
+    }
+
+    /**
+     * 获取订单描述信息
+     */
+    private String getOrderDescription(String orderType) {
+        switch (orderType) {
+            case "chongzhi":
+                return "会员卡充值";
+            case "yueqiu":
+                return "场地预约";
+            case "gouka":
+                return "购买次卡";
+            case "cansai":
+                return "赛事报名";
+            case "menpiao":
+                return "门票购买";
+            default:
+                return "订单支付";
+        }
     }
 
     /**

+ 5 - 1
qmjszx-pay/src/main/java/beilv/wx/pay/controller/WxPayController.java

@@ -40,8 +40,12 @@ public class WxPayController extends BaseController {
     /**
      * 调用统一下单接口(JSAPI)
      * 详见:https://pay.weixin.qq.com/doc/v3/merchant/4012791856
+     * 
+     * @deprecated 已整合到 CardAppController.addOrderLog 接口中,建议前端直接调用 /app-api/cardApp/addOrderLog
+     * 该接口保留用于内部调用和兼容性
      */
-    @ApiOperation(value = "统一下单,并组装所需支付参数")
+    @Deprecated
+    @ApiOperation(value = "统一下单,并组装所需支付参数(已废弃,建议使用 addOrderLog)")
     @PostMapping("app-api/pay/unifiedOrder")
     public AjaxResult unifiedOrder(@RequestBody AppPayParam param) throws Exception {
         log.info("收到统一下单请求,订单号: {}", param.getOrderId());