xiaoyu před 3 roky
rodič
revize
9dcefdd3cb
3 změnil soubory, kde provedl 37 přidání a 45 odebrání
  1. 3 13
      admin/control/card_key.php
  2. 18 32
      admin/control/orderstats.php
  3. 16 0
      helper/refill/rquery.php

+ 3 - 13
admin/control/card_key.php

@@ -10,22 +10,12 @@ class card_keyControl extends SystemControl
 
     public function statsOp()
     {
-        $condition = ['card_id' => ['gt', 0]];
-        $start_unixtime = intval(strtotime($_GET['query_start_time']));
-        $end_unixtime   = intval(strtotime($_GET['query_end_time']));
-
-        if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
-            $condition['assigned_time'] = [ ['egt', $start_unixtime] , ['lt', $end_unixtime] , 'and'];
-        }
-        elseif ($start_unixtime > 0) {
-            $condition['assigned_time'] = ['egt', $start_unixtime];
-        }
-        elseif ($end_unixtime > 0) {
-            $condition['assigned_time'] = ['lt', $end_unixtime];
-        }
+        $condition['card_id'] = ['gt', 0];
         if(!empty($_GET['store_id'])) {
             $condition['store_id'] = $_GET['store_id'];
         }
+        $time_cond = \refill\rquery::custom_time_cond($_GET, 'assigned_time');
+        $condition = array_merge($condition, $time_cond);
         $items = Model('')->table('card_key')
             ->field('card_type, amount, card_state, count(*) as card_count, sum(amount) as card_amounts')
             ->where($condition)

+ 18 - 32
admin/control/orderstats.php

@@ -13,23 +13,10 @@ class orderstatsControl extends SystemControl
         $type = $_GET['type'] ?? 'system';
         $page = "{$type}.order.stats";
         $model_refill_order = Model('refill_order');
+        $condition = $this->orderstats_cond($_GET);
         $condition['type'] = $type;
-        if (!empty($_GET['cid'])) {
-            $condition['cid'] = ['in', $_GET['cid']];
-        }
-        if (!empty($_GET['order_time_type'])) {
-            $condition['order_time_type'] = $_GET['order_time_type'];
-        }
-        $start_unixtime = intval(strtotime($_GET['query_start_time']));
-        $end_unixtime = intval(strtotime($_GET['query_end_time']));
-        if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
-            $condition['time_stamp'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
-        } elseif ($start_unixtime > 0) {
-            $condition['time_stamp'] = ['egt', $start_unixtime];
-        } elseif ($end_unixtime > 0) {
-            $condition['time_stamp'] = ['lt', $end_unixtime];
-        }
-
+        $time_cond = \refill\rquery::custom_time_cond($_GET, 'time_stamp');
+        $condition = array_merge($condition, $time_cond);
         $stats_list = $model_refill_order->getOrderStatsList($condition, 50, '*', 'time_stamp desc, cname asc');
         if($type == 'merchant') {
             foreach ($stats_list as $key => $stats) {
@@ -53,23 +40,10 @@ class orderstatsControl extends SystemControl
     public function ExportDataOp()
     {
         $type = $_GET['type'] ?? 'system';
-        $model_refill_order = Model('refill_order');
+        $condition = $this->orderstats_cond($_GET);
         $condition['type'] = $type;
-        if (!empty($_GET['cid'])) {
-            $condition['cid'] = ['in', $_GET['cid']];
-        }
-        if (!empty($_GET['order_time_type'])) {
-            $condition['order_time_type'] = $_GET['order_time_type'];
-        }
-        $start_unixtime = intval($_GET['query_start_time']);
-        $end_unixtime = intval($_GET['query_end_time']);
-        if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
-            $condition['time_stamp'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
-        } elseif ($start_unixtime > 0) {
-            $condition['time_stamp'] = ['egt', $start_unixtime];
-        } elseif ($end_unixtime > 0) {
-            $condition['time_stamp'] = ['lt', $end_unixtime];
-        }
+        $time_cond = \refill\rquery::custom_time_cond($_GET, 'time_stamp');
+        $condition = array_merge($condition, $time_cond);
         $stats_list = $this->all_orderstats_data($condition);
 
         $total_stats = $this->stats($condition);
@@ -120,4 +94,16 @@ class orderstatsControl extends SystemControl
         }
         return $result;
     }
+
+    private function orderstats_cond($input): array
+    {
+        $cond = [];
+        if (!empty($input['cid'])) {
+            $cond['cid'] = ['in', $input['cid']];
+        }
+        if (!empty($input['order_time_type'])) {
+            $cond['order_time_type'] = $input['order_time_type'];
+        }
+        return $cond;
+    }
 }

+ 16 - 0
helper/refill/rquery.php

@@ -128,4 +128,20 @@ class rquery
     {
         return $this->time_cond;
     }
+
+    public static function custom_time_cond($input,$field): array
+    {
+        $start = intval(strtotime($input['query_start_time']));
+        $end   = intval(strtotime($input['query_end_time']));
+
+        $cond = [];
+        if ($start > 0 && $end > $start) {
+            $cond[$field] = [['egt', $start], ['lt', $end], 'and'];
+        } elseif ($start > 0) {
+            $cond[$field] = ['egt', $start];
+        } elseif ($end > 0) {
+            $cond[$field] = ['lt', $end];
+        }
+        return $cond;
+    }
 }