|
@@ -21,6 +21,9 @@ class MatchSignService extends CrudService {
|
|
|
* @param {Object} body 参数体
|
|
|
*/
|
|
|
async beforeCreate(body) {
|
|
|
+ const { match_id } = body;
|
|
|
+ const num = await this.matchModel.count({ _id: match_id, status: '1' });
|
|
|
+ if (num <= 0) throw new BusinessError(ErrorCode.SERVICE_FAULT, '当前赛事无法报名');
|
|
|
await this.checkHas(body);
|
|
|
return body;
|
|
|
}
|
|
@@ -31,7 +34,7 @@ class MatchSignService extends CrudService {
|
|
|
const { id } = filter;
|
|
|
const data = await this.model.findById(id);
|
|
|
const { match_id } = data;
|
|
|
- const num = await this.matchModel.count({ _id: match_id, status: { $nin: [ '0', '1', '2' ] } });
|
|
|
+ const num = await this.matchModel.count({ _id: match_id, status: { $nin: ['0', '1', '2'] } });
|
|
|
if (num > 0) throw new BusinessError(ErrorCode.DATA_INVALID, '赛事已经处于准备开赛或开赛中,不能退赛');
|
|
|
return { filter, update };
|
|
|
}
|
|
@@ -43,7 +46,7 @@ class MatchSignService extends CrudService {
|
|
|
if (!raceUser) continue;
|
|
|
const { user_id } = raceUser;
|
|
|
const user = await this.baseUserModel.findById(user_id);
|
|
|
- if (user)i.user_name = user.name;
|
|
|
+ if (user) i.user_name = user.name;
|
|
|
}
|
|
|
return data;
|
|
|
}
|
|
@@ -53,7 +56,7 @@ class MatchSignService extends CrudService {
|
|
|
const { pay_status } = data;
|
|
|
if (pay_status !== '-3') return data;
|
|
|
// 线下管理人员允许退款,生成账单
|
|
|
- const obj = _.pick(data, [ 'match_id', 'group_id', 'project_id' ]);
|
|
|
+ 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';
|
|
@@ -68,7 +71,7 @@ class MatchSignService extends CrudService {
|
|
|
*/
|
|
|
async checkHas(body) {
|
|
|
const { match_id, group_id, project_id, user_id } = body;
|
|
|
- const query = { match_id, group_id, project_id, user_id, pay_status: [ '0', '1' ] };
|
|
|
+ const query = { match_id, group_id, project_id, user_id, pay_status: ['0', '1'] };
|
|
|
const num = await this.model.count(query);
|
|
|
if (num > 0) throw new BusinessError(ErrorCode.DATA_EXISTED, '您已报名');
|
|
|
return true;
|