Ver código fonte

新建标段根据项目配置,初始化合同支付

maixinrong 5 anos atrás
pai
commit
d2d9c6098d
1 arquivos alterados com 23 adições e 15 exclusões
  1. 23 15
      app/service/pay.js

+ 23 - 15
app/service/pay.js

@@ -30,23 +30,31 @@ module.exports = app => {
          */
         async addDefaultPayData(tid, transaction) {
             const existPays = this.getAllDataByCondition({tid: tid});
-            const pays = JSON.parse(JSON.stringify(payConst.payTemplate));
-            if (existPays.length >= pays.length) { return false; }
+            if (existPays.length >= 0) { return false; }
 
-            for (const p of pays) {
-                p.tid = tid;
-                p.csid = 0;
-                p.cstimes = 0;
-                p.csorder = 0;
-                p.csaorder = 0;
-            }
-            let result;
-            if (transaction) {
-                result = await transaction.insert(this.tableName, pays);
-            } else {
-                result = await this.db.insert(this.tableName, pays);
+            try {
+                const projectData = await this.ctx.service.project.getDataById(this.ctx.session.sessionProject.id);
+                const pays = projectData.dealpay_json 
+                    ? JSON.parse(projectData.dealpay_json)
+                    : JSON.parse(JSON.stringify(payConst.payTemplate));
+    
+                for (const p of pays) {
+                    p.tid = tid;
+                    p.csid = 0;
+                    p.cstimes = 0;
+                    p.csorder = 0;
+                    p.csaorder = 0;
+                }
+                let result;
+                if (transaction) {
+                    result = await transaction.insert(this.tableName, pays);
+                } else {
+                    result = await this.db.insert(this.tableName, pays);
+                }
+                return result.affectedRows === pays.length;
+            } catch(error) {
+                throw '项目的默认合同支付数据有误';
             }
-            return result.affectedRows === pays.length;
         }
 
         async _getMaxOrder(tenderId) {