|
@@ -30,29 +30,17 @@ class LessonStudentService extends CrudService {
|
|
|
const num = await this.model.count({ student_id, is_try: '1' });
|
|
|
if (num > 0) throw new BusinessError(ErrorCode.SERVICE_FAULT, '您已使用过免费试听的机会');
|
|
|
}
|
|
|
-
|
|
|
- body = await this.toComputedMoney(body);
|
|
|
return body;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- async reComputed({ id }) {
|
|
|
- let data = await this.model.findById(id);
|
|
|
- if (!data) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到数据');
|
|
|
- data = JSON.parse(JSON.stringify(data));
|
|
|
- data = await this.toComputedMoney(data);
|
|
|
- await this.model.updateOne({ _id: id }, data);
|
|
|
- return await this.model.findById(id);
|
|
|
- }
|
|
|
-
|
|
|
// 计算价格
|
|
|
- async toComputedMoney(data) {
|
|
|
- const { lesson_id, student_id } = data;
|
|
|
+ async toComputed({ lesson_id, student_id }) {
|
|
|
// 通过课程id找到该课的所有教练
|
|
|
const lesson = await this.lessonModel.findById(lesson_id);
|
|
|
- if (!lesson) return data;
|
|
|
- const lessonMoney = _.get(lesson, 'money');
|
|
|
- const lessonType = _.get(lesson, 'type');
|
|
|
+ if (!lesson) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到数据');
|
|
|
+ const data = JSON.parse(JSON.stringify(lesson));
|
|
|
+ const lessonMoney = _.get(data, 'money');
|
|
|
+ const lessonType = _.get(data, 'type');
|
|
|
if (!lessonMoney) throw new BusinessError(ErrorCode.DATA_INVALID, '课程设置错误,缺少教练费');
|
|
|
// lesson中的money: 是学生应缴费用;
|
|
|
// lessonStudent中的money:是学生应缴费用(公开课不计算,私教课需要查下有没有教师的优惠);
|
|
@@ -61,7 +49,7 @@ class LessonStudentService extends CrudService {
|
|
|
// 教练应收计算方式: 公开课: lessonCoach中设置的单价*人数; 私教课: (lesson的money - 对该学生的优惠) 之和
|
|
|
if (lessonType === '0') {
|
|
|
// 公开课
|
|
|
- data.money = lessonMoney;
|
|
|
+ data.real_money = lessonMoney;
|
|
|
} else {
|
|
|
// 找教练和学生的设置
|
|
|
// 虽然用find,但实际上只有一个教练,但凡有2个,就应该不是私教课了
|
|
@@ -76,12 +64,11 @@ class LessonStudentService extends CrudService {
|
|
|
// 优惠目前设置3种: 固定金额; ${num}(num>1):减num元; x折; 打x折(money * (x/100))
|
|
|
if (discountType === 'fixed') {
|
|
|
// 固定金额
|
|
|
- data.money = number >= 0 ? number : 0;
|
|
|
+ data.real_money = number >= 0 ? number : 0;
|
|
|
} else if (discountType === 'subtract') {
|
|
|
- data.money = lessonMoney - number >= 0 ? lessonMoney - number : 0;
|
|
|
+ data.real_money = lessonMoney - number >= 0 ? lessonMoney - number : 0;
|
|
|
} else if (discountType === 'discount') {
|
|
|
- console.log(_.divide(number, 100));
|
|
|
- data.money = _.round(_.multiply(lessonMoney, _.divide(number, 10)), 2);
|
|
|
+ data.real_money = _.round(_.multiply(lessonMoney, _.divide(number, 10)), 2);
|
|
|
}
|
|
|
data.config = _.get(rsc, 'config');
|
|
|
}
|