lisy
2023-08-04 4fa2598a31a505927eeb585ae25a3bb6902041cd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
package com.dsh.course.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.domain.Person;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsh.course.entity.*;
import com.dsh.course.feignclient.account.AppUserClient;
import com.dsh.course.feignclient.account.CoachClient;
import com.dsh.course.feignclient.account.model.AppUser;
import com.dsh.course.feignclient.account.model.Coach;
import com.dsh.course.feignclient.activity.BenefitVideoClient;
import com.dsh.course.feignclient.activity.CouponClient;
import com.dsh.course.feignclient.activity.model.BenefitsVideos;
import com.dsh.course.feignclient.activity.model.Coupon;
import com.dsh.course.feignclient.model.RecordAppoint;
import com.dsh.course.feignclient.other.StoreClient;
import com.dsh.course.feignclient.other.model.Store;
import com.dsh.course.mapper.*;
import com.dsh.course.model.dto.DiscountJsonDto;
import com.dsh.course.model.vo.RegisterCourseVo;
import com.dsh.course.model.vo.request.ClasspaymentRequest;
import com.dsh.course.model.vo.request.CourseOfAfterRequest;
import com.dsh.course.model.vo.request.CourseWithDetailsRequest;
import com.dsh.course.model.vo.request.UpdateCourseVideoStatusRequest;
import com.dsh.course.model.vo.response.AppUserVideoResponse;
import com.dsh.course.model.vo.response.CourseDetailsResponse;
import com.dsh.course.model.vo.response.CourseOfVideoResponse;
import com.dsh.course.service.TCoursePackagePaymentService;
import com.dsh.course.util.*;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 用户课程包购买记录 服务实现类
 * </p>
 *
 * @author administrator
 * @since 2023-06-14
 */
@Service
public class TCoursePackagePaymentServiceImpl extends ServiceImpl<TCoursePackagePaymentMapper, TCoursePackagePayment> implements TCoursePackagePaymentService {
 
 
    @Resource
    private BenefitVideoClient bfvoClient;
 
 
    @Resource
    private UserVideoDetailsMapper uvdmapper;
 
    @Resource
    private PostCourseVideoMapper pcvMapper;
 
    @Resource
    private TCoursePackageMapper tcpmapper;
 
    @Resource
    private StoreClient stoClient;
 
    @Resource
    private CoachClient coachClient;
 
    @Resource
    private CoursePackageStudentMapper cpsMapper;
 
    @Resource
    private CancelledClassesMapper cacMapper;
 
    @Resource
    private TCoursePackageDiscountMapper tcpdMapper;
 
 
    @Resource
    private CoursePackagePaymentConfigMapper cpConfigMapper;
 
    @Resource
    private CouponClient client;
 
    @Resource
    private PayMoneyUtil payMoneyUtil;
 
    @Resource
    private AppUserClient appuClient;
 
 
    /**
     * 获取课包购买人数
     * @param coursePackageId
     * @return
     */
    @Override
    public Integer queryCountNumber(Integer coursePackageId) {
        return this.baseMapper.queryCountNumber(coursePackageId);
    }
 
