stanley-king 3 anni fa
parent
commit
799efc24f9
1 ha cambiato i file con 37 aggiunte e 18 eliminazioni
  1. 37 18
      test/TestRefillUtil.php

+ 37 - 18
test/TestRefillUtil.php

@@ -154,6 +154,17 @@ class TestRefillUtil extends TestCase
             }
         };
 
+        $amount_checker = function ($amount)
+        {
+            $amount = floatval($amount) + 0.0005;
+            $amount = intval($amount);
+            if($amount > 0) {
+                return $amount;
+            } else {
+                return false;
+            }
+        };
+
         $differ = function ($left,$right)
         {
             $result = [];
@@ -182,29 +193,37 @@ class TestRefillUtil extends TestCase
             return $result;
         };
 
-        $filename = BASE_ROOT_PATH . "/data/upload/refill/all.xls";
-        if(!file_exists($filename)) {
-            Log::record("{$filename} not exists.",Log::ERR);
-            return false;
-        }
+        $refill_reader = function ($file) use ($field_reader,$cardno_checker,$amount_checker)
+        {
+            if(!file_exists($file)) {
+                Log::record("{$file} not exists.",Log::ERR);
+                return [];
+            }
 
-        $items = $field_reader($filename);
+            $result = [];
+            $items = $field_reader($file);
+            foreach ($items as $item) {
+                $no = $cardno_checker($item[0]);
+                $amount = $amount_checker($item[1]);
 
-        $left = [];
-        $right = [];
-        foreach ($items as $item) {
-            $noa = $cardno_checker($item[0]);
-            $nob = $cardno_checker($item[2]);
-            if ($noa != false) $left[] = $noa;
-            if ($nob != false) $right[] = $noa;
-        }
-        sort($left);
-        sort($right);
-        $result = $differ($left,$right);
+                if ($no != false && $amount != false) {
+                    $result[] = "{$no}-{$amount}";
+                }
+            }
+
+            return $result;
+        };
+
+        $all  = $refill_reader(BASE_ROOT_PATH . "/data/upload/refill/all.xls");
+        $succ = $refill_reader(BASE_ROOT_PATH . "/data/upload/refill/succ.xls");
+
+        sort($all);
+        sort($succ);
+        $result = $differ($all,$succ);
 
         $csv = fopen(BASE_ROOT_PATH . "/data/upload/refill/diff.csv", 'a+');
         foreach ($result as $item) {
-            $row = [$item,10];
+            $row = explode('-',$item);
             fputcsv($csv,$row);
         }
         fclose($csv);