| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 | 
							- <?php
 
- namespace Ad\Lib;
 
- use Dever;
 
- class Data
 
- {
 
-     public function get($key, $data = array(), $cache = true)
 
-     {
 
-         $cache = 'ad_' . md5($key);
 
-         $data = $cache ? Dever::cache($cache) : $cache;
 
-         if ($data) {
 
-             return $this->getData($data);
 
-         } elseif (!$data) {
 
-             $page = Dever::db('ad/page')->one(array('key' => $key));
 
-             if ($page) {
 
-                 $info = Dever::db('ad/info')->getAll(array('page_id' => $page['id']));
 
-                 if ($info) {
 
-                     foreach ($info as $k => $v) {
 
-                         $where['info_id'] = $v['id'];
 
-                         if ($v['order_type'] == 2) {
 
-                             $where['order'] = array('id' => 'asc');
 
-                         }
 
-                         $info[$k]['data'] = Dever::db('ad/data')->getAll($where);
 
-                         if ($info[$k]['data'] && $v['order_type'] == 3) {
 
-                             $order = array(array_rand($info[$k]['data'], 1));
 
-                             $temp = $info[$k]['data'];
 
-                             unset($info[$k]['data']);
 
-                             foreach ($order as $k1 => $v1) {
 
-                                 $info[$k]['data'][$k1] = $temp[$v1];
 
-                             }
 
-                         }
 
-                     }
 
-                     Dever::cache($cache, $info);
 
-                     return $this->getData($info);
 
-                 }
 
-             }
 
-         }
 
-         return false;
 
-     }
 
-     private function getData($data)
 
-     {
 
-         if ($data) {
 
-             $time = time();
 
-             $source_type = $this->config(Dever::input('source_type', 'h5'));
 
-             foreach ($data as $k => $v) {
 
-                 $child = $v['data'];
 
-                 $data[$k]['data'] = array();
 
-                 $i = 0;
 
-                 foreach ($child as $k1 => $v1) {
 
-                     if ($v1['type'] == 2 && ($time < $v1['sdate'] || $time > $v1['edate'])) {
 
-                         //unset($data[$k]['data'][$k1]);
 
-                     } elseif ($v1['system'] > 0 && $source_type != $v1['system']) {
 
-                         //unset($data[$k]['data'][$k1]);
 
-                     } else {
 
-                         $data[$k]['data'][$i] = $v1;
 
-                         $i++;
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         return $data;
 
-     }
 
-     private function config($type)
 
-     {
 
-         if ($type == 'ios') {
 
-             return 3;
 
-         }
 
-         if ($type == 'android') {
 
-             return 2;
 
-         }
 
-         if ($type == 'applet') {
 
-             return 4;
 
-         }
 
-         if ($type == 'h5') {
 
-             return 1;
 
-         }
 
-         return -1;
 
-     }
 
- }
 
 
  |