|
@@ -23,6 +23,25 @@ class PayOrderService extends CrudService {
|
|
this.billModel = this.ctx.model.Business.Bill;
|
|
this.billModel = this.ctx.model.Business.Bill;
|
|
this.tran = new Transaction();
|
|
this.tran = new Transaction();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ async toCharge(body = {}) {
|
|
|
|
+ body.payer_role = 'Student';
|
|
|
|
+ body.pay_for = 'Charge';
|
|
|
|
+ body.time = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
+ body.order_no = this.getOrderNo();
|
|
|
|
+ body.desc = '充值';
|
|
|
|
+ try {
|
|
|
|
+ const pay_id = this.tran.insert('PayOrder', body);
|
|
|
|
+ const wxSign = await this.payService.create({ ...body, notice_url: this.app.config.payReturn });
|
|
|
|
+ await this.tran.run();
|
|
|
|
+ return { pay_id, wxSign };
|
|
|
|
+ } catch (error) {
|
|
|
|
+ await this.tran.rollback();
|
|
|
|
+ } finally {
|
|
|
|
+ this.tran.clean();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 处理支付回调
|
|
* 处理支付回调
|
|
* @param {Object} body 参数体
|
|
* @param {Object} body 参数体
|
|
@@ -52,12 +71,25 @@ class PayOrderService extends CrudService {
|
|
// 生成账单
|
|
// 生成账单
|
|
const billData = _.pick(payOrder, [ 'school_id', 'payer_id', 'payer_role', 'pay_for', 'from_id' ]);
|
|
const billData = _.pick(payOrder, [ 'school_id', 'payer_id', 'payer_role', 'pay_for', 'from_id' ]);
|
|
// 充值为1,直接支付为-1
|
|
// 充值为1,直接支付为-1
|
|
- if (billData.pay_for && _.lowerCase(billData.pay_for) === 'charge') billData.type = '1';
|
|
|
|
|
|
+ if (billData.pay_for && _.lowerFirst(billData.pay_for) === 'charge') billData.type = '1';
|
|
else billData.type = '-1';
|
|
else billData.type = '-1';
|
|
billData.pay_id = payOrder._id;
|
|
billData.pay_id = payOrder._id;
|
|
billData.is_pay = update.status;
|
|
billData.is_pay = update.status;
|
|
billData.time = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
billData.time = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
+ // 如果是充值,则需要将充值的钱加上
|
|
|
|
+ if (billData.type === '1') {
|
|
|
|
+ const { money: cm, payer_id, school_id } = payOrder;
|
|
|
|
+ const rss = await this.rssModel.findOne({ school_id, student_id: payer_id });
|
|
|
|
+ if (!rss) billData.is_pay = '-4';
|
|
|
|
+ else {
|
|
|
|
+ const newMoney = this.ctx.plus(cm, rss.money);
|
|
|
|
+ this.tran.update('RelationStudentSchool', rss._id, { money: newMoney });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
this.tran.insert('Bill', billData);
|
|
this.tran.insert('Bill', billData);
|
|
|
|
+
|
|
|
|
+
|
|
await this.tran.run();
|
|
await this.tran.run();
|
|
} catch (error) {
|
|
} catch (error) {
|
|
await this.tran.rollback();
|
|
await this.tran.rollback();
|