lrf %!s(int64=2) %!d(string=hai) anos
pai
achega
47033f6fcd
Modificáronse 4 ficheiros con 20 adicións e 4 borrados
  1. 1 1
      app/model/race/matchSign.js
  2. 12 1
      app/service/bill.js
  3. 5 0
      app/service/matchSign.js
  4. 2 2
      app/service/payOrder.js

+ 1 - 1
app/model/race/matchSign.js

@@ -4,7 +4,7 @@ const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 
 // 赛事报名
 const match_sign = {
-  match_id: { type: String, required: true, zh: '赛事id', ref: 'Match', getProp: [ 'name' ] }, // 比赛信息中的名称
+  match_id: { type: String, required: true, zh: '赛事id', ref: 'Match', getProp: [ 'name', 'status' ] }, // 比赛信息中的名称
   group_id: { type: String, required: true, zh: '组别id', ref: 'MatchGroup', getProp: [ 'name' ] }, // 赛事组别中的名称
   project_id: { type: String, required: true, zh: '项目id', ref: 'MatchProject', getProp: [ 'name' ] }, // 组别项目中的名称
   user_id: { type: String, required: true, zh: '用户id' }, //

+ 12 - 1
app/service/bill.js

@@ -4,11 +4,22 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
 const _ = require('lodash');
 const assert = require('assert');
 
-// 
+//
 class BillService extends CrudService {
   constructor(ctx) {
     super(ctx, 'bill');
     this.model = this.ctx.model.Race.Bill;
+    this.baseUserModel = this.ctx.model.Base.User;
+  }
+
+  async afterQuery(filter, data) {
+    for (const i of data) {
+      const user_id = _.get(i, 'payer_id.user_id');
+      const user = await this.baseUserModel.findById(user_id);
+      if (user) i.payer_name = user.name;
+    }
+
+    return data;
   }
 }
 

+ 5 - 0
app/service/matchSign.js

@@ -22,6 +22,11 @@ class MatchSignService extends CrudService {
     await this.checkHas(body);
     return body;
   }
+  async beforeUpdate(filter, update) {
+    // 比赛结束后不能退款
+    return { filter, update };
+  }
+
   // 退赛
   async afterUpdate(filter, body, data) {
     const { pay_status } = data;

+ 2 - 2
app/service/payOrder.js

@@ -38,11 +38,11 @@ class PayOrderService extends CrudService {
     // 只有支付成功和退款才进行操作;不过这个退款是走线下,其实也没有
     if (status === '-3') throw new BusinessError(ErrorCode.DATA_INVALID, '退款应该是线下退款');
     const obj = _.pick(data, [ 'match_id', 'group_id', 'project_id' ]);
-    const { _id: pay_id, status: pay_status, payer_id: user_id } = data;
+    const { _id: pay_id, status: pay_status, payer_id: user_id, money } = data;
     // 报名数据
     const signData = { ...obj, pay_id, pay_status, user_id };
     // 账单数据
-    const billData = { ...obj, pay_id, payer_id: data.payer_id, type: '1', time: moment().format('YYYY-MM-DD HH:mm:ss'), is_pay: pay_status };
+    const billData = { ...obj, pay_id, payer_id: data.payer_id, type: '1', time: moment().format('YYYY-MM-DD HH:mm:ss'), is_pay: pay_status, money };
     // 生成报名数据,与账单数据. 如果失败,则删除报名数据并提示联系管理员
     const sign = await this.matchSignModel.create(signData);
     try {