xiaoyu 3 jaren geleden
bovenliggende
commit
2e16850563
2 gewijzigde bestanden met toevoegingen van 20 en 21 verwijderingen
  1. 17 17
      helper/task/handler.php
  2. 3 4
      test/TestTask.php

+ 17 - 17
helper/task/handler.php

@@ -103,28 +103,27 @@ class handler
             foreach ($items as $item)
             {
                 $order_state = $item['order_state'];
-                if(!array_key_exists($order_state,$result)) {
-                    $val = [];
-                    $val['order_count'] = $item['order_count'];
-                    $val['refill_amounts'] = ncPriceFormat($item['refill_amounts']);
-                    $val['channel_amounts'] = ncPriceFormat($item['channel_amounts']);
-                    $val['mch_amounts'] = ncPriceFormat($item['mch_amounts']);
-
-                    $result[$order_state] = $val;
-                }
-                else {
-                    $result[$order_state]['order_count'] += $item['order_count'];
-                    $result[$order_state]['refill_amounts'] += ncPriceFormat($item['refill_amounts']);
-                    $result[$order_state]['channel_amounts'] += ncPriceFormat($item['channel_amounts']);
-                    $result[$order_state]['mch_amounts'] += ncPriceFormat($item['mch_amounts']);
-                }
+
+                $result[$order_state]['order_count'] += $item['order_count'];
+                $result[$order_state]['refill_amounts'] += ncPriceFormat($item['refill_amounts']);
+                $result[$order_state]['channel_amounts'] += ncPriceFormat($item['channel_amounts']);
+                $result[$order_state]['mch_amounts'] += ncPriceFormat($item['mch_amounts']);
+            }
+        };
+
+        $initor = function (&$records)
+        {
+            $order_states = [ORDER_STATE_CANCEL, ORDER_STATE_SEND, ORDER_STATE_SUCCESS];
+            foreach ($order_states as $state) {
+                $val = ['order_count' => 0, 'refill_amounts' => 0, 'channel_amounts' => 0, 'mch_amounts' => 0];
+                $records[$state] = $val;
             }
         };
 
         $all_summer = function ($records)
         {
             $result = ['order_count' => 0, 'refill_amounts' => 0, 'channel_amounts' => 0, 'mch_amounts' => 0];
-            foreach ($records as $order_state => $item) {
+            foreach ($records as $item) {
                 $result['order_count'] += $item['order_count'];
                 $result['refill_amounts'] += ncPriceFormat($item['refill_amounts']);
                 $result['channel_amounts'] += ncPriceFormat($item['channel_amounts']);
@@ -138,6 +137,7 @@ class handler
         try
         {
             $records = [];
+            $initor($records);
             $stats = $order_reader($normal_cond, $time_scope);
             foreach ($stats as $items) {
                 $summer($items,$records);
@@ -158,7 +158,7 @@ class handler
 
     public function refill_order_stat_ex_title($condition)
     {
-        return md5("refill_order_stat-".serialize($condition));
+        return md5("refill_order_stat_ex-".serialize($condition));
     }
 
     public function refill_order_export($cond)

+ 3 - 4
test/TestTask.php

@@ -72,19 +72,18 @@ class TestTask extends TestCase
         Log::record($ret,Log::DEBUG);
     }
 
-    public function testOrderStats()
+    public function testOrderStatsEx()
     {
         $normal = [
             'inner_status' => 0,
-            'refill_order.mchid' => 1093,
-            'vr_order.order_state' => 40
+            'refill_order.mchid' => 1093
         ];
         $scope = [
             'order_time' => [1617206400, 1617724800],
             'add_time' => [1617206400, 1618156800]
         ];
         $handler = new handler();
-        [$succ,$result] = $handler->refill_order_stat(['normal' => $normal, 'time_scope' => $scope]);
+        [$succ,$result] = $handler->refill_order_stat_ex(['normal' => $normal, 'time_scope' => $scope]);
     }
 
     public function testArrayMerge()