    @Override
    public List<AppUserVideoResponse> queryAfterVideo(CourseOfAfterRequest search,List<Integer> courseIds) {
        List<AppUserVideoResponse> responses = new ArrayList<>();
        List<PostCourseVideo> videoList = new ArrayList<>();
        LambdaQueryWrapper<PostCourseVideo> queryWrapper = new LambdaQueryWrapper<PostCourseVideo>();
        if (courseIds.size() > 0 ){
            queryWrapper.in(PostCourseVideo::getCoursePackageId,courseIds);
        }
        videoList = pcvMapper.selectList(queryWrapper);
        System.out.println(videoList);
        if (videoList.size() > 0){
            List<Integer> videoIds = videoList.stream().map(PostCourseVideo::getCourseId).collect(Collectors.toList());
            List<UserVideoDetails> userVideoDetails = uvdmapper.selectList(new QueryWrapper<UserVideoDetails>()
                    .in("courseId", videoIds));
            if (userVideoDetails.size() > 0){
                for (UserVideoDetails userVideoDetail : userVideoDetails) {
                    AppUserVideoResponse response = new AppUserVideoResponse();
                    TCoursePackage coursePackage = tcpmapper.selectById(userVideoDetail.getCoursePackageId());
                    response.setPackageName(coursePackage.getName());
                    response.setCoursePackageId(userVideoDetail.getCoursePackageId());
                    BenefitsVideos videosWithIds = bfvoClient.getVideosWithIds(userVideoDetail.getCourseId());
                    response.setVideoId(userVideoDetail.getCourseId());
                    response.setCoverImage(videosWithIds.getCover());
                    response.setVideoName(videosWithIds.getName());
                    response.setSynopsis(videosWithIds.getIntroduction());
                    response.setIntegral(videosWithIds.getIntegral());
                    response.setStudyStatus(userVideoDetail.getState());
                    responses.add(response);
                }
                Collections.sort(responses, Comparator.comparing(AppUserVideoResponse::getStudyStatus));
            }
            if (ToolUtil.isNotEmpty(search.getSearch())){
                responses = responses.stream()
                        .filter(person -> person.getPackageName().contains(search.getSearch()))
                        .collect(Collectors.toList());
            }
            if (ToolUtil.isNotEmpty(search.getCourseTypeId())){
                responses = responses.stream()
                        .filter(person -> Objects.equals(person.getCoursePackageId(), search.getCourseTypeId()))
                        .collect(Collectors.toList());
            }
        }
        return responses;
    }
 
    @Override
    public CourseOfVideoResponse queryVideoDetails(CourseWithDetailsRequest detailsRequest,Integer appUserId) {
        CourseOfVideoResponse response = new CourseOfVideoResponse();
        BenefitsVideos videosWithIds = bfvoClient.getVideosWithIds(detailsRequest.getVideoId());
        TCoursePackage coursePackage = tcpmapper.selectById(detailsRequest.getCoursePackageId());
        if (null != videosWithIds && null != coursePackage){
            response.setCoursePackageId(coursePackage.getId());
            response.setVideoId(videosWithIds.getId());
            response.setVideoURL(videosWithIds.getVideos());
            response.setVideoName(videosWithIds.getName());
            response.setIntegral(videosWithIds.getIntegral());
            UserVideoDetails userVideoDetails = uvdmapper.selectOne(new QueryWrapper<UserVideoDetails>()
                    .eq("appUserId",appUserId )
                    .eq("coursePackageId",coursePackage.getId())
                    .eq("courseId",videosWithIds.getId()));
 
            response.setStudyStatus(userVideoDetails.getState());
            response.setPackageName(coursePackage.getName());
            response.setSynopsis(videosWithIds.getIntroduction());
            response.setDetailedDiagram(coursePackage.getIntroduceDrawing());
        }
 
        return response;
    }
 
    @Override
    public String updateVideoStatus(UpdateCourseVideoStatusRequest detailsRequest, Integer appUserId) {
        UserVideoDetails userVideoDetails = uvdmapper.selectOne(new QueryWrapper<UserVideoDetails>()
                .eq("appUserId",appUserId )
                .eq("coursePackageId",detailsRequest.getCoursePackageId())
                .eq("courseId",detailsRequest.getVideoId())
                );
        if (null != userVideoDetails && userVideoDetails.getState() ==1 && detailsRequest.getIsOver() == 1){
            userVideoDetails.setState(2);
            userVideoDetails.setUpdateTime(new Date());
            uvdmapper.updateById(userVideoDetails);
            return "SUCCESS";
        }
        return "ERROR";
    }
 
