|
@@ -12,6 +12,9 @@ class PayOrderService extends CrudService {
|
|
this.payService = this.ctx.service.wxpay;
|
|
this.payService = this.ctx.service.wxpay;
|
|
this.lessonStudentModel = this.ctx.model.Business.LessonStudent;
|
|
this.lessonStudentModel = this.ctx.model.Business.LessonStudent;
|
|
this.tempLessonApplyModel = this.ctx.model.Apply.TempLessonApply;
|
|
this.tempLessonApplyModel = this.ctx.model.Apply.TempLessonApply;
|
|
|
|
+ this.userModel = this.ctx.model.User.User;
|
|
|
|
+ this.studentModel = this.ctx.model.User.Student;
|
|
|
|
+ this.coachModel = this.ctx.model.User.Coach;
|
|
}
|
|
}
|
|
|
|
|
|
async beforeCreate(data) {
|
|
async beforeCreate(data) {
|
|
@@ -124,6 +127,47 @@ class PayOrderService extends CrudService {
|
|
getOrderNo() {
|
|
getOrderNo() {
|
|
return `ONCAPP${moment().format('YYYYMMDDHHmmss')}-${_.random(1, 999999)}`;
|
|
return `ONCAPP${moment().format('YYYYMMDDHHmmss')}-${_.random(1, 999999)}`;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ async toPayNative(body) {
|
|
|
|
+ body = await this.beforeCreate(body);
|
|
|
|
+ const data = await this.model.create(body);
|
|
|
|
+ const qrcode = await this.payService.createNative({ ...body });
|
|
|
|
+ return qrcode;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async nativeReturn(body) {
|
|
|
|
+ const result = _.get(body, 'result');
|
|
|
|
+ console.log(result);
|
|
|
|
+ if (!result) throw new BusinessError(ErrorCode.BADPARAM, '参数错误');
|
|
|
|
+ const { out_trade_no: order_no, trade_state, payer } = body;
|
|
|
|
+ const obj = {};
|
|
|
|
+ if (trade_state === 'SUCCESS') obj.status = '1';
|
|
|
|
+ else if (trade_state === 'REFUND') obj.status = '-3';
|
|
|
|
+ const openid = _.get(payer, 'openid');
|
|
|
|
+ if (openid) {
|
|
|
|
+ obj.openid = openid;
|
|
|
|
+
|
|
|
|
+ const user = await this.userModel.findOne({ openid });
|
|
|
|
+ if (user) {
|
|
|
|
+ const { _id: user_id } = user;
|
|
|
|
+ let roleUser = await this.studentModel.findOne({ user_id });
|
|
|
|
+ if (!roleUser) {
|
|
|
|
+ roleUser = await this.coachModel.findOne({ user_id });
|
|
|
|
+ if (roleUser) {
|
|
|
|
+ obj.payer_role = 'Coach';
|
|
|
|
+ obj.payer_id = roleUser._id;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ obj.payer_role = 'Student';
|
|
|
|
+ obj.payer_id = roleUser._id;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ console.log(order_no);
|
|
|
|
+ console.log(obj);
|
|
|
|
+ await this.model.updateOne({ order_no }, obj);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = PayOrderService;
|
|
module.exports = PayOrderService;
|