puzhibing
2023-07-06 ac6a07af9baba0e0fc8d181aae904da679ae8f5a
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
package com.dsh.course.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsh.course.entity.CoursePackagePaymentConfig;
import com.dsh.course.entity.TCoursePackage;
import com.dsh.course.entity.TCoursePackageDiscount;
import com.dsh.course.entity.TCoursePackagePayment;
import com.dsh.course.feignclient.account.AppUserClient;
import com.dsh.course.feignclient.account.StudentClient;
import com.dsh.course.feignclient.account.model.AppUser;
import com.dsh.course.feignclient.account.model.Student;
import com.dsh.course.feignclient.activity.CouponClient;
import com.dsh.course.feignclient.activity.UserCouponClient;
import com.dsh.course.feignclient.activity.model.Coupon;
import com.dsh.course.feignclient.activity.model.UserCoupon;
import com.dsh.course.feignclient.other.StoreClient;
import com.dsh.course.feignclient.other.model.Store;
import com.dsh.course.mapper.TCoursePackageMapper;
import com.dsh.course.feignclient.model.CourseOfStoreVo;
import com.dsh.course.model.*;
import com.dsh.course.service.ICoursePackagePaymentConfigService;
import com.dsh.course.service.TCoursePackageDiscountService;
import com.dsh.course.service.TCoursePackagePaymentService;
import com.dsh.course.service.TCoursePackageService;
import com.dsh.course.util.GDMapGeocodingUtil;
import com.dsh.course.util.GeodesyUtil;
import com.dsh.course.util.ResultUtil;
import com.dsh.course.util.ToolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 课包 服务实现类
 * </p>
 *
 * @author administrator
 * @since 2023-06-14
 */
@Service
public class TCoursePackageServiceImpl extends ServiceImpl<TCoursePackageMapper, TCoursePackage> implements TCoursePackageService {
 
    @Resource
    private StoreClient storeClient;
 
    @Autowired
    private GDMapGeocodingUtil gdMapGeocodingUtil;
 
    @Autowired
    private TCoursePackagePaymentService coursePackagePaymentService;
 
    @Autowired
    private ICoursePackagePaymentConfigService coursePackagePaymentConfigService;
 
    @Autowired
    private TCoursePackageDiscountService coursePackageDiscountService;
 
    @Resource
    private AppUserClient appUserClient;
 
    @Resource
    private StudentClient studentClient;
 
    @Resource
    private UserCouponClient userCouponClient;
 
