Browse Source

业务后台:修改公式相互套用替换

chen_yjin 5 months ago
parent
commit
d92172da30
1 changed files with 21 additions and 6 deletions
  1. 21 6
      JLHHJSvr/Helper/MattressHelper.cs

+ 21 - 6
JLHHJSvr/Helper/MattressHelper.cs

@@ -1009,7 +1009,7 @@ namespace JLHHJSvr.Helper
                 AddKeyValue("折扣率", mattress.discount);
             }
 
-            mattress.taxes = CalculateVarFormula("部门含税价").DecimalValue;
+            mattress.dept_cost = CalculateVarFormula("部门含税价").DecimalValue;
             AddKeyValue("部门含税价", mattress.dept_cost);
             #endregion
 
@@ -1397,8 +1397,28 @@ namespace JLHHJSvr.Helper
             if (!formula_replacements.ContainsKey(varname)) return null;
             return Calculate(formula_replacements[varname], varname);
         }
+        private void replaceFormulas(ref string expression)
+        {
+            bool hasReplace = false;
+
+            foreach (var replacement in formula_replacements)
+            {
+                if (expression.IndexOf(replacement.Key) > -1)
+                {
+                    expression = expression.Replace(replacement.Key, "(" + replacement.Value + ")");
+                    hasReplace = true;
+                }
+            }
+            if (hasReplace)
+            {
+                replaceFormulas(ref expression);
+            }
+        }
         private void FormatExpression(ref string expression)
         {
+            // 替换相互嵌套的公式
+            replaceFormulas(ref expression);
+
             expression = ConvertToEnglishSymbols(expression);
 
             // 定义正则表达式模式,匹配包含【】的内容
@@ -1407,11 +1427,6 @@ namespace JLHHJSvr.Helper
             // 创建正则表达式对象
             Regex regex = new Regex(pattern);
 
-            foreach (var replacement in formula_replacements)
-            {
-                expression = expression.Replace(replacement.Key, "(" + replacement.Value +")");
-            }
-
             // 使用正则表达式匹配输入字符串
             MatchCollection matches = regex.Matches(expression);