|  | @@ -19,6 +19,10 @@ module.exports = app => {
 | 
	
		
			
				|  |  |          async addFolder(projectId, uid, parentId = 0, name) {
 | 
	
		
			
				|  |  |              const transaction = await this.db.beginTransaction();
 | 
	
		
			
				|  |  |              try {
 | 
	
		
			
				|  |  | +                const tenderCount = await this.ctx.service.paymentTender.count({ folder_id: parentId });
 | 
	
		
			
				|  |  | +                if (tenderCount > 0) {
 | 
	
		
			
				|  |  | +                    throw '目录下存在标段无法创建子目录';
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |                  let level = 1;
 | 
	
		
			
				|  |  |                  let parent_path = '';
 | 
	
		
			
				|  |  |                  if (parentId !== 0) {
 | 
	
	
		
			
				|  | @@ -56,6 +60,9 @@ module.exports = app => {
 | 
	
		
			
				|  |  |              const transaction = await this.db.beginTransaction();
 | 
	
		
			
				|  |  |              try {
 | 
	
		
			
				|  |  |                  const info = await this.getDataById(id);
 | 
	
		
			
				|  |  | +                if (info.uid !== this.ctx.session.sessionUser.accountId && !this.ctx.session.sessionUser.is_admin) {
 | 
	
		
			
				|  |  | +                    throw '您没有权限删除此目录';
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |                  let ids = [info.id];
 | 
	
		
			
				|  |  |                  if (info.parent_path) {
 | 
	
		
			
				|  |  |                      const deleteData = await this.getDataByParentPath(this.tableName, info.parent_path + '-' + info.id + '%', transaction);
 | 
	
	
		
			
				|  | @@ -64,6 +71,11 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                          ids = [...ids, ...delids];
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | +                // 判断是否存在标段,有则无法删除目录
 | 
	
		
			
				|  |  | +                const tenderCount = await this.ctx.service.paymentTender.count({ folder_id: ids });
 | 
	
		
			
				|  |  | +                if (tenderCount > 0) {
 | 
	
		
			
				|  |  | +                    throw '目录下存在标段,无法删除';
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |                  await transaction.delete(this.tableName, { id: ids });
 | 
	
		
			
				|  |  |                  await transaction.commit();
 | 
	
		
			
				|  |  |              } catch (err) {
 | 
	
	
		
			
				|  | @@ -84,35 +96,48 @@ module.exports = app => {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async getList(uid, tenderList, auditPermission) {
 | 
	
		
			
				|  |  | +            // 获取所有项目参与者
 | 
	
		
			
				|  |  | +            const accountList = await this.ctx.service.projectAccount.getAllDataByCondition({
 | 
	
		
			
				|  |  | +                where: { project_id: this.ctx.session.sessionProject.id, enable: 1 },
 | 
	
		
			
				|  |  | +                columns: ['id', 'name'],
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +            let folderList = [];
 | 
	
		
			
				|  |  |              if (auditPermission.view_all) {
 | 
	
		
			
				|  |  | -                return await this.getAllDataByCondition({ where: { pid: this.ctx.session.sessionProject.id } });
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            let folderList = await this.getAllDataByCondition({ where: { uid } });
 | 
	
		
			
				|  |  | -            // 再找出标段对应的目录及自建的目录下的子目录
 | 
	
		
			
				|  |  | -            if (tenderList.length > 0) {
 | 
	
		
			
				|  |  | -                for (const t of tenderList) {
 | 
	
		
			
				|  |  | -                    if (this._.findIndex(folderList, { id: t.folder_id }) === -1) {
 | 
	
		
			
				|  |  | -                        const folderInfo = await this.getDataById(t.folder_id);
 | 
	
		
			
				|  |  | -                        folderList.push(folderInfo);
 | 
	
		
			
				|  |  | +                folderList = await this.getAllDataByCondition({ where: { pid: this.ctx.session.sessionProject.id } });
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                folderList = await this.getAllDataByCondition({ where: { uid } });
 | 
	
		
			
				|  |  | +                // 再找出标段对应的目录及自建的目录下的子目录
 | 
	
		
			
				|  |  | +                if (tenderList.length > 0) {
 | 
	
		
			
				|  |  | +                    for (const t of tenderList) {
 | 
	
		
			
				|  |  | +                        if (this._.findIndex(folderList, { id: t.folder_id }) === -1) {
 | 
	
		
			
				|  |  | +                            const folderInfo = await this.getDataById(t.folder_id);
 | 
	
		
			
				|  |  | +                            folderList.push(folderInfo);
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if (folderList.length > 0) {
 | 
	
		
			
				|  |  | +                    const leafFolderList = this._.filter(folderList, { is_leaf: 1 });
 | 
	
		
			
				|  |  | +                    const parentFolderIdList = this._.map(this._.filter(folderList, { is_leaf: 0 }), 'id');
 | 
	
		
			
				|  |  | +                    for (const lf of leafFolderList) {
 | 
	
		
			
				|  |  | +                        let parentPathArray = lf.parent_path !== '' ? lf.parent_path.split('-') : [];
 | 
	
		
			
				|  |  | +                        if (parentPathArray.length > 0) {
 | 
	
		
			
				|  |  | +                            parentPathArray = parentPathArray.map(function(data) {
 | 
	
		
			
				|  |  | +                                return +data;
 | 
	
		
			
				|  |  | +                            });// 字符串数组转整型数组
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        const notExistFolderIds = this._.difference(parentPathArray, parentFolderIdList);
 | 
	
		
			
				|  |  | +                        if (notExistFolderIds.length > 0) {
 | 
	
		
			
				|  |  | +                            const newFolderList = await this.getAllDataByCondition({ where: { id: notExistFolderIds } });
 | 
	
		
			
				|  |  | +                            console.log(newFolderList);
 | 
	
		
			
				|  |  | +                            folderList = [...folderList, ...newFolderList];
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              if (folderList.length > 0) {
 | 
	
		
			
				|  |  | -                const leafFolderList = this._.filter(folderList, { is_leaf: 1 });
 | 
	
		
			
				|  |  | -                const parentFolderIdList = this._.map(this._.filter(folderList, { is_leaf: 0 }), 'id');
 | 
	
		
			
				|  |  | -                for (const lf of leafFolderList) {
 | 
	
		
			
				|  |  | -                    let parentPathArray = lf.parent_path !== '' ? lf.parent_path.split('-') : [];
 | 
	
		
			
				|  |  | -                    if (parentPathArray.length > 0) {
 | 
	
		
			
				|  |  | -                        parentPathArray = parentPathArray.map(function(data) {
 | 
	
		
			
				|  |  | -                            return +data;
 | 
	
		
			
				|  |  | -                        });// 字符串数组转整型数组
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    const notExistFolderIds = this._.difference(parentPathArray, parentFolderIdList);
 | 
	
		
			
				|  |  | -                    if (notExistFolderIds.length > 0) {
 | 
	
		
			
				|  |  | -                        const newFolderList = await this.getAllDataByCondition({ where: { id: notExistFolderIds } });
 | 
	
		
			
				|  |  | -                        console.log(newFolderList);
 | 
	
		
			
				|  |  | -                        folderList = [...folderList, ...newFolderList];
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | +                for (const f of folderList) {
 | 
	
		
			
				|  |  | +                    const userInfo = this._.find(accountList, { id: f.uid });
 | 
	
		
			
				|  |  | +                    f.user_name = userInfo ? userInfo.name : '';
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              return folderList;
 |