无关风月
2025-04-03 b01f752252eaadd1fa31eda6a9ad43146660b721
xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/controller/client/ClientOrderController.java
@@ -107,8 +107,28 @@
            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "String", required = true),
    })
    public R<String> queryPayment(@RequestParam(value = "orderId") String orderId) throws Exception {
        JSONObject jsonObject = JuHeFuUtil.queryPayment(orderId);
        return R.ok(jsonObject.getString("status"));
        Order byId = orderService.getById(orderId);
        if (byId==null){
            return R.fail("订单失效");
        }
        if (byId.getPaymentStatus()==2){
            return R.ok("succeeded");
        }else if (byId.getPaymentStatus()==1){
            return R.fail("pending");
        }else{
            return R.fail("failed");
        }
    }
    @GetMapping("/getMeditationIsBuyAll/{id}")
    public R<List<Order>> getMeditationIsBuyAll(@PathVariable("id")Long id) {
        List<Order> list = orderService.lambdaQuery()
                .eq(Order::getAppUserId, id)
                .eq(Order::getOrderFrom, 1)
                .eq(Order::getPaymentStatus, 2)
                .ne(Order::getRefundStatus, 3).list();
        return R.ok(list);
    }
    @GetMapping("/getMeditationIsBuy/{id}/{meditationId}")
    public R<Integer> getMeditationIsBuy(@PathVariable("id")Long id,@PathVariable("meditationId")Long meditationId) {
@@ -123,6 +143,7 @@
            return R.ok(1);
        }
    }
    @PostMapping("/payOrder")
    @ApiOperation(value = "已购详情-待支付状态-页面数据",tags = "我的已购")
    @ApiImplicitParams({
@@ -353,6 +374,13 @@
            return R.tokenError("登录失效");
        }
        Long userId = loginUser.getUserid();
        AppUser data2 = remoteAppUserService.getAppUserById(userId + "").getData();
        if (data2==null){
            return R.tokenError("登录失效");
        }else if (!StringUtils.hasLength(data2.getCellPhone())){
            return R.tokenError("登录失效");
        }
        try {
            if (orderId!=null){
                Order order = orderService.getById(orderId);
@@ -471,6 +499,101 @@
        return R.ok();
    }
    /**
     * 处理苹果退款 回调通知
     * @param request
     * @param response
     */
    @ResponseBody
    @PostMapping("/refundApple")
    public void refundApple(HttpServletRequest request, HttpServletResponse response) {
        try {
            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);
            org.json.JSONObject jsonObject1 = new org.json.JSONObject(requestBody.toString());
            System.err.println("json串"+jsonObject1);
            String o = jsonObject1.getString("signedPayload");
            com.alibaba.fastjson.JSONObject payload = verifyAndGet(o);
            String notificationType = payload.get("notificationType").toString();
            com.alibaba.fastjson.JSONObject data = payload.getJSONObject("data");
            String signedTransactionInfo = data.get("signedTransactionInfo").toString();
            com.alibaba.fastjson.JSONObject transactionInfo = verifyAndGet(signedTransactionInfo);
            System.err.println("解签后的json串"+transactionInfo);
            System.err.println("data"+data);
            // 苹果流水号
            String string = transactionInfo.getString("originalTransactionId");
            OrderPaymentRecord one = orderPaymentRecordService.getOne(new QueryWrapper<OrderPaymentRecord>()
                    .eq("pay_order_no", string)
                    .eq("payment_type", 3));
            Order order = orderService.getById(one.getOrderId());
            if (one!=null && one.getPaymentStatus() == 2){
                one.setPaymentStatus(3);
                switch (order.getOrderFrom()){
                    case 1:
                        // 冥想订单 删除
                        break;
                    case 2:
                        // 删除用户与课程的关系表
                        remoteAppUserService.deleteAppUserCourse(order.getBusinessId(),order.getAppUserId());
                        break;
                    case 3:
                        // 会员订单 将用户会员到期时间回退
                        if (order.getBuyContent().contains("月")){
                            remoteAppUserService.subVipExpireTime(order.getAppUserId(),1);
                        }else if (order.getBuyContent().contains("季")){
                            remoteAppUserService.subVipExpireTime(order.getAppUserId(),2);
                        }else if (order.getBuyContent().contains("年")){
                            remoteAppUserService.subVipExpireTime(order.getAppUserId(),3);
                        }
                        break;
                }
                // 内购+余额支付 需要退回余额 并删除余额支付记录
                if (order.getPayType() == 7){
                    // 查询余额支付
                    OrderPaymentRecord two = orderPaymentRecordService.getOne(new QueryWrapper<OrderPaymentRecord>()
                            .eq("order_id", order.getId())
                            .eq("payment_type", 4)
                            .eq("payment_status", 2)
                    );
                    two.setPaymentStatus(3);
                    orderPaymentRecordService.updateById(two);
                    AppUserWalletRecord appUserWalletRecord = new AppUserWalletRecord();
                    appUserWalletRecord.setAppUserId(order.getAppUserId());
                    appUserWalletRecord.setChangeType(1);
                    appUserWalletRecord.setReason("后台退款");
                    appUserWalletRecord.setOrderId(order.getId());
                    appUserWalletRecord.setAmount(two.getPayAmount());
                    remoteAppUserService.addBalanceRecord(appUserWalletRecord);
                    remoteAppUserService.addBalance(order.getAppUserId(),two.getPayAmount());
                }
                order.setRefundStatus(3);
                order.setRefundRemark("后台退款");
                order.setRefundTime(LocalDateTime.now());
                order.setPaymentStatus(3);
                order.setCancelTime(LocalDateTime.now());
                orderPaymentRecordService.updateById(one);
                orderService.updateById(order);
            }
            System.err.println("苹果流水号"+string);
            PrintWriter out = response.getWriter();
            out.write("success");
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    private static final TrustManager myX509TrustManager = new X509TrustManager() {
        @Override
        public X509Certificate[] getAcceptedIssuers() {