zs 7 maanden geleden
bovenliggende
commit
d8b2230eca

+ 77 - 0
src/controller/users/applyCompany.controller.ts

@@ -0,0 +1,77 @@
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/core';
+import { ApplyCompanyService } from '../../service/users/applyCompany.service';
+import { CVO_applyCompany, FVO_applyCompany, QVO_applyCompany, UVAO_applyCompany } from '../../interface/users/applyCompany.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+import { BaseController } from '../../frame/BaseController';
+import { omit, pick } from 'lodash';
+import { ErrorCode, ServiceError } from '../../error/service.error';
+import { ServiceUtilService } from '../../service/serviceUtil.service';
+const namePrefix = '企业申请';
+@ApiTags(['企业申请'])
+@Controller('/applyCompany', { tagName: namePrefix })
+export class ApplyCompanyController implements BaseController {
+  @Inject()
+  service: ApplyCompanyService;
+
+  @Inject()
+  serviceUtil: ServiceUtilService;
+
+  @Post('/examine', { routerName: `审核${namePrefix}` })
+  @ApiTags('信息审核')
+  @ApiQuery({ name: 'examine' })
+  async examine(@Body('id') id: number, @Body('status') status: string) {
+    if (!id || !status) throw new ServiceError(ErrorCode.BODY_ERROR);
+    const result = await this.service.update({ id }, { status });
+    return result;
+  }
+
+  @Get('/')
+  @ApiTags('列表查询')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_applyCompany })
+  async index(@Query() query: object) {
+    const qobj = omit(query, ['skip', 'limit']);
+    const others = pick(query, ['skip', 'limit']);
+    const result = await this.service.query(qobj, others);
+    return result;
+  }
+
+  @Get('/:id')
+  @ApiTags('单查询')
+  @ApiResponse({ type: FVO_applyCompany })
+  async fetch(@Param('id') id: number) {
+    const data = await this.service.fetch({ id });
+    const result = new FVO_applyCompany(data);
+    return result;
+  }
+
+  @Post('/', { routerName: `创建${namePrefix}` })
+  @ApiTags('创建数据')
+  @Validate()
+  @ApiResponse({ type: CVO_applyCompany })
+  async create(@Body() data: object) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_applyCompany(dbData);
+    return result;
+  }
+
+  @Post('/:id', { routerName: `修改${namePrefix}` })
+  @ApiTags('修改数据')
+  @Validate()
+  @ApiResponse({ type: UVAO_applyCompany })
+  async update(@Param('id') id: number, @Body() data: object) {
+    if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
+    const result = await this.service.update({ id }, data);
+    return result;
+  }
+
+  @Del('/:id', { routerName: `删除${namePrefix}` })
+  @ApiTags('删除数据')
+  @Validate()
+  async delete(@Param('id') id: number) {
+    if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
+    const result = await this.service.delete({ id });
+    return result;
+  }
+}

+ 22 - 0
src/entity/users/applyCompany.entity.ts

@@ -0,0 +1,22 @@
+import { Column, Entity } from 'typeorm';
+import { BaseModel } from '../../frame/BaseModel';
+// 企业申请
+@Entity('applyCompany')
+export class ApplyCompany extends BaseModel {
+  @Column({ type: 'integer', nullable: true, comment: '平台用户id' })
+  user: number;
+  @Column({ type: 'integer', nullable: true, comment: '企业id' })
+  company: number;
+  @Column({ type: 'jsonb', nullable: true, comment: '营业执照', default: [] })
+  file: Array<any>;
+  @Column({ type: 'character varying', nullable: true, comment: '负责人' })
+  person: string;
+  @Column({ type: 'character varying', nullable: true, comment: '负责人电话' })
+  person_phone: string;
+  @Column({ type: 'jsonb', nullable: true, comment: '负责人身份证正反面', default: [] })
+  card: Array<any>;
+  @Column({ type: 'character varying', nullable: true, comment: '电子邮箱' })
+  email: string;
+  @Column({ type: 'character varying', nullable: true, default: '0', comment: '状态' })
+  status: string;
+}

+ 99 - 0
src/interface/users/applyCompany.interface.ts

