lrf 2 years ago
parent
commit
31ef43b222
2 changed files with 8 additions and 1 deletions
  1. 7 1
      app/service/business/lessonStudent.js
  2. 1 0
      app/service/business/payOrder.js

+ 7 - 1
app/service/business/lessonStudent.js

@@ -122,6 +122,9 @@ class LessonStudentService extends CrudService {
         result.wxSign = wxSign;
       }
       await this.tran.run();
+      // 然后将pay_id赋给课程
+      this.tran.update('LessonStudent', id, { pay_id });
+      await this.tran.run();
       return result;
     } catch (error) {
       await this.tran.rollback();
@@ -192,7 +195,9 @@ class LessonStudentService extends CrudService {
     }
     try {
       // 正常交钱的课,将 pay_id 的status 修改为 -3, 同时触发修改这条数据,但是没有退款;
+      console.log(data);
       const payOrder = await this.payOrderModel.findById(data.pay_id);
+      if (!payOrder) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到付款单信息');
       // 再生成账单记录
       const obj = _.pick(payOrder, [ 'school_id', 'payer_role', 'payer_id', 'pay_for', 'from_id' ]);
       obj.money = data.money;
@@ -224,7 +229,8 @@ class LessonStudentService extends CrudService {
       return;
     } catch (error) {
       await this.tran.rollback();
-      throw new Error(error);
+      console.log(error);
+      throw Error(error);
     } finally {
       this.tran.clean();
     }

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

@@ -74,6 +74,7 @@ class PayOrderService extends CrudService {
       // 充值为1,直接支付为-1
       if (billData.pay_for && _.lowerFirst(billData.pay_for) === 'charge') billData.type = '1';
       else billData.type = '-1';
+      billData.money = payOrder.money;
       billData.pay_id = payOrder._id;
       billData.is_pay = update.status;
       billData.time = moment().format('YYYY-MM-DD HH:mm:ss');