Browse Source

复制整块。公式计算调整

MaiXinRong 4 năm trước cách đây
mục cha
commit
3a33874369
3 tập tin đã thay đổi với 11 bổ sung3 xóa
  1. 3 2
      app/base/base_bills_service.js
  2. 6 0
      app/extend/helper.js
  3. 2 1
      app/service/tender.js

+ 3 - 2
app/base/base_bills_service.js

@@ -17,7 +17,6 @@ const upFields = ['unit_price'];
 const qtyFields = ['sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'quantity', 'deal_qty', 'dgn_qty1', 'dgn_qty2'];
 const tpFields = ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price', 'deal_tp'];
 const measureType = require('../const/tender').measureType;
-const math = require('mathjs');
 const billsUtils = require('../lib/bills_utils');
 
 class BaseBillsSerivce extends TreeService {
@@ -544,7 +543,9 @@ class BaseBillsSerivce extends TreeService {
     _calcExpr(data, field, expr, defaultValue, precision) {
         if (expr) {
             try {
-                data[field] = this.ctx.helper.round(math.eval(expr), precision.value);
+                console.log(expr);
+                data[field] = this.ctx.helper.round(this.ctx.helper.calcExpr(expr), precision.value);
+                console.log(data[field]);
             } catch (err) {
             }
         } else {

+ 6 - 0
app/extend/helper.js

@@ -20,6 +20,7 @@ const SMS = require('../lib/sms');
 const WX = require('../lib/wechat');
 const timesLen = 100;
 const UAParser = require('ua-parser-js');
+const math = require('mathjs');
 
 module.exports = {
     _,
@@ -1280,6 +1281,11 @@ module.exports = {
         return result;
     },
 
+    calcExpr(expr) {
+        const validExpr = expr.replace('=', '').replace('%', '/100');
+        return math.eval(validExpr);
+    },
+
     /**
      * 创建登录日志
      * @return {Boolean} 日志是否创建成功

+ 2 - 1
app/service/tender.js

@@ -332,13 +332,14 @@ module.exports = app => {
                 // 记录删除日志
                 await this.ctx.service.projectLog.addProjectLog(transaction, projectLogConst.type.tender, projectLogConst.status.delete, tenderMsg.name, id);
                 await transaction.commit();
+                this.ctx.query_tender = null;
                 return true;
             } catch (err) {
                 this.ctx.helper.log(err);
                 await transaction.rollback();
+                this.ctx.query_tender = null;
                 return false;
             }
-            this.ctx.query_tender = null;
         }
 
         /**