|  |  |  | 
|---|
|  |  |  | package com.dsh.course.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import cn.hutool.core.collection.CollectionUtil; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONArray; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.alibaba.nacos.common.utils.UuidUtils; | 
|---|
|  |  |  | import com.alipay.api.AlipayApiException; | 
|---|
|  |  |  | import com.alipay.api.AlipayClient; | 
|---|
|  |  |  | import com.alipay.api.DefaultAlipayClient; | 
|---|
|  |  |  | import com.alipay.api.domain.AlipayTradeOrderSettleModel; | 
|---|
|  |  |  | import com.alipay.api.domain.OpenApiRoyaltyDetailInfoPojo; | 
|---|
|  |  |  | import com.alipay.api.domain.RoyaltyDetailInfos; | 
|---|
|  |  |  | import com.alipay.api.request.AlipayTradeOrderSettleRequest; | 
|---|
|  |  |  | import com.alipay.api.request.AlipayTradeRoyaltyRelationBindRequest; | 
|---|
|  |  |  | import com.alipay.api.response.AlipayTradeOrderSettleResponse; | 
|---|
|  |  |  | import com.alipay.api.response.AlipayTradeQueryResponse; | 
|---|
|  |  |  | import com.alipay.api.response.AlipayTradeRoyaltyRelationBindResponse; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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.SendCouponReq; | 
|---|
|  |  |  | 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.CoursePackageStudentMapper; | 
|---|
|  |  |  | import com.dsh.course.mapper.TCoursePackageMapper; | 
|---|
|  |  |  | import com.dsh.course.feignclient.model.CourseOfStoreVo; | 
|---|
|  |  |  | import com.dsh.course.model.*; | 
|---|
|  |  |  | import com.dsh.course.service.*; | 
|---|
|  |  |  | import com.dsh.course.util.*; | 
|---|
|  |  |  | import com.dsh.course.util.httpClinet.HttpResult; | 
|---|
|  |  |  | 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.ParseException; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.time.LocalDate; | 
|---|
|  |  |  | import java.time.Period; | 
|---|
|  |  |  | import java.time.ZoneId; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class TCoursePackageServiceImpl extends ServiceImpl<TCoursePackageMapper, TCoursePackage> implements TCoursePackageService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private String aliAppid = "2021004105665036";//支付宝appid | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private String appPrivateKey = "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCi5i9nW/hGLJ3A06cZxTQdviFC7THpdSihoTYGLr9q006hu0V26ecBMY/o4w5bvIX0Ok/yofmZsVcCJpAPvbXL/uqVrIjnRRxXiaeBFThlxoBUTdunvbUSDYfzlEhJr5NvUKI6H6lz2niXlQGx4qy8Hau4ccWit9kM8jwUvsBVQoFgJA+xrjMvooA7YLopQtpOD+UJr5thApTSf1xrnr1W12yolTLEH15JmNV372cqXrYUuqnY0QsaPtxeqJUGAOcGdVLllQ7easEznP8DFBvDdHATcmp2SHNQDUEWN6MCVPbMgY06NQVqAXxqjTAYSVh+6TRu6bofPmpYC3TZB003AgMBAAECggEBAJAcR2+PA3NBYUYHeFrqBRMS8uX8ZR19kjZ7IgoSLTFaQsP9opRylPSPXhrPVBKAE5leRQAHn4MCSlESwHvMfxo7KFjFTFAc6dffZZpipYQUOc9bGampwJh58/3e/pyBgVMG6J23CPf/HJQtNFSkjd/V9+ayb/9l2dUEL3bC0fAZ/dbx8HsxdLw8wn3fLlWLj68hOMqa2deCZe3JdSVsPbeWqkh56FFsMLug0Nd+Ar4TgRl9/jnhXF0JWiD0LmPUYLhboY7EfUBzN4w1iYbDi1P+3zvoOYsiVKAXox9GMhQ2VzOO2UcSTuizSza2e98mGpabl/GpKmCz+RDFjtkX6eECgYEA2MyCij65eO3aGIm3FUe93DULRBYTfX8qJQSJq2WOWA3mmQlEW6L3O2B5/lG2h+8WmN6iLEs9eHpgycGYp7vAqgrANEn16ACVcuyx0scFtrZfZ+kmHMzFfiUWxJjVYk/6YngsGVBLdw6ueM42C8TTP67X9tU5TdVGoGWuqEj4W98CgYEAwFqwprXOch5Pqk/RPbb49r0Ou03K/UbciWnWWKzUhFFNS8MdlQPoDvQZbMwHLeWsa2VhaKITK3x5biLQb3U+0GLOn6lTvEyrEUH+ucREyLgVYTRAvwBPtnvlrzpyxPk2HnslQjju8WrvvLLBMKWUjlTrTOzhaHT21gz3pHMiOakCgYEAhLmfaXdBITGshb054sNLDtdCkGpbgEcrzAHdLps769iGxkYQHXHFngpQZUwtTUcoNGqIKknd1jZFrv7gsD+XkgKG7PwimehRlkwmCX5ilxtLiVgJRzRt6+5U5AMVD90a0tHzXYP0z2yjj73fBJF5KtGl0a10KZxaYrQdm1UhB00CgYBZZgzx/k9rtHC8LAqIj1CYhHejT92G53c6Gkl3vyOqN4sgKhfGmSEySfrDGPRBPZxr8ZtbIPCd5mUdberH0osWGMYFaJI1UsCy7aQwvGpniz7MhZeN7dweaOjwDs8mgtjHQ96mL4XGCDhR0BZ/wIURvZ/6iaGdhbbu9unlsWj3uQKBgQCmZYdsbbZkd3ev6f8rwyvMz+DrCQyYpY44cegBYuJgrZiQnL2fJioeN7ixX0UM48SfwsZEIrzshP/LGAwnc2MdjxKUl4jLN8SEe0NAjXOnz9Zaw740+aOmLpXcLWdP4uM2gIhWsvW1tEkQZCXmm7c9s/RsU8Pmzv+YL3+fSijOzA==";//支付宝开发者应用私钥 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private String alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAouYvZ1v4RiydwNOnGcU0Hb4hQu0x6XUooaE2Bi6/atNOobtFdunnATGP6OMOW7yF9DpP8qH5mbFXAiaQD721y/7qlayI50UcV4mngRU4ZcaAVE3bp721Eg2H85RISa+Tb1CiOh+pc9p4l5UBseKsvB2ruHHForfZDPI8FL7AVUKBYCQPsa4zL6KAO2C6KULaTg/lCa+bYQKU0n9ca569VtdsqJUyxB9eSZjVd+9nKl62FLqp2NELGj7cXqiVBgDnBnVS5ZUO3mrBM5z/AxQbw3RwE3JqdkhzUA1BFjejAlT2zIGNOjUFagF8ao0wGElYfuk0bum6Hz5qWAt02QdNNwIDAQAB";//支付宝应用公钥 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private String alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmu8n/4yTHWbn7VOrNc9OsLtDL1bEQ8gC1dHkj8Wy5z0mkaOsjJRIG/28ze12M0V8jdCKuuDr5Z1OPKiqf+XO3ypguEh+mYUVMBM/cZodDFQfTY1TKLWjvQCuaqlA+QUTCK6f7T7stsgyQ1o9Jj0rXZDz6PM4QHSTzjrLIBaeqM5WIBvH+fy/X+QG5Utd+/UT0kc0JyvuKhZ65yVUd/C9VcwJJAPliRsAQNrqYterwAJ9zvw9tF11wj9W0XgJ8Ccu4x3gR1vrlLRJJo/OA97RmxPQ+5hSacWQZCUd1dwiBq+YCrKVHGTj14izRHXrLc0yBlRXo7tBOIqcy3IsvKVthQIDAQAB";//支付宝支付公钥 | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private StoreClient storeClient; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ICoursePackagePaymentConfigService coursePackagePaymentConfigService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CourseCounsumService courseCounsumService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TCoursePackageDiscountService coursePackageDiscountService; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CoursePackageStudentService coursePackageStudentService; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private CoursePackageStudentMapper cpsMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ICoursePackageOrderStudentService coursePackageOrderStudentService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ICoursePackageOrderService coursePackageOrderService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TOrderService orderService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TCoursePackageService coursePackageService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private CoursePackageStudentMapper coursePackageStudentMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取课程列表 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param coursePackageList | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<CoursePackageListVo> queryCourseList(Integer uid, CoursePackageList coursePackageList) throws Exception { | 
|---|
|  |  |  | AppUser appUser = appUserClient.queryAppUser(uid); | 
|---|
|  |  |  | QueryWrapper<TCoursePackage> wrapper = new QueryWrapper<TCoursePackage>().in("status", Arrays.asList(1, 2)) | 
|---|
|  |  |  | .eq("auditStatus", 2).eq("state", 1); | 
|---|
|  |  |  | 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("storeId", collect); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<TCoursePackage> list1 = this.list(wrapper.last(" order by sort desc, insertTime desc")); | 
|---|
|  |  |  | Date currentTime = new Date(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<TCoursePackage> list = list1.stream() | 
|---|
|  |  |  | .filter(coursePackage -> coursePackage.getType() != 2 || currentTime.before(coursePackage.getEndTime())) | 
|---|
|  |  |  | .collect(Collectors.toList()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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").last(" 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()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String classStartTime = coursePackage.getClassStartTime(); | 
|---|
|  |  |  | String classEndTime = coursePackage.getClassEndTime(); | 
|---|
|  |  |  | ArrayList<String> classTime = new ArrayList<>(); | 
|---|
|  |  |  | String[] split = classStartTime.split(","); | 
|---|
|  |  |  | String[] split3 = classEndTime.split(","); | 
|---|
|  |  |  | if (ToolUtil.isNotEmpty(classStartTime)) { | 
|---|
|  |  |  | for (int i = 0; i < split.length; i++) { | 
|---|
|  |  |  | String s = split[i].substring(0, 5) + "-" + split3[i].substring(0, 5); | 
|---|
|  |  |  | classTime.add(s); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | coursePackageListVo.setClassStartTime(classTime); | 
|---|
|  |  |  | coursePackageListVo.setType(coursePackage.getType()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | coursePackageListVo.setApplicantsNumber(integer); | 
|---|
|  |  |  | Double cashPayment1 = coursePackagePaymentConfig.getCashPayment(); | 
|---|
|  |  |  | Integer playPaiCoin = coursePackagePaymentConfig.getPlayPaiCoin(); | 
|---|
|  |  |  | if (ToolUtil.isNotEmpty(cashPayment1) && cashPayment1 > 0 && ToolUtil.isNotEmpty(playPaiCoin) && playPaiCoin > 0) { | 
|---|
|  |  |  | coursePackageListVo.setPayType(3); | 
|---|
|  |  |  | } else if (ToolUtil.isNotEmpty(cashPayment1) && cashPayment1 > 0) { | 
|---|
|  |  |  | coursePackageListVo.setPayType(1); | 
|---|
|  |  |  | } else if (ToolUtil.isNotEmpty(playPaiCoin) && playPaiCoin > 0) { | 
|---|
|  |  |  | coursePackageListVo.setPayType(2); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (coursePackagePaymentConfig != null) { | 
|---|
|  |  |  | coursePackageListVo.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).eq("status", 1)); | 
|---|
|  |  |  | Double vipPrice = coursePackagePaymentConfig.getCashPayment(); | 
|---|
|  |  |  | for (TCoursePackageDiscount coursePackageDiscount : list2) { | 
|---|
|  |  |  | Double num1 = JSON.parseObject(coursePackageDiscount.getContent()).getDouble("discountMember"); | 
|---|
|  |  |  | if (vipPrice.compareTo(num1) > 0) { | 
|---|
|  |  |  | vipPrice = num1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | coursePackageListVo.setVipPrice(vipPrice); | 
|---|
|  |  |  | coursePackageListVo.setOriginalPrice(coursePackagePaymentConfig.getCashPayment()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Double paymentPrice = coursePackagePaymentConfig.getCashPayment(); | 
|---|
|  |  |  | List<TCoursePackageDiscount> list3 = coursePackageDiscountService.list(new QueryWrapper<TCoursePackageDiscount>().eq("coursePackagePaymentConfigId", coursePackagePaymentConfig.getId()) | 
|---|
|  |  |  | .eq("type", 3).eq("auditStatus", 2).eq("status", 1)); | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (coursePackageListVo.getPaymentPrice() < coursePackageListVo.getVipPrice()) { | 
|---|
|  |  |  | coursePackageListVo.setOriginalPrice(coursePackagePaymentConfig.getCashPayment()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (appUser.getIsVip() == 1) { | 
|---|
|  |  |  | if (coursePackageListVo.getVipPrice() < coursePackageListVo.getPaymentPrice()) { | 
|---|
|  |  |  | coursePackageListVo.setPaymentPrice(coursePackageListVo.getVipPrice()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | coursePackageListVo.setVipPrice(null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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()) && coursePackageList.getSalesRanking().equals("asc")) { | 
|---|
|  |  |  | Collections.sort(listVos, new Comparator<CoursePackageListVo>() { | 
|---|
|  |  |  | public int compare(CoursePackageListVo s1, CoursePackageListVo s2) { | 
|---|
|  |  |  | return Integer.compare(s1.getApplicantsNumber(), s2.getApplicantsNumber()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (ToolUtil.isNotEmpty(coursePackageList.getSalesRanking()) && coursePackageList.getSalesRanking().equals("desc")) { | 
|---|
|  |  |  | Collections.sort(listVos, new Comparator<CoursePackageListVo>() { | 
|---|
|  |  |  | public int compare(CoursePackageListVo s1, CoursePackageListVo s2) { | 
|---|
|  |  |  | return Integer.compare(s2.getApplicantsNumber(), s1.getApplicantsNumber()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //距离排行 | 
|---|
|  |  |  | if (ToolUtil.isNotEmpty(coursePackageList.getDistanceSort()) && coursePackageList.getDistanceSort().equals("asc")) { | 
|---|
|  |  |  | Collections.sort(listVos, new Comparator<CoursePackageListVo>() { | 
|---|
|  |  |  | public int compare(CoursePackageListVo s1, CoursePackageListVo s2) { | 
|---|
|  |  |  | return Double.compare(s1.getDistance(), s2.getDistance()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (ToolUtil.isNotEmpty(coursePackageList.getDistanceSort()) && coursePackageList.getDistanceSort().equals("desc")) { | 
|---|
|  |  |  | Collections.sort(listVos, new Comparator<CoursePackageListVo>() { | 
|---|
|  |  |  | public int compare(CoursePackageListVo s1, CoursePackageListVo s2) { | 
|---|
|  |  |  | return Double.compare(s2.getDistance(), s1.getDistance()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return listVos; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<CoursePackageListVo> queryCourseListOne(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()){ | 
|---|
|  |  |  | if (null != coursePackageList.getCoursePackageTypeId()) { | 
|---|
|  |  |  | wrapper.eq("coursePackageTypeId", coursePackageList.getCoursePackageTypeId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(null != coursePackageList.getStoreId()){ | 
|---|
|  |  |  | if (null != coursePackageList.getStoreId()) { | 
|---|
|  |  |  | wrapper.eq("storeId", coursePackageList.getStoreId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(null != coursePackageList.getStoreId()){ | 
|---|
|  |  |  | if (null != coursePackageList.getStoreId()) { | 
|---|
|  |  |  | wrapper.eq("storeId", coursePackageList.getStoreId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(ToolUtil.isNotEmpty(coursePackageList.getSearch())){ | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | if (collect.size() > 0) { | 
|---|
|  |  |  | wrapper.or().in("storeId", collect); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<TCoursePackage> list = this.list(wrapper.last(" order by sort, insertTime desc")); | 
|---|
|  |  |  | 
|---|
|  |  |  | coursePackageListVo.setId(coursePackage.getId()); | 
|---|
|  |  |  | coursePackageListVo.setName(coursePackage.getName()); | 
|---|
|  |  |  | coursePackageListVo.setStoreName(null != store ? store.getName() : ""); | 
|---|
|  |  |  | //            coursePackageListVo.setPayType(); | 
|---|
|  |  |  | coursePackageListVo.setCoverDrawing(coursePackage.getCoverDrawing()); | 
|---|
|  |  |  | coursePackageListVo.setClassStartTime(coursePackage.getClassStartTime() + "-" + coursePackage.getClassEndTime()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Double cashPayment1 = coursePackagePaymentConfig.getCashPayment(); | 
|---|
|  |  |  | Integer playPaiCoin = coursePackagePaymentConfig.getPlayPaiCoin(); | 
|---|
|  |  |  | if (ToolUtil.isNotEmpty(cashPayment1) && cashPayment1 > 0 && ToolUtil.isNotEmpty(playPaiCoin) && playPaiCoin > 0) { | 
|---|
|  |  |  | coursePackageListVo.setPayType(3); | 
|---|
|  |  |  | } else if (ToolUtil.isNotEmpty(cashPayment1) && cashPayment1 > 0) { | 
|---|
|  |  |  | coursePackageListVo.setPayType(1); | 
|---|
|  |  |  | } else if (ToolUtil.isNotEmpty(playPaiCoin) && playPaiCoin > 0) { | 
|---|
|  |  |  | coursePackageListVo.setPayType(2); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String classStartTime = coursePackage.getClassStartTime(); | 
|---|
|  |  |  | String classEndTime = coursePackage.getClassEndTime(); | 
|---|
|  |  |  | ArrayList<String> classTime = new ArrayList<>(); | 
|---|
|  |  |  | String[] split = classStartTime.split(","); | 
|---|
|  |  |  | String[] split3 = classEndTime.split(","); | 
|---|
|  |  |  | for (int i = 0; i < split.length; i++) { | 
|---|
|  |  |  | String s = split[i] + "-" + split3[i]; | 
|---|
|  |  |  | classTime.add(s); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | coursePackageListVo.setClassStartTime(classTime); | 
|---|
|  |  |  | coursePackageListVo.setType(coursePackage.getType()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | coursePackageListVo.setApplicantsNumber(integer); | 
|---|
|  |  |  | coursePackageListVo.setPayType(coursePackage.getPayType()); | 
|---|
|  |  |  | coursePackageListVo.setPlayPaiCoin(coursePackagePaymentConfig.getPlayPaiCoin()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //会员显示原价和会员价(最低)。非会员显示会员价和支付价(最低) | 
|---|
|  |  |  | if(appUser.getIsVip() == 0){//非会员 | 
|---|
|  |  |  | if (false) {//非会员 | 
|---|
|  |  |  | 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("discountMember"); | 
|---|
|  |  |  | if(vipPrice.compareTo(num1) > 0){ | 
|---|
|  |  |  | if (vipPrice.compareTo(num1) > 0) { | 
|---|
|  |  |  | vipPrice = num1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | 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()){ | 
|---|
|  |  |  | 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){ | 
|---|
|  |  |  | if (isFirstSunday) { | 
|---|
|  |  |  | week = week - 1; | 
|---|
|  |  |  | if(week == 0){ | 
|---|
|  |  |  | if (week == 0) { | 
|---|
|  |  |  | week = 7; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!weeks.contains(week)){ | 
|---|
|  |  |  | if (!weeks.contains(week)) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | e.set(Calendar.MINUTE, Integer.valueOf(split2[1])); | 
|---|
|  |  |  | e.set(Calendar.SECOND, Integer.valueOf(split2[2])); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(hour1 > hour2){ | 
|---|
|  |  |  | if(s.getTimeInMillis() > date.getTime()){ | 
|---|
|  |  |  | if (hour1 > hour2) { | 
|---|
|  |  |  | if (s.getTimeInMillis() > date.getTime()) { | 
|---|
|  |  |  | s.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) - 1); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | } 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){ | 
|---|
|  |  |  | if (timeMillis >= s.getTimeInMillis() && timeMillis < e.getTimeInMillis() && paymentPrice.compareTo(cashPayment) > 0) { | 
|---|
|  |  |  | paymentPrice = cashPayment; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | coursePackageListVo.setPaymentPrice(paymentPrice); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | } 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("discountMember"); | 
|---|
|  |  |  | if(vipPrice.compareTo(num1) > 0){ | 
|---|
|  |  |  | if (vipPrice.compareTo(num1) > 0) { | 
|---|
|  |  |  | vipPrice = num1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //销量排行 | 
|---|
|  |  |  | if(ToolUtil.isNotEmpty(coursePackageList.getSalesRanking())){ | 
|---|
|  |  |  | 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())){ | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取课包详情 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param uid | 
|---|
|  |  |  | * @param id | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public CoursePackageInfo queryCourseInfo(Integer uid, Integer id, String lon, String lat) throws Exception { | 
|---|
|  |  |  | public CoursePackageInfo queryCourseInfo(Integer uid, Integer id, String lon, String lat, Integer stuId) throws Exception { | 
|---|
|  |  |  | AppUser appUser = appUserClient.queryAppUser(uid); | 
|---|
|  |  |  | TCoursePackage coursePackage = this.getById(id); | 
|---|
|  |  |  | CoursePackageInfo coursePackageInfo = new CoursePackageInfo(); | 
|---|
|  |  |  | coursePackageInfo.setIsVip(appUser.getIsVip()); | 
|---|
|  |  |  | coursePackageInfo.setId(id); | 
|---|
|  |  |  | SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd"); | 
|---|
|  |  |  | if (coursePackage.getType() == 2) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | coursePackageInfo.setTime(format.format(coursePackage.getStartTime()) + "-" + format.format(coursePackage.getEndTime())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | coursePackageInfo.setCoverDrawing(coursePackage.getCoverDrawing()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | coursePackageInfo.setName(coursePackage.getName()); | 
|---|
|  |  |  | Store store = storeClient.queryStoreById(coursePackage.getStoreId()); | 
|---|
|  |  |  | coursePackageInfo.setStoreName(store.getName()); | 
|---|
|  |  |  | 
|---|
|  |  |  | coursePackageInfo.setStoreAddress(store.getAddress()); | 
|---|
|  |  |  | coursePackageInfo.setLon(store.getLon()); | 
|---|
|  |  |  | coursePackageInfo.setLat(store.getLat()); | 
|---|
|  |  |  | if(ToolUtil.isNotEmpty(lon) && ToolUtil.isNotEmpty(lat)){ | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String classStartTime = coursePackage.getClassStartTime(); | 
|---|
|  |  |  | String classEndTime = coursePackage.getClassEndTime(); | 
|---|
|  |  |  | ArrayList<String> classTime = new ArrayList<>(); | 
|---|
|  |  |  | String[] split4 = classStartTime.split(","); | 
|---|
|  |  |  | String[] split3 = classEndTime.split(","); | 
|---|
|  |  |  | if (ToolUtil.isNotEmpty(classStartTime)) { | 
|---|
|  |  |  | for (int i = 0; i < split4.length; i++) { | 
|---|
|  |  |  | String s = split4[i].substring(0, 5) + "-" + split3[i].substring(0, 5); | 
|---|
|  |  |  | classTime.add(s); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | coursePackageInfo.setTimes(classTime); | 
|---|
|  |  |  | coursePackageInfo.setType(coursePackage.getType()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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 (ToolUtil.isNotEmpty(coursePackagePaymentConfig.getCashPayment()) && coursePackagePaymentConfig.getCashPayment() > 0 && ToolUtil.isNotEmpty(coursePackagePaymentConfig.getPlayPaiCoin()) && coursePackagePaymentConfig.getPlayPaiCoin() > 0) { | 
|---|
|  |  |  | coursePackagePaymentConfigVo.setPayType(3); | 
|---|
|  |  |  | } else if (ToolUtil.isNotEmpty(coursePackagePaymentConfig.getCashPayment()) && coursePackagePaymentConfig.getCashPayment() > 0) { | 
|---|
|  |  |  | coursePackagePaymentConfigVo.setPayType(1); | 
|---|
|  |  |  | } else if (ToolUtil.isNotEmpty(coursePackagePaymentConfig.getPlayPaiCoin()) && coursePackagePaymentConfig.getPlayPaiCoin() > 0) { | 
|---|
|  |  |  | coursePackagePaymentConfigVo.setPayType(2); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //会员显示原价和支付价(会员价)。非会员显示会员价和支付价(最低) | 
|---|
|  |  |  | 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("discountMember"); | 
|---|
|  |  |  | if(vipPrice.compareTo(num1) > 0){ | 
|---|
|  |  |  | vipPrice = num1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //                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("discountMember"); | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | 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("discountMember"); | 
|---|
|  |  |  | if(vipPrice.compareTo(num1) > 0){ | 
|---|
|  |  |  | vipPrice = num1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | coursePackagePaymentConfigVo.setPaymentPrice(vipPrice); | 
|---|
|  |  |  | coursePackagePaymentConfigVo.setOriginalPrice(coursePackagePaymentConfig.getCashPayment()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | coursePackagePaymentConfigVo.setPaymentPrice(paymentPrice); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //                    TCoursePackageDiscount discount = coursePackageDiscountService.getOne(new QueryWrapper<TCoursePackageDiscount>().eq("coursePackagePaymentConfigId", coursePackagePaymentConfig.getId()) | 
|---|
|  |  |  | //                            .eq("type", 2).eq("auditStatus", 2)); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                    //这里是续课优惠 | 
|---|
|  |  |  | //                    Double continuingMember = JSON.parseObject(discount.getContent()).getDouble("continuingUser"); | 
|---|
|  |  |  | //                    Double vipcontinuingMember = JSON.parseObject(discount.getContent()).getDouble("continuingMember"); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                    if (coursePackagePaymentConfigVo.getPaymentPrice()>continuingMember){ | 
|---|
|  |  |  | //                        coursePackagePaymentConfigVo.setPaymentPrice(continuingMember); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                    if (coursePackagePaymentConfigVo.getVipPrice()>vipcontinuingMember){ | 
|---|
|  |  |  | //                        coursePackagePaymentConfigVo.setVipPrice(vipcontinuingMember); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | if (appUser.getIsVip() == 1) { | 
|---|
|  |  |  | if (coursePackagePaymentConfigVo.getVipPrice() < coursePackagePaymentConfigVo.getPaymentPrice()) { | 
|---|
|  |  |  | coursePackagePaymentConfigVo.setPaymentPrice(coursePackagePaymentConfigVo.getVipPrice()); | 
|---|
|  |  |  | coursePackagePaymentConfigVo.setOriginalPrice(coursePackagePaymentConfig.getCashPayment()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (coursePackagePaymentConfigVo.getPaymentPrice() < coursePackagePaymentConfigVo.getVipPrice()) { | 
|---|
|  |  |  | coursePackagePaymentConfigVo.setOriginalPrice(coursePackagePaymentConfig.getCashPayment()); | 
|---|
|  |  |  | coursePackagePaymentConfigVo.setVipPrice(null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                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("discountMember"); | 
|---|
|  |  |  | //                        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(); | 
|---|
|  |  |  | if(null != student){ | 
|---|
|  |  |  | Student student = null; | 
|---|
|  |  |  | if(null != stuId){ | 
|---|
|  |  |  | student = studentClient.queryStudentById(stuId); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | student = studentClient.queryDefaultStudent(uid); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (null != student) { | 
|---|
|  |  |  | studentVo.setId(student.getId()); | 
|---|
|  |  |  | studentVo.setPhone(student.getPhone()); | 
|---|
|  |  |  | studentVo.setName(student.getName()); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 课程包名支付 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param uid | 
|---|
|  |  |  | * @param paymentCourseVo | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | 
|---|
|  |  |  | @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(); | 
|---|
|  |  |  | CoursePackageInfo coursePackageInfo = queryCourseInfo(uid, paymentCourseVo.getId(), null, null, null); | 
|---|
|  |  |  | //校验是否已经报满 | 
|---|
|  |  |  | Integer integer = coursePackagePaymentService.queryCountNumber(paymentCourseVo.getId()); | 
|---|
|  |  |  | TCoursePackage course = coursePackageService.getById(paymentCourseVo.getId()); | 
|---|
|  |  |  | if (course.getType() == 1) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (integer + paymentCourseVo.getStudentIds().split(";").length > course.getMaxSubscribeNumber()) { | 
|---|
|  |  |  | return ResultUtil.error("报名失败,已达最大报名人数"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<CoursePackagePaymentConfigVo> list = coursePackageInfo.getList(); | 
|---|
|  |  |  | String[] students = paymentCourseVo.getStudentIds().split(";"); | 
|---|
|  |  |  | for (CoursePackagePaymentConfigVo coursePackagePaymentConfigVo : list) { | 
|---|
|  |  |  | if(paymentCourseVo.getCoursePackagePaymentConfigId().compareTo(coursePackagePaymentConfigVo.getId()) == 0){ | 
|---|
|  |  |  | if (paymentCourseVo.getCoursePackagePaymentConfigId().compareTo(coursePackagePaymentConfigVo.getId()) == 0) { | 
|---|
|  |  |  | CoursePackagePaymentConfig byId = coursePackagePaymentConfigService.getById(paymentCourseVo.getCoursePackagePaymentConfigId()); | 
|---|
|  |  |  | Double cashPayment = byId.getCashPayment(); | 
|---|
|  |  |  | Integer payType = coursePackagePaymentConfigVo.getPayType(); | 
|---|
|  |  |  | if(payType == 1 && paymentCourseVo.getPayType() == 3){//现金支付 | 
|---|
|  |  |  | return ResultUtil.error("支付方式错误,请刷新后重试"); | 
|---|
|  |  |  | Integer playPaiCoin1 = byId.getPlayPaiCoin(); | 
|---|
|  |  |  | if (cashPayment != null || cashPayment > 0) { | 
|---|
|  |  |  | payType = 1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(payType == 2 && paymentCourseVo.getPayType() != 3){//玩湃币支付 | 
|---|
|  |  |  | return ResultUtil.error("支付方式错误,请刷新后重试"); | 
|---|
|  |  |  | if (playPaiCoin1 != null || playPaiCoin1 > 0) { | 
|---|
|  |  |  | payType = 2; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if ((cashPayment != null || cashPayment > 0) && (playPaiCoin1 != null || playPaiCoin1 > 0)) { | 
|---|
|  |  |  | payType = 3; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (cashPayment != null && cashPayment > 0 && playPaiCoin1 != null && playPaiCoin1 > 0) { | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | 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){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (paymentCourseVo.getPayType() == 3 && playPaiCoin.compareTo(paymentCourseVo.getPrice()) != 0) { | 
|---|
|  |  |  | return ResultUtil.error("支付金额异常,请刷新后重试"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Double price = paymentCourseVo.getPrice();//支付金额 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //校验优惠券 | 
|---|
|  |  |  | Long couponId = paymentCourseVo.getCouponId(); | 
|---|
|  |  |  | if(null != couponId && paymentCourseVo.getPayType() != 3){ | 
|---|
|  |  |  | if (null != couponId && paymentCourseVo.getPayType() != 3) { | 
|---|
|  |  |  | UserCoupon userCoupon = userCouponClient.queryUserCouponById(couponId); | 
|---|
|  |  |  | if(userCoupon.getStatus() == 2){ | 
|---|
|  |  |  | return ResultUtil.error("优惠券已被核销"); | 
|---|
|  |  |  | if (userCoupon.getStatus() == 2) { | 
|---|
|  |  |  | return ResultUtil.error("优惠券已被使用"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Coupon coupon = couponClient.queryCouponById(userCoupon.getCouponId()); | 
|---|
|  |  |  | long time = coupon.getEndTime().getTime(); | 
|---|
|  |  |  | if(System.currentTimeMillis() >= time){ | 
|---|
|  |  |  | if (System.currentTimeMillis() >= time) { | 
|---|
|  |  |  | return ResultUtil.error("优惠券已过期"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(coupon.getType() == 1){//满减 | 
|---|
|  |  |  | if (coupon.getType() == 1) {//满减 | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); | 
|---|
|  |  |  | //                {"conditionalAmount":50,"deductionAmount":10,"experienceName":""} | 
|---|
|  |  |  | Double num1 = jsonObject.getDouble("conditionalAmount"); | 
|---|
|  |  |  | Double num2 = jsonObject.getDouble("deductionAmount"); | 
|---|
|  |  |  | if(price.compareTo(num1) <= 0){ | 
|---|
|  |  |  | 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){//代金券 | 
|---|
|  |  |  | if (coupon.getType() == 2) {//代金券 | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); | 
|---|
|  |  |  | Double num1 = jsonObject.getDouble("conditionalAmount"); | 
|---|
|  |  |  | if(price.compareTo(num1) <= 0){ | 
|---|
|  |  |  | if (price.compareTo(num1) <= 0) { | 
|---|
|  |  |  | return ResultUtil.error("该优惠券无法使用"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | price = new BigDecimal(price).subtract(new BigDecimal(num1)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | userCoupon.setStatus(2); | 
|---|
|  |  |  | userCouponClient.edit(userCoupon); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(paymentCourseVo.getPayType() == 1){//微信支付 | 
|---|
|  |  |  | if (paymentCourseVo.getPayType() == 1) {//微信支付 | 
|---|
|  |  |  | return weChatPaymentCourse(uid, price, paymentCourseVo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(paymentCourseVo.getPayType() == 2){//支付宝支付 | 
|---|
|  |  |  | if (paymentCourseVo.getPayType() == 2) {//支付宝支付 | 
|---|
|  |  |  | return aliPaymentCourse(uid, price, paymentCourseVo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(paymentCourseVo.getPayType() == 3){//玩湃币支付 | 
|---|
|  |  |  | if(appUser.getPlayPaiCoins() < price.intValue()){ | 
|---|
|  |  |  | if (paymentCourseVo.getPayType() == 3) {//玩湃币支付 | 
|---|
|  |  |  | if (appUser.getPlayPaiCoins() < price.intValue()) { | 
|---|
|  |  |  | return ResultUtil.error("报名失败,玩湃币不足,请充值!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return playPaiCoinPaymentCourse(appUser, price, paymentCourseVo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ResultUtil.success(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 课程微信支付 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param uid | 
|---|
|  |  |  | * @param paymentPrice | 
|---|
|  |  |  | * @param paymentCourseVo | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public ResultUtil weChatPaymentCourse(Integer uid, Double paymentPrice, PaymentCourseVo paymentCourseVo) 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); | 
|---|
|  |  |  | Long orderId = paymentCourseVo.getOrderId(); | 
|---|
|  |  |  | if(null == orderId){ | 
|---|
|  |  |  | //生成支付订单 | 
|---|
|  |  |  | CoursePackageOrder coursePackageOrder = new CoursePackageOrder(); | 
|---|
|  |  |  | coursePackageOrder.setCode(code); | 
|---|
|  |  |  | coursePackageOrder.setAppUserId(uid); | 
|---|
|  |  |  | coursePackageOrder.setStudentIds(paymentCourseVo.getStudentIds()); | 
|---|
|  |  |  | coursePackageOrder.setCoursePackageId(paymentCourseVo.getId()); | 
|---|
|  |  |  | coursePackageOrder.setPayType(paymentCourseVo.getPayType()); | 
|---|
|  |  |  | coursePackageOrder.setClassHours(coursePackagePaymentConfig.getClassHours()); | 
|---|
|  |  |  | coursePackageOrder.setOriginalPrice(paymentCourseVo.getPrice()); | 
|---|
|  |  |  | coursePackageOrder.setUserCouponId(paymentCourseVo.getCouponId()); | 
|---|
|  |  |  | coursePackageOrder.setCashPayment(new BigDecimal(paymentPrice)); | 
|---|
|  |  |  | coursePackageOrder.setPayUserType(1); | 
|---|
|  |  |  | coursePackageOrder.setPayStatus(1); | 
|---|
|  |  |  | coursePackageOrder.setPayUserId(uid); | 
|---|
|  |  |  | coursePackageOrder.setStatus(1); | 
|---|
|  |  |  | coursePackageOrder.setState(1); | 
|---|
|  |  |  | coursePackageOrder.setInsertTime(new Date()); | 
|---|
|  |  |  | coursePackageOrderService.save(coursePackageOrder); | 
|---|
|  |  |  | orderId = coursePackageOrder.getId(); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | CoursePackageOrder coursePackageOrder = coursePackageOrderService.getById(orderId); | 
|---|
|  |  |  | code = coursePackageOrder.getCode(); | 
|---|
|  |  |  | coursePackageOrder.setPayType(1); | 
|---|
|  |  |  | coursePackageOrder.setAppUserId(null); | 
|---|
|  |  |  | coursePackageOrder.setPayUserType(1); | 
|---|
|  |  |  | coursePackageOrder.setPayUserId(uid); | 
|---|
|  |  |  | coursePackageOrderService.updateById(coursePackageOrder); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ResultUtil weixinpay = payMoneyUtil.weixinpay("购买课程", "", code, paymentPrice.toString(), "/base/course/weChatPaymentCourseCallback", "APP", ""); | 
|---|
|  |  |  | if(weixinpay.getCode() == 200){ | 
|---|
|  |  |  | ResultUtil weixinpay = payMoneyUtil.weixinpay("购买课程", coursePackagePaymentConfig.getId().toString(), code, paymentPrice.toString(), "/base/course/weChatPaymentCourseCallback", "APP", ""); | 
|---|
|  |  |  | if (weixinpay.getCode() == 200) { | 
|---|
|  |  |  | String finalCode = code; | 
|---|
|  |  |  | new Thread(new Runnable() { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void run() { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | int num = 1; | 
|---|
|  |  |  | int wait = 0; | 
|---|
|  |  |  | while (num <= 10){ | 
|---|
|  |  |  | 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){ | 
|---|
|  |  |  | CoursePackageOrder coursePackageOrder1 = coursePackageOrderService.getOne(new QueryWrapper<CoursePackageOrder>() | 
|---|
|  |  |  | .eq("code", finalCode).eq("state", 1)); | 
|---|
|  |  |  | if (coursePackageOrder1.getPayStatus() == 2) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(code, ""); | 
|---|
|  |  |  | if(resultUtil.getCode() == 200 && one.getPayStatus() == 1){ | 
|---|
|  |  |  | ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(finalCode, ""); | 
|---|
|  |  |  | if (resultUtil.getCode() == 200 && coursePackageOrder1.getPayStatus() == 1) { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * SUCCESS—支付成功, | 
|---|
|  |  |  | * REFUND—转入退款, | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | if ("REFUND".equals(s) || "NOTPAY".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s) || num == 10) { | 
|---|
|  |  |  | //有待支付的订单,这里不处理 | 
|---|
|  |  |  | //                                    coursePackageOrder1.setState(3); | 
|---|
|  |  |  | //                                    coursePackageOrderService.updateById(coursePackageOrder1); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if("SUCCESS".equals(s)){ | 
|---|
|  |  |  | for (TCoursePackagePayment coursePackagePayment : list) { | 
|---|
|  |  |  | coursePackagePayment.setPayStatus(2); | 
|---|
|  |  |  | coursePackagePayment.setOrderNumber(transaction_id); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | coursePackagePaymentService.updateBatchById(list); | 
|---|
|  |  |  | if ("SUCCESS".equals(s)) { | 
|---|
|  |  |  | coursePackageOrder1.setPayStatus(2); | 
|---|
|  |  |  | coursePackageOrder1.setOrderNumber(transaction_id); | 
|---|
|  |  |  | coursePackageOrder1.setAppUserId(null); | 
|---|
|  |  |  | coursePackageOrderService.updateById(coursePackageOrder1); | 
|---|
|  |  |  | //修改课时有效期 | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | addCoursePackageOrderStudent(coursePackageOrder1.getId(), coursePackagePaymentConfig); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if("USERPAYING".equals(s)){ | 
|---|
|  |  |  | if ("USERPAYING".equals(s)) { | 
|---|
|  |  |  | num++; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | return weixinpay; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private String smid = "2088330203191220";//平台支付宝商户号 | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 课程支付宝支付 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param uid | 
|---|
|  |  |  | * @param paymentPrice | 
|---|
|  |  |  | * @param paymentCourseVo | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public ResultUtil aliPaymentCourse(Integer uid, Double paymentPrice, PaymentCourseVo paymentCourseVo) 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); | 
|---|
|  |  |  | String smid1=""; | 
|---|
|  |  |  | //生成支付订单 | 
|---|
|  |  |  | if (paymentCourseVo.getOrderId()==null){ | 
|---|
|  |  |  | CoursePackageOrder coursePackageOrder = new CoursePackageOrder(); | 
|---|
|  |  |  | coursePackageOrder.setCode(code); | 
|---|
|  |  |  | coursePackageOrder.setAppUserId(uid); | 
|---|
|  |  |  | coursePackageOrder.setStudentIds(paymentCourseVo.getStudentIds()); | 
|---|
|  |  |  | coursePackageOrder.setCoursePackageId(paymentCourseVo.getId()); | 
|---|
|  |  |  | coursePackageOrder.setPayType(paymentCourseVo.getPayType()); | 
|---|
|  |  |  | coursePackageOrder.setClassHours(coursePackagePaymentConfig.getClassHours()); | 
|---|
|  |  |  | coursePackageOrder.setOriginalPrice(paymentCourseVo.getPrice()); | 
|---|
|  |  |  | coursePackageOrder.setUserCouponId(paymentCourseVo.getCouponId()); | 
|---|
|  |  |  | coursePackageOrder.setCashPayment(new BigDecimal(paymentPrice)); | 
|---|
|  |  |  | coursePackageOrder.setPayUserType(1); | 
|---|
|  |  |  | coursePackageOrder.setPayStatus(1); | 
|---|
|  |  |  | coursePackageOrder.setPayUserId(uid); | 
|---|
|  |  |  | coursePackageOrder.setStatus(1); | 
|---|
|  |  |  | coursePackageOrder.setState(1); | 
|---|
|  |  |  | coursePackageOrder.setInsertTime(new Date()); | 
|---|
|  |  |  | coursePackageOrderService.save(coursePackageOrder); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | CoursePackageOrder coursePackageOrder = coursePackageOrderService.getById(paymentCourseVo.getOrderId()); | 
|---|
|  |  |  | code = coursePackageOrder.getCode(); | 
|---|
|  |  |  | coursePackageOrder.setPayType(2); | 
|---|
|  |  |  | coursePackageOrder.setAppUserId(null); | 
|---|
|  |  |  | coursePackageOrder.setPayUserType(1); | 
|---|
|  |  |  | coursePackageOrder.setPayUserId(uid); | 
|---|
|  |  |  | coursePackageOrderService.updateById(coursePackageOrder); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ResultUtil alipay = payMoneyUtil.alipay("购买课程", "购买课程", "", code, paymentPrice.toString(), "/base/course/aliPaymentCourseCallback"); | 
|---|
|  |  |  | if(alipay.getCode() == 200){ | 
|---|
|  |  |  | // 判断这个课包属于哪个门店 属于哪个运营商 根据运营商 id 获取对应的商户号 | 
|---|
|  |  |  | Integer coursePackageId = paymentCourseVo.getId(); | 
|---|
|  |  |  | TCoursePackage byId = coursePackageService.getById(coursePackageId); | 
|---|
|  |  |  | Store store = storeClient.queryStoreById(byId.getStoreId()); | 
|---|
|  |  |  | if (store.getOperatorId() == null){ | 
|---|
|  |  |  | smid1 = smid; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | if (store.getOperatorId()==0){ | 
|---|
|  |  |  | smid1 = smid; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | smid1 = storeClient.getSMIDByOperatorId(store.getOperatorId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ResultUtil alipay = payMoneyUtil.alipay(smid1,"购买课程", "购买课程", | 
|---|
|  |  |  | coursePackagePaymentConfig.getId().toString(), | 
|---|
|  |  |  | code, paymentPrice.toString(), "/base/course/aliPaymentCourseCallback"); | 
|---|
|  |  |  | if (alipay.getCode() == 200) { | 
|---|
|  |  |  | String finalCode = code; | 
|---|
|  |  |  | new Thread(new Runnable() { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void run() { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Thread.sleep(1000); | 
|---|
|  |  |  | int num = 1; | 
|---|
|  |  |  | int wait = 0; | 
|---|
|  |  |  | while (num <= 10){ | 
|---|
|  |  |  | 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){ | 
|---|
|  |  |  | CoursePackageOrder coursePackageOrder1 = coursePackageOrderService.getOne(new QueryWrapper<CoursePackageOrder>() | 
|---|
|  |  |  | .eq("code", finalCode).eq("state", 1)); | 
|---|
|  |  |  | if (coursePackageOrder1.getPayStatus() == 2) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryALIOrder(code); | 
|---|
|  |  |  | if(resultUtil.getCode() == 200 && one.getPayStatus() == 1){ | 
|---|
|  |  |  | AlipayTradeQueryResponse alipayTradeQueryResponse = payMoneyUtil.queryALIOrder(finalCode); | 
|---|
|  |  |  | if (null != alipayTradeQueryResponse) { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 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); | 
|---|
|  |  |  | String s = alipayTradeQueryResponse.getTradeStatus(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String tradeNo = alipayTradeQueryResponse.getTradeNo(); | 
|---|
|  |  |  | if ("TRADE_CLOSED".equals(s) || "TRADE_FINISHED".equals(s) || num == 10) { | 
|---|
|  |  |  | //有待支付的订单,这里不处理 | 
|---|
|  |  |  | //                                    coursePackageOrder1.setState(3); | 
|---|
|  |  |  | //                                    coursePackageOrderService.updateById(coursePackageOrder1); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if("TRADE_SUCCESS".equals(s)){ | 
|---|
|  |  |  | for (TCoursePackagePayment coursePackagePayment : list) { | 
|---|
|  |  |  | coursePackagePayment.setPayStatus(2); | 
|---|
|  |  |  | coursePackagePayment.setOrderNumber(tradeNo); | 
|---|
|  |  |  | if ("TRADE_SUCCESS".equals(s)) { | 
|---|
|  |  |  | coursePackageOrder1.setPayStatus(2); | 
|---|
|  |  |  | coursePackageOrder1.setOrderNumber(tradeNo); | 
|---|
|  |  |  | coursePackageOrder1.setAppUserId(null); | 
|---|
|  |  |  | coursePackageOrderService.updateById(coursePackageOrder1); | 
|---|
|  |  |  | addCoursePackageOrderStudent(coursePackageOrder1.getId(), coursePackagePaymentConfig); | 
|---|
|  |  |  | moneyOut(tradeNo,tradeNo,finalCode); | 
|---|
|  |  |  | // 根据课程id 查询这个课程属于哪个门店 属于哪个运营商 | 
|---|
|  |  |  | Integer id = paymentCourseVo.getId(); | 
|---|
|  |  |  | TCoursePackage byId = coursePackageService.getById(id); | 
|---|
|  |  |  | Integer storeId = byId.getStoreId(); | 
|---|
|  |  |  | Store store = storeClient.queryStoreById(storeId); | 
|---|
|  |  |  | Integer operatorId = store.getOperatorId(); | 
|---|
|  |  |  | if (operatorId==null){ | 
|---|
|  |  |  | String smid ="2088330203191220"; | 
|---|
|  |  |  | // 说明是平台的 | 
|---|
|  |  |  | payMoneyUtil.confirm(smid,finalCode,tradeNo,paymentPrice.toString()); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | }else if (operatorId==0){ | 
|---|
|  |  |  | String smid ="2088330203191220"; | 
|---|
|  |  |  | // 说明是平台的 | 
|---|
|  |  |  | payMoneyUtil.confirm(smid,finalCode,tradeNo,paymentPrice.toString()); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | // 当前课程不属于门店 查询这个课程属于哪个门店 属于哪个运营商 | 
|---|
|  |  |  | String smidByOperatorId = storeClient.getSMIDByOperatorId(operatorId); | 
|---|
|  |  |  | payMoneyUtil.confirm(smidByOperatorId,finalCode,tradeNo,paymentPrice.toString()); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | coursePackagePaymentService.updateBatchById(list); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if("WAIT_BUYER_PAY".equals(s)){ | 
|---|
|  |  |  | if ("WAIT_BUYER_PAY".equals(s)) { | 
|---|
|  |  |  | num++; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //分账 | 
|---|
|  |  |  | public void moneyOut(String outNum, String tradeNo,String code) throws AlipayApiException { | 
|---|
|  |  |  | AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", aliAppid, appPrivateKey, "json", "UTF-8", alipay_public_key, "RSA2"); | 
|---|
|  |  |  | AlipayTradeOrderSettleRequest request = new AlipayTradeOrderSettleRequest(); | 
|---|
|  |  |  | AlipayTradeOrderSettleModel model = new AlipayTradeOrderSettleModel(); | 
|---|
|  |  |  | model.setOutRequestNo(outNum); | 
|---|
|  |  |  | model.setTradeNo(tradeNo); | 
|---|
|  |  |  | List<RoyaltyDetailInfos> royaltyDetailInfos = new ArrayList<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //        AlipayTradeRoyaltyRelationBindRequest request1 = new AlipayTradeRoyaltyRelationBindRequest(); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        request1.setBizContent("{" + | 
|---|
|  |  |  | //                "  \"receiver_list\":[" + | 
|---|
|  |  |  | //                "    {" + | 
|---|
|  |  |  | //                "      \"type\":\"loginName\"," + | 
|---|
|  |  |  | //                "      \"account\":\"19522115070\"," + | 
|---|
|  |  |  | //                "      \"name\":\"罗易胜\"," + | 
|---|
|  |  |  | //                "      \"memo\":\"分账给测试商户\"," + | 
|---|
|  |  |  | //                "    }" + | 
|---|
|  |  |  | //                "  ]," + | 
|---|
|  |  |  | //                "  \"out_request_no\":\"" + tradeNo + "\"" + | 
|---|
|  |  |  | //                "}"); | 
|---|
|  |  |  | //        AlipayTradeRoyaltyRelationBindResponse response = alipayClient.execute(request1); | 
|---|
|  |  |  | //        if (response.isSuccess()) { | 
|---|
|  |  |  | //            System.out.println("绑定调用成功"); | 
|---|
|  |  |  | //        } else { | 
|---|
|  |  |  | //            System.out.println("调用失败"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // | 
|---|
|  |  |  | CoursePackageOrder one = coursePackageOrderService.getOne(new QueryWrapper<CoursePackageOrder>().eq("code", code)); | 
|---|
|  |  |  | TCoursePackage coursePackage = coursePackageService.getById(one.getCoursePackageId()); | 
|---|
|  |  |  | OperatorUser operatorUser = storeClient.queryByStoreId(coursePackage.getStoreId()); | 
|---|
|  |  |  | if (operatorUser!=null) { | 
|---|
|  |  |  | if(one.getPayType()==2){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | OpenApiRoyaltyDetailInfoPojo op = new OpenApiRoyaltyDetailInfoPojo(); | 
|---|
|  |  |  | op.setTransOutType("loginName"); | 
|---|
|  |  |  | op.setTransOut("happysports@weparklife.com"); | 
|---|
|  |  |  | op.setTransInType("userId"); | 
|---|
|  |  |  | //            op.setTransInType("loginName"); | 
|---|
|  |  |  | //        op.setTransIn("19522115070"); | 
|---|
|  |  |  | op.setTransIn(operatorUser.getAlipayNum()); | 
|---|
|  |  |  | op.setAmountPercentage(Long.valueOf(operatorUser.getAlipayProportion())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<OpenApiRoyaltyDetailInfoPojo> ops = new ArrayList<>(); | 
|---|
|  |  |  | ops.add(op); | 
|---|
|  |  |  | model.setRoyaltyParameters(ops); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | request.setBizModel(model); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AlipayTradeOrderSettleResponse response1 = alipayClient.execute(request); | 
|---|
|  |  |  | if (response1.isSuccess()) { | 
|---|
|  |  |  | System.out.println("调用成功"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | System.out.println("调用失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 玩湃币支付课程 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public ResultUtil playPaiCoinPaymentCourse(AppUser appUser, Double paymentPrice, PaymentCourseVo paymentCourseVo) throws Exception { | 
|---|
|  |  |  | Integer playPaiCoins = appUser.getPlayPaiCoins(); | 
|---|
|  |  |  | if (playPaiCoins.compareTo(paymentPrice.intValue()) < 0) { | 
|---|
|  |  |  | return ResultUtil.error("玩湃币不足"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | appUser.setPlayPaiCoins(playPaiCoins - paymentPrice.intValue()); | 
|---|
|  |  |  | appUserClient.updateAppUser(appUser); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | CoursePackagePaymentConfig coursePackagePaymentConfig = coursePackagePaymentConfigService.getById(paymentCourseVo.getCoursePackagePaymentConfigId()); | 
|---|
|  |  |  | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); | 
|---|
|  |  |  | String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5); | 
|---|
|  |  |  | Long orderId = paymentCourseVo.getOrderId(); | 
|---|
|  |  |  | if(null == orderId){ | 
|---|
|  |  |  | //生成支付订单 | 
|---|
|  |  |  | CoursePackageOrder coursePackageOrder = new CoursePackageOrder(); | 
|---|
|  |  |  | coursePackageOrder.setCode(code); | 
|---|
|  |  |  | coursePackageOrder.setAppUserId(appUser.getId()); | 
|---|
|  |  |  | coursePackageOrder.setStudentIds(paymentCourseVo.getStudentIds()); | 
|---|
|  |  |  | coursePackageOrder.setCoursePackageId(paymentCourseVo.getId()); | 
|---|
|  |  |  | coursePackageOrder.setPayType(paymentCourseVo.getPayType()); | 
|---|
|  |  |  | coursePackageOrder.setClassHours(coursePackagePaymentConfig.getClassHours()); | 
|---|
|  |  |  | coursePackageOrder.setOriginalPrice(paymentCourseVo.getPrice()); | 
|---|
|  |  |  | coursePackageOrder.setUserCouponId(paymentCourseVo.getCouponId()); | 
|---|
|  |  |  | coursePackageOrder.setCashPayment(new BigDecimal(paymentPrice)); | 
|---|
|  |  |  | coursePackageOrder.setPlayPaiCoin(paymentCourseVo.getPrice().intValue()); | 
|---|
|  |  |  | coursePackageOrder.setPayUserType(1); | 
|---|
|  |  |  | coursePackageOrder.setPayStatus(2); | 
|---|
|  |  |  | coursePackageOrder.setPayUserId(appUser.getId()); | 
|---|
|  |  |  | coursePackageOrder.setStatus(1); | 
|---|
|  |  |  | coursePackageOrder.setState(1); | 
|---|
|  |  |  | coursePackageOrder.setInsertTime(new Date()); | 
|---|
|  |  |  | coursePackageOrderService.save(coursePackageOrder); | 
|---|
|  |  |  | orderId = coursePackageOrder.getId(); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | CoursePackageOrder coursePackageOrder = coursePackageOrderService.getById(orderId); | 
|---|
|  |  |  | coursePackageOrder.setPayType(3); | 
|---|
|  |  |  | coursePackageOrder.setAppUserId(null); | 
|---|
|  |  |  | coursePackageOrder.setPayUserId(appUser.getId()); | 
|---|
|  |  |  | coursePackageOrder.setPayUserType(1); | 
|---|
|  |  |  | coursePackageOrder.setPayStatus(2); | 
|---|
|  |  |  | coursePackageOrderService.updateById(coursePackageOrder); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | addCoursePackageOrderStudent(orderId, coursePackagePaymentConfig); | 
|---|
|  |  |  | return ResultUtil.success(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 购买课程支付成功后的回调处理 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param code | 
|---|
|  |  |  | * @param trade_no | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public ResultUtil paymentCourseCallback(String code, String trade_no, String attach) throws AlipayApiException { | 
|---|
|  |  |  | CoursePackageOrder coursePackageOrder1 = coursePackageOrderService.getOne(new QueryWrapper<CoursePackageOrder>() | 
|---|
|  |  |  | .eq("code", code).eq("state", 1)); | 
|---|
|  |  |  | if (coursePackageOrder1.getPayStatus() == 2) { | 
|---|
|  |  |  | return ResultUtil.success(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | coursePackageOrder1.setPayStatus(2); | 
|---|
|  |  |  | coursePackageOrder1.setOrderNumber(trade_no); | 
|---|
|  |  |  | coursePackageOrder1.setAppUserId(null); | 
|---|
|  |  |  | coursePackageOrderService.updateById(coursePackageOrder1); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | CoursePackagePaymentConfig coursePackagePaymentConfig = coursePackagePaymentConfigService.getById(attach); | 
|---|
|  |  |  | addCoursePackageOrderStudent(coursePackageOrder1.getId(), coursePackagePaymentConfig); | 
|---|
|  |  |  | moneyOut(trade_no,trade_no,code); | 
|---|
|  |  |  | return ResultUtil.success(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 支付成功后添加学员课时数据 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param coursePackagePaymentConfig | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void addCoursePackageOrderStudent(Long coursePackageOrderId, CoursePackagePaymentConfig coursePackagePaymentConfig) { | 
|---|
|  |  |  | CoursePackageOrder coursePackageOrder = coursePackageOrderService.getById(coursePackageOrderId); | 
|---|
|  |  |  | // 发放优惠券 | 
|---|
|  |  |  | userCouponClient.sendUserCoupon(new SendCouponReq(coursePackageOrder.getAppUserId(), coursePackagePaymentConfig.getCouponIds())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //开始处理学员课程课时记录和排课数据 | 
|---|
|  |  |  | TCoursePackage coursePackage = coursePackageService.getById(coursePackageOrder.getCoursePackageId()); | 
|---|
|  |  |  | String[] split = coursePackageOrder.getStudentIds().split(";"); | 
|---|
|  |  |  | for (String id : split) { | 
|---|
|  |  |  | if(coursePackage.getType() == 1){ | 
|---|
|  |  |  | //增加学员课时有效期 | 
|---|
|  |  |  | Student student = studentClient.queryStudentById(Integer.valueOf(id)); | 
|---|
|  |  |  | CoursePackageOrderStudent coursePackageOrderStudent = coursePackageOrderStudentService.getOne(new QueryWrapper<CoursePackageOrderStudent>().eq("studentId", id) | 
|---|
|  |  |  | .eq("coursePackageId", coursePackageOrder.getCoursePackageId()).eq("state", 1)); | 
|---|
|  |  |  | if (null == coursePackageOrderStudent) { | 
|---|
|  |  |  | coursePackageOrderStudent = new CoursePackageOrderStudent(); | 
|---|
|  |  |  | coursePackageOrderStudent.setAppUserId(coursePackageOrder.getAppUserId()); | 
|---|
|  |  |  | coursePackageOrderStudent.setStudentId(Integer.valueOf(id)); | 
|---|
|  |  |  | coursePackageOrderStudent.setCoursePackageId(coursePackageOrder.getCoursePackageId()); | 
|---|
|  |  |  | coursePackageOrderStudent.setTotalClassHours(coursePackagePaymentConfig.getClassHours()); | 
|---|
|  |  |  | coursePackageOrderStudent.setLaveClassHours(coursePackagePaymentConfig.getClassHours()); | 
|---|
|  |  |  | coursePackageOrderStudent.setAbsencesNumber(0); | 
|---|
|  |  |  | coursePackageOrderStudent.setStatus(1); | 
|---|
|  |  |  | coursePackageOrderStudent.setState(1); | 
|---|
|  |  |  | coursePackageOrderStudent.setInsertTime(new Date()); | 
|---|
|  |  |  | coursePackageOrderStudent.setGiftClassHours(0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer validDays = coursePackage.getValidDays(); | 
|---|
|  |  |  | Calendar calendar = Calendar.getInstance(); | 
|---|
|  |  |  | calendar.setTime(new Date()); | 
|---|
|  |  |  | calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + validDays); | 
|---|
|  |  |  | coursePackageOrderStudent.setUseTime(calendar.getTime()); | 
|---|
|  |  |  | coursePackageOrderStudentService.saveOrUpdate(coursePackageOrderStudent); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新学员课时有效期 | 
|---|
|  |  |  | if(null == student.getValidity()){ | 
|---|
|  |  |  | student.setValidity(calendar.getTime()); | 
|---|
|  |  |  | addOldPackageStudent(student); | 
|---|
|  |  |  | }else if(calendar.getTimeInMillis() > student.getValidity().getTime()){ | 
|---|
|  |  |  | student.setValidity(calendar.getTime()); | 
|---|
|  |  |  | addOldPackageStudent(student); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | studentClient.frozen(student); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //开始排课 | 
|---|
|  |  |  | addPackageStudent(coursePackage, coursePackageOrder.getAppUserId(), Integer.valueOf(id), coursePackageOrderStudent, student.getValidity()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //课时记录 | 
|---|
|  |  |  | CourseCounsum courseCounsum = new CourseCounsum(); | 
|---|
|  |  |  | courseCounsum.setPaymentId(coursePackageOrderStudent.getId()); | 
|---|
|  |  |  | courseCounsum.setChangeType(1); | 
|---|
|  |  |  | courseCounsum.setNum(coursePackagePaymentConfig.getClassHours()); | 
|---|
|  |  |  | courseCounsum.setInsertTime(new Date()); | 
|---|
|  |  |  | courseCounsum.setReason("购买课包"); | 
|---|
|  |  |  | courseCounsumService.save(courseCounsum); | 
|---|
|  |  |  | //账单记录 | 
|---|
|  |  |  | if(coursePackageOrder.getPayType() != 3){ | 
|---|
|  |  |  | CourseCounsum courseCounsum1 = new CourseCounsum(); | 
|---|
|  |  |  | courseCounsum1.setPaymentId(coursePackageOrder.getId()); | 
|---|
|  |  |  | courseCounsum1.setChangeType(3); | 
|---|
|  |  |  | courseCounsum1.setInsertTime(new Date()); | 
|---|
|  |  |  | courseCounsum1.setReason("报名课程;"+coursePackageOrder.getCashPayment()); | 
|---|
|  |  |  | courseCounsum1.setAppUserId(coursePackageOrder.getAppUserId()); | 
|---|
|  |  |  | courseCounsumService.save(courseCounsum1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | Date useTime = coursePackageOrderStudent.getUseTime(); | 
|---|
|  |  |  | coursePackageOrderStudent.setTotalClassHours(coursePackageOrderStudent.getTotalClassHours() + coursePackagePaymentConfig.getClassHours()); | 
|---|
|  |  |  | coursePackageOrderStudent.setLaveClassHours(coursePackageOrderStudent.getLaveClassHours() + coursePackagePaymentConfig.getClassHours()); | 
|---|
|  |  |  | coursePackageOrderStudent.setStatus(1); | 
|---|
|  |  |  | coursePackageOrderStudent.setInsertTime(new Date()); | 
|---|
|  |  |  | Integer validDays = coursePackage.getValidDays(); | 
|---|
|  |  |  | Calendar calendar = Calendar.getInstance(); | 
|---|
|  |  |  | calendar.setTime(useTime.compareTo(new Date()) < 0 ? new Date() : useTime); | 
|---|
|  |  |  | calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + validDays); | 
|---|
|  |  |  | coursePackageOrderStudent.setUseTime(calendar.getTime()); | 
|---|
|  |  |  | coursePackageOrderStudentService.saveOrUpdate(coursePackageOrderStudent); | 
|---|
|  |  |  | //更新学员课时有效期 | 
|---|
|  |  |  | if(null == student.getValidity()){ | 
|---|
|  |  |  | student.setValidity(calendar.getTime()); | 
|---|
|  |  |  | addOldPackageStudent(student); | 
|---|
|  |  |  | }else if(calendar.getTimeInMillis() > student.getValidity().getTime()){ | 
|---|
|  |  |  | student.setValidity(calendar.getTime()); | 
|---|
|  |  |  | addOldPackageStudent(student); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | studentClient.frozen(student); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //中间断课,没有连续续费的情况需要重新排课 | 
|---|
|  |  |  | if (useTime.compareTo(new Date()) < 0) { | 
|---|
|  |  |  | addPackageStudent(coursePackage, coursePackageOrder.getAppUserId(), Integer.valueOf(id), coursePackageOrderStudent, student.getValidity()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //课时记录 | 
|---|
|  |  |  | CourseCounsum courseCounsum = new CourseCounsum(); | 
|---|
|  |  |  | courseCounsum.setPaymentId(coursePackageOrderStudent.getId()); | 
|---|
|  |  |  | courseCounsum.setChangeType(1); | 
|---|
|  |  |  | courseCounsum.setNum(coursePackagePaymentConfig.getClassHours()); | 
|---|
|  |  |  | courseCounsum.setInsertTime(new Date()); | 
|---|
|  |  |  | courseCounsum.setReason("续课"); | 
|---|
|  |  |  | courseCounsumService.save(courseCounsum); | 
|---|
|  |  |  | //账单记录 | 
|---|
|  |  |  | if(coursePackageOrder.getPayType() != 3){ | 
|---|
|  |  |  | CourseCounsum courseCounsum1 = new CourseCounsum(); | 
|---|
|  |  |  | courseCounsum1.setPaymentId(coursePackageOrder.getId()); | 
|---|
|  |  |  | courseCounsum1.setChangeType(3); | 
|---|
|  |  |  | courseCounsum1.setInsertTime(new Date()); | 
|---|
|  |  |  | courseCounsum1.setReason("续课;"+coursePackageOrder.getCashPayment()); | 
|---|
|  |  |  | courseCounsum1.setAppUserId(coursePackageOrder.getAppUserId()); | 
|---|
|  |  |  | courseCounsumService.save(courseCounsum1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(coursePackage.getType() == 2){ | 
|---|
|  |  |  | addPackageStudent(coursePackage, coursePackageOrder.getAppUserId(), Integer.valueOf(id), null, null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 新购买课程后的排课 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param userId | 
|---|
|  |  |  | * @param sId | 
|---|
|  |  |  | * @throws ParseException | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void addPackageStudent(TCoursePackage tCoursePackage, Integer userId, Integer sId, CoursePackageOrderStudent coursePackageOrderStudent, Date validity) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | //1常规 2假期 3体验 | 
|---|
|  |  |  | if (tCoursePackage.getType() == 1) { | 
|---|
|  |  |  | //上课星期 | 
|---|
|  |  |  | String classWeeks = tCoursePackage.getClassWeeks(); | 
|---|
|  |  |  | List<Integer> week = week(classWeeks); | 
|---|
|  |  |  | CoursePackageScheduling one = coursePackageSchedulingService.getOne(new QueryWrapper<CoursePackageScheduling>() | 
|---|
|  |  |  | .eq("studentId", sId) | 
|---|
|  |  |  | .eq("coursePackageId", tCoursePackage.getId()) | 
|---|
|  |  |  | .eq("status", 1) | 
|---|
|  |  |  | .orderByDesc("classDate") | 
|---|
|  |  |  | .last(" limit 0, 1") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(null != one){ | 
|---|
|  |  |  | //先检测是否需要继续进行排课 | 
|---|
|  |  |  | Calendar calendar1 = Calendar.getInstance(); | 
|---|
|  |  |  | calendar1.setTime(one.getClassDate()); | 
|---|
|  |  |  | int day_week1 = calendar1.get(Calendar.DAY_OF_WEEK); | 
|---|
|  |  |  | day_week1 = day_week1 - 1 == 0 ? 7 : day_week1 - 1; | 
|---|
|  |  |  | int week_of_month = calendar1.get(Calendar.WEEK_OF_MONTH); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Calendar calendar2 = Calendar.getInstance(); | 
|---|
|  |  |  | calendar2.setTime(new Date()); | 
|---|
|  |  |  | int week_of_month1 = calendar2.get(Calendar.WEEK_OF_MONTH); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //最后一次的排课时间不在本周,且是一周的最后一天。(如果是本周则表明已经课时用完了) | 
|---|
|  |  |  | if(week.get(week.size() - 1).equals(day_week1) && week_of_month != week_of_month1){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //上课时段 | 
|---|
|  |  |  | String[] split = tCoursePackage.getClassStartTime().split(","); | 
|---|
|  |  |  | String[] split1 = tCoursePackage.getClassEndTime().split(","); | 
|---|
|  |  |  | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); | 
|---|
|  |  |  | SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //剩余课时 | 
|---|
|  |  |  | Integer laveClassHours = coursePackageOrderStudent.getLaveClassHours(); | 
|---|
|  |  |  | //扣除课时数 | 
|---|
|  |  |  | Integer codeTime = tCoursePackage.getCodeTime(); | 
|---|
|  |  |  | //排课 本周+下周,课时不够扣则直接剩余不排课 | 
|---|
|  |  |  | Calendar calendar = Calendar.getInstance(); | 
|---|
|  |  |  | calendar.setTime(new Date()); | 
|---|
|  |  |  | calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + 1); | 
|---|
|  |  |  | calendar.set(Calendar.HOUR_OF_DAY, 0); | 
|---|
|  |  |  | calendar.set(Calendar.MINUTE, 0); | 
|---|
|  |  |  | calendar.set(Calendar.SECOND, 0); | 
|---|
|  |  |  | int day_week = calendar.get(Calendar.DAY_OF_WEEK); | 
|---|
|  |  |  | day_week = day_week - 1 == 0 ? 7 : day_week - 1; | 
|---|
|  |  |  | int num = 8 - day_week + 7; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (int i = 0; i < num; i++) { | 
|---|
|  |  |  | Date time = calendar.getTime(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断当天是否在排课星期内 | 
|---|
|  |  |  | int day = calendar.get(Calendar.DAY_OF_WEEK); | 
|---|
|  |  |  | day = day - 1 == 0 ? 7 : day - 1; | 
|---|
|  |  |  | if (!week.contains(day)) { | 
|---|
|  |  |  | calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + 1); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //大于有效期不进行排课 | 
|---|
|  |  |  | if (calendar.getTimeInMillis() >= validity.getTime()) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //检查是否有体验购课 | 
|---|
|  |  |  | int count = coursePackageSchedulingService.count(new QueryWrapper<CoursePackageScheduling>() | 
|---|
|  |  |  | .eq("type", 3) | 
|---|
|  |  |  | .eq("appUserId", userId) | 
|---|
|  |  |  | .eq("studentId", sId) | 
|---|
|  |  |  | .eq("coursePackageId", tCoursePackage.getId()) | 
|---|
|  |  |  | .eq("status", 1) | 
|---|
|  |  |  | .eq("DATE_FORMAT(classDate, '%Y-%m-%d')", format.format(time)) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //有体验购课,不进行排课 | 
|---|
|  |  |  | if(count != 0){ | 
|---|
|  |  |  | calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + 1); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (int j = 0; j < split.length; j++) { | 
|---|
|  |  |  | //剩余数量不足以排课 | 
|---|
|  |  |  | if (laveClassHours.compareTo(codeTime) < 0) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | laveClassHours -= codeTime; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | CoursePackageScheduling coursePackageScheduling = new CoursePackageScheduling(); | 
|---|
|  |  |  | coursePackageScheduling.setType(tCoursePackage.getType()); | 
|---|
|  |  |  | coursePackageScheduling.setAppUserId(userId); | 
|---|
|  |  |  | coursePackageScheduling.setStudentId(sId); | 
|---|
|  |  |  | coursePackageScheduling.setCoursePackageId(tCoursePackage.getId()); | 
|---|
|  |  |  | Date parse = format1.parse(format.format(time) + " " + split[j]); | 
|---|
|  |  |  | Date parse1 = format1.parse(format.format(time) + " " + split1[j]); | 
|---|
|  |  |  | coursePackageScheduling.setClassDate(parse); | 
|---|
|  |  |  | coursePackageScheduling.setEndDate(parse1); | 
|---|
|  |  |  | coursePackageScheduling.setStatus(1); | 
|---|
|  |  |  | coursePackageSchedulingService.save(coursePackageScheduling); | 
|---|
|  |  |  | CoursePackageStudent student1 = new CoursePackageStudent(); | 
|---|
|  |  |  | student1.setAppUserId(userId); | 
|---|
|  |  |  | student1.setStudentId(sId); | 
|---|
|  |  |  | student1.setCoursePackageId(tCoursePackage.getId()); | 
|---|
|  |  |  | student1.setCoursePackagePaymentId(coursePackageOrderStudent.getId()); | 
|---|
|  |  |  | student1.setCoursePackageSchedulingId(coursePackageScheduling.getId()); | 
|---|
|  |  |  | student1.setSignInOrNot(1); | 
|---|
|  |  |  | student1.setReservationStatus(1); | 
|---|
|  |  |  | student1.setInsertTime(new Date()); | 
|---|
|  |  |  | cpsMapper.insert(student1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //增加日期,用于判断 | 
|---|
|  |  |  | calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + 1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (tCoursePackage.getType() == 2) { | 
|---|
|  |  |  | //上课星期 | 
|---|
|  |  |  | String classWeeks = tCoursePackage.getClassWeeks(); | 
|---|
|  |  |  | List<Integer> week = week(classWeeks); | 
|---|
|  |  |  | //上课时段 | 
|---|
|  |  |  | String[] split = tCoursePackage.getClassStartTime().split(","); | 
|---|
|  |  |  | String[] split1 = tCoursePackage.getClassEndTime().split(","); | 
|---|
|  |  |  | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); | 
|---|
|  |  |  | SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Date startTime = tCoursePackage.getStartTime(); | 
|---|
|  |  |  | Date endTime = tCoursePackage.getEndTime(); | 
|---|
|  |  |  | //排课 本周+下周,课时不够扣则直接剩余不排课 | 
|---|
|  |  |  | Calendar calendar = Calendar.getInstance(); | 
|---|
|  |  |  | //假期开始使用当前时间为起始时间进行排课 | 
|---|
|  |  |  | calendar.setTime(startTime.getTime() > System.currentTimeMillis() ? startTime : new Date()); | 
|---|
|  |  |  | calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + 1); | 
|---|
|  |  |  | while (true) { | 
|---|
|  |  |  | Date time = calendar.getTime(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断当天是否在排课星期内 | 
|---|
|  |  |  | int day = calendar.get(Calendar.DAY_OF_WEEK); | 
|---|
|  |  |  | day = day - 1 == 0 ? 7 : day - 1; | 
|---|
|  |  |  | if (!week.contains(day)) { | 
|---|
|  |  |  | calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + 1); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //大于有效期不进行排课 | 
|---|
|  |  |  | if (calendar.getTimeInMillis() > endTime.getTime()) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (int j = 0; j < split.length; j++) { | 
|---|
|  |  |  | CoursePackageScheduling coursePackageScheduling = new CoursePackageScheduling(); | 
|---|
|  |  |  | coursePackageScheduling.setType(tCoursePackage.getType()); | 
|---|
|  |  |  | coursePackageScheduling.setAppUserId(userId); | 
|---|
|  |  |  | coursePackageScheduling.setStudentId(sId); | 
|---|
|  |  |  | coursePackageScheduling.setCoursePackageId(tCoursePackage.getId()); | 
|---|
|  |  |  | Date parse = format1.parse(format.format(time) + " " + split[j]); | 
|---|
|  |  |  | Date parse1 = format1.parse(format.format(time) + " " + split1[j]); | 
|---|
|  |  |  | coursePackageScheduling.setClassDate(parse); | 
|---|
|  |  |  | coursePackageScheduling.setEndDate(parse1); | 
|---|
|  |  |  | coursePackageScheduling.setStatus(1); | 
|---|
|  |  |  | coursePackageSchedulingService.save(coursePackageScheduling); | 
|---|
|  |  |  | CoursePackageStudent student1 = new CoursePackageStudent(); | 
|---|
|  |  |  | student1.setAppUserId(userId); | 
|---|
|  |  |  | student1.setStudentId(sId); | 
|---|
|  |  |  | student1.setCoursePackageId(tCoursePackage.getId()); | 
|---|
|  |  |  | student1.setCoursePackagePaymentId(null); | 
|---|
|  |  |  | student1.setCoursePackageSchedulingId(coursePackageScheduling.getId()); | 
|---|
|  |  |  | student1.setSignInOrNot(1); | 
|---|
|  |  |  | student1.setReservationStatus(1); | 
|---|
|  |  |  | student1.setInsertTime(new Date()); | 
|---|
|  |  |  | cpsMapper.insert(student1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //增加日期,用于判断 | 
|---|
|  |  |  | calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + 1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 课时有效期更新后-更新历史排课数据(因有效期限制的排课数据,还有剩余课时) | 
|---|
|  |  |  | * @param student | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void addOldPackageStudent(Student student){ | 
|---|
|  |  |  | Integer studentId = student.getId(); | 
|---|
|  |  |  | Date validity = student.getValidity(); | 
|---|
|  |  |  | List<CoursePackageOrderStudent> list = coursePackageOrderStudentService.list(new QueryWrapper<CoursePackageOrderStudent>() | 
|---|
|  |  |  | .eq("studentId", studentId) | 
|---|
|  |  |  | .eq("status", 1) | 
|---|
|  |  |  | .gt("laveClassHours", 0) | 
|---|
|  |  |  | .eq("state", 1) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | 
|---|
|  |  |  | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | for (CoursePackageOrderStudent coursePackageOrderStudent : list) { | 
|---|
|  |  |  | TCoursePackage coursePackage = coursePackageService.getById(coursePackageOrderStudent.getCoursePackageId()); | 
|---|
|  |  |  | CoursePackageScheduling one = coursePackageSchedulingService.getOne(new QueryWrapper<CoursePackageScheduling>() | 
|---|
|  |  |  | .eq("studentId", studentId) | 
|---|
|  |  |  | .eq("coursePackageId", coursePackageOrderStudent.getCoursePackageId()) | 
|---|
|  |  |  | .eq("status", 1) | 
|---|
|  |  |  | .orderByDesc("classDate") | 
|---|
|  |  |  | .last(" limit 0, 1") | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Calendar calendar = Calendar.getInstance(); | 
|---|
|  |  |  | //上课星期 | 
|---|
|  |  |  | String classWeeks = coursePackage.getClassWeeks(); | 
|---|
|  |  |  | List<Integer> week = week(classWeeks); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer laveClassHours = coursePackageOrderStudent.getLaveClassHours(); | 
|---|
|  |  |  | Integer codeTime = coursePackage.getCodeTime(); | 
|---|
|  |  |  | String classStartTime = coursePackage.getClassStartTime(); | 
|---|
|  |  |  | String classEndTime = coursePackage.getClassEndTime(); | 
|---|
|  |  |  | String[] split = classStartTime.split(","); | 
|---|
|  |  |  | String[] split1 = classEndTime.split(","); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(null == one){ | 
|---|
|  |  |  | calendar.setTime(new Date()); | 
|---|
|  |  |  | calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + 1); | 
|---|
|  |  |  | calendar.set(Calendar.HOUR_OF_DAY, 0); | 
|---|
|  |  |  | calendar.set(Calendar.MINUTE, 0); | 
|---|
|  |  |  | calendar.set(Calendar.SECOND, 0); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | String format = sdf1.format(one.getClassDate()); | 
|---|
|  |  |  | String time = format.substring(format.indexOf(" ") + 1); | 
|---|
|  |  |  | int n = Arrays.asList(split).indexOf(time); | 
|---|
|  |  |  | if(n != split.length - 1){ | 
|---|
|  |  |  | calendar.setTime(one.getClassDate()); | 
|---|
|  |  |  | //单独处理当天的剩余时间段 | 
|---|
|  |  |  | n++; | 
|---|
|  |  |  | for (int i = n; i < split.length; i++) { | 
|---|
|  |  |  | //剩余数量不足以排课 | 
|---|
|  |  |  | if (laveClassHours.compareTo(codeTime) < 0) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | laveClassHours -= codeTime; | 
|---|
|  |  |  | CoursePackageScheduling packageScheduling = new CoursePackageScheduling(); | 
|---|
|  |  |  | packageScheduling.setType(coursePackage.getType()); | 
|---|
|  |  |  | packageScheduling.setAppUserId(coursePackageOrderStudent.getAppUserId()); | 
|---|
|  |  |  | packageScheduling.setStudentId(coursePackageOrderStudent.getStudentId()); | 
|---|
|  |  |  | packageScheduling.setCoursePackageId(coursePackage.getId()); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Date parse = sdf.parse(format.format(time) + " " + split[i]); | 
|---|
|  |  |  | Date parse1 = sdf.parse(format.format(time) + " " + split1[i]); | 
|---|
|  |  |  | packageScheduling.setClassDate(parse); | 
|---|
|  |  |  | packageScheduling.setEndDate(parse1); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | packageScheduling.setStatus(1); | 
|---|
|  |  |  | coursePackageSchedulingService.save(packageScheduling); | 
|---|
|  |  |  | CoursePackageStudent student1 = new CoursePackageStudent(); | 
|---|
|  |  |  | student1.setAppUserId(coursePackageOrderStudent.getAppUserId()); | 
|---|
|  |  |  | student1.setStudentId(coursePackageOrderStudent.getStudentId()); | 
|---|
|  |  |  | student1.setCoursePackageId(coursePackage.getId()); | 
|---|
|  |  |  | student1.setCoursePackagePaymentId(coursePackageOrderStudent.getId()); | 
|---|
|  |  |  | student1.setCoursePackageSchedulingId(packageScheduling.getId()); | 
|---|
|  |  |  | student1.setSignInOrNot(1); | 
|---|
|  |  |  | student1.setReservationStatus(1); | 
|---|
|  |  |  | student1.setInsertTime(new Date()); | 
|---|
|  |  |  | coursePackageStudentMapper.insert(student1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | //先检测是否需要继续进行排课 | 
|---|
|  |  |  | Calendar calendar1 = Calendar.getInstance(); | 
|---|
|  |  |  | calendar1.setTime(one.getClassDate()); | 
|---|
|  |  |  | int day_week1 = calendar1.get(Calendar.DAY_OF_WEEK); | 
|---|
|  |  |  | day_week1 = day_week1 - 1 == 0 ? 7 : day_week1 - 1; | 
|---|
|  |  |  | int week_of_month = calendar1.get(Calendar.WEEK_OF_MONTH); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Calendar calendar2 = Calendar.getInstance(); | 
|---|
|  |  |  | calendar2.setTime(new Date()); | 
|---|
|  |  |  | int week_of_month1 = calendar2.get(Calendar.WEEK_OF_MONTH); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //最后一次的排课时间不在本周,且是一周的最后一天。(如果是本周则表明已经课时用完了) | 
|---|
|  |  |  | if(week.get(week.size() - 1).equals(day_week1) && week_of_month != week_of_month1){ | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | calendar.setTime(one.getClassDate()); | 
|---|
|  |  |  | calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + 1); | 
|---|
|  |  |  | calendar.set(Calendar.HOUR_OF_DAY, 0); | 
|---|
|  |  |  | calendar.set(Calendar.MINUTE, 0); | 
|---|
|  |  |  | calendar.set(Calendar.SECOND, 0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int day_week = calendar.get(Calendar.DAY_OF_WEEK); | 
|---|
|  |  |  | day_week = day_week - 1 == 0 ? 7 : day_week - 1; | 
|---|
|  |  |  | int num = 8 - day_week + 7; | 
|---|
|  |  |  | for (int i = 0; i < num; i++) { | 
|---|
|  |  |  | Date time1 = calendar.getTime(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断当天是否在排课星期内 | 
|---|
|  |  |  | int day = calendar.get(Calendar.DAY_OF_WEEK); | 
|---|
|  |  |  | day = day - 1 == 0 ? 7 : day - 1; | 
|---|
|  |  |  | if (!week.contains(day)) { | 
|---|
|  |  |  | calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + 1); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //大于有效期不进行排课 | 
|---|
|  |  |  | if (calendar.getTimeInMillis() >= validity.getTime()) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (int j = 0; j < split.length; j++) { | 
|---|
|  |  |  | //剩余数量不足以排课 | 
|---|
|  |  |  | if (laveClassHours.compareTo(codeTime) < 0) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | laveClassHours -= codeTime; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | CoursePackageScheduling packageScheduling = new CoursePackageScheduling(); | 
|---|
|  |  |  | packageScheduling.setType(coursePackage.getType()); | 
|---|
|  |  |  | packageScheduling.setAppUserId(coursePackageOrderStudent.getAppUserId()); | 
|---|
|  |  |  | packageScheduling.setStudentId(coursePackageOrderStudent.getStudentId()); | 
|---|
|  |  |  | packageScheduling.setCoursePackageId(coursePackage.getId()); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Date parse = sdf1.parse(sdf.format(time1) + " " + split[j]); | 
|---|
|  |  |  | Date parse1 = sdf1.parse(sdf.format(time1) + " " + split1[j]); | 
|---|
|  |  |  | packageScheduling.setClassDate(parse); | 
|---|
|  |  |  | packageScheduling.setEndDate(parse1); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | packageScheduling.setStatus(1); | 
|---|
|  |  |  | coursePackageSchedulingService.save(packageScheduling); | 
|---|
|  |  |  | CoursePackageStudent student1 = new CoursePackageStudent(); | 
|---|
|  |  |  | student1.setAppUserId(coursePackageOrderStudent.getAppUserId()); | 
|---|
|  |  |  | student1.setStudentId(coursePackageOrderStudent.getStudentId()); | 
|---|
|  |  |  | student1.setCoursePackageId(coursePackage.getId()); | 
|---|
|  |  |  | student1.setCoursePackagePaymentId(coursePackageOrderStudent.getId()); | 
|---|
|  |  |  | student1.setCoursePackageSchedulingId(packageScheduling.getId()); | 
|---|
|  |  |  | student1.setSignInOrNot(1); | 
|---|
|  |  |  | student1.setReservationStatus(1); | 
|---|
|  |  |  | student1.setInsertTime(new Date()); | 
|---|
|  |  |  | coursePackageStudentMapper.insert(student1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //增加日期,用于判断 | 
|---|
|  |  |  | calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + 1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static Date[] generateDateArray1(Date startDate, Date endDate) { | 
|---|
|  |  |  | List<Date> dateList = new ArrayList<>(); | 
|---|
|  |  |  | Calendar calendar = Calendar.getInstance(); | 
|---|
|  |  |  | calendar.setTime(startDate); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | while (!calendar.getTime().after(endDate)) { | 
|---|
|  |  |  | Date currentDate = calendar.getTime(); | 
|---|
|  |  |  | dateList.add(currentDate); | 
|---|
|  |  |  | calendar.add(Calendar.DAY_OF_MONTH, 1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return dateList.toArray(new Date[0]); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static Date createDate1(int year, int month, int day) { | 
|---|
|  |  |  | Calendar calendar = Calendar.getInstance(); | 
|---|
|  |  |  | calendar.set(year, month - 1, day); | 
|---|
|  |  |  | return calendar.getTime(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private List<Integer> week(String week) { | 
|---|
|  |  |  | String[] split = week.split(";"); | 
|---|
|  |  |  | ArrayList<Integer> integers = new ArrayList<>(); | 
|---|
|  |  |  | for (String s : split) { | 
|---|
|  |  |  | switch (s) { | 
|---|
|  |  |  | case "周一": | 
|---|
|  |  |  | integers.add(1); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case "周二": | 
|---|
|  |  |  | integers.add(2); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case "周三": | 
|---|
|  |  |  | integers.add(3); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case "周四": | 
|---|
|  |  |  | integers.add(4); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case "周五": | 
|---|
|  |  |  | integers.add(5); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case "周六": | 
|---|
|  |  |  | integers.add(6); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case "周日": | 
|---|
|  |  |  | integers.add(7); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return integers; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static Date[] generateDateArray(int numDays, Date date) { | 
|---|
|  |  |  | //        LocalDate tomorrow = LocalDate.now().plusDays(1); | 
|---|
|  |  |  | LocalDate tomorrow = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate().plusDays(1); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Date[] dates = new Date[numDays]; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (int i = 0; i < numDays; i++) { | 
|---|
|  |  |  | LocalDate currentDate = tomorrow.plusDays(i); | 
|---|
|  |  |  | dates[i] = Date.from(currentDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return dates; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取课包管理列表数据 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param queryCoursePackageLists | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | boolean coin = false; | 
|---|
|  |  |  | List<CoursePackagePaymentConfig> coursePackagePaymentConfigs = coursePackagePaymentConfigService.list(new QueryWrapper<CoursePackagePaymentConfig>().eq("coursePackageId", id)); | 
|---|
|  |  |  | for (CoursePackagePaymentConfig coursePackagePaymentConfig : coursePackagePaymentConfigs) { | 
|---|
|  |  |  | if(0 != coursePackagePaymentConfig.getCashPayment()){ | 
|---|
|  |  |  | if (0 != coursePackagePaymentConfig.getCashPayment()) { | 
|---|
|  |  |  | cash = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(0 != coursePackagePaymentConfig.getPlayPaiCoin()){ | 
|---|
|  |  |  | if (0 != coursePackagePaymentConfig.getPlayPaiCoin()) { | 
|---|
|  |  |  | coin = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | map.put("payType", (cash ? "现金支付" : "") + (coin ?  cash ? "&玩湃币支付" : "玩湃币支付" : "")); | 
|---|
|  |  |  | map.put("payType", (cash ? "现金支付" : "") + (coin ? cash ? "&玩湃币支付" : "玩湃币支付" : "")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return list; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 添加课包 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param coursePackage | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Integer addCoursePackage(TCoursePackage coursePackage) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | coursePackage.setInsertTime(new Date()); | 
|---|
|  |  |  | this.baseMapper.insert(coursePackage); | 
|---|
|  |  |  | //生成排课数据 | 
|---|
|  |  |  | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | 
|---|
|  |  |  | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | Date date = sdf1.parse(sdf.format(new Date()) + " 00:00:00"); | 
|---|
|  |  |  | List<String> list = Arrays.asList(coursePackage.getClassWeeks().split(";")); | 
|---|
|  |  |  | String classStartTime = coursePackage.getClassStartTime(); | 
|---|
|  |  |  | String[] split = classStartTime.split(":"); | 
|---|
|  |  |  | String classEndTime = coursePackage.getClassEndTime(); | 
|---|
|  |  |  | String[] split1 = classEndTime.split(":"); | 
|---|
|  |  |  | Calendar s = Calendar.getInstance(); | 
|---|
|  |  |  | s.setTime(date); | 
|---|
|  |  |  | s.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) + 1); | 
|---|
|  |  |  | s.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split[0])); | 
|---|
|  |  |  | s.set(Calendar.MINUTE, Integer.valueOf(split[1])); | 
|---|
|  |  |  | s.set(Calendar.SECOND, 0); | 
|---|
|  |  |  | if (coursePackage.getClassStartTime() != null && coursePackage.getClassStartTime() != "") { | 
|---|
|  |  |  | //生成排课数据 | 
|---|
|  |  |  | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | 
|---|
|  |  |  | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | Date date = sdf1.parse(sdf.format(new Date()) + " 00:00:00"); | 
|---|
|  |  |  | List<String> list = Arrays.asList(coursePackage.getClassWeeks().split(";")); | 
|---|
|  |  |  | String value = coursePackage.getClassStartTime(); | 
|---|
|  |  |  | String value1 = coursePackage.getClassEndTime().trim(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Calendar e = Calendar.getInstance(); | 
|---|
|  |  |  | e.setTime(date); | 
|---|
|  |  |  | e.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) + 13); | 
|---|
|  |  |  | long timeInMillis = e.getTimeInMillis(); | 
|---|
|  |  |  | String[] star = value.split(","); | 
|---|
|  |  |  | String[] end = value1.split(","); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | while (true){ | 
|---|
|  |  |  | int w = s.get(Calendar.DAY_OF_WEEK); | 
|---|
|  |  |  | WeekEnum weekEnum = WeekEnum.getWeekEnum(w); | 
|---|
|  |  |  | if(list.contains(weekEnum.getChineseName())){ | 
|---|
|  |  |  | Calendar classDate = Calendar.getInstance(); | 
|---|
|  |  |  | classDate.setTime(s.getTime()); | 
|---|
|  |  |  | classDate.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split[0])); | 
|---|
|  |  |  | classDate.set(Calendar.MINUTE, Integer.valueOf(split[1])); | 
|---|
|  |  |  | classDate.set(Calendar.SECOND, 0); | 
|---|
|  |  |  | for (int i = 0; i < star.length; i++) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Calendar endDate = Calendar.getInstance(); | 
|---|
|  |  |  | endDate.setTime(s.getTime()); | 
|---|
|  |  |  | endDate.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split1[0])); | 
|---|
|  |  |  | endDate.set(Calendar.MINUTE, Integer.valueOf(split1[1])); | 
|---|
|  |  |  | endDate.set(Calendar.SECOND, 0); | 
|---|
|  |  |  | //                int index = star[i].indexOf(","); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                String result = value.substring(0, index).trim(); | 
|---|
|  |  |  | String classStartTime = star[i]; | 
|---|
|  |  |  | String[] split = classStartTime.split(":"); | 
|---|
|  |  |  | //            String value1 = en; | 
|---|
|  |  |  | int index1 = value1.indexOf(","); | 
|---|
|  |  |  | //                String result1 = value.substring(0, index1).trim(); | 
|---|
|  |  |  | String classEndTime = end[i]; | 
|---|
|  |  |  | String[] split1 = classEndTime.split(":"); | 
|---|
|  |  |  | Calendar s = Calendar.getInstance(); | 
|---|
|  |  |  | s.setTime(date); | 
|---|
|  |  |  | s.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) + 1); | 
|---|
|  |  |  | s.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split[0])); | 
|---|
|  |  |  | s.set(Calendar.MINUTE, Integer.valueOf(split[1])); | 
|---|
|  |  |  | s.set(Calendar.SECOND, 0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | CoursePackageScheduling coursePackageScheduling = new CoursePackageScheduling(); | 
|---|
|  |  |  | coursePackageScheduling.setCoursePackageId(coursePackage.getId()); | 
|---|
|  |  |  | coursePackageScheduling.setClassDate(classDate.getTime()); | 
|---|
|  |  |  | coursePackageScheduling.setEndDate(endDate.getTime()); | 
|---|
|  |  |  | coursePackageScheduling.setStatus(1); | 
|---|
|  |  |  | coursePackageSchedulingService.save(coursePackageScheduling); | 
|---|
|  |  |  | Calendar e = Calendar.getInstance(); | 
|---|
|  |  |  | e.setTime(date); | 
|---|
|  |  |  | e.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) + 14); | 
|---|
|  |  |  | long timeInMillis = e.getTimeInMillis(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | while (true) { | 
|---|
|  |  |  | int w = s.get(Calendar.DAY_OF_WEEK); | 
|---|
|  |  |  | WeekEnum weekEnum = WeekEnum.getWeekEnum(w); | 
|---|
|  |  |  | if (list.contains(weekEnum.getChineseName())) { | 
|---|
|  |  |  | Calendar classDate = Calendar.getInstance(); | 
|---|
|  |  |  | classDate.setTime(s.getTime()); | 
|---|
|  |  |  | classDate.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split[0])); | 
|---|
|  |  |  | classDate.set(Calendar.MINUTE, Integer.valueOf(split[1])); | 
|---|
|  |  |  | classDate.set(Calendar.SECOND, 0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Calendar endDate = Calendar.getInstance(); | 
|---|
|  |  |  | endDate.setTime(s.getTime()); | 
|---|
|  |  |  | endDate.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split1[0])); | 
|---|
|  |  |  | endDate.set(Calendar.MINUTE, Integer.valueOf(split1[1])); | 
|---|
|  |  |  | endDate.set(Calendar.SECOND, 0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | CoursePackageScheduling coursePackageScheduling = new CoursePackageScheduling(); | 
|---|
|  |  |  | coursePackageScheduling.setCoursePackageId(coursePackage.getId()); | 
|---|
|  |  |  | coursePackageScheduling.setClassDate(classDate.getTime()); | 
|---|
|  |  |  | coursePackageScheduling.setEndDate(endDate.getTime()); | 
|---|
|  |  |  | coursePackageScheduling.setStatus(1); | 
|---|
|  |  |  | coursePackageSchedulingService.save(coursePackageScheduling); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | s.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) + 1); | 
|---|
|  |  |  | if (s.getTimeInMillis() >= timeInMillis) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | s.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) + 1); | 
|---|
|  |  |  | if(s.getTimeInMillis() > timeInMillis){ | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return coursePackage.getId(); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ICoursePackageOrderStudentService orderStudentService; | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 修改数据 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param coursePackage | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void updateCoursePackageById(TCoursePackage coursePackage) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | List<CoursePackageStudent> coursePackageStudents = coursePackageStudentService.list(new QueryWrapper<CoursePackageStudent>().eq("coursePackageId", coursePackage.getId())); | 
|---|
|  |  |  | List<Long> collect = coursePackageStudents.stream().map(CoursePackageStudent::getCoursePackageSchedulingId).collect(Collectors.toList()); | 
|---|
|  |  |  | //        try { | 
|---|
|  |  |  | //            List<CoursePackageStudent> coursePackageStudents = coursePackageStudentService.list(new QueryWrapper<CoursePackageStudent>().eq("coursePackageId", coursePackage.getId())); | 
|---|
|  |  |  | //            List<Long> collect = coursePackageStudents.stream().map(CoursePackageStudent::getCoursePackageSchedulingId).collect(Collectors.toList()); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            QueryWrapper<CoursePackageScheduling> coursePackageSchedulingQueryWrapper = new QueryWrapper<CoursePackageScheduling>().eq("coursePackageId", coursePackage.getId()); | 
|---|
|  |  |  | //            if (collect.size() > 0) { | 
|---|
|  |  |  | //                coursePackageSchedulingQueryWrapper.notIn("id", collect); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //            coursePackageSchedulingService.remove(coursePackageSchedulingQueryWrapper); | 
|---|
|  |  |  | //            int coursePackageId = orderStudentService.count(new QueryWrapper<CoursePackageOrderStudent>().eq("coursePackageId", coursePackage.getId())); | 
|---|
|  |  |  | //            if (coursePackageId>0) { | 
|---|
|  |  |  | this.baseMapper.updateById(coursePackage); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | QueryWrapper<CoursePackageScheduling> coursePackageSchedulingQueryWrapper = new QueryWrapper<CoursePackageScheduling>().eq("coursePackageId", coursePackage.getId()); | 
|---|
|  |  |  | if(collect.size() > 0){ | 
|---|
|  |  |  | coursePackageSchedulingQueryWrapper.notIn("id", collect); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | coursePackageSchedulingService.remove(coursePackageSchedulingQueryWrapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | this.baseMapper.updateById(coursePackage); | 
|---|
|  |  |  | //生成排课数据 | 
|---|
|  |  |  | Date date = null; | 
|---|
|  |  |  | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | 
|---|
|  |  |  | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | CoursePackageScheduling coursePackageScheduling = coursePackageSchedulingService.getOne(new QueryWrapper<CoursePackageScheduling>().eq("coursePackageId", coursePackage.getId()).last(" and classDate > now() order by classDate desc limit 0, 1")); | 
|---|
|  |  |  | if(null != coursePackageScheduling){ | 
|---|
|  |  |  | date = sdf1.parse(sdf.format(coursePackageScheduling.getClassDate()) + " 00:00:00"); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | date = sdf1.parse(sdf.format(new Date()) + " 00:00:00"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<String> list = Arrays.asList(coursePackage.getClassWeeks().split(";")); | 
|---|
|  |  |  | String classStartTime = coursePackage.getClassStartTime(); | 
|---|
|  |  |  | String[] split = classStartTime.split(":"); | 
|---|
|  |  |  | String classEndTime = coursePackage.getClassEndTime(); | 
|---|
|  |  |  | String[] split1 = classEndTime.split(":"); | 
|---|
|  |  |  | Calendar s = Calendar.getInstance(); | 
|---|
|  |  |  | s.setTime(date); | 
|---|
|  |  |  | s.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) + 1); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Calendar e = Calendar.getInstance(); | 
|---|
|  |  |  | e.setTime(date); | 
|---|
|  |  |  | if(null != coursePackageScheduling){ | 
|---|
|  |  |  | long time = sdf1.parse(sdf.format(new Date()) + " 00:00:00").getTime(); | 
|---|
|  |  |  | int d = Long.valueOf(14L - ((s.getTimeInMillis() - time) / 86400000L)).intValue(); | 
|---|
|  |  |  | e.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) + d); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | e.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) + 13); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | long timeInMillis = e.getTimeInMillis(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | while (true){ | 
|---|
|  |  |  | int w = s.get(Calendar.DAY_OF_WEEK); | 
|---|
|  |  |  | WeekEnum weekEnum = WeekEnum.getWeekEnum(w); | 
|---|
|  |  |  | if(list.contains(weekEnum.getChineseName())){ | 
|---|
|  |  |  | Calendar classDate = Calendar.getInstance(); | 
|---|
|  |  |  | classDate.setTime(s.getTime()); | 
|---|
|  |  |  | classDate.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split[0])); | 
|---|
|  |  |  | classDate.set(Calendar.MINUTE, Integer.valueOf(split[1])); | 
|---|
|  |  |  | classDate.set(Calendar.SECOND, 0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Calendar endDate = Calendar.getInstance(); | 
|---|
|  |  |  | endDate.setTime(s.getTime()); | 
|---|
|  |  |  | endDate.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split1[0])); | 
|---|
|  |  |  | endDate.set(Calendar.MINUTE, Integer.valueOf(split1[1])); | 
|---|
|  |  |  | endDate.set(Calendar.SECOND, 0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | CoursePackageScheduling coursePackageScheduling1 = new CoursePackageScheduling(); | 
|---|
|  |  |  | coursePackageScheduling1.setCoursePackageId(coursePackage.getId()); | 
|---|
|  |  |  | coursePackageScheduling1.setClassDate(classDate.getTime()); | 
|---|
|  |  |  | coursePackageScheduling1.setEndDate(endDate.getTime()); | 
|---|
|  |  |  | coursePackageScheduling1.setStatus(1); | 
|---|
|  |  |  | coursePackageSchedulingService.save(coursePackageScheduling1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | s.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) + 1); | 
|---|
|  |  |  | if(s.getTimeInMillis() > timeInMillis){ | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //生成排课数据 | 
|---|
|  |  |  | //                Date date = null; | 
|---|
|  |  |  | //                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | 
|---|
|  |  |  | //                SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | //                CoursePackageScheduling coursePackageScheduling = coursePackageSchedulingService.getOne(new QueryWrapper<CoursePackageScheduling>().eq("coursePackageId", coursePackage.getId()).last(" and classDate > now() order by classDate desc limit 0, 1")); | 
|---|
|  |  |  | //                if (null != coursePackageScheduling) { | 
|---|
|  |  |  | //                    date = sdf1.parse(sdf.format(coursePackageScheduling.getClassDate()) + " 00:00:00"); | 
|---|
|  |  |  | //                } else { | 
|---|
|  |  |  | //                    date = sdf1.parse(sdf.format(new Date()) + " 00:00:00"); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                List<String> list = Arrays.asList(coursePackage.getClassWeeks().split(";")); | 
|---|
|  |  |  | //                String classStartTime = coursePackage.getClassStartTime(); | 
|---|
|  |  |  | //                String[] split = classStartTime.split(":"); | 
|---|
|  |  |  | //                String classEndTime = coursePackage.getClassEndTime(); | 
|---|
|  |  |  | //                String[] split1 = classEndTime.split(":"); | 
|---|
|  |  |  | //                Calendar s = Calendar.getInstance(); | 
|---|
|  |  |  | //                s.setTime(date); | 
|---|
|  |  |  | //                s.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) + 1); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                Calendar e = Calendar.getInstance(); | 
|---|
|  |  |  | //                e.setTime(date); | 
|---|
|  |  |  | //                if (null != coursePackageScheduling) { | 
|---|
|  |  |  | //                    long time = sdf1.parse(sdf.format(new Date()) + " 00:00:00").getTime(); | 
|---|
|  |  |  | //                    int d = Long.valueOf(14L - ((s.getTimeInMillis() - time) / 86400000L)).intValue(); | 
|---|
|  |  |  | //                    e.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) + d); | 
|---|
|  |  |  | //                } else { | 
|---|
|  |  |  | //                    e.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) + 14); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                long timeInMillis = e.getTimeInMillis(); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                while (true) { | 
|---|
|  |  |  | //                    int w = s.get(Calendar.DAY_OF_WEEK); | 
|---|
|  |  |  | //                    WeekEnum weekEnum = WeekEnum.getWeekEnum(w); | 
|---|
|  |  |  | //                    if (list.contains(weekEnum.getChineseName())) { | 
|---|
|  |  |  | //                        Calendar classDate = Calendar.getInstance(); | 
|---|
|  |  |  | //                        classDate.setTime(s.getTime()); | 
|---|
|  |  |  | //                        classDate.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split[0])); | 
|---|
|  |  |  | //                        classDate.set(Calendar.MINUTE, Integer.valueOf(split[1])); | 
|---|
|  |  |  | //                        classDate.set(Calendar.SECOND, 0); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                        Calendar endDate = Calendar.getInstance(); | 
|---|
|  |  |  | //                        endDate.setTime(s.getTime()); | 
|---|
|  |  |  | //                        endDate.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split1[0])); | 
|---|
|  |  |  | //                        endDate.set(Calendar.MINUTE, Integer.valueOf(split1[1])); | 
|---|
|  |  |  | //                        endDate.set(Calendar.SECOND, 0); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                        CoursePackageScheduling coursePackageScheduling1 = new CoursePackageScheduling(); | 
|---|
|  |  |  | //                        coursePackageScheduling1.setCoursePackageId(coursePackage.getId()); | 
|---|
|  |  |  | //                        coursePackageScheduling1.setClassDate(classDate.getTime()); | 
|---|
|  |  |  | //                        coursePackageScheduling1.setEndDate(endDate.getTime()); | 
|---|
|  |  |  | //                        coursePackageScheduling1.setStatus(1); | 
|---|
|  |  |  | //                        coursePackageSchedulingService.save(coursePackageScheduling1); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                    s.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) + 1); | 
|---|
|  |  |  | //                    if (s.getTimeInMillis() > timeInMillis) { | 
|---|
|  |  |  | //                        break; | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } catch (Exception e) { | 
|---|
|  |  |  | //            e.printStackTrace(); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取课包审核列表 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param page | 
|---|
|  |  |  | * @param queryExamineCoursePackageLists | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | 
|---|
|  |  |  | boolean coin = false; | 
|---|
|  |  |  | List<CoursePackagePaymentConfig> coursePackagePaymentConfigs = coursePackagePaymentConfigService.list(new QueryWrapper<CoursePackagePaymentConfig>().eq("coursePackageId", id)); | 
|---|
|  |  |  | for (CoursePackagePaymentConfig coursePackagePaymentConfig : coursePackagePaymentConfigs) { | 
|---|
|  |  |  | if(0 != coursePackagePaymentConfig.getCashPayment()){ | 
|---|
|  |  |  | if (0 != coursePackagePaymentConfig.getCashPayment()) { | 
|---|
|  |  |  | cash = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(0 != coursePackagePaymentConfig.getPlayPaiCoin()){ | 
|---|
|  |  |  | if (0 != coursePackagePaymentConfig.getPlayPaiCoin()) { | 
|---|
|  |  |  | coin = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | map.put("payType", (cash ? "现金支付" : "") + (coin ?  cash ? "&玩湃币支付" : "玩湃币支付" : "")); | 
|---|
|  |  |  | map.put("payType", (cash ? "现金支付" : "") + (coin ? cash ? "&玩湃币支付" : "玩湃币支付" : "")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return list; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Map<String, Object>> queryByConfigId(Integer oneId) { | 
|---|
|  |  |  | return this.baseMapper.queryByConfigId(oneId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Integer> getHours(Integer coursePackageId) { | 
|---|
|  |  |  | return this.baseMapper.getHours(coursePackageId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public ResultUtil paymentCourseCouponList(Integer uid, Integer coursePackagePaymentConfigId) { | 
|---|
|  |  |  | //        CoursePackagePaymentConfig coursePackagePaymentConfig = coursePackagePaymentConfigService.getById(coursePackagePaymentConfigId); | 
|---|
|  |  |  | //        if(ToolUtil.isEmpty(coursePackagePaymentConfig.getCouponIds())){ | 
|---|
|  |  |  | //            coursePackagePaymentConfig.setCouponIds("-1"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        List<Coupon> coupons = couponClient.getCoupons(coursePackagePaymentConfig.getCouponIds()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Coupon> coupons = couponClient.queryCouponByUid(uid); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (CollectionUtil.isNotEmpty(coupons)) { | 
|---|
|  |  |  | for (Coupon coupon : coupons) { | 
|---|
|  |  |  | Date date1 = coupon.getStartTime(); // 2023-10-01 00:00:00 | 
|---|
|  |  |  | Date date2 = coupon.getEndTime(); // 2023-10-12 00:00:00 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd"); | 
|---|
|  |  |  | String dateString1 = sdf.format(date1); | 
|---|
|  |  |  | String dateString2 = sdf.format(date2); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String result = dateString1 + "-" + dateString2; | 
|---|
|  |  |  | coupon.setTimePeriod(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ResultUtil.success(coupons); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|