|  | @@ -32,7 +32,7 @@ import {
 | 
	
		
			
				|  |  |      G_FILE_VER
 | 
	
		
			
				|  |  |  } from './project_property_template';
 | 
	
		
			
				|  |  |  import optionSetting from '../../options/models/optionTypes';
 | 
	
		
			
				|  |  | -import fixedFlag from '../../common/const/bills_fixed';
 | 
	
		
			
				|  |  | +const { fixedFlag } = require('../../../public/common_constants');
 | 
	
		
			
				|  |  |  let FeeRateFiles = mongoose.model('fee_rate_file');
 | 
	
		
			
				|  |  |  let counter = require("../../../public/counter/counter.js");
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -236,75 +236,70 @@ ProjectsDAO.prototype.updateUserProjects = async function (userId, compilationId
 | 
	
		
			
				|  |  |                  data.updateData['deleteInfo'] = deleteInfo;
 | 
	
		
			
				|  |  |                  //Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
 | 
	
		
			
				|  |  |                  //update
 | 
	
		
			
				|  |  | -                try {
 | 
	
		
			
				|  |  | -                    if (data.updateData.projType === projectType.project) {
 | 
	
		
			
				|  |  | -                        let engineerings = await Projects.find({userID: userId, ParentID: data.updateData.ID});
 | 
	
		
			
				|  |  | -                        let isExist = false;
 | 
	
		
			
				|  |  | -                        if (engineerings.length > 0) {
 | 
	
		
			
				|  |  | -                            for (let j = 0, jLen = engineerings.length; j < jLen; j++) {
 | 
	
		
			
				|  |  | -                                let e_tenders = await Projects.find({userID: userId, ParentID: engineerings[j].ID});
 | 
	
		
			
				|  |  | -                                if (e_tenders.length > 0) {
 | 
	
		
			
				|  |  | -                                    isExist = true;
 | 
	
		
			
				|  |  | -                                    break;
 | 
	
		
			
				|  |  | -                                }
 | 
	
		
			
				|  |  | +                if (data.updateData.projType === projectType.project) {
 | 
	
		
			
				|  |  | +                    let engineerings = await Projects.find({ userID: userId, ParentID: data.updateData.ID });
 | 
	
		
			
				|  |  | +                    let isExist = false;
 | 
	
		
			
				|  |  | +                    if (engineerings.length > 0) {
 | 
	
		
			
				|  |  | +                        for (let j = 0, jLen = engineerings.length; j < jLen; j++) {
 | 
	
		
			
				|  |  | +                            let e_tenders = await Projects.find({ userID: userId, ParentID: engineerings[j].ID });
 | 
	
		
			
				|  |  | +                            if (e_tenders.length > 0) {
 | 
	
		
			
				|  |  | +                                isExist = true;
 | 
	
		
			
				|  |  | +                                break;
 | 
	
		
			
				|  |  |                              }
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  | -                        if (isExist) {//fake
 | 
	
		
			
				|  |  | -                            await UnitPriceFiles.update({
 | 
	
		
			
				|  |  | -                                user_id: userId,
 | 
	
		
			
				|  |  | -                                root_project_id: data.updateData.ID
 | 
	
		
			
				|  |  | -                            }, {$set: {deleteInfo: deleteInfo}}, {multi: true});
 | 
	
		
			
				|  |  | -                            await FeeRateFiles.update({
 | 
	
		
			
				|  |  | -                                userID: userId,
 | 
	
		
			
				|  |  | -                                rootProjectID: data.updateData.ID
 | 
	
		
			
				|  |  | -                            }, {$set: {deleteInfo: deleteInfo}}, {multi: true});
 | 
	
		
			
				|  |  | -                            await Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                        else {//true
 | 
	
		
			
				|  |  | -                            await UnitPriceFiles.remove({user_id: userId, root_project_id: data.updateData.ID});
 | 
	
		
			
				|  |  | -                            await FeeRateFiles.remove({userID: userId, rootProjectID: data.updateData.ID});
 | 
	
		
			
				|  |  | -                            //await Projects.update({userID: userId, NextSiblingID: data.updateData.ID, deleteInfo: null}, {$set: {NextSiblingID: data.NextSiblingID}});
 | 
	
		
			
				|  |  | -                            await Projects.remove({userID: userId, ID: data.updateData.ID}, updateAll);
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | -                    else if (data.updateData.projType === projectType.engineering) {
 | 
	
		
			
				|  |  | -                        let tenders = await Projects.find({userID: userId, ParentID: data.updateData.ID});
 | 
	
		
			
				|  |  | -                        if (tenders.length > 0) {//fake
 | 
	
		
			
				|  |  | -                            await Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
 | 
	
		
			
				|  |  | +                    if (isExist) {//fake
 | 
	
		
			
				|  |  | +                        await UnitPriceFiles.update({
 | 
	
		
			
				|  |  | +                            user_id: userId,
 | 
	
		
			
				|  |  | +                            root_project_id: data.updateData.ID
 | 
	
		
			
				|  |  | +                        }, { $set: { deleteInfo: deleteInfo } }, { multi: true });
 | 
	
		
			
				|  |  | +                        await FeeRateFiles.update({
 | 
	
		
			
				|  |  | +                            userID: userId,
 | 
	
		
			
				|  |  | +                            rootProjectID: data.updateData.ID
 | 
	
		
			
				|  |  | +                        }, { $set: { deleteInfo: deleteInfo } }, { multi: true });
 | 
	
		
			
				|  |  | +                        await Projects.update({ userID: userId, ID: data.updateData.ID }, data.updateData, updateAll);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    else {//true
 | 
	
		
			
				|  |  | +                        await UnitPriceFiles.remove({ user_id: userId, root_project_id: data.updateData.ID });
 | 
	
		
			
				|  |  | +                        await FeeRateFiles.remove({ userID: userId, rootProjectID: data.updateData.ID });
 | 
	
		
			
				|  |  | +                        //await Projects.update({userID: userId, NextSiblingID: data.updateData.ID, deleteInfo: null}, {$set: {NextSiblingID: data.NextSiblingID}});
 | 
	
		
			
				|  |  | +                        await Projects.remove({ userID: userId, ID: data.updateData.ID }, updateAll);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                else if (data.updateData.projType === projectType.engineering) {
 | 
	
		
			
				|  |  | +                    let tenders = await Projects.find({ userID: userId, ParentID: data.updateData.ID });
 | 
	
		
			
				|  |  | +                    if (tenders.length > 0) {//fake
 | 
	
		
			
				|  |  | +                        await Projects.update({ userID: userId, ID: data.updateData.ID }, data.updateData, updateAll);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    else {//true
 | 
	
		
			
				|  |  | +                        //await Projects.update({userID: userId, NextSiblingID: data.updateData.ID, deleteInfo: null}, {$set: {NextSiblingID: data.NextSiblingID}});
 | 
	
		
			
				|  |  | +                        await Projects.remove({ userID: userId, ID: data.updateData.ID }, updateAll);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                else if (data.updateData.projType === projectType.tender) {//fake
 | 
	
		
			
				|  |  | +                    let delTender = await Projects.findOne({ userID: userId, ID: data.updateData.ID });
 | 
	
		
			
				|  |  | +                    //如果这个单位工程用到的费率文件、单价文件,没有被其他的单位工程使用,则应该一起跟随删除
 | 
	
		
			
				|  |  | +                    if (delTender) {
 | 
	
		
			
				|  |  | +                        let unitPriceFile = delTender.property.unitPriceFile;
 | 
	
		
			
				|  |  | +                        let feeRateFile = delTender.property.feeFile;
 | 
	
		
			
				|  |  | +                        let usedUFTenders = await Projects.find(
 | 
	
		
			
				|  |  | +                            { userID: userId, $or: [{ deleteInfo: null }, { 'deleteInfo.deleted': false }], 'property.unitPriceFile.id': unitPriceFile.id });
 | 
	
		
			
				|  |  | +                        if (usedUFTenders.length === 1) {
 | 
	
		
			
				|  |  | +                            await UnitPriceFiles.update({ id: unitPriceFile.id }, { $set: { deleteInfo: deleteInfo } });
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  | -                        else {//true
 | 
	
		
			
				|  |  | -                            //await Projects.update({userID: userId, NextSiblingID: data.updateData.ID, deleteInfo: null}, {$set: {NextSiblingID: data.NextSiblingID}});
 | 
	
		
			
				|  |  | -                            await Projects.remove({userID: userId, ID: data.updateData.ID}, updateAll);
 | 
	
		
			
				|  |  | +                        let usedFRTenders = await Projects.find(
 | 
	
		
			
				|  |  | +                            { userID: userId, $or: [{ deleteInfo: null }, { 'deleteInfo.deleted': false }], 'property.feeFile.id': feeRateFile.id });
 | 
	
		
			
				|  |  | +                        if (usedFRTenders.length === 1) {
 | 
	
		
			
				|  |  | +                            await FeeRateFiles.update({ ID: feeRateFile.id }, { $set: { deleteInfo: deleteInfo } });
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  | +                        await Projects.update({ userID: userId, ID: data.updateData.ID }, data.updateData, updateAll);
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | -                    else if (data.updateData.projType === projectType.tender) {//fake
 | 
	
		
			
				|  |  | -                        let delTender = await Projects.findOne({userID: userId, ID: data.updateData.ID});
 | 
	
		
			
				|  |  | -                        //如果这个单位工程用到的费率文件、单价文件,没有被其他的单位工程使用,则应该一起跟随删除
 | 
	
		
			
				|  |  | -                        if(delTender){
 | 
	
		
			
				|  |  | -                            let unitPriceFile = delTender.property.unitPriceFile;
 | 
	
		
			
				|  |  | -                            let feeRateFile = delTender.property.feeFile;
 | 
	
		
			
				|  |  | -                            let usedUFTenders = await Projects.find(
 | 
	
		
			
				|  |  | -                                {userID: userId, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], 'property.unitPriceFile.id': unitPriceFile.id});
 | 
	
		
			
				|  |  | -                            if(usedUFTenders.length === 1){
 | 
	
		
			
				|  |  | -                                await UnitPriceFiles.update({id: unitPriceFile.id}, {$set: {deleteInfo: deleteInfo}});
 | 
	
		
			
				|  |  | -                            }
 | 
	
		
			
				|  |  | -                            let usedFRTenders = await Projects.find(
 | 
	
		
			
				|  |  | -                                {userID: userId, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], 'property.feeFile.id': feeRateFile.id});
 | 
	
		
			
				|  |  | -                            if(usedFRTenders.length === 1){
 | 
	
		
			
				|  |  | -                                await FeeRateFiles.update({ID: feeRateFile.id}, {$set: {deleteInfo: deleteInfo}});
 | 
	
		
			
				|  |  | -                            }
 | 
	
		
			
				|  |  | -                            await Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    else if (data.updateData.projType === projectType.folder) {//true
 | 
	
		
			
				|  |  | -                        await Projects.remove({userID: userId, ID: data.updateData.ID}, updateAll);
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    else throw '未知文件类型,删除失败!';
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                catch (error) {
 | 
	
		
			
				|  |  | -                    callback(1, error, null);
 | 
	
		
			
				|  |  | +                else if (data.updateData.projType === projectType.folder) {//true
 | 
	
		
			
				|  |  | +                    await Projects.remove({ userID: userId, ID: data.updateData.ID }, updateAll);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | +                else throw '未知文件类型,删除失败!';
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              else {
 | 
	
		
			
				|  |  |                  hasError = true;
 |