Prechádzať zdrojové kódy

清单数量计算问题

MaiXinRong 5 rokov pred
rodič
commit
ed6a3eedfb

+ 1 - 1
app/controller/stage_controller.js

@@ -199,7 +199,7 @@ module.exports = app => {
                 const responseData = {err: 0, msg: '', data: {}};
 
                 let curStageData, preStageData;
-                responseData.data = await ctx.service.pos.getPosData(condition);
+                responseData.data = await ctx.service.pos.getPosDataWithAddStageOrder(condition);
                 // 根据当前人,或指定对象查询数据
                 //console.time('cur');
                 const curWhere = JSON.parse(ctx.request.body.data);

+ 14 - 9
app/service/pos.js

@@ -23,17 +23,20 @@ module.exports = app => {
         }
 
         async getPosData(condition) {
+            return await this.db.select(this.tableName, {
+                where: condition,
+                columns: ['id', 'tid', 'lid', 'name', 'quantity', 'drawing_code', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'in_time', 'porder', 'add_stage'],
+                order: [['porder', 'ASC']],
+            });
+        }
+
+        async getPosDataWithAddStageOrder(condition) {
             const sql = 'SELECT p.id, p.tid, p.lid, p.name, p.quantity, p.drawing_code, p.sgfh_qty, p.sjcl_qty, p.qtcl_qty, p.porder, p.add_stage, p.add_times, p.add_user, s.order As add_stage_order ' +
                 '  FROM ' + this.tableName + ' p ' +
                 '  LEFT JOIN ' + this.ctx.service.stage.tableName + ' s' +
-                '  ON add_stage = s.id'
+                '  ON p.add_stage = s.id'
                 + this.ctx.helper.whereSql(condition, 'p');
             return await this.db.query(sql);
-            // return await this.db.select(this.tableName, {
-            //     where: condition,
-            //     columns: ['id', 'tid', 'lid', 'name', 'quantity', 'drawing_code', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'in_time', 'porder', 'add_stage'],
-            //     order: [['porder', 'ASC']],
-            // });
         }
 
         async getPosDataByIds(ids) {
@@ -56,7 +59,6 @@ module.exports = app => {
         }
 
         async getPosDataByUnits(tenderId, units) {
-            console.log(units);
             const sql = 'SELECT p.id, p.lid, p.sgfh_qty, p.sjcl_qty, p.qtcl_qty' +
                 '  FROM ' + this.tableName + ' p' +
                 '  LEFT JOIN ' + this.ctx.service.ledger.tableName + ' b' +
@@ -93,7 +95,6 @@ module.exports = app => {
             const transaction = await this.db.beginTransaction();
             try {
                 if (data.updateType === 'add') {
-                    const tender = await this.ctx.service.tender.getTender(tid);
                     if (data.updateData instanceof Array) {
                         for (const d of data.updateData) {
                             this._insertPosData(transaction, d, tid);
@@ -104,7 +105,11 @@ module.exports = app => {
                 } else if (data.updateType === 'update') {
                     const datas = data.updateData instanceof Array ? data.updateData : [data.updateData];
                     result.ledger.update = [];
-                    const orgPos = await this.getPosData({tid: tid, id: this._.map(datas, 'id')});
+                    const orgPos = await this.getAllDataByCondition({
+                        where: {tid: tid, id: this._.map(datas, 'id')},
+                        columns: ['id', 'tid', 'lid', 'name', 'quantity', 'drawing_code', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'in_time', 'porder', 'add_stage'],
+                        order: [['porder', 'ASC']],
+                    });
                     for (const d of datas) {
                         const op = this._.find(orgPos, function (p) { return p.id = d.id; });
                         if (d.sgfh_qty !== undefined || d.qtcl_qty !== undefined || d.sjcl_qty !== undefined) {

+ 1 - 1
app/service/stage_pos.js

@@ -386,7 +386,7 @@ module.exports = app => {
                     if (refreshData.isDeletePos) {
                         result.pos.pos = refreshData.pos;
                     } else if (refreshData.pos.length > 0) {
-                        result.pos.pos = await this.ctx.service.pos.getPosData({id: refreshData.pos});
+                        result.pos.pos = await this.ctx.service.pos.getPosDataWithAddStageOrder({id: refreshData.pos});
                         if (refreshData.stageUpdate) {
                             result.pos.curStageData = await this.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, {pid: refreshData.pos});
                         }