刘帅
2026-09-21 86ce1aaf6819a6d62cfba4233219fa4661aacbff
cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java
@@ -26,9 +26,11 @@
import com.dsh.course.model.vo.response.*;
import com.dsh.course.service.*;
import com.dsh.course.util.*;
import com.dsh.course.util.wx.WxV3PayConfig;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.obs.services.internal.ServiceException;
import com.wechat.pay.contrib.apache.httpclient.util.AesUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
@@ -44,8 +46,10 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
@@ -351,13 +355,19 @@
            }
            Store store = storeClient.queryStoreById(re.getStoreId());
            TAppUser appUser = appUserClient.queryAppUser1(re.getAppUserId());
            String studentId = re.getStudentId();
            String[] split = studentId.split(";");
            StringBuilder stringBuilder = new StringBuilder("");
            for (String s : split) {
                Student student = studentClient.queryStudentById(Integer.valueOf(s));
                stringBuilder.append(student.getName()+",");
            String studentId = re.getStudentId();
            if (studentId != null && !studentId.trim().isEmpty()) {
                String[] split = studentId.split(";");
                for (String s : split) {
                    if (s == null || s.trim().isEmpty()) {
                        continue;
                    }
                    Student student = studentClient.queryStudentById(Integer.valueOf(s));
                    if (student != null) {
                        stringBuilder.append(student.getName()).append(",");
                    }
                }
            }
            String string = stringBuilder.toString();
            if (string.length() > 0) {
@@ -487,11 +497,23 @@
                }
            }
            TAppUser appUser = appUserClient.queryAppUser1(re.getAppUserId());
            String[] split = re.getStudentIds().split(",");
            Student student = studentClient.queryStudentById(Integer.valueOf(split[0]));
            re.setPayStudent(student.getName());
            re.setPayUser(appUser.getName());
            re.setPhone(appUser.getPhone());
            // 统计接口只关心订单金额;历史订单可能没有关联学员或用户,不能因此整批查询失败。
            re.setPayStudent("无");
            if (re.getStudentIds() != null && !re.getStudentIds().trim().isEmpty()) {
                try {
                    String[] split = re.getStudentIds().split(",");
                    Student student = studentClient.queryStudentById(Integer.valueOf(split[0]));
                    if (student != null && student.getName() != null) {
                        re.setPayStudent(student.getName());
                    }
                } catch (NumberFormatException ignored) {
                    // 历史脏数据按“无学员”返回,避免影响其他有效订单。
                }
            }
            if (appUser != null) {
                re.setPayUser(appUser.getName());
                re.setPhone(appUser.getPhone());
            }
        }
        return res;
    }
