浏览代码

批量插入问题

MaiXinRong 3 年之前
父节点
当前提交
257d5d9ed0
共有 1 个文件被更改,包括 5 次插入6 次删除
  1. 5 6
      app/service/ledger.js

+ 5 - 6
app/service/ledger.js

@@ -584,7 +584,7 @@ module.exports = app => {
             const info = this.ctx.tender.info;
             this.transaction = await this.db.beginTransaction();
 
-            const insertBillsData = [], insertPosData = [];
+            const insertBillsData = [], insertPosData = [], in_time = new Date();
             const maxId = await this._getMaxLid(tenderId);
             const order = selectData.order;
             for (let i = 0, iLen = data.length; i < iLen; i++) {
@@ -606,20 +606,19 @@ module.exports = app => {
                 insertBillsData.push(qd);
                 const precision = this.ctx.helper.findPrecision(info.precision, qd.unit);
                 if (data[i].pos.length > 0) {
-                    for (const [i, p] of data[i].pos.entries()) {
+                    for (const [j, p] of data[i].pos.entries()) {
                         const inD = {
-                            id: this.uuid.v4(), tid: tid, lid: bills.id,
+                            id: this.uuid.v4(), tid: tenderId, lid: qd.id,
                             add_stage: 0, add_times: 0, add_user: this.ctx.session.sessionUser.accountId,
-                            in_time, porder: i + 1,
+                            in_time, porder: j + 1,
                             name: p.name, drawing_code: p.drawing_code,
                         };
-                        if (d.quantity) {
+                        if (p.quantity) {
                             inD.sgfh_qty = this.round(p.quantity, precision.value);
                             inD.quantity = inD.sgfh_qty;
                             qd.sgfh_qty = this.ctx.helper.add(qd.sgfh_qty, inD.sgfh_qty);
                         }
                         insertPosData.push(inD);
-                        await transaction.insert(this.tableName, insertDatas);
                     }
                     qd.sgfh_tp = this.ctx.helper.mul(qd.sgfh_qty, qd.unit_price, info.decimal.tp);
                     qd.quantity = qd.sgfh_qty;