|
@@ -142,8 +142,21 @@ class PayOrderService extends CrudService {
|
|
|
}
|
|
|
// 检查记录
|
|
|
async makeRecord(data) {
|
|
|
- const { config, _id: pay_id, status: is_pay } = data;
|
|
|
+ const { config, _id: pay_id, status: is_pay, pay_for, from_id } = data;
|
|
|
let billData;
|
|
|
+ let wxBill;
|
|
|
+ // 检查是否有本次微信支付部分的账单
|
|
|
+ wxBill = await this.billModel.find({ pay_id });
|
|
|
+ if (!wxBill) {
|
|
|
+ // 没有微信支付账单,需要创建
|
|
|
+ const obj = _.pick(data, [ 'school_id', 'payer_id', 'payer_role', 'pay_for', 'from_id', 'time' ]);
|
|
|
+ obj.type = '-1';
|
|
|
+ obj.pay_id = data._id;
|
|
|
+ obj.is_pay = is_pay;
|
|
|
+ wxBill = await this.billModel.create(obj);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
// 使用余额的处理
|
|
|
if (_.get(config, 'useSurplus')) {
|
|
|
const { bill } = config;
|
|
@@ -151,7 +164,7 @@ class PayOrderService extends CrudService {
|
|
|
// 如果是ObjectId,说明余额记录已经生成.无需操作
|
|
|
if (_.isObject(bill)) {
|
|
|
// 是数据,生成账单记录
|
|
|
- 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, is_pay, pay_for, from_id, time: moment().format('YYYY-MM-DD HH:mm:ss') });
|
|
|
if (billData) data.config.bill = ObjectId(billData._id).toString();
|
|
|
await this.model.updateOne({ _id: data._id }, data);
|
|
|
// 创建账单后,扣余额
|
|
@@ -163,11 +176,13 @@ class PayOrderService extends CrudService {
|
|
|
relation.money = relation.money - money;
|
|
|
await relation.save();
|
|
|
}
|
|
|
- } else {
|
|
|
- // 已经有数据了, 修改账单.并根据is_pay去做相应的处理
|
|
|
- await this.billModel.updateOne({ _id: data.config.bill }, { is_pay });
|
|
|
- billData = await this.billModel.findById(data.config.bill);
|
|
|
}
|
|
|
+ // 账单的退款是退款,支付是支付,各自生成数据,不需要修改
|
|
|
+ // else {
|
|
|
+ // // 已经有数据了, 修改账单.并根据is_pay去做相应的处理
|
|
|
+ // await this.billModel.updateOne({ _id: data.config.bill }, { is_pay });
|
|
|
+ // billData = await this.billModel.findById(data.config.bill);
|
|
|
+ // }
|
|
|
}
|
|
|
}
|
|
|
|