瀏覽代碼

删除期后,合同支付默认排序恢复为最新一期排序

MaiXinRong 2 年之前
父節點
當前提交
1968ff9ace
共有 3 個文件被更改,包括 14 次插入2 次删除
  1. 11 0
      app/service/pay.js
  2. 1 1
      app/service/stage.js
  3. 2 1
      db_script/pay_order.js

+ 11 - 0
app/service/pay.js

@@ -197,6 +197,17 @@ module.exports = app => {
                 return updateData;
             }
         }
+
+        async doDeleteStage(stage, transaction) {
+            await transaction.delete(this.tableName, { csid: id });
+            if (stage.order > 1) {
+                const preStage = await this.ctx.service.stage.getDataByCondition({ tid: stage.tid, order: stage.order - 1});
+                const max = await this.db.query('SELECT MAX(stimes) as stimes, MAX(sorder) as sorder FROM ? WHERE sid = ?', [this.ctx.service.stagePay.tableName, preStage.id]);
+                const resortSql = `UPDATE ${this.tableName} p LEFT JOIN ${this.ctx.service.stagePay.tableName} sp ON p.id === sp.pid`+
+                    '  SET p.`order` = sp.porder WHERE p.tid = ? and sp.sid = ? and sp.stimes = ? and sp.sorder = ?';
+                await transaction.query(resortSql, [stage.tid, preStage.id, max.stimes, max.sorder]);
+            }
+        }
     }
 
     return Pay;

+ 1 - 1
app/service/stage.js

@@ -626,7 +626,7 @@ module.exports = app => {
                     }
                 }
                 await transaction.delete(this.ctx.service.stagePay.tableName, { sid: id });
-                await transaction.delete(this.ctx.service.pay.tableName, { csid: id });
+                await this.ctx.service.pay.doDeleteStage(stageInfo, transaction);
                 // 删除计量附件文件
                 const attList = await this.ctx.service.stageAtt.getAllDataByCondition({ where: { tid: stageInfo.tid, sid: stageInfo.order } });
                 if (attList.length !== 0) {

+ 2 - 1
db_script/pay_order.js

@@ -4,7 +4,7 @@ const querySql = BaseUtil.querySql;
 const checkPayOrder = async function (tid) {
     const pays = await querySql('SELECT * FROM zh_pay WHERE tid = ? and valid = 1 order by `order`', [tid]);
     for (const [i, pay] of pays.entries()) {
-        if (pay.order !== i + 1) await querySql('Update zh_pay Set `order` = ? Where id = ?', [i+1, pay.order]);
+        if (pay.order !== i + 1) await querySql('Update zh_pay Set `order` = ? Where id = ?', [i+1, pay.id]);
     }
 };
 
@@ -35,6 +35,7 @@ const doCompleteTest = async function(tid) {
 
 const tenderId = process.argv[3];
 if (tenderId) {
+    console.log(tenderId);
     doCompleteTest(tenderId);
 } else {
     doComplete()