From c678894e37d15cca116d962eba5c107c99176945 Mon Sep 17 00:00:00 2001
From: lisy <linlangsur163@163.com>
Date: 星期四, 20 七月 2023 17:39:05 +0800
Subject: [PATCH] 开始上课的主页中课包列表展示;bmi工具类匹配对应的身体状态

---
 cloud-server-course/src/main/java/com/dsh/course/service/impl/TCoursePackageServiceImpl.java |  266 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 250 insertions(+), 16 deletions(-)

diff --git a/cloud-server-course/src/main/java/com/dsh/course/service/impl/TCoursePackageServiceImpl.java b/cloud-server-course/src/main/java/com/dsh/course/service/impl/TCoursePackageServiceImpl.java
index 356f640..471e3e0 100644
--- a/cloud-server-course/src/main/java/com/dsh/course/service/impl/TCoursePackageServiceImpl.java
+++ b/cloud-server-course/src/main/java/com/dsh/course/service/impl/TCoursePackageServiceImpl.java
@@ -3,6 +3,7 @@
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.nacos.common.utils.UuidUtils;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.dsh.course.entity.CoursePackagePaymentConfig;
@@ -26,10 +27,8 @@
 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 com.dsh.course.util.*;
+import com.dsh.course.util.httpClinet.HttpResult;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -78,6 +77,9 @@
     @Resource
     private CouponClient couponClient;
 
+    @Autowired
+    private PayMoneyUtil payMoneyUtil;
+
 
 
 
@@ -124,7 +126,7 @@
             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"));
+                    .eq("coursePackageId", coursePackage.getId()).orderByAsc("classHours").last(" limit 0, 1"));
             CoursePackageListVo coursePackageListVo = new CoursePackageListVo();
             coursePackageListVo.setId(coursePackage.getId());
             coursePackageListVo.setName(coursePackage.getName());
@@ -413,10 +415,13 @@
 
         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())));
+        if(null != student){
+            studentVo.setId(student.getId());
+            studentVo.setPhone(student.getPhone());
+            studentVo.setName(student.getName());
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
+            studentVo.setAge(Integer.valueOf(sdf.format(new Date())) - Integer.valueOf(sdf.format(student.getBirthday())));
+        }
         coursePackageInfo.setStudent(studentVo);
         return coursePackageInfo;
     }
@@ -493,21 +498,250 @@
         }
 
         if(paymentCourseVo.getPayType() == 1){//微信支付
-
+            return weChatPaymentCourse(uid, price, paymentCourseVo);
         }
         if(paymentCourseVo.getPayType() == 2){//支付宝支付
-
+            return aliPaymentCourse(uid, price, paymentCourseVo);
         }
         if(paymentCourseVo.getPayType() == 3){//玩湃币支付
-
+            if(appUser.getPlayPaiCoins() < price.intValue()){
+                return ResultUtil.error("报名失败,玩湃币不足,请充值!");
+            }
+            return playPaiCoinPaymentCourse(appUser, price, paymentCourseVo);
         }
-        return null;
+        return ResultUtil.success();
     }
 
 
