Showing
1 changed file
with
360 additions
and
353 deletions
1 | -<?php | ||
2 | - | ||
3 | -namespace Guang; | ||
4 | - | ||
5 | -use Api\Yohobuy; | ||
6 | -use LibModels\Web\Guang\InfoData; | ||
7 | -use LibModels\Web\Product\SearchData; | ||
8 | -use Plugin\Images; | ||
9 | -use WebPlugin\Helpers; | ||
10 | -use WebPlugin\HelperSearch; | ||
11 | - | ||
12 | - | ||
13 | -/** | ||
14 | - * 逛-文章页 | ||
15 | - */ | ||
16 | -class InfoModel | ||
17 | -{ | ||
18 | - /** | ||
19 | - * 获取详情页数据 | ||
20 | - * @param $id 文章id | ||
21 | - * @param $uid 用户id | ||
22 | - * @param $udid 客户端标示 | ||
23 | - * @param $page 评论分页 | ||
24 | - * @param $gender 性别 | ||
25 | - * @param $channel 频道 | ||
26 | - * @param $limit 评论每页显示条数 | ||
27 | - * @return array | ||
28 | - */ | ||
29 | - public static function articleInfo($id, $uid, $udid, $page, $gender, $channel, $limit) | ||
30 | - { | ||
31 | - $result = array(); | ||
32 | - //文章相关信息 | ||
33 | - $articleInfo = InfoData::getArticleInfo($id); | ||
34 | - if (isset($articleInfo['code']) && $articleInfo['code'] == 200 && isset($articleInfo['data']) && !empty($articleInfo['data'])) { | ||
35 | - //作者 | ||
36 | - if (isset($articleInfo['data']['author_id']) && !empty($articleInfo['data']['author_id'])) { | ||
37 | - $url['author'] = InfoData::author($articleInfo['data']['author_id'], true); | ||
38 | - } | ||
39 | - //文章内容 | ||
40 | - $url['contents'] = InfoData::articleContent($id, true); | ||
41 | - //热门标签 | ||
42 | - $url['hotTags'] = InfoData::tagTop(1, 20, true); | ||
43 | - //评论 | ||
44 | - $url['comments'] = InfoData::comment($id, $page, $limit, true); | ||
45 | - //基本信息 | ||
46 | - $url['baseInfo'] = InfoData::baseInfo($id, $uid, $udid, true); | ||
47 | - //相关品牌 | ||
48 | - $url['brands'] = InfoData::relateBrand($id, true); | ||
49 | - //相关文章 | ||
50 | - if (isset($articleInfo['data']['tag']) && !empty($articleInfo['data']['tag'])) { | ||
51 | - $url['relate'] = InfoData::relateList($id, $articleInfo['data']['tag'], 3, true); | ||
52 | - } | ||
53 | - //推荐文章 | ||
54 | - $url['recommend'] = InfoData::recommend($gender, 1, 10, true); | ||
55 | - $data = Yohobuy::getMulti($url); | ||
56 | - $result = self::formatInfo($articleInfo['data'], $data, $channel, $limit); | ||
57 | - } | ||
58 | - return $result; | ||
59 | - } | ||
60 | - | ||
61 | - /** | ||
62 | - * 格式化逛详情页数据 | ||
63 | - * @param $article 文章信息 | ||
64 | - * @param $data 作者信息、文章内容、热门标签、评论、相关文章、推荐文章 | ||
65 | - * @param $channel 频道 | ||
66 | - * @param $limit 评论一页显示记录数 | ||
67 | - * @return array | ||
68 | - */ | ||
69 | - public static function formatInfo($article, $data, $channel, $limit) | ||
70 | - { | ||
71 | - $result['content'] = $other = array(); | ||
72 | - //推荐商品列表 | ||
73 | - $goods = $goodsGroup = array(); | ||
74 | - $result['pathNav'] = self::getCenterCrumb($article['article_title'], $channel); | ||
75 | - //文章头部信息 | ||
76 | - $result['header']['title'] = $article['article_title']; | ||
77 | - $result['header']['avatar'] = isset($data['author']['avatar']) && !empty($data['author']['avatar']) ? $data['author']['avatar'] : ''; | ||
78 | - $result['header']['name'] = isset($data['author']['name']) && !empty($data['author']['name']) ? $data['author']['name'] : ''; | ||
79 | - $result['header']['authorUrl'] = isset($data['author']['name']) && !empty($data['author']['name']) ? Helpers::url('/Index/editor', array('author_id'=>$article['author_id']), 'guang') : ''; | ||
80 | - $result['header']['intro'] = isset($data['author']['author_desc']) && !empty($data['author']['author_desc']) ? $data['author']['author_desc'] : ''; | ||
81 | - $result['header']['time'] = date('Y年m月d日 H:i', $article['publish_time']); | ||
82 | - $result['header']['click'] = $article['pageViews']; | ||
83 | - $result['header']['commentNum'] = $data['comments']['total']; | ||
84 | - $result['header']['shareImg'] = Images::getImageUrl($article['cover_image'], 600, 600); | ||
85 | - $result['header']['desc'] = $article['article_summary']; | ||
86 | - $result['header']['weixinUrl'] = $article['url']; | ||
87 | - //文章详细 | ||
88 | - if (isset($data['contents']) && !empty($data['contents'])) { | ||
89 | - foreach ($data['contents'] as $key => $val) { | ||
90 | - foreach ($val as $type => $con) { | ||
91 | - if ($type === 'goods') { | ||
92 | - $goods = array_merge_recursive($goods, self::goods($con['data'])); | ||
93 | - } elseif ($type === 'goodsGroup') { | ||
94 | - $goodsGroup = array_merge_recursive($goodsGroup, self::goodsGroup($con['data'])); | ||
95 | - } else { | ||
96 | - $other = is_callable("self::$type") ? self::$type($con['data']) : ''; | ||
97 | - array_push($result['content'], $other); | ||
98 | - } | ||
99 | - } | ||
100 | - } | ||
101 | - } | ||
102 | - if (!empty($goods)) { | ||
103 | - $result['content'][]['relatedReco'] = array('recos'=>$goods); | ||
104 | - } | ||
105 | - if (!empty($goodsGroup)) { | ||
106 | - $result['content'][]['relatedReco'] = $goodsGroup; | ||
107 | - } | ||
108 | - //赞、收藏 | ||
109 | - if (isset($data['baseInfo']) && !empty($data['baseInfo'])) { | ||
110 | - $result['userInfo']['isLike'] = $data['baseInfo']['isPraise'] == 'Y' ? true : false; | ||
111 | - $result['userInfo']['likeNum'] = $data['baseInfo']['praise_num']; | ||
112 | - $result['userInfo']['isCollected'] = $data['baseInfo']['isFavor'] == 'Y' ? true : false;; | ||
113 | - } | ||
114 | - //文章tags | ||
115 | - if (isset($article['tags']) && !empty($article['tags'])) { | ||
116 | - foreach ($article['tags'] as $tagKey => $tagsValue) { | ||
117 | - $result['tag'][$tagKey]['name'] = $tagsValue['name']; | ||
118 | - $result['tag'][$tagKey]['url'] = Helpers::url('/tags/index', array('query' => $tagsValue['name']),'guang'); | ||
119 | - } | ||
120 | - } | ||
121 | - //相关品牌 | ||
122 | - if (isset($data['brands']) && !empty($data['brands'])) { | ||
123 | - $result['brands'] = $data['brands']; | ||
124 | - } | ||
125 | - //相关文章 | ||
126 | - if (isset($data['relate']) && !empty($data['relate'])) { | ||
127 | - foreach ($data['relate'] as $key => $val) { | ||
128 | - $result['relatedPost'][$key]['title'] = $val['title']; | ||
129 | - $result['relatedPost'][$key]['thumb'] = Images::getImageUrl($val['thumb'], 264, 173, 1); | ||
130 | - $result['relatedPost'][$key]['url'] = Helpers::url('/'.$val['id'].'.html', array(), 'guang'); | ||
131 | - } | ||
132 | - } | ||
133 | - //精彩推荐 | ||
134 | - if (isset($data['recommend']) && !empty($data['recommend'])) { | ||
135 | - foreach ($data['recommend'] as $key => $val) { | ||
136 | - $result['exRecos'][$key]['title'] = $val['title']; | ||
137 | - $result['exRecos'][$key]['img'] = isset($val['src']) ? Images::getImageUrl($val['src'], 90, 60) : ''; | ||
138 | - $result['exRecos'][$key]['url'] = Helpers::url('/'.$val['id'].'.html', array(), 'guang'); | ||
139 | - } | ||
140 | - } | ||
141 | - //热门标签 | ||
142 | - if (isset($data['hotTags']) && !empty($data['hotTags'])) { | ||
143 | - foreach ($data['hotTags'] as $key => $val) { | ||
144 | - $result['hotTags'][$key]['tagName'] = $val['tag_name']; | ||
145 | - $result['hotTags'][$key]['url'] = Helpers::url('/tags/index',array('query'=>$val['tag_name']), 'guang'); | ||
146 | - } | ||
147 | - } | ||
148 | - //评论 | ||
149 | - if (isset($data['comments']) && !empty($data['comments']) && isset($data['comments']['total'])) { | ||
150 | - $result['comment']['commentNum'] = $data['comments']['total']; | ||
151 | - $result['comment']['commentPager'] = HelperSearch::pager($data['comments']['total'], $limit); | ||
152 | - if ($data['comments']['total'] > 0 && !empty($data['comments']['list'])){ | ||
153 | - foreach ($data['comments']['list'] as $key => $val) { | ||
154 | - $result['comment']['list'][$key]['avatar'] = Images::getImageUrl($val['avator'], 100, 100); | ||
155 | - $result['comment']['list'][$key]['name'] = $val['username']; | ||
156 | - $result['comment']['list'][$key]['content'] = $val['content']; | ||
157 | - $result['comment']['list'][$key]['time'] = $val['create_time']; | ||
158 | - } | ||
159 | - } | ||
160 | - } | ||
161 | - return $result; | ||
162 | - } | ||
163 | - | ||
164 | - /** | ||
165 | - * 逛详情文本 | ||
166 | - * @param $con | ||
167 | - * @return mixed | ||
168 | - */ | ||
169 | - public static function text($con) | ||
170 | - { | ||
171 | - return $con; | ||
172 | - } | ||
173 | - | ||
174 | - /** | ||
175 | - * 逛详情单张图片 | ||
176 | - * @param $con | ||
177 | - * @return array | ||
178 | - */ | ||
179 | - public static function singleImage($con) | ||
180 | - { | ||
181 | - return array('pic' => Images::getImageUrl($con[0]['src'], 640, 640)); | ||
182 | - } | ||
183 | - | ||
184 | - /** | ||
185 | - * 逛详情商品组 | ||
186 | - * @param $goodsGroup | ||
187 | - * @return mixed | ||
188 | - */ | ||
189 | - public static function goodsGroup($goodsGroup) | ||
190 | - { | ||
191 | - $result = $groupSkn = array(); | ||
192 | - foreach ($goodsGroup as $key => $val) { | ||
193 | - if (!isset($val['list']) || empty($val['list'])) { | ||
194 | - continue; | ||
195 | - } | ||
196 | - $productSkn = array(); | ||
197 | - foreach ($val['list'] as $k => $v) { | ||
198 | - $groupSkn[$key][] = $v['id']; | ||
199 | - $productSkn[] = $v['id']; | ||
200 | - } | ||
201 | - if (!empty($productSkn)) { | ||
202 | - $product = SearchData::searchElasticByCondition(array('query' => implode(',', $productSkn))); | ||
203 | - if (isset($product['data']['product_list'])) { | ||
204 | - $result[$key]['recos'] = array_slice(self::formatProduct($product['data']['product_list']), 0, 4); | ||
205 | - } | ||
206 | - } | ||
207 | - } | ||
208 | - return $result; | ||
209 | - } | ||
210 | - | ||
211 | - /** | ||
212 | - * 逛详情商品列表 | ||
213 | - * @param $goods | ||
214 | - * @return array | ||
215 | - */ | ||
216 | - public static function goods($goods) | ||
217 | - { | ||
218 | - $result = $productSkn = array(); | ||
219 | - foreach ($goods as $key => $val) { | ||
220 | - $productSkn[] = $val['id']; | ||
221 | - } | ||
222 | - if (!empty($productSkn)) { | ||
223 | - $product = SearchData::searchElasticByCondition(array('query'=> implode(',', $productSkn))); | ||
224 | - if (isset($product['data']['product_list'])) { | ||
225 | - $result = self::formatProduct($product['data']['product_list']); | ||
226 | - } | ||
227 | - } else { | ||
228 | - return array(); | ||
229 | - } | ||
230 | - return $result; | ||
231 | - } | ||
232 | - | ||
233 | - /** | ||
234 | - * 逛详情两张小图 | ||
235 | - * @param $pic | ||
236 | - * @return array | ||
237 | - */ | ||
238 | - public static function smallPic($pic) | ||
239 | - { | ||
240 | - $result = array(); | ||
241 | - foreach ($pic as $key => $val) { | ||
242 | - if ($key < 2) { | ||
243 | - $result['smallPic'][] = Images::getImageUrl($val['src'], 600, 600); | ||
244 | - } | ||
245 | - } | ||
246 | - return $result; | ||
247 | - } | ||
248 | - | ||
249 | - /** | ||
250 | - * 逛详情链接 | ||
251 | - * @param $link | ||
252 | - * @return array | ||
253 | - */ | ||
254 | - public static function link($link) | ||
255 | - { | ||
256 | - $result = array(); | ||
257 | - return $result; | ||
258 | - } | ||
259 | - | ||
260 | - /** | ||
261 | - * 逛-面包屑 | ||
262 | - * name 当前停留面包屑名称 | ||
263 | - * nav 逛 之后的面包屑 | ||
264 | - */ | ||
265 | - public static function getCenterCrumb($name, $channel) | ||
266 | - { | ||
267 | - //根据频道判断home页地址 | ||
268 | - switch ($channel) { | ||
269 | - case 'boys': | ||
270 | - $home = Helpers::url('', '', 'default'); | ||
271 | - break; | ||
272 | - case 'girls': | ||
273 | - $home = Helpers::url('/woman', '', 'new'); | ||
274 | - break; | ||
275 | - case 'lifestyle': | ||
276 | - $home = Helpers::url('/lifestyle', '', 'new'); | ||
277 | - break; | ||
278 | - case 'kids': | ||
279 | - $home = Helpers::url('/kids', '', 'new'); | ||
280 | - break; | ||
281 | - default: | ||
282 | - $home = Helpers::url('', '', 'default'); | ||
283 | - break; | ||
284 | - } | ||
285 | - $retNav = array( | ||
286 | - array( | ||
287 | - 'name' => strtoupper($channel) . '首页', | ||
288 | - 'href' => $home | ||
289 | - ), | ||
290 | - array( | ||
291 | - 'name' => '逛', | ||
292 | - 'href' => Helpers::url('', '', 'guang') | ||
293 | - ) | ||
294 | - ); | ||
295 | - $retNav[] = array( | ||
296 | - 'name' => $name | ||
297 | - ); | ||
298 | - return $retNav; | ||
299 | - } | ||
300 | - | ||
301 | - /** | ||
302 | - * 文章评论列表 | ||
303 | - * @param $id | ||
304 | - * @param $page | ||
305 | - * @param $limit | ||
306 | - * @return array | ||
307 | - */ | ||
308 | - public static function commentList($id, $page, $limit) | ||
309 | - { | ||
310 | - $result = array(); | ||
311 | - $data = InfoData::comment($id, $page, $limit); | ||
312 | - //评论 | ||
313 | - if (isset($data['code']) && $data['code'] == 200) { | ||
314 | - $result['comment']['commentNum'] = $data['data']['total']; | ||
315 | - $result['comment']['commentPager'] = HelperSearch::pager($data['data']['total'], $limit); | ||
316 | - if ($data['data']['total'] > 0 && !empty($data['data']['list'])){ | ||
317 | - foreach ($data['data']['list'] as $key => $val) { | ||
318 | - $result['comment']['list'][$key]['avatar'] = Images::getImageUrl($val['avator'], 100, 100); | ||
319 | - $result['comment']['list'][$key]['name'] = $val['username']; | ||
320 | - $result['comment']['list'][$key]['content'] = $val['content']; | ||
321 | - $result['comment']['list'][$key]['time'] = $val['create_time']; | ||
322 | - } | ||
323 | - } | ||
324 | - } | ||
325 | - return $result; | ||
326 | - } | ||
327 | - | ||
328 | - /** | ||
329 | - * 格式化推荐商品 | ||
330 | - * @param $product | ||
331 | - * @return arr | ||
332 | - */ | ||
333 | - public static function formatProduct($product) | ||
334 | - { | ||
335 | - $result = array(); | ||
336 | - foreach ($product as $key => $val) { | ||
337 | - if (empty($val['default_images'])) { | ||
338 | - $val['default_images'] = $val['goods_list'][0]['images_url']; | ||
339 | - } | ||
340 | - $result[$key]['thumb'] = Images::getImageUrl($val['default_images'],235,314); | ||
341 | - $result[$key]['name'] = $val['product_name']; | ||
342 | - //市场价不等于售价时显示 | ||
343 | - if ($val['market_price'] != $val['sales_price']) { | ||
344 | - $result[$key]['marketPrice'] = $val['market_price']; | ||
345 | - } | ||
346 | - $result[$key]['salePrice'] = $val['sales_price']; | ||
347 | - $result[$key]['url'] = Helpers::getUrlBySkc($val['product_id'], $val['goods_list'][0]['goods_id'], $val['cn_alphabet']);; | ||
348 | - } | ||
349 | - return $result; | ||
350 | - } | ||
351 | - | ||
352 | -} | ||
353 | - | 1 | +<?php |
2 | + | ||
3 | +namespace Guang; | ||
4 | + | ||
5 | +use Api\Yohobuy; | ||
6 | +use LibModels\Web\Guang\InfoData; | ||
7 | +use LibModels\Web\Product\SearchData; | ||
8 | +use Plugin\Images; | ||
9 | +use WebPlugin\Helpers; | ||
10 | +use WebPlugin\HelperSearch; | ||
11 | + | ||
12 | + | ||
13 | +/** | ||
14 | + * 逛-文章页 | ||
15 | + */ | ||
16 | +class InfoModel | ||
17 | +{ | ||
18 | + /** | ||
19 | + * 获取详情页数据 | ||
20 | + * @param $id 文章id | ||
21 | + * @param $uid 用户id | ||
22 | + * @param $udid 客户端标示 | ||
23 | + * @param $page 评论分页 | ||
24 | + * @param $gender 性别 | ||
25 | + * @param $channel 频道 | ||
26 | + * @param $limit 评论每页显示条数 | ||
27 | + * @return array | ||
28 | + */ | ||
29 | + public static function articleInfo($id, $uid, $udid, $page, $gender, $channel, $limit) | ||
30 | + { | ||
31 | + $result = array(); | ||
32 | + //文章相关信息 | ||
33 | + $articleInfo = InfoData::getArticleInfo($id); | ||
34 | + if (isset($articleInfo['code']) && $articleInfo['code'] == 200 && isset($articleInfo['data']) && !empty($articleInfo['data'])) { | ||
35 | + //作者 | ||
36 | + if (isset($articleInfo['data']['author_id']) && !empty($articleInfo['data']['author_id'])) { | ||
37 | + $url['author'] = InfoData::author($articleInfo['data']['author_id'], true); | ||
38 | + } | ||
39 | + //文章内容 | ||
40 | + $url['contents'] = InfoData::articleContent($id, true); | ||
41 | + //热门标签 | ||
42 | + $url['hotTags'] = InfoData::tagTop(1, 20, true); | ||
43 | + //评论 | ||
44 | + $url['comments'] = InfoData::comment($id, $page, $limit, true); | ||
45 | + //基本信息 | ||
46 | + $url['baseInfo'] = InfoData::baseInfo($id, $uid, $udid, true); | ||
47 | + //相关品牌 | ||
48 | + $url['brands'] = InfoData::relateBrand($id, true); | ||
49 | + //相关文章 | ||
50 | + if (isset($articleInfo['data']['tag']) && !empty($articleInfo['data']['tag'])) { | ||
51 | + $url['relate'] = InfoData::relateList($id, $articleInfo['data']['tag'], 3, true); | ||
52 | + } | ||
53 | + //推荐文章 | ||
54 | + $url['recommend'] = InfoData::recommend($gender, 1, 10, true); | ||
55 | + $data = Yohobuy::getMulti($url); | ||
56 | + $result = self::formatInfo($articleInfo['data'], $data, $channel, $limit); | ||
57 | + } | ||
58 | + return $result; | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * 格式化逛详情页数据 | ||
63 | + * @param $article 文章信息 | ||
64 | + * @param $data 作者信息、文章内容、热门标签、评论、相关文章、推荐文章 | ||
65 | + * @param $channel 频道 | ||
66 | + * @param $limit 评论一页显示记录数 | ||
67 | + * @return array | ||
68 | + */ | ||
69 | + public static function formatInfo($article, $data, $channel, $limit) | ||
70 | + { | ||
71 | + $result['content'] = $other = array(); | ||
72 | + //推荐商品列表 | ||
73 | + $goods = $goodsGroup = array(); | ||
74 | + $result['pathNav'] = self::getCenterCrumb($article['article_title'], $channel); | ||
75 | + //文章头部信息 | ||
76 | + $result['header']['title'] = $article['article_title']; | ||
77 | + $result['header']['avatar'] = isset($data['author']['avatar']) && !empty($data['author']['avatar']) ? $data['author']['avatar'] : ''; | ||
78 | + $result['header']['name'] = isset($data['author']['name']) && !empty($data['author']['name']) ? $data['author']['name'] : ''; | ||
79 | + $result['header']['authorUrl'] = isset($data['author']['name']) && !empty($data['author']['name']) ? Helpers::url('/Index/editor', array('author_id'=>$article['author_id']), 'guang') : ''; | ||
80 | + $result['header']['intro'] = isset($data['author']['author_desc']) && !empty($data['author']['author_desc']) ? $data['author']['author_desc'] : ''; | ||
81 | + $result['header']['time'] = date('Y年m月d日 H:i', $article['publish_time']); | ||
82 | + $result['header']['click'] = $article['pageViews']; | ||
83 | + $result['header']['commentNum'] = $data['comments']['total']; | ||
84 | + $result['header']['shareImg'] = Images::getImageUrl($article['cover_image'], 600, 600); | ||
85 | + $result['header']['desc'] = $article['article_summary']; | ||
86 | + $result['header']['weixinUrl'] = $article['url']; | ||
87 | + //文章详细 | ||
88 | + if (isset($data['contents']) && !empty($data['contents'])) { | ||
89 | + foreach ($data['contents'] as $key => $val) { | ||
90 | + foreach ($val as $type => $con) { | ||
91 | + if ($type === 'goods') { | ||
92 | + $goods = array_merge_recursive($goods, self::goods($con['data'])); | ||
93 | + } elseif ($type === 'goodsGroup') { | ||
94 | + $goodsGroup = array_merge_recursive($goodsGroup, self::goodsGroup($con['data'])); | ||
95 | + } else { | ||
96 | + $other = is_callable("self::$type") ? self::$type($con['data']) : ''; | ||
97 | + array_push($result['content'], $other); | ||
98 | + } | ||
99 | + } | ||
100 | + } | ||
101 | + } | ||
102 | + if (!empty($goods)) { | ||
103 | + $result['content'][]['relatedReco'] = array('recos'=>$goods); | ||
104 | + } | ||
105 | + if (!empty($goodsGroup)) { | ||
106 | + $result['content'][]['relatedReco'] = $goodsGroup; | ||
107 | + } | ||
108 | + //赞、收藏 | ||
109 | + if (isset($data['baseInfo']) && !empty($data['baseInfo'])) { | ||
110 | + $result['userInfo']['isLike'] = $data['baseInfo']['isPraise'] == 'Y' ? true : false; | ||
111 | + $result['userInfo']['likeNum'] = $data['baseInfo']['praise_num']; | ||
112 | + $result['userInfo']['isCollected'] = $data['baseInfo']['isFavor'] == 'Y' ? true : false;; | ||
113 | + } | ||
114 | + //文章tags | ||
115 | + if (isset($article['tags']) && !empty($article['tags'])) { | ||
116 | + foreach ($article['tags'] as $tagKey => $tagsValue) { | ||
117 | + $result['tag'][$tagKey]['name'] = $tagsValue['name']; | ||
118 | + $result['tag'][$tagKey]['url'] = Helpers::url('/tags/index', array('query' => $tagsValue['name']),'guang'); | ||
119 | + } | ||
120 | + } | ||
121 | + //相关品牌 | ||
122 | + if (isset($data['brands']) && !empty($data['brands'])) { | ||
123 | + $result['brands'] = $data['brands']; | ||
124 | + } | ||
125 | + //相关文章 | ||
126 | + if (isset($data['relate']) && !empty($data['relate'])) { | ||
127 | + foreach ($data['relate'] as $key => $val) { | ||
128 | + $result['relatedPost'][$key]['title'] = $val['title']; | ||
129 | + $result['relatedPost'][$key]['thumb'] = Images::getImageUrl($val['thumb'], 264, 173, 1); | ||
130 | + $result['relatedPost'][$key]['url'] = Helpers::url('/'.$val['id'].'.html', array(), 'guang'); | ||
131 | + } | ||
132 | + } | ||
133 | + //精彩推荐 | ||
134 | + if (isset($data['recommend']) && !empty($data['recommend'])) { | ||
135 | + foreach ($data['recommend'] as $key => $val) { | ||
136 | + $result['exRecos'][$key]['title'] = $val['title']; | ||
137 | + $result['exRecos'][$key]['img'] = isset($val['src']) ? Images::getImageUrl($val['src'], 90, 60) : ''; | ||
138 | + $result['exRecos'][$key]['url'] = Helpers::url('/'.$val['id'].'.html', array(), 'guang'); | ||
139 | + } | ||
140 | + } | ||
141 | + //热门标签 | ||
142 | + if (isset($data['hotTags']) && !empty($data['hotTags'])) { | ||
143 | + foreach ($data['hotTags'] as $key => $val) { | ||
144 | + $result['hotTags'][$key]['tagName'] = $val['tag_name']; | ||
145 | + $result['hotTags'][$key]['url'] = Helpers::url('/tags/index',array('query'=>$val['tag_name']), 'guang'); | ||
146 | + } | ||
147 | + } | ||
148 | + //评论 | ||
149 | + if (isset($data['comments']) && !empty($data['comments']) && isset($data['comments']['total'])) { | ||
150 | + $result['comment']['commentNum'] = $data['comments']['total']; | ||
151 | + $result['comment']['commentPager'] = HelperSearch::pager($data['comments']['total'], $limit); | ||
152 | + if ($data['comments']['total'] > 0 && !empty($data['comments']['list'])){ | ||
153 | + foreach ($data['comments']['list'] as $key => $val) { | ||
154 | + $result['comment']['list'][$key]['avatar'] = Images::getImageUrl($val['avator'], 100, 100); | ||
155 | + $result['comment']['list'][$key]['name'] = $val['username']; | ||
156 | + $result['comment']['list'][$key]['content'] = $val['content']; | ||
157 | + $result['comment']['list'][$key]['time'] = $val['create_time']; | ||
158 | + } | ||
159 | + } | ||
160 | + } | ||
161 | + return $result; | ||
162 | + } | ||
163 | + | ||
164 | + /** | ||
165 | + * 逛详情文本 | ||
166 | + * @param $con | ||
167 | + * @return mixed | ||
168 | + */ | ||
169 | + public static function text($con) | ||
170 | + { | ||
171 | + return $con; | ||
172 | + } | ||
173 | + | ||
174 | + /** | ||
175 | + * 逛详情单张图片 | ||
176 | + * @param $con | ||
177 | + * @return array | ||
178 | + */ | ||
179 | + public static function singleImage($con) | ||
180 | + { | ||
181 | + return array('pic' => Images::getImageUrl($con[0]['src'], 640, 640)); | ||
182 | + } | ||
183 | + | ||
184 | + /** | ||
185 | + * 逛详情商品组 | ||
186 | + * @param $goodsGroup | ||
187 | + * @return mixed | ||
188 | + */ | ||
189 | + public static function goodsGroup($goodsGroup) | ||
190 | + { | ||
191 | + $result = $groupSkn = array(); | ||
192 | + foreach ($goodsGroup as $key => $val) { | ||
193 | + if (!isset($val['list']) || empty($val['list'])) { | ||
194 | + continue; | ||
195 | + } | ||
196 | + $productSkn = array(); | ||
197 | + foreach ($val['list'] as $k => $v) { | ||
198 | + $groupSkn[$key][] = $v['id']; | ||
199 | + $productSkn[] = $v['id']; | ||
200 | + $arr[$v['id']]=$v['src']; | ||
201 | + } | ||
202 | + if (!empty($productSkn)) { | ||
203 | + $product = SearchData::searchElasticByCondition(array('query' => implode(',', $productSkn))); | ||
204 | + if (isset($product['data']['product_list'])) { | ||
205 | + $result[$key]['recos'] = array_slice(self::formatProduct($product['data']['product_list'], $arr), 0, 4); | ||
206 | + } | ||
207 | + } | ||
208 | + } | ||
209 | + return $result; | ||
210 | + } | ||
211 | + | ||
212 | + /** | ||
213 | + * 逛详情商品列表 | ||
214 | + * @param $goods | ||
215 | + * @return array | ||
216 | + */ | ||
217 | + public static function goods($goods) | ||
218 | + { | ||
219 | + $result = $productSkn = array(); | ||
220 | + foreach ($goods as $key => $val) { | ||
221 | + $productSkn[] = $val['id']; | ||
222 | + $arr[$val['id']]=$val['src']; | ||
223 | + } | ||
224 | + if (!empty($productSkn)) { | ||
225 | + $product = SearchData::searchElasticByCondition(array('query'=> implode(',', $productSkn))); | ||
226 | + if (isset($product['data']['product_list'])) { | ||
227 | + $result = self::formatProduct($product['data']['product_list'], $arr); | ||
228 | + } | ||
229 | + } else { | ||
230 | + return array(); | ||
231 | + } | ||
232 | + return $result; | ||
233 | + } | ||
234 | + | ||
235 | + /** | ||
236 | + * 逛详情两张小图 | ||
237 | + * @param $pic | ||
238 | + * @return array | ||
239 | + */ | ||
240 | + public static function smallPic($pic) | ||
241 | + { | ||
242 | + $result = array(); | ||
243 | + foreach ($pic as $key => $val) { | ||
244 | + if ($key < 2) { | ||
245 | + $result['smallPic'][] = Images::getImageUrl($val['src'], 600, 600); | ||
246 | + } | ||
247 | + } | ||
248 | + return $result; | ||
249 | + } | ||
250 | + | ||
251 | + /** | ||
252 | + * 逛详情链接 | ||
253 | + * @param $link | ||
254 | + * @return array | ||
255 | + */ | ||
256 | + public static function link($link) | ||
257 | + { | ||
258 | + $result = array(); | ||
259 | + return $result; | ||
260 | + } | ||
261 | + | ||
262 | + /** | ||
263 | + * 逛-面包屑 | ||
264 | + * name 当前停留面包屑名称 | ||
265 | + * nav 逛 之后的面包屑 | ||
266 | + */ | ||
267 | + public static function getCenterCrumb($name, $channel) | ||
268 | + { | ||
269 | + //根据频道判断home页地址 | ||
270 | + switch ($channel) { | ||
271 | + case 'boys': | ||
272 | + $home = Helpers::url('', '', 'default'); | ||
273 | + break; | ||
274 | + case 'girls': | ||
275 | + $home = Helpers::url('/woman', '', 'new'); | ||
276 | + break; | ||
277 | + case 'lifestyle': | ||
278 | + $home = Helpers::url('/lifestyle', '', 'new'); | ||
279 | + break; | ||
280 | + case 'kids': | ||
281 | + $home = Helpers::url('/kids', '', 'new'); | ||
282 | + break; | ||
283 | + default: | ||
284 | + $home = Helpers::url('', '', 'default'); | ||
285 | + break; | ||
286 | + } | ||
287 | + $retNav = array( | ||
288 | + array( | ||
289 | + 'name' => strtoupper($channel) . '首页', | ||
290 | + 'href' => $home | ||
291 | + ), | ||
292 | + array( | ||
293 | + 'name' => '逛', | ||
294 | + 'href' => Helpers::url('', '', 'guang') | ||
295 | + ) | ||
296 | + ); | ||
297 | + $retNav[] = array( | ||
298 | + 'name' => $name | ||
299 | + ); | ||
300 | + return $retNav; | ||
301 | + } | ||
302 | + | ||
303 | + /** | ||
304 | + * 文章评论列表 | ||
305 | + * @param $id | ||
306 | + * @param $page | ||
307 | + * @param $limit | ||
308 | + * @return array | ||
309 | + */ | ||
310 | + public static function commentList($id, $page, $limit) | ||
311 | + { | ||
312 | + $result = array(); | ||
313 | + $data = InfoData::comment($id, $page, $limit); | ||
314 | + //评论 | ||
315 | + if (isset($data['code']) && $data['code'] == 200) { | ||
316 | + $result['comment']['commentNum'] = $data['data']['total']; | ||
317 | + $result['comment']['commentPager'] = HelperSearch::pager($data['data']['total'], $limit); | ||
318 | + if ($data['data']['total'] > 0 && !empty($data['data']['list'])){ | ||
319 | + foreach ($data['data']['list'] as $key => $val) { | ||
320 | + $result['comment']['list'][$key]['avatar'] = Images::getImageUrl($val['avator'], 100, 100); | ||
321 | + $result['comment']['list'][$key]['name'] = $val['username']; | ||
322 | + $result['comment']['list'][$key]['content'] = $val['content']; | ||
323 | + $result['comment']['list'][$key]['time'] = $val['create_time']; | ||
324 | + } | ||
325 | + } | ||
326 | + } | ||
327 | + return $result; | ||
328 | + } | ||
329 | + | ||
330 | + /** | ||
331 | + * 格式化推荐商品 | ||
332 | + * @param $product | ||
333 | + * @return arr | ||
334 | + */ | ||
335 | + public static function formatProduct($product, $arr) | ||
336 | + { | ||
337 | + $result = array(); | ||
338 | + foreach ($arr as $k => $v) { | ||
339 | + foreach ($product as $key => $val) { | ||
340 | + $goods = array(); | ||
341 | + $goods['thumb'] = Images::getImageUrl($val['default_images'],235,314); | ||
342 | + $goods['name'] = $val['product_name']; | ||
343 | + //市场价不等于售价时显示 | ||
344 | + if ($val['market_price'] != $val['sales_price']) { | ||
345 | + $goods['marketPrice'] = $val['market_price']; | ||
346 | + } | ||
347 | + $goods['salePrice'] = $val['sales_price']; | ||
348 | + $goods['url'] = Helpers::getUrlBySkc($val['product_id'], $val['goods_list'][0]['goods_id'], $val['cn_alphabet']);; | ||
349 | + if ($k == $val['product_skn']) { | ||
350 | + $goods['thumb'] = Images::getImageUrl($v,235,314); | ||
351 | + $result[] = $goods; | ||
352 | + } | ||
353 | + } | ||
354 | + } | ||
355 | + | ||
356 | + return $result; | ||
357 | + } | ||
358 | + | ||
359 | +} | ||
360 | + |
-
Please register or login to post a comment