更新搜索有关功能的逻辑,目前列表排序接口传参还存在问题,筛选传参也存在问题
Showing
13 changed files
with
196 additions
and
107 deletions
framework @ 75bbc3b0
@@ -36,7 +36,7 @@ class ClassData | @@ -36,7 +36,7 @@ class ClassData | ||
36 | * | 36 | * |
37 | * @param string $gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部 | 37 | * @param string $gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部 |
38 | * @param integer $brand 品牌Id | 38 | * @param integer $brand 品牌Id |
39 | - * @param integer $sort 品类Id | 39 | + * @param integer $sort 品类查询sort参数 |
40 | * @param integer $color 颜色Id | 40 | * @param integer $color 颜色Id |
41 | * @param integer $size 尺码Id | 41 | * @param integer $size 尺码Id |
42 | * @param string $price 价格 | 42 | * @param string $price 价格 |
1 | -<?php | ||
2 | - | ||
3 | -namespace Plugin\DataProcess; | ||
4 | - | ||
5 | -/** | ||
6 | - * 分类数据处理类 | ||
7 | - */ | ||
8 | -class ClassProcess | ||
9 | -{ | ||
10 | - | ||
11 | - /** | ||
12 | - * 处理品类数据 | ||
13 | - * @param $data | ||
14 | - * @return array 处理之后的品类数据 | ||
15 | - */ | ||
16 | - public static function getClassData($data) | ||
17 | - { | ||
18 | - $num = 1; | ||
19 | - $classes = array(); | ||
20 | - | ||
21 | - foreach ($data as $k => $v){ | ||
22 | - $oneClass = array('name'=>$k, 'ca'=>array()); | ||
23 | - if($num === 1) | ||
24 | - { | ||
25 | - $oneClass['focus'] = true; | ||
26 | - } | ||
27 | - | ||
28 | - foreach ($v as $val) { | ||
29 | - $item = array(); | ||
30 | - $item['name'] = $val['category_name']; | ||
31 | - foreach ($val['sub'] as $value) { | ||
32 | - $subitem = array(); | ||
33 | - $subitem['name'] = $value['category_name']; | ||
34 | - $subitem['url'] = $value['category_id']; | ||
35 | - | ||
36 | - $item['sub'][] = $subitem; | ||
37 | - } | ||
38 | - | ||
39 | - $oneClass['ca'][] = $item; | ||
40 | - } | ||
41 | - | ||
42 | - $num++; | ||
43 | - $classes[] = $oneClass; | ||
44 | - } | ||
45 | - | ||
46 | - return $classes; | ||
47 | - | ||
48 | - } | ||
49 | -} |
@@ -208,7 +208,7 @@ class ListProcess | @@ -208,7 +208,7 @@ class ListProcess | ||
208 | $category['dataId'] = $one['category_id']; | 208 | $category['dataId'] = $one['category_id']; |
209 | $category['name'] = $one['category_name']; | 209 | $category['name'] = $one['category_name']; |
210 | 210 | ||
211 | - // 子品类 | 211 | + /*// 子品类(目前h5不支持二级) |
212 | if(isset($one['sub'])) | 212 | if(isset($one['sub'])) |
213 | { | 213 | { |
214 | $category['subs'] = array(); | 214 | $category['subs'] = array(); |
@@ -219,7 +219,7 @@ class ListProcess | @@ -219,7 +219,7 @@ class ListProcess | ||
219 | 219 | ||
220 | $category['subs'][] = $subitem; | 220 | $category['subs'][] = $subitem; |
221 | } | 221 | } |
222 | - } | 222 | + }*/ |
223 | 223 | ||
224 | $result['subs'][] = $category; | 224 | $result['subs'][] = $category; |
225 | } | 225 | } |
@@ -25,7 +25,6 @@ class BoysController extends AbstractAction | @@ -25,7 +25,6 @@ class BoysController extends AbstractAction | ||
25 | 25 | ||
26 | // 渲染模板并输出 | 26 | // 渲染模板并输出 |
27 | $this->_view->display('index', array( | 27 | $this->_view->display('index', array( |
28 | - 'searchUrl' => '/search', | ||
29 | 'boysHomePage' => true, | 28 | 'boysHomePage' => true, |
30 | 'maybeLike' => true, | 29 | 'maybeLike' => true, |
31 | 'content' => Index\HomeModel::getBoysFloor() | 30 | 'content' => Index\HomeModel::getBoysFloor() |
@@ -25,7 +25,6 @@ class GirlsController extends AbstractAction | @@ -25,7 +25,6 @@ class GirlsController extends AbstractAction | ||
25 | 25 | ||
26 | // 渲染模板并输出 | 26 | // 渲染模板并输出 |
27 | $this->_view->display('index', array( | 27 | $this->_view->display('index', array( |
28 | - 'searchUrl' => '/search', | ||
29 | 'grilsHomePage' => true, | 28 | 'grilsHomePage' => true, |
30 | 'maybeLike' => true, | 29 | 'maybeLike' => true, |
31 | 'content' => Index\HomeModel::getGirlsFloor() | 30 | 'content' => Index\HomeModel::getGirlsFloor() |
@@ -25,7 +25,6 @@ class KidsController extends AbstractAction | @@ -25,7 +25,6 @@ class KidsController extends AbstractAction | ||
25 | 25 | ||
26 | // 渲染模板并输出 | 26 | // 渲染模板并输出 |
27 | $this->_view->display('index', array( | 27 | $this->_view->display('index', array( |
28 | - 'searchUrl' => '/search', | ||
29 | 'kidsHomePage' => true, | 28 | 'kidsHomePage' => true, |
30 | 'maybeLike' => true, | 29 | 'maybeLike' => true, |
31 | 'content' => Index\HomeModel::getKidsFloor() | 30 | 'content' => Index\HomeModel::getKidsFloor() |
@@ -25,7 +25,6 @@ class LifestyleController extends AbstractAction | @@ -25,7 +25,6 @@ class LifestyleController extends AbstractAction | ||
25 | 25 | ||
26 | // 渲染模板并输出 | 26 | // 渲染模板并输出 |
27 | $this->_view->display('index', array( | 27 | $this->_view->display('index', array( |
28 | - 'searchUrl' => '/search', | ||
29 | 'lifestyleHomePage' => true, | 28 | 'lifestyleHomePage' => true, |
30 | 'maybeLike' => true, | 29 | 'maybeLike' => true, |
31 | 'content' => Index\HomeModel::getLifestyleFloor() | 30 | 'content' => Index\HomeModel::getLifestyleFloor() |
@@ -57,37 +57,6 @@ class SearchController extends AbstractAction | @@ -57,37 +57,6 @@ class SearchController extends AbstractAction | ||
57 | 57 | ||
58 | $result = SearchData::searchFuzzyDatas($keyword); | 58 | $result = SearchData::searchFuzzyDatas($keyword); |
59 | 59 | ||
60 | - $this->_view->display('list', array('searchPage' => true, 'pageFooter' => true)); | ||
61 | - } | ||
62 | - } | ||
63 | - | ||
64 | - /** | ||
65 | - * 根据指定字符串查询数据 | ||
66 | - * | ||
67 | - * @return array 搜索的结果 | ||
68 | - */ | ||
69 | - public function listsearch() | ||
70 | - { | ||
71 | - $query = $this->get('query', ''); | ||
72 | - | ||
73 | - $result = SearchData::searchLiDatas($query); | ||
74 | - | ||
75 | - $this->echoJson($result); | ||
76 | - } | ||
77 | - | ||
78 | - /** | ||
79 | - * 根据指定条件筛选查询到数据 | ||
80 | - * | ||
81 | - * @return array 筛选之后的结果 | ||
82 | - */ | ||
83 | - public function sortsearch() | ||
84 | - { | ||
85 | - if($this->isAjax()) | ||
86 | - { | ||
87 | - $query = $this->post('query', ''); | ||
88 | - | ||
89 | - $result = SearchData::searchLiDatas($query); | ||
90 | - | ||
91 | $this->echoJson($result); | 60 | $this->echoJson($result); |
92 | } | 61 | } |
93 | } | 62 | } |
1 | +<?php | ||
2 | + | ||
3 | +namespace Category; | ||
4 | + | ||
5 | +use LibModels\Wap\Category\ClassData; | ||
6 | +use Configs\CacheConfig; | ||
7 | +use Plugin\Helpers; | ||
8 | +use Plugin\Cache; | ||
9 | + | ||
10 | +/** | ||
11 | + * 品牌相关的模板数据模型 | ||
12 | + * | ||
13 | + * @name BrandModel | ||
14 | + * @package Models/Category | ||
15 | + * @copyright yoho.inc | ||
16 | + * @version 1.0 (2015-10-21 13:52:44) | ||
17 | + * @author fei.hong <fei.hong@yoho.cn> | ||
18 | + */ | ||
19 | +class ClassModel | ||
20 | +{ | ||
21 | + | ||
22 | + /** | ||
23 | + * 根据频道获取品牌一览数据 | ||
24 | + * | ||
25 | + * @param int $channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道 | ||
26 | + * @return array | ||
27 | + */ | ||
28 | + public static function getClassData() | ||
29 | + { | ||
30 | + $classes = array(); | ||
31 | + | ||
32 | + if (USE_CACHE) { | ||
33 | + // 先尝试获取一级缓存(master), 有数据则直接返回. | ||
34 | + $result = Cache::get(CacheConfig::KEY_CATEGORY_CLASSES_DATA, 'master'); | ||
35 | + if (!empty($result)) { | ||
36 | + return $result; | ||
37 | + } | ||
38 | + } | ||
39 | + | ||
40 | + do { | ||
41 | + $num = 1; | ||
42 | + $data = ClassData::getClassesData(); | ||
43 | + | ||
44 | + if(!isset($data['code']) || $data['code'] !== 200) | ||
45 | + { | ||
46 | + break; | ||
47 | + } | ||
48 | + | ||
49 | + if(!isset($data['data'])) | ||
50 | + { | ||
51 | + break; | ||
52 | + } | ||
53 | + | ||
54 | + foreach ($data['data'] as $k => $v){ | ||
55 | + $oneClass = array('name'=>$k, 'ca'=>array()); | ||
56 | + if($num === 1) | ||
57 | + { | ||
58 | + $oneClass['focus'] = true; | ||
59 | + } | ||
60 | + | ||
61 | + foreach ($v as $val) { | ||
62 | + $item = array(); | ||
63 | + $item['name'] = $val['category_name']; | ||
64 | + $item['id'] = $val['relation_parameter']['sort']; | ||
65 | + foreach ($val['sub'] as $value) { | ||
66 | + $subitem = array(); | ||
67 | + $subitem['name'] = $value['category_name']; | ||
68 | + $subitem['id'] = $value['relation_parameter']['sort']; | ||
69 | + $subitem['url'] = $value['category_id']; | ||
70 | + | ||
71 | + $item['sub'][] = $subitem; | ||
72 | + } | ||
73 | + | ||
74 | + $oneClass['ca'][] = $item; | ||
75 | + } | ||
76 | + | ||
77 | + $num++; | ||
78 | + $classes[] = $oneClass; | ||
79 | + } | ||
80 | + | ||
81 | + if (USE_CACHE) { | ||
82 | + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据. | ||
83 | + if (empty($classes)) { | ||
84 | + $classes = Cache::get(CacheConfig::KEY_ACTION_INDEX_INDEX, 'slave'); | ||
85 | + } | ||
86 | + // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存 | ||
87 | + else { | ||
88 | + Cache::set(CacheConfig::KEY_ACTION_INDEX_INDEX, $classes); | ||
89 | + } | ||
90 | + } | ||
91 | + | ||
92 | + }while(false); | ||
93 | + | ||
94 | + return $classes; | ||
95 | + } | ||
96 | + | ||
97 | + | ||
98 | + /** | ||
99 | + * 返回品类构成的数组 | ||
100 | + * | ||
101 | + * @return array 键为品类查询sort参数,值为品类名称构成的数组 | ||
102 | + */ | ||
103 | + public static function getClassesArr() | ||
104 | + { | ||
105 | + $classes = array(); | ||
106 | + $classesData = self::getClassData(); | ||
107 | + | ||
108 | + foreach ($classesData as $val) { | ||
109 | + foreach ($val['ca'] as $single) { | ||
110 | + $classes[$single['id']] = $single['name']; | ||
111 | + $classes += array_column($single['sub'], 'name', 'id'); | ||
112 | + } | ||
113 | + } | ||
114 | + | ||
115 | + return $classes; | ||
116 | + } | ||
117 | + | ||
118 | +} |
1 | <?php | 1 | <?php |
2 | use Action\AbstractAction; | 2 | use Action\AbstractAction; |
3 | -use LibModels\Wap\Category\ClassData; | ||
4 | -use Plugin\DataProcess\ClassProcess; | 3 | +use Category\ClassModel; |
5 | 4 | ||
6 | /** | 5 | /** |
7 | * 品类 | 6 | * 品类 |
@@ -10,13 +9,7 @@ class ClassController extends AbstractAction | @@ -10,13 +9,7 @@ class ClassController extends AbstractAction | ||
10 | { | 9 | { |
11 | public function indexAction() | 10 | public function indexAction() |
12 | { | 11 | { |
13 | - $brandsData = ClassData::getClassesData(); | ||
14 | - | ||
15 | - $classes = array(); | ||
16 | - if($brandsData['code'] == 200) | ||
17 | - { | ||
18 | - $classes = ClassProcess::getClassData($brandsData['data']); | ||
19 | - } | 12 | + $classes = ClassModel::getClassData(); |
20 | 13 | ||
21 | $data = array( | 14 | $data = array( |
22 | "searchUrl" => "", | 15 | "searchUrl" => "", |
@@ -4,6 +4,7 @@ use Action\AbstractAction; | @@ -4,6 +4,7 @@ use Action\AbstractAction; | ||
4 | use LibModels\Wap\Product\SearchData; | 4 | use LibModels\Wap\Product\SearchData; |
5 | use LibModels\Wap\Category\BrandData; | 5 | use LibModels\Wap\Category\BrandData; |
6 | use LibModels\Wap\Category\ClassData; | 6 | use LibModels\Wap\Category\ClassData; |
7 | +use Category\ClassModel; | ||
7 | use Plugin\DataProcess\ListProcess; | 8 | use Plugin\DataProcess\ListProcess; |
8 | use Plugin\Helpers; | 9 | use Plugin\Helpers; |
9 | 10 | ||
@@ -31,11 +32,28 @@ class ListController extends AbstractAction | @@ -31,11 +32,28 @@ class ListController extends AbstractAction | ||
31 | 'navHome' => '/' | 32 | 'navHome' => '/' |
32 | ), | 33 | ), |
33 | 'goodListPage' => true, | 34 | 'goodListPage' => true, |
34 | - 'goodList' => array() | 35 | + 'goodList' => array( |
36 | + 'brand' => 0, | ||
37 | + 'msort' => 0, | ||
38 | + 'gender' => $this->getCookie('_Channel', '1,2'), | ||
39 | + 'sort' => 0, | ||
40 | + 'price' => 0, | ||
41 | + 'size' => 0, | ||
42 | + 'discount' => '', | ||
43 | + 'p_d' => '' | ||
44 | + ) | ||
35 | ); | 45 | ); |
36 | 46 | ||
47 | + // 首先查询是否属于内置品类 | ||
48 | + $classes = ClassModel::getClassesArr(); | ||
49 | + $classFlag = array_search($query, $classes); | ||
50 | + if($classFlag !== false)// 属于内部品类 | ||
51 | + { | ||
52 | + $data['pageHeader']['navTitle'] = '所有'.$query; | ||
53 | + } | ||
54 | + | ||
37 | // 如果存在搜索字符串就显示搜索栏 | 55 | // 如果存在搜索字符串就显示搜索栏 |
38 | - if(!is_null($query)) | 56 | + if(!is_null($query) && $classFlag === false) |
39 | { | 57 | { |
40 | $data['search'] = array( | 58 | $data['search'] = array( |
41 | 'default' => $query | 59 | 'default' => $query |
@@ -57,9 +75,12 @@ class ListController extends AbstractAction | @@ -57,9 +75,12 @@ class ListController extends AbstractAction | ||
57 | 'thumb' => Helpers::getImageUrl($brandData['brand_ico'], 75, 40), | 75 | 'thumb' => Helpers::getImageUrl($brandData['brand_ico'], 75, 40), |
58 | 'name' => $brandData['brand_name'] | 76 | 'name' => $brandData['brand_name'] |
59 | ); | 77 | ); |
78 | + | ||
79 | + // 设置品牌默认值 | ||
80 | + $data['goodList']['brand'] = $brandData['id']; | ||
60 | } | 81 | } |
61 | 82 | ||
62 | - $data['goodList'] = ListProcess::getListData($tmpData); | 83 | + $data['goodList'] += ListProcess::getListData($tmpData); |
63 | } | 84 | } |
64 | 85 | ||
65 | $this->_view->display('index', $data); | 86 | $this->_view->display('index', $data); |
@@ -80,6 +101,22 @@ class ListController extends AbstractAction | @@ -80,6 +101,22 @@ class ListController extends AbstractAction | ||
80 | $misort = $this->get('misort', null); | 101 | $misort = $this->get('misort', null); |
81 | $msort = $this->get('msort', null); | 102 | $msort = $this->get('msort', null); |
82 | 103 | ||
104 | + // 转换性别 | ||
105 | + if($gender === 'boys') | ||
106 | + { | ||
107 | + $gender = '1,2'; | ||
108 | + } | ||
109 | + elseif($gender === 'girls') | ||
110 | + { | ||
111 | + $gender = '2,3'; | ||
112 | + } | ||
113 | + else | ||
114 | + { | ||
115 | + $gender = '1,2,3'; | ||
116 | + } | ||
117 | + | ||
118 | + | ||
119 | + // 转换排序方式 | ||
83 | $order = $this->get('order', null); | 120 | $order = $this->get('order', null); |
84 | $type = $this->get('type', ''); | 121 | $type = $this->get('type', ''); |
85 | switch ($type) { | 122 | switch ($type) { |
@@ -138,9 +175,17 @@ class ListController extends AbstractAction | @@ -138,9 +175,17 @@ class ListController extends AbstractAction | ||
138 | ), | 175 | ), |
139 | 'goodListPage' => true, | 176 | 'goodListPage' => true, |
140 | 'goodList' => array( | 177 | 'goodList' => array( |
141 | - 'brand' => array( | 178 | + 'brandHome' => array( |
142 | 'id' => $brand | 179 | 'id' => $brand |
143 | - ) | 180 | + ), |
181 | + 'brand' => $brand, | ||
182 | + 'msort' => 0, | ||
183 | + 'gender' => $this->getCookie('_Channel', '1,2'), | ||
184 | + 'sort' => 0, | ||
185 | + 'price' => 0, | ||
186 | + 'size' => 0, | ||
187 | + 'discount' => '', | ||
188 | + 'p_d' => '' | ||
144 | ) | 189 | ) |
145 | ); | 190 | ); |
146 | 191 | ||
@@ -148,14 +193,15 @@ class ListController extends AbstractAction | @@ -148,14 +193,15 @@ class ListController extends AbstractAction | ||
148 | $introData = BrandData::getBrandIntro($brand); | 193 | $introData = BrandData::getBrandIntro($brand); |
149 | if(isset($introData['code']) && $introData['code'] === 200) | 194 | if(isset($introData['code']) && $introData['code'] === 200) |
150 | { | 195 | { |
151 | - $data['goodList']['brand']['intro'] = isset($introData['data']['brand_intro']) ? $introData['data']['brand_intro'] : ''; | 196 | + $data['goodList']['brandHome']['intro'] = isset($introData['data']['brand_intro']) ? $introData['data']['brand_intro'] : ''; |
152 | } | 197 | } |
153 | 198 | ||
154 | // 获取品牌banner的数据 | 199 | // 获取品牌banner的数据 |
155 | - $bannerData = BrandData::getBrandBanner($brand, 0); | 200 | + $uid = $this->getUid(); |
201 | + $bannerData = BrandData::getBrandBanner($brand, $uid); | ||
156 | if(isset($bannerData['code']) && $bannerData['code'] === 200) | 202 | if(isset($bannerData['code']) && $bannerData['code'] === 200) |
157 | { | 203 | { |
158 | - $data['goodList']['brand']['banner'] = isset($bannerData['data']['banner']) ? Helpers::getImageUrl($bannerData['data']['banner'], 640, 75) : ''; | 204 | + $data['goodList']['brandHome']['banner'] = isset($bannerData['data']['banner']) ? Helpers::getImageUrl($bannerData['data']['banner'], 640, 75) : ''; |
159 | } | 205 | } |
160 | 206 | ||
161 | // 查询数据 | 207 | // 查询数据 |
@@ -192,16 +238,29 @@ class ListController extends AbstractAction | @@ -192,16 +238,29 @@ class ListController extends AbstractAction | ||
192 | 'navHome' => '/' | 238 | 'navHome' => '/' |
193 | ), | 239 | ), |
194 | 'goodListPage' => true, | 240 | 'goodListPage' => true, |
195 | - 'goodList' => array() | 241 | + 'goodList' => array( |
242 | + 'brand' => 0, | ||
243 | + 'msort' => 0, | ||
244 | + 'gender' => $this->getCookie('_Channel', '1,2'), | ||
245 | + 'sort' => $sort, | ||
246 | + 'price' => 0, | ||
247 | + 'size' => 0, | ||
248 | + 'discount' => '', | ||
249 | + 'p_d' => '' | ||
250 | + ) | ||
196 | ); | 251 | ); |
197 | 252 | ||
253 | + // 根据id查询类的名称 | ||
254 | + $classes = ClassModel::getClassesArr(); | ||
255 | + $data['pageHeader']['navTitle'] = isset($classes[$sort]) ? $classes[$sort] : ''; | ||
256 | + | ||
198 | // 查询数据 | 257 | // 查询数据 |
199 | $listData = ClassData::selectClassDetail($gender, $brand, $sort, $color, $size, $price, $p_d); | 258 | $listData = ClassData::selectClassDetail($gender, $brand, $sort, $color, $size, $price, $p_d); |
200 | // 处理返回的数据 | 259 | // 处理返回的数据 |
201 | if (isset($listData['code']) && $listData['code'] === 200) { | 260 | if (isset($listData['code']) && $listData['code'] === 200) { |
202 | $tmpData = $listData['data']; | 261 | $tmpData = $listData['data']; |
203 | 262 | ||
204 | - $data['goodList'] = ListProcess::getListData($tmpData); | 263 | + $data['goodList'] += ListProcess::getListData($tmpData); |
205 | } | 264 | } |
206 | 265 | ||
207 | $this->_view->display('index', $data); | 266 | $this->_view->display('index', $data); |
-
Please register or login to post a comment