Jelajahi Sumber

Merge branch 'main' of http://git.cc-lotus.info/Information/cxyy-service into main

zs 6 bulan lalu
induk
melakukan
d5deef67d7

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

@@ -64,6 +64,7 @@ export class UserController implements BaseController {
   async create(@Body() data: object) {
     await this.service.createExamine(data);
     await this.service.checkPhone(data);
+    await this.service.checkEmail(data);
     const dbData = await this.service.create(data);
     const result = new CVO_user(dbData);
     return result;
@@ -75,6 +76,8 @@ export class UserController implements BaseController {
   @ApiResponse({ type: UVAO_user })
   async update(@Param('id') id: number, @Body() data: object) {
     if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
+    await this.service.checkPhone(data)
+    await this.service.checkEmail(data)
     const result = await this.service.update({ id }, data);
     return result;
   }

+ 7 - 4
src/controller/users/contactApply.controller.ts

@@ -101,10 +101,12 @@ export class ContactApplyController {
     /**组织数据,填充联系方式申请表:将被申请方的id填充 */
     const userData = get(otherData, 'userData');
     // 如果是在跳过检查列表中的申请,则不需要target_user.直接由管理员审核
+    // 09-20修改: 没有target_user也允许,由管理员去填写内容
     if (!skipCheckList.includes(source)) {
-      if (!userData) throw new ServiceError(ErrorCode.CONTACTAPPLY_TARGET_USER_NOT_FOUND);
-      const target_user = get(userData, 'id');
-      data['target_user'] = target_user;
+      if (userData) {
+        const target_user = get(userData, 'id');
+        data['target_user'] = target_user;
+      }
     }
     // 检查是否有未审核的申请
     await this.service.checkHasApply(data);
@@ -115,8 +117,9 @@ export class ContactApplyController {
       // 没有keyword,无法计算匹配度,不用继续往下了.
       if (!keyword) throw new ServiceError(ErrorCode.CONTACTAPPLY_NO_KEYWORD); //抛出异常: 无关键词,无法进行匹配计算
       // 查询匹配度
-      const result = await this.esService.getCS(keyword, source);
+      const result = await this.esService.getCS(keyword, source, source_id);
       if (!result) throw new ServiceError(ErrorCode.CONTACTAPPLY_MATCHING_NOT_ENOUGH); // 抛出异常,无匹配度到4星,无法进行预约
+      return;
     }
     /**创建申请数据 */
     const dbData = await this.service.create(data);

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

@@ -18,6 +18,7 @@ export enum ErrorCode {
   DUPLICATE_USERS_ACCOUNT = 'DUPLICATE_USERS_ACCOUNT',
   DUPLICATE_USERS_OPENID = 'DUPLICATE_USERS_OPENID',
   PHONE_IS_EXISTS = 'PHONE_IS_EXISTS',
+  EMAIL_IS_EXISTS = 'EMAIL_IS_EXISTS',
   LOGIN_VALICODE_EXPIRES = 'LOGIN_VALICODE_EXPIRES',
   LOGIN_VALICODE_ERROR = 'LOGIN_VALICODE_ERROR',
   PLEASE_INPUT_LOGIN_CODE = 'PLEASE_INPUT_LOGIN_CODE',

+ 3 - 2
src/service/elasticsearch/es.service.ts

@@ -89,9 +89,10 @@ export class ESService {
    * 计算匹配度
    * @param keyword 查询关键词
    * @param index 表
+   * @param source_id 数据id
    */
-  async getCS(keyword, index) {
-    const csUrl = `${this.esServiceHttpPrefix}/cs/${index}?keyword=${keyword}`;
+  async getCS(keyword, index, source_id) {
+    const csUrl = `${this.esServiceHttpPrefix}/cs/${index}?keyword=${keyword}&id=${source_id}`;
     let res;
     const token = get(this.ctx.request, 'header.token')
     try {

+ 4 - 4
src/service/login.service.ts

@@ -52,10 +52,10 @@ export class LoginService {
    * 注册验证 验证码
    * @param phone 电话号码
    * @param code 验证码
-   * @returns 
+   * @returns
    */
-  async checkRegCode(phone,code) {
-    const redisKey = `${this.regSmsSign}:${phone}`
+  async checkRegCode(phone, code) {
+    const redisKey = `${this.regSmsSign}:${phone}`;
     const redisCode = await this.redisService.get(redisKey);
     if (!redisCode) throw new ServiceError(ErrorCode.REG_VALICODE_EXPIRES); // 验证码已过期
     if (`${redisCode}` !== `${code}`) throw new ServiceError(ErrorCode.REG_VALICODE_ERROR); // 验证码错误
@@ -68,7 +68,7 @@ export class LoginService {
    * @param phone 电话号码
    */
   async sendRegCode(phone) {
-    const redisKey = `${this.regSmsSign}:${phone}`
+    const redisKey = `${this.regSmsSign}:${phone}`;
     const code = random(1000, 999999);
     await this.redisService.set(redisKey, code, 'EX', this.timeLimit);
     await this.smsService.send(phone, code);

+ 17 - 1
src/service/system/user.service.ts

@@ -18,11 +18,27 @@ export class UserService extends BaseServiceV2 {
     else data.status = '1';
     return data;
   }
+  async checkEmail(data) {
+    const email = get(data, 'email');
+    if (!email) return;
+    const builder = await this.model.createQueryBuilder().where('"email" =:value', { value: email });
+    // 如果有id,则视为修改,查非自己的email是否存在
+    const id = get(data, 'id');
+    if (id) builder.andWhere('"id" != :id', { id });
+    const num = await builder.getCount();
+    if (num <= 0) return true;
+    // 邮箱存在
+    throw new ServiceError(ErrorCode.EMAIL_IS_EXISTS);
+  }
 
   async checkPhone(data) {
     const phone = get(data, 'phone');
     if (!phone) return;
-    const num = await this.model.createQueryBuilder().where('"phone" =:value', { value: phone }).getCount();
+    const builder = await this.model.createQueryBuilder().where('"phone" =:value', { value: phone });
+    // 如果有id,则视为修改,查非自己的phone是否存在
+    const id = get(data, 'id');
+    if (id) builder.andWhere('"id" != :id', { id });
+    const num = await builder.getCount();
     if (num <= 0) return true;
     // 手机号存在
     throw new ServiceError(ErrorCode.PHONE_IS_EXISTS);