lisy
2023-08-09 525e21bf383c9cb4bfe18c72ebcb4fd6ef74db7c
cloud-server-account/src/main/java/com/dsh/account/service/impl/TAppUserServiceImpl.java
@@ -42,6 +42,7 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
@@ -854,6 +855,7 @@
    }
    @Override
    @Transactional
    public ResultUtil productRedemptionOperation(Integer userIdFormRedis, GoodsExchangeVo exchangeType) {
        System.out.println("exchangeType:--->");
        System.out.println(exchangeType);
@@ -888,6 +890,7 @@
            pointsMerchandise.setPointsMerchandiseId(exchangeType.getGoodId());
            pointsMerchandise.setUserId(userIdFormRedis);
            pointsMerchandise.setStatus(1);
            pointsMerchandise.setState(1);
            if (merchandise.getUseScope() == 3){
                if (exchangeType.getGoodsType() == 2){
                    CoursePackage coursePackage = cpageClient.queryCoursePackageById(merchandise.getCoursePackageId());
@@ -935,7 +938,6 @@
                                packagePayment.setPayUserId(userIdFormRedis);
                                packagePayment.setStatus(1);
                                packagePayment.setState(1);
                                packagePayment.setInsertTime(new Date());
                                packagePayment.setCode(code);
                                paymentClient.savePaymentCoursePackage(packagePayment);
                            }
@@ -946,7 +948,6 @@
                                coupon.setCouponId(exchangeType.getGoodId());
                                coupon.setUserId(userIdFormRedis);
                                coupon.setStatus(1);
                                coupon.setInsertTime(new Date());
                                ucponClient.insertToAppuserCoupon(coupon);
                            }
                            break;
@@ -960,59 +961,6 @@
            case 2:
//                积分+现金
                boolean dealt = dealAppUserIntegral(userIdFormRedis,tAppUser,merchandise.getIntegral());
                if (dealt){
                    switch (exchangeType.getGoodsType()){
//                        1实物 2课包 3门票 4优惠券
                        case 2:
                            Integer stuNums = 0;
                            if (ToolUtil.isNotEmpty(exchangeType.getStuIds())){
                                stuNums = exchangeType.getStuIds().size();
                            }else {
                                stuNums = 1;
                            }
                            for (int i = 0; i < stuNums; i++) {
                                List<CoursePackagePaymentConfig> courseConfigList = cpconClient.getCourseConfigList(merchandise.getCoursePackageId());
                                TCoursePackagePayment packagePayment = new TCoursePackagePayment();
                                packagePayment.setAppUserId(userIdFormRedis);
                                packagePayment.setStudentId(exchangeType.getStuIds().get(i));
                                packagePayment.setCoursePackageId(merchandise.getCoursePackageId());
                                for (CoursePackagePaymentConfig coursePackagePaymentConfig : courseConfigList) {
                                    if (Objects.equals(coursePackagePaymentConfig.getId(), merchandise.getCoursePackageConfigId())) {
                                        packagePayment.setClassHours(coursePackagePaymentConfig.getClassHours());
                                        packagePayment.setTotalClassHours(coursePackagePaymentConfig.getClassHours());
                                        packagePayment.setLaveClassHours(coursePackagePaymentConfig.getClassHours());
                                        packagePayment.setOriginalPrice(coursePackagePaymentConfig.getCashPayment());
                                        break;
                                    }
                                }
                                packagePayment.setPlayPaiCoin(merchandise.getIntegral());
                                packagePayment.setAbsencesNumber(0);
                                packagePayment.setPayUserType(1);
                                packagePayment.setPayStatus(1);
                                packagePayment.setPayUserId(userIdFormRedis);
                                packagePayment.setStatus(1);
                                packagePayment.setState(1);
                                packagePayment.setInsertTime(new Date());
                                packagePayment.setCode(code);
                                paymentClient.savePaymentCoursePackage(packagePayment);
                            }
                            break;
                        case 4:
                            for (int i = 0; i < goodsNums; i++) {
                                UserCoupon coupon = new UserCoupon();
                                coupon.setCouponId(exchangeType.getGoodId());
                                coupon.setUserId(userIdFormRedis);
                                coupon.setStatus(1);
                                coupon.setInsertTime(new Date());
                                ucponClient.insertToAppuserCoupon(coupon);
                            }
                            break;
                        default:
                            break;
                    }
                }else {
                    return ResultUtil.error("用户积分不足!");
                }
                switch (exchangeType.getPayType()) {
                    case 1:
                        try {
@@ -1035,55 +983,6 @@
                }
                break;
            case 3:
//                现金
                switch (exchangeType.getGoodsType()){
                    case 2:
                        Integer stuNums = 0;
                        if (ToolUtil.isNotEmpty(exchangeType.getStuIds())){
                            stuNums = exchangeType.getStuIds().size();
                        }else {
                            stuNums = 1;
                        }
                        for (int i = 0; i < stuNums; i++) {
                            List<CoursePackagePaymentConfig> courseConfigList = cpconClient.getCourseConfigList(merchandise.getCoursePackageId());
                            TCoursePackagePayment packagePayment = new TCoursePackagePayment();
                            packagePayment.setAppUserId(userIdFormRedis);
                            packagePayment.setStudentId(exchangeType.getStuIds().get(i));
                            packagePayment.setCoursePackageId(merchandise.getCoursePackageId());
                            for (CoursePackagePaymentConfig coursePackagePaymentConfig : courseConfigList) {
                                if (Objects.equals(coursePackagePaymentConfig.getId(), merchandise.getCoursePackageConfigId())) {
                                    packagePayment.setClassHours(coursePackagePaymentConfig.getClassHours());
                                    packagePayment.setTotalClassHours(coursePackagePaymentConfig.getClassHours());
                                    packagePayment.setLaveClassHours(coursePackagePaymentConfig.getClassHours());
                                    packagePayment.setOriginalPrice(coursePackagePaymentConfig.getCashPayment());
                                    break;
                                }
                            }
                            packagePayment.setCashPayment(merchandise.getCash());
                            packagePayment.setAbsencesNumber(0);
                            packagePayment.setPayUserType(1);
                            packagePayment.setPayStatus(1);
                            packagePayment.setPayUserId(userIdFormRedis);
                            packagePayment.setStatus(1);
                            packagePayment.setState(1);
                            packagePayment.setInsertTime(new Date());
                            packagePayment.setCode(code);
                            paymentClient.savePaymentCoursePackage(packagePayment);
                        }
                        break;
                    case 4:
                        for (int i = 0; i < goodsNums; i++) {
                            UserCoupon coupon = new UserCoupon();
                            coupon.setCouponId(exchangeType.getGoodId());
                            coupon.setUserId(userIdFormRedis);
                            coupon.setStatus(1);
                            coupon.setInsertTime(new Date());
                            ucponClient.insertToAppuserCoupon(coupon);
                        }
                        break;
                    default:
                        break;
                }
                switch (exchangeType.getPayType()) {
                    case 1:
                        try {
@@ -1163,11 +1062,10 @@
                                Map<String, String> data1 = resultUtil.getData();
                                String s = data1.get("tradeStatus");
                                String tradeNo = data1.get("tradeNo");
//                                if("TRADE_CLOSED".equals(s) || "TRADE_FINISHED".equals(s) || num == 10){
//                                    coursePackagePayment.setState(3);
//                                    couPayClient.delPaymentCoursePackage(coursePackagePayment.getId());
//                                    break;
//                                }
                                if("REFUND".equals(s) || "NOTPAY".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s) || num == 10){
                                    mcClient.deletePaymentRecord(code);
                                    break;
                                }
                                if("TRADE_SUCCESS".equals(s)){
                                    for (UserPointsMerchandise userPointsMerchandise : userPointsMerchandises) {
                                        userPointsMerchandise.setPayStatus(2);
@@ -1183,6 +1081,7 @@
                            }
                        }
                    }catch (Exception e){
                        mcClient.deletePaymentRecord(code);
                        e.printStackTrace();
                    }
                }
@@ -1223,11 +1122,10 @@
                                Map<String, String> data1 = resultUtil.getData();
                                String s = data1.get("trade_state");
                                String transaction_id = data1.get("transaction_id");
//                                if("REFUND".equals(s) || "NOTPAY".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s) || num == 10){
//                                    coursePackagePayment.setState(3);
//                                    couPayClient.delPaymentCoursePackage(coursePackagePayment.getId());
//                                    break;
//                                }
                                if("REFUND".equals(s) || "NOTPAY".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s) || num == 10){
                                    mcClient.deletePaymentRecord(code);
                                    break;
                                }
                                if("SUCCESS".equals(s)){
                                    for (UserPointsMerchandise userPointsMerchandise : userPointsMerchandises) {
                                        userPointsMerchandise.setPayStatus(2);
@@ -1279,7 +1177,6 @@
                        coupon.setCouponId(userPointsMerchandises.get(0).getPointsMerchandiseId());
                        coupon.setUserId(userPointsMerchandises.get(0).getUserId());
                        coupon.setStatus(1);
                        coupon.setInsertTime(new Date());
                        ucponClient.insertToAppuserCoupon(coupon);
                        break;
                    default:
@@ -1310,7 +1207,6 @@
                    coupon.setCouponId(userPointsMerchandises.get(0).getPointsMerchandiseId());
                    coupon.setUserId(userPointsMerchandises.get(0).getUserId());
                    coupon.setStatus(1);
                    coupon.setInsertTime(new Date());
                    ucponClient.insertToAppuserCoupon(coupon);
                    break;
                default: