Plusstar.php
7.69 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
use Action\AbstractAction;
use LibModels\Wap\Guang\PlusstarData;
use Plugin\Helpers;
use Plugin\Images;
use Plugin\UdpLog;
/**
* 明星品牌和原创品牌
*/
class PlusstarController extends AbstractAction
{
/**
* 国际优选-品牌列表页
* 明星原创-品牌列表页
*
* @param int gender "1,3"表示男, "2,3"表示女
* @param int type 1表示国际优选, 2表示明星原创
*/
public function indexAction()
{
$gender = $this->get('gender', '1,3');
$type = $this->get('type', 1);
if ($type == '2') {
$this->setTitle('明星原创');
$this->setNavHeader('明星原创', true, SITE_MAIN);
$data = Guang\PlusstarModel::getBrands($gender);
$data['psList'] = true; // 控制模板中的JS使用
$data['pageFooter'] = true;
$this->_view->display('list', $data);
} else {
$this->setTitle('国际优选');
$this->setNavHeader('国际优选', true, SITE_MAIN);
$data = Guang\PlusstarModel::getFirstBrands($gender);
$data['psList'] = true; // 控制模板中的JS使用
$data['pageFooter'] = true;
$this->_view->display('list', $data);
}
}
/**
* 明星原创-品牌列表页
* @param int gender "1,3"表示男, "2,3"表示女
*/
public function listAction()
{
$this->setTitle('明星原创');
$this->setNavHeader('明星原创', true, SITE_MAIN);
$gender = $this->get('gender', '1,3');
$data = Guang\PlusstarModel::getBrands($gender);
$data['psList'] = true; // 控制模板中的JS使用
$this->_view->display('list', $data);
}
/**
* 品牌介绍页
*/
public function detailAction()
{
$data = array();
do {
/* 判断参数是否有效 */
$id = $this->get('id');
if (!is_numeric($id)) {
break;
}
$channel = $this->get('yh_channel');
// 标识是不是APP客户端
$isApp = is_numeric($channel);
// 标识是否是微信访问
$isWeixin = stripos($this->server('HTTP_USER_AGENT', ''), 'MicroMessenger') !== false;
// APP访问时通过频道参数判断性别
if ($isApp) {
switch (intval($channel)) {
case 1: // 男
$gender = '1,3';
break;
case 2: // 女
$gender = '2,3';
break;
default: // 所有
$gender = '1,2,3';
}
$uid = $this->get('uid');
$udid = $this->get('udid');
$this->setSession('uid', $uid);
}
// 从Cookie获取
else {
$gender = Helpers::getGenderByCookie();
$uid = $this->getUid();
$udid = $this->getUdid();
}
/* 判断品牌信息是否为空 */
$brandInfo = array();
try {
$brandInfo = PlusstarData::brandInfo($id, $gender, $uid, $udid, $isApp);
} catch (\Exception $e) {
// do nothing
}
UdpLog::info('==$brandInfo==', $brandInfo);
if (empty($brandInfo['getBrandInfo']['data']['brand_id'])) {
break;
}
$brandId = $brandInfo['getBrandInfo']['data']['brand_id'];
$brandDomain = $brandInfo['getBrandInfo']['data']['brand_domain'];
$isDifferent = $brandInfo['getBrandInfo']['data']['is_different'];
/* 获取更多品牌的链接 */
// 构建成 品牌域名.xxx.com
$url = Helpers::url('', null, $brandDomain);
// 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护
if ($isApp) {
$url .= '?openby:yohobuy={"action":"go.brand","params":{"brand_id":"' . $brandId . '","is_different":"' . $isDifferent . '"}}';
}
$data['psDetail'] = true;
$data['ps']['id'] = $brandId;
$data['ps']['banner'] = Helpers::getImageUrl($brandInfo['getBrandInfo']['data']['cover_img'], 640, 309);
$data['ps']['logo'] = Images::getSourceUrl($brandInfo['getBrandInfo']['data']['brand_ico'], 'brandLogo');
$data['ps']['name'] = $brandInfo['getBrandInfo']['data']['brand_name'];
$data['ps']['isLike'] = $brandInfo['getUidBrandFav'];
$data['ps']['intro'] = empty($brandInfo['getBrandInfo']['data']['brand_intro']) ? false : strtr(strip_tags($brandInfo['getBrandInfo']['data']['brand_intro']), array(' ' => ' '));
$data['ps']['newArrival'] = array();
$data['ps']['newArrival']['moreUrl'] = $url;
$data['ps']['newArrival']['naList'] = $brandInfo['getNewProduct'];
$data['ps']['infos'] = array();
// 拼收藏的URL, 一个坑!
// 备注:此处是根据原来逛的代码硬扒过来的
$defaultUrl = Helpers::url('/plustar/brandinfo', array('id' => $id), 'guang');
if ($isApp) {
$url = $defaultUrl;
$url .= '&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"http:\/\/guang.m.yohobuy.com\/plustar\/brandinfo","param":{"id":'
. $id . '}},"requesturl":{"url":"\/guang\/api\/v1\/favorite\/togglebrand","param":{"brand_id":"' . $brandId . '"}},"priority":"Y"}}';
} else {
$url = Helpers::url('/signin.html', array('refer' => $defaultUrl));
}
$data['ps']['likeUrl'] = $url;
if (empty($brandInfo['getArticleByBrand'])) {
break;
}
// 相关文章
foreach ($brandInfo['getArticleByBrand'] as $value) {
$result = Helpers::formatArticle($value, false, false, false, $uid);
// $result = array(
// 'id' => $value['id'],
// 'url' => $value['id'],
// 'title' => $value['id'],
// 'pageView' => $value['id'],
// 'img' => $value['src'],
// 'text' => $value['intro'],
// 'publishTime' => $value['publish_time']
// );
if (!$isApp) {
$result['like'] = $value['like'];
}
$data['ps']['infos'][] = $result;
}
//jumpToApp = 1表示APP未登录的情况,此时不发送ajax请求而由a链接直接跳转APP
if ($isApp && !$this->getSession('uid')) {
$data['ps']['jumpToApp'] = 1;
}
// 设置头部信息
if (!$isApp && !$isWeixin) {
$this->setNavHeader($data['ps']['name'], true, SITE_MAIN);
}
// 标识有微信分享
$data['hasWxShare'] = true;
$data['shareLink'] = $defaultUrl;
$data['shareTitle'] = $data['ps']['name'];
$data['shareDesc'] = (mb_strlen($data['ps']['intro'], 'utf-8') > 120) ? trim(strip_tags(mb_substr($data['ps']['intro'], 0, 120, 'utf-8'))) . '...' : $data['ps']['intro'];
$data['shareImg'] = $data['ps']['logo'];
$this->setTitle($data['shareTitle'], false, '');
$this->setDescription($data['shareDesc']);
$brandInfo = array();
} while (false);
if (array() === $data) {
$this->error();
} else {
$this->_view->display('detail', $data);
}
}
}