Authored by whb

PC重构

Too many changes to show.

To preserve performance only 15 of 15+ files are displayed.

<?php
namespace Configs;
/**
* 缓存配置文件
*/
class CacheConfig
{
/* 公共的数据缓存 */
const KEY_COMMON_SIDE_NAV = 'key_common_side_nav'; // 公共的侧边栏
const KEY_COMMON_CATEGORY_CLASSES = 'key_common_category_classes'; // 公共的品类数据
const KEY_COMMON_CATEGORY_CLASSES_NAMES = 'key_common_category_classes_names'; // 公共的品类名称列表
/* 控制器方法中的数据缓存 */
const KEY_ACTION_INDEX_INDEX = 'key_action_index_index'; // 频道选择
const KEY_ACTION_BOYS_INDEX = 'key_action_boys_index'; // 男生首页
const KEY_ACTION_GIRLS_INDEX = 'key_action_girls_index'; // 女生首页
const KEY_ACTION_KIDS_INDEX = 'key_action_kids_index'; // 潮童首页
const KEY_ACTION_LIFESTYLE_INDEX = 'key_action_lifestyle_index'; // 创意生活首页
const KEY_ACTION_INDEX_CONFIG = 'key_action_index_config'; // 频道配置
const KEY_ACTION_BOYS_BOTTOM_BANNER = 'key_action_boys_bottom_banner'; // 男生首页底部banner
const KEY_ACTION_GRILS_BOTTOM_BANNER = 'key_action_girls_bottom_banner';// 女生首页底部banner
const KEY_ACTION_PRODUCT_NEWSALE_INDEX_BOYS = 'key_action_product_newsale_index_boys'; // 男生新品到着
const KEY_ACTION_PRODUCT_NEWSALE_INDEX_GIRLS = 'key_action_product_newsale_index_girls'; // 女生新品到着
const KEY_ACTION_PRODUCT_NEWSALE_INDEX_KIDS = 'key_action_product_newsale_index_kids'; // 潮童新品到着
const KEY_ACTION_PRODUCT_NEWSALE_INDEX_LIFESTYLE = 'key_action_product_newsale_index_lifestyle'; // 创意生活新品到着
const KEY_ACTION_PRODUCT_NEWSALE_DISCOUNT_BOYS = 'key_action_product_newsale_discount_boys'; // 男生热卖排行
const KEY_ACTION_PRODUCT_NEWSALE_DISCOUNT_GIRLS = 'key_action_product_newsale_discount_girls'; // 女生热卖排行
const KEY_ACTION_PRODUCT_NEWSALE_DISCOUNT_KIDS = 'key_action_product_newsale_discount_kids'; // 潮童热卖排行
const KEY_ACTION_PRODUCT_NEWSALE_DISCOUNT_LIFESTYLE = 'key_action_product_newsale_discount_lifestyle'; // 创意生活热卖排行
const KEY_ACTION_PRODUCT_INDEX = 'key_action_product_index'; // 品类商品列表
const KEY_ACTION_PRODUCT_BRAND = 'key_action_product_brand'; // 品类商品列表
const KEY_ACTION_PRODUCT_BRAND_DOMAINS = 'key_action_product_brand_domains'; // 所有品牌域名列表
const KEY_ACTION_PRODUCT_BRAND_NAMES = 'key_action_product_brand_names'; // 所有品牌名称列表
const KEY_ACTION_PRODUCT_BRAND_LOGO = 'key_action_product_brand_logo'; // 品牌信息
const KEY_ACTION_PRODUCT_BRAND_LOGO_DOMAIN = 'key_action_product_brand_logo_domain'; // 品牌信息通过域名取得
const KEY_ACTION_SEARCH_SEARCH = 'key_action_search_search'; // 搜索的数据
const KEY_ACTION_SEARCH_FILTER = 'key_action_search_filter'; // 搜索的过滤条件
const KEY_ACTION_HOME_GRADE = 'key_action_home_grade';//会员等级
const KEY_ACTION_HOME_PREFERENTIAL = 'key_action_home_preferential';//会员特权详情
const KEY_ACTION_HOME_ORDER_ORDER = 'key_action_home_order_order';//订单列表
const KEY_ACTION_GUANG_PLUSSTAR_INDEX = 'key_action_guang_plusstar_index'; // 国际优选
const KEY_ACTION_GUANG_PLUSSTAR_LIST = 'key_action_guang_plusstar_list'; // 明星原创
const KEY_ACTION_GUANG_PLUSTAR_DATA = 'key_action_guang_plustar_data'; // 逛PLUSTAR
const KEY_ACTION_GUANG_DETAIL_DATA = 'key_action_guang_detail_data'; // 逛内容详情
const KEY_ACTION_GUANG_RSS_DATA = 'key_action_guang_detail_data'; // 逛订阅内容
const KEY_ACTION_ADDRESS_LIST_DATA = 'key_action_address_list_data'; // 地址树数据
}
<?php
namespace Configs;
/**
* 缓存配置文件
*/
class CacheConfig
{
/* 公共的数据缓存 */
const KEY_COMMON_SIDE_NAV = 'key_common_side_nav'; // 公共的侧边栏
const KEY_COMMON_CATEGORY_CLASSES = 'key_common_category_classes'; // 公共的品类数据
const KEY_COMMON_CATEGORY_CLASSES_NAMES = 'key_common_category_classes_names'; // 公共的品类名称列表
/* 控制器方法中的数据缓存 */
const KEY_ACTION_INDEX_INDEX = 'key_action_index_index'; // 频道选择
const KEY_ACTION_BOYS_INDEX = 'key_action_boys_index'; // 男生首页
const KEY_ACTION_GIRLS_INDEX = 'key_action_girls_index'; // 女生首页
const KEY_ACTION_KIDS_INDEX = 'key_action_kids_index'; // 潮童首页
const KEY_ACTION_LIFESTYLE_INDEX = 'key_action_lifestyle_index'; // 创意生活首页
const KEY_ACTION_BOYS_BOTTOM_BANNER = 'key_action_boys_bottom_banner'; // 男生首页底部banner
const KEY_ACTION_GRILS_BOTTOM_BANNER = 'key_action_girls_bottom_banner';// 女生首页底部banner
const KEY_ACTION_PRODUCT_NEWSALE_INDEX_BOYS = 'key_action_product_newsale_index_boys'; // 男生新品到着
const KEY_ACTION_PRODUCT_NEWSALE_INDEX_GIRLS = 'key_action_product_newsale_index_girls'; // 女生新品到着
const KEY_ACTION_PRODUCT_NEWSALE_INDEX_KIDS = 'key_action_product_newsale_index_kids'; // 潮童新品到着
const KEY_ACTION_PRODUCT_NEWSALE_INDEX_LIFESTYLE = 'key_action_product_newsale_index_lifestyle'; // 创意生活新品到着
const KEY_ACTION_PRODUCT_NEWSALE_DISCOUNT_BOYS = 'key_action_product_newsale_discount_boys'; // 男生热卖排行
const KEY_ACTION_PRODUCT_NEWSALE_DISCOUNT_GIRLS = 'key_action_product_newsale_discount_girls'; // 女生热卖排行
const KEY_ACTION_PRODUCT_NEWSALE_DISCOUNT_KIDS = 'key_action_product_newsale_discount_kids'; // 潮童热卖排行
const KEY_ACTION_PRODUCT_NEWSALE_DISCOUNT_LIFESTYLE = 'key_action_product_newsale_discount_lifestyle'; // 创意生活热卖排行
const KEY_ACTION_PRODUCT_INDEX = 'key_action_product_index'; // 品类商品列表
const KEY_ACTION_PRODUCT_BRAND = 'key_action_product_brand'; // 品类商品列表
const KEY_ACTION_PRODUCT_BRAND_DOMAINS = 'key_action_product_brand_domains'; // 所有品牌域名列表
const KEY_ACTION_PRODUCT_BRAND_NAMES = 'key_action_product_brand_names'; // 所有品牌名称列表
const KEY_ACTION_PRODUCT_BRAND_LOGO = 'key_action_product_brand_logo'; // 品牌信息
const KEY_ACTION_PRODUCT_BRAND_LOGO_DOMAIN = 'key_action_product_brand_logo_domain'; // 品牌信息通过域名取得
const KEY_ACTION_SEARCH_SEARCH = 'key_action_search_search'; // 搜索的数据
const KEY_ACTION_SEARCH_FILTER = 'key_action_search_filter'; // 搜索的过滤条件
const KEY_ACTION_HOME_GRADE = 'key_action_home_grade';//会员等级
const KEY_ACTION_HOME_PREFERENTIAL = 'key_action_home_preferential';//会员特权详情
const KEY_ACTION_HOME_ORDER_ORDER = 'key_action_home_order_order';//订单列表
const KEY_ACTION_GUANG_PLUSSTAR_INDEX = 'key_action_guang_plusstar_index'; // 国际优选
const KEY_ACTION_GUANG_PLUSSTAR_LIST = 'key_action_guang_plusstar_list'; // 明星原创
const KEY_ACTION_GUANG_PLUSTAR_DATA = 'key_action_guang_plustar_data'; // 逛PLUSTAR
const KEY_ACTION_GUANG_DETAIL_DATA = 'key_action_guang_detail_data'; // 逛内容详情
const KEY_ACTION_GUANG_RSS_DATA = 'key_action_guang_detail_data'; // 逛订阅内容
const KEY_ACTION_ADDRESS_LIST_DATA = 'key_action_address_list_data'; // 地址树数据
const KEY_INDEX_BRANDS_LIST_DATA = 'key_index_brands_list_data';//频道brands数据
}
... ...
... ... @@ -6,6 +6,93 @@ class ChannelConfig
* 最新上架分类
*/
public static $newArrivalSortList = array(
//首页
'boys' => array(
array(
'misort' => 16,
'viewNum' => 5
),//卫衣
array(
'misort' => 44,
'viewNum' => 5
),//休闲/运动鞋
array(
'misort' => 21,
'viewNum' => 5
),//夹克
array(
'misort' => 26,
'viewNum' => 5
),//休闲裤
array(
'misort' => 11,
'viewNum' => 5
),//T恤
array(
'misort' => 49,
'viewNum' => 5
),//双肩包
array(
'misort' => 12,
'viewNum' => 5
),//衬衫
array(
'misort' => 27,
'viewNum' => 5
),//牛仔裤
array(
'misort' => 45,
'viewNum' => 5
),//靴子
array(
'misort' => 257,
'viewNum' => 5
),//毛衣/针织
array(
'misort' => 226,
'viewNum' => 5
),//防风外套
array(
'misort' => 22,
'viewNum' => 5
),//大衣/风衣
array(
'misort' => 50,
'viewNum' => 5
),//手拎包/单肩包
array(
'misort' => 18,
'viewNum' => 5
),//羽绒服
array(
'misort' => 20,
'viewNum' => 5
),//棉衣
array(
'misort' => 345,
'viewNum' => 5
),//运动裤
array(
'misort' => 48,
'viewNum' => 5
),//时装鞋
array(
'misort' => 60,
'viewNum' => 5
),//帽子
array(
'misort' => 61,
'viewNum' => 5
),//太阳镜/眼镜
array(
'misort' => 65,
'viewNum' => 5
),//首饰
array(
'misort' => 59,
'viewNum' => 5
),//手表
),
//女首上架分类
'girls' => array(
array(
... ...
<?php
namespace LibModels\Web\Product;
use Api\Yohobuy;
use Api\Sign;
/**
* 品牌数据接口操作类
*
* @name BrandData
* @package Library/LibModels/wap/Category
* @copyright yoho.inc
* @version 1.0 (2015-10-10)
* @author gtskk <rocky.zhang@yoho.cn>
*/
class BrandData
{
const URI_BRAND_TOPPOS = 'operations/api/v5/resource/get';
const URL_BRAND_LOGO = '/shops/service/v1/brand';
/**
* 获取品牌介绍
*
* @param integer $brandId 品牌ID
* @param int 用户ID
* @return array 品牌介绍信息
*/
public static function getBrandIntro($brandId, $uid)
{
// 构建必传参数
$param = Yohobuy::param();
$param['brand_id'] = $brandId;
$param['uid'] = '10267443';
$param['method'] = 'app.brand.getBrandIntro';
$param['client_secret'] = Sign::getSign($param);
$cache = empty($uid) ? 3600 : false;
return Yohobuy::get(Yohobuy::API_URL, $param, $cache); // 有缓存1小时
}
/**
* 获取品牌banner数据
* @param integer $brandId 品牌ID
* @return array banner数据
*/
public static function getBrandBanner($brandId)
{
// 构建必传参数
$param = Yohobuy::param();
$param['brand_id'] = $brandId;
$param['method'] = 'app.brand.banner';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param, 3600); // 有缓存1小时
}
/**
* 获取品牌介绍信息
*
* @param int $id 品牌id
* @return array
*/
public static function getBrandLogo($id)
{
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_BRAND_LOGO, 'getBrandByids', array($id ));
}
/**
* 通过域名获取品牌LOGO信息
*
* @param int $domain 品牌domain
* @return array
*/
public static function getBrandLogoByDomain($domain)
{
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_BRAND_LOGO, 'getBrandByDomain', array($domain ));
}
}
... ...
<?php
namespace LibModels\Web\Product;
use Api\Yohobuy;
class SearchData extends \LibModels\Wap\Product\SearchData
{
/**
* 获取搜索的服务地址
*
* 备注:此处是根据环境来确定使用阿里云内网还是外网的URL
*
* @return string
*/
private static function getUrl($type = 'search')
{
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer');
switch (APPLICATION_ENV) {
case 'release':
if($type == 'sort'){
return 'http://100.98.132.63/yohosearch/sortgroup.json';
}
if($type == 'discount'){
return 'http://100.98.132.63/yohosearch/discount.json';
}
if($type == 'recent'){
return 'http://100.98.132.63/yohosearch/recent.json';
}
return 'http://100.98.132.63/yohosearch/search.json';
case 'test':
case 'preview':
case 'developer':
default:
if($type == 'sort'){
return 'http://101.200.31.165/yohosearch/sortgroup.json';
}
if($type == 'discount'){
return 'http://101.200.31.165/yohosearch/discount.json';
}
if($type == 'recent'){
return 'http://101.200.31.165/yohosearch/recent.json';
}
return 'http://101.200.31.165/yohosearch/search.json';
}
}
/**
* 根据分类列表获取商品信息
*
*
* @param array $params
* @param array $sortList
* @return array
... ... @@ -17,8 +56,8 @@ class SearchData extends \LibModels\Wap\Product\SearchData
if(empty($v['viewNum'])){
continue;
}
$params = array_merge($params, $v);
$list = self::searchElasticByCondition($params, true);
$searchParams = array_merge($params, $v);
$list = self::searchElasticByCondition($searchParams, true);
$productList = empty($list['data']['product_list']) ? array() : $list['data']['product_list'];
if(count($productList) < $v['viewNum']){
continue;
... ... @@ -27,4 +66,29 @@ class SearchData extends \LibModels\Wap\Product\SearchData
}
return $data;
}
/**
* 获取品类数据
*
* @return array 品类数据
*/
public static function getClassesData($condition = array(), $cache = false)
{
$param['brand'] = $condition;
return Yohobuy::get(self::getUrl('sort'),$param, $cache);
}
/**
* 获取折扣区间
*/
public static function getDiscount(){
return Yohobuy::get(self::getUrl('discount'));
}
/**
* 获取最新上架
*/
public static function recentShelve(){
return Yohobuy::get(self::getUrl('recent'));
}
}
\ No newline at end of file
... ...
<?php
namespace Plugin;
use Hood\Cache as HoodCache;
/**
* 数据缓存的操作类
*
* @name Cache
* @package Plugin
* @copyright yoho.inc
* @version 1.0 (2015-10-10 11:23:47)
* @author fei.hong <fei.hong@yoho.cn>
*/
class Cache
{
/**
* 设置缓存
*
* 备注:
* 采用主从分布式缓存
* master 代表主缓存服务器
* slave 代表从缓存服务器
*
* 作用:
* 在后端的服务异常挂掉了并且主服务器缓存(master)的数据时间到期后,
* 能获取从服务器缓存(slave)的数据,不影响前端页面的正常访问.
*
* @param string $key 键名
* @param mixed $value 需要缓存的数据
* @param int $expire 缓存有效期(单位秒, 0表示永久)
* @return void
*/
public static function set($key, $value, $expire = 3600)
{
try {
// WINDOWS
if (DIRECTORY_SEPARATOR === '\\') {
HoodCache::Memcache('master')->set(self::makeKey($key, 'master'), $value, $expire);
HoodCache::Memcache('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天
}
// LINUX
else {
HoodCache::Memcached('master')->set(self::makeKey($key, 'master'), $value, $expire);
HoodCache::Memcached('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天
}
} catch (Exception $e) {
// do nothing
}
}
/**
* 获取缓存
*
* @param string $key 键名
* @param string $node master代表主服务器, slave代表从服务器
* @return mixed
*/
public static function get($key, $node = 'master')
{
$result = array();
try {
// WINDOWS
if (DIRECTORY_SEPARATOR === '\\') {
$result = HoodCache::Memcache($node)->get(self::makeKey($key, $node));
}
// LINUX
else {
$result = HoodCache::Memcached($node)->get(self::makeKey($key, $node));
}
} catch (Exception $e) {
$result = array();
}
return $result;
}
/**
* 清除缓存
*
* @param string $key 键名
* @return void
*/
public static function delete($key)
{
// WINDOWS
if (DIRECTORY_SEPARATOR === '\\') {
HoodCache::Memcache('master')->delete(self::makeKey($key, 'master'));
HoodCache::Memcache('slave')->delete(self::makeKey($key, 'slave'));
}
// LINUX
else {
HoodCache::Memcached('master')->delete(self::makeKey($key, 'master'));
HoodCache::Memcached('slave')->delete(self::makeKey($key, 'slave'));
}
}
/**
* 生成键名
*
* @param string $key 键名
* @param string $prefix 前缀标识
* @return string
*/
public static function makeKey($key, $prefix)
{
return md5($prefix . '_' . $key);
}
}
<?php
namespace Plugin;
use Hood\Cache as HoodCache;
/**
* 数据缓存的操作类
*
* @name Cache
* @package Plugin
* @copyright yoho.inc
* @version 1.0 (2015-10-10 11:23:47)
* @author fei.hong <fei.hong@yoho.cn>
*/
class Cache
{
/**
* 设置缓存
*
* 备注:
* 采用主从分布式缓存
* master 代表主缓存服务器
* slave 代表从缓存服务器
*
* 作用:
* 在后端的服务异常挂掉了并且主服务器缓存(master)的数据时间到期后,
* 能获取从服务器缓存(slave)的数据,不影响前端页面的正常访问.
*
* @param string $key 键名
* @param mixed $value 需要缓存的数据
* @param int $expire 缓存有效期(单位秒, 0表示永久)
* @return void
*/
public static function set($key, $value, $expire = 3600)
{
try {
// WINDOWS
if (DIRECTORY_SEPARATOR === '\\') {
HoodCache::Memcache('master')->set(self::makeKey($key, 'master'), $value, $expire);
HoodCache::Memcache('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天
}
// LINUX
else {
HoodCache::Memcached('master')->set(self::makeKey($key, 'master'), $value, $expire);
HoodCache::Memcached('slave')->set(self::makeKey($key, 'slave'), $value, 86400); // 二级缓存1天
}
} catch (Exception $e) {
// do nothing
}
}
/**
* 获取缓存
*
* @param string $key 键名
* @param string $node master代表主服务器, slave代表从服务器
* @return mixed
*/
public static function get($key, $node = 'master')
{
$result = array();
try {
// WINDOWS
if (DIRECTORY_SEPARATOR === '\\') {
$result = HoodCache::Memcache($node)->get(self::makeKey($key, $node));
}
// LINUX
else {
$result = HoodCache::Memcached($node)->get(self::makeKey($key, $node));
}
} catch (Exception $e) {
$result = array();
}
return $result;
}
/**
* 清除缓存
*
* @param string $key 键名
* @return void
*/
public static function delete($key)
{
// WINDOWS
if (DIRECTORY_SEPARATOR === '\\') {
HoodCache::Memcache('master')->delete(self::makeKey($key, 'master'));
HoodCache::Memcache('slave')->delete(self::makeKey($key, 'slave'));
}
// LINUX
else {
HoodCache::Memcached('master')->delete(self::makeKey($key, 'master'));
HoodCache::Memcached('slave')->delete(self::makeKey($key, 'slave'));
}
}
/**
* 生成键名
*
* @param string $key 键名
* @param string $prefix 前缀标识
* @return string
*/
public static function makeKey($key, $prefix)
{
return md5($prefix . '_' . $key);
}
}
... ...
<?php
namespace Plugin\DataProcess;
use Plugin\Helpers;
/**
* 楼层数据处理类
*/
class FloorProcess
{
/**
* 频道参数
*
* @var array
*/
private static $channel = array(
'1' => '1,3',
'2' => '2,3'
);
/**
* 处理首页内容
* @param $data
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
*/
public static function getContent($data, $type = 1)
{
if (empty($data['list'])) {
return array();
}
$result = array();
$build = array();
foreach ($data['list'] as $v) {
if (empty($v)) {
continue;
}
$fun = $v['template_name'];
if (empty($v['data']) || !is_callable("self::$fun")) {
continue;
}
$build = self::$fun($v['data'], $type);
if (empty($build)) {
continue;
}
$result[] = $build;
}
$build = array();
return $result;
}
/**
* 焦点图数据处理方法
* @param array $data 焦点图数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的焦点图数据
*/
private static function focus($data, $type)
{
$result = array();
foreach ($data as $one) {
$result['bannerTop']['list'][] = Helpers::formatBanner($one, 640, 240);
}
return $result;
}
/**
* 图标
*/
private static function floor($data)
{
$result = array();
foreach ($data as &$one) {
$one['url'] = Helpers::getFilterUrl($one['url']);
$one['img'] = Helpers::getImageUrl($one['src'], 98, 98);
unset($one['src']);
}
$result['iconsEnter']['list'] = $data;
return $result;
}
/**
* 图标列表数据处理方法
*
* @param array $data 图标列表数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的图标列表数据
*/
private static function app_icon_list($data, $type)
{
$result = array();
foreach ($data as &$one) {
$one['url'] = Helpers::getFilterUrl($one['url']);
$one['img'] = Helpers::getImageUrl($one['src'], 98, 98);
unset($one['src']);
}
$result['iconsEnter']['list'] = $data;
return $result;
}
/**
* 单广告图片数据处理方法
*
* @param array $data 单图片数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的单图片数据
*/
private static function single_image($data, $type)
{
$result = array();
foreach ($data as &$one) {
$one['url'] = Helpers::getFilterUrl($one['url']);
$one['img'] = Helpers::getImageUrl($one['src'], 640, 200);
unset($one['src']);
}
$result['banner'] = $data;
return $result;
}
/**
* 女生品类
* 推荐(1T-12F)
*/
private static function recommend_content_three($data, $type)
{
$result = array();
$build = array();
if (!empty($data['big_image'][0])) {
$build['img'] = Helpers::getImageUrl($data['big_image'][0]['src'], 640, 200);
$build['url'] = Helpers::getFilterUrl($data['big_image'][0]['url']);
$result['hotCategory']['banner'] = $build;
}
$build = array();
foreach ($data['list'] as $one) {
$build['url'] = Helpers::getFilterUrl($one['url']);
$build['img'] = Helpers::getImageUrl($one['src'], 128, 140);
$build['textCn'] = $one['title'];
$result['hotCategory']['list'][] = $build;
}
if (isset($data['title']['more_url'])) {
$data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
}
return $result;
}
/**
* 带标题的12个小图推荐数据处理方法
*
* @param array $data 带标题的12个小图推荐数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的带标题的12个小图推荐数据
*/
private static function recommend_content_five($data, $type)
{
$result = array();
foreach ($data['list'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 140, 140);
$one['textCn'] = $one['title'];
unset($one['src']);
}
$data['is_show_name'] = $data['title']['is_show'];
$data['name'] = $data['title']['title'];
unset($data['title']);
if (isset($data['title']['more_url'])) {
$data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
}
$result['hotCategory'] = $data;
return $result;
}
/**
* 推荐品牌数据处理方法
* @param array $data 推荐品牌数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的推荐品牌数据
*/
private static function app_hot_brands($data, $type)
{
$result = array();
$data['is_show_name'] = (isset($data['is_show_name']) && $data['is_show_name'] === 'Y') ? 1 : 0;
$data['name'] = $data['title']['title'];
unset($data['title']);
foreach ($data['list'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
isset(self::$channel[$type]) && $one['url'] .= '?gender=' . self::$channel[$type];
}
$one['img'] = Helpers::getImageUrl($one['src'], 158, 174);
unset($one['src']);
}
$data['more'] = '/brands?channel=' . $type;
$result['hotBrands'] = $data;
return $result;
}
/**
* 潮人·搭配数据处理方法
* @param array $data 潮人·搭配数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的潮人·搭配数据
*/
private static function trendsetter_collocation($data, $type)
{
$result = array();
foreach ($data as $key => &$value) {
if ($key == 'title') {
$value['more_url'] = Helpers::url('', array('id' => 3, 'gender' => self::$channel[$type]), 'guang');
}
if ($key == 'article') {
foreach ($value as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 400, 400);
unset($one['src']);
}
}
if ($key == 'recommend_collocation') {
foreach ($value as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 140, 140);
unset($one['src']);
}
}
}
$result['trendColloaction'] = $data;
return $result;
}
/**
* 潮品·话题数据处理方法
* @param array $data 潮品·话题数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的潮品·话题数据
*/
private static function trendgoods_topic($data, $type)
{
$result = array();
foreach ($data as $key => &$value) {
if ($key == 'title') {
$urlParam = array('id' => 4);
isset(self::$channel[$type]) && $urlParam['gender'] = self::$channel[$type];
$value['more_url'] = Helpers::url('', $urlParam, 'guang');
}
if ($key == 'list') {
foreach ($value as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 580, 360);
unset($one['src']);
}
}
}
$result['trendTopics'] = $data;
return $result;
}
/**
* 一张大图一个大的推荐和4个小图推荐数据处理方法
* @param array $data 一张大图一个大的推荐和4个小图推荐数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的一张大图一个大的推荐和4个小图推荐数据
*/
private static function recommend_content_one($data, $type)
{
$result = array();
foreach ($data['big_image'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 640, 403);
unset($one['src']);
}
// 区别多张图与一张图
if (count($data['big_image']) > 1) {
$result['big_image']['big_list'] = $data['big_image'];
unset($data['big_image']);
}
foreach ($data['list'] as $kk => &$one) {
if ($kk == 0) {
$one['img'] = Helpers::getImageUrl($one['src'], 253, 383);
} else {
$one['img'] = Helpers::getImageUrl($one['src'], 191, 191);
}
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['textCn'] = $one['title'];
unset($one['src']);
}
if (isset($data['title']['more_url'])) {
$data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
}
$result['goodsCategory'] = $data;
return $result;
}
/**
* 一张大图和6个小图推荐数据处理方法
* @param array $data 一张大图和6个小图推荐数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的一张大图和6个小图推荐数据
*/
private static function recommend_content_two($data, $type)
{
$result = array();
foreach ($data['big_image'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 640, 403);
unset($one['src']);
}
$data['banner'] = $data['big_image'];
unset($data['big_image']);
foreach ($data['list'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 191, 191);
unset($one['src']);
}
if (isset($data['title']['more_url'])) {
$data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
}
$result['creativeLife'] = $data;
return $result;
}
/**
* 小图片数据处理方法
* @param array $data 小图片数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的小图片数据
*/
private static function small_pic($data, $type)
{
// 按照以前业务操作,不显示
return array();
$result = array();
foreach ($data as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 98, 98);
unset($one['src']);
}
$result['small_pic'] = $data;
return $result;
}
/**
* plus,star
* @param array $data 单名字图片数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的单名字图片数据
*/
private static function single_name_image($data, $type)
{
if (empty($data)) {
return array();
}
$data['name'] = $data['title'];
$data['img'] = Helpers::getImageUrl($data['src'], 640, 198);
if (isset($data['url'])) {
$data['url'] = Helpers::getFilterUrl($data['url']);
}
return array('plusStar' => $data);
}
/**
* 自定义品牌
*
* @param unknown $data
* @param mixed $type
* @return multitype:
*/
private static function custom_brands($data, $type)
{
// URL附加参数
$param = '';
if (isset(self::$channel[$type])) {
$param = '/?gender=' . self::$channel[$type];
}
$result = array();
$result['hotBrandsScroll']['name'] = $data['title']['title'];
foreach ($data['list'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 140, 140);
$one['textCn'] = $one['name'];
if (isset($one['url'])) {
$one['url'] .= $param;
}
}
if (!empty($data['is_show_name']) && $data['is_show_name'] == 'Y') {
$result['hotBrandsScroll']['is_show_name'] = true;
}
$result['hotBrandsScroll']['list'] = $data['list'];
return $result;
}
}
<?php
namespace Plugin\DataProcess;
use Plugin\Helpers;
/**
* 楼层数据处理类
*/
class FloorProcess
{
/**
* 频道参数
*
* @var array
*/
private static $channel = array(
'1' => '1,3',
'2' => '2,3'
);
/**
* 处理首页内容
* @param $data
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
*/
public static function getContent($data, $type = 1)
{
if (empty($data['list'])) {
return array();
}
$result = array();
$build = array();
foreach ($data['list'] as $v) {
if (empty($v)) {
continue;
}
$fun = $v['template_name'];
if (empty($v['data']) || !is_callable("self::$fun")) {
continue;
}
$build = self::$fun($v['data'], $type);
if (empty($build)) {
continue;
}
$result[] = $build;
}
$build = array();
return $result;
}
/**
* 焦点图数据处理方法
* @param array $data 焦点图数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的焦点图数据
*/
private static function focus($data, $type)
{
$result = array();
foreach ($data as $one) {
$result['bannerTop']['list'][] = Helpers::formatBanner($one, 640, 240);
}
return $result;
}
/**
* 图标
*/
private static function floor($data)
{
$result = array();
foreach ($data as &$one) {
$one['url'] = Helpers::getFilterUrl($one['url']);
$one['img'] = Helpers::getImageUrl($one['src'], 98, 98);
unset($one['src']);
}
$result['iconsEnter']['list'] = $data;
return $result;
}
/**
* 图标列表数据处理方法
*
* @param array $data 图标列表数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的图标列表数据
*/
private static function app_icon_list($data, $type)
{
$result = array();
foreach ($data as &$one) {
$one['url'] = Helpers::getFilterUrl($one['url']);
$one['img'] = Helpers::getImageUrl($one['src'], 98, 98);
unset($one['src']);
}
$result['iconsEnter']['list'] = $data;
return $result;
}
/**
* 单广告图片数据处理方法
*
* @param array $data 单图片数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的单图片数据
*/
private static function single_image($data, $type)
{
$result = array();
foreach ($data as &$one) {
$one['url'] = Helpers::getFilterUrl($one['url']);
$one['img'] = Helpers::getImageUrl($one['src'], 640, 200);
unset($one['src']);
}
$result['banner'] = $data;
return $result;
}
/**
* 女生品类
* 推荐(1T-12F)
*/
private static function recommend_content_three($data, $type)
{
$result = array();
$build = array();
if (!empty($data['big_image'][0])) {
$build['img'] = Helpers::getImageUrl($data['big_image'][0]['src'], 640, 200);
$build['url'] = Helpers::getFilterUrl($data['big_image'][0]['url']);
$result['hotCategory']['banner'] = $build;
}
$build = array();
foreach ($data['list'] as $one) {
$build['url'] = Helpers::getFilterUrl($one['url']);
$build['img'] = Helpers::getImageUrl($one['src'], 128, 140);
$build['textCn'] = $one['title'];
$result['hotCategory']['list'][] = $build;
}
if (isset($data['title']['more_url'])) {
$data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
}
return $result;
}
/**
* 带标题的12个小图推荐数据处理方法
*
* @param array $data 带标题的12个小图推荐数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的带标题的12个小图推荐数据
*/
private static function recommend_content_five($data, $type)
{
$result = array();
foreach ($data['list'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 140, 140);
$one['textCn'] = $one['title'];
unset($one['src']);
}
$data['is_show_name'] = $data['title']['is_show'];
$data['name'] = $data['title']['title'];
unset($data['title']);
if (isset($data['title']['more_url'])) {
$data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
}
$result['hotCategory'] = $data;
return $result;
}
/**
* 推荐品牌数据处理方法
* @param array $data 推荐品牌数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的推荐品牌数据
*/
private static function app_hot_brands($data, $type)
{
$result = array();
$data['is_show_name'] = (isset($data['is_show_name']) && $data['is_show_name'] === 'Y') ? 1 : 0;
$data['name'] = $data['title']['title'];
unset($data['title']);
foreach ($data['list'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
isset(self::$channel[$type]) && $one['url'] .= '?gender=' . self::$channel[$type];
}
$one['img'] = Helpers::getImageUrl($one['src'], 158, 174);
unset($one['src']);
}
$data['more'] = '/brands?channel=' . $type;
$result['hotBrands'] = $data;
return $result;
}
/**
* 潮人·搭配数据处理方法
* @param array $data 潮人·搭配数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的潮人·搭配数据
*/
private static function trendsetter_collocation($data, $type)
{
$result = array();
foreach ($data as $key => &$value) {
if ($key == 'title') {
$value['more_url'] = Helpers::url('', array('id' => 3, 'gender' => self::$channel[$type]), 'guang');
}
if ($key == 'article') {
foreach ($value as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 400, 400);
unset($one['src']);
}
}
if ($key == 'recommend_collocation') {
foreach ($value as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 140, 140);
unset($one['src']);
}
}
}
$result['trendColloaction'] = $data;
return $result;
}
/**
* 潮品·话题数据处理方法
* @param array $data 潮品·话题数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的潮品·话题数据
*/
private static function trendgoods_topic($data, $type)
{
$result = array();
foreach ($data as $key => &$value) {
if ($key == 'title') {
$urlParam = array('id' => 4);
isset(self::$channel[$type]) && $urlParam['gender'] = self::$channel[$type];
$value['more_url'] = Helpers::url('', $urlParam, 'guang');
}
if ($key == 'list') {
foreach ($value as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 580, 360);
unset($one['src']);
}
}
}
$result['trendTopics'] = $data;
return $result;
}
/**
* 一张大图一个大的推荐和4个小图推荐数据处理方法
* @param array $data 一张大图一个大的推荐和4个小图推荐数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的一张大图一个大的推荐和4个小图推荐数据
*/
private static function recommend_content_one($data, $type)
{
$result = array();
foreach ($data['big_image'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 640, 403);
unset($one['src']);
}
// 区别多张图与一张图
if (count($data['big_image']) > 1) {
$result['big_image']['big_list'] = $data['big_image'];
unset($data['big_image']);
}
foreach ($data['list'] as $kk => &$one) {
if ($kk == 0) {
$one['img'] = Helpers::getImageUrl($one['src'], 253, 383);
} else {
$one['img'] = Helpers::getImageUrl($one['src'], 191, 191);
}
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['textCn'] = $one['title'];
unset($one['src']);
}
if (isset($data['title']['more_url'])) {
$data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
}
$result['goodsCategory'] = $data;
return $result;
}
/**
* 一张大图和6个小图推荐数据处理方法
* @param array $data 一张大图和6个小图推荐数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的一张大图和6个小图推荐数据
*/
private static function recommend_content_two($data, $type)
{
$result = array();
foreach ($data['big_image'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 640, 403);
unset($one['src']);
}
$data['banner'] = $data['big_image'];
unset($data['big_image']);
foreach ($data['list'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 191, 191);
unset($one['src']);
}
if (isset($data['title']['more_url'])) {
$data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
}
$result['creativeLife'] = $data;
return $result;
}
/**
* 小图片数据处理方法
* @param array $data 小图片数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的小图片数据
*/
private static function small_pic($data, $type)
{
// 按照以前业务操作,不显示
return array();
$result = array();
foreach ($data as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 98, 98);
unset($one['src']);
}
$result['small_pic'] = $data;
return $result;
}
/**
* plus,star
* @param array $data 单名字图片数据
* @param $type 类型 默认1:男首页 2:女首页 3:kids 4:lifestyle
* @return array 处理之后的单名字图片数据
*/
private static function single_name_image($data, $type)
{
if (empty($data)) {
return array();
}
$data['name'] = $data['title'];
$data['img'] = Helpers::getImageUrl($data['src'], 640, 198);
if (isset($data['url'])) {
$data['url'] = Helpers::getFilterUrl($data['url']);
}
return array('plusStar' => $data);
}
/**
* 自定义品牌
*
* @param unknown $data
* @param mixed $type
* @return multitype:
*/
private static function custom_brands($data, $type)
{
// URL附加参数
$param = '';
if (isset(self::$channel[$type])) {
$param = '/?gender=' . self::$channel[$type];
}
$result = array();
$result['hotBrandsScroll']['name'] = $data['title']['title'];
foreach ($data['list'] as &$one) {
if (isset($one['url'])) {
$one['url'] = Helpers::getFilterUrl($one['url']);
}
$one['img'] = Helpers::getImageUrl($one['src'], 140, 140);
$one['textCn'] = $one['name'];
if (isset($one['url'])) {
$one['url'] .= $param;
}
}
if (!empty($data['is_show_name']) && $data['is_show_name'] == 'Y') {
$result['hotBrandsScroll']['is_show_name'] = true;
}
$result['hotBrandsScroll']['list'] = $data['list'];
return $result;
}
}
... ...
<?php
namespace Plugin\DataProcess;
use Plugin\Helpers;
/**
* 列表数据处理类
*/
class ListProcess
{
/**
* 返回商品和过滤数据
*
* @param $data
* @return array 处理之后的商品数据
*/
public static function getListData($data, $returnFilter = true)
{
$result = array();
if (isset($data['product_list'])) {
$result['new'] = self::getProductData($data['product_list']);
}
if ($returnFilter && isset($data['filter'])) {
$result['filter'] = self::getFilterData($data['filter']);
}
return $result;
}
/**
* 处理列表商品数据
*
* @param $data
* @return array 处理之后的商品数据
*/
public static function getProductData($data)
{
// 处理商品
$products = array();
foreach ($data as $value) {
$products[] = Helpers::formatProduct($value, true, true, true, 235, 314);
}
return $products;
}
/**
* 处理筛选数据
*
* @param $data
* @param string | integer $gender 默认选择的性别,默认1,2,3表示所有
* @param null|string $exclude 需要排除的字段
* @return array 处理之后的筛选数据
*/
public static function getFilterData($data, $gender = '1,2,3', $exclude = null)
{
// 过滤条件数据
$filters = array('classify' => array());
// 返回数据中有没有gender时要添加gender
$data['gender'] = array('2,3' => 'GIRLS', '1,3' => 'BOYS');
$num = 1;
foreach ($data as $key => $val) {
if ($key === $exclude || empty($val) || !is_callable("self::$key")) {
continue;
}
$build = self::$key($val, $gender);
if ($num === 1) {
$build['active'] = true;
}
$num++;
$filters['classify'][] = $build;
}
// 按照指定字段进行排序筛选数据
self::sortArrByField($filters['classify'], 'sort_col');
return $filters;
}
private static function brand($data)
{
$result = array(
'title' => '品牌',
'name' => '所有品牌',
'sort_col' => 1,
'dataType' => 'brand',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有品牌'
)
)
);
// 对品牌数据按照品牌字母进行排序
self::sortArrByField($data, 'brand_alif');
foreach ($data as $one) {
$brand = array();
$brand['dataId'] = $one['id'];
$brand['name'] = $one['brand_name'];
$result['subs'][] = $brand;
}
return $result;
}
private static function color($data)
{
$result = array(
'title' => '颜色',
'name' => '所有颜色',
'sort_col' => 3,
'dataType' => 'color',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有颜色'
)
)
);
foreach ($data as $one) {
$color = array();
$color['dataId'] = $one['color_id'];
$color['name'] = $one['color_name'];
$result['subs'][] = $color;
}
return $result;
}
private static function discount($data)
{
$result = array(
'title' => '折扣',
'name' => '所有商品',
'sort_col' => 6,
'dataType' => 'discount',
'subs' => array(
array(
'chosed' => true,
'dataId' => '0.1,0.9',
'name' => '所有商品'
)
)
);
foreach ($data as $key => $one) {
$discount = array();
$discount['dataId'] = $key;
$discount['name'] = $one['name'] . '折商品';
$result['subs'][] = $discount;
}
return $result;
}
private static function gender($data, $gender)
{
$result = array(
'title' => '性别',
'name' => '所有性别',
'sort_col' => 0,
'dataType' => 'gender',
'subs' => array(
array(
'dataId' => '1,2,3',
'name' => '所有性别'
),
array(
'dataId' => '1,3',
'name' => 'BOYS'
),
array(
'dataId' => '2,3',
'name' => 'GIRLS'
),
)
);
// 处理选中状态
foreach ($result['subs'] as &$val) {
if ($val['dataId'] === $gender) {
$val['chosed'] = true;
$result['name'] = $val['name'];
}
}
return $result;
}
private static function group_sort($data)
{
$result = array(
'title' => '品类',
'name' => '所有品类',
'sort_col' => 2,
'dataType' => 'sort',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有品类'
)
)
);
$category = array();
foreach ($data as $one) {
$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'];
$category['subs'][] = $subitem;
}
} */
$result['subs'][] = $category;
}
return $result;
}
private static function priceRange($data)
{
// 首先对价格进行排序
ksort($data, SORT_NUMERIC);
$result = array(
'title' => '价格',
'name' => '所有价格',
'sort_col' => 5,
'dataType' => 'price',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有价格'
)
)
);
$price = array();
foreach ($data as $key => $one) {
$price['dataId'] = $key;
$price['name'] = $one;
$result['subs'][] = $price;
}
return $result;
}
private static function size($data)
{
$result = array(
'title' => '尺码',
'name' => '所有尺码',
'sort_col' => 4,
'dataType' => 'size',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有尺码'
)
)
);
$size = array();
foreach ($data as $one) {
$size['dataId'] = $one['size_id'];
$size['name'] = $one['size_name'];
$result['subs'][] = $size;
}
return $result;
}
/**
* 按照数组中指定字段排序二维数组
*
* @param array &$array 需要排序的数组
* @param string $field 字段名称
* @param boolean $desc 时候降序排列,默认为false
*/
private static function sortArrByField(&$array, $field, $desc = false)
{
$fieldArr = array();
foreach ($array as $k => $v) {
$fieldArr[$k] = isset($v[$field]) ? $v[$field] : '';
}
$sort = $desc == false ? SORT_ASC : SORT_DESC;
array_multisort($fieldArr, $sort, $array);
}
}
<?php
namespace Plugin\DataProcess;
use Plugin\Helpers;
/**
* 列表数据处理类
*/
class ListProcess
{
/**
* 返回商品和过滤数据
*
* @param $data
* @return array 处理之后的商品数据
*/
public static function getListData($data, $returnFilter = true)
{
$result = array();
if (isset($data['product_list'])) {
$result['new'] = self::getProductData($data['product_list']);
}
if ($returnFilter && isset($data['filter'])) {
$result['filter'] = self::getFilterData($data['filter']);
}
return $result;
}
/**
* 处理列表商品数据
*
* @param $data
* @return array 处理之后的商品数据
*/
public static function getProductData($data)
{
// 处理商品
$products = array();
foreach ($data as $value) {
$products[] = Helpers::formatProduct($value, true, true, true, 235, 314);
}
return $products;
}
/**
* 处理筛选数据
*
* @param $data
* @param string | integer $gender 默认选择的性别,默认1,2,3表示所有
* @param null|string $exclude 需要排除的字段
* @return array 处理之后的筛选数据
*/
public static function getFilterData($data, $gender = '1,2,3', $exclude = null)
{
// 过滤条件数据
$filters = array('classify' => array());
// 返回数据中有没有gender时要添加gender
$data['gender'] = array('2,3'=>'GIRLS','1,3'=>'BOYS');
$num = 1;
foreach ($data as $key => $val) {
if ($key === $exclude || empty($val) || !is_callable("self::$key")) {
continue;
}
$build = self::$key($val, $gender);
if ($num === 1) {
$build['active'] = true;
}
$num++;
$filters['classify'][] = $build;
}
// 按照指定字段进行排序筛选数据
self::sortArrByField($filters['classify'], 'sort_col');
return $filters;
}
private static function brand($data)
{
$result = array(
'title' => '品牌',
'name' => '所有品牌',
'sort_col' => 1,
'dataType' => 'brand',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有品牌'
)
)
);
// 对品牌数据按照品牌字母进行排序
self::sortArrByField($data, 'brand_alif');
foreach ($data as $one) {
$brand = array();
$brand['dataId'] = $one['id'];
$brand['name'] = $one['brand_name'];
$result['subs'][] = $brand;
}
return $result;
}
private static function color($data)
{
$result = array(
'title' => '颜色',
'name' => '所有颜色',
'sort_col' => 3,
'dataType' => 'color',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有颜色'
)
)
);
foreach ($data as $one) {
$color = array();
$color['dataId'] = $one['color_id'];
$color['name'] = $one['color_name'];
$result['subs'][] = $color;
}
return $result;
}
private static function discount($data)
{
$result = array(
'title' => '折扣',
'name' => '所有商品',
'sort_col' => 6,
'dataType' => 'discount',
'subs' => array(
array(
'chosed' => true,
'dataId' => '0.1,0.9',
'name' => '所有商品'
)
)
);
foreach ($data as $key => $one) {
$discount = array();
$discount['dataId'] = $key;
$discount['name'] = $one['name'] . '折商品';
$result['subs'][] = $discount;
}
return $result;
}
private static function gender($data, $gender)
{
$result = array(
'title' => '性别',
'name' => '所有性别',
'sort_col' => 0,
'dataType' => 'gender',
'subs' => array(
array(
'dataId' => '1,2,3',
'name' => '所有性别'
),
array(
'dataId' => '1,3',
'name' => 'BOYS'
),
array(
'dataId' => '2,3',
'name' => 'GIRLS'
),
)
);
// 处理选中状态
foreach ($result['subs'] as &$val) {
if ($val['dataId'] === $gender) {
$val['chosed'] = true;
$result['name'] = $val['name'];
}
}
return $result;
}
private static function group_sort($data)
{
$result = array(
'title' => '品类',
'name' => '所有品类',
'sort_col' => 2,
'dataType' => 'sort',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有品类'
)
)
);
$category = array();
foreach ($data as $one) {
$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'];
$category['subs'][] = $subitem;
}
} */
$result['subs'][] = $category;
}
return $result;
}
private static function priceRange($data)
{
// 首先对价格进行排序
ksort($data, SORT_NUMERIC);
$result = array(
'title' => '价格',
'name' => '所有价格',
'sort_col' => 5,
'dataType' => 'price',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有价格'
)
)
);
$price = array();
foreach ($data as $key => $one) {
$price['dataId'] = $key;
$price['name'] = $one;
$result['subs'][] = $price;
}
return $result;
}
private static function size($data)
{
$result = array(
'title' => '尺码',
'name' => '所有尺码',
'sort_col' => 4,
'dataType' => 'size',
'subs' => array(
array(
'chosed' => true,
'dataId' => 0,
'name' => '所有尺码'
)
)
);
$size = array();
foreach ($data as $one) {
$size['dataId'] = $one['size_id'];
$size['name'] = $one['size_name'];
$result['subs'][] = $size;
}
return $result;
}
/**
* 按照数组中指定字段排序二维数组
*
* @param array &$array 需要排序的数组
* @param string $field 字段名称
* @param boolean $desc 时候降序排列,默认为false
*/
private static function sortArrByField(&$array, $field, $desc = false)
{
$fieldArr = array();
foreach ($array as $k => $v) {
$fieldArr[$k] = isset($v[$field]) ? $v[$field] : '';
}
$sort = $desc == false ? SORT_ASC : SORT_DESC;
array_multisort($fieldArr, $sort, $array);
}
}
... ...
<?php
namespace Plugin\DataProcess\WebChannel;
class Channel
{
public static $formatChannel = array(
'boys' => '\Plugin\DataProcess\WebChannel\Channel\Kids',
'girls' => '\Plugin\DataProcess\WebChannel\Channel\Girls',
'kids' => '\Plugin\DataProcess\WebChannel\Channel\Kids'
);
public static function getFormat($channel, $data)
{
//通用处理器
$result = Process::getContent($data, $channel);
$channelResult = array();
if(isset(self::$formatChannel[$channel]))
{
$class = self::$formatChannel[$channel];
$channelResult = $class::format($data);
}
//组合数据
$result = $result + $channelResult;
ksort($result);
return array_values($result);
}
<?php
namespace Plugin\DataProcess\WebChannel;
class Channel
{
public static $formatChannel = array(
'boys' => '\Plugin\DataProcess\WebChannel\Channel\Boys',
'girls' => '\Plugin\DataProcess\WebChannel\Channel\Girls',
'kids' => '\Plugin\DataProcess\WebChannel\Channel\Kids',
'lifestyle' => '\Plugin\DataProcess\WebChannel\Channel\Lifestyle'
);
public static function getFormat($channel, $data)
{
// 通用处理器
$result = Process::getContent($data, $channel);
$channelResult = array();
if (isset(self::$formatChannel[$channel])) {
$class = self::$formatChannel[$channel];
$channelResult = $class::format($data);
}
// 组合数据
$result = $result + $channelResult;
ksort($result);
return array_values($result);
}
}
... ...
... ... @@ -8,4 +8,38 @@ abstract class AbstractChannel
* @return array[以key方式存储数据]
*/
public static function format($resource){}
/**
* 获取格式化最新上架数据
*
* @param array &$resource
* @return array
*/
public static function getFormatNewArrivals(&$resource)
{
$result = array();
foreach($resource as $key => $val)
{
if(isset($resource[$key]) && isset($resource[$key + 2]))
{
$temp = array('newArrivls' => array('name' => '', 'navs' => array()), 'href' => '');
//newArrivals
if($resource[$key]['template_name'] == 'text' && $resource[$key + 1]['template_name'] == 'textNav')
{
//text模版
$temp['newArrivls']['name'] = $resource[$key]['data']['text'];
//textNav模版
foreach($resource[$key + 1]['data'] as $val)
{
$temp['newArrivls']['navs'][] = array('href' => $val['url'],'name' => $val['name']);
}
//link模版
$temp['href'] = $resource[$key + 2]['data'][0]['url'];
unset($resource[$key], $resource[$key + 1], $resource[$key + 2]);
$result[$key] = $temp;
}
}
}
return $result;
}
}
\ No newline at end of file
... ...
<?php
namespace Plugin\DataProcess\WebChannel\Channel;
class Boys extends AbstractChannel
{
/**
* 格式化数据
*
* @param array $resource
* @return
*/
public static function format($resource)
{
$result = self::getFormatNewArrivals($resource);
return $result;
}
}
\ No newline at end of file
... ...
<?php
namespace Plugin\DataProcess\WebChannel\Channel;
class Girls extends AbstractChannel
{
public static function format($resource)
{
$result = array();
$result += self::getFormatNewArrivals($resource);
foreach($resource as $key => $val)//老版是title模版
{
if(isset($resource[$key]) && isset($resource[$key + 2]))
{
$temp = array('newArrivls' => array('name' => '', 'navs' => array(), 'href' => ''));
if($resource[$key]['template_name'] == 'text' &&
$resource[$key + 1]['template_name'] == 'title' && //老版是title模版
$resource[$key + 2]['template_name'] == 'link'
)
{
//text模版
$temp['newArrivls']['name'] = $resource[$key]['data']['text'];
//title模版
foreach($resource[$key + 1]['data']['nav'] as $val)
{
$temp['newArrivls']['navs'][] = array('href' => $val['url'],'name' => $val['name']);
}
$link = $resource[$key + 2]['data'][0];
$temp['newArrivls']['href'] = $link['url'];
unset($resource[$key], $resource[$key + 1]);
$result[$key] = $temp;
}
}
}
return $result;
}
}
... ...
... ... @@ -3,17 +3,36 @@ namespace Plugin\DataProcess\WebChannel\Channel;
class Kids extends AbstractChannel
{
/**
* {@inheritDoc}
* @see \Plugin\DataProcess\WebChannel\Channel\AbstractChannel::format()
* 格式化数据
*
* @param array $resource
* @return
*/
public static function format($resource)
{
$data = array();
foreach($resource as $key => $val)
$result = array();
$result += self::getFormatNewArrivals($resource);
foreach($resource as $key => $val)//老版处理
{
if(isset($resource[$key]) && isset($resource[$key + 1]))
{
$temp = array('newArrivls' => array('name' => '', 'navs' => array()));
//newArrivals
if($resource[$key]['template_name'] == 'text' && $resource[$key + 1]['template_name'] == 'textNav')
{
//text模版
$temp['newArrivls']['name'] = $resource[$key]['data']['text'];
//textNav模版
foreach($resource[$key + 1]['data'] as $val)
{
$temp['newArrivls']['navs'][] = array('href' => $val['url'],'name' => $val['name']);
}
unset($resource[$key], $resource[$key + 1]);
$result[$key] = $temp;
}
}
}
return $data;
return $result;
}
... ...
<?php
namespace Plugin\DataProcess\WebChannel\Channel;
class Lifestyle extends AbstractChannel
{
/**
* 格式化数据
*
* @param array $resource
* @return
*/
public static function format($resource)
{
$result = array();
$result += self::getFormatNewArrivals($resource);
foreach($resource as $key => $val)//老版处理
{
if(isset($resource[$key]) && isset($resource[$key + 1]))
{
$temp = array('newArrivls' => array('name' => '', 'navs' => array()));
//newArrivals
if($resource[$key]['template_name'] == 'textNav' && $resource[$key + 1]['template_name'] == 'link')
{
//text模版
$temp['newArrivls']['name'] = '最新上架 NEW ARRIVALS';
//textNav模版
foreach($resource[$key]['data'] as $val)
{
$temp['newArrivls']['navs'][] = array('href' => $val['url'],'name' => $val['name']);
}
unset($resource[$key], $resource[$key + 1]);
$result[$key] = $temp;
}
}
}
return $result;
}
}
\ No newline at end of file
... ...
<?php
namespace Plugin\DataProcess\WebChannel;
use Plugin\Images;
use Plugin\Helpers;
/**
* web版通用处理器
*/
class Process
{
public static function getContent(array &$data, $type = 1)
{
//组合处理数据
$result = self::mergeProcess($data, $type);
foreach($data as $key => $val)
{
$fun = $val['template_name'];
if (empty($val['data']) || !is_callable("self::$fun")) {
continue;
}
//单个处理数据
$build = self::$fun($val, $type);
if(!empty($build))
{
$result[$key] = $build;
}
unset($data[$key]);
}
return $result;
}
/**
* 热门分类处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function hotCategory(array $data, $type)
{
$data = $data['data'];
$result = $temp = array();
$temp = array('name' => $data['name'],
'navs' => array(),'tplrecommend'=> array());
foreach($data['navs']['list'] as $val) {
$temp['navs'][] = array(
'id'=>'', 'href'=> $val['url'],
'name' => $val['name']
);
}
foreach($data['menuNav']['blocks'] as $val) {
$val['img'] = Images::getImageUrl($val['img'], 185, 76, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['tplrecommend']['keyword'][] = array('href'=> $val['url'],'name'=> $val['title'], 'img'=>$val['img']);
}
foreach($data['menuNav']['list'] as $val) {
if(empty($val['name']) && empty($val['url']))
{
continue;
}
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['tplrecommend']['category'][] = array('name'=> $val['name'],'url'=> $val['url']);
}
foreach($data['imgs'] as $key => $val) {
$w = 185; $h = 248;
if($key == 0)
{
$w = 377;
$h = 504;
}
$val['img'] = Images::getImageUrl($val['img'], $w, $h, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
if($key == 0)
{
$temp['tplrecommend']['brands'][] = array('href'=> $val['url'],'name'=> $val['title'],'img'=> $val['img']);
}
else
{
$temp['tplrecommend']['types'][] = array('href'=> $val['url'],'name'=> $val['title'],'img'=> $val['img']);
}
}
$result['recommend'] = $temp;
return $result;
}
/**
* banner处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function focus(array $data, $type)
{
$result = array();
$temp = array();
$width = 1150;
$height = 450;
if($data['focus_type'] == 1) {
foreach($data['data'] as $val) {
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp[] = array('href'=> $val['url'],'img' => $val['src']);
}
$result['slide']['list'] = $temp;
}
return $result;
}
/**
* 组合数据处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function mergeProcess(array &$data, $type)
{
$result = array();
foreach($data as $key => $val)
{
if(isset($data[$key]) && isset($data[$key+3])) //人气单品[template: text & textNav & goods & floor]
{
$temp = array('singlehot' => array('name'=>'','imgHot'=> array(),'brands'=> array()));
if($data[$key]['template_name'] == 'text' && $data[$key+1]['template_name'] == 'textNav'
&& $data[$key+2]['template_name'] == 'goods' && $data[$key+3]['template_name'] == 'floor')
{
//text模版
$temp['singlehot']['name']= $val['data']['text'];
//goods模版
foreach($data[$key+2]['data'] as $val)//TODO
{
$temp['singlehot']['imgHot'][] = array('href'=> '',//$val['url'],
'name' => '','price'=> '');
}
//floor模版
foreach($data[$key+3]['data'] as $val)
{
$val['src'] = Images::getImageUrl($val['src'], 185, 86, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['singlehot']['brands'][] = array('href' => $val['url'],
'img' => $val['src'],'name'=>$val['title']);
}
$result[$key] = $temp;
unset($data[$key], $data[$key+1], $data[$key+2], $data[$key+3]);
}
}
if(isset($data[$key]) && isset($data[$key+1])) //优选品牌 [ template: text & focus ]
{
$temp = array('preferenceBrands'=> array('name'=>'', 'slider'=> array()));
if($data[$key]['template_name'] =='text' && $data[$key+1]['template_name'] =='focus')
{
$temp['preferenceBrands']['name'] = $val['data']['text'];
//focus 分类
foreach($data[$key+1]['data'] as $val)
{
$width = 320;
$height = 430;
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['preferenceBrands']['slider'][] = array('href'=> $val['url'],'img'=> $val['src']);
}
$result[$key] = $temp;
unset($data[$key], $data[$key+1]);
}
}
if(isset($data[$key]) && isset($data[$key+2])) //girlkids[ template: text & textNav & goods]
{
$temp = array('girlkids'=> array('name'=>'', 'imgHot'=> array()));
if($data[$key]['template_name'] =='text' && $data[$key+2]['template_name'] =='goods')
{
$temp['girlkids']['name'] = $val['data']['text'];
foreach($data[$key+2]['data'] as $val)//TODO
{
$temp['girlkids']['imgHot'][] = array('href'=> '',//$val['url'],
'name' => '','price'=>'');
}
$result[$key] = $temp;
unset($data[$key], $data[$key+1], $data[$key+2]);
}
}
}
<?php
namespace Plugin\DataProcess\WebChannel;
use Plugin\Images;
use Plugin\Helpers;
use Plugin\Cache;
use Configs\CacheConfig;
use LibModels\Web\Product\SearchData;
/**
* web版通用处理器
*/
class Process
{
/**
*
* @param array $data
* @param string $type (boys, girls, kids, lifestyle)
*/
public static function getContent(array &$data, $type = '')
{
// 组合处理数据
$result = self::mergeProcess($data, $type);
foreach ($data as $key => $val) {
$fun = $val['template_name'];
if (empty($val['data']) || ! is_callable("self::$fun")) {
continue;
}
// 单个处理数据
$build = self::$fun($val, $type);
if (! empty($build)) {
$result[$key] = $build;
unset($data[$key]);
}
}
return $result;
}
/**
* 热门分类处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function hotCategory(array $data, $type)
{
$data = $data['data'];
$result = $temp = array();
$temp = array(
'name' => $data['name'],
'navs' => array(),
'tplrecommend' => array()
);
foreach ($data['navs']['list'] as $val) {
$temp['navs'][] = array(
'id' => '',
'href' => $val['url'],
'name' => $val['name']
);
}
foreach ($data['menuNav']['blocks'] as $val) {
$val['img'] = Images::getImageUrl($val['img'], 185, 76, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['tplrecommend']['keyword'][] = array(
'href' => $val['url'],
'name' => $val['title'],
'img' => $val['img']
);
}
foreach ($data['menuNav']['list'] as $val) {
if (empty($val['name']) && empty($val['url'])) {
continue;
}
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['tplrecommend']['category'][] = array(
'name' => $val['name'],
'url' => $val['url']
);
}
foreach ($data['imgs'] as $key => $val) {
$val['url'] = Helpers::transUrl($val['url'], $type);
if ($key == 0) {
$val['img'] = Images::getImageUrl($val['img'], 377, 504, 1); // 大图
$temp['tplrecommend']['brands'][] = array(
'href' => $val['url'],
'name' => $val['title'],
'img' => $val['img']
);
} else {
$val['img'] = Images::getImageUrl($val['img'], 185, 504, 1); // 小图
$temp['tplrecommend']['types'][] = array(
'href' => $val['url'],
'name' => $val['title'],
'img' => $val['img']
);
}
}
$result['recommend'] = $temp;
return $result;
}
/**
* banner处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function focus(array $data, $type)
{
$result = array();
$temp = array();
$width = 1150;
$height = 450;
if ($data['focus_type'] == 1) {
foreach ($data['data'] as $val) {
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp[] = array(
'href' => $val['url'],
'img' => $val['src']
);
}
$result['slide']['list'] = $temp;
}
return $result;
}
/**
* boys焦点图处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function recommend_content_three(array $data, $type)
{
$result = array();
$temp = array();
if ($data['template_name'] == 'recommend_content_three') {
foreach ($data['data']['big_image'] as $val) {
$width = 1150;
$height = 450;
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['list'][] = array(
'href' => $val['url'],
'img' => $val['src']
);
}
foreach ($data['data']['list'] as $val) {
$width = 138;
$height = 54;
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['pagination'][] = array(
'href' => $val['url'],
'img' => $val['src']
);
}
$result['slide'] = $temp;
}
return $result;
}
/**
* 广告位
*
* @param array $data
* @param string $type
* @return array
*/
public static function single_image(array $data, $type)
{
$result = array();
$temp = array();
if ($data['template_name'] == 'single_image') {
$temp = array(
'href' => '',
'img' => '',
'name' => ''
);
if (isset($data['data'][0])) {
$val = $data['data'][0];
$temp['img'] = Images::getImageUrl($val['src'], 1150, 129, 1);
$temp['href'] = $val['url'];
$temp['name'] = $val['title'];
$result['adbanner'] = $temp;
}
}
return $result;
}
/**
* 左右banner
*
* @param array $data
* @param string $type
*/
public static function debrisSlider(array $data, $type)
{
$data = $data['data'];
$result = array(
'debrisSlider' => array(
'left' => array(),
'center' => array(),
'right' => array()
)
);
foreach ($data['left'] as $val) {
$val['img'] = Images::getImageUrl($val['img'], 280, 265, 1);
$result['debrisSlider']['left'][] = array(
'img' => $val['img'],
'href' => $val['url'],
'name' => $val['title']
);
}
foreach ($data['center'] as $val) {
$val['img'] = Images::getImageUrl($val['img'], 570, 633, 1);
$result['debrisSlider']['center'][] = array(
'img' => $val['img'],
'href' => $val['url'],
'name' => $val['title']
);
}
foreach ($data['right'] as $val) {
$val['img'] = Images::getImageUrl($val['img'], 280, 449, 1);
$result['debrisSlider']['right'][] = array(
'img' => $val['img'],
'href' => $val['url'],
'name' => $val['title']
);
}
return $result;
}
/**
* 组合数据处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function mergeProcess(array &$data, $type)
{
$result = array();
$mergeProcessList = array(
'mergeSinglehotData',
'mergePreferenceBrandsData',
'mergeAccordionData',
'mergeCategoryData',
'mergeNewReportData',
'mergeSinglehotData2',
'mergeHotCategoryData',
'mergeGirlkidsData'
);
foreach ($data as $key => $val) {
foreach ($mergeProcessList as $merge) {
if (isset($data[$key])) {
$temp = self::$merge($key, $data, $type);
if (! empty($temp)) {
$result[$key] = $temp;
}
}
}
}
return $result;
}
/**
* 组合人气单品 [
* template: text & textNav & goods & floor ||
* textNav & goods & floor ||
* text & textNav & goods & app_icon_list
* ]
*
* @param string $key
* @param array $data
* @param string $type
* @return array
*/
public static function mergeSinglehotData($key, array &$data, $type)
{
$result = array();
if ((isset($data[$key]) && isset($data[$key + 2])) || (isset($data[$key]) && isset($data[$key + 3])))
{
$title = '';
$source = $goods = $floor = array();
if ($data[$key]['template_name'] == 'textNav' && $data[$key + 1]['template_name'] == 'goods'
&& $data[$key + 2]['template_name'] == 'floor')
{
$title = '人气单品 TOP100';
$source = $data[$key];
$goods = $data[$key + 1];
$floor = $data[$key + 2];
unset($data[$key], $data[$key + 1], $data[$key + 2]);
} else if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav'
&& $data[$key + 2]['template_name'] == 'goods' && $data[$key + 3]['template_name'] == 'floor')
{
$title = $data[$key]['data']['text'];
$source = $data[$key + 1];
$goods = $data[$key + 2];
$floor = $data[$key + 3];
unset($data[$key], $data[$key + 1], $data[$key + 2], $data[$key + 3]);
} else if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav'
&& $data[$key + 2]['template_name'] == 'goods' && $data[$key + 3]['template_name'] == 'app_icon_list')
{
$title = $data[$key]['data']['text'];
$source = $data[$key + 1];
$goods = $data[$key + 2];
$floor = $data[$key + 3];
unset($data[$key], $data[$key + 1], $data[$key + 2], $data[$key + 3]);
}
if (! empty($source) && ! empty($floor))
{
$result = array(
'singlehot' => array(
'name' => '',
'imgHot' => array(),
'brands' => array()
)
);
// text模版
$result['singlehot']['name'] = $title;
// goods模版
$result['singlehot']['imgHot'] = self::mergeGoodsProcess($goods, $type);
// floor模版
foreach ($floor['data'] as $val) {
$val['src'] = Images::getImageUrl($val['src'], 185, 86, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$result['singlehot']['brands'][] = array(
'href' => $val['url'],
'img' => $val['src'],
'name' => $val['title']
);
}
}
}
return $result;
}
/**
* 组合人气单品 [template: text & small_pic & floor ]
*
* @return array
*/
public static function mergeSinglehotData2($key, array &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 2])) {
if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'small_pic'
&& $data[$key + 2]['template_name'] == 'floor')
{
$result = array(
'singlehot' => array(
'name' => '',
'imgHot' => array()
)
);
// text
$result['singlehot']['name'] = $data[$key]['data']['text'];
$len = 10;
$list = array();
// small_pic
foreach ($data[$key + 1]['data'] as &$val) {
$w = 378;
$h = 248;
$val['src'] = Images::getImageUrl($val['src'], $w, $h, 1);
}
//floor
foreach ($data[$key + 2]['data'] as &$val)
{
$w = 185;
$h = 248;
$val['src'] = Images::getImageUrl($val['src'], $w, $h, 1);
}
for ($i = 0; $i < $len; $i ++)
{
$pos = $i;
if ($i == 1)
{
$val = $data[$key + 1]['data'][0]; // 第二个是大图
}
else if ($i == $len - 1)
{
$val = $data[$key + 1]['data'][1]; // 最后一个是大图
}
else
{
if ($pos > 1) // 小图
{
$pos = $pos - 1;
}
$val = $data[$key + 2]['data'][$pos];
}
$result['singlehot']['imgHot'][] = array(
'href' => $val['url'],
'img' => $val['src'],
'name' => $val['alt']
);
}
unset($data[$key], $data[$key + 1], $data[$key + 2]);
}
}
return $result;
}
/**
* 组合优选品牌数据 [ template: text & focus & floor]
*
* @param string $key
* @param array $data
* @param string $type
* @return array
*/
public static function mergePreferenceBrandsData($key, array &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 2])) {
if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'focus'
&& ($data[$key + 2]['template_name'] == 'floor' ||
$data[$key + 2]['template_name'] == 'app_icon_list'))
{
$result = array(
'preferenceBrands' => array(
'name' => '',
'imgBrand' => array(),
'brandUrl' => ''
)
);
// text模版
$result['preferenceBrands']['name'] = $data[$key]['data']['text'];
// focus模版
foreach ($data[$key + 1]['data'] as $val) {
if($type == 'boys') {
$width = 378; $height = 175;
} else{
$width = 320;$height = 430;
}
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$result['preferenceBrands']['imgBrand'][] = array(
'href' => $val['url'],
'img' => $val['src']
);
}
// floor模版
$floor = array(
'logoBrand' => '',
'moreBrand' => ''
);
foreach ($data[$key + 2]['data'] as $val) {
$width = 185;
$height = 86;
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 2);
$val['url'] = Helpers::transUrl($val['url'], $type);
$floor['logoBrand'][] = array(
'href' => $val['url'],
'img' => $val['src']
);
}
// textNav模版
if (isset($data[$key + 3]['data'][0]['url']) && $data[$key + 3]['template_name'] == 'textNav') {
$floor['moreBrand'] = $data[$key + 3]['data'][0]['url'];
unset($data[$key + 3]);
}
$type_key = sprintf("%s_%s", $type, $key + 2);
$cacheKey = sprintf("%s_%s", CacheConfig::KEY_INDEX_BRANDS_LIST_DATA, $type_key);
Cache::set($cacheKey, $floor, 7200);
$result['preferenceBrands']['brandUrl'] = '/common/getIndexResourceBrand?type=' . $type_key;
unset($data[$key], $data[$key + 1], $data[$key + 2]);
}
}
return $result;
}
/**
* 组合girlkids数据 [ template: text & textNav & goods]
*
* @param string $key
* @param array $data
* @param string $type
* @return array
*/
public static function mergeGirlkidsData($key, array &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 2]))
{
if ($data[$key]['template_name'] == 'text' && $data[$key + 2]['template_name'] == 'goods')
{
$result = array(
'girlkids' => array(
'name' => '',
'imgHot' => array()
)
);
// text
$result['girlkids']['name'] = $data[$key]['data']['text'];
// goods
$result['girlkids']['imgHot'] = self::mergeGoodsProcess($data[$key + 2], $type);
unset($data[$key], $data[$key + 1], $data[$key + 2]);
}
}
return $result;
}
/**
* 组合accordion数据 [ template: text & textNav & focus ]
*
* @param string $key
* @param array $data
* @param string $type
* @return array
*/
public static function mergeAccordionData($key, array &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 2]))
{
if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav'
&& $data[$key + 2]['template_name'] == 'focus')
{
$result = array(
'accordion' => array(
'name' => '',
'navs' => array(),
'slide' => array()
)
);
$result['accordion']['name'] = $data[$key]['data']['text'];
// textNav模版
if (! empty($data[$key + 1]['data'])) {
$result['accordion']['navs'] = self::mergeNavProcess($data[$key + 1], $type);
}
// focus模版
foreach ($data[$key + 2]['data'] as $val) {
$val['src'] = Images::getImageUrl($val['src'], 650, 400, 1);
$result['accordion']['slide'][] = array(
'href' => $val['url'],
'img' => $val['src'],
'name' => $val['title']
);
}
unset($data[$key], $data[$key + 1], $data[$key + 2]);
}
}
return $result;
}
/**
* 组合boys最新速报数据 [ template: text & single_image & floor & single_image]
*
* @param string $key
* @param array $data
* @param string $type
* @return array
*/
public static function mergeNewReportData($key, array &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 3]))
{
if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'single_image'
&& $data[$key + 2]['template_name'] == 'floor' &&
$data[$key + 3]['template_name'] == 'single_image')
{
$result = array(
'newReport' => array(
'name' => '',
'list' => array()
)
);
// text
$result['newReport']['name'] = $data[$key]['data']['text'];
// single_image & floor & single_image
$list = array_merge($data[$key + 1]['data'], array_slice($data[$key + 2]['data'], 0, 6), $data[$key + 3]['data']);
foreach ($list as $listKey => $val) {
$width = 185;
$height = 248;
$w = 377;
$h = 504;
if ($listKey == 0 || $listKey == 7) {
$val['src'] = Images::getImageUrl($val['src'], $w, $h, 1);
$result['newReport']['list'][] = array(
'href' => $val['url'],
'img' => $val['src']
);
} else {
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
$result['newReport']['list'][] = array(
'href' => $val['url'],
'img' => $val['src']
);
}
}
unset($data[$key], $data[$key + 1], $data[$key + 2], $data[$key + 3]);
}
}
return $result;
}
/**
* 组合category数据 [template: text & textNav & floor ]
*
* @param array $data
* @param string $type
* @return array
*/
public static function mergeCategoryData($key, array &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 2])) {
if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav'
&& $data[$key + 2]['template_name'] == 'floor') {
$result = array(
'category' => array(
'name' => '',
'navs' => array(),
'list' => array()
)
);
// text模版
$result['category']['name'] = $data[$key]['data']['text'];
// textNav模版
if (! empty($data[$key + 1]['data'])) {
$result['category']['navs'] = self::mergeNavProcess($data[$key + 1], $type);
}
// floor模版
foreach ($data[$key + 2]['data'] as $val) {
$val['src'] = Images::getImageUrl($val['src'], 185, 510, 2);
$val['url'] = Helpers::transUrl($val['url'], $type);
$result['category']['list'][] = array(
'href' => $val['url'],
'img' => $val['src'],
'name' => $val['title']
);
}
unset($data[$key], $data[$key + 1], $data[$key + 2]);
}
}
return $result;
}
/**
* 组合HotCategory数据 [template: hotCategory & floor] 首页使用
*
* @param string $key
* @param array $data
* @param string $type
* @return array
*/
public static function mergeHotCategoryData($key, &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 1]))
{
if ($data[$key]['template_name'] == 'hotCategory' && $data[$key + 1]['template_name'] == 'floor')
{
$result = array(
'name' => '',
'navs' => array(),
'tplrecommend' => array(
'keyword' => array(),
'category' => array(),
'brands' => array(),
'types' => array(),
'products' => array()
)
);
// hotCategory模版
$temp = self::hotCategory($data[$key], $type);
$temp = $temp['recommend'];
$result['name'] = $temp['name'];
$result['navs'] = $temp['navs'];
$result['tplrecommend']['keyword'] = $temp['tplrecommend']['keyword'];
$result['tplrecommend']['category'] = $temp['tplrecommend']['category'];
foreach ($data[$key]['data']['imgs'] as $key2 => $val)
{
$val['url'] = Helpers::transUrl($val['url'], $type);
if ($key2 == 0 || $key2 == 4) // 两个大图
{
$val['img'] = Images::getImageUrl($val['img'], 378, 248, 1); // 大图
$result['tplrecommend']['brands'][] = array(
'href' => $val['url'],
'name' => $val['title'],
'img' => $val['img']
);
} else {
$val['img'] = Images::getImageUrl($val['img'], 185, 248, 1); // 小图
$result['tplrecommend']['types'][] = array(
'href' => $val['url'],
'name' => $val['title'],
'img' => $val['img']
);
}
}
// floor模版
foreach ($data[$key + 1]['data'] as $val)
{
$val['src'] = Images::getImageUrl($val['src'], 222, 298, 1); // 小图
$result['tplrecommend']['products'][] = array(
'href' => $val['url'],
'name' => $val['title'],
'img' => $val['src']
);
}
unset($data[$key], $data[$key + 1]);
$result = array(
'recommend' => $result
);
}
}
return $result;
}
/**
* 组合之nav处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function mergeNavProcess(array $data, $type)
{
$result = array();
foreach ($data['data'] as $val) {
if (empty($val))
continue;
$result[] = array(
'href' => $val['url'],
'name' => $val['name']
);
}
return $result;
}
/**
* 组合之商品处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function mergeGoodsProcess(array $data, $type)
{
$result = array();
$skns = '';
foreach ($data['data'] as $val) {
$skns .= $val['id'] . ' ';
}
$params = array(
'query' => rtrim($skns),
'client_type' => 'web'
);
$goodsList = SearchData::searchElasticByCondition($params, false);
$goodsList = $goodsList['data']['product_list'];
$pos = 0;
foreach ($goodsList as $goods)
{
$oneGoods = array();
$pos ++;
if ($pos > 12) {
break;
}
if (empty($goods)) {
continue;
}
$oneGoods['img'] = Images::getImageUrl($goods['goods_list'][0]['images_url'], 280, 373, 1);
$oneGoods['name'] = $goods['product_name'];
$oneGoods['price'] = $goods['sales_price'];
/*
* if($pos < 4) {
* $oneGoods['tip'] = 'TOP'.$pos;
* }
*/
$url = 'http://item.yohobuy.com/`/product/pro_' .
$goods['product_id'] . '_' . $goods['goods_list'][0]['goods_id']
. '/' . $goods['cn_alphabet'] . '.html';
$oneGoods['href'] = Helpers::transUrl($url, $type);
$result[$goods['product_skn']] = $oneGoods;
}
// 排序
uksort($result, function ($a, $b) use($skns) {
$skn_arr = explode(' ', $skns);
return array_search($a, $skn_arr) > array_search($b, $skn_arr);
});
return $result;
}
... ...
<?php
namespace Plugin;
use Plugin\Images;
/**
* 搜索辅助类
*/
class HelperSearch
{
/**
* 请求时用的所有参数
*/
private static $params = array();
//当前页面
private static $current_url = '';
private static $page = 1;
/**
* 选中的条件
*/
public static $selected = array();
/**
* list分类面包屑
* @var array
*/
public static $listnav = array(
array(
'href' => '',
'name' => '首页'
),
array(
'href' => '',
'name' => '列表'
)
);
/**
* 组织搜索模板数据
* @param array $data
* @param array $options
* @return array
*/
public static function getList($data = array() , $options = array()) {
if (empty($data)) {
return array();
}
self::$params = $_GET;
unset(self::$params['/']);
unset(self::$params['page']);
unset(self::$params['/sale']);
unset(self::$params['sale']);
$result = array();
if (!isset($data['data']) || !isset($data['data']['product_list']) || !is_array($data['data']['product_list'])) {
return array();
}
$result['product_list'] = self::getProductList($data['data']['product_list'], $options['imgSize'], $options['minImgSize'], $options['gender']);
$result['page_total'] = $data['data']['page_total'];
$result['total'] = $data['data']['total'];
$result['page'] = $data['data']['page'];
//设置当前页
self::$page = $result['page'];
//搜索条件
if (isset($data['data']['filter']) && !empty($data['data']['filter'])) {
$filter = $data['data']['filter'];
$result['filter']['left_sort'] = isset($filter['minsort']) ? self::minsort($filter['minsort']) : array();
$result['filter']['group_sort'] = isset($filter['group_sort']) ? self::groupSort($filter['group_sort'], $options) : array();
$result['filter']['size'] = self::size($filter);
$result['filter']['color'] = self::color($filter);
$result['filter']['price'] = self::price($filter);
$result['filter']['brand'] = self::brand($filter);
$result['filter']['parameters'] = self::standard($filter);
$result['filter']['rowNum4'] = self::rowNum();
$result['filter']['rowNum6'] = self::rowNum(6);
$result['filter']['viewNum'] = self::viewNum();
$result['filter']['priceSubmit'] = self::priceSubmit();
$result['filter']['gender'] = self::gender($filter);
$result['filter']['selected'] = self::getSelected();
$result['filter']['checks'] = array(self::isnew(),self::specialoffer(),self::limited());
$result['filter']['sortType'] = array( self::orderDefault(),self::orderTime(),self::orderPrice(),self::orderDiscount());
$result['filter']['clear'] =self::current();
$result['filter']['next'] = self::next($data['data']['page_total'],$data['data']['filter']);
$result['filter']['listnav'] = self::$listnav;
$result['filter']['discount'] = self::getDiscount($filter['discount']);
$result['filter']['recent'] = self::recentShelve($filter['recent']);
$result['filter']['seniorChose'] = self::seniorChose($filter);
}
return $result;
}
/**
* 组织列表模板数据
*
*/
public static function getTemplateData($result, $options){
//模板数据
$data = array(
'brandBanner' => array(),
'pathNav' => $result['filter']['listnav'],
'shopEntry' => array(),
'filters' => array(
'checkedConditions' => array(
'conditions' => $result['filter']['selected'],
'clearUrl' => $result['filter']['clear']
),
'channel' => $result['filter']['gender'],
'sort' => array() ,
'brand' => $result['filter']['brand'],
'price' => $result['filter']['price'],
'color' => $result['filter']['color'],
'size' => $result['filter']['size'],
'seniorChose' => $result['filter']['seniorChose']
),
'opts' => array(
'sortType' => $result['filter']['sortType'],
'checks' => $result['filter']['checks'],
'fivePerLine' => true,
'sixPerLineHref' => '',
'countPerPage' => $options['viewNum'],
'pageCounts' => $result['filter']['viewNum'],
'curPage' => $result['page'],
'pageCount' => $result['page_total'],
'nextHref' => $result['filter']['next']
),
'goods' => $result['product_list'],
'allSort' => array(
'updateNum' => $result['filter']['group_sort']['all']['num'],
'list' => $result['filter']['group_sort']['list']
),
'advNav' => array(),
'advPic' => array(),
'newSales' => $result['filter']['recent'],
'allDiscount' => $result['filter']['discount']
);
return $data;
}
/**
* TODO 组织商品列表信息
* @param $product 接口返回商品列表
* @author sefon 2015-12-21 17:24:04
* @return array
*/
public static function getProductList($product,$imgSize){
$result = array();
foreach($product as $key => $val){
$isNew = $val['is_new'] == 'Y' ? true : false;
$isFew = $val['is_soon_sold_out'] == 'Y' ? true : false;
$is_promotion = $val['is_promotion'];
foreach($val['goods_list'] as $k => $v){
$goods_list[$k]['url'] = Helpers::getUrlBySkc($val['product_id'], $v['goods_id'], $val['cn_alphabet']);
}
if (!empty($val['default_images'])) {
$val['default_images'] = Images::getImageUrl($val['default_images'],$imgSize[0],$imgSize[1]);
}
$result[] = array(
'tags' => array(
'isNew' => $isNew,
'isYearEndPromotion' => $is_promotion
),
'url' => $goods_list[0]['url'],
'thumb' => $val['default_images'],
'name' => $val['product_name'],
'salePrice' => $val['sales_price'],
'isFew' => $isFew
);
}
return $result;
}
/**
* 版型等其它筛选项
* @param $filter
* @return array
*/
public static function standard($filter) {
$params = self::$params;
$result = array();
if (empty(self::$params)) {
return $result;
}
if (empty($filter) || !is_array($filter)) {
return array();
}
foreach ($filter as $key => $val) {
if (substr_compare($key, 'parameter', 0, 9) != 0) {
continue;
}
if (!isset($val['sub']) || empty($val['sub'])) {
continue;
}
$sub = array();
foreach ($val['sub'] as $pval) {
if (isset(self::$params['parameter_' . $val['standard_id']]) && self::$params['parameter_' . $val['standard_id']] == $pval['standard_id']) {
$tmpParams = self::$params;
unset($tmpParams['parameter_' . $val['standard_id']]);
self::$selected['parameter_' . $val['standard_id']] = array(
'name' => $pval['standard_name'],
'href' => self::buildurl($tmpParams)
);
}
$sub[] = array(
'name' => $pval['standard_name'],
'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
);
}
if (!empty($sub) && count($sub) > 1) {
$result[] = array(
'name' => $val['standard_name'],
'sub' => $sub
);
}
}
return $result;
}
/**
* 性别
* @return array
*/
public static function gender($filter) {
if (empty($filter) || !isset($filter['gender']) || empty($filter['gender'])) {
return array();
}
$params = self::$params;
$gender = isset($params['gender']) ? $params['gender'] : '';
if (isset($params['gender'])) {
unset($params['gender']);
}
if ($gender == '1,3' || $gender == '2,3') {
self::$selected['gender'] = array(
'name' => $gender == '1,3' ? 'BOYS' : 'GIRLS',
'href' => self::buildurl($params)
);
}
$result = array();
foreach ($filter['gender'] as $key => $val) {
$result[] = array(
'name' => $val,
'href' => self::buildurl(array_merge($params, array(
'gender' => $key
))) ,
'selected' => $gender == $key ? true : false
);
}
return $result;
}
/**
* 组织搜索列表页面的左侧分类
* @param array $sort
* @param array $params
* @return array
*/
/**
* 组织搜索列表页面的左侧分类
* @param array $sort
* @param array $params
* @return array
*/
public static function groupSort($sort, $option = array()) {
$params = self::$params;
$gender = isset($params['gender']) ? $params['gender'] : '';
$query = array();
if (isset($option['needKeyword']) && $option['needKeyword'] == 'Y') {
if (isset($params['query']) && !empty($params['query'])) {
$query['query'] = $params['query'];
}
if (isset($params['keyword']) && !empty($params['keyword'])) {
$query['keyword'] = $params['keyword'];
}
}
if (isset($params['gender']) && !empty($params['gender'])) {
$query['gender'] = $params['gender'];
}
if (isset($option['needDay']) && !empty($option['needDay']) && isset($params['day']) && !empty($params['day'])) {
$query['day'] = $params['day'];
}
if (isset($option['needPd']) && !empty($option['needPd']) && isset($params['p_d']) && !empty($params['p_d'])) {
$query['p_d'] = $params['p_d'];
}
if (isset($option['specialsale_id']) && !empty($option['specialsale_id']) && isset($params['specialsale_id']) && !empty($params['specialsale_id'])) {
$query['specialsale_id'] = $params['specialsale_id'];
}
$result = array(
'all' => array(
'sort_id' => 0,
'name' => '全部品类',
'href' => self::buildurl($query) ,
'num' => 0,
'selected' => ''
) ,
'list' => array()
);
foreach ($sort as $val) {
if (isset($params['msort']) && $params['msort'] == $val['sort_id']) {
self::$listnav[1] = array(
'sort_id' => $val['sort_id'],
'name' => $val['sort_name'],
'href' => self::buildurl(array(
'msort' => $val['sort_id'],
'gender' => $gender
))
);
}
$result['all']['num']+= $val['count'];
$msort = array(
'sort_id' => $val['sort_id'],
'name' => $val['sort_name'],
'num' => $val['count'],
'selected' => isset($params['msort']) && $params['msort'] == $val['sort_id'] ? true : false,
'href' => self::buildurl(array_merge($query, array(
'msort' => $val['sort_id']
))) ,
'childList' => array()
);
$sub = array();
if (!empty($val['sub'])) {
$sub[] = array(
'sort_id' => $val['sort_id'],
'name' => '全部' . $val['sort_name'],
'num' => $val['count'],
'selected' => !isset($params['misort']) && isset($params['msort']) && $params['msort'] == $val['sort_id'] ? true : false,
'href' => self::buildurl(array_merge($query, array(
'msort' => $val['sort_id']
))) ,
);
foreach ($val['sub'] as $mval) {
if (isset($params['misort']) && $params['misort'] == $mval['sort_id']) {
self::$listnav[2] = array(
'sort_id' => $mval['sort_id'],
'name' => $mval['sort_name'],
'href' => ''
);
}
$sub[] = array(
'sort_id' => $mval['sort_id'],
'name' => $mval['sort_name'],
'num' => $mval['count'],
'selected' => isset($params['misort']) && $params['misort'] == $mval['sort_id'] ? true : false,
'href' => self::buildurl(array_merge($query, array(
'msort' => $val['sort_id'],
'misort' => $mval['sort_id']
))) ,
);
}
$msort['childList'] = $sub;
}
$result['list'][] = $msort;
}
return $result;
}
/**
* 品牌,可以多选
* @param array $brand
* @return array
*/
public static function brand($filter) {
$params = self::$params;
$brand_ids = isset($params['brand']) && !empty($params['brand']) ? explode(',', $params['brand']) : array();
if (isset($params['brand'])) {
unset($params['brand']);
}
$result = array(
'default' => array() ,
'brandIndex' => array(
'0~9',
'A~G',
'H~N',
'O~T',
'U~Z') ,
'brandsShow' => array() ,
'list' => array(
'0~9' => array() ,
'A~G' => array() ,
'H~N' => array() ,
'O~T' => array() ,
'U~Z' => array() ,
)
);
$brand_keys = array_reverse(array_keys($result['list']));
if (isset($filter['brand']) && !empty($filter['brand'])) {
//有商品结果时
$brand = $filter['brand'];
foreach ($brand as $v) {
if (!isset($v['brand_alif']) && isset($v['brand_name_en'])) {
$v['brand_alif'] = substr($v['brand_name_en'], 0, 1);
}
else if (!isset($v['brand_alif'])) {
$v['brand_alif'] = '';
}
if (!isset($v['brand_domain'])) {
$v['brand_domain'] = '';
}
//选中的筛选条件
if (in_array($v['id'], $brand_ids)) {
$selected_brand = explode(',', self::$params['brand']);
$selected_key = array_search($v['id'], $selected_brand);
unset($selected_brand[$selected_key]);
$selected_params = $params;
$selected_params['brand'] = implode(',', $selected_brand);
self::$selected['brand'][] = array(
'name' => $v['brand_name'],
'href' => self::buildurl($selected_params)
);
}
$selected_brand = isset(self::$params['brand']) && !empty(self::$params['brand']) ? explode(',', self::$params['brand']) : array();
if (empty($selected_brand)) {
$url = self::buildurl(array_merge($params, array(
'brand' => $v['id']
)));
}
else if (in_array($v['id'], $brand_ids)) {
$tk = array_search($v['id'], $selected_brand);
unset($selected_brand[$tk]);
$url = self::buildurl(array_merge($params, array(
'brand' => implode(',', $selected_brand)
)));
}
else {
$selected_brand[] = $v['id'];
$url = self::buildurl(array_merge($params, array(
'brand' => implode(',', $selected_brand)
)));
}
$this_brand = array(
'brand_id' => $v['id'],
'name' => $v['brand_name'],
'alif' => $v['brand_alif'],
'href' => $url,
'selected' => in_array($v['id'], $brand_ids) ? true : false
);
if (count($result['default']) < 10) {
$result['default'][] = $this_brand;
}
$result['brandsShow'][] = $this_brand;
foreach ($brand_keys as $range) {
if (ord($v['brand_alif']) >= ord($range)) {
$_order_key = $v['brand_alif'] . $v['brand_name'];
$result['list'][$range][$_order_key] = $this_brand;
break;
}
}
}
foreach ($result['list'] as $key => $value) {
ksort($result['list'][$key]);
$result['list'][$key] = array_values($result['list'][$key]);
if (empty($value)) {
unset($result['list'][$key]);
}
}
}
else if (isset($filter['paramNames']) && isset($filter['paramNames']['brand'])) {
//无商品结果时且选择了品牌
$brand = $filter['paramNames']['brand'];
foreach ($brand as $v) {
//选中的筛选条件
if (in_array($v['id'], $brand_ids)) {
$selected_brand = explode(',', self::$params['brand']);
$selected_key = array_search($v['id'], $selected_brand);
unset($selected_brand[$selected_key]);
$selected_params = $params;
$selected_params['brand'] = implode(',', $selected_brand);
self::$selected['brand'][] = array(
'name' => $v['name'],
'href' => self::buildurl($selected_params)
);
}
}
$result['list'] = array();
}
else {
$result['list'] = array();
}
return $result;
}
/**
* 尺码的链接,不能多选
* @param array $size
* @return array
*/
public static function size($filter) {
$params = self::$params;
$size_id = isset($params['size']) && !empty($params['size']) ? $params['size'] : '';
if (isset($params['size'])) {
unset($params['size']);
}
$result = array();
if (isset($filter['size']) && !empty($filter['size'])) {
$size = $filter['size'];
foreach ($size as $v) {
if ($v['size_id'] == $size_id) {
self::$selected['size'] = array(
'name' => $v['size_name'],
'href' => self::buildurl($params)
);
}
$result[] = array(
'size_id' => $v['size_id'],
'name' => $v['size_name'],
'href' => self::buildurl(array_merge($params, array(
'size' => $v['size_id']
))) ,
'selected' => $size_id == $v['size_id'] ? true : false
);
}
}
else if (isset($filter['paramNames']) && isset($filter['paramNames']['size'])) {
$size = $filter['paramNames']['size'];
foreach ($size as $val) {
self::$selected['size'] = array(
'name' => $val['name'],
'href' => self::buildurl($params)
);
}
}
return $result;
}
/**
* 颜色,不能多选
* @param array $color
* @return array
*/
public static function color($filter) {
$params = self::$params;
$color_id = isset($params['color']) && !empty(self::$params['color']) ? self::$params['color'] : '';
if (isset($params['color'])) {
unset($params['color']);
}
$result = array();
if (isset($filter['color']) && !empty($filter['color'])) {
//有商品结果时的颜色
$color = $filter['color'];
foreach ($color as $v) {
if ($v['color_id'] == $color_id) {
$background = empty($v['color_value']) ? '#' . $v['color_code'] : "url(" . $v['color_value'] . ")";
self::$selected['color'] = array(
'color' => $background,
'href' => self::buildurl($params)
);
}
$result[] = array(
'color_id' => $v['color_id'],
'name' => $v['color_name'],
'rgb' => empty($v['color_value']) ? '#' . $v['color_code'] : "url({$v['color_value']})",
'href' => self::buildurl(array_merge($params, array(
'color' => $v['color_id']
))) ,
'selected' => $color_id == $v['color_id'] ? true : false
);
}
}
else if (isset($filter['paramNames']) && isset($filter['paramNames']['color'])) {
//无商品结果时的颜色
$color = $filter['paramNames']['color'];
foreach ($color as $v) {
if ($v['id'] == $color_id) {
$background = empty($v['value']) ? '#' . $v['code'] : "url(" . $v['value'] . ")";
self::$selected['color'] = array(
'name' => '<em style="background:' . $background . ';">&nbsp;</em>',
'href' => self::buildurl($params)
);
}
}
}
return $result;
}
/**
* 获取价格,不能多选
* @param array $price
* @return array
*/
public static function price($filter) {
$params = self::$params;
$price_id = isset($params['price']) && !empty(self::$params['price']) ? self::$params['price'] : '';
if (isset($params['price'])) {
unset($params['price']);
}
$result = array();
if (isset($filter['price']) && !empty($filter['price'])) {
//有商品时
if (!empty($price_id) && isset($filter['price'][$price_id])) {
self::$selected['price'] = array(
'name' => $filter['price'][$price_id],
'href' => self::buildurl($params)
);
}
else if (!empty($price_id)) {
$_price = explode(',', $price_id);
if (count($_price) == 2) {
self::$selected['price'] = array(
'name' => self::$params['price'] == '2000,99999' ? '¥2000以上' : '¥' . (int)$_price[0] . '-' . (int)$_price[1],
'href' => self::buildurl($params)
);
}
}
foreach ($filter['price'] as $key => $val) {
$val = trim($val,'¥');
$result[] = array(
'name' => $val,
'href' => self::buildurl(array_merge($params, array(
'price' => $key
))) ,
'selected' => isset(self::$params['price']) && $key == self::$params['price'] ? true : false
);
}
}
else if (!empty($price_id)) {
//无商品结果时
$_price = explode(',', $price_id);
if (count($_price) == 2) {
self::$selected['price'] = array(
'name' => self::$params['price'] == '2000,99999' ? '¥2000以上' : '¥' . (int)$_price[0] . '-' . (int)$_price[1],
'href' => self::buildurl($params)
);
}
}
return $result;
}
/**
* 风格,可以多选
* @param array $style
* @return array
*/
public static function style($filter) {
$params = self::$params;
$style_ids = isset($params['style']) && !empty($params['style']) ? explode(',', $params['style']) : array();
if (isset($params['style'])) {
unset($params['style']);
}
$result = array();
if (isset($filter['style']) && !empty($filter['style'])) {
//有商品结果时
$style = $filter['style'];
foreach ($style as $v) {
//选中的筛选条件
if (in_array($v['style_id'], $style_ids)) {
$selected_style = explode(',', self::$params['style']);
$selected_key = array_search($v['style_id'], $selected_style);
unset($selected_style[$selected_key]);
$selected_params = $params;
$selected_params['style'] = implode(',', $selected_style);
self::$selected['style'][] = array(
'name' => $v['style_name'],
'href' => self::buildurl($selected_params)
);
}
$selected_style = isset(self::$params['style']) && !empty(self::$params['style']) ? explode(',', self::$params['style']) : array();
if (empty($selected_style)) {
$url = self::buildurl(array_merge($params, array(
'style' => $v['style_id']
)));
}
else if (in_array($v['style_id'], $selected_style)) {
$tk = array_search($v['style_id'], $selected_style);
unset($selected_style[$tk]);
$url = self::buildurl(array_merge($params, array(
'style' => implode(',', $selected_style)
)));
}
else {
$selected_style[] = $v['style_id'];
$url = self::buildurl($params + array(
'style' => implode(',', $selected_style)
));
}
$result[] = array(
'style_id' => $v['style_id'],
'name' => $v['style_name'],
'href' => $url,
'selected' => in_array($v['style_id'], $style_ids) ? true : false
);
}
}
else if (isset($filter['paramNames']) && isset($filter['paramNames']['style'])) {
//无商品结果时
$style = $filter['paramNames']['style'];
foreach ($style as $v) {
//选中的筛选条件
if (in_array($v['id'], $style_ids)) {
$selected_style = explode(',', self::$params['style']);
$selected_key = array_search($v['id'], $selected_style);
unset($selected_style[$selected_key]);
$selected_params = $params;
$selected_params['style'] = implode(',', $selected_style);
self::$selected['style'][] = array(
'name' => $v['name'],
'href' => self::buildurl($selected_params)
);
}
}
}
$data[0] = array(
'attr' => 'style',
'name' => '风格',
'showMulti' => true,
'sub' => $result
);
return $data;
}
/**
* 高级选项
*/
public static function seniorChose($filter){
$style = self::style($filter);
$other = self::standard($filter);
$result = array_merge($style,$other);
return $result;
}
/**
* 每页显示数量
*/
public static function viewNum() {
$params = self::$params;
$view_num = array(
60,
100,
200
);
$result = array();
foreach ($view_num as $value) {
$params['viewNum'] = $value;
$params['page'] = 1;
$result[] = array(
'count' => $value,
'href' => self::buildurl($params)
);
}
return $result;
}
/**
* 显示行数
*/
public static function rowNum($num = 5) {
$params = self::$params;
$params['rowNum'] = $num;
return self::buildurl($params);
}
/**
* 是否特价
*/
public static function specialoffer() {
$params = self::$params;
if (isset($params['specialoffer']) && !empty($params['specialoffer'])) {
unset($params['specialoffer']);
$selected = true;
}
else {
$params['specialoffer'] = 1;
$selected = '';
}
return array(
'name' => '打折',
'href' => self::buildurl($params) ,
'checked' => $selected
);
}
/**
* 是否限量
*/
public static function limited() {
$params = self::$params;
if (isset($params['limited']) && !empty($params['limited'])) {
unset($params['limited']);
$selected = true;
}
else {
$params['limited'] = 'Y';
$selected = '';
}
return array(
'name' => '限量',
'href' => self::buildurl($params) ,
'checked' => $selected
);
}
/**
* 是否新品
*/
public static function isnew() {
$params = self::$params;
if (isset($params['isNew']) && !empty($params['isNew'])) {
unset($params['isNew']);
$selected = true;
}
else {
$params['isNew'] = 'Y';
$selected = false;
}
return array(
'name' => '新品',
'href' => self::buildurl($params) ,
'checked' => $selected
);
}
/**
* 排序是否最新
*/
public static function orderTime() {
$params = self::$params;
if (isset($params['order'])) {
unset($params['order']);
}
$result = array(
'name' => '最新',
'href' => isset(self::$params['order']) && self::$params['order'] == 's_t_desc' ? self::buildurl($params) : self::buildurl(array_merge($params, array(
'order' => 's_t_desc'
))) ,
'selected' => isset(self::$params['order']) && self::$params['order'] == 's_t_desc' ? true : ''
);
return $result;
}
/**
* 排序是否默认
*/
public static function orderDefault() {
$params = self::$params;
if (isset($params['order'])) {
unset($params['order']);
}
$result = array(
'name' => '默认',
'href' => self::buildurl($params) ,
'selected' => !isset(self::$params['order']) || empty(self::$params['order']) ? true : ''
);
return $result;
}
/**
* 价格排序
*/
public static function orderPrice() {
$params = self::$params;
if (isset($params['order'])) {
unset($params['order']);
}
if (!isset(self::$params['order']) || empty(self::$params['order']) || !in_array(self::$params['order'], array(
's_p_asc',
's_p_desc'
))) {
$url = self::buildurl(array_merge($params, array(
'order' => 's_p_asc'
)));
$asc = '';
$desc = '';
}
else if (self::$params['order'] == 's_p_asc') {
$url = self::buildurl(array_merge($params, array(
'order' => 's_p_desc'
)));
$asc = true;
$desc = '';
}
else {
$url = self::buildurl(array_merge($params, array(
'order' => 's_p_asc'
)));
$asc = '';
$desc = true;
}
$result = array(
'name' => '价格',
'href' => $url,
'asc' => $asc,
'desc' => $desc
);
return $result;
}
/**
* 折扣排序
*/
public static function orderDiscount() {
$params = self::$params;
if (isset($params['order'])) {
unset($params['order']);
}
if (!isset(self::$params['order']) || empty(self::$params['order']) || !in_array(self::$params['order'], array(
'p_d_asc',
'p_d_desc'
))) {
$url = self::buildurl(array_merge($params, array(
'order' => 'p_d_asc'
)));
$asc = '';
$desc = '';
}
else if (self::$params['order'] == 'p_d_asc') {
$url = self::buildurl(array_merge($params, array(
'order' => 'p_d_desc'
)));
$asc = true;
$desc = '';
}
else {
$url = self::buildurl(array_merge($params, array(
'order' => 'p_d_asc'
)));
$asc = '';
$desc = true;
}
$result = array(
'name' => '折扣',
'href' => $url,
'asc' => $asc,
'desc' => $desc
);
return $result;
}
/**
* 获取自定义价格要提交的地址
*/
public static function priceSubmit() {
$params = self::$params;
$price = array();
if (isset($params['price'])) {
$price = explode(',', $params['price']);
unset($params['price']);
}
$result = array();
foreach ($params as $key => $value) {
$result[] = '<input type="hidden" name="' . $key . '" value="' . $value . '">';
}
if (count($price) == 2 && !in_array(self::$params['price'], array(
'0,300',
'300,600',
'600,1000',
'1000,2000',
'2000,99999'
))) {
return array(
'start' => $price[0],
'end' => $price[1],
'selected' => true,
'form' => implode('', $result)
);
}
else {
return array(
'start' => '',
'end' => '',
'selected' => false,
'form' => implode('', $result)
);
}
}
/**
* 组织参数
* @param array $params
* @return string
*/
private static function buildurl($params) {
if (empty($params)) {
return self::current();
}
$queryPath = explode('?', $_SERVER['REQUEST_URI']);
$params_arr = array();
foreach ($params as $key => $val) {
if (is_array($val) || $val === '') {
continue;
}
$params_arr[] = $key . '=' . $val;
}
if (empty($params_arr)) {
return self::current();
}
else {
return (empty($queryPath[0]) ? '/' : $queryPath[0]) . '?' . implode('&', $params_arr);
}
}
/**
* 获取选中的条件
*/
public static function getSelected() {
$result = array();
$is_array_key = array(
'brand',
'style'
);
foreach (self::$selected as $key => $val) {
if (in_array($key, $is_array_key)) {
foreach ($val as $k => $v) {
$result[] = $v;
}
}
else {
$result[] = $val;
}
}
return $result;
}
/**
* 打折区间
* @param array $list
* @return array
*/
public static function getDiscount(array $list = array()) {
if (empty($list)) {
return array();
}
$params = $_GET;
$query = array();
if (isset($params['gender'])) {
$query['gender'] = $params['gender'];
}
if (isset($params['msort'])) {
$query['msort'] = $params['msort'];
}
if (isset($params['misort'])) {
$query['misort'] = $params['misort'];
}
$total = 0;
foreach ($list as $k => $v) {
$total+= $v['count'];
$query['p_d'] = $k;
$list[$k]['href'] = self::buildurl($query);
$list[$k]['num'] = $total;
$list[$k]['selected'] = isset($params['p_d']) && $params['p_d'] == $k ? true : false;
}
$result = array(
'updateNum' => $total,
'list' => $list
);
return $result;
}
/**
* 最新上架
*/
public static function recentShelve($list = array()){
if (empty($list)) {
return array();
}
$params = $_GET;
$query = array();
if (isset($params['gender'])) {
$query['gender'] = $params['gender'];
}
if (isset($params['msort'])) {
$query['msort'] = $params['msort'];
}
if (isset($params['misort'])) {
$query['misort'] = $params['misort'];
}
$data = array();
$total = 0;
$i = 0;
foreach ($list as $k => $v) {
$total+= $v;
$star_time = strtotime($k);
$end_time = $star_time+60*60*24;
$query['shelve_time'] = '';
$query['shelve_time'] = $star_time.','.$end_time;
@$data[$i]['href'] = self::buildurl($query);
$data[$i]['num'] = $v;
$data[$i]['name'] = $k;
$i++;
}
$result = array(
'updateNum' => $total,
'list' => $data
);
return $result;
}
/**
* 当前页地址
*/
public static function current(){
$url = explode('?', $_SERVER['REQUEST_URI']);
self::$current_url = $url[0];
self::$listnav[0] = array(
'href' => '$url[0]',
'name' => '首页'
);
return $url[0];
}
/**
* 下一页地址
*/
public static function next($total,$filter){
$page = 1;
$param = self::$params;
$page = self::$page;
if($page < $total){
$page ++;
$param['page'] = $page;
}
return self::buildurl($param);
}
}
... ...