Authored by Rock Zhang

更新搜索有关功能的逻辑,目前列表排序接口传参还存在问题,筛选传参也存在问题

framework @ 75bbc3b0
Subproject commit 119c247f5cf929aa1e059e40609bb16dd6b58f05
Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2
... ...
... ... @@ -17,4 +17,7 @@ class CacheConfig
const KEY_COMMON_SIDE_NAV = 'key_common_side_nav'; // 公共的侧边栏
const KEY_CATEGORY_CLASSES_DATA = 'key_category_classes_data';
}
... ...
... ... @@ -36,7 +36,7 @@ class ClassData
*
* @param string $gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部
* @param integer $brand 品牌Id
* @param integer $sort 品类Id
* @param integer $sort 品类查询sort参数
* @param integer $color 颜色Id
* @param integer $size 尺码Id
* @param string $price 价格
... ...
<?php
namespace Plugin\DataProcess;
/**
* 分类数据处理类
*/
class ClassProcess
{
/**
* 处理品类数据
* @param $data
* @return array 处理之后的品类数据
*/
public static function getClassData($data)
{
$num = 1;
$classes = array();
foreach ($data as $k => $v){
$oneClass = array('name'=>$k, 'ca'=>array());
if($num === 1)
{
$oneClass['focus'] = true;
}
foreach ($v as $val) {
$item = array();
$item['name'] = $val['category_name'];
foreach ($val['sub'] as $value) {
$subitem = array();
$subitem['name'] = $value['category_name'];
$subitem['url'] = $value['category_id'];
$item['sub'][] = $subitem;
}
$oneClass['ca'][] = $item;
}
$num++;
$classes[] = $oneClass;
}
return $classes;
}
}
... ... @@ -208,7 +208,7 @@ class ListProcess
$category['dataId'] = $one['category_id'];
$category['name'] = $one['category_name'];
// 子品类
/*// 子品类(目前h5不支持二级)
if(isset($one['sub']))
{
$category['subs'] = array();
... ... @@ -219,7 +219,7 @@ class ListProcess
$category['subs'][] = $subitem;
}
}
}*/
$result['subs'][] = $category;
}
... ...
... ... @@ -25,7 +25,6 @@ class BoysController extends AbstractAction
// 渲染模板并输出
$this->_view->display('index', array(
'searchUrl' => '/search',
'boysHomePage' => true,
'maybeLike' => true,
'content' => Index\HomeModel::getBoysFloor()
... ...
... ... @@ -25,7 +25,6 @@ class GirlsController extends AbstractAction
// 渲染模板并输出
$this->_view->display('index', array(
'searchUrl' => '/search',
'grilsHomePage' => true,
'maybeLike' => true,
'content' => Index\HomeModel::getGirlsFloor()
... ...
... ... @@ -25,7 +25,6 @@ class KidsController extends AbstractAction
// 渲染模板并输出
$this->_view->display('index', array(
'searchUrl' => '/search',
'kidsHomePage' => true,
'maybeLike' => true,
'content' => Index\HomeModel::getKidsFloor()
... ...
... ... @@ -25,7 +25,6 @@ class LifestyleController extends AbstractAction
// 渲染模板并输出
$this->_view->display('index', array(
'searchUrl' => '/search',
'lifestyleHomePage' => true,
'maybeLike' => true,
'content' => Index\HomeModel::getLifestyleFloor()
... ...
... ... @@ -57,37 +57,6 @@ class SearchController extends AbstractAction
$result = SearchData::searchFuzzyDatas($keyword);
$this->_view->display('list', array('searchPage' => true, 'pageFooter' => true));
}
}
/**
* 根据指定字符串查询数据
*
* @return array 搜索的结果
*/
public function listsearch()
{
$query = $this->get('query', '');
$result = SearchData::searchLiDatas($query);
$this->echoJson($result);
}
/**
* 根据指定条件筛选查询到数据
*
* @return array 筛选之后的结果
*/
public function sortsearch()
{
if($this->isAjax())
{
$query = $this->post('query', '');
$result = SearchData::searchLiDatas($query);
$this->echoJson($result);
}
}
... ...
<?php
namespace Category;
use LibModels\Wap\Category\ClassData;
use Configs\CacheConfig;
use Plugin\Helpers;
use Plugin\Cache;
/**
* 品牌相关的模板数据模型
*
* @name BrandModel
* @package Models/Category
* @copyright yoho.inc
* @version 1.0 (2015-10-21 13:52:44)
* @author fei.hong <fei.hong@yoho.cn>
*/
class ClassModel
{
/**
* 根据频道获取品牌一览数据
*
* @param int $channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
* @return array
*/
public static function getClassData()
{
$classes = array();
if (USE_CACHE) {
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get(CacheConfig::KEY_CATEGORY_CLASSES_DATA, 'master');
if (!empty($result)) {
return $result;
}
}
do {
$num = 1;
$data = ClassData::getClassesData();
if(!isset($data['code']) || $data['code'] !== 200)
{
break;
}
if(!isset($data['data']))
{
break;
}
foreach ($data['data'] as $k => $v){
$oneClass = array('name'=>$k, 'ca'=>array());
if($num === 1)
{
$oneClass['focus'] = true;
}
foreach ($v as $val) {
$item = array();
$item['name'] = $val['category_name'];
$item['id'] = $val['relation_parameter']['sort'];
foreach ($val['sub'] as $value) {
$subitem = array();
$subitem['name'] = $value['category_name'];
$subitem['id'] = $value['relation_parameter']['sort'];
$subitem['url'] = $value['category_id'];
$item['sub'][] = $subitem;
}
$oneClass['ca'][] = $item;
}
$num++;
$classes[] = $oneClass;
}
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($classes)) {
$classes = Cache::get(CacheConfig::KEY_ACTION_INDEX_INDEX, 'slave');
}
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set(CacheConfig::KEY_ACTION_INDEX_INDEX, $classes);
}
}
}while(false);
return $classes;
}
/**
* 返回品类构成的数组
*
* @return array 键为品类查询sort参数,值为品类名称构成的数组
*/
public static function getClassesArr()
{
$classes = array();
$classesData = self::getClassData();
foreach ($classesData as $val) {
foreach ($val['ca'] as $single) {
$classes[$single['id']] = $single['name'];
$classes += array_column($single['sub'], 'name', 'id');
}
}
return $classes;
}
}
... ...
<?php
use Action\AbstractAction;
use LibModels\Wap\Category\ClassData;
use Plugin\DataProcess\ClassProcess;
use Category\ClassModel;
/**
* 品类
... ... @@ -10,13 +9,7 @@ class ClassController extends AbstractAction
{
public function indexAction()
{
$brandsData = ClassData::getClassesData();
$classes = array();
if($brandsData['code'] == 200)
{
$classes = ClassProcess::getClassData($brandsData['data']);
}
$classes = ClassModel::getClassData();
$data = array(
"searchUrl" => "",
... ...
... ... @@ -4,6 +4,7 @@ use Action\AbstractAction;
use LibModels\Wap\Product\SearchData;
use LibModels\Wap\Category\BrandData;
use LibModels\Wap\Category\ClassData;
use Category\ClassModel;
use Plugin\DataProcess\ListProcess;
use Plugin\Helpers;
... ... @@ -31,11 +32,28 @@ class ListController extends AbstractAction
'navHome' => '/'
),
'goodListPage' => true,
'goodList' => array()
'goodList' => array(
'brand' => 0,
'msort' => 0,
'gender' => $this->getCookie('_Channel', '1,2'),
'sort' => 0,
'price' => 0,
'size' => 0,
'discount' => '',
'p_d' => ''
)
);
// 首先查询是否属于内置品类
$classes = ClassModel::getClassesArr();
$classFlag = array_search($query, $classes);
if($classFlag !== false)// 属于内部品类
{
$data['pageHeader']['navTitle'] = '所有'.$query;
}
// 如果存在搜索字符串就显示搜索栏
if(!is_null($query))
if(!is_null($query) && $classFlag === false)
{
$data['search'] = array(
'default' => $query
... ... @@ -57,9 +75,12 @@ class ListController extends AbstractAction
'thumb' => Helpers::getImageUrl($brandData['brand_ico'], 75, 40),
'name' => $brandData['brand_name']
);
// 设置品牌默认值
$data['goodList']['brand'] = $brandData['id'];
}
$data['goodList'] = ListProcess::getListData($tmpData);
$data['goodList'] += ListProcess::getListData($tmpData);
}
$this->_view->display('index', $data);
... ... @@ -80,6 +101,22 @@ class ListController extends AbstractAction
$misort = $this->get('misort', null);
$msort = $this->get('msort', null);
// 转换性别
if($gender === 'boys')
{
$gender = '1,2';
}
elseif($gender === 'girls')
{
$gender = '2,3';
}
else
{
$gender = '1,2,3';
}
// 转换排序方式
$order = $this->get('order', null);
$type = $this->get('type', '');
switch ($type) {
... ... @@ -138,9 +175,17 @@ class ListController extends AbstractAction
),
'goodListPage' => true,
'goodList' => array(
'brand' => array(
'brandHome' => array(
'id' => $brand
)
),
'brand' => $brand,
'msort' => 0,
'gender' => $this->getCookie('_Channel', '1,2'),
'sort' => 0,
'price' => 0,
'size' => 0,
'discount' => '',
'p_d' => ''
)
);
... ... @@ -148,14 +193,15 @@ class ListController extends AbstractAction
$introData = BrandData::getBrandIntro($brand);
if(isset($introData['code']) && $introData['code'] === 200)
{
$data['goodList']['brand']['intro'] = isset($introData['data']['brand_intro']) ? $introData['data']['brand_intro'] : '';
$data['goodList']['brandHome']['intro'] = isset($introData['data']['brand_intro']) ? $introData['data']['brand_intro'] : '';
}
// 获取品牌banner的数据
$bannerData = BrandData::getBrandBanner($brand, 0);
$uid = $this->getUid();
$bannerData = BrandData::getBrandBanner($brand, $uid);
if(isset($bannerData['code']) && $bannerData['code'] === 200)
{
$data['goodList']['brand']['banner'] = isset($bannerData['data']['banner']) ? Helpers::getImageUrl($bannerData['data']['banner'], 640, 75) : '';
$data['goodList']['brandHome']['banner'] = isset($bannerData['data']['banner']) ? Helpers::getImageUrl($bannerData['data']['banner'], 640, 75) : '';
}
// 查询数据
... ... @@ -192,16 +238,29 @@ class ListController extends AbstractAction
'navHome' => '/'
),
'goodListPage' => true,
'goodList' => array()
'goodList' => array(
'brand' => 0,
'msort' => 0,
'gender' => $this->getCookie('_Channel', '1,2'),
'sort' => $sort,
'price' => 0,
'size' => 0,
'discount' => '',
'p_d' => ''
)
);
// 根据id查询类的名称
$classes = ClassModel::getClassesArr();
$data['pageHeader']['navTitle'] = isset($classes[$sort]) ? $classes[$sort] : '';
// 查询数据
$listData = ClassData::selectClassDetail($gender, $brand, $sort, $color, $size, $price, $p_d);
// 处理返回的数据
if (isset($listData['code']) && $listData['code'] === 200) {
$tmpData = $listData['data'];
$data['goodList'] = ListProcess::getListData($tmpData);
$data['goodList'] += ListProcess::getListData($tmpData);
}
$this->_view->display('index', $data);
... ...