Showing
1 changed file
with
173 additions
and
170 deletions
1 | -<?php | ||
2 | - | ||
3 | -namespace LibModels\Wap\Product; | ||
4 | - | ||
5 | -use Api\Yohobuy; | ||
6 | -use Api\Sign; | ||
7 | - | ||
8 | -/** | ||
9 | - * 搜索有关数据操作类 | ||
10 | - * | ||
11 | - * @name SearchData | ||
12 | - * @package Library/LibModels/wap/Product | ||
13 | - * @copyright yoho.inc | ||
14 | - * @version 1.0 (2015-10-8) | ||
15 | - * @author gtskk <rocky.zhang@yoho.cn> | ||
16 | - */ | ||
17 | -class SearchData | ||
18 | -{ | ||
19 | - | ||
20 | - /** | ||
21 | - * 获取搜索的服务地址 | ||
22 | - * | ||
23 | - * 备注:此处是根据环境来确定使用阿里云内网还是外网的URL | ||
24 | - * | ||
25 | - * @return string | ||
26 | - */ | ||
27 | - private static function getSearchUrl() | ||
28 | - { | ||
29 | - defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer'); | ||
30 | - switch (APPLICATION_ENV) { | ||
31 | - case 'release': | ||
32 | - return 'http://100.98.132.63/yohosearch/search.json'; | ||
33 | - case 'test': | ||
34 | - case 'preview': | ||
35 | - case 'developer': | ||
36 | - default: | ||
37 | - return 'http://101.200.31.165/yohosearch/search.json'; | ||
38 | - } | ||
39 | - } | ||
40 | - | ||
41 | - /** | ||
42 | - * 模糊搜索提供的关键词 | ||
43 | - * | ||
44 | - * @param string $keyword 关键词 | ||
45 | - * @return array 根据给定关键词搜索到的结果,包括数据数目count和提供的关键词keyword | ||
46 | - */ | ||
47 | - public static function searchFuzzyDatas($keyword) | ||
48 | - { | ||
49 | - // 构建必传参数 | ||
50 | - $param = Yohobuy::param(); | ||
51 | - | ||
52 | - $param['keyword'] = $keyword; | ||
53 | - $param['method'] = 'app.search.fuzzy'; | ||
54 | - $param['client_secret'] = Sign::getSign($param); | ||
55 | - | ||
56 | - return Yohobuy::get(Yohobuy::API_URL, $param); | ||
57 | - } | ||
58 | - | ||
59 | - /** | ||
60 | - * 根据给定查询数据搜索数据列表 (老的) | ||
61 | - * | ||
62 | - * @param string $query 查询条件, 默认为null | ||
63 | - * @param string $brand 品牌,默认为null | ||
64 | - * @param string $gender 性别,默认为null,"1,3"表示男, "2,3"表示女, "1,2,3"表示全部 | ||
65 | - * @param integer $color 颜色id | ||
66 | - * @param integer $size 尺码id | ||
67 | - * @param integer $price 价格 | ||
68 | - * @param string $p_d 折扣,默认为null | ||
69 | - * @param string $sort 商品所属品类,默认为null | ||
70 | - * @param string $order 排序方式,默认为按照时间倒序排列s_t_desc, | ||
71 | - * s_t_asc表示按时间正序排列, | ||
72 | - * s_p_asc表示按价格正序排列, | ||
73 | - * s_p_desc表示按价格倒序排列, | ||
74 | - * p_d_asc表示按折扣正序排列, | ||
75 | - * p_d_desc表示按折扣倒序排列 | ||
76 | - * @param integer $page 指定查询是多少页,默认为第一页 | ||
77 | - * @param integer $limit 指定查询多少个,默认是60个 | ||
78 | - * @param integer $channel表示哪个频道,1表示男生,2表示女生,3表示潮童,4表示创意生活 | ||
79 | - * @return array 搜索到的数据 | ||
80 | - */ | ||
81 | - public static function searchByCondition($condition) | ||
82 | - { | ||
83 | - $param = Yohobuy::param(); | ||
84 | - $param['method'] = 'app.search.li'; | ||
85 | - if (!isset($condition['order'])) { | ||
86 | - $param['order'] = 's_t_desc'; | ||
87 | - } | ||
88 | - if (!isset($condition['page'])) { | ||
89 | - $param['page'] = 1; | ||
90 | - } | ||
91 | - if (!isset($condition['limit'])) { | ||
92 | - $param['limit'] = 60; | ||
93 | - } | ||
94 | - if (!empty($condition)) { | ||
95 | - $param += $condition; | ||
96 | - } | ||
97 | - $param['client_secret'] = Sign::getSign($param); | ||
98 | - | ||
99 | - return Yohobuy::get(Yohobuy::API_URL, $param); | ||
100 | - } | ||
101 | - | ||
102 | - /** | ||
103 | - * 根据给定查询数据搜索数据列表 (新的) | ||
104 | - * | ||
105 | - * @param string $query 查询条件, 默认为null | ||
106 | - * @param string $brand 品牌,默认为null | ||
107 | - * @param string $gender 性别,默认为null,"1,3"表示男, "2,3"表示女, "1,2,3"表示全部 | ||
108 | - * @param integer $color 颜色id | ||
109 | - * @param integer $size 尺码id | ||
110 | - * @param integer $price 价格 | ||
111 | - * @param string $p_d 折扣,默认为null | ||
112 | - * @param string $sort 商品所属品类,默认为null | ||
113 | - * @param string $order 排序方式,默认为按照时间倒序排列s_t_desc, | ||
114 | - * s_t_asc表示按时间正序排列, | ||
115 | - * s_p_asc表示按价格正序排列, | ||
116 | - * s_p_desc表示按价格倒序排列, | ||
117 | - * p_d_asc表示按折扣正序排列, | ||
118 | - * p_d_desc表示按折扣倒序排列 | ||
119 | - * @param integer $page 指定查询是多少页,默认为第一页 | ||
120 | - * @param integer $limit 指定查询多少个,默认是60个 | ||
121 | - * @param integer $channel表示哪个频道,1表示男生,2表示女生,3表示潮童,4表示创意生活 | ||
122 | - * @return array 搜索到的数据 | ||
123 | - */ | ||
124 | - public static function searchElasticByCondition($condition, $cache = false) | ||
125 | - { | ||
126 | - // 排序数据映射表 | ||
127 | - $orderMaps = array( | ||
128 | - 's_t_desc' => 'shelve_time:desc', | ||
129 | - 's_t_asc' => 'shelve_time:asc', | ||
130 | - 's_p_asc' => 'sales_price:asc', | ||
131 | - 's_p_desc' => 'sales_price:desc', | ||
132 | - 'p_d_desc' => 'discount:desc', | ||
133 | - 'p_d_asc' => 'discount:asc', | ||
134 | - 'skn_desc' => 'product_skn:desc', | ||
135 | - 'skn_asc' => 'product_skn:asc', | ||
136 | - 'activities_desc' => 'activities.order_by:desc', | ||
137 | - 'activities_asc' => 'activities.order_by:asc', | ||
138 | - 's_n_asc' => 'sales_num:asc', | ||
139 | - 's_n_desc' => 'sales_num:desc', | ||
140 | - 'activities_id_desc' => 'activities.activity_id:desc', | ||
141 | - 'activities_id_asc' => 'activities.activity_id:asc', | ||
142 | - ); | ||
143 | - | ||
144 | - $param = array(); | ||
145 | - $param['status'] = 1; // 是否上架,1表示在架,2表示不在 | ||
146 | - $param['sales'] = 'Y'; // 只搜索销售的产品 | ||
147 | - $param['stocknumber'] = 1; // 过滤掉已售罄的商品 | ||
148 | - // $param['needFilter'] = 1; // 是否需要返回筛选条件 | ||
149 | - if (!isset($condition['order'])) { | ||
150 | - $param['order'] = $orderMaps['s_t_desc']; | ||
151 | - } else { | ||
152 | - $param['order'] = $orderMaps[$condition['order']]; | ||
153 | - } | ||
154 | - if (!isset($condition['page'])) { | ||
155 | - $param['page'] = 1; | ||
156 | - } | ||
157 | - if (!isset($condition['limit'])) { | ||
158 | - $param['viewNum'] = 60; | ||
159 | - } else { | ||
160 | - $param['viewNum'] = $condition['limit']; | ||
161 | - unset($condition['limit']); | ||
162 | - } | ||
163 | - if (!empty($condition)) { | ||
164 | - $param += $condition; | ||
165 | - } | ||
166 | - | ||
167 | - return Yohobuy::get(self::getSearchUrl(), $param, $cache); | ||
168 | - } | ||
169 | - | ||
170 | -} | 1 | +<?php |
2 | + | ||
3 | +namespace LibModels\Wap\Product; | ||
4 | + | ||
5 | +use Api\Yohobuy; | ||
6 | +use Api\Sign; | ||
7 | + | ||
8 | +/** | ||
9 | + * 搜索有关数据操作类 | ||
10 | + * | ||
11 | + * @name SearchData | ||
12 | + * @package Library/LibModels/wap/Product | ||
13 | + * @copyright yoho.inc | ||
14 | + * @version 1.0 (2015-10-8) | ||
15 | + * @author gtskk <rocky.zhang@yoho.cn> | ||
16 | + */ | ||
17 | +class SearchData | ||
18 | +{ | ||
19 | + | ||
20 | + /** | ||
21 | + * 获取搜索的服务地址 | ||
22 | + * | ||
23 | + * 备注:此处是根据环境来确定使用阿里云内网还是外网的URL | ||
24 | + * | ||
25 | + * @return string | ||
26 | + */ | ||
27 | + private static function getSearchUrl() | ||
28 | + { | ||
29 | + defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer'); | ||
30 | + switch (APPLICATION_ENV) { | ||
31 | + case 'release': | ||
32 | + return 'http://100.98.132.63/yohosearch/search.json'; | ||
33 | + case 'test': | ||
34 | + case 'preview': | ||
35 | + case 'developer': | ||
36 | + default: | ||
37 | + return 'http://101.200.31.165/yohosearch/search.json'; | ||
38 | + } | ||
39 | + } | ||
40 | + | ||
41 | + /** | ||
42 | + * 模糊搜索提供的关键词 | ||
43 | + * | ||
44 | + * @param string $keyword 关键词 | ||
45 | + * @return array 根据给定关键词搜索到的结果,包括数据数目count和提供的关键词keyword | ||
46 | + */ | ||
47 | + public static function searchFuzzyDatas($keyword) | ||
48 | + { | ||
49 | + // 构建必传参数 | ||
50 | + $param = Yohobuy::param(); | ||
51 | + | ||
52 | + $param['keyword'] = $keyword; | ||
53 | + $param['method'] = 'app.search.fuzzy'; | ||
54 | + $param['client_secret'] = Sign::getSign($param); | ||
55 | + | ||
56 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
57 | + } | ||
58 | + | ||
59 | + /** | ||
60 | + * 根据给定查询数据搜索数据列表 (老的) | ||
61 | + * | ||
62 | + * @param string $query 查询条件, 默认为null | ||
63 | + * @param string $brand 品牌,默认为null | ||
64 | + * @param string $gender 性别,默认为null,"1,3"表示男, "2,3"表示女, "1,2,3"表示全部 | ||
65 | + * @param integer $color 颜色id | ||
66 | + * @param integer $size 尺码id | ||
67 | + * @param integer $price 价格 | ||
68 | + * @param string $p_d 折扣,默认为null | ||
69 | + * @param string $sort 商品所属品类,默认为null | ||
70 | + * @param string $order 排序方式,默认为按照时间倒序排列s_t_desc, | ||
71 | + * s_t_asc表示按时间正序排列, | ||
72 | + * s_p_asc表示按价格正序排列, | ||
73 | + * s_p_desc表示按价格倒序排列, | ||
74 | + * p_d_asc表示按折扣正序排列, | ||
75 | + * p_d_desc表示按折扣倒序排列 | ||
76 | + * @param integer $page 指定查询是多少页,默认为第一页 | ||
77 | + * @param integer $limit 指定查询多少个,默认是60个 | ||
78 | + * @param integer $channel表示哪个频道,1表示男生,2表示女生,3表示潮童,4表示创意生活 | ||
79 | + * @return array 搜索到的数据 | ||
80 | + */ | ||
81 | + public static function searchByCondition($condition) | ||
82 | + { | ||
83 | + $param = Yohobuy::param(); | ||
84 | + $param['method'] = 'app.search.li'; | ||
85 | + if (!isset($condition['order'])) { | ||
86 | + $param['order'] = 's_t_desc'; | ||
87 | + } | ||
88 | + if (!isset($condition['page'])) { | ||
89 | + $param['page'] = 1; | ||
90 | + } | ||
91 | + if (!isset($condition['limit'])) { | ||
92 | + $param['limit'] = 60; | ||
93 | + } | ||
94 | + if (!empty($condition)) { | ||
95 | + $param += $condition; | ||
96 | + } | ||
97 | + $param['client_secret'] = Sign::getSign($param); | ||
98 | + | ||
99 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
103 | + * 根据给定查询数据搜索数据列表 (新的) | ||
104 | + * | ||
105 | + * @param string $query 查询条件, 默认为null | ||
106 | + * @param string $brand 品牌,默认为null | ||
107 | + * @param string $gender 性别,默认为null,"1,3"表示男, "2,3"表示女, "1,2,3"表示全部 | ||
108 | + * @param integer $color 颜色id | ||
109 | + * @param integer $size 尺码id | ||
110 | + * @param integer $price 价格 | ||
111 | + * @param string $p_d 折扣,默认为null | ||
112 | + * @param string $sort 商品所属品类,默认为null | ||
113 | + * @param string $order 排序方式,默认为按照时间倒序排列s_t_desc, | ||
114 | + * s_t_asc表示按时间正序排列, | ||
115 | + * s_p_asc表示按价格正序排列, | ||
116 | + * s_p_desc表示按价格倒序排列, | ||
117 | + * p_d_asc表示按折扣正序排列, | ||
118 | + * p_d_desc表示按折扣倒序排列 | ||
119 | + * @param integer $page 指定查询是多少页,默认为第一页 | ||
120 | + * @param integer $limit 指定查询多少个,默认是60个 | ||
121 | + * @param integer $channel表示哪个频道,1表示男生,2表示女生,3表示潮童,4表示创意生活 | ||
122 | + * @return array 搜索到的数据 | ||
123 | + */ | ||
124 | + public static function searchElasticByCondition($condition, $cache = false) | ||
125 | + { | ||
126 | + // 排序数据映射表 | ||
127 | + $orderMaps = array( | ||
128 | + 's_t_desc' => 'shelve_time:desc', | ||
129 | + 's_t_asc' => 'shelve_time:asc', | ||
130 | + 's_p_asc' => 'sales_price:asc', | ||
131 | + 's_p_desc' => 'sales_price:desc', | ||
132 | + 'p_d_desc' => 'discount:desc', | ||
133 | + 'p_d_asc' => 'discount:asc', | ||
134 | + 'skn_desc' => 'product_skn:desc', | ||
135 | + 'skn_asc' => 'product_skn:asc', | ||
136 | + 'activities_desc' => 'activities.order_by:desc', | ||
137 | + 'activities_asc' => 'activities.order_by:asc', | ||
138 | + 's_n_asc' => 'sales_num:asc', | ||
139 | + 's_n_desc' => 'sales_num:desc', | ||
140 | + 'activities_id_desc' => 'activities.activity_id:desc', | ||
141 | + 'activities_id_asc' => 'activities.activity_id:asc', | ||
142 | + ); | ||
143 | + | ||
144 | + $param = array(); | ||
145 | + $param['status'] = 1; // 是否上架,1表示在架,2表示不在 | ||
146 | + $param['sales'] = 'Y'; // 只搜索销售的产品 | ||
147 | + $param['stocknumber'] = 1; // 过滤掉已售罄的商品 | ||
148 | + // $param['needFilter'] = 1; // 是否需要返回筛选条件 | ||
149 | + if (!isset($condition['order'])) { | ||
150 | + $param['order'] = $orderMaps['s_t_desc']; | ||
151 | + } else { | ||
152 | + $param['order'] = $orderMaps[$condition['order']]; | ||
153 | + } | ||
154 | + if (!isset($condition['page'])) { | ||
155 | + $param['page'] = 1; | ||
156 | + } | ||
157 | + | ||
158 | + if(isset($condition['viewNum'])) { | ||
159 | + $param['viewNum'] = $condition['viewNum']; | ||
160 | + } else if (!isset($condition['limit'])) { | ||
161 | + $param['viewNum'] = 60; | ||
162 | + } else { | ||
163 | + $param['viewNum'] = $condition['limit']; | ||
164 | + unset($condition['limit']); | ||
165 | + } | ||
166 | + if (!empty($condition)) { | ||
167 | + $param += $condition; | ||
168 | + } | ||
169 | + | ||
170 | + return Yohobuy::get(self::getSearchUrl(), $param, $cache); | ||
171 | + } | ||
172 | + | ||
173 | +} |
-
Please register or login to post a comment