@@ -0,0 +1,99 @@
+import { ApiProperty } from '@midwayjs/swagger';
+import { Rule, RuleType } from '@midwayjs/validate';
+import { dealVO } from '../../frame/VOBase';
+export class FVO_applyCompany {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  id: string = undefined;
+  @ApiProperty({ description: '平台用户id' })
+  'user': number = undefined;
+  @ApiProperty({ description: '企业id' })
+  'company': number = undefined;
+  @ApiProperty({ description: '营业执照' })
+  'file': Array<any> = undefined;
+  @ApiProperty({ description: '负责人' })
+  'person': string = undefined;
+  @ApiProperty({ description: '负责人电话' })
+  'person_phone': string = undefined;
+  @ApiProperty({ description: '负责人身份证正反面' })
+  'card': Array<any> = undefined;
+  @ApiProperty({ description: '电子邮箱' })
+  'email': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+export class QDTO_applyCompany {
+  @ApiProperty({ description: '平台用户id' })
+  'user': number = undefined;
+  @ApiProperty({ description: '企业id' })
+  'company': number = undefined;
+  @ApiProperty({ description: '营业执照' })
+  'file': Array<any> = undefined;
+  @ApiProperty({ description: '负责人' })
+  'person': string = undefined;
+  @ApiProperty({ description: '负责人电话' })
+  'person_phone': string = undefined;
+  @ApiProperty({ description: '负责人身份证正反面' })
+  'card': Array<any> = undefined;
+  @ApiProperty({ description: '电子邮箱' })
+  'email': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+}
+
+export class QVO_applyCompany extends FVO_applyCompany {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_applyCompany {
+  @ApiProperty({ description: '平台用户id' })
+  @Rule(RuleType['number']().empty(''))
+  'user': number = undefined;
+  @ApiProperty({ description: '企业id' })
+  @Rule(RuleType['number']().empty(''))
+  'company': number = undefined;
+  @ApiProperty({ description: '营业执照' })
+  @Rule(RuleType['array']().empty(''))
+  'file': Array<any> = undefined;
+  @ApiProperty({ description: '负责人' })
+  @Rule(RuleType['string']().empty(''))
+  'person': string = undefined;
+  @ApiProperty({ description: '负责人电话' })
+  @Rule(RuleType['string']().empty(''))
+  'person_phone': string = undefined;
+  @ApiProperty({ description: '负责人身份证正反面' })
+  @Rule(RuleType['array']().empty(''))
+  'card': Array<any> = undefined;
+  @ApiProperty({ description: '电子邮箱' })
+  @Rule(RuleType['string']().empty(''))
+  'email': string = undefined;
+  @ApiProperty({ description: '状态' })
+  @Rule(RuleType['string']().empty(''))
+  'status': string = undefined;
+}
+
+export class CVO_applyCompany extends FVO_applyCompany {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_applyCompany extends CDTO_applyCompany {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['number']().empty(''))
+  id: number = undefined;
+}
+
+export class UVAO_applyCompany extends FVO_applyCompany {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 10 - 0
src/service/users/applyCompany.service.ts

@@ -0,0 +1,10 @@
+import { Provide } from '@midwayjs/core';
+import { InjectEntityModel } from '@midwayjs/typeorm';
+import { Repository } from 'typeorm';
+import { ApplyCompany } from '../../entity/users/applyCompany.entity';
+import { BaseServiceV2 } from '../../frame/BaseServiceV2';
+@Provide()
+export class ApplyCompanyService extends BaseServiceV2 {
+  @InjectEntityModel(ApplyCompany)
+  model: Repository<ApplyCompany>;
+}

+ 5 - 14
src/service/util.service.ts

@@ -407,27 +407,18 @@ export class UtilService {
     // 需要查看是否有人,有人更新数据,没人添加数据
     for (const [index, i] of result.entries()) {
       // 根据 企业名称 查重
-      const { name, industry } = i;
+      const { name } = i;
       const data = await this.companyModel.findOne({ where: { name: Equal(name) } });
       if (data && data.id) {
         try {
           i.id = data.id;
-          const userInfo = await this.userModel.findOne({ where: { account: Equal(name), nick_name: Equal(name) } });
-          if (userInfo && userInfo.id) {
-            await this.companyModel.update({ id: data.id }, { ...i, user: userInfo.id, status: '1' });
-          } else {
-            const userInfo = await this.userModel.insert({ account: name, nick_name: name, password: '123456', industry: [industry], gender: '0', role: ['User', 'Company'], status: '1' });
-            const id = get(userInfo, 'identifiers.0.id');
-            await this.companyModel.update({ id: data.id }, { ...i, user: id, status: '1' });
-          }
+          await this.companyModel.update({ id: data.id }, { ...i, status: '1' });
         } catch (error) {
           errorList.push(`修改第${index + 1}条${name}出现错误!!!`);
         }
       } else {
         try {
-          const userInfo = await this.userModel.insert({ account: name, nick_name: name, password: '123456', industry: [industry], gender: '0', role: ['User', 'Company'], status: '1' });
-          const id = get(userInfo, 'identifiers.0.id');
-          await this.companyModel.insert({ ...i, user: id, status: '1', is_show: '1' });
+          await this.companyModel.insert({ ...i, status: '1', is_show: '1' });
         } catch (error) {
           const namek = Object.keys(error.errors)[0];
           const mapping = mappingList.find(i => i.field === namek);
@@ -455,7 +446,7 @@ export class UtilService {
           i.id = data.id;
           await this.yModel.update({ id: data.id }, i);
         } catch (error) {
-          errorList.push(`修改第${index + 1}条${name}出现错误!!!`);
+          errorList.push(`修改第${index + 1}条${company}出现错误!!!`);
         }
       } else {
         try {
@@ -466,7 +457,7 @@ export class UtilService {
         } catch (error) {
           const namek = Object.keys(error.errors)[0];
           const mapping = mappingList.find(i => i.field === namek);
-          errorList.push(`第${index + 1}条${mapping.zh}列${name}字段出现错误!!!`);
+          errorList.push(`第${index + 1}条${mapping.zh}列${company}字段出现错误!!!`);
         }
       }
     }