    @Resource
    private CouponClient couponClient;
 
 
 
 
    @Override
    public List<CourseOfStoreVo> queryStoreOfCourse() {
        return this.baseMapper.queryStoreOfCourse();
    }
 
 
    /**
     * 获取课程列表
     * @param coursePackageList
     * @return
     * @throws Exception
     */
    @Override
    public List<CoursePackageListVo> queryCourseList(Integer uid, CoursePackageList coursePackageList) throws Exception {
        AppUser appUser = appUserClient.queryAppUser(uid);
        Map<String, String> geocode = gdMapGeocodingUtil.geocode(coursePackageList.getLon(), coursePackageList.getLat());
        String provinceCode = geocode.get("provinceCode");
        String cityCode = geocode.get("cityCode");
        QueryWrapper<TCoursePackage> wrapper = new QueryWrapper<TCoursePackage>().in("status", Arrays.asList(1, 2))
                .eq("auditStatus", 2).eq("state", 1).eq("provinceCode", provinceCode).eq("cityCode", cityCode);
        if(null != coursePackageList.getCoursePackageTypeId()){
            wrapper.eq("coursePackageTypeId", coursePackageList.getCoursePackageTypeId());
        }
        if(null != coursePackageList.getStoreId()){
            wrapper.eq("storeId", coursePackageList.getStoreId());
        }
        if(null != coursePackageList.getStoreId()){
            wrapper.eq("storeId", coursePackageList.getStoreId());
        }
        if(ToolUtil.isNotEmpty(coursePackageList.getSearch())){
            wrapper.like("name", coursePackageList.getSearch());
            List<Store> stores = storeClient.queryStoreListByName(coursePackageList.getSearch());
            List<Integer> collect = stores.stream().map(Store::getId).collect(Collectors.toList());
            if(collect.size() > 0){
                wrapper.or().in("id", collect);
            }
        }
        List<TCoursePackage> list = this.list(wrapper.last(" order by sort, insertTime desc"));
        List<CoursePackageListVo> listVos = new ArrayList<>();
        for (TCoursePackage coursePackage : list) {
            Store store = storeClient.queryStoreById(coursePackage.getStoreId());
            Integer integer = coursePackagePaymentService.queryCountNumber(coursePackage.getId());
            CoursePackagePaymentConfig coursePackagePaymentConfig = coursePackagePaymentConfigService.getOne(new QueryWrapper<CoursePackagePaymentConfig>()
                    .eq("coursePackageId", coursePackage.getId()).orderByAsc("classHours limit 0, 1"));
            CoursePackageListVo coursePackageListVo = new CoursePackageListVo();
            coursePackageListVo.setId(coursePackage.getId());
            coursePackageListVo.setName(coursePackage.getName());
            coursePackageListVo.setStoreName(null != store ? store.getName() : "");
            coursePackageListVo.setCoverDrawing(coursePackage.getCoverDrawing());
            coursePackageListVo.setClassStartTime(coursePackage.getClassStartTime() + "-" + coursePackage.getClassEndTime());
            coursePackageListVo.setApplicantsNumber(integer);
            coursePackageListVo.setPayType(coursePackage.getPayType());
            coursePackageListVo.setPlayPaiCoin(coursePackageListVo.getPlayPaiCoin());
 
            //会员显示原价和会员价(最低)。非会员显示会员价和支付价(最低)
            if(appUser.getIsVip() == 0){//非会员
                List<TCoursePackageDiscount> list2 = coursePackageDiscountService.list(new QueryWrapper<TCoursePackageDiscount>().eq("coursePackagePaymentConfigId", coursePackagePaymentConfig.getId())
                        .eq("type", 1).eq("auditStatus", 2));
                Double vipPrice = coursePackagePaymentConfig.getCashPayment();
                for (TCoursePackageDiscount coursePackageDiscount : list2) {
                    Double num1 = JSON.parseObject(coursePackageDiscount.getContent()).getDouble("num1");
                    if(vipPrice.compareTo(num1) > 0){
                        vipPrice = num1;
                    }
                }
                coursePackageListVo.setVipPrice(vipPrice);
 
                Double paymentPrice = coursePackagePaymentConfig.getCashPayment();
                List<TCoursePackageDiscount> list3 = coursePackageDiscountService.list(new QueryWrapper<TCoursePackageDiscount>().eq("coursePackagePaymentConfigId", coursePackagePaymentConfig.getId())
                        .eq("type", 3).eq("auditStatus", 2));
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                for (TCoursePackageDiscount coursePackageDiscount : list3) {
                    /**
                     * [{
                     *     "startDate": "2023-01-01 00:00:00",
                     *     "endDate": "2023-12-31 23:59:59",
                     *     "startTime": "02:00:00",
                     *     "endTime": "23:00:00",
                     *     "weeks": [1, 2, 7],
                     *     "cashPayment": 100
                     * }]
                     */
                    JSONArray jsonArray = JSON.parseArray(coursePackageDiscount.getContent());
                    for (int i = 0; i < jsonArray.size(); i++) {
                        try {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            String startDate = jsonObject.getString("startDate");
                            String endDate = jsonObject.getString("endDate");
                            String startTime = jsonObject.getString("startTime");
                            String endTime = jsonObject.getString("endTime");
                            List<Integer> weeks = jsonObject.getJSONArray("weeks").toJavaList(Integer.class);
                            Double cashPayment = jsonObject.getDouble("cashPayment");
                            Date startDate_date = sdf.parse(startDate);
                            Date endDate_date = sdf.parse(endDate);
                            long timeMillis = System.currentTimeMillis();
                            if(timeMillis >= startDate_date.getTime() && timeMillis < endDate_date.getTime()){
                                Date date = new Date();
                                Calendar calendar = Calendar.getInstance();
                                calendar.setTime(date);
                                int week = calendar.get(Calendar.DAY_OF_WEEK);
                                boolean isFirstSunday = (calendar.getFirstDayOfWeek() == Calendar.SUNDAY);
                                if(isFirstSunday){
                                    week = week - 1;
                                    if(week == 0){
                                        week = 7;
                                    }
                                }
                                if(!weeks.contains(week)){
                                    continue;
                                }
 
                                String[] split1 = startTime.split(":");
                                Integer hour1 = Integer.valueOf(split1[0]);
                                Calendar s = Calendar.getInstance();
                                s.setTime(date);
                                s.set(Calendar.HOUR_OF_DAY, hour1);
                                s.set(Calendar.MINUTE, Integer.valueOf(split1[1]));
                                s.set(Calendar.SECOND, Integer.valueOf(split1[2]));
 
                                String[] split2 = endTime.split(":");
                                Integer hour2 = Integer.valueOf(split2[0]);
                                Calendar e = Calendar.getInstance();
                                e.setTime(date);
                                e.set(Calendar.HOUR_OF_DAY, hour2);
                                e.set(Calendar.MINUTE, Integer.valueOf(split2[1]));
                                e.set(Calendar.SECOND, Integer.valueOf(split2[2]));
 
                                if(hour1 > hour2){
                                    if(s.getTimeInMillis() > date.getTime()){
                                        s.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) - 1);
                                    }else{
                                        e.set(Calendar.DAY_OF_YEAR, e.get(Calendar.DAY_OF_YEAR) + 1);
                                    }
                                }
                                if(timeMillis >= s.getTimeInMillis() && timeMillis < e.getTimeInMillis() && paymentPrice.compareTo(cashPayment) > 0){
                                    paymentPrice = cashPayment;
                                }
                            }
                        }catch (Exception e){
                            e.printStackTrace();
                        }
                    }
                }
                coursePackageListVo.setPaymentPrice(paymentPrice);
            }else{
                List<TCoursePackageDiscount> list2 = coursePackageDiscountService.list(new QueryWrapper<TCoursePackageDiscount>().eq("coursePackagePaymentConfigId", coursePackagePaymentConfig.getId())
                        .eq("type", 1).eq("auditStatus", 2));
                Double vipPrice = coursePackagePaymentConfig.getCashPayment();
                for (TCoursePackageDiscount coursePackageDiscount : list2) {
                    Double num1 = JSON.parseObject(coursePackageDiscount.getContent()).getDouble("num1");
                    if(vipPrice.compareTo(num1) > 0){
                        vipPrice = num1;
                    }
                }
                coursePackageListVo.setPaymentPrice(vipPrice);
                coursePackageListVo.setOriginalPrice(coursePackagePaymentConfig.getCashPayment());
            }
 
