Authored by whb

修改手机视频相关

@@ -121,12 +121,10 @@ class Controller_News extends Controller_Abstract @@ -121,12 +121,10 @@ class Controller_News extends Controller_Abstract
121 } 121 }
122 if($this->_platform == 'android' || $this->_platform == 'iphone') 122 if($this->_platform == 'android' || $this->_platform == 'iphone')
123 { 123 {
124 - $sameID = Facade_Brand::getSameNewsByNewsID($id);  
125 - if(!empty($sameID))  
126 - {  
127 - $news[] = Facade_News::getOneById($sameID);  
128 - }  
129 - $news = array_slice(array_merge($news, Facade_News::getList(array(), 0, 3, array('视频'))), 0, 3); 124 + $exceptTags = array('视频');
  125 + $news[] = Facade_News::getSameNewsById($id, $exceptTags);
  126 + $news = array_merge($news, Facade_News::getList(array(), 0, 3, $exceptTags));
  127 + $news = array_slice(array_filter($news), 0, 3);
130 } 128 }
131 $info['title'] = strip_tags($info['title']); 129 $info['title'] = strip_tags($info['title']);
132 $info['pics'] = array_filter(explode('|', $info['pics'])); 130 $info['pics'] = array_filter(explode('|', $info['pics']));
@@ -147,15 +145,12 @@ class Controller_News extends Controller_Abstract @@ -147,15 +145,12 @@ class Controller_News extends Controller_Abstract
147 { 145 {
148 $id = intval($this->_request->id); 146 $id = intval($this->_request->id);
149 $list = array('recom'=> array(), 'hotVideo'=> array(), 'lastVideo' => array()); 147 $list = array('recom'=> array(), 'hotVideo'=> array(), 'lastVideo' => array());
150 - $sameID = Facade_Brand::getSameNewsByNewsID($id);  
151 $tag = '视频'; 148 $tag = '视频';
152 $exceptTags = array('手机视频'); 149 $exceptTags = array('手机视频');
153 $recom = array(); 150 $recom = array();
154 - if(!empty($sameID))  
155 - {  
156 - $recom[] = Facade_News::getOneById($sameID);  
157 - }  
158 - $recom = array_slice(array_merge($recom, Facade_News::getList(array(), 0, 3, $exceptTags)), 0, 3); 151 + $recom[] = Facade_News::getSameNewsById($id, $exceptTags);
  152 + $recom = array_merge($recom, Facade_News::getList(array(), 0, 3, $exceptTags));
  153 + $recom = array_slice(array_filter($recom), 0, 3);
159 $hotVideo = array_values(Facade_News::getListByHits($tag, 0, 5, $exceptTags)); 154 $hotVideo = array_values(Facade_News::getListByHits($tag, 0, 5, $exceptTags));
160 $lastVideo = array_values(Facade_News::getList($tag, 0, 5, $exceptTags)); 155 $lastVideo = array_values(Facade_News::getList($tag, 0, 5, $exceptTags));
161 $list['recom'] = $recom; 156 $list['recom'] = $recom;
@@ -334,14 +334,4 @@ class Facade_Brand @@ -334,14 +334,4 @@ class Facade_Brand
334 return self::service()->getBrandByName($name, $state); 334 return self::service()->getBrandByName($name, $state);
335 } 335 }
336 336
337 - /**  
338 - * 根据news_id获取相同的新闻  
339 - *  
340 - * @param int $news_id  
341 - * @return int  
342 - */  
343 - public static function getSameNewsByNewsID($news_id)  
344 - {  
345 - return self::service()->getSameNewsByNewsID($news_id);  
346 - }  
347 } 337 }
@@ -245,4 +245,16 @@ class Facade_News @@ -245,4 +245,16 @@ class Facade_News
245 { 245 {
246 return self::service()->getListByHits($tag, $offset, $limit, $exceptTags); 246 return self::service()->getListByHits($tag, $offset, $limit, $exceptTags);
247 } 247 }
  248 +
  249 + /**
  250 + * 根据id获取相同的新闻
  251 + *
  252 + * @param int $id
  253 + * @param array $exceptTags
  254 + * @return int
  255 + */
  256 + public static function getSameNewsById($id, $exceptTags = array())
  257 + {
  258 + return self::service()->getSameNewsById($id, $exceptTags);
  259 + }
