|
@@ -454,7 +454,7 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
|
|
|
* @return 缓存 key teacherId value List<CourseTimeEntity>
|
|
|
*/
|
|
|
public RMap<Long, List<CourseTimeEntity>> getLiveLockTimeCache(Long teacherId) {
|
|
|
- String key = String.join(":", LiveRoomConstant.COOLESHOW, CourseConstant.LOCK_COURSE_TIME_INFO, teacherId.toString());
|
|
|
+ String key = CourseConstant.LOCK_COURSE_TIME_INFO.replace(CourseConstant.TEACHER_ID, teacherId.toString());
|
|
|
return redissonClient.getMap(key);
|
|
|
}
|
|
|
|
|
@@ -525,7 +525,7 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public HttpResponseResult<OrderCreateRes> buyLiveCourse(OrderReq.OrderReqInfo orderReqInfo) {
|
|
|
- log.info("学生购买直播课程组,请求参数:{}", JSON.toJSONString(orderReqInfo));
|
|
|
+ log.info("buyLiveCourse param:{}", JSON.toJSONString(orderReqInfo));
|
|
|
Map<String, Object> param = WrapperUtil.toMap(orderReqInfo.getBizContent());
|
|
|
Long groupId = WrapperUtil.toLong(param, "groupId", "课程组id不能为空!");
|
|
|
Long studentId = orderReqInfo.getUserId();
|
|
@@ -547,46 +547,36 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
|
|
|
}
|
|
|
//校验购买的课程组每节课时间是否和自己的课时冲突
|
|
|
batchCheckStudentCourseTime(studentId, courseList, CourseSchedule::getStartTime, CourseSchedule::getEndTime);
|
|
|
- //返回的数据 有用后面aftet的方法使用
|
|
|
- Map<String, Object> bizContent = new HashMap<>();
|
|
|
- bizContent.put("courseGroup", courseGroup);
|
|
|
- bizContent.put("courseList", courseList);
|
|
|
- bizContent.put("studentId", studentId);
|
|
|
+ //写入学生购买课程记录
|
|
|
+ buyLiveCourseAfter(orderReqInfo.getOrderNo(), studentId, courseList, courseGroup);
|
|
|
+
|
|
|
OrderCreateRes orderCreateRes = new OrderCreateRes();
|
|
|
orderCreateRes.setRes(true);
|
|
|
orderCreateRes.setMerchId(courseGroup.getTeacherId());
|
|
|
orderCreateRes.setBizId(courseGroup.getId());
|
|
|
orderCreateRes.setOriginalPrice(courseGroup.getCoursePrice());
|
|
|
orderCreateRes.setExpectPrice(courseGroup.getCoursePrice());
|
|
|
- orderCreateRes.setBizParam(bizContent);
|
|
|
orderCreateRes.setGoodNum(courseGroup.getCourseNum());
|
|
|
orderCreateRes.setGoodType(GoodTypeEnum.LIVE);
|
|
|
|
|
|
HttpResponseResult<OrderCreateRes> httpResponseResult = new HttpResponseResult<>();
|
|
|
httpResponseResult.setData(orderCreateRes);
|
|
|
+ log.info("buyLiveCourse return {}", httpResponseResult);
|
|
|
return httpResponseResult;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 待订单创建完毕后继续后续操作
|
|
|
*
|
|
|
- * @param afterParam 传入参数
|
|
|
- * <p> - courseList 课程列表
|
|
|
- * <p> - studentId 学员id
|
|
|
- * <p> - courseGroup 直播课程组信息
|
|
|
+ * @param orderNo 订单号
|
|
|
+ * @param courseList 课程列表
|
|
|
+ * @param studentId 学员id
|
|
|
+ * @param courseGroup 直播课程组信息
|
|
|
*/
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- @Override
|
|
|
- public void buyLiveCourseAfter(UserOrderDetailVo afterParam) {
|
|
|
- log.info("学生购买直播课程组 after ,请求参数:{}", JSON.toJSONString(afterParam));
|
|
|
- Map<String, Object> param = WrapperUtil.toMap(afterParam.getBizParam());
|
|
|
- String orderNo = afterParam.getOrderNo();
|
|
|
- Long studentId = (Long) param.get("studentId");
|
|
|
- List<CourseSchedule> courseList = JSONArray.parseArray(JSON.toJSONString(param.get("courseList")), CourseSchedule.class);
|
|
|
- CourseGroup courseGroup = (CourseGroup) param.get("courseGroup");
|
|
|
-
|
|
|
+ private void buyLiveCourseAfter(String orderNo, Long studentId, List<CourseSchedule> courseList, CourseGroup courseGroup) {
|
|
|
+ log.info("buyLiveCourse buyLiveCourseAfter -> order {} studentId {} courseList {} courseGroup {}", orderNo, studentId, JSON.toJSONString(courseList), JSON.toJSONString(courseGroup));
|
|
|
//获取每节课购买的价格
|
|
|
- Map<Integer, BigDecimal> courseAveragePrice = getCourseAveragePrice(courseGroup.getCourseNum(), courseGroup.getCoursePrice());
|
|
|
+ Map<Integer, BigDecimal> courseAveragePrice = WrapperUtil.getAveragePrice(courseGroup.getCourseNum(), courseGroup.getCoursePrice());
|
|
|
//写course_schedule_student_payment表 作为记录锁定时间用,防止重复购买,如果支付失败则删除该数据
|
|
|
List<CourseScheduleStudentPayment> studentPaymentList = new ArrayList<>();
|
|
|
Date now = new Date();
|
|
@@ -615,7 +605,7 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void buyLiveCourseSuccess(UserOrderDetailVo orderParam) {
|
|
|
- log.info("学生购买直播课程-成功-回调,请求参数:{}", JSON.toJSONString(orderParam));
|
|
|
+ log.info("buyLiveCourseSuccess param :{}", JSON.toJSONString(orderParam));
|
|
|
String orderNo = orderParam.getOrderNo();
|
|
|
//更新课程组的购买人数+1
|
|
|
CourseScheduleStudentPayment studentPayment = courseScheduleStudentPaymentService.getOne(Wrappers.<CourseScheduleStudentPayment>lambdaQuery()
|
|
@@ -640,7 +630,7 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
|
|
|
//总课酬 1 - (1 * 手续费率)
|
|
|
BigDecimal totalRatePrice = expectPrice.subtract(expectPrice.multiply(liveServiceRate)).setScale(2, RoundingMode.HALF_UP);
|
|
|
//获取每节课的课酬 key 课堂数 value 课酬
|
|
|
- Map<Integer, BigDecimal> singerCourseSalary = getCourseAveragePrice(courseGroup.getCourseNum(), totalRatePrice);
|
|
|
+ Map<Integer, BigDecimal> singerCourseSalary = WrapperUtil.getAveragePrice(courseGroup.getCourseNum(), totalRatePrice);
|
|
|
//写入课酬表计算-根据课程组总金额计算分配到每节课的金额
|
|
|
Date now = new Date();
|
|
|
List<CourseScheduleTeacherSalary> teacherSalaryList = new ArrayList<>();
|
|
@@ -659,41 +649,7 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
|
|
|
teacherSalaryList.add(teacherSalary);
|
|
|
});
|
|
|
courseScheduleTeacherSalaryService.getDao().insertBatch(teacherSalaryList);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 计算课堂每节课价格
|
|
|
- *
|
|
|
- * @param totalCourseNum 总课程数
|
|
|
- * @param totalRatePrice 总金额
|
|
|
- * @return key 课堂数 value 课酬
|
|
|
- */
|
|
|
- private Map<Integer, BigDecimal> getCourseAveragePrice(Integer totalCourseNum, BigDecimal totalRatePrice) {
|
|
|
- //每节课的单价 四舍五入
|
|
|
- BigDecimal singerSalary = totalRatePrice.divide(BigDecimal.valueOf(totalCourseNum), 2, RoundingMode.HALF_UP);
|
|
|
- //单价累计总额
|
|
|
- BigDecimal cumulativeAmount = BigDecimal.ZERO;
|
|
|
- Map<Integer, BigDecimal> map = new HashMap<>();
|
|
|
- for (int i = 1; i <= totalCourseNum; i++) {
|
|
|
- //最后一节课,直接用总课酬减去累计总额
|
|
|
- if (i == totalCourseNum) {
|
|
|
- singerSalary = totalRatePrice.subtract(cumulativeAmount);
|
|
|
- }
|
|
|
- cumulativeAmount = cumulativeAmount.add(singerSalary);
|
|
|
- map.put(i, singerSalary);
|
|
|
- }
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 学生购买直播课-失败-回调
|
|
|
- */
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void buyLiveCourseFailed(String orderNo) {
|
|
|
- //删除 course_schedule_student_payment表 数据
|
|
|
-
|
|
|
-
|
|
|
- //修改订单为失败
|
|
|
+ log.info("buyLiveCourseSuccess ok");
|
|
|
}
|
|
|
|
|
|
private SysUser getSysUser(Long userId) {
|
|
@@ -723,7 +679,7 @@ public class CourseGroupServiceImpl extends ServiceImpl<CourseGroupDao, CourseGr
|
|
|
courseGroupList.forEach(courseGroup -> {
|
|
|
courseGroup.setStatus(CourseGroupEnum.APPLY.getCode());
|
|
|
this.updateById(courseGroup);
|
|
|
- }) ;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
}
|