stanley-king 4 éve
szülő
commit
90a1229d04
1 módosított fájl, 65 hozzáadás és 63 törlés
  1. 65 63
      admin/control/merchant.php

+ 65 - 63
admin/control/merchant.php

@@ -167,77 +167,79 @@ class merchantControl extends SystemControl
             $this->cache_storge_limit($result);
             showMessage('编辑成功', 'index.php?act=merchant&op=merchant');
         }
-        $order_limit = rcache('storge_limit' , 'merchant-');
-
-        if(empty($order_limit)){
-            $order_limit = [];
-        }else{
-            $order_limit = unserialize($order_limit['data']);
-        }
-
-        $initialiser = function ($merchant) {
-            $amount = [
-                '100' => -1,
-                '200' => -1,
-                '500' => -1,
-                '1000' => -1
-            ];
-            $data['mchid'] = $merchant['mchid'];
-            $data['petrochina'] = $data['sinopec'] = $amount;
-            $data['time'] = time();
-            return $data;
-        };
-
-        $reader = function ($mchid,$time)
+        else
         {
-            $cond['mchid'] = $mchid;
-            $cond['inner_status'] = 0;
-            $cond['order_state'] = ORDER_STATE_SUCCESS;
-            $cond['refill_order.order_time'] = ['egt', $time];
-
-            $items = Model('')->table('refill_order,vr_order')->join('inner')
-                ->on('refill_order.order_id=vr_order.order_id')
-                ->field('refill_order.mchid,refill_order.card_type,refill_order.refill_amount,count(*) as num')
-                ->group('refill_order.card_type,refill_order.refill_amount')
-                ->where($cond)->select();
-
-            return $items;
-        };
+            $order_limit = rcache('storge_limit' , 'merchant-');
 
-        $type_map = [1 => 'petrochina' , 2 => 'sinopec'];
-        $new_cache = [];
-        $model_merchant = model('merchant');
-        $merchant_list = $model_merchant->getMerchantList([], 1000, 'mchid asc' , 'mchid,company_name');
-        foreach ($merchant_list as $merchant)
-        {
-            $mchid = intval($merchant['mchid']);
-
-            if(array_key_exists($mchid , $order_limit)) {
-                $result[$mchid] = $order_limit[$mchid];
+            if(empty($order_limit)){
+                $order_limit = [];
             }else{
-                $result[$mchid] = $initialiser($merchant);
+                $order_limit = unserialize($order_limit['data']);
             }
-            $start = $result[$mchid]['time'];
-            $items = $reader($mchid,$start);
-            $new_cache[$mchid] = $result[$mchid];
-            foreach ($items as $item) {
-                $refill_amount = intval($item['refill_amount'] + 0.005);
-                $card_type = $type_map[$item['card_type']];
-                $cache_num = $result[$mchid][$card_type][$refill_amount];
-                if ($cache_num == -1) {
-                    $new_num = -1;
+
+            $initialiser = function ($merchant) {
+                $amount = [
+                    '100' => -1,
+                    '200' => -1,
+                    '500' => -1,
+                    '1000' => -1
+                ];
+                $data['mchid'] = $merchant['mchid'];
+                $data['petrochina'] = $data['sinopec'] = $amount;
+                $data['time'] = time();
+                return $data;
+            };
+
+            $reader = function ($mchid,$time)
+            {
+                $cond['mchid'] = $mchid;
+                $cond['inner_status'] = 0;
+                $cond['order_state'] = ORDER_STATE_SUCCESS;
+                $cond['refill_order.order_time'] = ['egt', $time];
+
+                $items = Model('')->table('refill_order,vr_order')->join('inner')
+                    ->on('refill_order.order_id=vr_order.order_id')
+                    ->field('refill_order.mchid,refill_order.card_type,refill_order.refill_amount,count(*) as num')
+                    ->group('refill_order.card_type,refill_order.refill_amount')
+                    ->where($cond)->select();
+
+                return $items;
+            };
+
+            $type_map = [1 => 'petrochina' , 2 => 'sinopec'];
+
+            $cur_limits = [];
+            $model_merchant = model('merchant');
+            $merchant_list = $model_merchant->getMerchantList([], 1000, 'mchid asc' , 'mchid,company_name');
+            foreach ($merchant_list as $merchant)
+            {
+                $mchid = intval($merchant['mchid']);
+
+                if(array_key_exists($mchid , $order_limit)) {
+                    $result[$mchid] = $order_limit[$mchid];
                 }else{
-                    $new_num = ($cache_num - $item['num']) >= 0 ? $cache_num - $item['num'] : 0;
+                    $result[$mchid] = $initialiser($merchant);
+                }
+                $start = $result[$mchid]['time'];
+                $items = $reader($mchid,$start);
+                $cur_limits[$mchid] = $result[$mchid];
+                foreach ($items as $item) {
+                    $refill_amount = intval($item['refill_amount'] + 0.005);
+                    $card_type = $type_map[$item['card_type']];
+                    $cache_num = $result[$mchid][$card_type][$refill_amount];
+                    if ($cache_num == -1) {
+                        $new_num = -1;
+                    }else{
+                        $new_num = ($cache_num - $item['num']) >= 0 ? $cache_num - $item['num'] : 0;
+                    }
+                    $cur_limits[$mchid][$card_type][$refill_amount] = $new_num;
                 }
-                $new_cache[$mchid][$card_type][$refill_amount] = $new_num;
-                $new_cache[$mchid]['time'] = time();
+                $cur_limits[$mchid]['company_name'] = $merchant['company_name'];
             }
-            $new_cache[$mchid]['company_name'] = $merchant['company_name'];
-        }
-        $this->cache_storge_limit($new_cache);
 
-        Tpl::output('data', $new_cache);
-        Tpl::showpage('merchant.orderlimit');
+            Tpl::output('data', $cur_limits);
+            Tpl::showpage('merchant.orderlimit');
+        }
     }
 
     private function cache_storge_limit($data)