rabin 2 years ago
parent
commit
a869bf15df
1 changed files with 28 additions and 25 deletions
  1. 28 25
      app/card/src/Api.php

+ 28 - 25
app/card/src/Api.php

@@ -34,19 +34,21 @@ class Api extends Core
     public function getCard()
     {
         $where['type'] = 1;
-        $this->data['card'] = Dever::db('card/type')->getAll($where);
+        $this->data['card'] = array();
+        $card = Dever::db('card/type')->getAll($where);
 
-        if ($this->data['card']) {
-            foreach ($this->data['card'] as $k => $v) {
+        if ($card) {
+            foreach ($card] as $k => $v) {
                 $w['type_id'] = $v['id'];
                 $w['status'] = 1;
                 $w['create_type'] = 1;
                 $w['buy'] = 1;
                 $list = Dever::db('card/info')->select($w);
                 if (!$list) {
-                    unset($this->data['card'][$k]);
+                    unset($card[$k]);
                 } else {
-                    $this->data['card'][$k]['value'] = $list;
+                    $card[$k]['value'] = $list;
+                    $this->data['card'][] = $card[$k];
                 }
             }
         }
@@ -225,8 +227,8 @@ class Api extends Core
         $config = Dever::db('main/sell_config')->find();
         $this->data['card_pic'] = $config['card'];
         $this->data['card_name'] = $config['card_name'];
-
-        $this->data['card'] = Dever::db('card/code')->getPageData(array('dh_uid' => $this->uid));
+        $this->data['card'] = array();
+        $card = Dever::db('card/code')->getPageData(array('dh_uid' => $this->uid));
 
         $city = Dever::input('city');
         if ($city) {
@@ -236,12 +238,12 @@ class Api extends Core
             }
         }
         $time = time();
-        if ($this->data['card']) {
-            foreach ($this->data['card'] as $k => $v) {
-                $v['info'] = $this->data['card'][$k]['info'] = Dever::db('card/info')->find($v['card_id']);
+        if ($card) {
+            foreach ($card as $k => $v) {
+                $v['info'] = $card[$k]['info'] = Dever::db('card/info')->find($v['card_id']);
 
                 if (!$v['info']) {
-                    unset($this->data['card'][$k]);
+                    unset($card[$k]);
                     continue;
                 }
 
@@ -251,7 +253,7 @@ class Api extends Core
 
                 if (isset($v['eddate']) && $v['eddate'] && $v['eddate'] > 0) {
                     if ($v['eddate'] <= $time) {
-                        unset($this->data['card'][$k]);
+                        unset($card[$k]);
                         continue;
                     }
                 }
@@ -262,11 +264,11 @@ class Api extends Core
                 if (!$v['use_cash']) {
                     $v['use_cash'] = 0;
                 }
-                $this->data['card'][$k]['cash'] = $v['total_cash'] - $v['use_cash'];
+                $card[$k]['cash'] = $v['total_cash'] - $v['use_cash'];
                 
-                $info = $this->data['card'][$k]['type'] = Dever::db('card/type')->find($this->data['card'][$k]['info']['type_id']);
+                $info = $card[$k]['type'] = Dever::db('card/type')->find($card[$k]['info']['type_id']);
 
-                $this->data['card'][$k]['minfo'] = '';
+                $card[$k]['minfo'] = '';
 
                 if ($info['city_type'] == 2) {
                     $city = $v['city'];
@@ -280,45 +282,46 @@ class Api extends Core
                     if ($city) {
                         $city = Dever::db('area/city')->find($city);
                         if ($city) {
-                            $this->data['card'][$k]['minfo'] = '仅限' . $city['name'] . '可用';
+                            $card[$k]['minfo'] = '仅限' . $city['name'] . '可用';
                         }
                     }
                 } elseif ($info['type'] == 2 && $v['shop_id']) {
                     $shop = Dever::db('shop/info')->find($v['shop_id']);
                     if ($shop) {
-                        $this->data['card'][$k]['minfo'] = '限' . $shop['name'] . '可用';
+                        $card[$k]['minfo'] = '限' . $shop['name'] . '可用';
                     }
                 } else {
                     $config_type = Dever::db('shop/info')->config['config_type'];
 
                     /*
                     $info['shop_type'] = explode(',', $info['shop_type']);
-                    $this->data['card'][$k]['minfo'] = array();
+                    $card[$k]['minfo'] = array();
                     foreach ($info['shop_type'] as $tv) {
                         if (isset($config_type[$tv])) {
-                            $this->data['card'][$k]['minfo'][] = $config_type[$tv];
+                            $card[$k]['minfo'][] = $config_type[$tv];
                         }
                     }
-                    $this->data['card'][$k]['minfo'] = implode('、', $this->data['card'][$k]['minfo']) . '可用';
+                    $card[$k]['minfo'] = implode('、', $card[$k]['minfo']) . '可用';
                     */
 
                     
                     if ($info['shop_type'] && strstr($info['shop_type'], ',')) {
-                        $this->data['card'][$k]['minfo'] = '多店铺可用';
+                        $card[$k]['minfo'] = '多店铺可用';
                     } elseif ($info['shop_type'] && isset($config_type[$info['shop_type']])) {
-                        $this->data['card'][$k]['minfo'] = $config_type[$info['shop_type']] . '可用';
+                        $card[$k]['minfo'] = $config_type[$info['shop_type']] . '可用';
                     }
                 }
 
-                $this->data['card'][$k]['cinfo'] = '';
+                $card[$k]['cinfo'] = '';
                 if ($v['info']['category']) {
-                    $this->data['card'][$k]['cinfo'] = '限部分要求商品可用';
+                    $card[$k]['cinfo'] = '限部分要求商品可用';
                 } else {
                     $goods = Dever::db('card/info_goods')->find(array('card_id' => $v['info']['id']));
                     if ($goods) {
-                        $this->data['card'][$k]['cinfo'] = '限部分要求商品可用';
+                        $card[$k]['cinfo'] = '限部分要求商品可用';
                     }
                 }
+                $this->data['card'][] = $card[$k];
             }
         }