Product.class.php
3.63 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
<?php
/**
* 默认控制器
*/
class Controller_Product extends Controller_Abstract
{
public function indexAction()
{
return $this->_forward('news/index');
}
/**
* 详情页
*
*/
public function detailAction()
{
$id = intval($this->_request->id);
if (empty($id))
{
return $this->_redirect('news/index');
}
$info = Facade_News::getOneById($id);
if (!$info)
{
return $this->_redirect('news/index');
}
//增加浏览量
Facade_News::updateHits($id);
//获取上一个
$prev = Facade_News::getPrevNews($id);
if ($prev)
{
if ($prev['thumb'])
{
$thumb = Lib_Images::getImageUrl($prev['thumb'], '0138x0075','fragmentimg');
}else
{
$thumb = SITE_IMG.'/pic01.png';
}
$prev['thumb'] = $thumb ;
$prev['title'] = Util_StringHelper::substr_cn( $this->stripTags($prev['title']),20 );
$prev['desc'] = Util_StringHelper::substr_cn( $this->stripTags($prev['content']),40 );
}
//获取下一个
$next = Facade_News::getNextNews($id);
if ($next)
{
if ($next['thumb'])
{
$thumb = Lib_Images::getImageUrl($next['thumb'], '0138x0075','fragmentimg');
}else
{
$thumb = SITE_IMG.'/pic01.png';
}
$next['thumb'] = $thumb ;
$next['title'] = Util_StringHelper::substr_cn( $this->stripTags($next['title']),20 );
$next['desc'] = Util_StringHelper::substr_cn( $this->stripTags($next['content']),40 );
}
$this->_view['next'] = $next ;
$this->_view['prev'] = $prev ;
$this->_view['info'] = $info ;
/***设置网站的SEO信息***/
$seo = C('APP.Seo');
$this->setTitle($info['title']);
$this->setKeywords($seo['channel_news_keywords']);
$this->setDescription($seo['channel_news_description']);
}
/**
* 限量推荐
*/
public function recommendAction()
{
/*
* $test = $this->_request->query('test', 1);
if($test)
{
$this->_viewname ='recommend_ad';
}*/
$limit = 10;
$recomStatus = 1;
$total = Facade_Prod::getProdTotal($recomStatus);
$page = new Lib_Helper_Pagination($total, $limit);
list($offset, $limit) = $page->getLimit();
$products = Facade_Prod::getProd($recomStatus, $offset, $limit);
$brands = array();
foreach($products as $product)
{
if(!isset($brands[$product['brand_id']]))
{
$brand = Facade_Brand::getBrandbyID($product['brand_id']);
if ($brand['logo'])
{
$thumb = Lib_Images::getImageUrl($brand['logo'], '0110x0073','fragmentimg');
}
else
{
$thumb = SITE_IMG.'/pic01.png';
}
$brand['logo'] = $thumb;
$brands[$product['brand_id']] = $brand;
}
}
$this->_view['products'] = $products;
$this->_view['brands'] = $brands;
$this->_view['pagination'] = $page->getPagination();
}
/**
* 获取限量推荐
*
* @return json
*/
public function getrecommendAction()
{
$offset = intval($this->_request->query('offset', 0));
$limit = intval($this->_request->query('limit', 5));
$recomStatus = 1;
$products = Facade_Prod::getProd($recomStatus, $offset, $limit);
return $this->returnJson(true, 200, $products, '');
}
}