|
@@ -13,9 +13,6 @@ class LessonStudentService extends CrudService {
|
|
|
this.rscModel = this.ctx.model.Relation.RelationStudentCoach;
|
|
|
this.lessonCoachModel = this.ctx.model.Business.LessonCoach;
|
|
|
this.lessonModel = this.ctx.model.Business.Lesson;
|
|
|
- this.payOrderService = this.ctx.service.business.payOrder;
|
|
|
- this.payOrderModel = this.ctx.model.Business.PayOrder;
|
|
|
- this.billModel = this.ctx.model.Business.Bill;
|
|
|
}
|
|
|
|
|
|
async checkCanUse({ school_id, student_id, lesson_id }) {
|
|
@@ -87,6 +84,9 @@ class LessonStudentService extends CrudService {
|
|
|
|
|
|
// 退课,将钱退至余额
|
|
|
async toRefund({ lesson_id, student_id }) {
|
|
|
+ const payOrderService = this.ctx.service.business.payOrder;
|
|
|
+ const payOrderModel = this.ctx.model.Business.PayOrder;
|
|
|
+ const billModel = this.ctx.model.Business.Bill;
|
|
|
const data = await this.model.findOne({ lesson_id, student_id });
|
|
|
if (!data) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到数据');
|
|
|
if (data.is_pay === '-3') throw new BusinessError(ErrorCode.DATA_INVALID, '已经完成退课,无法再次退课');
|
|
@@ -97,14 +97,22 @@ class LessonStudentService extends CrudService {
|
|
|
return;
|
|
|
}
|
|
|
// 正常交钱的课,将 pay_id 的status 修改为 -3, 同时触发修改这条数据,但是没有退款;
|
|
|
- await this.payOrderService.updateOne({ _id: data.pay_id }, { status: '-3' });
|
|
|
- const payOrder = await this.payOrderModel.findById(data.pay_id);
|
|
|
+ await payOrderService.update({ _id: data.pay_id }, { status: '-3' });
|
|
|
+ const payOrder = await payOrderModel.findById(data.pay_id);
|
|
|
// 再生成账单记录
|
|
|
- const obj = _.pick(payOrder, [ 'school_id', 'payer_role', 'payer_id', 'pay_for', 'from_id' ]);
|
|
|
+ const obj = _.pick(payOrder, [ 'school_id', 'payer_role', 'payer_id', 'pay_for', 'from_id', 'money', 'pay_id' ]);
|
|
|
obj.type = '2';
|
|
|
obj.is_pay = '1';
|
|
|
obj.time = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
|
- await this.billModel.create(obj);
|
|
|
+ await billModel.create(obj);
|
|
|
+ // 再将钱返回给余额
|
|
|
+ let relation;
|
|
|
+ const { payer_role, payer_id, school_id } = payOrder;
|
|
|
+ if (payer_role === 'Student') relation = await this.rssModel.findOne({ student_id: payer_id, school_id });
|
|
|
+ else if (payer_role === 'Coach') relation = await this.rcsModel.findOne({ coach_id: payer_id, school_id });
|
|
|
+ relation.money = relation.money + obj.money;
|
|
|
+ await relation.save();
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|