-    public ResultUtil weChatPaymentCourse(Integer uid, PaymentCourseVo paymentCourseVo){
-        TCoursePackagePayment coursePackagePayment = new TCoursePackagePayment();
-//        coursePackagePayment
+    /**
+     * 课程微信支付
+     * @param uid
+     * @param paymentPrice
+     * @param paymentCourseVo
+     * @return
+     * @throws Exception
+     */
+    public ResultUtil weChatPaymentCourse(Integer uid, Double paymentPrice, PaymentCourseVo paymentCourseVo) throws Exception{
+        CoursePackagePaymentConfig coursePackagePaymentConfig = coursePackagePaymentConfigService.getById(paymentCourseVo.getCoursePackagePaymentConfigId());
+        String[] split = paymentCourseVo.getStudentIds().split(";");
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+        String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);
+        for (String s : split) {
+            TCoursePackagePayment coursePackagePayment = new TCoursePackagePayment();
+            coursePackagePayment.setCode(code);
+            coursePackagePayment.setAppUserId(uid);
+            coursePackagePayment.setStudentId(Integer.valueOf(s));
+            coursePackagePayment.setCoursePackageId(paymentCourseVo.getId());
+            coursePackagePayment.setPayType(paymentCourseVo.getPayType());
+            coursePackagePayment.setClassHours(coursePackagePaymentConfig.getClassHours());
+            coursePackagePayment.setOriginalPrice(paymentCourseVo.getPrice());
+            coursePackagePayment.setUserCouponId(paymentCourseVo.getCouponId());
+            coursePackagePayment.setCashPayment(new BigDecimal(paymentPrice));
+            coursePackagePayment.setTotalClassHours(coursePackagePaymentConfig.getClassHours());
+            coursePackagePayment.setLaveClassHours(coursePackagePaymentConfig.getClassHours());
+            coursePackagePayment.setAbsencesNumber(0);
+            coursePackagePayment.setPayUserType(1);
+            coursePackagePayment.setPayStatus(1);
+            coursePackagePayment.setPayUserId(uid);
+            coursePackagePayment.setStatus(1);
+            coursePackagePayment.setState(1);
+            coursePackagePayment.setInsertTime(new Date());
+            coursePackagePaymentService.save(coursePackagePayment);
+        }
+
+        ResultUtil weixinpay = payMoneyUtil.weixinpay("购买课程", "", code, paymentPrice.toString(), "/base/course/weChatPaymentCourseCallback", "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);
+                            List<TCoursePackagePayment> list = coursePackagePaymentService.list(new QueryWrapper<TCoursePackagePayment>().eq("state", 1).eq("code", code).eq("payType", 1));
+                            TCoursePackagePayment one = list.get(0);
+                            if(one.getPayStatus() == 2){
+                                break;
+                            }
+                            ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(code, "");
+                            if(resultUtil.getCode() == 200 && one.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){
+                                    for (TCoursePackagePayment coursePackagePayment : list) {
+                                        coursePackagePayment.setStatus(3);
+                                    }
+                                    coursePackagePaymentService.updateBatchById(list);
+                                    break;
+                                }
+                                if("SUCCESS".equals(s)){
+                                    for (TCoursePackagePayment coursePackagePayment : list) {
+                                        coursePackagePayment.setPayStatus(2);
+                                        coursePackagePayment.setOrderNumber(transaction_id);
+                                    }
+                                    coursePackagePaymentService.updateBatchById(list);
+                                    break;
+                                }
+                                if("USERPAYING".equals(s)){
+                                    num++;
+                                }
+                            }
+                        }
+                    }catch (Exception e){
+                        e.printStackTrace();
+                    }
+                }
+            }).start();
+        }
+        return weixinpay;
+    }
+
+
+    /**
+     * 课程支付宝支付
+     * @param uid
+     * @param paymentPrice
+     * @param paymentCourseVo
+     * @return
+     * @throws Exception
+     */
+    public ResultUtil aliPaymentCourse(Integer uid, Double paymentPrice, PaymentCourseVo paymentCourseVo) throws Exception{
+        CoursePackagePaymentConfig coursePackagePaymentConfig = coursePackagePaymentConfigService.getById(paymentCourseVo.getCoursePackagePaymentConfigId());
+        String[] split = paymentCourseVo.getStudentIds().split(";");
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+        String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);
+        for (String s : split) {
+            TCoursePackagePayment coursePackagePayment = new TCoursePackagePayment();
+            coursePackagePayment.setCode(code);
+            coursePackagePayment.setAppUserId(uid);
+            coursePackagePayment.setStudentId(Integer.valueOf(s));
+            coursePackagePayment.setCoursePackageId(paymentCourseVo.getId());
+            coursePackagePayment.setPayType(paymentCourseVo.getPayType());
+            coursePackagePayment.setClassHours(coursePackagePaymentConfig.getClassHours());
+            coursePackagePayment.setOriginalPrice(paymentCourseVo.getPrice());
+            coursePackagePayment.setUserCouponId(paymentCourseVo.getCouponId());
+            coursePackagePayment.setCashPayment(new BigDecimal(paymentPrice));
+            coursePackagePayment.setTotalClassHours(coursePackagePaymentConfig.getClassHours());
+            coursePackagePayment.setLaveClassHours(coursePackagePaymentConfig.getClassHours());
+            coursePackagePayment.setAbsencesNumber(0);
+            coursePackagePayment.setPayUserType(1);
+            coursePackagePayment.setPayStatus(1);
+            coursePackagePayment.setPayUserId(uid);
+            coursePackagePayment.setStatus(1);
+            coursePackagePayment.setState(1);
+            coursePackagePayment.setInsertTime(new Date());
+            coursePackagePaymentService.save(coursePackagePayment);
+        }
+
+        ResultUtil alipay = payMoneyUtil.alipay("购买课程", "", "", code, paymentPrice.toString(), "/base/course/aliPaymentCourseCallback");
+        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);
+                            List<TCoursePackagePayment> list = coursePackagePaymentService.list(new QueryWrapper<TCoursePackagePayment>().eq("state", 1).eq("code", code).eq("payType", 2));
+                            TCoursePackagePayment one = list.get(0);
+                            if(one.getPayStatus() == 2){
+                                break;
+                            }
+                            ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryALIOrder(code);
+                            if(resultUtil.getCode() == 200 && one.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){
+                                    for (TCoursePackagePayment coursePackagePayment : list) {
+                                        coursePackagePayment.setStatus(3);
+                                    }
+                                    coursePackagePaymentService.updateBatchById(list);
+                                    break;
+                                }
+                                if("TRADE_SUCCESS".equals(s)){
+                                    for (TCoursePackagePayment coursePackagePayment : list) {
+                                        coursePackagePayment.setPayStatus(2);
+                                        coursePackagePayment.setOrderNumber(tradeNo);
+                                    }
+                                    coursePackagePaymentService.updateBatchById(list);
+                                    break;
+                                }
+                                if("WAIT_BUYER_PAY".equals(s)){
+                                    num++;
+                                }
+                            }
+                        }
+                    }catch (Exception e){
+                        e.printStackTrace();
+                    }
+                }
+            }).start();
+        }
+        return alipay;
+    }
+
+
+    /**
+     * 玩湃币支付课程
+     * @param appUser
+     * @param paymentPrice
+     * @param paymentCourseVo
+     * @return
+     * @throws Exception
+     */
+    public ResultUtil playPaiCoinPaymentCourse(AppUser appUser, Double paymentPrice, PaymentCourseVo paymentCourseVo) throws Exception{
+        CoursePackagePaymentConfig coursePackagePaymentConfig = coursePackagePaymentConfigService.getById(paymentCourseVo.getCoursePackagePaymentConfigId());
+        String[] split = paymentCourseVo.getStudentIds().split(";");
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+        String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);
+        for (String s : split) {
+            TCoursePackagePayment coursePackagePayment = new TCoursePackagePayment();
+            coursePackagePayment.setCode(code);
+            coursePackagePayment.setAppUserId(appUser.getId());
+            coursePackagePayment.setStudentId(Integer.valueOf(s));
+            coursePackagePayment.setCoursePackageId(paymentCourseVo.getId());
+            coursePackagePayment.setPayType(paymentCourseVo.getPayType());
+            coursePackagePayment.setClassHours(coursePackagePaymentConfig.getClassHours());
+            coursePackagePayment.setOriginalPrice(paymentCourseVo.getPrice());
+            coursePackagePayment.setPlayPaiCoin(paymentPrice.intValue());
+            coursePackagePayment.setTotalClassHours(coursePackagePaymentConfig.getClassHours());
+            coursePackagePayment.setLaveClassHours(coursePackagePaymentConfig.getClassHours());
+            coursePackagePayment.setAbsencesNumber(0);
+            coursePackagePayment.setPayUserType(1);
+            coursePackagePayment.setPayStatus(2);
+            coursePackagePayment.setPayUserId(appUser.getId());
+            coursePackagePayment.setStatus(1);
+            coursePackagePayment.setState(1);
+            coursePackagePayment.setInsertTime(new Date());
+            coursePackagePaymentService.save(coursePackagePayment);
+        }
+
+        Integer playPaiCoins = appUser.getPlayPaiCoins();
+        appUser.setPlayPaiCoins(playPaiCoins - paymentPrice.intValue());
+        appUserClient.updateAppUser(appUser);
         return ResultUtil.success();
     }
 }

--
Gitblit v1.7.1