|
@@ -28,6 +28,7 @@ import com.ym.mec.util.collection.MapUtil;
|
|
|
import com.ym.mec.util.date.DateUtil;
|
|
|
import com.ym.mec.util.http.HttpUtil;
|
|
|
import com.ym.mec.util.string.MessageFormatter;
|
|
|
+
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -41,6 +42,7 @@ import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.*;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
@@ -2826,14 +2828,14 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
- public HttpResponseResult buyPracticeGroup(PracticeGroupBuyDto practiceGroupBuyParams) {
|
|
|
+ public HttpResponseResult buyPracticeGroup(PracticeGroupBuyDto practiceGroupBuyParams, String operatorInfo) {
|
|
|
if (Objects.isNull(practiceGroupBuyParams.getUserId())) {
|
|
|
return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "请选择教师");
|
|
|
}
|
|
|
if (Objects.isNull(practiceGroupBuyParams.getSubjectId())) {
|
|
|
return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "请选择声部");
|
|
|
}
|
|
|
- if (Objects.isNull(practiceGroupBuyParams.getBuyMonths())) {
|
|
|
+ if (Objects.isNull(practiceGroupBuyParams.getAllCourseNum())) {
|
|
|
return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "请选择需要购买的课时数");
|
|
|
}
|
|
|
if (Objects.isNull(practiceGroupBuyParams.getDrillTimesOnWeek())) {
|
|
@@ -2868,7 +2870,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
*/
|
|
|
Date now = new Date();
|
|
|
|
|
|
- int studentExitChargePractices = practiceGroupDao.checkStudentExitChargePractice(practiceGroupBuyParams.getStudentId(),"2021-03-09 00:00:00");
|
|
|
+// int studentExitChargePractices = practiceGroupDao.checkStudentExitChargePractice(practiceGroupBuyParams.getStudentId(),"2021-03-09 00:00:00");
|
|
|
|
|
|
LocalDate courseStartDay = LocalDate.now();
|
|
|
LocalDate tempCourseLocalDate = LocalDate.parse("2020-03-01", DateUtil.dateFormatter);
|
|
@@ -2987,13 +2989,16 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
} else {
|
|
|
oneMonthPrice = practiceGroupBuyParams.getDrillTimesOnWeek() == 1 ? practiceGroupSellPrice.getOnceOriginalPrice() : practiceGroupSellPrice.getTwiceOriginalPrice();
|
|
|
}*/
|
|
|
- BigDecimal amount = oneMonthPrice.multiply(new BigDecimal(practiceGroupBuyParams.getBuyMonths()));
|
|
|
+ BigDecimal amount = oneMonthPrice.multiply(new BigDecimal(practiceGroupBuyParams.getAllCourseNum()));
|
|
|
|
|
|
practiceGroupBuyParams.setDrillTimesJson(drillTimesObject.toJSONString());
|
|
|
practiceGroupBuyParams.setOrganId(sysUser.getOrganId());
|
|
|
practiceGroupBuyParams.setSingleClassMinutes(practiceCourseMinutes);
|
|
|
practiceGroupBuyParams.setGroupStatus(GroupStatusEnum.LOCK);
|
|
|
practiceGroupBuyParams.setType(PracticeGroupType.CHARGE);
|
|
|
+ if(StringUtils.isNotBlank(operatorInfo)){
|
|
|
+ practiceGroupBuyParams.setMemo(operatorInfo+",教务代买");
|
|
|
+ }
|
|
|
practiceGroupDao.insert(practiceGroupBuyParams);
|
|
|
|
|
|
//创建班级信息
|
|
@@ -3010,6 +3015,26 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
classGroup.setCreateTime(now);
|
|
|
classGroup.setUpdateTime(now);
|
|
|
classGroupDao.insert(classGroup);
|
|
|
+
|
|
|
+ //使用优惠券
|
|
|
+ StudentPaymentOrder studentPaymentOrder = sysCouponCodeService.use(practiceGroupBuyParams.getCouponIdList(),amount,true);
|
|
|
+ amount = studentPaymentOrder.getActualAmount();
|
|
|
+ studentPaymentOrder.setUserId(practiceGroupBuyParams.getStudentId());
|
|
|
+ studentPaymentOrder.setGroupType(GroupType.PRACTICE);
|
|
|
+ String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
+ studentPaymentOrder.setOrderNo(orderNo);
|
|
|
+ studentPaymentOrder.setStatus(DealStatusEnum.ING);
|
|
|
+ studentPaymentOrder.setType(OrderTypeEnum.PRACTICE_GROUP_BUY);
|
|
|
+ if (practiceGroupBuyParams.isRenew()) {
|
|
|
+ studentPaymentOrder.setType(OrderTypeEnum.PRACTICE_GROUP_RENEW);
|
|
|
+ }
|
|
|
+ studentPaymentOrder.setMusicGroupId(practiceGroupBuyParams.getId().toString());
|
|
|
+ studentPaymentOrder.setClassGroupId(classGroup.getId());
|
|
|
+ studentPaymentOrder.setVersion(0);
|
|
|
+ if(StringUtils.isNotBlank(operatorInfo)){
|
|
|
+ studentPaymentOrder.setMemo(operatorInfo+",教务代买");
|
|
|
+ }
|
|
|
+ studentPaymentOrderService.insert(studentPaymentOrder);
|
|
|
|
|
|
//创建班级老师关联记录
|
|
|
ClassGroupTeacherMapper classGroupTeacherMapper = new ClassGroupTeacherMapper();
|
|
@@ -3071,13 +3096,18 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
if(teacherDefaultSalary == null){
|
|
|
throw new BizException("请设置教师课酬");
|
|
|
}
|
|
|
- BigDecimal studentSingleCourseCost = amount.divide(new BigDecimal(practiceCourses.size()), CommonConstants.DECIMAL_PLACE, ROUND_DOWN);
|
|
|
+// BigDecimal studentSingleCourseCost = amount.divide(new BigDecimal(practiceCourses.size()), CommonConstants.DECIMAL_PLACE, ROUND_DOWN);
|
|
|
|
|
|
- BigDecimal oneMonthOriginalPrice=practiceGroupBuyParams.getDrillTimesOnWeek()==1?practiceGroupSellPrice.getOnceOriginalPrice():practiceGroupSellPrice.getTwiceOriginalPrice();
|
|
|
- BigDecimal originalAmount = oneMonthOriginalPrice.multiply(new BigDecimal(practiceGroupBuyParams.getBuyMonths()));
|
|
|
- BigDecimal studentSingleCourseOriginalCost=originalAmount.divide(new BigDecimal(practiceCourses.size()), CommonConstants.DECIMAL_PLACE, ROUND_DOWN);
|
|
|
+// BigDecimal oneMonthOriginalPrice=practiceGroupBuyParams.getDrillTimesOnWeek()==1?practiceGroupSellPrice.getOnceOriginalPrice():practiceGroupSellPrice.getTwiceOriginalPrice();
|
|
|
+// BigDecimal originalAmount = oneMonthOriginalPrice.multiply(new BigDecimal(practiceGroupBuyParams.getBuyMonths()));
|
|
|
+// BigDecimal studentSingleCourseOriginalCost=originalAmount.divide(new BigDecimal(practiceCourses.size()), CommonConstants.DECIMAL_PLACE, ROUND_DOWN);
|
|
|
|
|
|
- for (CourseSchedule courseSchedule : practiceCourses) {
|
|
|
+ //实际支付金额,去除优惠券
|
|
|
+ BigDecimal actualPrice = studentPaymentOrder.getExpectAmount();
|
|
|
+ BigDecimal divide = actualPrice.divide(new BigDecimal(practiceCourses.size()), ROUND_DOWN);
|
|
|
+ BigDecimal firstAmount = actualPrice.subtract(divide.multiply(new BigDecimal(practiceCourses.size()))).add(divide);
|
|
|
+ for (int i = 0; i < practiceCourses.size(); i++) {
|
|
|
+ CourseSchedule courseSchedule = practiceCourses.get(i);
|
|
|
//课程与老师薪水表
|
|
|
CourseScheduleTeacherSalary courseScheduleTeacherSalary = new CourseScheduleTeacherSalary();
|
|
|
courseScheduleTeacherSalary.setCourseScheduleId(courseSchedule.getId());
|
|
@@ -3097,9 +3127,16 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
courseScheduleStudentPayment.setMusicGroupId(practiceGroupBuyParams.getId().toString());
|
|
|
courseScheduleStudentPayment.setCourseScheduleId(courseSchedule.getId());
|
|
|
courseScheduleStudentPayment.setUserId(practiceGroupBuyParams.getStudentId());
|
|
|
- courseScheduleStudentPayment.setExpectPrice(studentSingleCourseCost);
|
|
|
- courseScheduleStudentPayment.setActualPrice(studentSingleCourseCost);
|
|
|
- courseScheduleStudentPayment.setOriginalPrice(studentSingleCourseOriginalCost);
|
|
|
+ if(i == 0){
|
|
|
+ courseScheduleStudentPayment.setExpectPrice(firstAmount);
|
|
|
+ courseScheduleStudentPayment.setActualPrice(firstAmount);
|
|
|
+ }else {
|
|
|
+ courseScheduleStudentPayment.setExpectPrice(divide);
|
|
|
+ courseScheduleStudentPayment.setActualPrice(divide);
|
|
|
+ }
|
|
|
+// courseScheduleStudentPayment.setExpectPrice(oneMonthPrice);
|
|
|
+// courseScheduleStudentPayment.setActualPrice(studentSingleCourseCost);
|
|
|
+ courseScheduleStudentPayment.setOriginalPrice(oneMonthPrice);
|
|
|
courseScheduleStudentPayment.setClassGroupId(classGroup.getId());
|
|
|
courseScheduleStudentPayment.setCreateTime(now);
|
|
|
courseScheduleStudentPayment.setUpdateTime(now);
|
|
@@ -3136,24 +3173,6 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
}
|
|
|
return BaseController.failed(HttpStatus.FOUND, errMessage);
|
|
|
}
|
|
|
- //使用优惠券
|
|
|
- StudentPaymentOrder studentPaymentOrder = sysCouponCodeService.use(practiceGroupBuyParams.getCouponIdList(),amount,true);
|
|
|
- amount = studentPaymentOrder.getActualAmount();
|
|
|
- studentPaymentOrder.setUserId(practiceGroupBuyParams.getStudentId());
|
|
|
- studentPaymentOrder.setGroupType(GroupType.PRACTICE);
|
|
|
- String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
- studentPaymentOrder.setOrderNo(orderNo);
|
|
|
- studentPaymentOrder.setStatus(DealStatusEnum.ING);
|
|
|
- studentPaymentOrder.setType(OrderTypeEnum.PRACTICE_GROUP_BUY);
|
|
|
- if (practiceGroupBuyParams.isRenew()) {
|
|
|
- studentPaymentOrder.setType(OrderTypeEnum.PRACTICE_GROUP_RENEW);
|
|
|
- }
|
|
|
- studentPaymentOrder.setExpectAmount(amount);
|
|
|
- studentPaymentOrder.setMusicGroupId(practiceGroupBuyParams.getId().toString());
|
|
|
- studentPaymentOrder.setActualAmount(studentPaymentOrder.getExpectAmount());
|
|
|
- studentPaymentOrder.setClassGroupId(classGroup.getId());
|
|
|
- studentPaymentOrder.setVersion(0);
|
|
|
- studentPaymentOrderService.insert(studentPaymentOrder);
|
|
|
|
|
|
BigDecimal balance = BigDecimal.ZERO;
|
|
|
if (practiceGroupBuyParams.isUseBalancePayment() || studentPaymentOrder.getExpectAmount().doubleValue() == 0) {
|
|
@@ -4363,7 +4382,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
practiceBuyResult.setOrderNo(orderNo);
|
|
|
practiceBuyResult.setStatus(order.getStatus());
|
|
|
practiceBuyResult.setCreateTime(order.getCreateTime());
|
|
|
- practiceBuyResult.setPrice(order.getExpectAmount());
|
|
|
+ practiceBuyResult.setPrice(order.getExpectAmount().subtract(order.getCouponRemitFee()));
|
|
|
practiceBuyResult.setType(order.getType().getCode());
|
|
|
|
|
|
if(order.getGroupType().equals(GroupType.GOODS_SELL)){
|
|
@@ -4379,6 +4398,8 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
if(Objects.nonNull(practiceGroup.getType())&&(PracticeGroupType.CARE_PACKAGE.equals(practiceGroup.getType())||PracticeGroupType.COME_ON_PACKAGE.equals(practiceGroup.getType()))){
|
|
|
practiceCourseMinutes = 50;
|
|
|
}
|
|
|
+
|
|
|
+ practiceBuyResult.setCourseNum(practiceGroup.getAllCourseNum());
|
|
|
|
|
|
if(StringUtils.isNotEmpty(practiceGroup.getDrillTimesJson())){
|
|
|
JSONArray coursesArry = new JSONArray();
|
|
@@ -4560,14 +4581,40 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
- public HttpResponseResult cancelWaitPayOrder(Integer userId, Integer groupId) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public HttpResponseResult cancelWaitPayOrder(Integer userId, Integer groupId) throws Exception {
|
|
|
PracticeGroup practiceGroup = practiceGroupDao.get(groupId.longValue());
|
|
|
if (practiceGroup.getGroupStatus().equals(GroupStatusEnum.LOCK)) {
|
|
|
groupService.deleteGroupOtherInfo(groupId.toString(), GroupType.PRACTICE);
|
|
|
practiceGroup.setGroupStatus(GroupStatusEnum.CANCEL);
|
|
|
practiceGroup.setMemo("用户手动取消");
|
|
|
practiceGroupDao.update(practiceGroup);
|
|
|
+
|
|
|
+ // 判断是否存在支付中的记录
|
|
|
+ List<StudentPaymentOrder> list = studentPaymentOrderService.queryByCondition(GroupType.PRACTICE, groupId + "", userId, DealStatusEnum.ING,
|
|
|
+ OrderTypeEnum.PRACTICE_GROUP_BUY);
|
|
|
+
|
|
|
+ if (list.size() > 0) {
|
|
|
+ StudentPaymentOrder applyOrder = list.get(list.size() - 1);
|
|
|
+ // 查询订单状态
|
|
|
+ PayStatus payStatus = studentPaymentOrderService.queryPayStatus(applyOrder.getPaymentChannel(), applyOrder.getOrderNo(), applyOrder.getTransNo());
|
|
|
+ if(payStatus == PayStatus.SUCCESSED){
|
|
|
+ throw new BizException("订单已支付成功,请勿重复支付");
|
|
|
+ }/*else if(payStatus == PayStatus.PAYING){
|
|
|
+ throw new BizException("订单还在交易中,请稍后重试");
|
|
|
+ }*/
|
|
|
+ //处理关闭订单
|
|
|
+ applyOrder.setStatus(DealStatusEnum.CLOSE);
|
|
|
+ applyOrder.setMemo("主动关闭订单");
|
|
|
+ if (applyOrder.getBalancePaymentAmount() != null && applyOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ sysUserCashAccountService.updateBalance(applyOrder.getUserId(), applyOrder.getBalancePaymentAmount(),
|
|
|
+ PlatformCashAccountDetailTypeEnum.REFUNDS, "购买网管课支付失败");
|
|
|
+ }
|
|
|
+ studentPaymentOrderService.update(applyOrder);
|
|
|
+ sysCouponCodeService.quit(applyOrder.getCouponCodeId());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
} else if (practiceGroup.getGroupStatus().equals(GroupStatusEnum.NORMAL)) {
|
|
|
return BaseController.failed(HttpStatus.CREATED, "该订单已经支付成功");
|
|
|
} else if (practiceGroup.getGroupStatus().equals(GroupStatusEnum.CANCEL)) {
|