无关风月
2025-05-08 9486766c806fe1d9e082b2fd02ea1cc558f1b443
cloud-server-account/src/main/java/com/dsh/account/service/impl/TAppUserServiceImpl.java
@@ -130,6 +130,7 @@
    @Resource
    private UserConponClient ucponClient;
    @Resource
    private CoursePackageClient cpageClient;
@@ -1363,11 +1364,9 @@
            }
            //查询该用户是否超出限领数量
            Integer usercounts = userConponClient.queryCounts1(queryIds);
            if (usercounts == coupon.getPickUpQuantity()) {
                return new ResultUtil<>(0, "限领数量已达最大");
            }
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
            String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);
            //生成支付订单
@@ -1423,7 +1422,7 @@
                }
            }
        }
        System.out.println(exchangeType);
        System.out.println("兑换积分商品"+exchangeType);
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
            String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);
@@ -1524,7 +1523,7 @@
            if(null != merchandise.getIntegral()){
                pointsMerchandise.setIntegral(merchandise.getIntegral() * goodsNums);
            }
            if(exchangeType.getExchangeType() == 2){
            if(exchangeType.getExchangeType() == 2 || exchangeType.getExchangeType() == 3){
                pointsMerchandise.setCash(merchandise.getCash());
                pointsMerchandise.setCashPayType(exchangeType.getPayType());
            }
@@ -1540,6 +1539,7 @@
                return ResultUtil.success(returnModel);
            }
            System.err.println("兑换方式"+exchangeType);
            switch (exchangeType.getExchangeType()) {
//            积分
                case 1:
@@ -1636,6 +1636,8 @@
                                    return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(exchangeType.getStuIds().size())), code,merchandise.getId());
                                } else if (merchandise.getType() == 1){
                                    return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code,merchandise.getId());
                                }else if(merchandise.getType() == 3){
                                    return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code,merchandise.getId());
                                }
                            } catch (Exception e) {
                                return ResultUtil.runErr();
@@ -1702,6 +1704,7 @@
        if (coupon.getPublisherType()!=null&&coupon.getPublisherType()!=2){
            temp  = "1";
        }
        System.err.println("购买优惠券");
        ResultUtil weixinpay = payMoneyUtil.weixinpay(body+"-"+temp, "", code, cash.toString(),
                "/base/coupon/weChatPaymentCouponCallback", "APP", "");
        if (weixinpay.getCode() == 200) {
@@ -1758,38 +1761,6 @@
                                        TAppUser user = appUserService.getById(userCouponPayment1.getUserId());
                                        user.setIntegral(user.getIntegral() - userCouponPayment1.getIntegral().intValue());
                                        appUserService.updateById(user);
                                    }
                                    // 休眠两分钟后再调用分账接口 避免提示订单正在处理中
                                    Thread.sleep(120000);
                                    if (coupon!=null){
                                        if (coupon.getPublisherType()!=null&&coupon.getPublisherType()!=2){
                                            if (coupon.getPublisherType() == 3){
                                                // 门店 向上查询运营商
                                                Store store = storeClient.queryStoreById(coupon.getCityManagerId());
                                                if (store.getOperatorId()==null || store.getOperatorId()==0){
                                                    // 平台不分账
                                                    break;
                                                }else{
                                                    // 根据运营商id获取对应运营商分账比例 返回格式: 微信分账比例,支付宝分账比例
                                                    String proportionByOperatorId = storeClient.getProportionByOperatorId(store.getOperatorId());
                                                    String[] split = proportionByOperatorId.split(",");
                                                    String s1 = split[0];
                                                    if (!s1.equals("未设置")){
                                                        BigDecimal bigDecimal = new BigDecimal(s1);
                                                        // 分账比例
                                                        BigDecimal bigDecimal1 = bigDecimal.divide(new BigDecimal(100)).setScale(2);
                                                        // 微信商户号
                                                        String s2 = storeClient.getmerchantNumberByOperatorId(store.getOperatorId());
                                                        BigDecimal bigDecimal2 = new BigDecimal(cash);
                                                        ResultUtil fenzhang = payMoneyUtil.fenzhang(userCouponPayment1.getOrderNumber(), bigDecimal2.multiply(bigDecimal1), s2);
                                                        if (!fenzhang.getCode().equals(500)){
                                                            System.err.println("分账失败 原因是:"+fenzhang.getMsg());
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                                }
@@ -1902,7 +1873,8 @@
     * @return
     */
    @Override
    public ResultUtil paymentCouponCallback(String code, String orderNumber) {
    public ResultUtil paymentCouponCallback(String code, String orderNumber) throws Exception {
        System.err.println("进入回调");
        UserCouponPayment userCouponPayment1 = userCouponPaymentClient.getUserCouponPayment(code);
        if (userCouponPayment1.getStatus() == 2) {
            return ResultUtil.success();
@@ -1927,8 +1899,70 @@
            vo.setRemark("兑换优惠券");
            vo.setType(2);
            userIntegralChangesService.saveUserIntegralChanges(vo);
        }
        Coupon coupon = ucponClient.queryCouponById(userCouponPayment1.getCouponId());
        // 创建一个两分钟后执行的线程
        new Thread(() -> {
            try {
                Thread.sleep(120000);
                if (coupon!=null){
                    if (coupon.getPublisherType()!=null&&coupon.getPublisherType()!=2){
                        if (coupon.getPublisherType() == 1){
                            System.err.println("进入分账逻辑");
                            // 根据运营商id获取对应运营商分账比例 返回格式: 微信分账比例,支付宝分账比例
                            String proportionByOperatorId = storeClient.getProportionByOperatorId(coupon.getCityManagerId());
                            System.err.println("分账比例:"+proportionByOperatorId);
                            String[] split = proportionByOperatorId.split(",");
                            String s1 = split[0];
                            if (!s1.equals("未设置")){
                                BigDecimal bigDecimal = new BigDecimal(s1);
                                // 分账比例
                                BigDecimal bigDecimal1 = bigDecimal.divide(new BigDecimal(100)).setScale(2);
                                // 微信商户号
                                String s2 = storeClient.getmerchantNumberByOperatorId(coupon.getCityManagerId());
                                System.err.println("商户号"+s2);
                                System.err.println("分账比例"+bigDecimal1);
                                System.err.println("分账金额"+coupon.getCash().multiply(bigDecimal1));
                                ResultUtil fenzhang = payMoneyUtil.fenzhang(userCouponPayment1.getOrderNumber(), coupon.getCash().multiply(bigDecimal1), s2,"");
                                if (!fenzhang.getCode().equals(200)){
                                    System.err.println("分账失败 原因是:"+fenzhang.getMsg());
                                }
                            }
                        } else if (coupon.getPublisherType() == 3){
                            // 门店 向上查询运营商
                            Store store = storeClient.queryStoreById(coupon.getCityManagerId());
                            if (store.getOperatorId()==null || store.getOperatorId()==0){
                                // 平台不分账
                            }else{
                                // 根据运营商id获取对应运营商分账比例 返回格式: 微信分账比例,支付宝分账比例
                                String proportionByOperatorId = storeClient.getProportionByOperatorId(store.getOperatorId());
                                String[] split = proportionByOperatorId.split(",");
                                String s1 = split[0];
                                if (!s1.equals("未设置")){
                                    BigDecimal bigDecimal = new BigDecimal(s1);
                                    // 分账比例
                                    BigDecimal bigDecimal1 = bigDecimal.divide(new BigDecimal(100)).setScale(2);
                                    // 微信商户号
                                    String s2 = storeClient.getmerchantNumberByOperatorId(store.getOperatorId());
                                    ResultUtil fenzhang = payMoneyUtil.fenzhang(userCouponPayment1.getOrderNumber(), coupon.getCash().multiply(bigDecimal1), s2,"购买优惠券分账");
                                    if (!fenzhang.getCode().equals(200)){
                                        System.err.println("分账失败 原因是:"+fenzhang.getMsg());
                                    }else{
                                        System.err.println("分账成功");
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
        return ResultUtil.success();
    }
@@ -2125,7 +2159,10 @@
    private ResultUtil WechatPayment(Integer type, BigDecimal cash, String code,Integer id) throws Exception {
        String name = (type == 1 ? "购买实体商品" : type == 2 ? "报名运动营": type == 3 ? "购买门票" : "购买优惠券");
        System.err.println("微信支付:"+name);
        PointsMerchandise pointsMerchandise = mcClient.selectPointsMerchandiseById(id);
        System.err.println("查询积分商品"+pointsMerchandise);
        // 分账表示 0否1是
        String temp = "0";
        switch (type){
@@ -2155,8 +2192,10 @@
                // 查询门票指定的门店 属于平台还是运营商
                break;
        }
        System.err.println("支付");
        ResultUtil weixinpay = payMoneyUtil.weixinpay(name+"-"+temp, "", code, cash.toString(),
                "/base/pointMer/exchangeGoodPaymentWeChatCallback", "APP", "");
        System.err.println("提交支付"+weixinpay);
        if (weixinpay.getCode() == 200) {
            new Thread(new Runnable() {
                @Override
@@ -2222,59 +2261,6 @@
                                            paymentClient.addCoursePackageOrderStudent(addCoursePackageOrderStudent);
                                        }
                                    }
                                    // 休眠两分钟后再调用分账接口 避免提示订单正在处理中
                                    Thread.sleep(120000);
                                    // 分账表示 0否1是
                                    String temp = "0";
                                    // 运营商id
                                    Integer operatorId = 0;
                                    switch (type){
                                        case 1:
                                            temp = "0";
                                            break;
                                        case 2:
                                            // 判断课包属于平台还是运营商
                                            CoursePackage coursePackage = cpageClient.queryCoursePackageById(pointsMerchandise.getCoursePackageId());
                                            Store store = storeClient.queryStoreById(coursePackage.getStoreId());
                                            if (store.getOperatorId() ==null || store.getOperatorId() == 0){
                                                // 平台课包 不分账
                                            }else{
                                                temp = "1";
                                                operatorId = store.getOperatorId();
                                            }
                                            break;
                                        case 3:
                                            List<Integer> integers = mcsClient.queryPointMerStoreIds(pointsMerchandise.getId());
                                            if (!integers.isEmpty()){
                                                Store store1 = storeClient.queryStoreById(integers.get(0));
                                                if (store1.getOperatorId() ==null || store1.getOperatorId() == 0){
                                                    // 平台门票 不分账
                                                }else{
                                                    temp = "1";
                                                    operatorId = store1.getOperatorId();
                                                }
                                            }
                                            // 查询门票指定的门店 属于平台还是运营商
                                            break;
                                    }
                                    if (operatorId != 0) {
                                        // 根据运营商id获取对应运营商分账比例 返回格式: 微信分账比例,支付宝分账比例
                                        String proportionByOperatorId = storeClient.getProportionByOperatorId(operatorId);
                                        String[] split = proportionByOperatorId.split(",");
                                        String s1 = split[0];
                                        if (!s1.equals("未设置")){
                                            BigDecimal bigDecimal = new BigDecimal(s1);
                                            // 分账比例
                                            BigDecimal bigDecimal1 = bigDecimal.divide(new BigDecimal(100)).setScale(2);
                                            // 微信商户号
                                            String s2 = storeClient.getmerchantNumberByOperatorId(operatorId);
                                            ResultUtil fenzhang = payMoneyUtil.fenzhang(transaction_id, cash.multiply(bigDecimal1), s2);
                                            if (!fenzhang.getCode().equals(500)){
                                                System.err.println("分账失败 原因是:"+fenzhang.getMsg());
                                            }
                                        }
                                    }
                                    break;
                                }
                                if ("USERPAYING".equals(s) || "NOTPAY".equals(s)) {
@@ -2293,7 +2279,9 @@
    @Override
    public ResultUtil exchangeAddPaymentCallback(String code, String orderNumber) {
        System.err.println("进入回调"+code);
        UserPointsMerchandise userPointsMerchandise = mcClient.queryUserPointMerchaseByCode(code).get(0);
        System.err.println("商品"+userPointsMerchandise);
        if (userPointsMerchandise.getPayStatus() == 2) {
            return ResultUtil.success();
        }
@@ -2328,7 +2316,113 @@
                paymentClient.addCoursePackageOrderStudent(addCoursePackageOrderStudent);
            }
        }
        // 创建一个2分钟后执行的线程
        new Thread(() -> {
            try {
                // 休眠两分钟后再调用分账接口 避免提示订单正在处理中
                Thread.sleep(1000 * 60 * 2);
                // 分账表示 0否1是
                String temp = "0";
                // 运营商id
                Integer operatorId = 0;
                System.err.println("商品"+pointsMerchandise);
                switch (pointsMerchandise.getType()){
                    case 1:
                        temp = "0";
                        break;
                    case 2:
                        // 判断课包属于平台还是运营商
                        CoursePackage coursePackage = cpageClient.queryCoursePackageById(pointsMerchandise.getCoursePackageId());
                        Store store = storeClient.queryStoreById(coursePackage.getStoreId());
                        if (store.getOperatorId() ==null || store.getOperatorId() == 0){
                            // 平台课包 不分账
                        }else{
                            temp = "1";
                            operatorId = store.getOperatorId();
                        }
                        break;
                    case 3:
                        List<Integer> integers = mcsClient.queryPointMerStoreIds(pointsMerchandise.getId());
                        System.err.println("门店ids"+integers);
                        if (!integers.isEmpty()){
                            Store store1 = storeClient.queryStoreById(integers.get(0));
                            if (store1.getOperatorId() ==null || store1.getOperatorId() == 0){
                                // 平台门票 不分账
                            }else{
                                temp = "1";
                                operatorId = store1.getOperatorId();
                            }
                        }
                        // 查询门票指定的门店 属于平台还是运营商
                        break;
                }
                System.err.println("运营商id"+operatorId);
                if (operatorId != 0) {
                    //课程
                    if(pointsMerchandise.getType() == 2){
                        //课程
                        CoursePackageOrder coursePackageOrder1 = paymentClient.getCoursePackageOrderByCode(code);
                        if(null != coursePackageOrder1){
                            coursePackageOrder1.setPayStatus(2);
                            coursePackageOrder1.setOrderNumber(orderNumber);
                            coursePackageOrder1.setAppUserId(null);
                            paymentClient.updateCoursePackageOrder(coursePackageOrder1);
                            GetCoursePackagePaymentConfig getCoursePackagePaymentConfig = new GetCoursePackagePaymentConfig();
                            getCoursePackagePaymentConfig.setCoursePackageId(coursePackageOrder1.getCoursePackageId());
                            getCoursePackagePaymentConfig.setClassHours(coursePackageOrder1.getClassHours());
                            CoursePackagePaymentConfig coursePackagePaymentConfig = paymentClient.getCoursePackagePaymentConfig(getCoursePackagePaymentConfig);
                            AddCoursePackageOrderStudent addCoursePackageOrderStudent = new AddCoursePackageOrderStudent();
                            addCoursePackageOrderStudent.setCoursePackageOrderId(coursePackageOrder1.getId());
                            addCoursePackageOrderStudent.setCoursePackagePaymentConfig(coursePackagePaymentConfig);
                            paymentClient.addCoursePackageOrderStudent(addCoursePackageOrderStudent);
                            // 根据运营商id获取对应运营商分账比例 返回格式: 微信分账比例,支付宝分账比例
                            String proportionByOperatorId = storeClient.getProportionByOperatorId(operatorId);
                            String[] split = proportionByOperatorId.split(",");
                            String s1 = split[0];
                            if (!s1.equals("未设置")){
                                BigDecimal bigDecimal = new BigDecimal(s1);
                                // 分账比例
                                BigDecimal bigDecimal1 = bigDecimal.divide(new BigDecimal(100)).setScale(2);
                                // 微信商户号
                                String s2 = storeClient.getmerchantNumberByOperatorId(operatorId);
                                ResultUtil fenzhang = payMoneyUtil.fenzhang(orderNumber, coursePackageOrder1.getCashPayment().multiply(bigDecimal1), s2,"运动营商品");
                                if (!fenzhang.getCode().equals(200)){
                                    System.err.println("分账失败 原因是:"+fenzhang.getMsg());
                                }
                            }
                        }
                    }else{
                        System.err.println("门票");
                        // 根据运营商id获取对应运营商分账比例 返回格式: 微信分账比例,支付宝分账比例
                        String proportionByOperatorId = storeClient.getProportionByOperatorId(operatorId);
                        System.err.println("分账比例"+proportionByOperatorId);
                        String[] split = proportionByOperatorId.split(",");
                        String s1 = split[0];
                        if (!s1.equals("未设置")){
                            BigDecimal bigDecimal = new BigDecimal(s1);
                            // 分账比例
                            BigDecimal bigDecimal1 = bigDecimal.divide(new BigDecimal(100)).setScale(2);
                            // 微信商户号
                            String s2 = storeClient.getmerchantNumberByOperatorId(operatorId);
                            System.err.println("微信商户号"+s2);
                            ResultUtil fenzhang = payMoneyUtil.fenzhang(orderNumber, pointsMerchandise.getCash().multiply(bigDecimal1), s2,"门票");
                            if (!fenzhang.getCode().equals(200)){
                                System.err.println("分账失败 原因是:"+fenzhang.getMsg());
                            }
                        }
                    }
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }).start();
        return ResultUtil.success();
    }