rabin 1 tydzień temu
rodzic
commit
cb83c6853c
3 zmienionych plików z 11 dodań i 11 usunięć
  1. 8 0
      src/Dever/Helper/Math.php
  2. 0 9
      src/Dever/Helper/Str.php
  3. 3 2
      src/Dever/Model.php

+ 8 - 0
src/Dever/Helper/Math.php

@@ -3,6 +3,14 @@ use Dever;
 class Math
 {
     private static $bc = null;
+    public static function value($cash, $value)
+    {
+        if (strstr($value, '%')) {
+            $value = str_replace('%', '', $value);
+            $value = self::divMul($value, 100, $cash);
+        }
+        return self::format($value, 2);
+    }
     public static function check(): bool
     {
         if (self::$bc === null) {

+ 0 - 9
src/Dever/Helper/Str.php

@@ -13,15 +13,6 @@ class Str
     {
         return substr_replace($string, $hide, $start, $len);
     }
-    public static function per($cash, $value)
-    {
-        if (strstr($value, '%')) {
-            $value = str_replace('%', '', $value);
-            $value = round($value/100, 2);
-            $value = $value * $cash;
-        }
-        return round($value, 2);
-    }
     public static function salt($len)
     {
         return bin2hex(random_bytes($len));

+ 3 - 2
src/Dever/Model.php

@@ -369,15 +369,16 @@ class Model
         }
         return false;
     }
-    public function tree($where, $config, $func = false, $set = [])
+    public function tree($where, $config, $func = false, $set = [], $index = 0)
     {
         $where[$config[0]] = $config[1];
         $data = $this->select($where, $set);
         if ($data) {
             foreach ($data as $k => &$v) {
                 if ($func) $v = call_user_func($func, $k, $v);
+                //if ($index > 0) $v['name'] = ' -- ' . $v['name'];
                 $config[1] = $v[$config[2]];
-                $child = $this->tree($where, $config, $func, $set);
+                $child = $this->tree($where, $config, $func, $set, 1);
                 if ($child) {
                     $v['children'] = $child;
                 }