|
@@ -5,6 +5,7 @@ const _ = require('lodash');
|
|
|
const assert = require('assert');
|
|
|
const moment = require('moment');
|
|
|
const Transaction = require('mongoose-transactions');
|
|
|
+const { find } = require('lodash');
|
|
|
|
|
|
//
|
|
|
class LessonStudentService extends CrudService {
|
|
@@ -45,6 +46,27 @@ class LessonStudentService extends CrudService {
|
|
|
return body;
|
|
|
}
|
|
|
|
|
|
+ async toRePay({ id }) {
|
|
|
+ const data = await this.model.findById(id);
|
|
|
+ if (!data) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到报名信息');
|
|
|
+ if (data.is_pay === '1') throw new BusinessError(ErrorCode.SERVICE_FAULT, '该课程已支付成功');
|
|
|
+ const payOrder = await this.payOrderModel.findById(data.pay_id);
|
|
|
+ if (!payOrder) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到课程缴费信息');
|
|
|
+ const { openid, money, school_id, payer_id: student_id, from_id: lesson_id, order_no } = payOrder;
|
|
|
+ try {
|
|
|
+ // 关闭订单
|
|
|
+ await this.payService.close(order_no);
|
|
|
+ // 删了重做
|
|
|
+ this.tran.remove('LessonStudent', id);
|
|
|
+ await this.create({ openid, money, school_id, student_id, lesson_id });
|
|
|
+ await this.tran.run();
|
|
|
+ } catch (error) {
|
|
|
+ await this.tran.rollback();
|
|
|
+ } finally {
|
|
|
+ this.tran.clean();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
async create(data) {
|
|
|
// 检查是否能报名上课
|
|
|
data = await this.beforeCreate(data);
|