浏览代码

Merge branch 'dev' of http://192.168.1.41:3000/maixinrong/Calculation into dev

laiguoran 4 年之前
父节点
当前提交
75a6ab1d8b

+ 14 - 1
app/base/base_bills_service.js

@@ -21,6 +21,19 @@ const math = require('mathjs');
 
 class BaseBillsSerivce extends TreeService {
 
+    constructor (ctx, setting, relaPosName) {
+        super(ctx, setting);
+        this.relaPosService = relaPosName;
+    }
+
+    set relaPosService(posName) {
+        this._posName = posName;
+    }
+
+    get relaPosService() {
+        return this.ctx.service[this._posName];
+    }
+
     // 继承方法
     clearParentingData(data) {
         data.unit_price = null;
@@ -649,7 +662,7 @@ class BaseBillsSerivce extends TreeService {
             }
             this._cacheMaxLid(tid, maxId);
             if (pastePosData.length > 0) {
-                await this.transaction.insert(this.ctx.service.pos.tableName, pastePosData);
+                await this.transaction.insert(this.relaPosService.tableName, pastePosData);
             }
             await this.transaction.commit();
         } catch (err) {

+ 4 - 10
app/controller/revise_controller.js

@@ -455,15 +455,8 @@ module.exports = app => {
                 const revise = await ctx.service.ledgerRevise.getLastestRevise(ctx.tender.id);
                 if (!revise) throw '台账修订数据有误';
 
-                const billsFile = revise.bills_file ? this.ctx.app.config.filePath + revise.bills_file : undefined;
-                const reviseBills = billsFile && fs.existsSync(billsFile)
-                    ? JSON.parse(await fs.readFileSync(billsFile, 'utf8'))
-                    : await ctx.service.reviseBills.getData(ctx.tender.id);
-
-                const posFile = revise.pos_file ? this.ctx.app.config.filePath + revise.pos_file : undefined;
-                const revisePos = posFile && fs.existsSync(posFile)
-                    ? JSON.parse(await fs.readFileSync(posFile, 'utf8'))
-                    : await ctx.service.revisePos.getData(ctx.tender.id);
+                const reviseBills = await ctx.service.reviseBills.getData(ctx.tender.id);
+                const revisePos = await ctx.service.revisePos.getData(ctx.tender.id);
 
                 const qtyData = ctx.helper.checkBillsWithPos(reviseBills, revisePos,
                     ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity']);
@@ -479,7 +472,8 @@ module.exports = app => {
                             bills: [...qtyData.source.bills, ...tpData.source.bills],
                             pos: [...qtyData.source.pos, ...tpData.source.pos],
                         },
-                    }};
+                    }
+                };
             } catch (err) {
                 this.log(err);
                 ctx.body = this.ajaxErrorBody(err, '检查数据错误');

+ 1 - 1
app/service/ledger.js

@@ -51,7 +51,7 @@ module.exports = app => {
                 fullPath: 'full_path',
                 keyPre: 'ledger_bills_maxLid:',
                 uuid: true,
-            });
+            }, 'pos');
             this.tableName = 'ledger';
         }
 

+ 4 - 4
app/service/pos.js

@@ -215,8 +215,8 @@ module.exports = app => {
 
                 const transaction = await this.db.beginTransaction();
                 try {
-                    transaction.update(this.tableName, data);
-                    transaction.update(this.ctx.service.ledger.tableName, updateBills);
+                    await transaction.update(this.tableName, data);
+                    await transaction.update(this.ctx.service.ledger.tableName, updateBills);
                     await transaction.commit();
                     updateBills.ledger_id = bills.ledger_id;
                     return {
@@ -288,7 +288,7 @@ module.exports = app => {
             const transaction = await this.db.beginTransaction();
             try {
                 for (const d of data) {
-                    transaction.update(this.tableName, d);
+                    await transaction.update(this.tableName, d);
                 }
                 if (needUpdateBills) await transaction.update(this.ctx.service.ledger.tableName, updateBills);
                 await transaction.commit();
@@ -417,7 +417,7 @@ module.exports = app => {
                         await transaction.update(this.tableName, d);
                     } else {
                         this._completeInsertPosData(tid, d);
-                        transaction.insert(this.tableName, d);
+                        await transaction.insert(this.tableName, d);
                     }
                 }
 

+ 1 - 1
app/service/revise_bills.js

@@ -28,7 +28,7 @@ module.exports = app => {
                 fullPath: 'full_path',
                 keyPre: 'revise_bills_maxLid:',
                 uuid: true,
-            });
+            }, 'revisePos');
             this.tableName = 'revise_bills';
         }
 

+ 3 - 3
app/service/revise_pos.js

@@ -172,8 +172,8 @@ module.exports = app => {
 
                 const transaction = await this.db.beginTransaction();
                 try {
-                    transaction.update(this.tableName, data);
-                    transaction.update(this.ctx.service.reviseBills.tableName, updateBills);
+                    await transaction.update(this.tableName, data);
+                    await transaction.update(this.ctx.service.reviseBills.tableName, updateBills);
                     await transaction.commit();
                     updateBills.ledger_id = bills.ledger_id;
                     return {
@@ -357,7 +357,7 @@ module.exports = app => {
                     if (d.id) {
                         await transaction.update(this.tableName, d);
                     } else {
-                        this._insertPosData(transaction, d, tid, rid);
+                        await this._insertPosData(transaction, d, tid, rid);
                     }
                 }
                 const info = this.ctx.tender.info;