Exemplo n.º 1
0
 public static function tops_type($limit, $offset, $type)
 {
     $device = IjoyPlusServiceUtils::getDevice();
     $where = '';
     if ($device === false) {
         $key = SearchManager::CACHE_TOPS_LIMIT_OFFSET . '_LIMIT_' . $limit . '_OFFSET_' . $offset . '_TYPE_' . $type;
     } else {
         $where = ' AND (can_search_device like \'%' . $device . '%\' or can_search_device is null or can_search_device =\'\' ) ';
         $key = SearchManager::CACHE_TOPS_LIMIT_OFFSET . '_LIMIT_' . $limit . '_OFFSET_' . $offset . '_DEVICE_' . $device . '_TYPE_' . $type;
     }
     $lists = CacheManager::getValueFromCache($key);
     if ($lists) {
         return $lists;
     }
     $lists = Yii::app()->db->createCommand()->select('t_id as id, t_name as name, t_type as prod_type, 	t_pic as pic_url,t_des as content,t_toptype as toptype')->from('mac_vod_topic ')->where('t_flag=:t_flag and t_type=' . $type . ' and t_id>4 and t_bdtype=1 ' . $where, array(':t_flag' => 1))->order('t_toptype desc ,t_sort desc ,create_date desc')->limit($limit)->offset($offset)->queryAll();
     $temp = array();
     if (isset($lists) && is_array($lists)) {
         foreach ($lists as $list) {
             $items = SearchManager::listItems($list['id'], SearchManager::TOPS_LIST_ITEM_NUM, 0);
             if (isset($items) && is_array($items) && count($items) > 0) {
                 $list['items'] = $items;
                 if (!(isset($list['pic_url']) && is_null($list['pic_url']))) {
                     $list['pic_url'] = $items[0]['prod_pic_url'];
                 }
                 $list['big_pic_url'] = $items[0]['big_prod_pic_url'];
             }
             $itemNum = SearchManager::listItemNums($list['id']);
             if (isset($itemNum) && is_array($itemNum) && count($itemNum) > 0 && array_key_exists('countNum', $itemNum[0])) {
                 $list['num'] = $itemNum[0]['countNum'];
             }
             $temp[] = $list;
         }
         if (count($temp) > 0) {
             $prodExpired = CacheManager::getExpireByCache(CacheManager::CACHE_PARAM_EXPIRED_POPULAR_PROGRAM);
             CacheManager::setValueToCache($key, $temp, $prodExpired);
         }
     }
     return $temp;
 }