@@ -35,7 +35,7 @@ export class AccountService {
3535 request : Request ,
3636 currentInfo : ICurrentUserType
3737 ) : Promise < string > {
38- console . log ( request ) ;
38+ console . log ( '进来了------------------》》' , request ) ;
3939 // 1.判断当前商户下是否已经存在该账号
4040 const accountEntity : Pick < AccountEntity , 'id' > | null = await this . accountRepository . findOne ( {
4141 where : { username : req . username , tenantId : currentInfo . tenantId } ,
@@ -54,9 +54,9 @@ export class AccountService {
5454 sort : req . sort ,
5555 password : password ,
5656 tenantId : currentInfo . tenantId ,
57- parentId : currentInfo . accountId ,
57+ parentId : req . parentId ? req . parentId : currentInfo . id ,
5858 salt : salt ,
59- lastLoginIp : this . toolsService . getReqIP ( request ) ,
59+ // lastLoginIp: this.toolsService.getReqIP(request),
6060 lastLoginDate : new Date ( ) ,
6161 } ) ;
6262 await this . accountRepository . save ( data ) ;
@@ -180,7 +180,7 @@ export class AccountService {
180180 if ( [ StatusEnum . NORMAL , StatusEnum . FORBIDDEN ] . includes ( status ) ) {
181181 query . set ( 'status' , Equal ( status + '' ) ) ;
182182 }
183- const { accountType, accountId , tenantId } = currentInfo ;
183+ const { accountType, id , tenantId } = currentInfo ;
184184 /**
185185 * 1.如果是超管,查询到全部的账号
186186 * 2.如果不是超管,是主账号的时候查询下面全部的账号
@@ -194,19 +194,18 @@ export class AccountService {
194194 } else if ( accountType == AccountTypeEnum . PRIMARY_ACCOUNT ) {
195195 query . set ( 'tenantId' , Equal ( tenantId + '' ) ) ;
196196 } else if ( accountType == AccountTypeEnum . NORMAL_ACCOUNT ) {
197- query . set ( 'parentId' , Equal ( accountId + '' ) ) ;
197+ query . set ( 'parentId' , Equal ( id + '' ) ) ;
198198 }
199199 }
200200
201- console . log ( mapToObj ( query ) , '???????????????????' ) ;
202201 const total = await this . accountRepository
203202 . createQueryBuilder ( 'account' )
204203 . where ( mapToObj ( query ) )
205204 . getCount ( ) ;
206205 const queryBuilder = this . queryAccountBuilder ;
207206 const data = await queryBuilder
208207 . where ( mapToObj ( query ) )
209- . orderBy ( { id : 'DESC' } )
208+ . orderBy ( { accountType : 'DESC' , id : 'DESC' } )
210209 . offset ( ( pageNumber - 1 ) * pageSize )
211210 . limit ( pageSize )
212211 . getRawMany ( ) ;
@@ -218,6 +217,37 @@ export class AccountService {
218217 } ;
219218 }
220219
220+ /**
221+ * @Author : 水痕
222+ * @Date : 2023-10-10 18:56:27
223+ * @LastEditors : 水痕
224+ * @Description : 获取当前账号下的子账号
225+ * @param {ICurrentUserType } currentInfo
226+ * @param {number } status
227+ * @return {* }
228+ */
229+ async getAccountListApi (
230+ currentInfo : ICurrentUserType ,
231+ status : number
232+ ) : Promise < Pick < AccountEntity , 'id' | 'username' > [ ] > {
233+ const { id, accountType } = currentInfo ;
234+ console . log ( status , '状态' ) ;
235+ const query = new Map < string , FindOperator < string > > ( ) ;
236+ if ( Object . is ( accountType , AccountTypeEnum . SUPER_ACCOUNT ) ) {
237+ query . set ( 'parentId' , Equal ( - 1 + '' ) ) ;
238+ } else {
239+ query . set ( 'parentId' , Equal ( id + '' ) ) ;
240+ }
241+ if ( [ StatusEnum . FORBIDDEN , StatusEnum . NORMAL ] . includes ( status ) ) {
242+ query . set ( 'status' , Equal ( status + '' ) ) ;
243+ }
244+ const accountEntity : Pick < AccountEntity , 'id' | 'username' > [ ] =
245+ await this . accountRepository . find ( {
246+ where : mapToObj ( query ) ,
247+ select : [ 'id' , 'username' ] ,
248+ } ) ;
249+ return accountEntity ;
250+ }
221251 /**
222252 * @Author : 水痕
223253 * @Date : 2023-10-07 20:28:16
0 commit comments