Explorar o código

修复支付审批列表bug

ellisran hai 2 meses
pai
achega
a68b458202
Modificáronse 2 ficheiros con 9 adicións e 3 borrados
  1. 6 0
      app/service/payment_folder.js
  2. 3 3
      app/service/payment_tender.js

+ 6 - 0
app/service/payment_folder.js

@@ -86,6 +86,12 @@ module.exports = app => {
                         const delids = this._.map(deleteData, 'folder_id');
                         ids = [...ids, ...delids];
                     }
+                    // 父节点可能变成is_leaf为0
+                    const parentFolderInfo = await this.getDataByCondition({ spid: this.ctx.subProject.id, folder_id: info.parent_id });
+                    const childrenCount = await this.getAllDataByCondition({ where: { spid: this.ctx.subProject.id, parent_id: parentFolderInfo.folder_id } });
+                    if (childrenCount.length === 1) {
+                        await transaction.update(this.tableName, { id: parentFolderInfo.id, is_leaf: 1 });
+                    }
                 }
                 // 判断是否存在标段,有则无法删除目录
                 const tenderCount = await this.ctx.service.paymentTender.count({ spid: this.ctx.subProject.id, folder_id: ids });

+ 3 - 3
app/service/payment_tender.js

@@ -59,7 +59,7 @@ module.exports = app => {
         async addTender(projectId, uid, folderId, name) {
             const transaction = await this.db.beginTransaction();
             try {
-                const folderInfo = await this.ctx.service.paymentFolder.getDataById(folderId);
+                const folderInfo = await this.ctx.service.paymentFolder.getDataByCondition({ spid: this.ctx.subProject.id, folder_id: parseInt(folderId) });
                 if (!folderInfo || folderInfo.is_leaf === 0) {
                     throw '文件夹不存在或存在子目录不能新建标段';
                 }
@@ -110,12 +110,12 @@ module.exports = app => {
                 if (had_detail) {
                     throw '请先删除所有报表表单详情';
                 }
-                const folderInfo = await this.ctx.service.paymentFolder.getDataById(tenderInfo.folder_id);
+                const folderInfo = await this.ctx.service.paymentFolder.getDataByCondition({ spid: this.ctx.subProject.id, folder_id: tenderInfo.folder_id });
                 if (!folderInfo) {
                     throw '文件夹不存在';
                 }
                 // 判断folderInfo下是否还存在tender,不存在则把had_tender为0,并判断父节点是否需要也为0
-                const leafTenderCount = await transaction.count(this.tableName, { folder_id: folderInfo.id });
+                const leafTenderCount = await transaction.count(this.tableName, { spid: this.ctx.subProject.id, folder_id: folderInfo.folder_id });
                 if (leafTenderCount === 1) {
                     const updateDatas = [{
                         id: folderInfo.id,