ellisran 4 minggu lalu
induk
melakukan
aeb2727589
1 mengubah file dengan 19 tambahan dan 21 penghapusan
  1. 19 21
      app/service/financial_transfer_tender.js

+ 19 - 21
app/service/financial_transfer_tender.js

@@ -41,7 +41,7 @@ module.exports = app => {
             const transaction = await this.db.beginTransaction();
             try {
                 const insertDatas = [];
-                const needCalc = [];
+                // const needCalc = [];
                 const updateDatas = [];
                 const ftList = await this.ctx.service.financialTransfer.getAllDataByCondition({ where: { spid: transferInfo.spid } });
                 const beforeFt = this._.filter(ftList, function(item) {
@@ -59,12 +59,12 @@ module.exports = app => {
                     if (ftt) {
                         throw '资金划拨标段已存在';
                     }
-                    await this.ctx.service.tenderCache.loadTenderCache(tender, this.ctx.session.sessionUser.accountId);
-                    if (tender.stage_tp) {
-                        tender.end_sf_tp = this.ctx.helper.add(tender.stage_tp.pre_sf_tp, tender.stage_tp.sf_tp);
-                    } else if (tender.lastStage) {
-                        tender.end_sf_tp = this.ctx.helper.add(tender.lastStage.pre_sf_tp, tender.lastStage.sf_tp);
-                    }
+                    // await this.ctx.service.tenderCache.loadTenderCache(tender, this.ctx.session.sessionUser.accountId);
+                    // if (tender.stage_tp) {
+                    //     tender.end_sf_tp = this.ctx.helper.add(tender.stage_tp.pre_sf_tp, tender.stage_tp.sf_tp);
+                    // } else if (tender.lastStage) {
+                    //     tender.end_sf_tp = this.ctx.helper.add(tender.lastStage.pre_sf_tp, tender.lastStage.sf_tp);
+                    // }
                     // 找出已添加的划拨标段,得出pre_hb_tp
                     let pre_hb_tp = 0;
                     if (beforeFt.length > 0) {
@@ -79,7 +79,7 @@ module.exports = app => {
                         trid: transferInfo.id,
                         tid: t,
                         uid: this.ctx.session.sessionUser.accountId,
-                        hb_tp: tender.end_sf_tp,
+                        hb_tp: 0,
                         pre_hb_tp,
                     };
                     if (afterFt.length > 0) {
@@ -88,7 +88,7 @@ module.exports = app => {
                             for (const aftt of afterFttList) {
                                 aftt.pre_hb_tp = this.ctx.helper.add(aftt.pre_hb_tp, insertData.hb_tp);
                                 updateDatas.push({ id: aftt.id, pre_hb_tp: aftt.pre_hb_tp });
-                                needCalc.push(aftt.trid);
+                                // needCalc.push(aftt.trid);
                             }
                         }
                     }
@@ -100,22 +100,22 @@ module.exports = app => {
                 }
                 // 计算划拨金额
                 await this.calcHbTp(transferInfo.id, transaction);
-                if (needCalc.length > 0) {
+                if (afterFt.length > 0) {
                     const newFtList = await transaction.select(this.ctx.service.financialTransfer.tableName, { where: { spid: transferInfo.spid } });
                     // 更新划拨金额
                     const updatePreHbTp = [];
-                    for (const tr of needCalc) {
+                    for (const tr of afterFt) {
                         // await this.calcHbTp(tr, transaction);
-                        const thisFt = this._.find(newFtList, { id: tr });
+                        const thisFt = this._.find(newFtList, { id: tr.id });
                         let pre_hb_tp = 0;
                         const beforeFtList = this._.filter(newFtList, function(item) {
-                            return item.id < tr;
+                            return item.id < tr.id;
                         });
                         if (beforeFtList && beforeFtList.length > 0) {
                             pre_hb_tp = this.ctx.helper.sum(this._.map(beforeFtList, 'total_price'));
                         }
                         if (pre_hb_tp !== thisFt.pre_hb_tp) {
-                            updatePreHbTp.push({ id: tr, pre_hb_tp });
+                            updatePreHbTp.push({ id: tr.id, pre_hb_tp });
                         }
                     }
                     if (updatePreHbTp.length > 0) {
@@ -213,34 +213,32 @@ module.exports = app => {
                 return item.id > transferInfo.id;
             });
             if (afterFt.length === 0) return;
-            const needCalc = [];
             const updateDatas = [];
             const afterFttList = await this.getAllDataByCondition({ where: { spid: transferInfo.spid, trid: this._.map(afterFt, 'id'), tid: ftt.tid } });
             if (afterFttList && afterFttList.length > 0) {
                 for (const aftt of afterFttList) {
                     aftt.pre_hb_tp = this.ctx.helper.add(this.ctx.helper.sub(aftt.pre_hb_tp, ftt.hb_tp), newHbTp);
                     updateDatas.push({ id: aftt.id, pre_hb_tp: aftt.pre_hb_tp });
-                    needCalc.push(aftt.trid);
                 }
             }
             if (updateDatas.length > 0) {
                 await transaction.updateRows(this.tableName, updateDatas);
             }
-            if (needCalc.length > 0) {
+            if (afterFt.length > 0) {
                 // 更新划拨金额
                 const updatePreHbTp = [];
-                for (const tr of needCalc) {
+                for (const tr of afterFt) {
                     // await this.calcHbTp(tr, transaction);
-                    const thisFt = this._.find(ftList, { id: tr });
+                    const thisFt = this._.find(ftList, { id: tr.id });
                     let pre_hb_tp = 0;
                     const beforeFtList = this._.filter(ftList, function(item) {
-                        return item.id < tr;
+                        return item.id < tr.id;
                     });
                     if (beforeFtList && beforeFtList.length > 0) {
                         pre_hb_tp = this.ctx.helper.sum(this._.map(beforeFtList, 'total_price'));
                     }
                     if (pre_hb_tp !== thisFt.pre_hb_tp) {
-                        updatePreHbTp.push({ id: tr, pre_hb_tp });
+                        updatePreHbTp.push({ id: tr.id, pre_hb_tp });
                     }
                 }
                 if (updatePreHbTp.length > 0) {