|
@@ -3,7 +3,7 @@ const { CrudService } = require('naf-framework-mongoose-free/lib/service');
|
|
|
const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
const _ = require('lodash');
|
|
|
const assert = require('assert');
|
|
|
-
|
|
|
+const moment = require('moment');
|
|
|
//
|
|
|
class MatchSignService extends CrudService {
|
|
|
constructor(ctx) {
|
|
@@ -12,6 +12,7 @@ class MatchSignService extends CrudService {
|
|
|
this.matchModel = this.ctx.model.Race.Match;
|
|
|
this.matchGroupModel = this.ctx.model.Race.MatchGroup;
|
|
|
this.matchProjectModel = this.ctx.model.Race.MatchProject;
|
|
|
+ this.billModel = this.ctx.model.Race.Bill;
|
|
|
}
|
|
|
/**
|
|
|
* 检查是否已经有该赛事,该组别,该项目的报名
|
|
@@ -21,6 +22,18 @@ class MatchSignService extends CrudService {
|
|
|
await this.checkHas(body);
|
|
|
return body;
|
|
|
}
|
|
|
+ // 退赛
|
|
|
+ async afterUpdate(filter, body, data) {
|
|
|
+ const { pay_status } = data;
|
|
|
+ if (pay_status !== '-3') return data;
|
|
|
+ // 线下管理人员允许退款,生成账单
|
|
|
+ const obj = _.pick(data, [ 'match_id', 'group_id', 'project_id' ]);
|
|
|
+ obj.payer_id = data.user_id;
|
|
|
+ obj.time = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ obj.type = '-1';
|
|
|
+ await this.billModel.create(obj);
|
|
|
+ return data;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 检查有没有报过名
|
|
@@ -59,7 +72,6 @@ class MatchSignService extends CrudService {
|
|
|
if (gender !== cardGender) throw new BusinessError(ErrorCode.DATA_INVALID, '性别不符合组别条件');
|
|
|
}
|
|
|
return true;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
checkAgeInRange(age, cardAge) {
|
|
@@ -172,16 +184,13 @@ class MatchSignService extends CrudService {
|
|
|
return '1';
|
|
|
}
|
|
|
return '0';
|
|
|
-
|
|
|
} else if (idCard.length === 18) {
|
|
|
if (idCard.substring(14, 17) % 2 === 0) {
|
|
|
return '1';
|
|
|
}
|
|
|
return '0';
|
|
|
-
|
|
|
}
|
|
|
return null;
|
|
|
-
|
|
|
}
|
|
|
// 年龄
|
|
|
getAge(idCard) {
|