248 } 260 }
@@ -294,16 +294,5 @@ class Service_Brand extends Lib_Service @@ -294,16 +294,5 @@ class Service_Brand extends Lib_Service
294 $name = '%'.addslashes($name).'%'; 294 $name = '%'.addslashes($name).'%';
295 return self::service(self::ROUTER)->tag(self::$_tag)->fetchAssoc('getBrandByName', 295 return self::service(self::ROUTER)->tag(self::$_tag)->fetchAssoc('getBrandByName',
296 array('state'=> $state,'name'=> $name)); 296 array('state'=> $state,'name'=> $name));
297 - }  
298 -  
299 - /**  
300 - * 根据news_id获取相同的新闻  
301 - *  
302 - * @param int $news_id  
303 - * @return int  
304 - */  
305 - public function getSameNewsByNewsID($news_id)  
306 - {  
307 - return self::service(self::ROUTER)->tag(self::$_tag)->fetchOne('getSameNewsByNewsID', array('news_id' => $news_id));  
308 - } 297 + }
309 } 298 }
@@ -248,5 +248,24 @@ class Service_News extends Lib_Service @@ -248,5 +248,24 @@ class Service_News extends Lib_Service
248 return self::service(self::ROUTER)->tag(self::$_tag)->fetchAssoc('getListByHits',array('tag'=> $tag, 248 return self::service(self::ROUTER)->tag(self::$_tag)->fetchAssoc('getListByHits',array('tag'=> $tag,
249 'offset'=> intval($offset), 'limit'=> intval($limit)), array('where'=> $exceptWhere)); 249 'offset'=> intval($offset), 'limit'=> intval($limit)), array('where'=> $exceptWhere));
250 } 250 }
  251 +
  252 + /**
  253 + * 根据news_id获取相同的新闻
  254 + *
  255 + * @param int $news_id
  256 + * @param array $exceptTags
  257 + * @return int
  258 + */
  259 + public function getSameNewsById($news_id, $exceptTags)
  260 + {
  261 + $exceptWhere = "1";
  262 + if(is_array($exceptTags) && !empty($exceptTags))
  263 + {
  264 + $exceptTags = implode("','", $exceptTags);
  265 + $exceptWhere = " `tag` NOT IN ('$exceptTags') ";
  266 + }
  267 + return self::service(self::ROUTER)->tag(self::$_tag)->fetchRow('getSameNewsById', array('news_id' => $news_id), array('where'=> $exceptWhere));
  268 + }
  269 +
251 } 270 }
252 271
@@ -30,7 +30,6 @@ @@ -30,7 +30,6 @@
30 <insert id="createTag"> 30 <insert id="createTag">
31 INSERT INTO `tbl_tag` VALUES (:tag, :num, 0) 31 INSERT INTO `tbl_tag` VALUES (:tag, :num, 0)
32 </insert> 32 </insert>
33 -  
34 <select id="getTags"> 33 <select id="getTags">
35 SELECT * FROM `tbl_tag` ORDER BY `sort` DESC 34 SELECT * FROM `tbl_tag` ORDER BY `sort` DESC
36 </select> 35 </select>
@@ -46,4 +45,8 @@ @@ -46,4 +45,8 @@
46 <select id="getListByHits"> 45 <select id="getListByHits">
47 SELECT * FROM tbl_news WHERE `tag` = :tag AND #where# ORDER BY hits DESC LIMIT :offset, :limit 46 SELECT * FROM tbl_news WHERE `tag` = :tag AND #where# ORDER BY hits DESC LIMIT :offset, :limit
48 </select> 47 </select>
  48 + <select id="getSameNewsById">
  49 + SELECT * FROM tbl_news WHERE id &lt;&gt; :news_id AND #where# AND id IN (
  50 + SELECT news_id FROM tbl_news_brand_rela WHERE brand_id IN (SELECT brand_id FROM tbl_news_brand_rela WHERE news_id = :news_id) )
  51 + </select>
49 </sqlMap> 52 </sqlMap>