|
@@ -10,12 +10,27 @@ class TeamApplyService extends CrudService {
|
|
|
super(ctx, 'teamapply');
|
|
|
this.model = this.ctx.model.Race.TeamApply;
|
|
|
this.matchSignModel = this.ctx.model.Race.MatchSign;
|
|
|
+ this.matchProjectModel = this.ctx.model.Race.MatchProject;
|
|
|
}
|
|
|
|
|
|
async beforeCreate(body) {
|
|
|
- // 检查该项目下,这个俩用户是否有报名申请
|
|
|
+ // 检查:1.这两个人 是否报过 该比赛项目,且支付成功
|
|
|
+ // 2.该比赛项目是否是双打, type 是否为1
|
|
|
+ // 3.这两人是否有 组队申请,且申请拒绝
|
|
|
const { project_id, one_member_id, one_member_name, two_member_id, two_member_name } = body;
|
|
|
- let num = await this.checkHasTeamApply(project_id, one_member_id);
|
|
|
+ // check 1
|
|
|
+ const check1 = async (project_id, user_id) => await this.matchSignModel.count({ project_id, user_id });
|
|
|
+ let num = await check1(project_id, one_member_id);
|
|
|
+ if (num <= 0) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, `${one_member_name} 没有报名该比赛项目`);
|
|
|
+ num = await check1(project_id, two_member_id);
|
|
|
+ if (num <= 0) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, `${two_member_name} 没有报名该比赛项目`);
|
|
|
+ // check2
|
|
|
+ const project = await this.matchProjectModel.findById(project_id);
|
|
|
+ if (!project) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到比赛项目');
|
|
|
+ const { type } = project;
|
|
|
+ if (type !== '1') throw new BusinessError(ErrorCode.DATA_INVALID, '该比赛项目不为双打,无需进行组队申请');
|
|
|
+ // check3
|
|
|
+ num = await this.checkHasTeamApply(project_id, one_member_id);
|
|
|
if (num > 0) throw new BusinessError(ErrorCode.SERVICE_FAULT, `${one_member_name} 在该比赛项目下已有组队申请`);
|
|
|
num = await this.checkHasTeamApply(project_id, two_member_id);
|
|
|
if (num > 0) throw new BusinessError(ErrorCode.SERVICE_FAULT, `${two_member_name} 在该比赛项目下已有组队申请`);
|
|
@@ -109,13 +124,13 @@ class TeamApplyService extends CrudService {
|
|
|
return count;
|
|
|
}
|
|
|
/**
|
|
|
- * 查询该比赛项目下,这个用户是否有组队申请
|
|
|
+ * 查询该比赛项目下,这个用户是否有 有效的 组队申请
|
|
|
* @param {String} project_id 比赛项目
|
|
|
* @param {String} user_id 比赛模块用户数据id
|
|
|
* @return {number} 组队条数
|
|
|
*/
|
|
|
async checkHasTeamApply(project_id, user_id) {
|
|
|
- return await this.model.count({ project_id, $or: [{ one_member_id: user_id }, { two_member_id: user_id }] });
|
|
|
+ return await this.model.count({ project_id, $or: [{ one_member_id: user_id }, { two_member_id: user_id }], type: { $ne: '-1' } });
|
|
|
}
|
|
|
|
|
|
selfQueryDeal(condition) {
|