    @Override
    public List<RegisterCourseVo> queryRegisteredCourseList(CourseOfAfterRequest courseTypeId, Integer appUserId) {
        List<RegisterCourseVo> courseVos = new ArrayList<>();
        List<TCoursePackagePayment> tCoursePackagePayments = this.list(new QueryWrapper<TCoursePackagePayment>()
                .eq("appUserId",appUserId ));
        System.out.println(tCoursePackagePayments);
        if (tCoursePackagePayments.size() > 0){
            for (TCoursePackagePayment tCoursePackagePayment : tCoursePackagePayments) {
                TCoursePackage coursePackage = tcpmapper.selectById(tCoursePackagePayment.getCoursePackageId());
                Store store = stoClient.queryStoreById(coursePackage.getStoreId());
                RegisterCourseVo registerCourseVo = new RegisterCourseVo();
                registerCourseVo.setCoursePayId(tCoursePackagePayment.getId());
                registerCourseVo.setCoursePackageId(tCoursePackagePayment.getCoursePackageId());
                registerCourseVo.setCoursePackTypeId(coursePackage.getCoursePackageTypeId());
                registerCourseVo.setPackageImg(coursePackage.getCoverDrawing());
                String storeAndCourse = coursePackage.getName()+"("+ store.getName() +")";
                registerCourseVo.setCourseNameStore(storeAndCourse);
                registerCourseVo.setCourseTime(coursePackage.getClassStartTime()+"-"+coursePackage.getClassEndTime());
                Coach coach = coachClient.queryCoachById(coursePackage.getCoachId());
                registerCourseVo.setCourseTeacher(coach.getName());
                List<CoursePackageStudent> coursePackageStudents = cpsMapper.selectList(new QueryWrapper<CoursePackageStudent>()
                        .eq("coursePackageId",coursePackage.getId())
                        .eq("studentId",appUserId ));
                if (coursePackageStudents.size() > 0 ){
                    registerCourseVo.setCourseNums(coursePackageStudents.size() * 2);
                }
                registerCourseVo.setPayStatus(tCoursePackagePayment.getPayStatus());
                courseVos.add(registerCourseVo);
            }
 
            if (ToolUtil.isNotEmpty(courseTypeId.getSearch())){
                courseVos = courseVos.stream()
                        .filter(person -> person.getCourseNameStore().contains(courseTypeId.getSearch()))
                        .collect(Collectors.toList());
            }
 
            if (ToolUtil.isNotEmpty(courseTypeId.getCourseTypeId())){
                courseVos = courseVos.stream()
                        .filter(person -> Objects.equals(person.getCoursePackTypeId(), courseTypeId.getCourseTypeId()))
                        .collect(Collectors.toList());
            }
 
            if (courseVos.size() > 0 ){
                courseVos = courseVos.stream()
                        .sorted(Comparator.comparingInt(person -> person.getPayStatus() == 1 ? -1 : 1))
                        .collect(Collectors.toList());
            }
        }
        return courseVos;
    }
 
