lrf 2 years ago
parent
commit
2e6780f015

+ 3 - 0
app/controller/business/config/.lessonStudent.js

@@ -52,4 +52,7 @@ module.exports = {
   toRefund: {
     requestBody: ['!lesson_id', '!student_id'],
   },
+  toRePay: {
+    requestBody: ['!id'],
+  },
 };

+ 22 - 0
app/service/business/lessonStudent.js

@@ -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);

+ 1 - 1
app/service/business/payOrder.js

@@ -184,7 +184,7 @@ class PayOrderService extends CrudService {
   }
 
   /**
-   * 重新支付
+   * 重新支付; 弃用
    * @param {String} body 参数体
    * @property {String} id 数据id
    */

+ 1 - 0
app/z_router/business/lessonStudent.js

@@ -7,6 +7,7 @@ const rkey = 'lessonStudent';
 const ckey = 'business.lessonStudent';
 const keyZh = '课程-学员';
 const routes = [
+  { method: 'post', path: `${rkey}/toRePay`, controller: `${ckey}.toRePay`, name: `${ckey}toRePay`, zh: `重新缴费${keyZh}` },
   { method: 'post', path: `${rkey}/toRefund`, controller: `${ckey}.toRefund`, name: `${ckey}toRefund`, zh: `退课${keyZh}` },
   { method: 'post', path: `${rkey}/checkCanUse`, controller: `${ckey}.checkCanUse`, name: `${ckey}checkCanUse`, zh: `查询是否可以报名${keyZh}` },
   { method: 'post', path: `${rkey}/toComputed`, controller: `${ckey}.toComputed`, name: `${ckey}toComputed`, zh: `计算价格${keyZh}` },