@@ -718,7 +740,8 @@
        );
        List<Long> collect = list1.stream().map(CoursePackageOrderStudent::getId).collect(Collectors.toList());
        QueryWrapper<CourseCounsum> in = new QueryWrapper<CourseCounsum>().in("paymentId", collect).in("changeType", changes);
        QueryWrapper<CourseCounsum> in = new QueryWrapper<CourseCounsum>()
                .in("paymentId", collect).in("changeType", changes);
        if (recordTimeRequest.getType() != null) {
            if (recordTimeRequest.getType() == 2) {
@@ -1216,6 +1239,51 @@
    /**
     * 课包续课微信支付回调接口
     */
    @PostMapping("/base/coursePackage/wechatRegisteredCoursesCallback1")
    public void weChatCallback1(HttpServletRequest request, HttpServletResponse response) {
        try {
            System.err.println("微信回调");
            System.err.println("请求" + request);
            BufferedReader reader = request.getReader();
            String string1 = reader.toString();
            System.err.println("请求reader" + string1);
            StringBuilder requestBody = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                requestBody.append(line);
            }
            System.err.println("全部请求体" + requestBody);
            com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(requestBody.toString());
            com.alibaba.fastjson.JSONObject resource = jsonObject.getJSONObject("resource");
            AesUtil aesUtil = new AesUtil(WxV3PayConfig.apiV3Key.getBytes(StandardCharsets.UTF_8));
            String decryptedData = aesUtil.decryptToString(resource.getString("associated_data").getBytes(StandardCharsets.UTF_8), resource.getString("nonce").getBytes(StandardCharsets.UTF_8),
                    resource.getString("ciphertext"));
            System.err.println("微信解密的字符串信息" + decryptedData);
            com.alibaba.fastjson.JSONObject jsonInfo = (com.alibaba.fastjson.JSONObject) com.alibaba.fastjson.JSONObject.parse(decryptedData);
            String out_trade_no = jsonInfo.getString("out_trade_no");
            String transaction_id = jsonInfo.getString("transaction_id");
            String trade_state = jsonInfo.getString("trade_state");
            if (trade_state.equals("SUCCESS")) {
                ResultUtil resultUtil = packagePaymentService.insertVipPaymentCallback(out_trade_no, transaction_id);
                if (resultUtil.getCode() == 200) {
                    PrintWriter out = response.getWriter();
                    out.write("SUCCESS");
                    out.flush();
                    out.close();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 课包续课微信支付回调接口
     */
    /**
     * 课包续课微信支付回调接口
     */
    @PostMapping("/base/coursePackage/wechatRegisteredCoursesCallback")
    public void weChatCallback(HttpServletRequest request, HttpServletResponse response) {
        try {
@@ -1236,8 +1304,6 @@
            e.printStackTrace();
        }
    }
    /**
     * 获取学员剩余课时
     *
@@ -2431,7 +2497,8 @@
        // 找出门店的所有课程 排出体验
        List<TCoursePackage> list = tcpService.list(new LambdaQueryWrapper<TCoursePackage>()
                .eq(TCoursePackage::getStoreId, courseDetailReq.getStoreId()).ne(TCoursePackage::getType, 3)
                .eq(TCoursePackage::getState, 1).like(TCoursePackage::getClassWeeks, week));
                .eq(TCoursePackage::getState, 1).like(TCoursePackage::getClassWeeks, week)
                .eq(TCoursePackage::getAuditStatus, 2));
        List<Integer> collect = list.stream().map(TCoursePackage::getId).collect(Collectors.toList());
        if (collect.size() == 0) {
            collect.add(-1);
@@ -2613,7 +2680,8 @@
    @PostMapping("/coursePackagePayment/queryCourseData")
    public List<Map<String, Object>> queryCourseData(@RequestBody List<Integer> ids) {
        // 找出课程类型  找出剩余的课时数
        List<TCoursePackageType> list = coursePackageTypeService.list();
        List<TCoursePackageType> list = coursePackageTypeService.list(
                new LambdaQueryWrapper<TCoursePackageType>().ne(TCoursePackageType::getState, 3));
        if (ids.size() == 0) {
            ids.add(-1);
        }
@@ -2665,7 +2733,8 @@
        map.put("allCourse",sum-sum1);
        //所有课包
        List<TCoursePackage> coursePackages = tcpService.list();
        List<TCoursePackage> coursePackages = tcpService.list(
                new LambdaQueryWrapper<TCoursePackage>().ne(TCoursePackage::getState, 3));
        // 年
@@ -2815,7 +2884,8 @@
        map.put("allCourse", sum - sum1);
        //所有课包
        List<TCoursePackage> coursePackages = tcpService.list();
        List<TCoursePackage> coursePackages = tcpService.list(
                new LambdaQueryWrapper<TCoursePackage>().ne(TCoursePackage::getState, 3));
        // 年
@@ -2962,7 +3032,8 @@
        map.put("allCourse", sum - sum1);
        //所有课包
        List<TCoursePackage> coursePackages = tcpService.list();
        List<TCoursePackage> coursePackages = tcpService.list(
                new LambdaQueryWrapper<TCoursePackage>().ne(TCoursePackage::getState, 3));
        // 年