|
@@ -3,6 +3,7 @@ const { CrudService } = require('naf-framework-mongoose-free/lib/service');
|
|
const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
const _ = require('lodash');
|
|
const _ = require('lodash');
|
|
const assert = require('assert');
|
|
const assert = require('assert');
|
|
|
|
+const moment = require('moment');
|
|
|
|
|
|
|
|
|
|
class LessonStudentService extends CrudService {
|
|
class LessonStudentService extends CrudService {
|
|
@@ -12,6 +13,9 @@ class LessonStudentService extends CrudService {
|
|
this.rscModel = this.ctx.model.Relation.RelationStudentCoach;
|
|
this.rscModel = this.ctx.model.Relation.RelationStudentCoach;
|
|
this.lessonCoachModel = this.ctx.model.Business.LessonCoach;
|
|
this.lessonCoachModel = this.ctx.model.Business.LessonCoach;
|
|
this.lessonModel = this.ctx.model.Business.Lesson;
|
|
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 }) {
|
|
async checkCanUse({ school_id, student_id, lesson_id }) {
|
|
@@ -85,6 +89,7 @@ class LessonStudentService extends CrudService {
|
|
async toRefund({ lesson_id, student_id }) {
|
|
async toRefund({ lesson_id, student_id }) {
|
|
const data = await this.model.findOne({ lesson_id, student_id });
|
|
const data = await this.model.findOne({ lesson_id, student_id });
|
|
if (!data) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到数据');
|
|
if (!data) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到数据');
|
|
|
|
+ if (data.is_pay === '-3') throw new BusinessError(ErrorCode.DATA_INVALID, '已经完成退课,无法再次退课');
|
|
if (data.is_try === '1') {
|
|
if (data.is_try === '1') {
|
|
|
|
|
|
data.is_pay = '-3';
|
|
data.is_pay = '-3';
|
|
@@ -92,8 +97,14 @@ class LessonStudentService extends CrudService {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+ await this.payOrderService.updateOne({ _id: data.pay_id }, { status: '-3' });
|
|
-
|
|
+ const payOrder = await this.payOrderModel.findById(data.pay_id);
|
|
|
|
+
|
|
|
|
+ const obj = _.pick(payOrder, [ 'school_id', 'payer_role', 'payer_id', 'pay_for', 'from_id' ]);
|
|
|
|
+ obj.type = '2';
|
|
|
|
+ obj.is_pay = '1';
|
|
|
|
+ obj.time = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
+ await this.billModel.create(obj);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|