|
@@ -154,19 +154,20 @@ class PayOrderService extends CrudService {
|
|
billData = await this.billModel.create({ ...bill, pay_id, is_pay, time: moment().format('YYYY-MM-DD HH:mm:ss') });
|
|
billData = await this.billModel.create({ ...bill, pay_id, is_pay, time: moment().format('YYYY-MM-DD HH:mm:ss') });
|
|
if (billData) data.config.bill = ObjectId(billData._id).toString();
|
|
if (billData) data.config.bill = ObjectId(billData._id).toString();
|
|
await this.model.updateOne({ _id: data._id }, data);
|
|
await this.model.updateOne({ _id: data._id }, data);
|
|
|
|
+ // 创建账单后,扣余额
|
|
|
|
+ const { type, payer_role, payer_id, money, school_id } = billData;
|
|
|
|
+ if (type === '-2') {
|
|
|
|
+ let relation;
|
|
|
|
+ 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 - money;
|
|
|
|
+ await relation.save();
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
// 已经有数据了, 修改账单.并根据is_pay去做相应的处理
|
|
// 已经有数据了, 修改账单.并根据is_pay去做相应的处理
|
|
await this.billModel.updateOne({ _id: data.config.bill }, { is_pay });
|
|
await this.billModel.updateOne({ _id: data.config.bill }, { is_pay });
|
|
billData = await this.billModel.findById(data.config.bill);
|
|
billData = await this.billModel.findById(data.config.bill);
|
|
}
|
|
}
|
|
- const { type, payer_role, payer_id, money, school_id } = billData;
|
|
|
|
- if (type === '-2') {
|
|
|
|
- let relation;
|
|
|
|
- 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 - money;
|
|
|
|
- await relation.save();
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|