    @Override
    public CourseDetailsResponse queryRegisteredCourseDetails(Integer coursePayId, Integer appUserId) {
        CourseDetailsResponse response = new CourseDetailsResponse();
        TCoursePackagePayment tCoursePackagePayment = this.baseMapper.selectById(coursePayId);
 
        if (null != tCoursePackagePayment){
            TCoursePackage coursePackage = tcpmapper.selectById(tCoursePackagePayment.getCoursePackageId());
            response.setCoursePackageId(tCoursePackagePayment.getCoursePackageId());
            response.setCoverDrawing(coursePackage.getCoverDrawing());
            response.setCoursePackageName(coursePackage.getName());
            response.setCoursePayId(tCoursePackagePayment.getId());
            List<Integer> integers = StrUtils.dealStrToList(coursePackage.getClassWeeks());
            if (integers.size() > 0){
                StringBuilder courWeeks = new StringBuilder("每");
                for (Integer integer : integers) {
                    courWeeks.append(integer).append("、");
                }
                if (courWeeks.length() > 0 && courWeeks.charAt(courWeeks.length() - 1) == '、'){
                    courWeeks.deleteCharAt(courWeeks.length() - 1);
                }
                response.setWeeks(courWeeks.toString());
            }
            response.setCourseTimeFrame(coursePackage.getClassStartTime()+"-"+coursePackage.getClassEndTime());
            response.setIntroduceDrawing(coursePackage.getIntroduceDrawing());
 
            Integer payType = tCoursePackagePayment.getPayType();
            BigDecimal cashPayment = tCoursePackagePayment.getCashPayment();
            double cashPaymentValue = cashPayment.doubleValue();
            Integer playPaiCoin = tCoursePackagePayment.getPlayPaiCoin();
            TCoursePackageDiscount coursePackageDiscount = tcpdMapper.selectOne(new QueryWrapper<TCoursePackageDiscount>()
                    .eq("coursePackageId",coursePackage.getId() )
                    .eq("type",1)
                    .eq("auditStatus",2));
            ObjectMapper objectMapper = new ObjectMapper();
            String content = coursePackageDiscount.getContent();
            double discountMember = 0.0;
            DiscountJsonDto discountJsonDto = null;
            try {
                discountJsonDto = objectMapper.readValue(content, DiscountJsonDto.class);
                discountMember = discountJsonDto.getDiscountMember();
            } catch (JsonProcessingException e) {
                throw new RuntimeException(e);
            }
            switch (payType) {
                case 1:
                case 2:
                    response.setAmount(cashPaymentValue);
                    response.setVipAmount(discountMember);
                    break;
                case 3:
                    response.setWpGold(playPaiCoin);
                    break;
            }
            response.setPayStatus(tCoursePackagePayment.getPayStatus());
        }
        return response;
    }
 
