Authored by xuqi

Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into develop

<?php
namespace Plugin\DataProcess;
use Plugin\Helpers;
/**
... ... @@ -18,9 +17,10 @@ class ListProcess
*/
public static function getListData($data, $returnFilter = true)
{
$result = array('new' => array(), 'filter' => array());
$result = array();
if (isset($data['product_list'])) {
if(isset($data['product_list']))
{
$result['new'] = self::getProductData($data['product_list']);
}
if ($returnFilter && isset($data['filter'])) {
... ... @@ -28,6 +28,7 @@ class ListProcess
}
return $result;
}
/**
... ... @@ -46,34 +47,40 @@ class ListProcess
}
return $products;
}
/**
* 处理筛选数据
*
* @param $data
* @param string | integer $gender 默认选择的性别,默认1,2,3表示所有
* @return array 处理之后的筛选数据
*/
public static function getFilterData($data)
public static function getFilterData($data, $gender = '1,2,3')
{
// 过滤条件数据
$filters = array('classify' => array());
$filters = array('classify'=>array());
// 返回数据中有没有gender时要添加gender
// $data['gender'] = array('2,3'=>'GIRLS','1,3'=>'BOYS');
$num = 1;
$build = array();
foreach ($data as $key => $val) {
if (empty($val)) {
if(empty($val))
{
continue;
}
if (!is_callable("self::$key")) {
continue;
}
$build = self::$key($val);
if ($num === 1) {
$build = self::$key($val, $gender);
if($num === 1)
{
$build['active'] = true;
}
$num ++;
$num++;
$filters['classify'][] = $build;
}
... ... @@ -81,6 +88,7 @@ class ListProcess
self::sortArrByField($filters['classify'], 'sort_col');
return $filters;
}
private static function brand($data)
... ... @@ -159,7 +167,7 @@ class ListProcess
foreach ($data as $key => $one) {
$discount = array();
$discount['dataId'] = $key;
$discount['name'] = $one['name'] . '折商品';
$discount['name'] = $one['name'] .'折商品';
$result['subs'][] = $discount;
}
... ... @@ -167,7 +175,7 @@ class ListProcess
return $result;
}
private static function gender($data)
private static function gender($data, $gender)
{
$result = array(
'title' => '性别',
... ... @@ -176,8 +184,7 @@ class ListProcess
'dataType' => 'gender',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'dataId' => '1,2,3',
'name' => '所有性别'
),
array(
... ... @@ -191,6 +198,11 @@ class ListProcess
)
);
// 处理选中状态
foreach ($result['subs'] as &$val) {
$val['dataId'] === $gender && $val['chosed'] = true;
}
return $result;
}
... ... @@ -215,18 +227,18 @@ class ListProcess
$category['dataId'] = isset($one['relation_parameter']) ? $one['relation_parameter']['sort'] : 0;
$category['name'] = $one['category_name'];
/* // 子品类(目前h5不支持二级)
if(isset($one['sub']))
{
$category['subs'] = array();
foreach ($one['sub'] as $single) {
$subitem = array();
$subitem['dataId'] = $single['category_id'];
$subitem['name'] = $single['category_name'];
/*// 子品类(目前h5不支持二级)
if(isset($one['sub']))
{
$category['subs'] = array();
foreach ($one['sub'] as $single) {
$subitem = array();
$subitem['dataId'] = $single['category_id'];
$subitem['name'] = $single['category_name'];
$category['subs'][] = $subitem;
}
} */
$category['subs'][] = $subitem;
}
}*/
$result['subs'][] = $category;
}
... ... @@ -279,7 +291,7 @@ class ListProcess
foreach ($data as $one) {
$size = array();
$size['dataId'] = $one['size_id'];
$size['dataId'] = $one['size_id'];
$size['name'] = $one['size_name'];
$result['subs'][] = $size;
... ... @@ -295,8 +307,7 @@ class ListProcess
* @param string $field 字段名称
* @param boolean $desc 时候降序排列,默认为false
*/
private static function sortArrByField(&$array, $field, $desc = false)
{
private static function sortArrByField(&$array, $field, $desc = false){
$fieldArr = array();
foreach ($array as $k => $v) {
$fieldArr[$k] = $v[$field];
... ... @@ -304,5 +315,4 @@ class ListProcess
$sort = $desc == false ? SORT_ASC : SORT_DESC;
array_multisort($fieldArr, $sort, $array);
}
}
... ...
... ... @@ -161,7 +161,7 @@ class Helpers
break;
case 'newest':
default:
$result = ($order == 0) ? 's_t_desc' : 's_t_asc';
$result = ($order == 1) ? 's_t_desc' : 's_t_asc';
break;
}
... ...
... ... @@ -57,6 +57,8 @@ class BoysController extends AbstractAction
$this->echoJson($bottomBanner);
} while (false);
echo ' ';
}
}
... ...
... ... @@ -53,6 +53,8 @@ class GirlsController extends AbstractAction
$this->echoJson($bottomBanner);
} while (false);
echo ' ';
}
}
... ...
<?php
use Action\AbstractAction;
use LibModels\Wap\Product\SearchData;
// use LibModels\Wap\Product\SearchData;
use Plugin\DataProcess\ListProcess;
use Plugin\Helpers;
... ... @@ -94,8 +94,7 @@ class SearchController extends AbstractAction
if ($domain !== null) {
$url = Helpers::url('', array(
'from' => 'search',
'query' => $query,
'gender' => $condition['gender']
'query' => $query
), $domain);
$this->go($url);
}
... ... @@ -271,23 +270,22 @@ class SearchController extends AbstractAction
'gender' => FILTER_DEFAULT,
'p_d' => FILTER_DEFAULT,), false);
// 转义分类
if (isset($condition['sort'])) {
$condition['sort'] = rawurldecode($condition['sort']);
}
// 转换折扣
if (isset($condition['discount'])) {
$condition['p_d'] = rawurldecode($condition['discount']);
unset($condition['discount']);
}
// 转义性别
if (isset($condition['gender'])) {
$condition['gender'] = rawurldecode($condition['gender']);
}
$listData = SearchData::searchByCondition($condition);
// 处理返回的数据
if (isset($listData['data']) && isset($listData['data']['filter'])) {
$data['filter'] = ListProcess::getFilterData($listData['data']['filter']);
}
$listData = array();
// 区别各种列表页面的筛选数据
$data = Product\FilterModel::getFilterData($condition);
}
if (empty($data)) {
... ... @@ -302,7 +300,7 @@ class SearchController extends AbstractAction
*
* @return array 模糊搜索的结果
*/
public function fuzzysearch()
/*public function fuzzysearch()
{
if ($this->isAjax()) {
$keyword = $this->post('keyword', '');
... ... @@ -311,6 +309,6 @@ class SearchController extends AbstractAction
$this->echoJson($result);
}
}
}*/
}
... ...
<?php
namespace Product;
use Configs\CacheConfig;
use LibModels\Wap\Product\SearchData;
use LibModels\Wap\Category\BrandData;
use LibModels\Wap\Category\ClassData;
use Plugin\DataProcess\ListProcess;
/**
* 搜索相关的模板数据模型
*
* @name Filter
* @package Product
* @copyright yoho.inc
* @version 1.0 (2015-11-1 17:35:52)
*/
class FilterModel
{
/**
* 获取筛选的数据
*
* @param array $condition 查询条件
* @return array
*/
public static function getFilterData($condition)
{
$result = array();
// 区别各种列表页面的筛选数据
if (isset($condition['brand'])) {
$listData = BrandData::filterBrandData($condition);
} else if(isset($condition['sort'])) {
$listData = ClassData::filterClassData($condition);
} else {
$listData = SearchData::searchByCondition($condition);
}
if (isset($listData['data']) && isset($listData['data']['filter'])) {
$result['filter'] = ListProcess::getFilterData($listData['data']['filter']);
}
return $result;
}
}
... ...
... ... @@ -224,15 +224,16 @@ class NewsaleModel
/**
* 获取筛选数据
* @param array $data 接口返回的数据
* @param string $gender 默认选择的性别,默认1,2,3表示所有
* @return array 处理之后的数据
*/
public static function filterData($data)
public static function filterData($data, $gender = '1,2,3')
{
$result = array();
/* 格式化筛选数据 */
if (isset($data['code']) && $data['code'] == 200 && isset($data['data']['filter'])) {
$result['filter'] = ListProcess::getFilterData($data['data']['filter']);
$result['filter'] = ListProcess::getFilterData($data['data']['filter'], $gender);
}
return $result;
... ...
... ... @@ -117,6 +117,8 @@ class IndexController extends AbstractAction
if (isset($condition['gender'])) {
$condition['gender'] = rawurldecode($condition['gender']);
} else {
$condition['gender'] = Helpers::getGenderByCookie();
}
$data = array();
... ...
... ... @@ -54,7 +54,7 @@ class NewsaleController extends AbstractAction
// 设置一些默认参数
$data = array(
'discountPage' => true,
'headerBanner' => \Product\NewsaleModel::getNewFocus($channel),
'headerBanner' => \Product\NewsaleModel::getSaleFocus($channel),
'showDownloadApp' => true,
'pageFooter' => true,
'brand' => '0',
... ... @@ -142,7 +142,7 @@ class NewsaleController extends AbstractAction
$data = NewsaleData::selectNewSaleProducts(
$gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit, $limit, $page, $order
);
$result = \Product\NewsaleModel::filterData($data);
$result = \Product\NewsaleModel::filterData($data, $gender);
}
if (empty($result)) {
... ...