            Map<String, Double> distance = GeodesyUtil.getDistance(coursePackageList.getLon() + "," + coursePackageList.getLat(), store.getLon() + "," + store.getLat());
            coursePackageListVo.setDistance(distance.get("WGS84") / 1000);
            listVos.add(coursePackageListVo);
        }
 
        //销量排行
        if(ToolUtil.isNotEmpty(coursePackageList.getSalesRanking())){
            Collections.sort(listVos, new Comparator<CoursePackageListVo>() {
                public int compare(CoursePackageListVo s1, CoursePackageListVo s2) {
                    return Integer.compare(s1.getApplicantsNumber(), s2.getApplicantsNumber());
                }
            });
        }
        //距离排行
        if(ToolUtil.isNotEmpty(coursePackageList.getDistanceSort())){
            Collections.sort(listVos, new Comparator<CoursePackageListVo>() {
                public int compare(CoursePackageListVo s1, CoursePackageListVo s2) {
                    return Double.compare(s1.getDistance(), s2.getDistance());
                }
            });
        }
        return listVos;
    }
 
 
    /**
     * 获取课包详情
     * @param uid
     * @param id
     * @return
     * @throws Exception
     */
    @Override
    public CoursePackageInfo queryCourseInfo(Integer uid, Integer id, String lon, String lat) throws Exception {
        AppUser appUser = appUserClient.queryAppUser(uid);
        TCoursePackage coursePackage = this.getById(id);
        CoursePackageInfo coursePackageInfo = new CoursePackageInfo();
        coursePackageInfo.setId(id);
        coursePackageInfo.setCoverDrawing(coursePackage.getCoverDrawing());
        coursePackageInfo.setName(coursePackage.getName());
        Store store = storeClient.queryStoreById(coursePackage.getStoreId());
        coursePackageInfo.setStoreName(store.getName());
        coursePackageInfo.setStoreCoverDrawing(store.getCoverDrawing());
        coursePackageInfo.setStoreAddress(store.getAddress());
        coursePackageInfo.setLon(store.getLon());
        coursePackageInfo.setLat(store.getLat());
        if(ToolUtil.isNotEmpty(lon) && ToolUtil.isNotEmpty(lat)){
            Map<String, Double> distance = GeodesyUtil.getDistance(lon + "," + lat, store.getLon() + "," + store.getLat());
            double wgs84 = new BigDecimal(distance.get("WGS84")).divide(new BigDecimal(1000)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
            coursePackageInfo.setDistance(wgs84);
        }
 
        String[] split = coursePackage.getClassWeeks().split(";");
        coursePackageInfo.setWeeks(Arrays.asList(split));
        coursePackageInfo.setTimes(coursePackage.getClassStartTime() + "-" + coursePackage.getClassEndTime());
        coursePackageInfo.setDetailDrawing(coursePackage.getDetailDrawing());
        coursePackageInfo.setIntroduceDrawing(coursePackage.getIntroduceDrawing());
        List<CoursePackagePaymentConfigVo> list = new ArrayList<>();
        List<CoursePackagePaymentConfig> list1 = coursePackagePaymentConfigService.list(new QueryWrapper<CoursePackagePaymentConfig>().eq("coursePackageId", id).orderByAsc("classHours"));
        list1.forEach(coursePackagePaymentConfig -> {
            CoursePackagePaymentConfigVo coursePackagePaymentConfigVo = new CoursePackagePaymentConfigVo();
            coursePackagePaymentConfigVo.setId(coursePackagePaymentConfig.getId());
            coursePackagePaymentConfigVo.setClassHours(coursePackagePaymentConfig.getClassHours());
            coursePackagePaymentConfigVo.setPayType(coursePackage.getPayType());
            coursePackagePaymentConfigVo.setPlayPaiCoin(coursePackagePaymentConfig.getPlayPaiCoin());
            //会员显示原价和支付价(会员价)。非会员显示会员价和支付价(最低)
            if(appUser.getIsVip() == 0){//非会员
                List<TCoursePackageDiscount> list2 = coursePackageDiscountService.list(new QueryWrapper<TCoursePackageDiscount>().eq("coursePackagePaymentConfigId", coursePackagePaymentConfig.getId())
                        .eq("type", 1).eq("auditStatus", 2));
                Double vipPrice = coursePackagePaymentConfig.getCashPayment();
                for (TCoursePackageDiscount coursePackageDiscount : list2) {
                    Double num1 = JSON.parseObject(coursePackageDiscount.getContent()).getDouble("num1");
                    if(vipPrice.compareTo(num1) > 0){
                        vipPrice = num1;
                    }
                }
                coursePackagePaymentConfigVo.setVipPrice(vipPrice);
 
                Double paymentPrice = coursePackagePaymentConfig.getCashPayment();
                List<TCoursePackageDiscount> list3 = coursePackageDiscountService.list(new QueryWrapper<TCoursePackageDiscount>().eq("coursePackagePaymentConfigId", coursePackagePaymentConfig.getId())
                        .eq("type", 3).eq("auditStatus", 2));
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                for (TCoursePackageDiscount coursePackageDiscount : list3) {
                    /**
                     * [{
                     *     "startDate": "2023-01-01 00:00:00",
                     *     "endDate": "2023-12-31 23:59:59",
                     *     "startTime": "02:00:00",
                     *     "endTime": "23:00:00",
                     *     "weeks": [1, 2, 7],
                     *     "cashPayment": 100
                     * }]
                     */
                    JSONArray jsonArray = JSON.parseArray(coursePackageDiscount.getContent());
                    for (int i = 0; i < jsonArray.size(); i++) {
                        try {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            String startDate = jsonObject.getString("startDate");
                            String endDate = jsonObject.getString("endDate");
                            String startTime = jsonObject.getString("startTime");
                            String endTime = jsonObject.getString("endTime");
                            List<Integer> weeks = jsonObject.getJSONArray("weeks").toJavaList(Integer.class);
                            Double cashPayment = jsonObject.getDouble("cashPayment");
                            Date startDate_date = sdf.parse(startDate);
                            Date endDate_date = sdf.parse(endDate);
                            long timeMillis = System.currentTimeMillis();
                            if(timeMillis >= startDate_date.getTime() && timeMillis < endDate_date.getTime()){
                                Date date = new Date();
                                Calendar calendar = Calendar.getInstance();
                                calendar.setTime(date);
                                int week = calendar.get(Calendar.DAY_OF_WEEK);
                                boolean isFirstSunday = (calendar.getFirstDayOfWeek() == Calendar.SUNDAY);
                                if(isFirstSunday){
                                    week = week - 1;
                                    if(week == 0){
                                        week = 7;
                                    }
                                }
                                if(!weeks.contains(week)){
                                    continue;
                                }
 
                                String[] split1 = startTime.split(":");
                                Integer hour1 = Integer.valueOf(split1[0]);
                                Calendar s = Calendar.getInstance();
                                s.setTime(date);
                                s.set(Calendar.HOUR_OF_DAY, hour1);
                                s.set(Calendar.MINUTE, Integer.valueOf(split1[1]));
                                s.set(Calendar.SECOND, Integer.valueOf(split1[2]));
 
                                String[] split2 = endTime.split(":");
                                Integer hour2 = Integer.valueOf(split2[0]);
                                Calendar e = Calendar.getInstance();
                                e.setTime(date);
                                e.set(Calendar.HOUR_OF_DAY, hour2);
                                e.set(Calendar.MINUTE, Integer.valueOf(split2[1]));
                                e.set(Calendar.SECOND, Integer.valueOf(split2[2]));
 
                                if(hour1 > hour2){
                                    if(s.getTimeInMillis() > date.getTime()){
                                        s.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) - 1);
                                    }else{
                                        e.set(Calendar.DAY_OF_YEAR, e.get(Calendar.DAY_OF_YEAR) + 1);
                                    }
                                }
                                if(timeMillis >= s.getTimeInMillis() && timeMillis < e.getTimeInMillis() && paymentPrice.compareTo(cashPayment) > 0){
                                    paymentPrice = cashPayment;
                                }
                            }
                        }catch (Exception e){
                            e.printStackTrace();
                        }
                    }
                }
                coursePackagePaymentConfigVo.setPaymentPrice(paymentPrice);
            }else{
                List<TCoursePackageDiscount> list2 = coursePackageDiscountService.list(new QueryWrapper<TCoursePackageDiscount>().eq("coursePackagePaymentConfigId", coursePackagePaymentConfig.getId())
                        .eq("type", 1).eq("auditStatus", 2));
                Double vipPrice = coursePackagePaymentConfig.getCashPayment();
                for (TCoursePackageDiscount coursePackageDiscount : list2) {
                    Double num1 = JSON.parseObject(coursePackageDiscount.getContent()).getDouble("num1");
                    if(vipPrice.compareTo(num1) > 0){
                        vipPrice = num1;
                    }
                }
                coursePackagePaymentConfigVo.setPaymentPrice(vipPrice);
                coursePackagePaymentConfigVo.setOriginalPrice(coursePackagePaymentConfig.getCashPayment());
            }
            list.add(coursePackagePaymentConfigVo);
        });
        coursePackageInfo.setList(list);
 
        Student student = studentClient.queryDefaultStudent(uid);
        StudentVo studentVo = new StudentVo();
        studentVo.setId(student.getId());
        studentVo.setPhone(student.getPhone());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        studentVo.setAge(Integer.valueOf(sdf.format(new Date())) - Integer.valueOf(sdf.format(student.getBirthday())));
        coursePackageInfo.setStudent(studentVo);
        return coursePackageInfo;
    }
 
 
    /**
     * 课程包名支付
     * @param uid
     * @param paymentCourseVo
     * @return
     * @throws Exception
     */
    @Override
    public ResultUtil paymentCourse(Integer uid, PaymentCourseVo paymentCourseVo) throws Exception {
        AppUser appUser = appUserClient.queryAppUser(uid);
        CoursePackageInfo coursePackageInfo = queryCourseInfo(uid, paymentCourseVo.getId(), null, null);
        List<CoursePackagePaymentConfigVo> list = coursePackageInfo.getList();
 
        String[] students = paymentCourseVo.getStudentIds().split(";");
        for (CoursePackagePaymentConfigVo coursePackagePaymentConfigVo : list) {
            if(paymentCourseVo.getCoursePackagePaymentConfigId().compareTo(coursePackagePaymentConfigVo.getId()) == 0){
                Integer payType = coursePackagePaymentConfigVo.getPayType();
                if(payType == 1 && paymentCourseVo.getPayType() == 3){//现金支付
                    return ResultUtil.error("支付方式错误,请刷新后重试");
                }
                if(payType == 2 && paymentCourseVo.getPayType() != 3){//玩湃币支付
                    return ResultUtil.error("支付方式错误,请刷新后重试");
                }
                Double paymentPrice = coursePackagePaymentConfigVo.getPaymentPrice();//支付价
                paymentPrice = new BigDecimal(students.length).multiply(new BigDecimal(paymentPrice)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
                Double playPaiCoin = coursePackagePaymentConfigVo.getPlayPaiCoin().doubleValue();//支付币
                playPaiCoin = new BigDecimal(students.length).multiply(new BigDecimal(playPaiCoin)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
                if(payType == 1 && paymentPrice.compareTo(paymentCourseVo.getPrice()) != 0){
                    return ResultUtil.error("支付金额异常,请刷新后重试");
                }
                if(payType == 2 && playPaiCoin.compareTo(paymentCourseVo.getPrice()) != 0){
                    return ResultUtil.error("支付金额异常,请刷新后重试");
                }
            }
        }
 
        Double price = paymentCourseVo.getPrice();//支付金额
 
        //校验优惠券
        Long couponId = paymentCourseVo.getCouponId();
        if(null != couponId && paymentCourseVo.getPayType() != 3){
            UserCoupon userCoupon = userCouponClient.queryUserCouponById(couponId);
            if(userCoupon.getStatus() == 2){
                return ResultUtil.error("优惠券已被核销");
            }
            Coupon coupon = couponClient.queryCouponById(userCoupon.getCouponId());
            long time = coupon.getEndTime().getTime();
            if(System.currentTimeMillis() >= time){
                return ResultUtil.error("优惠券已过期");
            }
            if(coupon.getType() == 1){//满减
                JSONObject jsonObject = JSON.parseObject(coupon.getContent());
                Double num1 = jsonObject.getDouble("num1");
                Double num2 = jsonObject.getDouble("num2");
                if(price.compareTo(num1) <= 0){
                    return ResultUtil.error("该优惠券无法使用");
                }
 
                price = new BigDecimal(price).subtract(new BigDecimal(num2)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
            }
            if(coupon.getType() == 2){//代金券
                JSONObject jsonObject = JSON.parseObject(coupon.getContent());
                Double num1 = jsonObject.getDouble("num1");
                if(price.compareTo(num1) <= 0){
                    return ResultUtil.error("该优惠券无法使用");
                }
                price = new BigDecimal(price).subtract(new BigDecimal(num1)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
            }
        }
 
        if(paymentCourseVo.getPayType() == 1){//微信支付
 
        }
        if(paymentCourseVo.getPayType() == 2){//支付宝支付
 
        }
        if(paymentCourseVo.getPayType() == 3){//玩湃币支付
 
        }
        return null;
    }
 
 
    public ResultUtil weChatPaymentCourse(Integer uid, PaymentCourseVo paymentCourseVo){
        TCoursePackagePayment coursePackagePayment = new TCoursePackagePayment();
//        coursePackagePayment
        return ResultUtil.success();
    }
}