소스 검색

合同支付,bqwc基数计算相关

MaiXinRong 5 년 전
부모
커밋
a3ef92ff95
1개의 변경된 파일26개의 추가작업 그리고 1개의 파일을 삭제
  1. 26 1
      app/lib/pay_calc.js

+ 26 - 1
app/lib/pay_calc.js

@@ -39,6 +39,30 @@ class PayCalculate {
         }
     }
 
+    calculateTpExpr(pay, first, addRela) {
+        let formula = pay.expr;
+        for (const b of this.bases) {
+            if ((b.code === 'bqwc') && (first && pay.sprice)) {
+                formula = formula.replace(b.reg, this.ctx.helper.sub(addRela.gather_tp, pay.sprice));
+            } else {
+                formula = formula.replace(b.reg, b.value);
+            }
+        }
+        const percent = formula.match(this.percentReg);
+        if (percent) {
+            for (const p of percent) {
+                const v = math.eval(p.replace('%', '/100'));
+                formula = formula.replace(p, v);
+            }
+        }
+        try {
+            const value = math.eval(formula);
+            return value;
+        } catch(err) {
+            return 0;
+        }
+    }
+
     calculateExpr(expr) {
         let formula = expr;
         for (const b of this.bases) {
@@ -135,8 +159,9 @@ class PayCalculate {
         for (const p of pays) {
             if (p.ptype === payType.normal || p.ptype === payType.wc) {
                 if (p.expr && p.expr !== '') {
-                    const value = this.ctx.helper.round(this.calculateExpr(p.expr), this.decimal);
                     if (!p.pause && (!p.sprice || addRela.gather_tp > p.sprice)) {
+                        const first = !(p.pre_tp && !this.ctx.helper.checkZero(p.pre_tp));
+                        const value = this.ctx.helper.round(this.calculateTpExpr(p, first, addRela), this.decimal);
                         if (p.rprice) {
                             if (this.checkDeadline(p)) {
                                 p.tp = this.ctx.helper.sub(p.rprice, p.pre_total_price);