zs hace 1 año
padre
commit
39de83def4

+ 6 - 0
src/controller/Statistics.controller.ts

@@ -12,4 +12,10 @@ export class StatisticsController {
     const list = await this.service.order();
     return list;
   }
+
+  @Get('/user')
+  async userView() {
+    const list = await this.service.user();
+    return list;
+  }
 }

+ 2 - 0
src/entity/User.entity.ts

@@ -40,6 +40,8 @@ export class User extends BaseModel {
   community: string;
   @prop({ required: false, index: true, zh: '微信id' })
   openid: string;
+  @prop({ required: false, index: true, zh: '创建时间' })
+  create_time: string;
   @prop({
     required: false,
     index: true,

+ 8 - 0
src/interface/User.interface.ts

@@ -28,6 +28,8 @@ export class FVO_User {
   'street': string = undefined;
   @ApiProperty({ description: '所属社区' })
   'community': string = undefined;
+  @ApiProperty({ description: '创建时间' })
+  'create_time': string = undefined;
   @ApiProperty({ description: '微信id' })
   'openid': string = undefined;
   @ApiProperty({ description: '状态' })
@@ -45,6 +47,7 @@ export class QDTO_User extends SearchBase {
       'street',
       'community',
       'openid',
+      'create_time',
       'status',
     ];
     const mapping = [];
@@ -64,6 +67,8 @@ export class QDTO_User extends SearchBase {
   'community': string = undefined;
   @ApiProperty({ description: '微信id' })
   'openid': string = undefined;
+  @ApiProperty({ description: '创建时间' })
+  'create_time': string = undefined;
   @ApiProperty({ description: '状态' })
   'status': string = undefined;
 }
@@ -97,6 +102,9 @@ export class CDTO_User {
   @ApiProperty({ description: '所属社区' })
   @Rule(RuleType['string']().empty(''))
   'community': string = undefined;
+  @ApiProperty({ description: '创建时间' })
+  @Rule(RuleType['string']().empty(''))
+  'create_time': string = undefined;
   @ApiProperty({ description: '微信id' })
   @Rule(RuleType['string']().empty(''))
   'openid': string = undefined;

+ 17 - 0
src/service/Statistics.service.ts

@@ -33,4 +33,21 @@ export class StatisticsService {
     }
     return result;
   }
+
+  // 每个月注册数量
+  async user(): Promise<Array<any>> {
+    const result = [];
+    const time = moment().format('YYYY');
+    for (let i = 1; i < 13; i++) {
+      let create_time;
+      if (i < 10) create_time = `${time}-0${i}`;
+      else create_time = `${time}-${i}`;
+      result.push(
+        await this.userModel
+          .count({ create_time: { $regex: create_time } })
+          .lean()
+      );
+    }
+    return result;
+  }
 }