Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy.git into develop
Showing
6 changed files
with
1903 additions
and
2057 deletions
Too many changes to show.
To preserve performance only 6 of 6+ files are displayed.
@@ -29,7 +29,7 @@ class SearchData | @@ -29,7 +29,7 @@ class SearchData | ||
29 | defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer'); | 29 | defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer'); |
30 | switch (APPLICATION_ENV) { | 30 | switch (APPLICATION_ENV) { |
31 | case 'release': | 31 | case 'release': |
32 | - return 'http://100.98.132.63/yohosearch/search.json'; //return 'http://101.201.178.220/yohosearch/search.json'; | 32 | + return 'http://101.201.178.220/yohosearch/search.json'; //return 'http://100.98.132.63/yohosearch/search.json'; |
33 | case 'preview': | 33 | case 'preview': |
34 | return 'http://101.200.31.165/yohosearch/search.json'; | 34 | return 'http://101.200.31.165/yohosearch/search.json'; |
35 | case 'test': | 35 | case 'test': |
@@ -155,10 +155,7 @@ class SearchData | @@ -155,10 +155,7 @@ class SearchData | ||
155 | if (!isset($condition['page'])) { | 155 | if (!isset($condition['page'])) { |
156 | $param['page'] = 1; | 156 | $param['page'] = 1; |
157 | } | 157 | } |
158 | - | ||
159 | - if(isset($condition['viewNum'])) { | ||
160 | - $param['viewNum'] = $condition['viewNum']; | ||
161 | - } else if (!isset($condition['limit'])) { | 158 | + if (!isset($condition['limit'])) { |
162 | $param['viewNum'] = 60; | 159 | $param['viewNum'] = 60; |
163 | } else { | 160 | } else { |
164 | $param['viewNum'] = $condition['limit']; | 161 | $param['viewNum'] = $condition['limit']; |
1 | -<?php | ||
2 | - | ||
3 | -namespace Plugin; | ||
4 | - | ||
5 | -use Hood\Cache as HoodCache; | ||
6 | - | ||
7 | -/** | ||
8 | - * 数据缓存的操作类 | ||
9 | - * | ||
10 | - * @name Cache | ||
11 | - * @package Plugin | ||
12 | - * @copyright yoho.inc | ||
13 | - * @version 1.0 (2015-10-10 11:23:47) | ||
14 | - * @author fei.hong <fei.hong@yoho.cn> | ||
15 | - */ | ||
16 | -class Cache | ||
17 | -{ | ||
18 | - | ||
19 | - /** | ||
20 | - * 设置缓存 | ||
21 | - * | ||
22 | - * 备注: | ||
23 | - * 采用主从分布式缓存 | ||
24 | - * master 代表主缓存服务器 | ||
25 | - * slave 代表从缓存服务器 | ||
26 | - * | ||
27 | - * 作用: | ||
28 | - * 在后端的服务异常挂掉了并且主服务器缓存(master)的数据时间到期后, | ||
29 | - * 能获取从服务器缓存(slave)的数据,不影响前端页面的正常访问. | ||
30 | - * | ||
31 | - * @param string $key 键名 | ||
32 | - * @param mixed $value 需要缓存的数据 | ||
33 | - * @param int $expire 缓存有效期(单位秒, 0表示永久) | ||
34 | - * @return void | ||
35 | - */ | ||
36 | - public static function set($key, $value, $expire = 3600) | ||
37 | - { | ||
38 | - if(USE_CACHE) { | ||
39 | - try { | ||
40 | - // WINDOWS | ||
41 | - if (DIRECTORY_SEPARATOR === '\\') { | ||
42 | - HoodCache::Memcache('master')->set(self::makeKey($key, 'master'), $value, $expire); | ||
43 | - HoodCache::Memcache('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天 | ||
44 | - } | ||
45 | - // LINUX | ||
46 | - else { | ||
47 | - HoodCache::Memcached('master')->set(self::makeKey($key, 'master'), $value, $expire); | ||
48 | - HoodCache::Memcached('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天 | ||
49 | - } | ||
50 | - } catch (Exception $e) { | ||
51 | - // do nothing | ||
52 | - } | ||
53 | - } | ||
54 | - } | ||
55 | - | ||
56 | - /** | ||
57 | - * 获取缓存 | ||
58 | - * | ||
59 | - * @param string $key 键名 | ||
60 | - * @param string $node master代表主服务器, slave代表从服务器 | ||
61 | - * @return mixed | ||
62 | - */ | ||
63 | - public static function get($key, $node = 'master') | ||
64 | - { | ||
65 | - $result = array(); | ||
66 | - if(USE_CACHE) { | ||
67 | - try { | ||
68 | - // WINDOWS | ||
69 | - if (DIRECTORY_SEPARATOR === '\\') { | ||
70 | - $result = HoodCache::Memcache($node)->get(self::makeKey($key, $node)); | ||
71 | - } | ||
72 | - // LINUX | ||
73 | - else { | ||
74 | - $result = HoodCache::Memcached($node)->get(self::makeKey($key, $node)); | ||
75 | - } | ||
76 | - } catch (Exception $e) { | ||
77 | - $result = array(); | ||
78 | - } | ||
79 | - } | ||
80 | - return $result; | ||
81 | - } | ||
82 | - | ||
83 | - /** | ||
84 | - * 清除缓存 | ||
85 | - * | ||
86 | - * @param string $key 键名 | ||
87 | - * @return void | ||
88 | - */ | ||
89 | - public static function delete($key) | ||
90 | - { | ||
91 | - if(USE_CACHE) { | ||
92 | - // WINDOWS | ||
93 | - if (DIRECTORY_SEPARATOR === '\\') { | ||
94 | - HoodCache::Memcache('master')->delete(self::makeKey($key, 'master')); | ||
95 | - HoodCache::Memcache('slave')->delete(self::makeKey($key, 'slave')); | ||
96 | - } | ||
97 | - // LINUX | ||
98 | - else { | ||
99 | - HoodCache::Memcached('master')->delete(self::makeKey($key, 'master')); | ||
100 | - HoodCache::Memcached('slave')->delete(self::makeKey($key, 'slave')); | ||
101 | - } | ||
102 | - } | ||
103 | - } | ||
104 | - | ||
105 | - /** | ||
106 | - * 生成键名 | ||
107 | - * | ||
108 | - * @param string $key 键名 | ||
109 | - * @param string $prefix 前缀标识 | ||
110 | - * @return string | ||
111 | - */ | ||
112 | - public static function makeKey($key, $prefix) | ||
113 | - { | ||
114 | - return md5($prefix . '_' . $key); | ||
115 | - } | ||
116 | - | ||
117 | - /** | ||
118 | - * 累加 | ||
119 | - * | ||
120 | - * @param string $key | ||
121 | - * @param int $offset | ||
122 | - * @param int $initialValue | ||
123 | - * @param int $expiry | ||
124 | - * @return boolean | ||
125 | - */ | ||
126 | - public static function increment($key, $offset = 1, $initialValue = 0, $expiry = 0) { | ||
127 | - return self::getMemcache('master')->increment(self::makeKey($key, 'master'), $offset, $initialValue, $expiry); | ||
128 | - } | ||
129 | - | ||
130 | - /** | ||
131 | - * 递减 | ||
132 | - * | ||
133 | - * @param string $key | ||
134 | - * @param int $offset | ||
135 | - * @return boolean | ||
136 | - */ | ||
137 | - public static function decrement($key, $offset = 1) { | ||
138 | - return self::getMemcache('master')->decrement(self::makeKey($key, 'master'), $offset); | ||
139 | - } | ||
140 | - | ||
141 | - /** | ||
142 | - * 获取memcache | ||
143 | - * | ||
144 | - * @param string $host | ||
145 | - * @return object | ||
146 | - */ | ||
147 | - private static function getMemcache($host) { | ||
148 | - $cache = new \stdClass(); | ||
149 | - if (DIRECTORY_SEPARATOR === '\\') { | ||
150 | - $cache = HoodCache::Memcache($host); | ||
151 | - } | ||
152 | - else { | ||
153 | - $cache = HoodCache::Memcached($host); | ||
154 | - } | ||
155 | - return $cache; | ||
156 | - } | ||
157 | -} | 1 | +<?php |
2 | + | ||
3 | +namespace Plugin; | ||
4 | + | ||
5 | +use Hood\Cache as HoodCache; | ||
6 | + | ||
7 | +/** | ||
8 | + * 数据缓存的操作类 | ||
9 | + * | ||
10 | + * @name Cache | ||
11 | + * @package Plugin | ||
12 | + * @copyright yoho.inc | ||
13 | + * @version 1.0 (2015-10-10 11:23:47) | ||
14 | + * @author fei.hong <fei.hong@yoho.cn> | ||
15 | + */ | ||
16 | +class Cache | ||
17 | +{ | ||
18 | + | ||
19 | + /** | ||
20 | + * 设置缓存 | ||
21 | + * | ||
22 | + * 备注: | ||
23 | + * 采用主从分布式缓存 | ||
24 | + * master 代表主缓存服务器 | ||
25 | + * slave 代表从缓存服务器 | ||
26 | + * | ||
27 | + * 作用: | ||
28 | + * 在后端的服务异常挂掉了并且主服务器缓存(master)的数据时间到期后, | ||
29 | + * 能获取从服务器缓存(slave)的数据,不影响前端页面的正常访问. | ||
30 | + * | ||
31 | + * @param string $key 键名 | ||
32 | + * @param mixed $value 需要缓存的数据 | ||
33 | + * @param int $expire 缓存有效期(单位秒, 0表示永久) | ||
34 | + * @return void | ||
35 | + */ | ||
36 | + public static function set($key, $value, $expire = 3600) | ||
37 | + { | ||
38 | + try { | ||
39 | + // WINDOWS | ||
40 | + if (DIRECTORY_SEPARATOR === '\\') { | ||
41 | + HoodCache::Memcache('master')->set(self::makeKey($key, 'master'), $value, $expire); | ||
42 | + HoodCache::Memcache('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天 | ||
43 | + } | ||
44 | + // LINUX | ||
45 | + else { | ||
46 | + HoodCache::Memcached('master')->set(self::makeKey($key, 'master'), $value, $expire); | ||
47 | + HoodCache::Memcached('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天 | ||
48 | + } | ||
49 | + } catch (Exception $e) { | ||
50 | + // do nothing | ||
51 | + } | ||
52 | + } | ||
53 | + | ||
54 | + /** | ||
55 | + * 获取缓存 | ||
56 | + * | ||
57 | + * @param string $key 键名 | ||
58 | + * @param string $node master代表主服务器, slave代表从服务器 | ||
59 | + * @return mixed | ||
60 | + */ | ||
61 | + public static function get($key, $node = 'master') | ||
62 | + { | ||
63 | + $result = array(); | ||
64 | + | ||
65 | + try { | ||
66 | + // WINDOWS | ||
67 | + if (DIRECTORY_SEPARATOR === '\\') { | ||
68 | + $result = HoodCache::Memcache($node)->get(self::makeKey($key, $node)); | ||
69 | + } | ||
70 | + // LINUX | ||
71 | + else { | ||
72 | + $result = HoodCache::Memcached($node)->get(self::makeKey($key, $node)); | ||
73 | + } | ||
74 | + } catch (Exception $e) { | ||
75 | + $result = array(); | ||
76 | + } | ||
77 | + | ||
78 | + return $result; | ||
79 | + } | ||
80 | + | ||
81 | + /** | ||
82 | + * 清除缓存 | ||
83 | + * | ||
84 | + * @param string $key 键名 | ||
85 | + * @return void | ||
86 | + */ | ||
87 | + public static function delete($key) | ||
88 | + { | ||
89 | + // WINDOWS | ||
90 | + if (DIRECTORY_SEPARATOR === '\\') { | ||
91 | + HoodCache::Memcache('master')->delete(self::makeKey($key, 'master')); | ||
92 | + HoodCache::Memcache('slave')->delete(self::makeKey($key, 'slave')); | ||
93 | + } | ||
94 | + // LINUX | ||
95 | + else { | ||
96 | + HoodCache::Memcached('master')->delete(self::makeKey($key, 'master')); | ||
97 | + HoodCache::Memcached('slave')->delete(self::makeKey($key, 'slave')); | ||
98 | + } | ||
99 | + } | ||
100 | + | ||
101 | + /** | ||
102 | + * 生成键名 | ||
103 | + * | ||
104 | + * @param string $key 键名 | ||
105 | + * @param string $prefix 前缀标识 | ||
106 | + * @return string | ||
107 | + */ | ||
108 | + public static function makeKey($key, $prefix) | ||
109 | + { | ||
110 | + return md5($prefix . '_' . $key); | ||
111 | + } | ||
112 | + | ||
113 | +} |
1 | -<?php | ||
2 | - | ||
3 | -namespace Plugin\DataProcess; | ||
4 | - | ||
5 | -use Plugin\Helpers; | ||
6 | - | ||
7 | -/** | ||
8 | - * 楼层数据处理类 | ||
9 | - */ | ||
10 | -class FloorProcess | ||
11 | -{ | ||
12 | - | ||
13 | - /** | ||
14 | - * 频道参数 | ||
15 | - * | ||
16 | - * @var array | ||
17 | - */ | ||
18 | - private static $channel = array( | ||
19 | - '1' => '1,3', | ||
20 | - '2' => '2,3' | ||
21 | - ); | ||
22 | - | ||
23 | - /** | ||
24 | - * 处理首页内容 | ||
25 | - * @param $data | ||
26 | - * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
27 | - */ | ||
28 | - public static function getContent($data, $type = 1) | ||
29 | - { | ||
30 | - if (empty($data['list'])) { | ||
31 | - return array(); | ||
32 | - } | ||
33 | - | ||
34 | - $result = array(); | ||
35 | - | ||
36 | - $build = array(); | ||
37 | - foreach ($data['list'] as $v) { | ||
38 | - if (empty($v)) { | ||
39 | - continue; | ||
40 | - } | ||
41 | - | ||
42 | - $fun = $v['template_name']; | ||
43 | - if (empty($v['data']) || !is_callable("self::$fun")) { | ||
44 | - continue; | ||
45 | - } | ||
46 | - $build = self::$fun($v['data'], $type); | ||
47 | - if (empty($build)) { | ||
48 | - continue; | ||
49 | - } | ||
50 | - $result[] = $build; | ||
51 | - } | ||
52 | - $build = array(); | ||
53 | - | ||
54 | - return $result; | ||
55 | - } | ||
56 | - | ||
57 | - /** | ||
58 | - * 焦点图数据处理方法 | ||
59 | - * @param array $data 焦点图数据 | ||
60 | - * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
61 | - * @return array 处理之后的焦点图数据 | ||
62 | - */ | ||
63 | - private static function focus($data, $type) | ||
64 | - { | ||
65 | - $result = array(); | ||
66 | - | ||
67 | - foreach ($data as $one) { | ||
68 | - $result['bannerTop']['list'][] = Helpers::formatBanner($one, 640, 240); | ||
69 | - } | ||
70 | - | ||
71 | - return $result; | ||
72 | - } | ||
73 | - | ||
74 | - /** | ||
75 | - * 图标 | ||
76 | - */ | ||
77 | - private static function floor($data) | ||
78 | - { | ||
79 | - $result = array(); | ||
80 | - | ||
81 | - foreach ($data as &$one) { | ||
82 | - $one['url'] = Helpers::getFilterUrl($one['url']); | ||
83 | - $one['img'] = Helpers::getImageUrl($one['src'], 98, 98); | ||
84 | - unset($one['src']); | ||
85 | - } | ||
86 | - $result['iconsEnter']['list'] = $data; | ||
87 | - | ||
88 | - return $result; | ||
89 | - } | ||
90 | - | ||
91 | - /** | ||
92 | - * 图标列表数据处理方法 | ||
93 | - * | ||
94 | - * @param array $data 图标列表数据 | ||
95 | - * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
96 | - * @return array 处理之后的图标列表数据 | ||
97 | - */ | ||
98 | - private static function app_icon_list($data, $type) | ||
99 | - { | ||
100 | - $result = array(); | ||
101 | - | ||
102 | - foreach ($data as &$one) { | ||
103 | - $one['url'] = Helpers::getFilterUrl($one['url']); | ||
104 | - $one['img'] = Helpers::getImageUrl($one['src'], 98, 98); | ||
105 | - unset($one['src']); | ||
106 | - } | ||
107 | - $result['iconsEnter']['list'] = $data; | ||
108 | - | ||
109 | - return $result; | ||
110 | - } | ||
111 | - | ||
112 | - /** | ||
113 | - * 单广告图片数据处理方法 | ||
114 | - * | ||
115 | - * @param array $data 单图片数据 | ||
116 | - * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
117 | - * @return array 处理之后的单图片数据 | ||
118 | - */ | ||
119 | - private static function single_image($data, $type) | ||
120 | - { | ||
121 | - $result = array(); | ||
122 | - | ||
123 | - foreach ($data as &$one) { | ||
124 | - $one['url'] = Helpers::getFilterUrl($one['url']); | ||
125 | - $one['img'] = Helpers::getImageUrl($one['src'], 640, 200); | ||
126 | - unset($one['src']); | ||
127 | - } | ||
128 | - $result['banner'] = $data; | ||
129 | - | ||
130 | - return $result; | ||
131 | - } | ||
132 | - | ||
133 | - /** | ||
134 | - * 女生品类 | ||
135 | - * 推荐(1T-12F) | ||
136 | - */ | ||
137 | - private static function recommend_content_three($data, $type) | ||
138 | - { | ||
139 | - $result = array(); | ||
140 | - | ||
141 | - $build = array(); | ||
142 | - if (!empty($data['big_image'][0])) { | ||
143 | - $build['img'] = Helpers::getImageUrl($data['big_image'][0]['src'], 640, 200); | ||
144 | - $build['url'] = Helpers::getFilterUrl($data['big_image'][0]['url']); | ||
145 | - $result['hotCategory']['banner'] = $build; | ||
146 | - } | ||
147 | - | ||
148 | - $build = array(); | ||
149 | - foreach ($data['list'] as $one) { | ||
150 | - $build['url'] = Helpers::getFilterUrl($one['url']); | ||
151 | - $build['img'] = Helpers::getImageUrl($one['src'], 128, 140); | ||
152 | - $build['textCn'] = $one['title']; | ||
153 | - $result['hotCategory']['list'][] = $build; | ||
154 | - } | ||
155 | - | ||
156 | - if (isset($data['title']['more_url'])) { | ||
157 | - $data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']); | ||
158 | - } | ||
159 | - | ||
160 | - return $result; | ||
161 | - } | ||
162 | - | ||
163 | - /** | ||
164 | - * 带标题的12个小图推荐数据处理方法 | ||
165 | - * | ||
166 | - * @param array $data 带标题的12个小图推荐数据 | ||
167 | - * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
168 | - * @return array 处理之后的带标题的12个小图推荐数据 | ||
169 | - */ | ||
170 | - private static function recommend_content_five($data, $type) | ||
171 | - { | ||
172 | - $result = array(); | ||
173 | - | ||
174 | - foreach ($data['list'] as &$one) { | ||
175 | - if (isset($one['url'])) { | ||
176 | - $one['url'] = Helpers::getFilterUrl($one['url']); | ||
177 | - } | ||
178 | - $one['img'] = Helpers::getImageUrl($one['src'], 140, 140); | ||
179 | - $one['textCn'] = $one['title']; | ||
180 | - unset($one['src']); | ||
181 | - } | ||
182 | - $data['is_show_name'] = $data['title']['is_show']; | ||
183 | - $data['name'] = $data['title']['title']; | ||
184 | - unset($data['title']); | ||
185 | - | ||
186 | - if (isset($data['title']['more_url'])) { | ||
187 | - $data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']); | ||
188 | - } | ||
189 | - | ||
190 | - $result['hotCategory'] = $data; | ||
191 | - | ||
192 | - return $result; | ||
193 | - } | ||
194 | - | ||
195 | - /** | ||
196 | - * 推荐品牌数据处理方法 | ||
197 | - * @param array $data 推荐品牌数据 | ||
198 | - * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
199 | - * @return array 处理之后的推荐品牌数据 | ||
200 | - */ | ||
201 | - private static function app_hot_brands($data, $type) | ||
202 | - { | ||
203 | - $result = array(); | ||
204 | - | ||
205 | - $data['is_show_name'] = (isset($data['is_show_name']) && $data['is_show_name'] === 'Y') ? 1 : 0; | ||
206 | - $data['name'] = $data['title']['title']; | ||
207 | - unset($data['title']); | ||
208 | - foreach ($data['list'] as &$one) { | ||
209 | - if (isset($one['url'])) { | ||
210 | - $one['url'] = Helpers::getFilterUrl($one['url']); | ||
211 | -// isset(self::$channel[$type]) && $one['url'] .= '?gender=' . self::$channel[$type]; | ||
212 | - } | ||
213 | - $one['img'] = Helpers::getImageUrl($one['src'], 158, 174); | ||
214 | - unset($one['src']); | ||
215 | - } | ||
216 | - $data['more'] = '/brands?channel=' . $type; | ||
217 | - $result['hotBrands'] = $data; | ||
218 | - | ||
219 | - return $result; | ||
220 | - } | ||
221 | - | ||
222 | - /** | ||
223 | - * 潮人·搭配数据处理方法 | ||
224 | - * @param array $data 潮人·搭配数据 | ||
225 | - * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
226 | - * @return array 处理之后的潮人·搭配数据 | ||
227 | - */ | ||
228 | - private static function trendsetter_collocation($data, $type) | ||
229 | - { | ||
230 | - $result = array(); | ||
231 | - | ||
232 | - foreach ($data as $key => &$value) { | ||
233 | - if ($key == 'title') { | ||
234 | - $value['more_url'] = Helpers::url('', array('id' => 3, 'gender' => self::$channel[$type]), 'guang'); | ||
235 | - } | ||
236 | - if ($key == 'article') { | ||
237 | - foreach ($value as &$one) { | ||
238 | - if (isset($one['url'])) { | ||
239 | - $one['url'] = Helpers::getFilterUrl($one['url']); | ||
240 | - } | ||
241 | - $one['img'] = Helpers::getImageUrl($one['src'], 400, 400); | ||
242 | - unset($one['src']); | ||
243 | - } | ||
244 | - } | ||
245 | - if ($key == 'recommend_collocation') { | ||
246 | - foreach ($value as &$one) { | ||
247 | - if (isset($one['url'])) { | ||
248 | - $one['url'] = Helpers::getFilterUrl($one['url']); | ||
249 | - } | ||
250 | - $one['img'] = Helpers::getImageUrl($one['src'], 140, 140); | ||
251 | - unset($one['src']); | ||
252 | - } | ||
253 | - } | ||
254 | - } | ||
255 | - $result['trendColloaction'] = $data; | ||
256 | - | ||
257 | - return $result; | ||
258 | - } | ||
259 | - | ||
260 | - /** | ||
261 | - * 潮品·话题数据处理方法 | ||
262 | - * @param array $data 潮品·话题数据 | ||
263 | - * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
264 | - * @return array 处理之后的潮品·话题数据 | ||
265 | - */ | ||
266 | - private static function trendgoods_topic($data, $type) | ||
267 | - { | ||
268 | - $result = array(); | ||
269 | - | ||
270 | - foreach ($data as $key => &$value) { | ||
271 | - if ($key == 'title') { | ||
272 | - $urlParam = array('id' => 4); | ||
273 | - isset(self::$channel[$type]) && $urlParam['gender'] = self::$channel[$type]; | ||
274 | - $value['more_url'] = Helpers::url('', $urlParam, 'guang'); | ||
275 | - } | ||
276 | - if ($key == 'list' && is_array($value)) { | ||
277 | - foreach ($value as &$one) { | ||
278 | - if (isset($one['url'])) { | ||
279 | - $one['url'] = Helpers::getFilterUrl($one['url']); | ||
280 | - } | ||
281 | - $one['img'] = Helpers::getImageUrl($one['src'], 580, 360); | ||
282 | - unset($one['src']); | ||
283 | - } | ||
284 | - } | ||
285 | - } | ||
286 | - $result['trendTopics'] = $data; | ||
287 | - | ||
288 | - return $result; | ||
289 | - } | ||
290 | - | ||
291 | - /** | ||
292 | - * 一张大图一个大的推荐和4个小图推荐数据处理方法 | ||
293 | - * @param array $data 一张大图一个大的推荐和4个小图推荐数据 | ||
294 | - * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
295 | - * @return array 处理之后的一张大图一个大的推荐和4个小图推荐数据 | ||
296 | - */ | ||
297 | - private static function recommend_content_one($data, $type) | ||
298 | - { | ||
299 | - $result = array(); | ||
300 | - | ||
301 | - foreach ($data['big_image'] as &$one) { | ||
302 | - if (isset($one['url'])) { | ||
303 | - $one['url'] = Helpers::getFilterUrl($one['url']); | ||
304 | - } | ||
305 | - $one['img'] = Helpers::getImageUrl($one['src'], 640, 403); | ||
306 | - unset($one['src']); | ||
307 | - } | ||
308 | - | ||
309 | - // 区别多张图与一张图 | ||
310 | - if (count($data['big_image']) > 1) { | ||
311 | - $result['big_image']['big_list'] = $data['big_image']; | ||
312 | - unset($data['big_image']); | ||
313 | - } | ||
314 | - | ||
315 | - foreach ($data['list'] as $kk => &$one) { | ||
316 | - if ($kk == 0) { | ||
317 | - $one['img'] = Helpers::getImageUrl($one['src'], 253, 383); | ||
318 | - } else { | ||
319 | - $one['img'] = Helpers::getImageUrl($one['src'], 191, 191); | ||
320 | - } | ||
321 | - if (isset($one['url'])) { | ||
322 | - $one['url'] = Helpers::getFilterUrl($one['url']); | ||
323 | - } | ||
324 | - $one['textCn'] = $one['title']; | ||
325 | - | ||
326 | - unset($one['src']); | ||
327 | - } | ||
328 | - | ||
329 | - if (isset($data['title']['more_url'])) { | ||
330 | - $data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']); | ||
331 | - } | ||
332 | - | ||
333 | - $result['goodsCategory'] = $data; | ||
334 | - | ||
335 | - return $result; | ||
336 | - } | ||
337 | - | ||
338 | - /** | ||
339 | - * 一张大图和6个小图推荐数据处理方法 | ||
340 | - * @param array $data 一张大图和6个小图推荐数据 | ||
341 | - * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
342 | - * @return array 处理之后的一张大图和6个小图推荐数据 | ||
343 | - */ | ||
344 | - private static function recommend_content_two($data, $type) | ||
345 | - { | ||
346 | - $result = array(); | ||
347 | - | ||
348 | - foreach ($data['big_image'] as &$one) { | ||
349 | - if (isset($one['url'])) { | ||
350 | - $one['url'] = Helpers::getFilterUrl($one['url']); | ||
351 | - } | ||
352 | - $one['img'] = Helpers::getImageUrl($one['src'], 640, 403); | ||
353 | - unset($one['src']); | ||
354 | - } | ||
355 | - $data['banner'] = $data['big_image']; | ||
356 | - unset($data['big_image']); | ||
357 | - | ||
358 | - foreach ($data['list'] as &$one) { | ||
359 | - if (isset($one['url'])) { | ||
360 | - $one['url'] = Helpers::getFilterUrl($one['url']); | ||
361 | - } | ||
362 | - $one['img'] = Helpers::getImageUrl($one['src'], 191, 191); | ||
363 | - unset($one['src']); | ||
364 | - } | ||
365 | - | ||
366 | - if (isset($data['title']['more_url'])) { | ||
367 | - $data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']); | ||
368 | - } | ||
369 | - $result['creativeLife'] = $data; | ||
370 | - | ||
371 | - return $result; | ||
372 | - } | ||
373 | - | ||
374 | - /** | ||
375 | - * 小图片数据处理方法 | ||
376 | - * @param array $data 小图片数据 | ||
377 | - * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
378 | - * @return array 处理之后的小图片数据 | ||
379 | - */ | ||
380 | - private static function small_pic($data, $type) | ||
381 | - { | ||
382 | - $result = array(); | ||
383 | - | ||
384 | - foreach ($data as &$one) { | ||
385 | - if (isset($one['url'])) { | ||
386 | - $one['url'] = Helpers::getFilterUrl($one['url']); | ||
387 | - } | ||
388 | - $one['img'] = Helpers::getImageUrl($one['src'], 275, 160); | ||
389 | - unset($one['src']); | ||
390 | - } | ||
391 | - if (!empty($data)) { | ||
392 | - $result['smallPic']['list'] = $data; | ||
393 | - } | ||
394 | - | ||
395 | - return $result; | ||
396 | - } | ||
397 | - | ||
398 | - /** | ||
399 | - * plus,star | ||
400 | - * @param array $data 单名字图片数据 | ||
401 | - * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
402 | - * @return array 处理之后的单名字图片数据 | ||
403 | - */ | ||
404 | - private static function single_name_image($data, $type) | ||
405 | - { | ||
406 | - if (empty($data)) { | ||
407 | - return array(); | ||
408 | - } | ||
409 | - | ||
410 | - $data['name'] = $data['title']; | ||
411 | - $data['img'] = Helpers::getImageUrl($data['src'], 640, 198); | ||
412 | - if (isset($data['url'])) { | ||
413 | - $data['url'] = Helpers::getFilterUrl($data['url']); | ||
414 | - } | ||
415 | - | ||
416 | - return array('plusStar' => $data); | ||
417 | - } | ||
418 | - | ||
419 | - /** | ||
420 | - * 自定义品牌 | ||
421 | - * | ||
422 | - * @param unknown $data | ||
423 | - * @param mixed $type | ||
424 | - * @return multitype: | ||
425 | - */ | ||
426 | - private static function custom_brands($data, $type) | ||
427 | - { | ||
428 | - // URL附加参数 | ||
429 | - $param = ''; | ||
430 | - /*if (isset(self::$channel[$type])) { | ||
431 | - $param = '/?gender=' . self::$channel[$type]; | ||
432 | - }*/ | ||
433 | - | ||
434 | - $result = array(); | ||
435 | - $result['hotBrandsScroll']['name'] = $data['title']['title']; | ||
436 | - foreach ($data['list'] as &$one) { | ||
437 | - if (isset($one['url'])) { | ||
438 | - $one['url'] = Helpers::getFilterUrl($one['url']); | ||
439 | - } | ||
440 | - $one['img'] = Helpers::getImageUrl($one['src'], 140, 140); | ||
441 | - $one['textCn'] = $one['name']; | ||
442 | - if (isset($one['url'])) { | ||
443 | - $one['url'] .= $param; | ||
444 | - } | ||
445 | - } | ||
446 | - if (!empty($data['is_show_name']) && $data['is_show_name'] == 'Y') { | ||
447 | - $result['hotBrandsScroll']['is_show_name'] = true; | ||
448 | - } | ||
449 | - $result['hotBrandsScroll']['list'] = $data['list']; | ||
450 | - | ||
451 | - return $result; | ||
452 | - } | ||
453 | - | ||
454 | -} | 1 | +<?php |
2 | + | ||
3 | +namespace Plugin\DataProcess; | ||
4 | + | ||
5 | +use Plugin\Helpers; | ||
6 | + | ||
7 | +/** | ||
8 | + * 楼层数据处理类 | ||
9 | + */ | ||
10 | +class FloorProcess | ||
11 | +{ | ||
12 | + | ||
13 | + /** | ||
14 | + * 频道参数 | ||
15 | + * | ||
16 | + * @var array | ||
17 | + */ | ||
18 | + private static $channel = array( | ||
19 | + '1' => '1,3', | ||
20 | + '2' => '2,3' | ||
21 | + ); | ||
22 | + | ||
23 | + /** | ||
24 | + * 处理首页内容 | ||
25 | + * @param $data | ||
26 | + * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
27 | + */ | ||
28 | + public static function getContent($data, $type = 1) | ||
29 | + { | ||
30 | + if (empty($data['list'])) { | ||
31 | + return array(); | ||
32 | + } | ||
33 | + | ||
34 | + $result = array(); | ||
35 | + | ||
36 | + $build = array(); | ||
37 | + foreach ($data['list'] as $v) { | ||
38 | + if (empty($v)) { | ||
39 | + continue; | ||
40 | + } | ||
41 | + | ||
42 | + $fun = $v['template_name']; | ||
43 | + if (empty($v['data']) || !is_callable("self::$fun")) { | ||
44 | + continue; | ||
45 | + } | ||
46 | + $build = self::$fun($v['data'], $type); | ||
47 | + if (empty($build)) { | ||
48 | + continue; | ||
49 | + } | ||
50 | + $result[] = $build; | ||
51 | + } | ||
52 | + $build = array(); | ||
53 | + | ||
54 | + return $result; | ||
55 | + } | ||
56 | + | ||
57 | + /** | ||
58 | + * 焦点图数据处理方法 | ||
59 | + * @param array $data 焦点图数据 | ||
60 | + * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
61 | + * @return array 处理之后的焦点图数据 | ||
62 | + */ | ||
63 | + private static function focus($data, $type) | ||
64 | + { | ||
65 | + $result = array(); | ||
66 | + | ||
67 | + foreach ($data as $one) { | ||
68 | + $result['bannerTop']['list'][] = Helpers::formatBanner($one, 640, 240); | ||
69 | + } | ||
70 | + | ||
71 | + return $result; | ||
72 | + } | ||
73 | + | ||
74 | + /** | ||
75 | + * 图标 | ||
76 | + */ | ||
77 | + private static function floor($data) | ||
78 | + { | ||
79 | + $result = array(); | ||
80 | + | ||
81 | + foreach ($data as &$one) { | ||
82 | + $one['url'] = Helpers::getFilterUrl($one['url']); | ||
83 | + $one['img'] = Helpers::getImageUrl($one['src'], 98, 98); | ||
84 | + unset($one['src']); | ||
85 | + } | ||
86 | + $result['iconsEnter']['list'] = $data; | ||
87 | + | ||
88 | + return $result; | ||
89 | + } | ||
90 | + | ||
91 | + /** | ||
92 | + * 图标列表数据处理方法 | ||
93 | + * | ||
94 | + * @param array $data 图标列表数据 | ||
95 | + * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
96 | + * @return array 处理之后的图标列表数据 | ||
97 | + */ | ||
98 | + private static function app_icon_list($data, $type) | ||
99 | + { | ||
100 | + $result = array(); | ||
101 | + | ||
102 | + foreach ($data as &$one) { | ||
103 | + $one['url'] = Helpers::getFilterUrl($one['url']); | ||
104 | + $one['img'] = Helpers::getImageUrl($one['src'], 98, 98); | ||
105 | + unset($one['src']); | ||
106 | + } | ||
107 | + $result['iconsEnter']['list'] = $data; | ||
108 | + | ||
109 | + return $result; | ||
110 | + } | ||
111 | + | ||
112 | + /** | ||
113 | + * 单广告图片数据处理方法 | ||
114 | + * | ||
115 | + * @param array $data 单图片数据 | ||
116 | + * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
117 | + * @return array 处理之后的单图片数据 | ||
118 | + */ | ||
119 | + private static function single_image($data, $type) | ||
120 | + { | ||
121 | + $result = array(); | ||
122 | + | ||
123 | + foreach ($data as &$one) { | ||
124 | + $one['url'] = Helpers::getFilterUrl($one['url']); | ||
125 | + $one['img'] = Helpers::getImageUrl($one['src'], 640, 200); | ||
126 | + unset($one['src']); | ||
127 | + } | ||
128 | + $result['banner'] = $data; | ||
129 | + | ||
130 | + return $result; | ||
131 | + } | ||
132 | + | ||
133 | + /** | ||
134 | + * 女生品类 | ||
135 | + * 推荐(1T-12F) | ||
136 | + */ | ||
137 | + private static function recommend_content_three($data, $type) | ||
138 | + { | ||
139 | + $result = array(); | ||
140 | + | ||
141 | + $build = array(); | ||
142 | + if (!empty($data['big_image'][0])) { | ||
143 | + $build['img'] = Helpers::getImageUrl($data['big_image'][0]['src'], 640, 200); | ||
144 | + $build['url'] = Helpers::getFilterUrl($data['big_image'][0]['url']); | ||
145 | + $result['hotCategory']['banner'] = $build; | ||
146 | + } | ||
147 | + | ||
148 | + $build = array(); | ||
149 | + foreach ($data['list'] as $one) { | ||
150 | + $build['url'] = Helpers::getFilterUrl($one['url']); | ||
151 | + $build['img'] = Helpers::getImageUrl($one['src'], 128, 140); | ||
152 | + $build['textCn'] = $one['title']; | ||
153 | + $result['hotCategory']['list'][] = $build; | ||
154 | + } | ||
155 | + | ||
156 | + if (isset($data['title']['more_url'])) { | ||
157 | + $data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']); | ||
158 | + } | ||
159 | + | ||
160 | + return $result; | ||
161 | + } | ||
162 | + | ||
163 | + /** | ||
164 | + * 带标题的12个小图推荐数据处理方法 | ||
165 | + * | ||
166 | + * @param array $data 带标题的12个小图推荐数据 | ||
167 | + * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
168 | + * @return array 处理之后的带标题的12个小图推荐数据 | ||
169 | + */ | ||
170 | + private static function recommend_content_five($data, $type) | ||
171 | + { | ||
172 | + $result = array(); | ||
173 | + | ||
174 | + foreach ($data['list'] as &$one) { | ||
175 | + if (isset($one['url'])) { | ||
176 | + $one['url'] = Helpers::getFilterUrl($one['url']); | ||
177 | + } | ||
178 | + $one['img'] = Helpers::getImageUrl($one['src'], 140, 140); | ||
179 | + $one['textCn'] = $one['title']; | ||
180 | + unset($one['src']); | ||
181 | + } | ||
182 | + $data['is_show_name'] = $data['title']['is_show']; | ||
183 | + $data['name'] = $data['title']['title']; | ||
184 | + unset($data['title']); | ||
185 | + | ||
186 | + if (isset($data['title']['more_url'])) { | ||
187 | + $data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']); | ||
188 | + } | ||
189 | + | ||
190 | + $result['hotCategory'] = $data; | ||
191 | + | ||
192 | + return $result; | ||
193 | + } | ||
194 | + | ||
195 | + /** | ||
196 | + * 推荐品牌数据处理方法 | ||
197 | + * @param array $data 推荐品牌数据 | ||
198 | + * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
199 | + * @return array 处理之后的推荐品牌数据 | ||
200 | + */ | ||
201 | + private static function app_hot_brands($data, $type) | ||
202 | + { | ||
203 | + $result = array(); | ||
204 | + | ||
205 | + $data['is_show_name'] = (isset($data['is_show_name']) && $data['is_show_name'] === 'Y') ? 1 : 0; | ||
206 | + $data['name'] = $data['title']['title']; | ||
207 | + unset($data['title']); | ||
208 | + foreach ($data['list'] as &$one) { | ||
209 | + if (isset($one['url'])) { | ||
210 | + $one['url'] = Helpers::getFilterUrl($one['url']); | ||
211 | + isset(self::$channel[$type]) && $one['url'] .= '?gender=' . self::$channel[$type]; | ||
212 | + } | ||
213 | + $one['img'] = Helpers::getImageUrl($one['src'], 158, 174); | ||
214 | + unset($one['src']); | ||
215 | + } | ||
216 | + $data['more'] = '/brands?channel=' . $type; | ||
217 | + $result['hotBrands'] = $data; | ||
218 | + | ||
219 | + return $result; | ||
220 | + } | ||
221 | + | ||
222 | + /** | ||
223 | + * 潮人·搭配数据处理方法 | ||
224 | + * @param array $data 潮人·搭配数据 | ||
225 | + * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
226 | + * @return array 处理之后的潮人·搭配数据 | ||
227 | + */ | ||
228 | + private static function trendsetter_collocation($data, $type) | ||
229 | + { | ||
230 | + $result = array(); | ||
231 | + | ||
232 | + foreach ($data as $key => &$value) { | ||
233 | + if ($key == 'title') { | ||
234 | + $value['more_url'] = Helpers::url('', array('id' => 3, 'gender' => self::$channel[$type]), 'guang'); | ||
235 | + } | ||
236 | + if ($key == 'article') { | ||
237 | + foreach ($value as &$one) { | ||
238 | + if (isset($one['url'])) { | ||
239 | + $one['url'] = Helpers::getFilterUrl($one['url']); | ||
240 | + } | ||
241 | + $one['img'] = Helpers::getImageUrl($one['src'], 400, 400); | ||
242 | + unset($one['src']); | ||
243 | + } | ||
244 | + } | ||
245 | + if ($key == 'recommend_collocation') { | ||
246 | + foreach ($value as &$one) { | ||
247 | + if (isset($one['url'])) { | ||
248 | + $one['url'] = Helpers::getFilterUrl($one['url']); | ||
249 | + } | ||
250 | + $one['img'] = Helpers::getImageUrl($one['src'], 140, 140); | ||
251 | + unset($one['src']); | ||
252 | + } | ||
253 | + } | ||
254 | + } | ||
255 | + $result['trendColloaction'] = $data; | ||
256 | + | ||
257 | + return $result; | ||
258 | + } | ||
259 | + | ||
260 | + /** | ||
261 | + * 潮品·话题数据处理方法 | ||
262 | + * @param array $data 潮品·话题数据 | ||
263 | + * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
264 | + * @return array 处理之后的潮品·话题数据 | ||
265 | + */ | ||
266 | + private static function trendgoods_topic($data, $type) | ||
267 | + { | ||
268 | + $result = array(); | ||
269 | + | ||
270 | + foreach ($data as $key => &$value) { | ||
271 | + if ($key == 'title') { | ||
272 | + $urlParam = array('id' => 4); | ||
273 | + isset(self::$channel[$type]) && $urlParam['gender'] = self::$channel[$type]; | ||
274 | + $value['more_url'] = Helpers::url('', $urlParam, 'guang'); | ||
275 | + } | ||
276 | + if ($key == 'list') { | ||
277 | + foreach ($value as &$one) { | ||
278 | + if (isset($one['url'])) { | ||
279 | + $one['url'] = Helpers::getFilterUrl($one['url']); | ||
280 | + } | ||
281 | + $one['img'] = Helpers::getImageUrl($one['src'], 580, 360); | ||
282 | + unset($one['src']); | ||
283 | + } | ||
284 | + } | ||
285 | + } | ||
286 | + $result['trendTopics'] = $data; | ||
287 | + | ||
288 | + return $result; | ||
289 | + } | ||
290 | + | ||
291 | + /** | ||
292 | + * 一张大图一个大的推荐和4个小图推荐数据处理方法 | ||
293 | + * @param array $data 一张大图一个大的推荐和4个小图推荐数据 | ||
294 | + * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
295 | + * @return array 处理之后的一张大图一个大的推荐和4个小图推荐数据 | ||
296 | + */ | ||
297 | + private static function recommend_content_one($data, $type) | ||
298 | + { | ||
299 | + $result = array(); | ||
300 | + | ||
301 | + foreach ($data['big_image'] as &$one) { | ||
302 | + if (isset($one['url'])) { | ||
303 | + $one['url'] = Helpers::getFilterUrl($one['url']); | ||
304 | + } | ||
305 | + $one['img'] = Helpers::getImageUrl($one['src'], 640, 403); | ||
306 | + unset($one['src']); | ||
307 | + } | ||
308 | + | ||
309 | + // 区别多张图与一张图 | ||
310 | + if (count($data['big_image']) > 1) { | ||
311 | + $result['big_image']['big_list'] = $data['big_image']; | ||
312 | + unset($data['big_image']); | ||
313 | + } | ||
314 | + | ||
315 | + foreach ($data['list'] as $kk => &$one) { | ||
316 | + if ($kk == 0) { | ||
317 | + $one['img'] = Helpers::getImageUrl($one['src'], 253, 383); | ||
318 | + } else { | ||
319 | + $one['img'] = Helpers::getImageUrl($one['src'], 191, 191); | ||
320 | + } | ||
321 | + if (isset($one['url'])) { | ||
322 | + $one['url'] = Helpers::getFilterUrl($one['url']); | ||
323 | + } | ||
324 | + $one['textCn'] = $one['title']; | ||
325 | + | ||
326 | + unset($one['src']); | ||
327 | + } | ||
328 | + | ||
329 | + if (isset($data['title']['more_url'])) { | ||
330 | + $data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']); | ||
331 | + } | ||
332 | + | ||
333 | + $result['goodsCategory'] = $data; | ||
334 | + | ||
335 | + return $result; | ||
336 | + } | ||
337 | + | ||
338 | + /** | ||
339 | + * 一张大图和6个小图推荐数据处理方法 | ||
340 | + * @param array $data 一张大图和6个小图推荐数据 | ||
341 | + * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
342 | + * @return array 处理之后的一张大图和6个小图推荐数据 | ||
343 | + */ | ||
344 | + private static function recommend_content_two($data, $type) | ||
345 | + { | ||
346 | + $result = array(); | ||
347 | + | ||
348 | + foreach ($data['big_image'] as &$one) { | ||
349 | + if (isset($one['url'])) { | ||
350 | + $one['url'] = Helpers::getFilterUrl($one['url']); | ||
351 | + } | ||
352 | + $one['img'] = Helpers::getImageUrl($one['src'], 640, 403); | ||
353 | + unset($one['src']); | ||
354 | + } | ||
355 | + $data['banner'] = $data['big_image']; | ||
356 | + unset($data['big_image']); | ||
357 | + | ||
358 | + foreach ($data['list'] as &$one) { | ||
359 | + if (isset($one['url'])) { | ||
360 | + $one['url'] = Helpers::getFilterUrl($one['url']); | ||
361 | + } | ||
362 | + $one['img'] = Helpers::getImageUrl($one['src'], 191, 191); | ||
363 | + unset($one['src']); | ||
364 | + } | ||
365 | + | ||
366 | + if (isset($data['title']['more_url'])) { | ||
367 | + $data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']); | ||
368 | + } | ||
369 | + $result['creativeLife'] = $data; | ||
370 | + | ||
371 | + return $result; | ||
372 | + } | ||
373 | + | ||
374 | + /** | ||
375 | + * 小图片数据处理方法 | ||
376 | + * @param array $data 小图片数据 | ||
377 | + * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
378 | + * @return array 处理之后的小图片数据 | ||
379 | + */ | ||
380 | + private static function small_pic($data, $type) | ||
381 | + { | ||
382 | + // 按照以前业务操作,不显示 | ||
383 | + return array(); | ||
384 | + | ||
385 | + $result = array(); | ||
386 | + | ||
387 | + foreach ($data as &$one) { | ||
388 | + if (isset($one['url'])) { | ||
389 | + $one['url'] = Helpers::getFilterUrl($one['url']); | ||
390 | + } | ||
391 | + $one['img'] = Helpers::getImageUrl($one['src'], 98, 98); | ||
392 | + unset($one['src']); | ||
393 | + } | ||
394 | + $result['small_pic'] = $data; | ||
395 | + | ||
396 | + return $result; | ||
397 | + } | ||
398 | + | ||
399 | + /** | ||
400 | + * plus,star | ||
401 | + * @param array $data 单名字图片数据 | ||
402 | + * @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle | ||
403 | + * @return array 处理之后的单名字图片数据 | ||
404 | + */ | ||
405 | + private static function single_name_image($data, $type) | ||
406 | + { | ||
407 | + if (empty($data)) { | ||
408 | + return array(); | ||
409 | + } | ||
410 | + | ||
411 | + $data['name'] = $data['title']; | ||
412 | + $data['img'] = Helpers::getImageUrl($data['src'], 640, 198); | ||
413 | + if (isset($data['url'])) { | ||
414 | + $data['url'] = Helpers::getFilterUrl($data['url']); | ||
415 | + } | ||
416 | + | ||
417 | + return array('plusStar' => $data); | ||
418 | + } | ||
419 | + | ||
420 | + /** | ||
421 | + * 自定义品牌 | ||
422 | + * | ||
423 | + * @param unknown $data | ||
424 | + * @param mixed $type | ||
425 | + * @return multitype: | ||
426 | + */ | ||
427 | + private static function custom_brands($data, $type) | ||
428 | + { | ||
429 | + // URL附加参数 | ||
430 | + $param = ''; | ||
431 | + if (isset(self::$channel[$type])) { | ||
432 | + $param = '/?gender=' . self::$channel[$type]; | ||
433 | + } | ||
434 | + | ||
435 | + $result = array(); | ||
436 | + $result['hotBrandsScroll']['name'] = $data['title']['title']; | ||
437 | + foreach ($data['list'] as &$one) { | ||
438 | + if (isset($one['url'])) { | ||
439 | + $one['url'] = Helpers::getFilterUrl($one['url']); | ||
440 | + } | ||
441 | + $one['img'] = Helpers::getImageUrl($one['src'], 140, 140); | ||
442 | + $one['textCn'] = $one['name']; | ||
443 | + if (isset($one['url'])) { | ||
444 | + $one['url'] .= $param; | ||
445 | + } | ||
446 | + } | ||
447 | + if (!empty($data['is_show_name']) && $data['is_show_name'] == 'Y') { | ||
448 | + $result['hotBrandsScroll']['is_show_name'] = true; | ||
449 | + } | ||
450 | + $result['hotBrandsScroll']['list'] = $data['list']; | ||
451 | + | ||
452 | + return $result; | ||
453 | + } | ||
454 | + | ||
455 | +} |
1 | -<?php | ||
2 | - | ||
3 | -namespace Plugin\DataProcess; | ||
4 | - | ||
5 | -use Plugin\Helpers; | ||
6 | - | ||
7 | -/** | ||
8 | - * 列表数据处理类 | ||
9 | - */ | ||
10 | -class ListProcess | ||
11 | -{ | ||
12 | - | ||
13 | - /** | ||
14 | - * 返回商品和过滤数据 | ||
15 | - * | ||
16 | - * @param $data | ||
17 | - * @return array 处理之后的商品数据 | ||
18 | - */ | ||
19 | - public static function getListData($data, $returnFilter = true) | ||
20 | - { | ||
21 | - $result = array(); | ||
22 | - | ||
23 | - if (isset($data['product_list'])) { | ||
24 | - $result['new'] = self::getProductData($data['product_list']); | ||
25 | - } | ||
26 | - if ($returnFilter && isset($data['filter'])) { | ||
27 | - $result['filter'] = self::getFilterData($data['filter']); | ||
28 | - } | ||
29 | - | ||
30 | - return $result; | ||
31 | - } | ||
32 | - | ||
33 | - /** | ||
34 | - * 处理列表商品数据 | ||
35 | - * | ||
36 | - * @param $data | ||
37 | - * @return array 处理之后的商品数据 | ||
38 | - */ | ||
39 | - public static function getProductData($data) | ||
40 | - { | ||
41 | - // 处理商品 | ||
42 | - $products = array(); | ||
43 | - | ||
44 | - foreach ($data as $value) { | ||
45 | - $products[] = Helpers::formatProduct($value, true, true, true, 235, 314); | ||
46 | - } | ||
47 | - | ||
48 | - return $products; | ||
49 | - } | ||
50 | - | ||
51 | - /** | ||
52 | - * 处理筛选数据 | ||
53 | - * | ||
54 | - * @param $data | ||
55 | - * @param string | integer $gender 默认选择的性别,默认1,2,3表示所有 | ||
56 | - * @param null|string $exclude 需要排除的字段 | ||
57 | - * @return array 处理之后的筛选数据 | ||
58 | - */ | ||
59 | - public static function getFilterData($data, $gender = '1,2,3', $exclude = null) | ||
60 | - { | ||
61 | - // 过滤条件数据 | ||
62 | - $filters = array('classify' => array()); | ||
63 | - | ||
64 | - // 返回数据中有没有gender时要添加gender | ||
65 | - $data['gender'] = array('2,3'=>'GIRLS','1,3'=>'BOYS'); | ||
66 | - | ||
67 | - $num = 1; | ||
68 | - foreach ($data as $key => $val) { | ||
69 | - if ($key === $exclude || empty($val) || !is_callable("self::$key")) { | ||
70 | - continue; | ||
71 | - } | ||
72 | - | ||
73 | - $build = self::$key($val, $gender); | ||
74 | - if ($num === 1) { | ||
75 | - $build['active'] = true; | ||
76 | - } | ||
77 | - | ||
78 | - $num++; | ||
79 | - $filters['classify'][] = $build; | ||
80 | - } | ||
81 | - | ||
82 | - // 按照指定字段进行排序筛选数据 | ||
83 | - self::sortArrByField($filters['classify'], 'sort_col'); | ||
84 | - | ||
85 | - return $filters; | ||
86 | - } | ||
87 | - | ||
88 | - private static function brand($data) | ||
89 | - { | ||
90 | - $result = array( | ||
91 | - 'title' => '品牌', | ||
92 | - 'name' => '所有品牌', | ||
93 | - 'sort_col' => 1, | ||
94 | - 'dataType' => 'brand', | ||
95 | - 'subs' => array( | ||
96 | - array( | ||
97 | - 'chosed' => true, | ||
98 | - 'dataId' => 0, | ||
99 | - 'name' => '所有品牌' | ||
100 | - ) | ||
101 | - ) | ||
102 | - ); | ||
103 | - | ||
104 | - // 对品牌数据按照品牌字母进行排序 | ||
105 | - self::sortArrByField($data, 'brand_alif'); | ||
106 | - | ||
107 | - foreach ($data as $one) { | ||
108 | - $brand = array(); | ||
109 | - $brand['dataId'] = $one['id']; | ||
110 | - $brand['name'] = $one['brand_name']; | ||
111 | - | ||
112 | - $result['subs'][] = $brand; | ||
113 | - } | ||
114 | - | ||
115 | - return $result; | ||
116 | - } | ||
117 | - | ||
118 | - private static function color($data) | ||
119 | - { | ||
120 | - $result = array( | ||
121 | - 'title' => '颜色', | ||
122 | - 'name' => '所有颜色', | ||
123 | - 'sort_col' => 3, | ||
124 | - 'dataType' => 'color', | ||
125 | - 'subs' => array( | ||
126 | - array( | ||
127 | - 'chosed' => true, | ||
128 | - 'dataId' => 0, | ||
129 | - 'name' => '所有颜色' | ||
130 | - ) | ||
131 | - ) | ||
132 | - ); | ||
133 | - | ||
134 | - foreach ($data as $one) { | ||
135 | - $color = array(); | ||
136 | - $color['dataId'] = $one['color_id']; | ||
137 | - $color['name'] = $one['color_name']; | ||
138 | - | ||
139 | - $result['subs'][] = $color; | ||
140 | - } | ||
141 | - | ||
142 | - return $result; | ||
143 | - } | ||
144 | - | ||
145 | - private static function discount($data) | ||
146 | - { | ||
147 | - $result = array( | ||
148 | - 'title' => '折扣', | ||
149 | - 'name' => '所有商品', | ||
150 | - 'sort_col' => 6, | ||
151 | - 'dataType' => 'discount', | ||
152 | - 'subs' => array( | ||
153 | - array( | ||
154 | - 'chosed' => true, | ||
155 | - 'dataId' => '0.1,0.9', | ||
156 | - 'name' => '所有商品' | ||
157 | - ) | ||
158 | - ) | ||
159 | - ); | ||
160 | - | ||
161 | - foreach ($data as $key => $one) { | ||
162 | - $discount = array(); | ||
163 | - $discount['dataId'] = $key; | ||
164 | - $discount['name'] = $one['name'] . '折商品'; | ||
165 | - | ||
166 | - $result['subs'][] = $discount; | ||
167 | - } | ||
168 | - | ||
169 | - return $result; | ||
170 | - } | ||
171 | - | ||
172 | - private static function gender($data, $gender) | ||
173 | - { | ||
174 | - $result = array( | ||
175 | - 'title' => '性别', | ||
176 | - 'name' => '所有性别', | ||
177 | - 'sort_col' => 0, | ||
178 | - 'dataType' => 'gender', | ||
179 | - 'subs' => array( | ||
180 | - array( | ||
181 | - 'dataId' => '1,2,3', | ||
182 | - 'name' => '所有性别' | ||
183 | - ), | ||
184 | - array( | ||
185 | - 'dataId' => '1,3', | ||
186 | - 'name' => 'BOYS' | ||
187 | - ), | ||
188 | - array( | ||
189 | - 'dataId' => '2,3', | ||
190 | - 'name' => 'GIRLS' | ||
191 | - ), | ||
192 | - ) | ||
193 | - ); | ||
194 | - | ||
195 | - // 处理选中状态 | ||
196 | - foreach ($result['subs'] as &$val) { | ||
197 | - if ($val['dataId'] === $gender) { | ||
198 | - $val['chosed'] = true; | ||
199 | - | ||
200 | - $result['name'] = $val['name']; | ||
201 | - } | ||
202 | - } | ||
203 | - | ||
204 | - return $result; | ||
205 | - } | ||
206 | - | ||
207 | - private static function group_sort($data) | ||
208 | - { | ||
209 | - $result = array( | ||
210 | - 'title' => '品类', | ||
211 | - 'name' => '所有品类', | ||
212 | - 'sort_col' => 2, | ||
213 | - 'dataType' => 'sort', | ||
214 | - 'subs' => array( | ||
215 | - array( | ||
216 | - 'chosed' => true, | ||
217 | - 'dataId' => 0, | ||
218 | - 'name' => '所有品类' | ||
219 | - ) | ||
220 | - ) | ||
221 | - ); | ||
222 | - | ||
223 | - $category = array(); | ||
224 | - foreach ($data as $one) { | ||
225 | - | ||
226 | - $category['dataId'] = isset($one['relation_parameter']) ? $one['relation_parameter']['sort'] : 0; | ||
227 | - $category['name'] = $one['category_name']; | ||
228 | - | ||
229 | - /* // 子品类(目前h5不支持二级) | ||
230 | - if(isset($one['sub'])) | ||
231 | - { | ||
232 | - $category['subs'] = array(); | ||
233 | - foreach ($one['sub'] as $single) { | ||
234 | - $subitem = array(); | ||
235 | - $subitem['dataId'] = $single['category_id']; | ||
236 | - $subitem['name'] = $single['category_name']; | ||
237 | - | ||
238 | - $category['subs'][] = $subitem; | ||
239 | - } | ||
240 | - } */ | ||
241 | - | ||
242 | - $result['subs'][] = $category; | ||
243 | - } | ||
244 | - | ||
245 | - return $result; | ||
246 | - } | ||
247 | - | ||
248 | - private static function priceRange($data) | ||
249 | - { | ||
250 | - // 首先对价格进行排序 | ||
251 | - ksort($data, SORT_NUMERIC); | ||
252 | - | ||
253 | - $result = array( | ||
254 | - 'title' => '价格', | ||
255 | - 'name' => '所有价格', | ||
256 | - 'sort_col' => 5, | ||
257 | - 'dataType' => 'price', | ||
258 | - 'subs' => array( | ||
259 | - array( | ||
260 | - 'chosed' => true, | ||
261 | - 'dataId' => 0, | ||
262 | - 'name' => '所有价格' | ||
263 | - ) | ||
264 | - ) | ||
265 | - ); | ||
266 | - | ||
267 | - $price = array(); | ||
268 | - foreach ($data as $key => $one) { | ||
269 | - | ||
270 | - $price['dataId'] = $key; | ||
271 | - $price['name'] = $one; | ||
272 | - | ||
273 | - $result['subs'][] = $price; | ||
274 | - } | ||
275 | - | ||
276 | - return $result; | ||
277 | - } | ||
278 | - | ||
279 | - private static function size($data) | ||
280 | - { | ||
281 | - $result = array( | ||
282 | - 'title' => '尺码', | ||
283 | - 'name' => '所有尺码', | ||
284 | - 'sort_col' => 4, | ||
285 | - 'dataType' => 'size', | ||
286 | - 'subs' => array( | ||
287 | - array( | ||
288 | - 'chosed' => true, | ||
289 | - 'dataId' => 0, | ||
290 | - 'name' => '所有尺码' | ||
291 | - ) | ||
292 | - ) | ||
293 | - ); | ||
294 | - | ||
295 | - $size = array(); | ||
296 | - foreach ($data as $one) { | ||
297 | - | ||
298 | - $size['dataId'] = $one['size_id']; | ||
299 | - $size['name'] = $one['size_name']; | ||
300 | - | ||
301 | - $result['subs'][] = $size; | ||
302 | - } | ||
303 | - | ||
304 | - return $result; | ||
305 | - } | ||
306 | - | ||
307 | - /** | ||
308 | - * 按照数组中指定字段排序二维数组 | ||
309 | - * | ||
310 | - * @param array &$array 需要排序的数组 | ||
311 | - * @param string $field 字段名称 | ||
312 | - * @param boolean $desc 时候降序排列,默认为false | ||
313 | - */ | ||
314 | - private static function sortArrByField(&$array, $field, $desc = false) | ||
315 | - { | ||
316 | - $fieldArr = array(); | ||
317 | - foreach ($array as $k => $v) { | ||
318 | - $fieldArr[$k] = isset($v[$field]) ? $v[$field] : ''; | ||
319 | - } | ||
320 | - $sort = $desc == false ? SORT_ASC : SORT_DESC; | ||
321 | - array_multisort($fieldArr, $sort, $array); | ||
322 | - } | ||
323 | - | ||
324 | -} | 1 | +<?php |
2 | + | ||
3 | +namespace Plugin\DataProcess; | ||
4 | + | ||
5 | +use Plugin\Helpers; | ||
6 | + | ||
7 | +/** | ||
8 | + * 列表数据处理类 | ||
9 | + */ | ||
10 | +class ListProcess | ||
11 | +{ | ||
12 | + | ||
13 | + /** | ||
14 | + * 返回商品和过滤数据 | ||
15 | + * | ||
16 | + * @param $data | ||
17 | + * @return array 处理之后的商品数据 | ||
18 | + */ | ||
19 | + public static function getListData($data, $returnFilter = true) | ||
20 | + { | ||
21 | + $result = array(); | ||
22 | + | ||
23 | + if (isset($data['product_list'])) { | ||
24 | + $result['new'] = self::getProductData($data['product_list']); | ||
25 | + } | ||
26 | + if ($returnFilter && isset($data['filter'])) { | ||
27 | + $result['filter'] = self::getFilterData($data['filter']); | ||
28 | + } | ||
29 | + | ||
30 | + return $result; | ||
31 | + } | ||
32 | + | ||
33 | + /** | ||
34 | + * 处理列表商品数据 | ||
35 | + * | ||
36 | + * @param $data | ||
37 | + * @return array 处理之后的商品数据 | ||
38 | + */ | ||
39 | + public static function getProductData($data) | ||
40 | + { | ||
41 | + // 处理商品 | ||
42 | + $products = array(); | ||
43 | + | ||
44 | + foreach ($data as $value) { | ||
45 | + $products[] = Helpers::formatProduct($value, true, true, true, 235, 314); | ||
46 | + } | ||
47 | + | ||
48 | + return $products; | ||
49 | + } | ||
50 | + | ||
51 | + /** | ||
52 | + * 处理筛选数据 | ||
53 | + * | ||
54 | + * @param $data | ||
55 | + * @param string | integer $gender 默认选择的性别,默认1,2,3表示所有 | ||
56 | + * @param null|string $exclude 需要排除的字段 | ||
57 | + * @return array 处理之后的筛选数据 | ||
58 | + */ | ||
59 | + public static function getFilterData($data, $gender = '1,2,3', $exclude = null) | ||
60 | + { | ||
61 | + // 过滤条件数据 | ||
62 | + $filters = array('classify' => array()); | ||
63 | + | ||
64 | + // 返回数据中有没有gender时要添加gender | ||
65 | + $data['gender'] = array('2,3' => 'GIRLS', '1,3' => 'BOYS'); | ||
66 | + | ||
67 | + $num = 1; | ||
68 | + foreach ($data as $key => $val) { | ||
69 | + if ($key === $exclude || empty($val) || !is_callable("self::$key")) { | ||
70 | + continue; | ||
71 | + } | ||
72 | + | ||
73 | + $build = self::$key($val, $gender); | ||
74 | + if ($num === 1) { | ||
75 | + $build['active'] = true; | ||
76 | + } | ||
77 | + | ||
78 | + $num++; | ||
79 | + $filters['classify'][] = $build; | ||
80 | + } | ||
81 | + | ||
82 | + // 按照指定字段进行排序筛选数据 | ||
83 | + self::sortArrByField($filters['classify'], 'sort_col'); | ||
84 | + | ||
85 | + return $filters; | ||
86 | + } | ||
87 | + | ||
88 | + private static function brand($data) | ||
89 | + { | ||
90 | + $result = array( | ||
91 | + 'title' => '品牌', | ||
92 | + 'name' => '所有品牌', | ||
93 | + 'sort_col' => 1, | ||
94 | + 'dataType' => 'brand', | ||
95 | + 'subs' => array( | ||
96 | + array( | ||
97 | + 'chosed' => true, | ||
98 | + 'dataId' => 0, | ||
99 | + 'name' => '所有品牌' | ||
100 | + ) | ||
101 | + ) | ||
102 | + ); | ||
103 | + | ||
104 | + // 对品牌数据按照品牌字母进行排序 | ||
105 | + self::sortArrByField($data, 'brand_alif'); | ||
106 | + | ||
107 | + foreach ($data as $one) { | ||
108 | + $brand = array(); | ||
109 | + $brand['dataId'] = $one['id']; | ||
110 | + $brand['name'] = $one['brand_name']; | ||
111 | + | ||
112 | + $result['subs'][] = $brand; | ||
113 | + } | ||
114 | + | ||
115 | + return $result; | ||
116 | + } | ||
117 | + | ||
118 | + private static function color($data) | ||
119 | + { | ||
120 | + $result = array( | ||
121 | + 'title' => '颜色', | ||
122 | + 'name' => '所有颜色', | ||
123 | + 'sort_col' => 3, | ||
124 | + 'dataType' => 'color', | ||
125 | + 'subs' => array( | ||
126 | + array( | ||
127 | + 'chosed' => true, | ||
128 | + 'dataId' => 0, | ||
129 | + 'name' => '所有颜色' | ||
130 | + ) | ||
131 | + ) | ||
132 | + ); | ||
133 | + | ||
134 | + foreach ($data as $one) { | ||
135 | + $color = array(); | ||
136 | + $color['dataId'] = $one['color_id']; | ||
137 | + $color['name'] = $one['color_name']; | ||
138 | + | ||
139 | + $result['subs'][] = $color; | ||
140 | + } | ||
141 | + | ||
142 | + return $result; | ||
143 | + } | ||
144 | + | ||
145 | + private static function discount($data) | ||
146 | + { | ||
147 | + $result = array( | ||
148 | + 'title' => '折扣', | ||
149 | + 'name' => '所有商品', | ||
150 | + 'sort_col' => 6, | ||
151 | + 'dataType' => 'discount', | ||
152 | + 'subs' => array( | ||
153 | + array( | ||
154 | + 'chosed' => true, | ||
155 | + 'dataId' => '0.1,0.9', | ||
156 | + 'name' => '所有商品' | ||
157 | + ) | ||
158 | + ) | ||
159 | + ); | ||
160 | + | ||
161 | + foreach ($data as $key => $one) { | ||
162 | + $discount = array(); | ||
163 | + $discount['dataId'] = $key; | ||
164 | + $discount['name'] = $one['name'] . '折商品'; | ||
165 | + | ||
166 | + $result['subs'][] = $discount; | ||
167 | + } | ||
168 | + | ||
169 | + return $result; | ||
170 | + } | ||
171 | + | ||
172 | + private static function gender($data, $gender) | ||
173 | + { | ||
174 | + $result = array( | ||
175 | + 'title' => '性别', | ||
176 | + 'name' => '所有性别', | ||
177 | + 'sort_col' => 0, | ||
178 | + 'dataType' => 'gender', | ||
179 | + 'subs' => array( | ||
180 | + array( | ||
181 | + 'dataId' => '1,2,3', | ||
182 | + 'name' => '所有性别' | ||
183 | + ), | ||
184 | + array( | ||
185 | + 'dataId' => '1,3', | ||
186 | + 'name' => 'BOYS' | ||
187 | + ), | ||
188 | + array( | ||
189 | + 'dataId' => '2,3', | ||
190 | + 'name' => 'GIRLS' | ||
191 | + ), | ||
192 | + ) | ||
193 | + ); | ||
194 | + | ||
195 | + // 处理选中状态 | ||
196 | + foreach ($result['subs'] as &$val) { | ||
197 | + if ($val['dataId'] === $gender) { | ||
198 | + $val['chosed'] = true; | ||
199 | + | ||
200 | + $result['name'] = $val['name']; | ||
201 | + } | ||
202 | + } | ||
203 | + | ||
204 | + return $result; | ||
205 | + } | ||
206 | + | ||
207 | + private static function group_sort($data) | ||
208 | + { | ||
209 | + $result = array( | ||
210 | + 'title' => '品类', | ||
211 | + 'name' => '所有品类', | ||
212 | + 'sort_col' => 2, | ||
213 | + 'dataType' => 'sort', | ||
214 | + 'subs' => array( | ||
215 | + array( | ||
216 | + 'chosed' => true, | ||
217 | + 'dataId' => 0, | ||
218 | + 'name' => '所有品类' | ||
219 | + ) | ||
220 | + ) | ||
221 | + ); | ||
222 | + | ||
223 | + $category = array(); | ||
224 | + foreach ($data as $one) { | ||
225 | + | ||
226 | + $category['dataId'] = isset($one['relation_parameter']) ? $one['relation_parameter']['sort'] : 0; | ||
227 | + $category['name'] = $one['category_name']; | ||
228 | + | ||
229 | + /* // 子品类(目前h5不支持二级) | ||
230 | + if(isset($one['sub'])) | ||
231 | + { | ||
232 | + $category['subs'] = array(); | ||
233 | + foreach ($one['sub'] as $single) { | ||
234 | + $subitem = array(); | ||
235 | + $subitem['dataId'] = $single['category_id']; | ||
236 | + $subitem['name'] = $single['category_name']; | ||
237 | + | ||
238 | + $category['subs'][] = $subitem; | ||
239 | + } | ||
240 | + } */ | ||
241 | + | ||
242 | + $result['subs'][] = $category; | ||
243 | + } | ||
244 | + | ||
245 | + return $result; | ||
246 | + } | ||
247 | + | ||
248 | + private static function priceRange($data) | ||
249 | + { | ||
250 | + // 首先对价格进行排序 | ||
251 | + ksort($data, SORT_NUMERIC); | ||
252 | + | ||
253 | + $result = array( | ||
254 | + 'title' => '价格', | ||
255 | + 'name' => '所有价格', | ||
256 | + 'sort_col' => 5, | ||
257 | + 'dataType' => 'price', | ||
258 | + 'subs' => array( | ||
259 | + array( | ||
260 | + 'chosed' => true, | ||
261 | + 'dataId' => 0, | ||
262 | + 'name' => '所有价格' | ||
263 | + ) | ||
264 | + ) | ||
265 | + ); | ||
266 | + | ||
267 | + $price = array(); | ||
268 | + foreach ($data as $key => $one) { | ||
269 | + | ||
270 | + $price['dataId'] = $key; | ||
271 | + $price['name'] = $one; | ||
272 | + | ||
273 | + $result['subs'][] = $price; | ||
274 | + } | ||
275 | + | ||
276 | + return $result; | ||
277 | + } | ||
278 | + | ||
279 | + private static function size($data) | ||
280 | + { | ||
281 | + $result = array( | ||
282 | + 'title' => '尺码', | ||
283 | + 'name' => '所有尺码', | ||
284 | + 'sort_col' => 4, | ||
285 | + 'dataType' => 'size', | ||
286 | + 'subs' => array( | ||
287 | + array( | ||
288 | + 'chosed' => true, | ||
289 | + 'dataId' => 0, | ||
290 | + 'name' => '所有尺码' | ||
291 | + ) | ||
292 | + ) | ||
293 | + ); | ||
294 | + | ||
295 | + $size = array(); | ||
296 | + foreach ($data as $one) { | ||
297 | + | ||
298 | + $size['dataId'] = $one['size_id']; | ||
299 | + $size['name'] = $one['size_name']; | ||
300 | + | ||
301 | + $result['subs'][] = $size; | ||
302 | + } | ||
303 | + | ||
304 | + return $result; | ||
305 | + } | ||
306 | + | ||
307 | + /** | ||
308 | + * 按照数组中指定字段排序二维数组 | ||
309 | + * | ||
310 | + * @param array &$array 需要排序的数组 | ||
311 | + * @param string $field 字段名称 | ||
312 | + * @param boolean $desc 时候降序排列,默认为false | ||
313 | + */ | ||
314 | + private static function sortArrByField(&$array, $field, $desc = false) | ||
315 | + { | ||
316 | + $fieldArr = array(); | ||
317 | + foreach ($array as $k => $v) { | ||
318 | + $fieldArr[$k] = isset($v[$field]) ? $v[$field] : ''; | ||
319 | + } | ||
320 | + $sort = $desc == false ? SORT_ASC : SORT_DESC; | ||
321 | + array_multisort($fieldArr, $sort, $array); | ||
322 | + } | ||
323 | + | ||
324 | +} |
1 | -<?php | ||
2 | - | ||
3 | -namespace Plugin; | ||
4 | - | ||
5 | -/** | ||
6 | - * 辅助类 | ||
7 | - */ | ||
8 | -class Helpers | ||
9 | -{ | ||
10 | - | ||
11 | - /** | ||
12 | - * 构建网站的URL | ||
13 | - * | ||
14 | - * 备注:所有的URL构建都尽量使用该方法,便于以后维护. | ||
15 | - * | ||
16 | - * @param string $uri 如 "/passport/reg/index" | ||
17 | - * @param array $param 参数项 array(key1 => value1, key2 => value2,),默认为array() | ||
18 | - * @param string $module 模块名 如"index"表示默认, "guang"表示逛,"list"表示商品列表,"search"表示搜索 | ||
19 | - * @return string | ||
20 | - */ | ||
21 | - public static function url($uri, $param = array(), $module = 'index') | ||
22 | - { | ||
23 | - $url = ''; | ||
24 | - | ||
25 | - switch ($module) { | ||
26 | - case 'default': | ||
27 | - $url = 'http://m.yohobuy.com'; | ||
28 | - break; | ||
29 | - case 'guang': // 逛 | ||
30 | - $url = 'http://guang' . SUB_DOMAIN; | ||
31 | - break; | ||
32 | - case 'list': // 商品列表 | ||
33 | - $url = 'http://list' . SUB_DOMAIN; | ||
34 | - break; | ||
35 | - case 'search': // 搜索 | ||
36 | - $url = 'http://search' . SUB_DOMAIN; | ||
37 | - break; | ||
38 | - case 'index': // 默认 | ||
39 | - $url = SITE_MAIN; | ||
40 | - break; | ||
41 | - case '': // 相对地址 | ||
42 | - break; | ||
43 | - default: // 其它子域名 | ||
44 | - $url = 'http://' . $module . SUB_DOMAIN; | ||
45 | - } | ||
46 | - $url .= $uri; | ||
47 | - if (!empty($param)) { | ||
48 | - $url .= '?' . http_build_query($param, null, '&'); | ||
49 | - } | ||
50 | - | ||
51 | - return $url; | ||
52 | - } | ||
53 | - | ||
54 | - /** | ||
55 | - * 根据尺寸获得图片url | ||
56 | - * | ||
57 | - * @param string $url 路径 | ||
58 | - * @param integer $width 图片宽度 | ||
59 | - * @param integer $height 图片高度 | ||
60 | - * @param integer $mode 模式 | ||
61 | - * @return string 图片地址 | ||
62 | - */ | ||
63 | - public static function getImageUrl($url, $width, $height, $mode = 2) | ||
64 | - { | ||
65 | - return strtr($url, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode)); | ||
66 | - } | ||
67 | - | ||
68 | - /** | ||
69 | - * 获取过滤APP里附加参数后的URL链接 | ||
70 | - * | ||
71 | - * @param string $url 路径 | ||
72 | - * @return string 去除掉如&openby:yohobuy={"action":"go.brand"}这样的APP附加参数 | ||
73 | - */ | ||
74 | - public static function getFilterUrl($url) | ||
75 | - { | ||
76 | - $url = strtr($url, array('.m.yohobuy.com' => SUB_DOMAIN, OLD_MAIN => SITE_MAIN, 'www.yohobuy.com' => SITE_MAIN)); | ||
77 | - $filter = strstr($url, 'openby:yohobuy=', true); | ||
78 | - if ($filter) { | ||
79 | - return rtrim(rtrim($filter, '?'), '&'); | ||
80 | - } else { | ||
81 | - return $url; | ||
82 | - } | ||
83 | - } | ||
84 | - | ||
85 | - /** | ||
86 | - * 根据用户访问的COOKIE判断出性别 | ||
87 | - * | ||
88 | - * @return string | ||
89 | - */ | ||
90 | - public static function getGenderByCookie() | ||
91 | - { | ||
92 | - $cookie = isset($_COOKIE['_Channel']) ? $_COOKIE['_Channel'] : 'boys'; | ||
93 | - switch (strval($cookie)) { | ||
94 | - case 'boys': // 男 | ||
95 | - return '1,3'; | ||
96 | - case 'girls': // 女 | ||
97 | - return '2,3'; | ||
98 | - default: // 其它 | ||
99 | - return '1,2,3'; | ||
100 | - } | ||
101 | - } | ||
102 | - | ||
103 | - /** | ||
104 | - * 根据用户访问的COOKIE判断出频道 | ||
105 | - * | ||
106 | - * @return int | ||
107 | - */ | ||
108 | - public static function getChannelByCookie() | ||
109 | - { | ||
110 | - $cookie = isset($_COOKIE['_Channel']) ? $_COOKIE['_Channel'] : 'boys'; | ||
111 | - switch (strval($cookie)) { | ||
112 | - case 'boys': // 男 | ||
113 | - return 1; | ||
114 | - case 'girls': // 女 | ||
115 | - return 2; | ||
116 | - case 'kids': // 潮童 | ||
117 | - return 3; | ||
118 | - case 'lifestyle': // 创意生活 | ||
119 | - return 4; | ||
120 | - default: // 其它 | ||
121 | - return 1; | ||
122 | - } | ||
123 | - } | ||
124 | - | ||
125 | - /** | ||
126 | - * 从用户加入购物车的COOKIE取出购物车凭证 | ||
127 | - * | ||
128 | - * @return string | ||
129 | - */ | ||
130 | - public static function getShoppingKeyByCookie() | ||
131 | - { | ||
132 | - $cookie = isset($_COOKIE['_SPK']) ? $_COOKIE['_SPK'] : ''; | ||
133 | - return $cookie; | ||
134 | - } | ||
135 | - | ||
136 | - /** | ||
137 | - * 获取商品的ICON | ||
138 | - * | ||
139 | - * @param int $type | ||
140 | - * @return array | ||
141 | - */ | ||
142 | - public static function getProductIcon($type) | ||
143 | - { | ||
144 | - static $icons = array( | ||
145 | - 1 => 'cloth', | ||
146 | - 3 => 'pants', | ||
147 | - 4 => 'dress', | ||
148 | - 6 => 'shoe', | ||
149 | - 7 => 'bag', | ||
150 | - 10 => 'lamp', | ||
151 | - 241 => 'headset', | ||
152 | - 8 => 'watch', | ||
153 | - 360 => 'swim-suit', | ||
154 | - 308 => 'under' | ||
155 | - ); | ||
156 | - $type = intval($type); | ||
157 | - | ||
158 | - return isset($icons[$type]) ? $icons[$type] : ''; | ||
159 | - } | ||
160 | - | ||
161 | - /** | ||
162 | - * 根据排序类型和类型值获得正确的排序参数 | ||
163 | - * @param integer $order 类型值 | ||
164 | - * @param string $type 排序类型 | ||
165 | - * @return string 转换之后的排序参数 | ||
166 | - */ | ||
167 | - public static function transOrder($order, $type) | ||
168 | - { | ||
169 | - switch ($type) { | ||
170 | - case 'price': | ||
171 | - $result = ($order == 0) ? 's_p_desc' : 's_p_asc'; | ||
172 | - break; | ||
173 | - case 'discount': | ||
174 | - $result = ($order == 0) ? 'p_d_desc' : 'p_d_asc'; | ||
175 | - break; | ||
176 | - case 'newest': | ||
177 | - default: | ||
178 | - $result = ($order == 1) ? 's_t_desc' : 's_t_asc'; | ||
179 | - break; | ||
180 | - } | ||
181 | - | ||
182 | - return $result; | ||
183 | - } | ||
184 | - | ||
185 | - /** | ||
186 | - * 转换价格 | ||
187 | - * | ||
188 | - * @param float|string $price 价格 | ||
189 | - * @return float|string 转换之后的价格 | ||
190 | - */ | ||
191 | - public static function transPrice($price) | ||
192 | - { | ||
193 | - return !empty($price) ? number_format($price, 2, '.', '') : 0; | ||
194 | - } | ||
195 | - | ||
196 | - /** | ||
197 | - * 格式化商品信息 | ||
198 | - * | ||
199 | - * @param array $productData 需要格式化的商品数据 | ||
200 | - * @param bool $showTags 控制是否显示标签 | ||
201 | - * @param bool $showNew 控制是否显示NEW图标 | ||
202 | - * @param bool $showSale 控制是否显示SALE图标 | ||
203 | - * @param int $width 图片的宽度 | ||
204 | - * @param int $height 图片的高度 | ||
205 | - * @param bool $isApp 判断是不是APP访问 | ||
206 | - * @param bool $showPoint 商品价格是否显示小数位,默认显示 | ||
207 | - * @return array | false | ||
208 | - */ | ||
209 | - public static function formatProduct($productData, $showTags = true, $showNew = true, $showSale = true, $width = 290, $height = 388, $isApp = false, $showPoint = true) | ||
210 | - { | ||
211 | - // 商品信息有问题,则不显示 | ||
212 | - if (!isset($productData['product_skn']) || !isset($productData['goods_list'][0])) { | ||
213 | - return false; | ||
214 | - } | ||
215 | - | ||
216 | - // 市场价和售价一样,则不显示市场价 | ||
217 | - if (intval($productData['market_price']) === intval($productData['sales_price'])) { | ||
218 | - $productData['market_price'] = false; | ||
219 | - } | ||
220 | - | ||
221 | - // 判别默认的商品是否将默认的图片URL赋值到skn | ||
222 | - $flag = false; | ||
223 | - // 如果设置了默认图片,就取默认的图片 | ||
224 | - foreach ($productData['goods_list'] as $oneGoods) { | ||
225 | - // 此skc是默认的,则将图片赋值给skn | ||
226 | - if ($oneGoods['is_default'] === 'Y') { | ||
227 | - $productData['default_images'] = self::procProductImg($oneGoods); | ||
228 | - $flag = true; | ||
229 | - } | ||
230 | - } | ||
231 | - // 如果还未赋值,则取第一个skc产品的默认图片 | ||
232 | - if (!$flag) { | ||
233 | - $productData['default_images'] = self::procProductImg($productData['goods_list'][0]); | ||
234 | - } | ||
235 | - | ||
236 | - $result = array(); | ||
237 | - $result['id'] = $productData['product_skn']; | ||
238 | - $result['product_id'] = $productData['product_id']; | ||
239 | - $result['thumb'] = Images::getImageUrl($productData['default_images'], $width, $height); | ||
240 | - $result['name'] = $productData['product_name']; | ||
241 | - $result['price'] = empty($productData['market_price']) ? false : $productData['market_price']; | ||
242 | - $result['salePrice'] = $productData['sales_price']; | ||
243 | - if ($showPoint) { | ||
244 | - $result['price'] && $result['price'] .= '.00'; | ||
245 | - $result['salePrice'] && $result['salePrice'] .= '.00'; | ||
246 | - } | ||
247 | - $result['is_soon_sold_out'] = ($productData['is_soon_sold_out'] === 'Y'); | ||
248 | - $result['url'] = self::url('/product/pro_' . $productData['product_id'] . '_' | ||
249 | - . $productData['goods_list'][0]['goods_id'] | ||
250 | - . '/' . $productData['cn_alphabet'] . '.html'); | ||
251 | - // APP访问需要加附加的参数 | ||
252 | - // 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护 | ||
253 | - if ($isApp) { | ||
254 | - $result['url'] .= '?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":' . $productData['product_skn'] . '}}'; | ||
255 | - } | ||
256 | - | ||
257 | - if ($showTags) { | ||
258 | - $result['tags'] = array(); | ||
259 | - $result['tags']['is_new'] = $showNew && isset($productData['is_new']) && $productData['is_new'] === 'Y'; // 新品 | ||
260 | - $result['tags']['is_discount'] = $showSale && isset($productData['is_discount']) && $productData['is_discount'] === 'Y'; // 在售 | ||
261 | - $result['tags']['is_limited'] = isset($productData['is_limited']) && $productData['is_limited'] === 'Y'; // 限量 | ||
262 | - $result['tags']['is_yohood'] = isset($productData['is_yohood']) && $productData['is_yohood'] === 'Y'; // YOHOOD | ||
263 | - $result['tags']['midYear'] = isset($productData['mid-year']) && $productData['mid-year'] === 'Y'; // 年中 | ||
264 | - $result['tags']['yearEnd'] = isset($productData['year-end']) && $productData['year-end'] === 'Y'; // 年末 | ||
265 | - $result['tags']['is_advance'] = isset($productData['is_advance']) && $productData['is_advance'] === 'Y'; // 再到着 | ||
266 | - // 打折与即将售完组合显示打折 | ||
267 | - if ($result['is_soon_sold_out'] && $result['tags']['is_discount']) { | ||
268 | - $result['tags']['is_new'] = false; | ||
269 | - } | ||
270 | - // 打折与其它组合则隐藏打折 | ||
271 | - elseif ($result['tags']['is_discount'] && | ||
272 | - ($result['tags']['is_new'] || $result['tags']['is_limited'] || $result['tags']['is_yohood'] || $result['tags']['is_advance'])) { | ||
273 | - $result['tags']['is_discount'] = false; | ||
274 | - } | ||
275 | - // YOHOOD和新品组合显示YOHOOD | ||
276 | - elseif ($result['tags']['is_yohood'] && $result['tags']['is_new']) { | ||
277 | - $result['tags']['is_new'] = false; | ||
278 | - } | ||
279 | - } | ||
280 | - | ||
281 | - return $result; | ||
282 | - } | ||
283 | - | ||
284 | - /** | ||
285 | - * 根据性别来决定 默认图片获取字段 如果是 2、3 | ||
286 | - * | ||
287 | - * 则优先从cover2 --》 cover1 -- 》 images_url | ||
288 | - * 否则优先从cover1 --》 cover2 -- 》 images_url | ||
289 | - * | ||
290 | - * @param array $images | ||
291 | - * @return string 商品图片 | ||
292 | - */ | ||
293 | - public static function procProductImg($images) | ||
294 | - { | ||
295 | - $imgUrl = isset($images['images_url']) ? $images['images_url'] : ''; | ||
296 | - $cover1 = isset($images['cover_1']) ? $images['cover_1'] : ''; | ||
297 | - $cover2 = isset($images['cover_2']) ? $images['cover_2'] : ''; | ||
298 | - $gender = self::getGenderByCookie(); | ||
299 | - if ($gender === '2,3') { | ||
300 | - return !empty($cover2) ? $cover2 : (!empty($cover1) ? $cover1 : $imgUrl); | ||
301 | - } else { | ||
302 | - return !empty($cover1) ? $cover1 : (!empty($cover2) ? $cover2 : $imgUrl); | ||
303 | - } | ||
304 | - } | ||
305 | - | ||
306 | - /** | ||
307 | - * 格式化资讯文章 | ||
308 | - * | ||
309 | - * @param array $articleData 需要格式化的资讯数据 | ||
310 | - * @param bool $showTag 是否显示左上角标签 | ||
311 | - * @param mixed $isApp 是否显示分享,在APP客户端里嵌入需要传url链接 | ||
312 | - * @param bool $showAuthor 控制是否显示作者信息 | ||
313 | - * @param int $uid 当前登录的用户ID | ||
314 | - * @return array | false | ||
315 | - */ | ||
316 | - public static function formatArticle($articleData, $showTag = true, $isApp = false, $showAuthor = true, $uid = null) | ||
317 | - { | ||
318 | - // 资讯ID不存在,则不显示 | ||
319 | - if (!isset($articleData['id'])) { | ||
320 | - return false; | ||
321 | - } | ||
322 | - | ||
323 | - $result = array(); | ||
324 | - $result['id'] = $articleData['id']; | ||
325 | - $result['showTags'] = $showTag; | ||
326 | - $result['img'] = self::getImageUrl($articleData['src'], 640, 640); | ||
327 | - $result['url'] = $isApp ? $articleData['url'] : self::url('/info/index', array('id' => $articleData['id']), 'guang'); | ||
328 | - $result['title'] = $articleData['title']; | ||
329 | - $result['text'] = $articleData['intro']; | ||
330 | - $result['publishTime'] = $articleData['publish_time']; | ||
331 | - $result['pageView'] = $articleData['views_num']; | ||
332 | - | ||
333 | - // 收藏 | ||
334 | - if ($isApp) { | ||
335 | - $result['collect'] = array(); | ||
336 | - $result['collect']['isCollected'] = isset($articleData['isFavor']) && $articleData['isFavor'] === 'Y'; | ||
337 | - $result['collect']['url'] = !empty($uid) ? 'javascript:;' : strtr($articleData['url'], array('"islogin":"N"' => '"islogin":"Y"')); | ||
338 | - } | ||
339 | - // 点赞 | ||
340 | - else { | ||
341 | - $result['like'] = array(); | ||
342 | - $result['like']['count'] = $articleData['praise_num']; | ||
343 | - $result['like']['isLiked'] = isset($articleData['isPraise']) && $articleData['isPraise'] === 'Y'; | ||
344 | - } | ||
345 | - | ||
346 | - // 分享链接 | ||
347 | - $result['share'] = $isApp && isset($articleData['share']['url']) ? $articleData['share']['url'] : false; | ||
348 | - | ||
349 | - // 判断是否显示作者信息 | ||
350 | - if ($showAuthor && !empty($articleData['author'])) { | ||
351 | - if (!$isApp) { | ||
352 | - $articleData['author']['url'] = Helpers::getFilterUrl($articleData['author']['url']); | ||
353 | - } | ||
354 | - $result['author'] = $articleData['author']; | ||
355 | - } | ||
356 | - | ||
357 | - // 模板中需要的标签标识 | ||
358 | - if ($showTag && isset($articleData['category_id'])) { | ||
359 | - switch (strval($articleData['category_id'])) { | ||
360 | - case '1': // 话题 | ||
361 | - $result['isTopic'] = true; | ||
362 | - break; | ||
363 | - case '2': // 搭配 | ||
364 | - $result['isCollocation'] = true; | ||
365 | - break; | ||
366 | - case '3': // 潮人 | ||
367 | - $result['isFashionMan'] = true; | ||
368 | - break; | ||
369 | - case '4': // 潮品 | ||
370 | - $result['isFashionGood'] = true; | ||
371 | - break; | ||
372 | - case '5': // 小贴士 | ||
373 | - $result['isTip'] = true; | ||
374 | - break; | ||
375 | - } | ||
376 | - } | ||
377 | - | ||
378 | - return $result; | ||
379 | - } | ||
380 | - | ||
381 | - /** | ||
382 | - * 格式化广告焦点图数据 | ||
383 | - * | ||
384 | - * @param array $bannerData 需要格式化的广告图数据 | ||
385 | - * @param int $width 图片的宽度 | ||
386 | - * @param int $height 图片的高度 | ||
387 | - * @param int $mode 使用的七牛模式 | ||
388 | - * @return array | ||
389 | - */ | ||
390 | - public static function formatBanner($bannerData, $width, $height, $mode = 2) | ||
391 | - { | ||
392 | - $result = array(); | ||
393 | - | ||
394 | - $result['img'] = self::getImageUrl($bannerData['src'], $width, $height, $mode); | ||
395 | - if (isset($bannerData['url'])) { | ||
396 | - $result['url'] = self::getFilterUrl($bannerData['url']); | ||
397 | - } | ||
398 | - $result['title'] = $bannerData['title']; | ||
399 | - | ||
400 | - return $result; | ||
401 | - } | ||
402 | - | ||
403 | - /** | ||
404 | - * 生成公开的TOKEN凭证 | ||
405 | - * | ||
406 | - * @param string $string 字符串 | ||
407 | - * @return string | ||
408 | - */ | ||
409 | - public static function makeToken($string) | ||
410 | - { | ||
411 | - return md5(md5($string . '#@!@#')); | ||
412 | - } | ||
413 | - | ||
414 | - /** | ||
415 | - * 验证TOKEN凭证 | ||
416 | - * | ||
417 | - * @param string $string 字符串 | ||
418 | - * @param string $token 公开访问TOKEN | ||
419 | - * @return bool | ||
420 | - */ | ||
421 | - public static function verifyToken($string, $token) | ||
422 | - { | ||
423 | - if ($token === self::makeToken($string)) { | ||
424 | - return true; | ||
425 | - } else { | ||
426 | - return false; | ||
427 | - } | ||
428 | - } | ||
429 | - | ||
430 | - /** | ||
431 | - * 验证手机是否合法 | ||
432 | - * | ||
433 | - * @param int $mobile | ||
434 | - * @return boolean | ||
435 | - */ | ||
436 | - public static function verifyMobile($mobile) | ||
437 | - { | ||
438 | - if (empty($mobile)) { | ||
439 | - return false; | ||
440 | - } | ||
441 | - return (bool) preg_match('/^1[3|4|5|8|7][0-9]{9}$/', trim($mobile)); | ||
442 | - } | ||
443 | - | ||
444 | - /** | ||
445 | - * 验证密码是否合法 | ||
446 | - * | ||
447 | - * @param int $password | ||
448 | - * @return boolean | ||
449 | - */ | ||
450 | - public static function verifyPassword($password) | ||
451 | - { | ||
452 | - if (empty($password)) { | ||
453 | - return false; | ||
454 | - } | ||
455 | - return (bool) preg_match('/^([a-zA-Z0-9\-\+_!@\#$%\^&\*\(\)\:\;\.=\[\]\\\',\?]){6,20}$/', trim($password)); | ||
456 | - } | ||
457 | - | ||
458 | - /** | ||
459 | - * 验证邮箱是否合法 | ||
460 | - * | ||
461 | - * @param string $email | ||
462 | - * @return boolean | ||
463 | - */ | ||
464 | - public static function verifyEmail($email) | ||
465 | - { | ||
466 | - if (empty($email)) { | ||
467 | - return false; | ||
468 | - } | ||
469 | - return !!filter_var($email, FILTER_VALIDATE_EMAIL); | ||
470 | - } | ||
471 | - | ||
472 | - /** | ||
473 | - * 验证国际手机号是否合法 | ||
474 | - * | ||
475 | - * @param string $areaMobile | ||
476 | - * @return boolean | ||
477 | - */ | ||
478 | - public static function verifyAreaMobile($areaMobile) | ||
479 | - { | ||
480 | - if (empty($areaMobile)) { | ||
481 | - return false; | ||
482 | - } | ||
483 | - if (!strpos($areaMobile, '-')) { | ||
484 | - return self::areaMobielVerify($areaMobile); | ||
485 | - } else { | ||
486 | - $mobileData = explode('-', $areaMobile); | ||
487 | - if (count($mobileData) != 2) { | ||
488 | - return false; | ||
489 | - } | ||
490 | - } | ||
491 | - return self::areaMobielVerify($mobileData[1], $mobileData[0]); | ||
492 | - } | ||
493 | - | ||
494 | - /** | ||
495 | - * 根据url获取拼接之后的地址,用于用户清理缓存 | ||
496 | - * @param string $url url地址 | ||
497 | - * @param string $channel 频道,默认为woman | ||
498 | - * | ||
499 | - * @return string 处理之后的地址 | ||
500 | - */ | ||
501 | - public static function transUrl($url, $channel='woman') { | ||
502 | - | ||
503 | - $extra = ''; | ||
504 | - if(!empty($url) && stripos($url, '?') === false) { | ||
505 | - $extra = '?channel='.$channel; | ||
506 | - } | ||
507 | - if(!empty($url) && stripos($url, '?') !== false){ | ||
508 | - $extra = '&channel='.$channel; | ||
509 | - } | ||
510 | - return $url . $extra; | ||
511 | - } | ||
512 | - | ||
513 | - | ||
514 | - /** | ||
515 | - * 各国手机号规则 | ||
516 | - */ | ||
517 | - private static function areaMobielVerify($mobile, $area = 86) | ||
518 | - { | ||
519 | - $verify = array( | ||
520 | - 86 => array( | ||
521 | - 'name' => '中国', | ||
522 | - 'match' => (bool) preg_match('/^1[3|4|5|8|7][0-9]{9}$/', trim($mobile)), | ||
523 | - ), | ||
524 | - 852 => array( | ||
525 | - 'name' => '中国香港', | ||
526 | - 'match' => (bool) preg_match('/^[9|6|5][0-9]{7}$/', trim($mobile)), | ||
527 | - ), | ||
528 | - 853 => array( | ||
529 | - 'name' => '中国澳门', | ||
530 | - 'match' => (bool) preg_match('/^[0-9]{8}$/', trim($mobile)), | ||
531 | - ), | ||
532 | - 886 => array( | ||
533 | - 'name' => '中国台湾', | ||
534 | - 'match' => (bool) preg_match('/^[0-9]{10}$/', trim($mobile)), | ||
535 | - ), | ||
536 | - 65 => array( | ||
537 | - 'name' => '新加坡', | ||
538 | - 'match' => (bool) preg_match('/^[9|8][0-9]{7}$/', trim($mobile)), | ||
539 | - ), | ||
540 | - 60 => array( | ||
541 | - 'name' => '马来西亚', | ||
542 | - 'match' => (bool) preg_match('/^1[1|2|3|4|6|7|9][0-9]{8}$/', trim($mobile)), | ||
543 | - ), | ||
544 | - 1 => array( | ||
545 | - 'name' => '加拿大&美国', | ||
546 | - 'match' => (bool) preg_match('/^[0-9]{10}$/', trim($mobile)), | ||
547 | - ), | ||
548 | - 82 => array( | ||
549 | - 'name' => '韩国', | ||
550 | - 'match' => (bool) preg_match('/^01[0-9]{9}$/', trim($mobile)), | ||
551 | - ), | ||
552 | - 44 => array( | ||
553 | - 'name' => '英国', | ||
554 | - 'match' => (bool) preg_match('/^7[7|8|9][0-9]{8}$/', trim($mobile)), | ||
555 | - ), | ||
556 | - 81 => array( | ||
557 | - 'name' => '日本', | ||
558 | - 'match' => (bool) preg_match('/^0[9|8|7][0-9]{9}$/', trim($mobile)), | ||
559 | - ), | ||
560 | - 61 => array( | ||
561 | - 'name' => '澳大利亚', | ||
562 | - 'match' => (bool) preg_match('/^[0-9]{11}$/', trim($mobile)), | ||
563 | - ), | ||
564 | - ); | ||
565 | - if (isset($verify[$area])) { | ||
566 | - return $verify[$area]['match']; | ||
567 | - } | ||
568 | - return false; | ||
569 | - } | ||
570 | - | ||
571 | - /** | ||
572 | - * 格式化订单商品 | ||
573 | - * | ||
574 | - * @param array $orderGoods 订单 | ||
575 | - * @param int $count 计订单件数 | ||
576 | - * @param bool $haveLink 控制是否需要商品链接 | ||
577 | - * @return array $arr 处理之后的订单商品数据 | ||
578 | - */ | ||
579 | - public static function formatOrderGoods($orderGoods, &$count = 0, $haveLink = false) | ||
580 | - { | ||
581 | - $arr = array(); | ||
582 | - | ||
583 | - foreach ($orderGoods as $key => $vo) { | ||
584 | - $arr[$key]['thumb'] = Helpers::getImageUrl($vo['goods_image'], 90, 120); | ||
585 | - $arr[$key]['name'] = $vo['product_name']; | ||
586 | - $arr[$key]['color'] = $vo['color_name']; | ||
587 | - $arr[$key]['size'] = $vo['size_name']; | ||
588 | - $arr[$key]['price'] = $vo['goods_price']; | ||
589 | - $arr[$key]['count'] = $vo['buy_number']; | ||
590 | - //gift=>是否赠品,advanceBuy=>是否加价购; | ||
591 | - if ($vo['goods_type'] == 'gift') { | ||
592 | - $arr[$key]['gift'] = true; | ||
593 | - } elseif ($vo['goods_type'] == 'price_gift') { | ||
594 | - $arr[$key]['advanceBuy'] = true; | ||
595 | - } | ||
596 | - // 上市期 | ||
597 | - if (!empty($vo['expect_arrival_time'])) { | ||
598 | - $arr[$key]['appearDate'] = $vo['expect_arrival_time']; | ||
599 | - } | ||
600 | - // 商品链接 | ||
601 | - if ($haveLink && isset($vo['product_skn'])) { | ||
602 | - $arr[$key]['link'] = self::url('/product/show_' . $vo['product_skn'] . '.html'); | ||
603 | - } | ||
604 | - // 累计购买数 | ||
605 | - $count += intval($vo['buy_number']); | ||
606 | - } | ||
607 | - | ||
608 | - return $arr; | ||
609 | - } | ||
610 | - | ||
611 | -/** | ||
612 | - * 格式化购物车商品 | ||
613 | - * | ||
614 | - * @param array $cartGoods 购物车商品列表 | ||
615 | - * @param boolean $isValid 是否是可用商品(非失效商品),默认是 | ||
616 | - * @param bool $isAdvanceCart 是否是预售购物车(和上市期有关) | ||
617 | - * @return array 处理之后的购物车商品数据 | ||
618 | - */ | ||
619 | - public static function formatCartGoods($cartGoods, $isAdvanceCart, $isValid = true) | ||
620 | - { | ||
621 | - $arr = array(); | ||
622 | - | ||
623 | - $oneGoods = array(); | ||
624 | - foreach ($cartGoods as $key => $value) { | ||
625 | - $oneGoods = array(); | ||
626 | - $oneGoods['id'] = $value['product_sku']; | ||
627 | - $oneGoods['skn'] = $value['product_skn']; | ||
628 | - $oneGoods['name'] = $value['product_name']; | ||
629 | - $oneGoods['thumb'] = !empty($value['goods_images']) ? Images::getImageUrl($value['goods_images'], 120, 160) : ''; | ||
630 | - $oneGoods['color'] = $value['color_name']; | ||
631 | - $oneGoods['size'] = $value['size_name']; | ||
632 | - $oneGoods['checked'] = $value['selected'] === 'Y'; | ||
633 | - $oneGoods['price'] = self::transPrice($value['last_vip_price']); | ||
634 | - $oneGoods['isVipPrice'] = $value['sales_price'] !== $value['last_vip_price']; | ||
635 | - $oneGoods['count'] = $value['buy_number']; | ||
636 | - | ||
637 | - if ($isValid) { | ||
638 | - // 库存不足 | ||
639 | - $oneGoods['lowStocks'] = ($value['buy_number'] > $value['storage_number']); | ||
640 | - } else { // 失效商品 | ||
641 | - $oneGoods['inValid'] = true; | ||
642 | - } | ||
643 | - | ||
644 | - //gift=>是否赠品,advanceBuy=>是否加价购,soldOut=>失效商品; | ||
645 | - if (!isset($value['goods_type'])) { | ||
646 | - $oneGoods['inValid'] = true; | ||
647 | - } elseif ($value['goods_type'] == 'gift' && !isset($value['isAdvanceBuy'])) { | ||
648 | - $oneGoods['isGift'] = true; | ||
649 | - $oneGoods['salesPrice'] = self::transPrice($value['sales_price']); | ||
650 | - $oneGoods['price'] = self::transPrice($value['last_price']); | ||
651 | - } elseif ($value['goods_type'] == 'price_gift') { | ||
652 | - $oneGoods['showCheckbox'] = true; | ||
653 | - $oneGoods['isAdvanceBuy'] = true; | ||
654 | - $oneGoods['salesPrice'] = self::transPrice($value['sales_price']); | ||
655 | - $oneGoods['price'] = self::transPrice($value['last_price']); | ||
656 | - } else { | ||
657 | - $oneGoods['showCheckbox'] = true; | ||
658 | - } | ||
659 | - | ||
660 | - // 上市期 | ||
661 | - if ($isAdvanceCart && !empty($value['expect_arrival_time'])) { | ||
662 | - $oneGoods['appearDate'] = $value['expect_arrival_time']; | ||
663 | - } | ||
664 | - // 商品链接 | ||
665 | - $oneGoods['link'] = self::url('/product/show_' . $value['product_skn'] . '.html'); | ||
666 | - | ||
667 | - $arr[$key] = $oneGoods; | ||
668 | - } | ||
669 | - | ||
670 | - return $arr; | ||
671 | - } | ||
672 | - | ||
673 | - /** | ||
674 | - * 格式化加价购和赠品商品 | ||
675 | - * | ||
676 | - * @param array $advanceGoods 加价购商品列表 | ||
677 | - * @param int $count 计商品件数 | ||
678 | - * @return array $arr 处理之后的加价购商品数据 | ||
679 | - */ | ||
680 | - public static function formatAdvanceGoods($advanceGoods, &$count = 0) | ||
681 | - { | ||
682 | - $arr = array(); | ||
683 | - | ||
684 | - $gift = array(); | ||
685 | - $oneGoods = array(); | ||
686 | - $number = 0; | ||
687 | - foreach ($advanceGoods as $value) { | ||
688 | - $gift = array(); | ||
689 | - $gift['promotionId'] = $value['promotion_id']; | ||
690 | - $gift['promotionTitle'] = $value['promotion_title']; | ||
691 | - | ||
692 | - $number = 0; | ||
693 | - foreach ($value['goods_list'] as $single) { | ||
694 | - $oneGoods = array(); | ||
695 | - $oneGoods['id'] = $single['product_skn']; | ||
696 | - $oneGoods['name'] = $single['product_name']; | ||
697 | - $oneGoods['thumb'] = !empty($single['goods_images']) ? Images::getImageUrl($single['goods_images'], 120, 160) : ''; | ||
698 | - $oneGoods['price'] = self::transPrice($single['last_price']); | ||
699 | - $oneGoods['marketPrice'] = self::transPrice($single['market_price']); | ||
700 | - $oneGoods['count'] = $single['storage_number']; | ||
701 | - | ||
702 | - $gift['goods'][] = $oneGoods; | ||
703 | - $number ++; | ||
704 | - } | ||
705 | - | ||
706 | - $arr[] = $gift; | ||
707 | - | ||
708 | - // 计算加价购商品数目 | ||
709 | - //$count += count($value['goods_list']); | ||
710 | - $count += $number; | ||
711 | - } | ||
712 | - | ||
713 | - return $arr; | ||
714 | - } | ||
715 | - | ||
716 | - /** | ||
717 | - * 订单状态,按订单支付类型和订单状态 | ||
718 | - * @var array | ||
719 | - */ | ||
720 | - public static function getOrderStatus() | ||
721 | - { | ||
722 | - return array( | ||
723 | - '1' => array(//在线支付 | ||
724 | - 0 => '待付款', | ||
725 | - 1 => '已付款', | ||
726 | - 2 => '已付款', | ||
727 | - 3 => '已付款', | ||
728 | - 4 => '已发货', | ||
729 | - 5 => '已发货', | ||
730 | - 6 => '交易成功' | ||
731 | - ), | ||
732 | - '2' => array(//货到付款 | ||
733 | - 0 => '备货中', | ||
734 | - 1 => '已付款', | ||
735 | - 2 => '已付款', | ||
736 | - 3 => '已付款', | ||
737 | - 4 => '已发货', | ||
738 | - 5 => '已发货', | ||
739 | - 6 => '交易成功' | ||
740 | - ), | ||
741 | - '3' => array(//现金支付 | ||
742 | - 0 => '待付款', | ||
743 | - 1 => '已付款', | ||
744 | - 2 => '已付款', | ||
745 | - 3 => '已付款', | ||
746 | - 4 => '已发货', | ||
747 | - 5 => '已发货', | ||
748 | - 6 => '交易成功' | ||
749 | - ), | ||
750 | - '4' => array(//抵消支付 | ||
751 | - 0 => '待付款', | ||
752 | - 1 => '已付款', | ||
753 | - 2 => '已付款', | ||
754 | - 3 => '已付款', | ||
755 | - 4 => '已发货', | ||
756 | - 5 => '已发货', | ||
757 | - 6 => '交易成功' | ||
758 | - ) | ||
759 | - ); | ||
760 | - } | ||
761 | - | ||
762 | - /** | ||
763 | - * 获取会员的级别 | ||
764 | - * | ||
765 | - * @param string $vipInfo | ||
766 | - * @return int | ||
767 | - */ | ||
768 | - public static function getVipLevel($vipInfo) | ||
769 | - { | ||
770 | - $vipLevel = 0; | ||
771 | - | ||
772 | - switch ($vipInfo) { | ||
773 | - case '普通会员': | ||
774 | - $vipLevel = 0; | ||
775 | - break; | ||
776 | - case '银卡会员': | ||
777 | - $vipLevel = 1; | ||
778 | - break; | ||
779 | - case '金卡会员': | ||
780 | - $vipLevel = 2; | ||
781 | - break; | ||
782 | - case '白金会员': | ||
783 | - $vipLevel = 3; | ||
784 | - break; | ||
785 | - } | ||
786 | - | ||
787 | - return $vipLevel; | ||
788 | - } | ||
789 | - | ||
790 | - /** | ||
791 | - * 同步用户的会话 | ||
792 | - * | ||
793 | - * 转向老的PHP服务器上处理, 因购物车相关的操作会依赖SESSION | ||
794 | - * | ||
795 | - * @param int $uid 用户ID | ||
796 | - * @param string $refer 访问来源 | ||
797 | - * @param string $callback 回调方法名 | ||
798 | - * @return string | ||
799 | - */ | ||
800 | - public static function syncUserSession($uid, $refer = '', $callback = 'call') | ||
801 | - { | ||
802 | - return 'http://mapi.yohobuy.com/Passport/session/index?callback=' . $callback | ||
803 | - . '&sign=' . md5(md5($uid . 'Js8Yn0!EwPM45-ws')) . '&uid=' . $uid . '&go=' . $refer; | ||
804 | - } | ||
805 | - | ||
806 | - /** | ||
807 | - * 退出清除用户的会话 | ||
808 | - * | ||
809 | - * 转向老的PHP服务器上处理, 因购物车相关的操作会依赖SESSION | ||
810 | - * | ||
811 | - * @param int $uid 用户ID | ||
812 | - * @param string $refer 访问来源 | ||
813 | - * @param string $callback 回调方法名 | ||
814 | - * @return string | ||
815 | - */ | ||
816 | - public static function logoutSession($token, $refer = '', $callback = 'call') | ||
817 | - { | ||
818 | - return 'http://mapi.yohobuy.com/Passport/session/logout?callback=' . $callback | ||
819 | - . '&sign=' . md5(md5('Js8Yn0!EwPM45-ws')) . '&token=' . $token . '&go=' . $refer; | ||
820 | - } | ||
821 | - | ||
822 | - /** | ||
823 | - * 根据skc获取商品链接 | ||
824 | - * @param unknown $productSkc | ||
825 | - * @return string | ||
826 | - */ | ||
827 | - public static function getUrlBySkc($product_id, $goods_id, $cn_alphabet='') | ||
828 | - { | ||
829 | - if (empty($cn_alphabet)) { | ||
830 | - $cn_alphabet = 'goods.html'; | ||
831 | - } | ||
832 | - return 'http://item.yohobuy.com/product/pro_' . $product_id . '_' . $goods_id . '/' . $cn_alphabet. '.html'; | ||
833 | - } | ||
834 | - | ||
835 | - /** | ||
836 | - * 获取真实IP | ||
837 | - * | ||
838 | - * @return string | ||
839 | - */ | ||
840 | - public static function getClientIp() | ||
841 | - { | ||
842 | - $ip = '0.0.0.0'; | ||
843 | - if (isset($_SERVER['HTTP_CLIENT_IP']) && $_SERVER['HTTP_CLIENT_IP'] != '') | ||
844 | - $ip = $_SERVER['HTTP_CLIENT_IP']; | ||
845 | - elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != '') | ||
846 | - $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; | ||
847 | - elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] != '') | ||
848 | - $ip = $_SERVER['REMOTE_ADDR']; | ||
849 | - return $ip; | ||
850 | - } | ||
851 | - | ||
852 | - /** | ||
853 | - * 组合国际手机号 | ||
854 | - * @param $area | ||
855 | - * @param $mobile | ||
856 | - * @return string | ||
857 | - */ | ||
858 | - public static function makeMobile($area, $mobile){ | ||
859 | - if(empty($area) || $area == 86){ | ||
860 | - return $mobile; | ||
861 | - } | ||
862 | - return $area.'-'.$mobile; | ||
863 | - } | ||
864 | -} | 1 | +<?php |
2 | + | ||
3 | +namespace Plugin; | ||
4 | + | ||
5 | +/** | ||
6 | + * 辅助类 | ||
7 | + */ | ||
8 | +class Helpers | ||
9 | +{ | ||
10 | + | ||
11 | + /** | ||
12 | + * 构建网站的URL | ||
13 | + * | ||
14 | + * 备注:所有的URL构建都尽量使用该方法,便于以后维护. | ||
15 | + * | ||
16 | + * @param string $uri 如 "/passport/reg/index" | ||
17 | + * @param array $param 参数项 array(key1 => value1, key2 => value2,),默认为array() | ||
18 | + * @param string $module 模块名 如"index"表示默认, "guang"表示逛,"list"表示商品列表,"search"表示搜索 | ||
19 | + * @return string | ||
20 | + */ | ||
21 | + public static function url($uri, $param = array(), $module = 'index') | ||
22 | + { | ||
23 | + $url = ''; | ||
24 | + | ||
25 | + switch ($module) { | ||
26 | + case 'default': | ||
27 | + $url = 'http://m.yohobuy.com'; | ||
28 | + break; | ||
29 | + case 'guang': // 逛 | ||
30 | + $url = 'http://guang' . SUB_DOMAIN; | ||
31 | + break; | ||
32 | + case 'list': // 商品列表 | ||
33 | + $url = 'http://list' . SUB_DOMAIN; | ||
34 | + break; | ||
35 | + case 'search': // 搜索 | ||
36 | + $url = 'http://search' . SUB_DOMAIN; | ||
37 | + break; | ||
38 | + case 'index': // 默认 | ||
39 | + $url = SITE_MAIN; | ||
40 | + break; | ||
41 | + case '': // 相对地址 | ||
42 | + break; | ||
43 | + default: // 其它子域名 | ||
44 | + $url = 'http://' . $module . SUB_DOMAIN; | ||
45 | + } | ||
46 | + $url .= $uri; | ||
47 | + if (!empty($param)) { | ||
48 | + $url .= '?' . http_build_query($param, null, '&'); | ||
49 | + } | ||
50 | + | ||
51 | + return $url; | ||
52 | + } | ||
53 | + | ||
54 | + /** | ||
55 | + * 根据尺寸获得图片url | ||
56 | + * | ||
57 | + * @param string $url 路径 | ||
58 | + * @param integer $width 图片宽度 | ||
59 | + * @param integer $height 图片高度 | ||
60 | + * @param integer $mode 模式 | ||
61 | + * @return string 图片地址 | ||
62 | + */ | ||
63 | + public static function getImageUrl($url, $width, $height, $mode = 2) | ||
64 | + { | ||
65 | + return strtr($url, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode)); | ||
66 | + } | ||
67 | + | ||
68 | + /** | ||
69 | + * 获取过滤APP里附加参数后的URL链接 | ||
70 | + * | ||
71 | + * @param string $url 路径 | ||
72 | + * @return string 去除掉如&openby:yohobuy={"action":"go.brand"}这样的APP附加参数 | ||
73 | + */ | ||
74 | + public static function getFilterUrl($url) | ||
75 | + { | ||
76 | + $url = strtr($url, array('.m.yohobuy.com' => SUB_DOMAIN, OLD_MAIN => SITE_MAIN, 'www.yohobuy.com' => SITE_MAIN)); | ||
77 | + $filter = strstr($url, 'openby:yohobuy=', true); | ||
78 | + if ($filter) { | ||
79 | + return rtrim(rtrim($filter, '?'), '&'); | ||
80 | + } else { | ||
81 | + return $url; | ||
82 | + } | ||
83 | + } | ||
84 | + | ||
85 | + /** | ||
86 | + * 根据用户访问的COOKIE判断出性别 | ||
87 | + * | ||
88 | + * @return string | ||
89 | + */ | ||
90 | + public static function getGenderByCookie() | ||
91 | + { | ||
92 | + $cookie = isset($_COOKIE['_Channel']) ? $_COOKIE['_Channel'] : 'boys'; | ||
93 | + switch (strval($cookie)) { | ||
94 | + case 'boys': // 男 | ||
95 | + return '1,3'; | ||
96 | + case 'girls': // 女 | ||
97 | + return '2,3'; | ||
98 | + default: // 其它 | ||
99 | + return '1,2,3'; | ||
100 | + } | ||
101 | + } | ||
102 | + | ||
103 | + /** | ||
104 | + * 根据用户访问的COOKIE判断出频道 | ||
105 | + * | ||
106 | + * @return int | ||
107 | + */ | ||
108 | + public static function getChannelByCookie() | ||
109 | + { | ||
110 | + $cookie = isset($_COOKIE['_Channel']) ? $_COOKIE['_Channel'] : 'boys'; | ||
111 | + switch (strval($cookie)) { | ||
112 | + case 'boys': // 男 | ||
113 | + return 1; | ||
114 | + case 'girls': // 女 | ||
115 | + return 2; | ||
116 | + case 'kids': // 潮童 | ||
117 | + return 3; | ||
118 | + case 'lifestyle': // 创意生活 | ||
119 | + return 4; | ||
120 | + default: // 其它 | ||
121 | + return 1; | ||
122 | + } | ||
123 | + } | ||
124 | + | ||
125 | + /** | ||
126 | + * 从用户加入购物车的COOKIE取出购物车凭证 | ||
127 | + * | ||
128 | + * @return string | ||
129 | + */ | ||
130 | + public static function getShoppingKeyByCookie() | ||
131 | + { | ||
132 | + $cookie = isset($_COOKIE['_SPK']) ? $_COOKIE['_SPK'] : ''; | ||
133 | + | ||
134 | + return $cookie; | ||
135 | + } | ||
136 | + | ||
137 | + /** | ||
138 | + * 获取商品的ICON | ||
139 | + * | ||
140 | + * @param int $type | ||
141 | + * @return array | ||
142 | + */ | ||
143 | + public static function getProductIcon($type) | ||
144 | + { | ||
145 | + static $icons = array( | ||
146 | + 1 => 'cloth', | ||
147 | + 3 => 'pants', | ||
148 | + 4 => 'dress', | ||
149 | + 6 => 'shoe', | ||
150 | + 7 => 'bag', | ||
151 | + 10 => 'lamp', | ||
152 | + 241 => 'headset', | ||
153 | + 8 => 'watch', | ||
154 | + 360 => 'swim-suit', | ||
155 | + 308 => 'under' | ||
156 | + ); | ||
157 | + $type = intval($type); | ||
158 | + | ||
159 | + return isset($icons[$type]) ? $icons[$type] : ''; | ||
160 | + } | ||
161 | + | ||
162 | + /** | ||
163 | + * 根据排序类型和类型值获得正确的排序参数 | ||
164 | + * @param integer $order 类型值 | ||
165 | + * @param string $type 排序类型 | ||
166 | + * @return string 转换之后的排序参数 | ||
167 | + */ | ||
168 | + public static function transOrder($order, $type) | ||
169 | + { | ||
170 | + switch ($type) { | ||
171 | + case 'price': | ||
172 | + $result = ($order == 0) ? 's_p_desc' : 's_p_asc'; | ||
173 | + break; | ||
174 | + case 'discount': | ||
175 | + $result = ($order == 0) ? 'p_d_desc' : 'p_d_asc'; | ||
176 | + break; | ||
177 | + case 'newest': | ||
178 | + default: | ||
179 | + $result = ($order == 1) ? 's_t_desc' : 's_t_asc'; | ||
180 | + break; | ||
181 | + } | ||
182 | + | ||
183 | + return $result; | ||
184 | + } | ||
185 | + | ||
186 | + /** | ||
187 | + * 转换价格 | ||
188 | + * | ||
189 | + * @param float|string $price 价格 | ||
190 | + * @return float|string 转换之后的价格 | ||
191 | + */ | ||
192 | + public static function transPrice($price) | ||
193 | + { | ||
194 | + return number_format($price, 2, '.', ''); | ||
195 | + } | ||
196 | + | ||
197 | + /** | ||
198 | + * 格式化商品信息 | ||
199 | + * | ||
200 | + * @param array $productData 需要格式化的商品数据 | ||
201 | + * @param bool $showTags 控制是否显示标签 | ||
202 | + * @param bool $showNew 控制是否显示NEW图标 | ||
203 | + * @param bool $showSale 控制是否显示SALE图标 | ||
204 | + * @param int $width 图片的宽度 | ||
205 | + * @param int $height 图片的高度 | ||
206 | + * @param bool $isApp 判断是不是APP访问 | ||
207 | + * @param bool $showPoint 商品价格是否显示小数位,默认显示 | ||
208 | + * @return array | false | ||
209 | + */ | ||
210 | + public static function formatProduct($productData, $showTags = true, $showNew = true, $showSale = true, $width = 290, $height = 388, $isApp = false, $showPoint = true) | ||
211 | + { | ||
212 | + // 商品信息有问题,则不显示 | ||
213 | + if (!isset($productData['product_skn']) || !isset($productData['goods_list'][0])) { | ||
214 | + return false; | ||
215 | + } | ||
216 | + | ||
217 | + // 市场价和售价一样,则不显示市场价 | ||
218 | + if (intval($productData['market_price']) === intval($productData['sales_price'])) { | ||
219 | + $productData['market_price'] = false; | ||
220 | + } | ||
221 | + | ||
222 | + // 如果$productData['default_images']为空,就取$productData['goods_list']中第一个,为空就不处理 | ||
223 | + if (empty($productData['default_images'])) { | ||
224 | + $productData['default_images'] = $productData['goods_list'][0]['images_url']; | ||
225 | + } | ||
226 | + | ||
227 | + $result = array(); | ||
228 | + $result['id'] = $productData['product_skn']; | ||
229 | + $result['product_id'] = $productData['product_id']; | ||
230 | + $result['thumb'] = Images::getImageUrl($productData['default_images'], $width, $height); | ||
231 | + $result['name'] = $productData['product_name']; | ||
232 | + $result['price'] = empty($productData['market_price']) ? false : $productData['market_price']; | ||
233 | + $result['salePrice'] = $productData['sales_price']; | ||
234 | + if ($showPoint) { | ||
235 | + $result['price'] && $result['price'] .= '.00'; | ||
236 | + $result['salePrice'] && $result['salePrice'] .= '.00'; | ||
237 | + } | ||
238 | + $result['is_soon_sold_out'] = ($productData['is_soon_sold_out'] === 'Y'); | ||
239 | + $result['url'] = self::url('/product/pro_' . $productData['product_id'] . '_' | ||
240 | + . $productData['goods_list'][0]['goods_id'] | ||
241 | + . '/' . $productData['cn_alphabet'] . '.html'); | ||
242 | + // APP访问需要加附加的参数 | ||
243 | + // 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护 | ||
244 | + if ($isApp) { | ||
245 | + $result['url'] .= '?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":' . $productData['product_skn'] . '}}'; | ||
246 | + } | ||
247 | + | ||
248 | + if ($showTags) { | ||
249 | + $result['tags'] = array(); | ||
250 | + $result['tags']['is_new'] = $showNew && isset($productData['is_new']) && $productData['is_new'] === 'Y'; // 新品 | ||
251 | + $result['tags']['is_discount'] = $showSale && isset($productData['is_discount']) && $productData['is_discount'] === 'Y'; // 在售 | ||
252 | + $result['tags']['is_limited'] = isset($productData['is_limited']) && $productData['is_limited'] === 'Y'; // 限量 | ||
253 | + $result['tags']['is_yohood'] = isset($productData['is_yohood']) && $productData['is_yohood'] === 'Y'; // YOHOOD | ||
254 | + $result['tags']['midYear'] = isset($productData['mid-year']) && $productData['mid-year'] === 'Y'; // 年中 | ||
255 | + $result['tags']['yearEnd'] = isset($productData['year-end']) && $productData['year-end'] === 'Y'; // 年末 | ||
256 | + $result['tags']['is_advance'] = isset($productData['is_advance']) && $productData['is_advance'] === 'Y'; // 再到着 | ||
257 | + // 打折与即将售完组合显示打折 | ||
258 | + if ($result['is_soon_sold_out'] && $result['tags']['is_discount']) { | ||
259 | + $result['tags']['is_new'] = false; | ||
260 | + } | ||
261 | + // 打折与其它组合则隐藏打折 | ||
262 | + elseif ($result['tags']['is_discount'] && | ||
263 | + ($result['tags']['is_new'] || $result['tags']['is_limited'] || $result['tags']['is_yohood'] || $result['tags']['is_advance'])) { | ||
264 | + $result['tags']['is_discount'] = false; | ||
265 | + } | ||
266 | + // YOHOOD和新品组合显示YOHOOD | ||
267 | + elseif ($result['tags']['is_yohood'] && $result['tags']['is_new']) { | ||
268 | + $result['tags']['is_new'] = false; | ||
269 | + } | ||
270 | + } | ||
271 | + | ||
272 | + return $result; | ||
273 | + } | ||
274 | + | ||
275 | + /** | ||
276 | + * 格式化资讯文章 | ||
277 | + * | ||
278 | + * @param array $articleData 需要格式化的资讯数据 | ||
279 | + * @param bool $showTag 是否显示左上角标签 | ||
280 | + * @param mixed $isApp 是否显示分享,在APP客户端里嵌入需要传url链接 | ||
281 | + * @param bool $showAuthor 控制是否显示作者信息 | ||
282 | + * @param int $uid 当前登录的用户ID | ||
283 | + * @return array | false | ||
284 | + */ | ||
285 | + public static function formatArticle($articleData, $showTag = true, $isApp = false, $showAuthor = true, $uid = null) | ||
286 | + { | ||
287 | + // 资讯ID不存在,则不显示 | ||
288 | + if (!isset($articleData['id'])) { | ||
289 | + return false; | ||
290 | + } | ||
291 | + | ||
292 | + $result = array(); | ||
293 | + $result['id'] = $articleData['id']; | ||
294 | + $result['showTags'] = $showTag; | ||
295 | + $result['img'] = self::getImageUrl($articleData['src'], 640, 640); | ||
296 | + $result['url'] = $isApp ? $articleData['url'] : self::url('/info/index', array('id' => $articleData['id']), 'guang'); | ||
297 | + $result['title'] = $articleData['title']; | ||
298 | + $result['text'] = $articleData['intro']; | ||
299 | + $result['publishTime'] = $articleData['publish_time']; | ||
300 | + $result['pageView'] = $articleData['views_num']; | ||
301 | + | ||
302 | + // 收藏 | ||
303 | + if ($isApp) { | ||
304 | + $result['collect'] = array(); | ||
305 | + $result['collect']['isCollected'] = isset($articleData['isFavor']) && $articleData['isFavor'] === 'Y'; | ||
306 | + $result['collect']['url'] = !empty($uid) ? 'javascript:;' : strtr($articleData['url'], array('"islogin":"N"' => '"islogin":"Y"')); | ||
307 | + } | ||
308 | + // 点赞 | ||
309 | + else { | ||
310 | + $result['like'] = array(); | ||
311 | + $result['like']['count'] = $articleData['praise_num']; | ||
312 | + $result['like']['isLiked'] = isset($articleData['isPraise']) && $articleData['isPraise'] === 'Y'; | ||
313 | + } | ||
314 | + | ||
315 | + // 分享链接 | ||
316 | + $result['share'] = $isApp && isset($articleData['share']['url']) ? $articleData['share']['url'] : false; | ||
317 | + | ||
318 | + // 判断是否显示作者信息 | ||
319 | + if ($showAuthor && !empty($articleData['author'])) { | ||
320 | + if (!$isApp) { | ||
321 | + $articleData['author']['url'] = Helpers::getFilterUrl($articleData['author']['url']); | ||
322 | + } | ||
323 | + $result['author'] = $articleData['author']; | ||
324 | + } | ||
325 | + | ||
326 | + // 模板中需要的标签标识 | ||
327 | + if ($showTag && isset($articleData['category_id'])) { | ||
328 | + switch (strval($articleData['category_id'])) { | ||
329 | + case '1': // 话题 | ||
330 | + $result['isTopic'] = true; | ||
331 | + break; | ||
332 | + case '2': // 搭配 | ||
333 | + $result['isCollocation'] = true; | ||
334 | + break; | ||
335 | + case '3': // 潮人 | ||
336 | + $result['isFashionMan'] = true; | ||
337 | + break; | ||
338 | + case '4': // 潮品 | ||
339 | + $result['isFashionGood'] = true; | ||
340 | + break; | ||
341 | + case '5': // 小贴士 | ||
342 | + $result['isTip'] = true; | ||
343 | + break; | ||
344 | + } | ||
345 | + } | ||
346 | + | ||
347 | + return $result; | ||
348 | + } | ||
349 | + | ||
350 | + /** | ||
351 | + * 格式化广告焦点图数据 | ||
352 | + * | ||
353 | + * @param array $bannerData 需要格式化的广告图数据 | ||
354 | + * @param int $width 图片的宽度 | ||
355 | + * @param int $height 图片的高度 | ||
356 | + * @param int $mode 使用的七牛模式 | ||
357 | + * @return array | ||
358 | + */ | ||
359 | + public static function formatBanner($bannerData, $width, $height, $mode = 2) | ||
360 | + { | ||
361 | + $result = array(); | ||
362 | + | ||
363 | + $result['img'] = self::getImageUrl($bannerData['src'], $width, $height, $mode); | ||
364 | + if (isset($bannerData['url'])) { | ||
365 | + $result['url'] = self::getFilterUrl($bannerData['url']); | ||
366 | + } | ||
367 | + $result['title'] = $bannerData['title']; | ||
368 | + | ||
369 | + return $result; | ||
370 | + } | ||
371 | + | ||
372 | + /** | ||
373 | + * 生成公开的TOKEN凭证 | ||
374 | + * | ||
375 | + * @param string $string 字符串 | ||
376 | + * @return string | ||
377 | + */ | ||
378 | + public static function makeToken($string) | ||
379 | + { | ||
380 | + return md5(md5($string . '#@!@#')); | ||
381 | + } | ||
382 | + | ||
383 | + /** | ||
384 | + * 验证TOKEN凭证 | ||
385 | + * | ||
386 | + * @param string $string 字符串 | ||
387 | + * @param string $token 公开访问TOKEN | ||
388 | + * @return bool | ||
389 | + */ | ||
390 | + public static function verifyToken($string, $token) | ||
391 | + { | ||
392 | + if ($token === self::makeToken($string)) { | ||
393 | + return true; | ||
394 | + } else { | ||
395 | + return false; | ||
396 | + } | ||
397 | + } | ||
398 | + | ||
399 | + /** | ||
400 | + * 验证手机是否合法 | ||
401 | + * | ||
402 | + * @param int $mobile | ||
403 | + * @return boolean | ||
404 | + */ | ||
405 | + public static function verifyMobile($mobile) | ||
406 | + { | ||
407 | + if (empty($mobile)) { | ||
408 | + return false; | ||
409 | + } | ||
410 | + return (bool) preg_match('/^1[3|4|5|8|7][0-9]{9}$/', trim($mobile)); | ||
411 | + } | ||
412 | + | ||
413 | + /** | ||
414 | + * 验证密码是否合法 | ||
415 | + * | ||
416 | + * @param int $password | ||
417 | + * @return boolean | ||
418 | + */ | ||
419 | + public static function verifyPassword($password) | ||
420 | + { | ||
421 | + if (empty($password)) { | ||
422 | + return false; | ||
423 | + } | ||
424 | + return (bool) preg_match('/^([a-zA-Z0-9\-\+_!@\#$%\^&\*\(\)\:\;\.=\[\]\\\',\?]){6,20}$/', trim($password)); | ||
425 | + } | ||
426 | + | ||
427 | + /** | ||
428 | + * 验证邮箱是否合法 | ||
429 | + * | ||
430 | + * @param string $email | ||
431 | + * @return boolean | ||
432 | + */ | ||
433 | + public static function verifyEmail($email) | ||
434 | + { | ||
435 | + if (empty($email)) { | ||
436 | + return false; | ||
437 | + } | ||
438 | + return !!filter_var($email, FILTER_VALIDATE_EMAIL); | ||
439 | + } | ||
440 | + | ||
441 | + /** | ||
442 | + * 验证国际手机号是否合法 | ||
443 | + * | ||
444 | + * @param string $areaMobile | ||
445 | + * @param int $area | ||
446 | + * @return boolean | ||
447 | + */ | ||
448 | + public static function verifyAreaMobile($areaMobile, $area) | ||
449 | + { | ||
450 | + if (empty($areaMobile)) { | ||
451 | + return false; | ||
452 | + } | ||
453 | + if (!strpos($areaMobile, '-')) { | ||
454 | + return self::areaMobielVerify($areaMobile, $area); | ||
455 | + } else { | ||
456 | + $mobileData = explode('-', $areaMobile); | ||
457 | + if (count($mobileData) != 2) { | ||
458 | + return false; | ||
459 | + } | ||
460 | + } | ||
461 | + return self::areaMobielVerify($mobileData[1], $mobileData[0]); | ||
462 | + } | ||
463 | + | ||
464 | + /** | ||
465 | + * 各国手机号规则 | ||
466 | + */ | ||
467 | + private static function areaMobielVerify($mobile, $area = 86) | ||
468 | + { | ||
469 | + $verify = array( | ||
470 | + 86 => array( | ||
471 | + 'name' => '中国', | ||
472 | + 'match' => (bool) preg_match('/^1[3|4|5|8|7][0-9]{9}$/', trim($mobile)), | ||
473 | + ), | ||
474 | + 852 => array( | ||
475 | + 'name' => '中国香港', | ||
476 | + 'match' => (bool) preg_match('/^[9|6|5][0-9]{7}$/', trim($mobile)), | ||
477 | + ), | ||
478 | + 853 => array( | ||
479 | + 'name' => '中国澳门', | ||
480 | + 'match' => (bool) preg_match('/^[0-9]{8}$/', trim($mobile)), | ||
481 | + ), | ||
482 | + 886 => array( | ||
483 | + 'name' => '中国台湾', | ||
484 | + 'match' => (bool) preg_match('/^[0-9]{10}$/', trim($mobile)), | ||
485 | + ), | ||
486 | + 65 => array( | ||
487 | + 'name' => '新加坡', | ||
488 | + 'match' => (bool) preg_match('/^[9|8][0-9]{7}$/', trim($mobile)), | ||
489 | + ), | ||
490 | + 60 => array( | ||
491 | + 'name' => '马来西亚', | ||
492 | + 'match' => (bool) preg_match('/^1[1|2|3|4|6|7|9][0-9]{8}$/', trim($mobile)), | ||
493 | + ), | ||
494 | + 1 => array( | ||
495 | + 'name' => '加拿大&美国', | ||
496 | + 'match' => (bool) preg_match('/^[0-9]{10}$/', trim($mobile)), | ||
497 | + ), | ||
498 | + 82 => array( | ||
499 | + 'name' => '韩国', | ||
500 | + 'match' => (bool) preg_match('/^01[0-9]{9}$/', trim($mobile)), | ||
501 | + ), | ||
502 | + 44 => array( | ||
503 | + 'name' => '英国', | ||
504 | + 'match' => (bool) preg_match('/^7[7|8|9][0-9]{8}$/', trim($mobile)), | ||
505 | + ), | ||
506 | + 81 => array( | ||
507 | + 'name' => '日本', | ||
508 | + 'match' => (bool) preg_match('/^0[9|8|7][0-9]{9}$/', trim($mobile)), | ||
509 | + ), | ||
510 | + 61 => array( | ||
511 | + 'name' => '澳大利亚', | ||
512 | + 'match' => (bool) preg_match('/^[0-9]{11}$/', trim($mobile)), | ||
513 | + ), | ||
514 | + ); | ||
515 | + if (isset($verify[$area])) { | ||
516 | + return $verify[$area]['match']; | ||
517 | + } | ||
518 | + return false; | ||
519 | + } | ||
520 | + | ||
521 | + /** | ||
522 | + * 格式化订单商品 | ||
523 | + * | ||
524 | + * @param array $orderGoods 订单 | ||
525 | + * @param int $count 计订单件数 | ||
526 | + * @param bool $haveLink 控制是否需要商品链接 | ||
527 | + * @return array $arr 处理之后的订单商品数据 | ||
528 | + */ | ||
529 | + public static function formatOrderGoods($orderGoods, &$count = 0, $haveLink = false) | ||
530 | + { | ||
531 | + $arr = array(); | ||
532 | + | ||
533 | + foreach ($orderGoods as $key => $vo) { | ||
534 | + $arr[$key]['thumb'] = Helpers::getImageUrl($vo['goods_image'], 90, 120); | ||
535 | + $arr[$key]['name'] = $vo['product_name']; | ||
536 | + $arr[$key]['color'] = $vo['color_name']; | ||
537 | + $arr[$key]['size'] = $vo['size_name']; | ||
538 | + $arr[$key]['price'] = $vo['goods_price']; | ||
539 | + $arr[$key]['count'] = $vo['buy_number']; | ||
540 | + //gift=>是否赠品,advanceBuy=>是否加价购; | ||
541 | + if ($vo['goods_type'] == 'gift') { | ||
542 | + $arr[$key]['gift'] = true; | ||
543 | + } elseif ($vo['goods_type'] == 'price_gift') { | ||
544 | + $arr[$key]['advanceBuy'] = true; | ||
545 | + } | ||
546 | + // 上市期 | ||
547 | + if (!empty($vo['expect_arrival_time'])) { | ||
548 | + $arr[$key]['appearDate'] = $vo['expect_arrival_time']; | ||
549 | + } | ||
550 | + // 商品链接 | ||
551 | + if ($haveLink && isset($vo['product_skn'])) { | ||
552 | + $arr[$key]['link'] = self::url('/product/show_' . $vo['product_skn'] . '.html'); | ||
553 | + } | ||
554 | + // 累计购买数 | ||
555 | + $count += intval($vo['buy_number']); | ||
556 | + } | ||
557 | + | ||
558 | + return $arr; | ||
559 | + } | ||
560 | + | ||
561 | + /** | ||
562 | + * 格式化购物车商品 | ||
563 | + * | ||
564 | + * @param array $cartGoods 购物车商品列表 | ||
565 | + * @param boolean $isValid 是否是可用商品(非失效商品),默认是 | ||
566 | + * @param bool $isAdvanceCart 是否是预售购物车(和上市期有关) | ||
567 | + * @return array 处理之后的购物车商品数据 | ||
568 | + */ | ||
569 | + public static function formatCartGoods($cartGoods, $isAdvanceCart, $isValid = true) | ||
570 | + { | ||
571 | + $arr = array(); | ||
572 | + | ||
573 | + $oneGoods = array(); | ||
574 | + foreach ($cartGoods as $key => $value) { | ||
575 | + $oneGoods = array(); | ||
576 | + $oneGoods['id'] = $value['product_sku']; | ||
577 | + $oneGoods['skn'] = $value['product_skn']; | ||
578 | + $oneGoods['name'] = $value['product_name']; | ||
579 | + $oneGoods['thumb'] = !empty($value['goods_images']) ? Images::getImageUrl($value['goods_images'], 120, 160) : ''; | ||
580 | + $oneGoods['color'] = $value['color_name']; | ||
581 | + $oneGoods['size'] = $value['size_name']; | ||
582 | + $oneGoods['checked'] = $value['selected'] === 'Y'; | ||
583 | + $oneGoods['price'] = self::transPrice($value['last_vip_price']); | ||
584 | + $oneGoods['isVipPrice'] = $value['sales_price'] !== $value['last_vip_price']; | ||
585 | + $oneGoods['count'] = $value['buy_number']; | ||
586 | + | ||
587 | + if ($isValid) { | ||
588 | + // 库存不足 | ||
589 | + $oneGoods['lowStocks'] = ($value['buy_number'] > $value['storage_number']); | ||
590 | + } else { // 失效商品 | ||
591 | + $oneGoods['inValid'] = true; | ||
592 | + } | ||
593 | + | ||
594 | + //gift=>是否赠品,advanceBuy=>是否加价购,soldOut=>失效商品; | ||
595 | + if (!isset($value['goods_type'])) { | ||
596 | + $oneGoods['inValid'] = true; | ||
597 | + } elseif ($value['goods_type'] == 'gift' && !isset($value['isAdvanceBuy'])) { | ||
598 | + $oneGoods['isGift'] = true; | ||
599 | + $oneGoods['salesPrice'] = self::transPrice($value['sales_price']); | ||
600 | + $oneGoods['price'] = self::transPrice($value['last_price']); | ||
601 | + } elseif ($value['goods_type'] == 'price_gift') { | ||
602 | + $oneGoods['showCheckbox'] = true; | ||
603 | + $oneGoods['isAdvanceBuy'] = true; | ||
604 | + $oneGoods['salesPrice'] = self::transPrice($value['sales_price']); | ||
605 | + $oneGoods['price'] = self::transPrice($value['last_price']); | ||
606 | + } else { | ||
607 | + $oneGoods['showCheckbox'] = true; | ||
608 | + } | ||
609 | + | ||
610 | + // 上市期 | ||
611 | + if ($isAdvanceCart && !empty($value['expect_arrival_time'])) { | ||
612 | + $oneGoods['appearDate'] = $value['expect_arrival_time']; | ||
613 | + } | ||
614 | + // 商品链接 | ||
615 | + $oneGoods['link'] = self::url('/product/show_' . $value['product_skn'] . '.html'); | ||
616 | + | ||
617 | + $arr[$key] = $oneGoods; | ||
618 | + } | ||
619 | + | ||
620 | + return $arr; | ||
621 | + } | ||
622 | + | ||
623 | + /** | ||
624 | + * 格式化加价购和赠品商品 | ||
625 | + * | ||
626 | + * @param array $advanceGoods 加价购商品列表 | ||
627 | + * @param int $count 计商品件数 | ||
628 | + * @return array $arr 处理之后的加价购商品数据 | ||
629 | + */ | ||
630 | + public static function formatAdvanceGoods($advanceGoods, &$count = 0) | ||
631 | + { | ||
632 | + $arr = array(); | ||
633 | + | ||
634 | + $gift = array(); | ||
635 | + $oneGoods = array(); | ||
636 | + $number = 0; | ||
637 | + foreach ($advanceGoods as $value) { | ||
638 | + $gift = array(); | ||
639 | + $gift['promotionId'] = $value['promotion_id']; | ||
640 | + $gift['promotionTitle'] = $value['promotion_title']; | ||
641 | + | ||
642 | + $number = 0; | ||
643 | + foreach ($value['goods_list'] as $single) { | ||
644 | + $oneGoods = array(); | ||
645 | + $oneGoods['id'] = $single['product_skn']; | ||
646 | + $oneGoods['name'] = $single['product_name']; | ||
647 | + $oneGoods['thumb'] = !empty($single['goods_images']) ? Images::getImageUrl($single['goods_images'], 120, 160) : ''; | ||
648 | + $oneGoods['price'] = self::transPrice($single['last_price']); | ||
649 | + $oneGoods['marketPrice'] = self::transPrice($single['market_price']); | ||
650 | + $oneGoods['count'] = $single['storage_number']; | ||
651 | + | ||
652 | + $gift['goods'][] = $oneGoods; | ||
653 | + $number ++; | ||
654 | + } | ||
655 | + | ||
656 | + $arr[] = $gift; | ||
657 | + | ||
658 | + // 计算加价购商品数目 | ||
659 | + //$count += count($value['goods_list']); | ||
660 | + $count += $number; | ||
661 | + } | ||
662 | + | ||
663 | + return $arr; | ||
664 | + } | ||
665 | + | ||
666 | + /** | ||
667 | + * 订单状态,按订单支付类型和订单状态 | ||
668 | + * @var array | ||
669 | + */ | ||
670 | + public static function getOrderStatus() | ||
671 | + { | ||
672 | + return array( | ||
673 | + '1' => array(//在线支付 | ||
674 | + 0 => '待付款', | ||
675 | + 1 => '已付款', | ||
676 | + 2 => '已付款', | ||
677 | + 3 => '已付款', | ||
678 | + 4 => '已发货', | ||
679 | + 5 => '已发货', | ||
680 | + 6 => '交易成功' | ||
681 | + ), | ||
682 | + '2' => array(//货到付款 | ||
683 | + 0 => '备货中', | ||
684 | + 1 => '已付款', | ||
685 | + 2 => '已付款', | ||
686 | + 3 => '已付款', | ||
687 | + 4 => '已发货', | ||
688 | + 5 => '已发货', | ||
689 | + 6 => '交易成功' | ||
690 | + ), | ||
691 | + '3' => array(//现金支付 | ||
692 | + 0 => '待付款', | ||
693 | + 1 => '已付款', | ||
694 | + 2 => '已付款', | ||
695 | + 3 => '已付款', | ||
696 | + 4 => '已发货', | ||
697 | + 5 => '已发货', | ||
698 | + 6 => '交易成功' | ||
699 | + ), | ||
700 | + '4' => array(//抵消支付 | ||
701 | + 0 => '待付款', | ||
702 | + 1 => '已付款', | ||
703 | + 2 => '已付款', | ||
704 | + 3 => '已付款', | ||
705 | + 4 => '已发货', | ||
706 | + 5 => '已发货', | ||
707 | + 6 => '交易成功' | ||
708 | + ) | ||
709 | + ); | ||
710 | + } | ||
711 | + | ||
712 | + /** | ||
713 | + * 获取会员的级别 | ||
714 | + * | ||
715 | + * @param string $vipInfo | ||
716 | + * @return int | ||
717 | + */ | ||
718 | + public static function getVipLevel($vipInfo) | ||
719 | + { | ||
720 | + $vipLevel = 0; | ||
721 | + | ||
722 | + switch ($vipInfo) { | ||
723 | + case '普通会员': | ||
724 | + $vipLevel = 0; | ||
725 | + break; | ||
726 | + case '银卡会员': | ||
727 | + $vipLevel = 1; | ||
728 | + break; | ||
729 | + case '金卡会员': | ||
730 | + $vipLevel = 2; | ||
731 | + break; | ||
732 | + case '白金会员': | ||
733 | + $vipLevel = 3; | ||
734 | + break; | ||
735 | + } | ||
736 | + | ||
737 | + return $vipLevel; | ||
738 | + } | ||
739 | + | ||
740 | + /** | ||
741 | + * 同步用户的会话 | ||
742 | + * | ||
743 | + * 转向老的PHP服务器上处理, 因购物车相关的操作会依赖SESSION | ||
744 | + * | ||
745 | + * @param int $uid 用户ID | ||
746 | + * @param string $refer 访问来源 | ||
747 | + * @param string $callback 回调方法名 | ||
748 | + * @return string | ||
749 | + */ | ||
750 | + public static function syncUserSession($uid, $refer = '', $callback = 'call') | ||
751 | + { | ||
752 | + return 'http://mapi.yohobuy.com/Passport/session/index?callback=' . $callback | ||
753 | + . '&sign=' . md5(md5($uid . 'Js8Yn0!EwPM45-ws')) . '&uid=' . $uid . '&go=' . $refer; | ||
754 | + } | ||
755 | + | ||
756 | + /** | ||
757 | + * 退出清除用户的会话 | ||
758 | + * | ||
759 | + * 转向老的PHP服务器上处理, 因购物车相关的操作会依赖SESSION | ||
760 | + * | ||
761 | + * @param int $uid 用户ID | ||
762 | + * @param string $refer 访问来源 | ||
763 | + * @param string $callback 回调方法名 | ||
764 | + * @return string | ||
765 | + */ | ||
766 | + public static function logoutSession($token, $refer = '', $callback = 'call') | ||
767 | + { | ||
768 | + return 'http://mapi.yohobuy.com/Passport/session/logout?callback=' . $callback | ||
769 | + . '&sign=' . md5(md5('Js8Yn0!EwPM45-ws')) . '&token=' . $token . '&go=' . $refer; | ||
770 | + } | ||
771 | + | ||
772 | +} |
1 | -<?php | ||
2 | - | ||
3 | -/** | ||
4 | - * User: Zip | ||
5 | - * Date: 15/10/28 | ||
6 | - * Time: 下午13:08 | ||
7 | - */ | ||
8 | - | ||
9 | -namespace Plugin; | ||
10 | - | ||
11 | -class Images | ||
12 | -{ | ||
13 | - | ||
14 | - private static $domain = '.static.yhbimg.com'; | ||
15 | - private static $default_image = '/2015/08/25/02/01dd632a6e07bfef457ce4beda21dd6413.png'; | ||
16 | - private static $domainList = array( | ||
17 | - '01' => array( | ||
18 | - 'img10.static.yhbimg.com', | ||
19 | - 'img11.static.yhbimg.com', | ||
20 | - ), | ||
21 | - '02' => array( | ||
22 | - 'img12.static.yhbimg.com', | ||
23 | - 'img13.static.yhbimg.com' | ||
24 | - ), | ||
25 | - 'yhb-head' => 'head.static.yhbimg.com' | ||
26 | - ); | ||
27 | - private static $qiniuDomain = 'yhfair.qiniudn.com'; | ||
28 | - | ||
29 | - /** | ||
30 | - * 缩略图模板 | ||
31 | - * @param $fileName | ||
32 | - * @param $bucket | ||
33 | - * @param string $position () | ||
34 | - * @param string $background | ||
35 | - * @return string | ||
36 | - */ | ||
37 | - static function template($fileName, $bucket = 'yhfair', $mode = 1) | ||
38 | - { | ||
39 | - return self::url($fileName, $bucket, $mode); | ||
40 | - } | ||
41 | - | ||
42 | - /** | ||
43 | - * | ||
44 | - * @param unknown $fileName | ||
45 | - * @param string $bucket | ||
46 | - * @return string | ||
47 | - */ | ||
48 | - public static function getSourceUrl($fileName, $bucket = 'yhfair') | ||
49 | - { | ||
50 | - if (stripos($fileName, 'http://') === 0) { | ||
51 | - return $fileName; | ||
52 | - } | ||
53 | - $domain = self::getDomain($bucket, $fileName); | ||
54 | - return 'http://' . $domain . '/' . $bucket . $fileName; | ||
55 | - } | ||
56 | - | ||
57 | - /** | ||
58 | - * 根据尺寸获得图片url | ||
59 | - * @param unknown $fileName | ||
60 | - * @param unknown $width | ||
61 | - * @param unknown $height | ||
62 | - * @param number $mode | ||
63 | - * @param string $bucket | ||
64 | - * @return mixed | ||
65 | - */ | ||
66 | - public static function getImageUrl($fileName, $width, $height, $mode = 2, $bucket = 'goodsimg') | ||
67 | - { | ||
68 | - if (!is_string($fileName)) { | ||
69 | - return self::template(self::$default_image, $bucket, $mode); | ||
70 | - } | ||
71 | - if (stripos($fileName, 'http://') !== 0) { | ||
72 | - $fileName = self::template($fileName, $bucket, $mode); | ||
73 | - } | ||
74 | - return strtr($fileName, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode)); | ||
75 | - } | ||
76 | - | ||
77 | - /** | ||
78 | - * 获取图片URL模板 | ||
79 | - * @param $fileName | ||
80 | - * @param int $mode | ||
81 | - * @param string $bucket | ||
82 | - * @return string | ||
83 | - */ | ||
84 | - public static function url($fileName, $bucket = 'yhfair', $mode = 1) | ||
85 | - { | ||
86 | - $domain = self::getDomain($bucket, $fileName); | ||
87 | - return self::getImgTemplateUrl($bucket . $fileName, $mode, $domain); | ||
88 | - } | ||
89 | - | ||
90 | - public static function getDomain($bucket, $fileName) | ||
91 | - { | ||
92 | - $domain = ''; | ||
93 | - if (!empty(self::$domainList[$bucket])) { | ||
94 | - $domain = self::$domainList[$bucket]; | ||
95 | - } else { | ||
96 | - $node = mb_substr($fileName, 15, 2); | ||
97 | - if (!empty(self::$domainList[$node])) { | ||
98 | - $domainList = self::$domainList[$node]; | ||
99 | - $nodeNum = sprintf('%u', crc32($fileName)) % count($domainList); | ||
100 | - $domain = $domainList[$nodeNum]; | ||
101 | - } | ||
102 | - } | ||
103 | - return $domain; | ||
104 | - } | ||
105 | - | ||
106 | - | ||
107 | - /** | ||
108 | - * 图片上传 | ||
109 | - * @param string $name 文件表单name, 即用于$_FILES[$name] | ||
110 | - */ | ||
111 | - public static function saveImage($name) | ||
112 | - { | ||
113 | - if (empty($_FILES[$name])) | ||
114 | - { | ||
115 | - return array(); | ||
116 | - } | ||
117 | - $files = $_FILES[$name]; | ||
118 | - $images = array(); | ||
119 | - if (is_array($files['tmp_name'])) | ||
120 | - { | ||
121 | - foreach ($files['tmp_name'] as $k => $tmp_name) | ||
122 | - { | ||
123 | - if(!empty($tmp_name)) | ||
124 | - { | ||
125 | - $images[$files['name'][$k]] = $tmp_name; | ||
126 | - } | ||
127 | - } | ||
128 | - } | ||
129 | - else | ||
130 | - { | ||
131 | - $images[$files['name']] = $files['tmp_name']; | ||
132 | - } | ||
133 | - | ||
134 | - return self::uploadStreamImage($images); | ||
135 | - } | ||
136 | - | ||
137 | - /** | ||
138 | - * 上传图片[图片上传域名限制于http://test.service.api.yohobuy.com] | ||
139 | - * | ||
140 | - * @param string | array(filename => absolute file path) $file | ||
141 | - * url:http://upload.static.yohobuy.com?project=sns&fileData=xxx | ||
142 | - * @return mixed | ||
143 | - */ | ||
144 | - public static function uploadStreamImage($file) | ||
145 | - { | ||
146 | - $end ="\r\n"; | ||
147 | - $twoHyphens ="--"; | ||
148 | - $boundary = "*****"; | ||
149 | - $stream = ''; | ||
150 | - $files = is_array($file) ? $file : array($file); | ||
151 | - foreach($files as $name => $filename) | ||
152 | - { | ||
153 | - if(!file_exists($filename)) | ||
154 | - { | ||
155 | - continue; | ||
156 | - } | ||
157 | - $name = is_numeric($name) ? name.'.jpg' : $name; | ||
158 | - $stream .= $twoHyphens.$boundary.$end; | ||
159 | - $stream .="Content-Disposition: form-data; "."name=\"fileData\";filename=\"".$name ."\"".$end; // form file element name :fileData | ||
160 | - $stream .= $end; | ||
161 | - $stream .= file_get_contents($filename); | ||
162 | - $stream .= $end; | ||
163 | - } | ||
164 | - if(empty($stream)) | ||
165 | - { | ||
166 | - return false; | ||
167 | - } | ||
168 | - $stream .= $twoHyphens.$boundary.$end; | ||
169 | - $stream .="Content-Disposition: form-data; "."name=\"project\"".$end; | ||
170 | - $stream .= $end; | ||
171 | - $stream .= "suggest";//project sns | ||
172 | - $stream .= $end; | ||
173 | - $stream .= $twoHyphens .$boundary .$twoHyphens .$end; | ||
174 | - $opts = array( | ||
175 | - 'http' => array( | ||
176 | - 'method' => 'POST', | ||
177 | - 'header' => 'content-type:multipart/form-data;boundary='.$boundary, | ||
178 | - 'content' => $stream | ||
179 | - ) | ||
180 | - ); | ||
181 | - $context = stream_context_create($opts); | ||
182 | - $result = json_decode(file_get_contents('http://upload.static.yohobuy.com', false, $context), true); | ||
183 | - if(!empty($result['data']['imagesList'])) | ||
184 | - { | ||
185 | - $imgExtra = '?imageMogr2/thumbnail/130x130/extent/130x130/background/d2hpdGU=/position/center/quality/90'; | ||
186 | - $imgList = array('imgList'=>array()); | ||
187 | - | ||
188 | - if(count($file) == 1 || !is_array($file)) | ||
189 | - { | ||
190 | - $imgRelUrl = current($result['data']['imagesList']); | ||
191 | - $imgList['imgList'][] = array( | ||
192 | - 'imgUrl' => self::getSourceUrl($imgRelUrl, 'suggest') . $imgExtra, | ||
193 | - 'imgRelUrl' => $imgRelUrl | ||
194 | - ); | ||
195 | - } | ||
196 | - else | ||
197 | - { | ||
198 | - $img = array(); | ||
199 | - foreach ($result['data']['imagesList'] as $val) { | ||
200 | - $img = array(); | ||
201 | - $img['imgUrl'] = self::getSourceUrl($val, 'suggest') . $imgExtra; | ||
202 | - $img['imgRelUrl'] = $val; | ||
203 | - $imgList['imgList'][] = $img; | ||
204 | - } | ||
205 | - } | ||
206 | - | ||
207 | - return $imgList; | ||
208 | - } | ||
209 | - else | ||
210 | - { | ||
211 | - return false; | ||
212 | - } | ||
213 | - } | ||
214 | - | ||
215 | - /** | ||
216 | - * 获取模板的图片地址 | ||
217 | - * @param $fileName | ||
218 | - * @param int $width | ||
219 | - * @param int $height | ||
220 | - * @param int $mode | ||
221 | - * @param null $domain | ||
222 | - * @return string | ||
223 | - */ | ||
224 | - private static function getImgTemplateUrl($fileName, $mode = 1, $domain = null) | ||
225 | - { | ||
226 | - if ($domain == null) { | ||
227 | - $domain = self::$qiniuDomain; | ||
228 | - } | ||
229 | - $baseUrl = self::MakeBaseUrl($domain, $fileName); | ||
230 | - return self::MakeTemplateRequest($baseUrl); | ||
231 | - } | ||
232 | - | ||
233 | - private static function MakeBaseUrl($domain, $key) // => $baseUrl | ||
234 | - { | ||
235 | - $keyEsc = str_replace("%2F", "/", rawurlencode($key)); | ||
236 | - return "http://$domain/$keyEsc"; | ||
237 | - } | ||
238 | - | ||
239 | - private static function MakeTemplateRequest($url) | ||
240 | - { | ||
241 | - $ops = array(); | ||
242 | - $ops[] = '{mode}'; | ||
243 | - $ops[] = 'w/{width}'; | ||
244 | - $ops[] = 'h/{height}'; | ||
245 | - | ||
246 | - if (empty($ops)) { | ||
247 | - return $url; | ||
248 | - } | ||
249 | - | ||
250 | - return $url . "?imageView/" . implode('/', $ops); | ||
251 | - } | ||
252 | - | ||
253 | -} | 1 | +<?php |
2 | + | ||
3 | +/** | ||
4 | + * User: Zip | ||
5 | + * Date: 15/10/28 | ||
6 | + * Time: 下午13:08 | ||
7 | + */ | ||
8 | + | ||
9 | +namespace Plugin; | ||
10 | + | ||
11 | +class Images | ||
12 | +{ | ||
13 | + | ||
14 | + private static $domain = '.static.yhbimg.com'; | ||
15 | + private static $default_image = '/2015/08/25/02/01dd632a6e07bfef457ce4beda21dd6413.png'; | ||
16 | + private static $domainList = array( | ||
17 | + '01' => array( | ||
18 | + 'img10.static.yhbimg.com', | ||
19 | + 'img11.static.yhbimg.com', | ||
20 | + ), | ||
21 | + '02' => array( | ||
22 | + 'img12.static.yhbimg.com', | ||
23 | + 'img13.static.yhbimg.com' | ||
24 | + ), | ||
25 | + 'yhb-head' => 'head.static.yhbimg.com' | ||
26 | + ); | ||
27 | + private static $qiniuDomain = 'yhfair.qiniudn.com'; | ||
28 | + | ||
29 | + /** | ||
30 | + * 缩略图模板 | ||
31 | + * @param $fileName | ||
32 | + * @param $bucket | ||
33 | + * @param string $position () | ||
34 | + * @param string $background | ||
35 | + * @return string | ||
36 | + */ | ||
37 | + static function template($fileName, $bucket = 'yhfair', $mode = 1) | ||
38 | + { | ||
39 | + return self::url($fileName, $bucket, $mode); | ||
40 | + } | ||
41 | + | ||
42 | + /** | ||
43 | + * | ||
44 | + * @param unknown $fileName | ||
45 | + * @param string $bucket | ||
46 | + * @return string | ||
47 | + */ | ||
48 | + public static function getSourceUrl($fileName, $bucket = 'yhfair') | ||
49 | + { | ||
50 | + if (stripos($fileName, 'http://') === 0) { | ||
51 | + return $fileName; | ||
52 | + } | ||
53 | + $domain = self::getDomain($bucket, $fileName); | ||
54 | + return 'http://' . $domain . '/' . $bucket . $fileName; | ||
55 | + } | ||
56 | + | ||
57 | + /** | ||
58 | + * 根据尺寸获得图片url | ||
59 | + * @param unknown $fileName | ||
60 | + * @param unknown $width | ||
61 | + * @param unknown $height | ||
62 | + * @param number $mode | ||
63 | + * @param string $bucket | ||
64 | + * @return mixed | ||
65 | + */ | ||
66 | + public static function getImageUrl($fileName, $width, $height, $mode = 2, $bucket = 'goodsimg') | ||
67 | + { | ||
68 | + if (!is_string($fileName)) { | ||
69 | + return self::template(self::$default_image, $bucket, $mode); | ||
70 | + } | ||
71 | + if (stripos($fileName, 'http://') !== 0) { | ||
72 | + $fileName = self::template($fileName, $bucket, $mode); | ||
73 | + } | ||
74 | + return strtr($fileName, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode)); | ||
75 | + } | ||
76 | + | ||
77 | + /** | ||
78 | + * 获取图片URL模板 | ||
79 | + * @param $fileName | ||
80 | + * @param int $mode | ||
81 | + * @param string $bucket | ||
82 | + * @return string | ||
83 | + */ | ||
84 | + public static function url($fileName, $bucket = 'yhfair', $mode = 1) | ||
85 | + { | ||
86 | + $domain = self::getDomain($bucket, $fileName); | ||
87 | + return self::getImgTemplateUrl($bucket . $fileName, $mode, $domain); | ||
88 | + } | ||
89 | + | ||
90 | + public static function getDomain($bucket, $fileName) | ||
91 | + { | ||
92 | + $domain = ''; | ||
93 | + if (!empty(self::$domainList[$bucket])) { | ||
94 | + $domain = self::$domainList[$bucket]; | ||
95 | + } else { | ||
96 | + $node = mb_substr($fileName, 15, 2); | ||
97 | + if (!empty(self::$domainList[$node])) { | ||
98 | + $domainList = self::$domainList[$node]; | ||
99 | + $nodeNum = sprintf('%u', crc32($fileName)) % count($domainList); | ||
100 | + $domain = $domainList[$nodeNum]; | ||
101 | + } | ||
102 | + } | ||
103 | + return $domain; | ||
104 | + } | ||
105 | + | ||
106 | + /** | ||
107 | + * 图片上传 | ||
108 | + * @param string $name 文件表单name, 即用于$_FILES[$name] | ||
109 | + */ | ||
110 | + public static function saveImage($name) | ||
111 | + { | ||
112 | + if (empty($_FILES[$name])) { | ||
113 | + return array(); | ||
114 | + } | ||
115 | + $files = $_FILES[$name]; | ||
116 | + $images = array(); | ||
117 | + if (is_array($files['tmp_name'])) { | ||
118 | + foreach ($files['tmp_name'] as $k => $tmp_name) { | ||
119 | + if (!empty($tmp_name)) { | ||
120 | + $images[$files['name'][$k]] = $tmp_name; | ||
121 | + } | ||
122 | + } | ||
123 | + } else { | ||
124 | + $images[$files['name']] = $files['tmp_name']; | ||
125 | + } | ||
126 | + | ||
127 | + return self::uploadStreamImage($images); | ||
128 | + } | ||
129 | + | ||
130 | + /** | ||
131 | + * 上传图片[图片上传域名限制于http://test.service.api.yohobuy.com] | ||
132 | + * | ||
133 | + * @param string | array(filename => absolute file path) $file | ||
134 | + * url:http://upload.static.yohobuy.com?project=sns&fileData=xxx | ||
135 | + * @return mixed | ||
136 | + */ | ||
137 | + public static function uploadStreamImage($file) | ||
138 | + { | ||
139 | + $end = "\r\n"; | ||
140 | + $twoHyphens = "--"; | ||
141 | + $boundary = "*****"; | ||
142 | + $stream = ''; | ||
143 | + $files = is_array($file) ? $file : array($file); | ||
144 | + foreach ($files as $name => $filename) { | ||
145 | + if (!file_exists($filename)) { | ||
146 | + continue; | ||
147 | + } | ||
148 | + $name = is_numeric($name) ? name . '.jpg' : $name; | ||
149 | + $stream .= $twoHyphens . $boundary . $end; | ||
150 | + $stream .="Content-Disposition: form-data; " . "name=\"fileData\";filename=\"" . $name . "\"" . $end; // form file element name :fileData | ||
151 | + $stream .= $end; | ||
152 | + $stream .= file_get_contents($filename); | ||
153 | + $stream .= $end; | ||
154 | + } | ||
155 | + if (empty($stream)) { | ||
156 | + return false; | ||
157 | + } | ||
158 | + $stream .= $twoHyphens . $boundary . $end; | ||
159 | + $stream .="Content-Disposition: form-data; " . "name=\"project\"" . $end; | ||
160 | + $stream .= $end; | ||
161 | + $stream .= "suggest"; //project sns | ||
162 | + $stream .= $end; | ||
163 | + $stream .= $twoHyphens . $boundary . $twoHyphens . $end; | ||
164 | + $opts = array( | ||
165 | + 'http' => array( | ||
166 | + 'method' => 'POST', | ||
167 | + 'header' => 'content-type:multipart/form-data;boundary=' . $boundary, | ||
168 | + 'content' => $stream | ||
169 | + ) | ||
170 | + ); | ||
171 | + $context = stream_context_create($opts); | ||
172 | + $result = json_decode(file_get_contents('http://upload.static.yohobuy.com', false, $context), true); | ||
173 | + if (!empty($result['data']['imagesList'])) { | ||
174 | + $imgExtra = '?imageMogr2/thumbnail/130x130/extent/130x130/background/d2hpdGU=/position/center/quality/90'; | ||
175 | + $imgList = array('imgList' => array()); | ||
176 | + | ||
177 | + if (count($file) == 1 || !is_array($file)) { | ||
178 | + $imgRelUrl = current($result['data']['imagesList']); | ||
179 | + $imgList['imgList'][] = array( | ||
180 | + 'imgUrl' => self::getSourceUrl($imgRelUrl, 'suggest') . $imgExtra, | ||
181 | + 'imgRelUrl' => $imgRelUrl | ||
182 | + ); | ||
183 | + } else { | ||
184 | + $img = array(); | ||
185 | + foreach ($result['data']['imagesList'] as $val) { | ||
186 | + $img = array(); | ||
187 | + $img['imgUrl'] = self::getSourceUrl($val, 'suggest') . $imgExtra; | ||
188 | + $img['imgRelUrl'] = $val; | ||
189 | + $imgList['imgList'][] = $img; | ||
190 | + } | ||
191 | + } | ||
192 | + | ||
193 | + return $imgList; | ||
194 | + } else { | ||
195 | + return false; | ||
196 | + } | ||
197 | + } | ||
198 | + | ||
199 | + /** | ||
200 | + * 获取模板的图片地址 | ||
201 | + * @param $fileName | ||
202 | + * @param int $width | ||
203 | + * @param int $height | ||
204 | + * @param int $mode | ||
205 | + * @param null $domain | ||
206 | + * @return string | ||
207 | + */ | ||
208 | + private static function getImgTemplateUrl($fileName, $mode = 1, $domain = null) | ||
209 | + { | ||
210 | + if ($domain == null) { | ||
211 | + $domain = self::$qiniuDomain; | ||
212 | + } | ||
213 | + $baseUrl = self::MakeBaseUrl($domain, $fileName); | ||
214 | + return self::MakeTemplateRequest($baseUrl); | ||
215 | + } | ||
216 | + | ||
217 | + private static function MakeBaseUrl($domain, $key) // => $baseUrl | ||
218 | + { | ||
219 | + $keyEsc = str_replace("%2F", "/", rawurlencode($key)); | ||
220 | + return "http://$domain/$keyEsc"; | ||
221 | + } | ||
222 | + | ||
223 | + private static function MakeTemplateRequest($url) | ||
224 | + { | ||
225 | + $ops = array(); | ||
226 | + $ops[] = '{mode}'; | ||
227 | + $ops[] = 'w/{width}'; | ||
228 | + $ops[] = 'h/{height}'; | ||
229 | + | ||
230 | + if (empty($ops)) { | ||
231 | + return $url; | ||
232 | + } | ||
233 | + | ||
234 | + return $url . "?imageView/" . implode('/', $ops); | ||
235 | + } | ||
236 | + | ||
237 | +} |
-
Please register or login to post a comment