Brand.class.php
4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
* 默认控制器
*/
class Controller_Brand extends Controller_Abstract
{
public function indexAction()
{
$limit = 1000 ;
$total = Facade_Brand::getBrandTotal(1);
$pagination = new Lib_Helper_Pagination($total, $limit);
$list = Facade_Brand::getBrandByState( $pagination->getOffset(), $limit,1);
foreach ($list as $k => $v)
{
if ($v['logo'])
{
$thumb = $v['logo'];
}
else
{
$thumb = SITE_IMG.'/pic01.png';
}
$list[$k]['logo'] = $thumb ;
}
$this->_view['list'] = $list ;
$this->_view['pagination'] = $pagination->getPagination() ;
/***设置网站的SEO信息***/
$seo = C('APP.Seo');
$this->setTitle($seo['channel_brand_title']);
$this->setKeywords($seo['channel_brand_keywords']);
$this->setDescription($seo['channel_brand_description']);
$seo = null; unset($seo);
}
/**
* 详情页
*/
public function detailAction()
{
$id = intval($this->_request->id);
if (empty($id))
{
return $this->_redirect('brand/index');
}
$total = 0;
$page = new Lib_Helper_Pagination($total, 100);
list($offset, $limit) = $page->getLimit();
$info = Facade_Brand::getBrandbyID($id);
$news = array();
$goodsList = $this->getGoods($id, intval($offset), intval($limit), $total);
$page->setRecordCount($total)->setParames(array('id'=> $id))->setModel('ajax','#goods_list');
$this->_view['goods'] = $goodsList;
$this->_view['isAjax'] = $this->_request->isAjax();
if(!$this->_request->isAjax())
{
if(isset($info['news_ids']) && $info['news_ids'])
{
$ids = explode(',', $info['news_ids']);
foreach ($ids as $id)
{
$new = Facade_News::getOneById($id);
if($new)
{
$news[] = $new;
}
}
$news = $this->procNews($news);
}
$this->_view['news'] = $news;
if (!$info)
{
return $this->_redirect('brand/index');
}
$this->_view['info'] = $info ;
/***设置网站的SEO信息***/
$seo = C('APP.Seo');
$this->setTitle($info['name']."|YO'HOOD 品牌 | YO'HOOD, 2013非常潮流盛事");
$this->setKeywords($seo['channel_brand_keywords']);
$this->setDescription($seo['channel_brand_description']);
$seo = null; unset($seo);
}
$this->_view['pagination'] = $page->getPagination();
}
/**
* 处理新闻
*/
private function procNews($list, $num1 = 90, $num2 = 100)
{
foreach ($list as $k => $v)
{
if ($v['thumb'])
{
$thumb = Lib_Images::getImageUrl($v['thumb'], 'source','fragmentimg');
}else
{
$thumb = SITE_IMG.'/pic01.png';
}
$list[$k]['thumb'] = $thumb ;
$list[$k]['desc'] = Util_StringHelper::substr_cn( $this->stripTags($v['content']), $num1);
$list[$k]['desc']=str_replace(array("\r\n", "\n", "\r"), "", $list[$k]['desc']);
$list[$k]['type_name'] = $v['tag'] ;
$list[$k]['title'] = Util_StringHelper::substr_cn('['.$v['tag'].'] '.$v['title'], $num2);
}
return $list;
}
/**
* 获取商品
*/
private function getGoods($brandId, $offset, $limit, &$total = 0)
{
$goodsList = Facade_Prod::getProdByBrandId($offset, $limit ,$brandId);
$total = Facade_Prod::getProdTotalByBrandId($brandId);
foreach ($goodsList as $k => $v)
{
$thumb = explode('|', $v['pic']);
$goodsList[$k]['pic'] = $thumb;
$goodsList[$k]['thumb'] = preg_replace('/-(\w+\d+)-/','-0150x0200-', $thumb[0]);
foreach ($thumb as $key => $val)
{
$thumb[$key] = preg_replace('/-(\w+\d+)-/','-0362x0481-', $val);
}
$goodsList[$k]['big'] = $thumb;
$goodsList[$k]['shortTitle'] = Util_StringHelper::substr_cn($v['name'], 21);
$goodsList[$k]['info'] = Util_StringHelper::substr_cn($v['text'], 20);
}
return $goodsList;
}
}