浏览代码

修改错误提示

zs 9 月之前
父节点
当前提交
fc98ad4daf

+ 11 - 12
src/controller/login.controller.ts

@@ -42,19 +42,18 @@ export class LoginController {
 
   /**
    * TODO:微信小程序登录
-   * @param openid 微信小程序openid
+   * @param type 用户类型
    */
-  // @Post('/wxapp/:openid')
-  // async wxAppLogin(@Param('openid') openid: string) {
-  //   if (!openid) throw new ServiceError('缺少微信凭证!', FrameworkErrorEnum.BAD_PARAMS);
-  //   const user = await this.loginService.wxAppLogin(openid);
-  //   let vo = new LoginVO(user);
-  //   vo = JSON.parse(JSON.stringify(vo));
-  //   const token = await this.jwtService.sign(vo, this.jwtSecret, {
-  //     expiresIn: this.jwtExpiresIn,
-  //   });
-  //   return token;
-  // }
+  @Post('/wxapp/:type')
+  async wxAppLogin(@Body('openid') openid: string, @Param('type') type: string) {
+    if (!openid) assert(openid, '缺少微信唯一标识信息');
+    const user = await this.loginService.wxAppLogin(openid, LoginType[type]);
+    let vo = new LoginVO(user);
+    vo = JSON.parse(JSON.stringify(vo));
+    vo.login_code = await this.loginService.onePointLogin(vo);
+    const token = await this.jwtService.sign(vo, this.jwtSecret);
+    return token;
+  }
   /**
    * 修改密码
    * @param data 修改密码所需数据

+ 7 - 2
src/controller/platform/sign.controller.ts

@@ -6,6 +6,7 @@ import { Controller, Inject, Get, Param, Post, Body, Del, Query } from '@midwayj
 import { omit, pick } from 'lodash';
 import { ServiceError, ErrorCode } from '../../error/service.error';
 import { BaseController } from '../../frame/BaseController';
+import { Context } from '@midwayjs/koa';
 const namePrefix = '赛事报名表';
 
 @ApiTags(['赛事报名表'])
@@ -14,6 +15,9 @@ export class SignController implements BaseController {
   @Inject()
   service: SignService;
 
+  @Inject()
+  ctx: Context;
+
   @Get('/')
   @ApiTags('列表查询')
   @ApiQuery({ name: 'query' })
@@ -41,6 +45,7 @@ export class SignController implements BaseController {
   @Validate()
   @ApiResponse({ type: CVO_sign })
   async create(@Body() data: object) {
+    await this.service.createExamine(data);
     const dbData = await this.service.create(data);
     const result = new CVO_sign(dbData);
     return result;
@@ -65,8 +70,8 @@ export class SignController implements BaseController {
     return result;
   }
   @Get('/sign')
-  async sign(@Query() filter) {
-    const list = await this.service.sign(filter);
+  async sign() {
+    const list = await this.service.sign(this.ctx.query);
     return list;
   }
 }

+ 1 - 0
src/controller/system/user.controller.ts

@@ -49,6 +49,7 @@ export class UserController implements BaseController {
   @Validate()
   @ApiResponse({ type: CVO_user })
   async create(@Body() data: object) {
+    await this.service.createExamine(data);
     const dbData = await this.service.create(data);
     const result = new CVO_user(dbData);
     return result;

+ 2 - 0
src/entity/platform/sign.entity.ts

@@ -23,4 +23,6 @@ export class Sign extends BaseModel {
   time: string;
   @Column({ type: 'character varying', nullable: true, comment: '备注' })
   remark: string;
+  @Column({ type: 'character varying', nullable: true, comment: '状态', default: '0' })
+  status: string;
 }

+ 2 - 0
src/error/service.error.ts

@@ -12,6 +12,8 @@ export enum ErrorCode {
   USER_IS_DISABLED = 'USER_IS_DISABLED',
   ROLE_IS_DISABLED = 'ROLE_IS_DISABLED',
   SERVICE_REPEAT = 'SERVICE_REPEAT',
+  DUPLICATE_USERS_ACCOUNT = 'DUPLICATE_USERS_ACCOUNT',
+  DUPLICATE_USERS_OPENID = 'DUPLICATE_USERS_OPENID',
 
   // 参数
   ID_NOT_FOUND = 'ID_NOT_FOUND',

+ 7 - 0
src/interface/platform/sign.interface.ts

@@ -28,6 +28,8 @@ export class FVO_sign {
   'time': string = undefined;
   @ApiProperty({ description: '备注' })
   'remark': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
 }
 
 export class QDTO_sign extends SearchBase {
@@ -39,6 +41,8 @@ export class QDTO_sign extends SearchBase {
   'name': string = undefined;
   @ApiProperty({ description: '报名时间' })
   'time': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
 }
 
 export class QVO_sign extends FVO_sign {
@@ -79,6 +83,9 @@ export class CDTO_sign {
   @ApiProperty({ description: '备注' })
   @Rule(RuleType['string']().empty(''))
   'remark': string = undefined;
+  @ApiProperty({ description: '状态' })
+  @Rule(RuleType['string']().empty(''))
+  'status': string = undefined;
 }
 
 export class CVO_sign extends FVO_sign {

+ 10 - 15
src/service/login.service.ts

@@ -97,22 +97,17 @@ export class LoginService {
     user.password = data.password;
     await user.save();
   }
+
   // 需要改的时候再用
-  // async wxAppLogin(openid: string) {
-  //   const tables = ['Doctor', 'Nurse', 'Patient'];
-  //   let user;
-  //   let role;
-  //   for (const table of tables) {
-  //     const model = GetModel(upperFirst(table));
-  //     user = await model.findOne({ openid }).lean();
-  //     if (user) {
-  //       role = table;
-  //       break;
-  //     }
-  //   }
-  //   if (user) return { ...user, role };
-  //   throw new ServiceError('未找到用户信息!', FrameworkErrorEnum.NOT_FOUND_DATA);
-  // }
+  async wxAppLogin(openid: string, type: LoginType) {
+    let model;
+    if (type === LoginType.Admin) model = this.adminModel;
+    else model = this.userModel;
+    const user = await model.findOne({ where: { openid: Equal(openid) } });
+    if (!user) throw new ServiceError(ErrorCode.USER_NOT_FOUND);
+    return user;
+  }
+
   randomStr(len = 32) {
     return Math.random().toString(36).slice(-len);
   }

+ 1 - 10
src/service/platform/sign.service.ts

@@ -37,16 +37,7 @@ export class SignService extends BaseService<Sign> {
         // const matchInfo = await this.mModel.findById(val.match).lean();
         const matchInfo = await this.mModel.findOne({ where: { id: Equal(val.match) } });
         if (matchInfo) {
-          data.push({
-            _id: get(val, 'id'),
-            match: get(val, 'match'),
-            money: get(matchInfo, 'money'),
-            match_name: get(matchInfo, 'name'),
-            match_time: get(matchInfo, 'time'),
-            organization: get(matchInfo, 'organization'),
-            time: get(val, 'time'),
-            status: get(matchInfo, 'match_status'),
-          });
+          data.push({ ...val, ...{ matchInfo } });
         }
       }
     }

+ 15 - 0
src/service/system/user.service.ts

@@ -3,6 +3,7 @@ import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Equal, Repository } from 'typeorm';
 import { BaseService } from '../../frame/BaseService';
 import { User } from '../../entity/system/user.entity';
+import { ErrorCode, ServiceError } from '../../error/service.error';
 @Provide()
 export class UserService extends BaseService<User> {
   @InjectEntityModel(User)
@@ -15,6 +16,20 @@ export class UserService extends BaseService<User> {
     return data;
   }
 
+  // 用户账号,微信唯一标识检查
+  async createExamine(data) {
+    const { openid, account } = data;
+    let result;
+    if (account) {
+      result = await this.model.findOne({ where: { account: Equal(account) } });
+      if (result) throw new ServiceError(ErrorCode.DUPLICATE_USERS_ACCOUNT);
+    }
+    if (openid) {
+      result = await this.model.findOne({ where: { openid: Equal(openid) } });
+      if (result) throw new ServiceError(ErrorCode.DUPLICATE_USERS_OPENID);
+    }
+  }
+
   // 修改后判断是否有身份 如何审核通过将有身份的数据也审核成功
   async updateAfter(id, body) {
     const arr = await this.detail(id);