xiongzhu 2 лет назад
Родитель
Сommit
7ba9282a98

+ 37 - 7
src/commission/commission.service.ts

@@ -1,3 +1,4 @@
+import { join } from 'path'
 import { Injectable } from '@nestjs/common'
 import { InjectRepository } from '@nestjs/typeorm'
 import { CommissionConfig } from './entities/commission-config.entity'
@@ -7,6 +8,8 @@ import { Users } from '../users/entities/users.entity'
 import { UserBalanceService } from '../user-balance/user-balance.service'
 import { BalanceType as BalanceType } from 'src/user-balance/entities/balance-record.entity'
 import { BigNumber } from 'bignumber.js'
+import { CommissionRecordDto } from './dto/commission-record.dto'
+import { hideSensitiveData } from 'src/utils/common'
 
 @Injectable()
 export class CommissionService {
@@ -60,13 +63,40 @@ export class CommissionService {
     }
 
     async getRecords(userId: number) {
-        return await this.commissionRecordRepository.find({
-            where: {
-                userId
-            },
-            order: {
-                createdAt: 'DESC'
-            }
+        return (
+            await this.commissionRecordRepository
+                .createQueryBuilder()
+                .leftJoinAndMapOne(
+                    'CommissionRecord.fromUser',
+                    Users,
+                    'fromUser',
+                    'CommissionRecord.fromUserId = fromUser.id'
+                )
+                .where('CommissionRecord.userId = :userId', { userId })
+                .orderBy('CommissionRecord.createdAt', 'DESC')
+                .getMany()
+        ).map((record) => {
+            return new CommissionRecordDto({
+                id: record.id,
+                userId: record.userId,
+                fromUserId: record.fromUserId,
+                name: hideSensitiveData(record.fromUser?.name),
+                level: record.level,
+                ratio: record.ratio,
+                amount: record.amount
+            })
         })
+
+        // return await this.commissionRecordRepository.find({
+        //     relations: {
+        //         fromUser: true
+        //     },
+        //     where: {
+        //         userId
+        //     },
+        //     order: {
+        //         createdAt: 'DESC'
+        //     }
+        // })
     }
 }

+ 16 - 0
src/commission/dto/commission-record.dto.ts

@@ -0,0 +1,16 @@
+import BigNumber from "bignumber.js"
+
+export class CommissionRecordDto {
+    id: number
+    userId: number
+    name: string
+    fromUserId: number
+    level: number
+    ratio: BigNumber
+    amount: BigNumber
+    createdAt: Date
+
+    constructor(data: Partial<CommissionRecordDto>) {
+        Object.assign(this, data)
+    }
+}

+ 2 - 0
src/commission/entities/commission-record.entity.ts

@@ -13,6 +13,8 @@ export class CommissionRecord {
     @Column()
     fromUserId: number
 
+    fromUser: any
+
     @Column()
     level: number
 

+ 3 - 0
src/utils/common.ts

@@ -0,0 +1,3 @@
+export function hideSensitiveData(str: string) {
+    return str.replace(/(?<=.).(?=.*.)/g, '*')
+}