    @Override
    public ResultUtil ContinuationOrpaymentCourse(Integer ids, ClasspaymentRequest request) {
        AppUser userIdFormRedis = appuClient.queryAppUser(ids);
        TCoursePackagePayment tCoursePackagePayment = this.baseMapper.selectById(request.getCoursePayId());
        String code = "";
        BigDecimal money = tCoursePackagePayment.getCashPayment();
        Integer wpGold = tCoursePackagePayment.getPlayPaiCoin();
        if (tCoursePackagePayment.getPayStatus() == 1){
//            待支付的订单
            code = tCoursePackagePayment.getCode();
            tCoursePackagePayment.setPayType(request.getPayType());
            if (request.getUseConpon() == 1){
                tCoursePackagePayment.setUserCouponId(Long.valueOf(request.getUseConpon()));
            }
            this.baseMapper.updateById(tCoursePackagePayment);
        }else {
//            续课的订单
//            查询是否续课优惠
 
            CoursePackagePaymentConfig paymentConfig = cpConfigMapper.selectOne(new QueryWrapper<CoursePackagePaymentConfig>()
                    .eq("coursePackageId", request.getLessonId())
                    .eq("classHours", request.getCourseHoursNum()));
            TCoursePackageDiscount coursePackageDiscount = tcpdMapper.selectOne(new QueryWrapper<TCoursePackageDiscount>()
                    .eq("coursePackageId", request.getLessonId())
                    .eq("type", 2)
                    .eq("auditStatus", 1)
                    .eq("coursePackagePaymentConfigId", paymentConfig.getCoursePackageId()));
            if (ToolUtil.isNotEmpty(coursePackageDiscount)){
                String content = coursePackageDiscount.getContent();
                JSONObject jsonObject = JSON.parseObject(content);
                if (userIdFormRedis.getIsVip() == 1){
                    Double jsonObjectDouble = jsonObject.getDouble("num1");
                    money = BigDecimal.valueOf(jsonObjectDouble);
                }else {
                    Double jsonObjectDouble = jsonObject.getDouble("num2");
                    money = BigDecimal.valueOf(jsonObjectDouble);
                }
            }
            TCoursePackagePayment newPayment = new TCoursePackagePayment();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
            newPayment.setCode(sdf.format(new Date()) + UUIDUtil.getNumberRandom(5));
            newPayment.setAppUserId(userIdFormRedis.getId());
            newPayment.setStudentId(request.getStuId());
            newPayment.setCoursePackageId(request.getLessonId());
            newPayment.setClassHours(tCoursePackagePayment.getClassHours());
            newPayment.setOriginalPrice(tCoursePackagePayment.getOriginalPrice());
            newPayment.setTotalClassHours(tCoursePackagePayment.getTotalClassHours());
            newPayment.setLaveClassHours(tCoursePackagePayment.getTotalClassHours());
            if (request.getUseConpon() == 1){
                newPayment.setUserCouponId(Long.valueOf(request.getUseConpon()));
            }
            newPayment.setAbsencesNumber(0);
            newPayment.setPayUserType(1);
            newPayment.setPayStatus(1);
            newPayment.setStatus(1);
            newPayment.setPayType(request.getPayType());
            newPayment.setState(1);
            newPayment.setInsertTime(new Date());
            this.baseMapper.insert(newPayment);
            code = newPayment.getCode();
        }
        switch (request.getPayType()){
            case 1:
                if (request.getUseConpon() == 1){
                    Coupon coupon = client.queryCouponById(request.getConponId());
                    if (coupon.getType() == 1){
                        Map<String, Object> couponRules = client.getCouponRules(coupon.getId());
                        Double conditionalAmount = (Double) couponRules.get("conditionalAmount");
                        Double deductionAmount = (Double) couponRules.get("deductionAmount");
                        if (money.compareTo(BigDecimal.valueOf(conditionalAmount)) >= 0){
                            money = BigDecimal.valueOf(deductionAmount);
                        }
                    }
                    if (coupon.getType() == 2){
                        Map<String, Object> couponRules = client.getCouponRules(coupon.getId());
                        Object amount = couponRules.get("deductionAmount");
                        money = BigDecimal.valueOf((Double) amount);
                    }
                }
                try {
                    return WeChatPayment(code,money);
                }catch (Exception e){
                    return ResultUtil.runErr();
                }
            case 2:
                if (request.getUseConpon() == 1){
                    Coupon coupon = client.queryCouponById(request.getConponId());
                    if (coupon.getType() == 1){
                        Map<String, Object> couponRules = client.getCouponRules(coupon.getId());
                        Double conditionalAmount = (Double) couponRules.get("conditionalAmount");
                        Double deductionAmount = (Double) couponRules.get("deductionAmount");
                        if (money.compareTo(BigDecimal.valueOf(conditionalAmount)) >= 0){
                            money = BigDecimal.valueOf(deductionAmount);
                        }
                    }
                    if (coupon.getType() == 2){
                        Map<String, Object> couponRules = client.getCouponRules(coupon.getId());
                        Object amount = couponRules.get("deductionAmount");
                        money = BigDecimal.valueOf((Double) amount);
                    }
                }
                return AlipayPayment(code,money);
            case 3:
                PlaypaiGoldPayment(userIdFormRedis,code,wpGold);
                break;
            default:
                break;
        }
        return ResultUtil.success();
    }
 
 
    public ResultUtil WeChatPayment(String code, BigDecimal request) throws Exception {
        TCoursePackagePaymentMapper baseMapper1 = this.baseMapper;
        ResultUtil weixinpay = payMoneyUtil.weixinpay("课包续费", "", code, request.toString(),
                "/base/coursePackage/wechatRegisteredCoursesCallback", "APP", "");
        if(weixinpay.getCode() == 200){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        int num = 1;
                        int wait = 0;
                        while (num <= 10){
                            int min = 5000;
                            wait += (min * num);
                            Thread.sleep(wait);
                            TCoursePackagePayment coursePackagePayment = baseMapper1.getCoursePackagePaymentByCode(code);
                            if(coursePackagePayment.getPayStatus() == 2){
                                break;
                            }
                            ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(code, "");
                            if(resultUtil.getCode() == 200 && coursePackagePayment.getPayStatus() == 1){
                                /**
                                 * SUCCESS—支付成功,
                                 * REFUND—转入退款,
                                 * NOTPAY—未支付,
                                 * CLOSED—已关闭,
                                 * REVOKED—已撤销(刷卡支付),
                                 * USERPAYING--用户支付中,
                                 * PAYERROR--支付失败(其他原因,如银行返回失败)
                                 */
                                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);
                                    baseMapper1.deleteById(coursePackagePayment.getId());
                                    break;
                                }
                                if("SUCCESS".equals(s)){
                                    coursePackagePayment.setPayStatus(2);
                                    coursePackagePayment.setOrderNumber(transaction_id);
                                    baseMapper1.updateById(coursePackagePayment);
                                    break;
                                }
                                if("USERPAYING".equals(s)){
                                    num++;
                                }
                            }
                        }
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
            }).start();
        }
        return weixinpay;
    }
 
 
 
    public ResultUtil AlipayPayment(String code, BigDecimal request){
        TCoursePackagePaymentMapper baseMapper1 = this.baseMapper;
        ResultUtil alipay = payMoneyUtil.alipay("课包购买", "", "", code, request.toString(),
                "/base/coursePackage/alipayRegisteredCoursesCallback");
        if(alipay.getCode() == 200){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        int num = 1;
                        int wait = 0;
                        while (num <= 10){
                            int min = 5000;
                            wait += (min * num);
                            Thread.sleep(wait);
                            TCoursePackagePayment coursePackagePayment = baseMapper1.getCoursePackagePaymentByCode(code);
                            if(coursePackagePayment.getPayStatus() == 2){
                                break;
                            }
                            ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryALIOrder(code);
                            if(resultUtil.getCode() == 200 && coursePackagePayment.getPayStatus() == 1){
                                /**
                                 * WAIT_BUYER_PAY(交易创建,等待买家付款)、
                                 * TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、
                                 * TRADE_SUCCESS(交易支付成功)、
                                 * TRADE_FINISHED(交易结束,不可退款)
                                 */
                                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);
                                    baseMapper1.deleteById(coursePackagePayment.getId());
                                    break;
                                }
                                if("TRADE_SUCCESS".equals(s)){
                                    coursePackagePayment.setPayStatus(2);
                                    coursePackagePayment.setOrderNumber(tradeNo);
                                    baseMapper1.updateById(coursePackagePayment);
                                    break;
                                }
                                if("WAIT_BUYER_PAY".equals(s)){
                                    num++;
                                }
                            }
                        }
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
            }).start();
        }
        return alipay;
    }
 
    public ResultUtil PlaypaiGoldPayment(AppUser appUser,String code, Integer wpGold){
        TCoursePackagePayment packagePayment = this.baseMapper.selectOne(new QueryWrapper<TCoursePackagePayment>()
                .eq("code",code ));
        if (appUser.getPlayPaiCoins() < wpGold){
            return ResultUtil.error("玩牌币不足!");
        }
        packagePayment.setPayStatus(2);
        packagePayment.setPayUserId(appUser.getId());
        packagePayment.setPlayPaiCoin(wpGold);
        this.baseMapper.updateById(packagePayment);
 
        appUser.setPlayPaiCoins(ToolUtil.isNotEmpty(appUser.getPlayPaiCoins()) ? appUser.getPlayPaiCoins()-wpGold : wpGold);
        appuClient.updateAppUser(appUser);
        return ResultUtil.success();
    }
 
 
    @Override
    public List<RecordAppoint> obtainStuClassDetails(Integer stuId, Integer appUserId) {
        List<RecordAppoint> recordVoList = new ArrayList<>();
        List<TCoursePackagePayment> tCoursePackagePayments = this.baseMapper.selectList(new QueryWrapper<TCoursePackagePayment>()
                .eq("studentId",stuId )
                .eq("appUserId",appUserId )
                .eq("payStatus",2 )
                .eq("status",1 )
                .orderByDesc("insertTime"));
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd");
        SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
        if (tCoursePackagePayments.size() > 0 ){
            for (TCoursePackagePayment tCoursePackagePayment : tCoursePackagePayments) {
                RecordAppoint recordVo = new RecordAppoint();
                recordVo.setCoursePackageId(tCoursePackagePayment.getCoursePackageId());
 
                TCoursePackage coursePackage = tcpmapper.selectById(tCoursePackagePayment.getCoursePackageId());
 
                recordVo.setCoursePackageName(coursePackage.getName());
                recordVo.setCourseHours(tCoursePackagePayment.getClassHours());
                Date date = DateUtil.getDate();
 
                String classStartTime = coursePackage.getClassStartTime();
                String classEndTime = coursePackage.getClassEndTime();
                recordVo.setTimeFrame(simpleDateFormat.format(date)+" "+classStartTime+"-"+classEndTime);
                Store store = stoClient.queryStoreById(coursePackage.getStoreId());
                recordVo.setStoreNameAddr(store.getName()+store.getAddress());
                CoursePackageStudent coursePackageStudent = cpsMapper.selectOne(new QueryWrapper<CoursePackageStudent>()
                        .eq("coursePackageId",tCoursePackagePayment.getCoursePackageId() )
                        .eq("studentId",stuId)
                        .eq("appUserId",appUserId)
                        .eq("reservationStatus",1));
                if (ToolUtil.isNotEmpty(coursePackageStudent) && coursePackageStudent.getReservationStatus() == 1){
 
                    recordVo.setCourseStuRecordId(coursePackageStudent.getId());
                    String classWeeks = coursePackage.getClassWeeks();
                    String[] split = classWeeks.split(";");
                    List<Integer> integerList = Arrays.stream(split)
                            .map(Integer::parseInt)
                            .collect(Collectors.toList());
                    int dayOfWeek = DateTimeHelper.getDayOfWeek(new Date());
 
                    if (integerList.contains(dayOfWeek)){
                        String dat = simpleDateFormat.format(date) +" "+ classStartTime;
 
                        Date start = null;
                        try {
                            start = format.parse(dat);
                        } catch (ParseException e) {
                            throw new RuntimeException(e);
                        }
                        if (start.after(new Date())){
                            recordVo.setStatus(1);
                        }else {
                            CancelledClasses cancelledClasses = cacMapper.selectOne(new QueryWrapper<CancelledClasses>()
                                    .eq("coursePackageId",tCoursePackagePayment.getCoursePackageId() ));
                            if (ToolUtil.isNotEmpty(cancelledClasses)){
                                recordVo.setStatus(3);
                            }else {
                                recordVo.setStatus(2);
                            }
                        }
                    }else {
                        recordVo.setStatus(1);
                    }
                }else {
                    recordVo.setStatus(4);
                }
 
                recordVoList.add(recordVo);
            }
        }
        return recordVoList;
    }
 
    @Override
    public ResultUtil insertVipPaymentCallback(String code, String orderNumber) {
        TCoursePackagePayment coursePackagePayment = this.baseMapper.getCoursePackagePaymentByCode(code);
        if(coursePackagePayment.getPayStatus() != 1){
            return ResultUtil.success();
        }
        coursePackagePayment.setPayStatus(2);
        coursePackagePayment.setOrderNumber(orderNumber);
        this.baseMapper.updateById(coursePackagePayment);
        return ResultUtil.success();
    }
 
 
}