Authored by 周少峰

代码整理,条件处理到model公用

... ... @@ -107,15 +107,23 @@ class HelperSearch
//左侧分类分类
$result['leftContent'][]['allSort'] = isset($data['sort']) ? self::groupSort($data['sort']['sort']) : array();
//一周新品上架
$result['leftContent'][]['newSales'] = isset($data['recent']) ? self::recentShelve($data['recent']) : array();
$result['leftContent'][]['newSales'] = isset($data['recent']) ? self::recentShelve($data['recent']['recent']) : array();
//全部折扣
$result['leftContent'][]['allDiscount'] = isset($data['discount']) ? self::getDiscount($data['discount']['discount']) : array();
//总记录数
$result['totalCount'] = $data['product']['total'];
//品牌店铺信息
$result['shopEntry'] = isset($data['shop']) && !empty($data['shop']) ? self::shop($data['shop'], $data['sort']['sort']) : array();
//分页
$result['pager'] = self::pager($result['totalCount'],$options['viewNum']);
//选中条件
if (self::getSelected()) {
$result['filters']['checkedConditions']['conditions'] = self::getSelected();
}
//没有选中
else{
$result['filters']['checkedConditions'] = array();
}
if (isset($options['controller']) && $options['controller'] == 'Search') {
self::setSearchNav($data['product']['total']);
}
... ... @@ -202,7 +210,7 @@ class HelperSearch
'href' => self::buildUrl(array_merge($params, array(
'parameter_' . $val['standard_id'] => $pval['standard_id']
))) ,
'selected' => isset(self::$params['parameter_' . $val['standard_id']]) && self::$params['parameter_' . $val['standard_id']] == $pval['standard_id'] ? true : false
'checked' => isset(self::$params['parameter_' . $val['standard_id']]) && self::$params['parameter_' . $val['standard_id']] == $pval['standard_id'] ? true : false
);
}
if (!empty($sub) && count($sub) > 1) {
... ... @@ -245,8 +253,9 @@ class HelperSearch
$result[] = array(
'name' => $val,
'href' => self::buildUrl(array_merge($params, array(
'gender' => $key
'gender' => $key,
))) ,
'checked' => isset(self::$params['gender']) && self::$params['gender'] == $key ? true : false
);
}
return $result;
... ... @@ -394,7 +403,7 @@ class HelperSearch
'href' => $url,
'name' => $v['brand_name'],
'key' => strtolower($v['brand_name']),
'active' => in_array($v['id'], $brandIds) ? true : false
'checked' => in_array($v['id'], $brandIds) ? true : false
);
if (is_numeric($v['brand_alif'])) {
$this_brand['index'] = '0-9';
... ... @@ -1065,13 +1074,16 @@ class HelperSearch
/**
* 组织品牌店铺信息
* @param $shop
* @param $shopSort
* @return array
*/
public static function shop($shop)
public static function shop($shop, $shopSort)
{
$url = Helpers::url('','',$shop['brand_domain']);
$shopEntry = array();
$sort = array();
foreach ($shop['sort'] as $msort) {
foreach ($shopSort as $msort) {
if (!isset($msort['sub']) || empty($msort['sub'])) {
continue;
}
... ... @@ -1221,7 +1233,15 @@ class HelperSearch
// }
/**
* 获取品牌店铺接口地址
* @param $param
* @return string
*/
public static function getShopUrl($param)
{
return Yohobuy::httpBuildQuery(self::getUrl('shop'), $param);
}
/**
* 获取搜索的服务地址
*
... ...
... ... @@ -24,12 +24,12 @@ class SearchModel
* @param $option
* @return mixed
*/
public static function SearchCondition($param, $option)
public static function searchCondition($param, $option)
{
/* 过滤请求参数 */
$condition = filter_input_array(INPUT_GET, array(
'query' => FILTER_SANITIZE_STRING,
'brand' => FILTER_VALIDATE_INT,
'brand' => FILTER_SANITIZE_STRING,
'sort' => FILTER_VALIDATE_INT,
'msort' => FILTER_VALIDATE_INT,
'misort' => FILTER_VALIDATE_INT,
... ... @@ -51,6 +51,10 @@ class SearchModel
if (isset($condition['query']) && !empty($condition['query'])) {
$condition['query'] = rawurldecode($condition['query']);
}
//品牌
if (isset($condition['brand']) && !empty($condition['brand'])) {
$condition['brand'] = rawurldecode($condition['brand']);
}
//性别
if (isset($condition['gender']) && !empty($condition['gender'])) {
$condition['gender'] = rawurldecode($condition['gender']);
... ... @@ -128,7 +132,7 @@ class SearchModel
* @param array $customOptions
* @return array
*/
public static function getSearchData($customCondition = array(), $customOptions = array())
public static function getListData($customCondition = array(), $customOptions = array())
{
$urlList = array();
$searchCondition = self::searchCondition($customCondition, $customOptions);
... ... @@ -144,14 +148,6 @@ class SearchModel
//$urlList['reviewUrl'] = HelperSearch::getReviewUrl($searchCondition['condition']);
$result = Yohobuy::getMulti($urlList, array(), true);
// print_r($result['product']);
// print_r($result['sort']);
// print_r($result['discount']);
// print_r($result['recent']);
// exit;
// 组织模板数据
$data = HelperSearch::getList($result, $searchCondition['options']);
return $data;
... ... @@ -159,30 +155,27 @@ class SearchModel
/**
* 搜索页面获取搜索数据
* @param $condition
* @param $options
* @param $customCondition
* @param $customOptions
* @return array
*/
public static function searchData($condition, $options)
public static function searchData($customCondition, $customOptions)
{
$data = self::getSearchData($condition, $options);
//获取品牌店铺信息
if (isset($condition['query'])) {
$param['keyword'] = $condition['query'];
$result = SearchData::getShop($param);
if (isset($result['code']) && $result['code'] === 200 && isset($result['data']) && !empty($result['data'])) {
//调用品牌分类
$class['brand'] = $result['data']['id'];
$brandSort = SearchData::getClassesData($class);
$shop = $result['data'];
if (isset($brandSort['data']['sort']) && !empty($brandSort['data']['sort']))
$shop['sort'] = $brandSort['data']['sort'];
$shopEntry = HelperSearch::shop($shop);
}
}
$data['shopEntry'] = isset($shopEntry) ? $shopEntry : array();
$urlList = array();
$searchCondition = self::searchCondition($customCondition, $customOptions);
// 组合搜索商品url
$urlList['product'] = HelperSearch::getProductUrl($searchCondition['condition']);
// 组合搜索分类url
$urlList['sort'] = HelperSearch::getClassesUrl($searchCondition['condition']);
// 组合搜索店铺url
$param['keyword'] = $searchCondition['condition']['query'];
$urlList['shop'] = HelperSearch::getShopUrl($param);
//用户浏览记录
//$urlList['reviewUrl'] = HelperSearch::getReviewUrl($searchCondition['condition']);
$result = Yohobuy::getMulti($urlList, array(), true);
// 组织模板数据
$data = HelperSearch::getList($result, $searchCondition['options']);
return $data;
}
/**
* 根据product_sn查询产品图片信息
... ...
... ... @@ -17,87 +17,12 @@ class ListController extends WebAction
*/
public function saleAction()
{
/* 过滤请求参数 */
$condition = filter_input_array(INPUT_GET, array(
//'query' => FILTER_SANITIZE_STRING,
'brand' => FILTER_VALIDATE_INT,
'sort' => FILTER_VALIDATE_INT,
'msort' => FILTER_VALIDATE_INT,
'misort' => FILTER_VALIDATE_INT,
'color' => FILTER_VALIDATE_INT,
'size' => FILTER_DEFAULT,
'style' => FILTER_DEFAULT,
'price' => FILTER_DEFAULT,
'gender' => FILTER_DEFAULT,
'p_d' => FILTER_DEFAULT,
'shelve_time' => FILTER_DEFAULT,
'isNew' => FILTER_DEFAULT,
'specialoffer' => FILTER_DEFAULT,
'limited' => FILTER_DEFAULT,
'order' => FILTER_DEFAULT,
'viewNum' => FILTER_VALIDATE_INT,
'rowNum' => FILTER_VALIDATE_INT,
'page' => FILTER_VALIDATE_INT), false);
//字符转码
if (!empty($condition)) {
foreach ($condition as $key => $val) {
$condition[$key] = rawurldecode($val);
}
}
//性別(频道)
$gender_cookie = !isset($_COOKIE['_Gender']) ? '3' : ($_COOKIE['_Gender']=='2,3' ? 2 : 1);
$gender = $this->get('gender') ? ($this->get('gender') == '2,3' ? 2 : 1) : $gender_cookie ;
$condition['gender'] = $gender;
//每页显示商品数
if(!isset($condition['viewNum']) || empty($condition['viewNum'])){
$condition['viewNum'] =60;
}
$view_num_arr = array(60, 100, 200);
if (!in_array($condition['viewNum'], $view_num_arr)) {
$condition['viewNum'] = 60;
}
//每行显示的商品数量
if(!isset($condition['rowNum']) || empty($condition['rowNum'])){
$condition['rowNum'] =5;
}
if ($condition['rowNum'] == 6) {
$imgSize = array(195, 260);
$minImgSize = array(50, 67);
} else {
$condition['rowNum'] = 5;
$imgSize = array(235, 314);
$minImgSize = array(60, 80);
}
//返回搜索条件
$condition['needFilter'] = 1;
//过滤赠品
$condition['attribute_not'] = 2;
/*sale*/
//默认排序
if (!isset($condition['order']) || empty($condition['order'])) {
$condition['order'] = 's_n_desc';
}
if (!isset($condition['p_d']) || empty($condition['p_d'])) {
$condition['p_d'] = '0,0.9';
}
$options = array(
'imgSize' => $imgSize,
'minImgSize' => $minImgSize,
'rowNum' =>$condition['rowNum'],
'viewNum' =>$condition['viewNum'],
);
$params = $condition + $_GET;
$params = array_filter($params);
//每页记录数减1,下一页占位
$params['viewNum'] = $params['viewNum'] - 1;
$list = SearchModel::getSearchData($params,$options);
$list = SearchModel::getListData();
$data = array(
//初始化js
'productListPage' => true,
'list' => $list
);
$cate = array('boys','girls','kids','lifestyle');
$this->setWebNavHeader($cate[$gender-1]);
$this->_view->display('list', $data);
}
... ...
... ... @@ -7,12 +7,12 @@ class SearchController extends WebAction
{
$options['controller'] = $this->_request->controller;
$searchData = SearchModel::searchData(array(),$options);
$this->setWebNavHeader();
$data = array(
//初始化js
'searchListPage' => true,
'search' => $searchData
);
$this->setWebNavHeader();
$this->_view->display('search', $data);
}
}
\ No newline at end of file
... ...