Authored by Rock Zhang

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

Showing 61 changed files with 3296 additions and 833 deletions

Too many changes to show.

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

<?php return function ($in, $debugopt = 1) {
$cx = array(
'flags' => array(
'jstrue' => false,
'jsobj' => false,
'spvar' => true,
'prop' => false,
'method' => false,
'mustlok' => true,
'echo' => false,
'debug' => $debugopt,
),
'constants' => array(),
'helpers' => array(),
'blockhelpers' => array(),
'hbhelpers' => array(),
'partials' => array(),
'scopes' => array(),
'sp_vars' => array('root' => $in),
'lcrun' => 'Plugin\LCRun3',
);
return '<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('staticTitle')), ENT_QUOTES, 'UTF-8').'</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<style>
*{margin: 0;padding: 0;}
#coupon-container {width: 100%;}
#coupon-container img {width: 100%; height: auto; display: block;overflow: hidden;}
.img-box {width: 100%;position: relative;}
.img-box .href {width: 50%; height: 100%;position: absolute;top: 0;}
.img-box .href-left {left: 0}
.img-box .href-right {right: 0}
.img-box .href-center {width: 90%;height: 100%;position: absolute;top: 0;left: 5%;}
.show-more {height: 100%;width: 25%;position: absolute;top: 0;right: 10%;}
.yoho-tip {position: fixed;display: none;text-align: center;width: 70%;padding: 34px 0;top: 50%;left: 50%;margin-left: -35%;margin-top: -45px;background-color: #000;opacity: 0.9;color: #fff;font-size: 18px;border: none;border-radius: 10px;}
</style>
<link rel="dns-prefetch" href="//cdn.yoho.cn">
<link rel="dns-prefetch" href="//static.yohobuy.com">
</head>
<body>
<div id="coupon-container" param="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('activityId')), ENT_QUOTES, 'UTF-8').'" isLogged="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('isLogged')), ENT_QUOTES, 'UTF-8').'">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/01.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/02.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/03-a.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/line-1.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/04-a.jpg">
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/05-a.jpg">
<a class="href href-right" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_yohope')), ENT_QUOTES, 'UTF-8').'"></a>
</div>
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/06.jpg">
<a class="href href-center" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_mycoupon')), ENT_QUOTES, 'UTF-8').'"></a>
</div>
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/line-2.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/07.jpg">
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/08.jpg">
<a class="href href-left" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_more')), ENT_QUOTES, 'UTF-8').'"></a>
<a class="href href-right" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_more')), ENT_QUOTES, 'UTF-8').'"></a>
</div>
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/09.jpg">
<span class="href href-left get-coupon" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jumpUrl')), ENT_QUOTES, 'UTF-8').'" param="17443"></span>
<span class="href href-right get-coupon" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jumpUrl')), ENT_QUOTES, 'UTF-8').'" param="17445"></span>
</div>
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/line-1.jpg">
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/10.jpg">
<a class="href href-left" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_more')), ENT_QUOTES, 'UTF-8').'"></a>
<a class="href href-right" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_1')), ENT_QUOTES, 'UTF-8').'"></a>
</div>
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/11.jpg">
<span class="href href-left get-coupon" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jumpUrl')), ENT_QUOTES, 'UTF-8').'" param="17463"></span>
<span class="href href-right get-coupon" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jumpUrl')), ENT_QUOTES, 'UTF-8').'" param="17451"></span>
</div>
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/line-1.jpg">
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/12.jpg">
<a class="href href-left" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_2')), ENT_QUOTES, 'UTF-8').'"></a>
<a class="href href-right" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_3')), ENT_QUOTES, 'UTF-8').'"></a>
</div>
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/13.jpg">
<span class="href href-left get-coupon" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jumpUrl')), ENT_QUOTES, 'UTF-8').'" param="17461"></span>
<span class="href href-right get-coupon" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jumpUrl')), ENT_QUOTES, 'UTF-8').'" param="17459"></span>
</div>
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/line-1.jpg">
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/14.jpg">
<a class="href href-left" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_4')), ENT_QUOTES, 'UTF-8').'"></a>
<a class="href href-right" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_5')), ENT_QUOTES, 'UTF-8').'"></a>
</div>
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/15.jpg">
<span class="href href-left get-coupon" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jumpUrl')), ENT_QUOTES, 'UTF-8').'" param="17453"></span>
<span class="href href-right get-coupon" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jumpUrl')), ENT_QUOTES, 'UTF-8').'" param="17455"></span>
</div>
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/line-1.jpg">
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/16.jpg">
<a class="href href-left" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_6')), ENT_QUOTES, 'UTF-8').'"></a>
</div>
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/17.jpg">
<span class="href href-left get-coupon" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jumpUrl')), ENT_QUOTES, 'UTF-8').'" param="17449"></span>
</div>
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/line-1.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/24-1.jpg">
<div class="img-box">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/24-2.jpg">
<a class="show-more" href="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('url_help')), ENT_QUOTES, 'UTF-8').'"></a>
</div>
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/24-3.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/line-2.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/25-1-a.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/25-2-a.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/25-3-a.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/26-a.jpg">
<img src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/img/newuser/160107/27-a.jpg">
</div>
<script type="text/javascript" src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/js/jquery.min.js"></script>
<script type="text/javascript" src="'.htmlentities((string)Plugin\LCRun3::v($cx, $in, array('jsUrl')), ENT_QUOTES, 'UTF-8').'/cuxiao/js/newuser/coupon2.js"></script>
</body>
</html>';
}
?>
\ No newline at end of file
... ...
... ... @@ -513,6 +513,11 @@
{
attr: 'style', //查找的键值
name: '风格',
//若无子项,传url
url: '',
//若有子项,传sub
showMulti: true, //是否显示多选按钮
sub: [
{
... ...
<?php
namespace LibModels\Web\Home;
use Api\Yohobuy;
use Api\Sign;
use Plugin\Helpers;
class UserData extends \LibModels\Wap\Home\UserData
{
/**
* 根据手机号获取用户信息[TODO +cache]
*
* @param string $area
* @param string $mobile
* @return array
*/
public static function getUserInfoByMobile($area, $mobile)
{
$param = Yohobuy::param();
$param['method'] = 'app.passport.userlist';
$param['mobile'] = Helpers::makeMobile($area, $mobile);
$param['debug'] = 'Y';
$param['screen_size'] = '320x568';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::post(Yohobuy::API_URL, $param);
}
/**
* 根据email获取用户信息
*
* @param string $email
* @return array
*/
public static function getUserInfoByEmail($email)
{
$param = Yohobuy::param();
$param['method'] = 'app.passport.userlist';
$param['email'] = $email;
$param['debug'] = 'Y';
$param['screen_size'] = '320x568';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::post(Yohobuy::API_URL, $param);
}
}
\ No newline at end of file
... ...
<?php
namespace LibModels\Web\Passport;
use Api\Yohobuy;
use Api\Sign;
use Plugin\Helpers;
class RegData extends \LibModels\Wap\Passport\RegData
{
/**
* 根据手机号获取用户信息[TODO +cache]
*
* @param string $area
* @param string $mobile
* @return string
*/
public static function getUserInfoByMobile($area, $mobile)
{
$param = Yohobuy::param();
$param['method'] = 'app.passport.userlist';
$param['mobile'] = Helpers::makeMobile($area, $mobile);
$param['debug'] = 'Y';
$param['screen_size'] = '320x568';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::post(Yohobuy::API_URL, $param);
}
}
\ No newline at end of file
... ...
... ... @@ -11,31 +11,114 @@ class SearchData extends \LibModels\Wap\Product\SearchData
*
* @return string
*/
private static function getUrl($type = 'search')
public static function getUrl($type = 'search')
{
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer');
switch (APPLICATION_ENV) {
case 'release':
if($type == 'sort'){
if ($type == 'sort') {
return 'http://100.98.132.63/yohosearch/sortgroup.json';
}
elseif($type == 'suggest'){
return 'http://100.98.132.63/yohosearch/suggest.json';
elseif ($type == 'discount') {
return 'http://100.98.132.63/yohosearch/discount.json';
}
elseif ($type == 'recent') {
return 'http://100.98.132.63/yohosearch/recent.json';
}
elseif ($type == 'shop') {
return 'http://100.98.132.63/yohosearch/shops.json';
}
return 'http://100.98.132.63/yohosearch/search.json';
case 'test':
case 'preview':
case 'developer':
default:
if($type == 'sort'){
if ($type == 'sort') {
return 'http://101.200.31.165/yohosearch/sortgroup.json';
}
elseif($type == 'suggest'){
return 'http://101.200.31.165/yohosearch/suggest.json';
elseif ($type == 'discount') {
return 'http://101.200.31.165/yohosearch/discount.json';
}
elseif ($type == 'recent') {
return 'http://101.200.31.165/yohosearch/recent.json';
}
elseif ($type == 'shop') {
return 'http://101.200.31.165/yohosearch/shops.json';
}
// return 'http://101.200.31.165/yohosearch/search.json';
return 'http://192.168.10.64:8080/yohosearch/search-once.json';
}
}
/**
* 根据给定查询数据搜索数据列表 (新的)
*
* @param string $query 查询条件, 默认为null
* @param string $brand 品牌,默认为null
* @param string $gender 性别,默认为null,"1,3"表示男, "2,3"表示女, "1,2,3"表示全部
* @param integer $color 颜色id
* @param integer $size 尺码id
* @param integer $price 价格
* @param string $p_d 折扣,默认为null
* @param string $sort 商品所属品类,默认为null
* @param string $order 排序方式,默认为按照时间倒序排列s_t_desc,
* s_t_asc表示按时间正序排列,
* s_p_asc表示按价格正序排列,
* s_p_desc表示按价格倒序排列,
* p_d_asc表示按折扣正序排列,
* p_d_desc表示按折扣倒序排列
* @param integer $page 指定查询是多少页,默认为第一页
* @param integer $limit 指定查询多少个,默认是60个
* @param integer $channel表示哪个频道,1表示男生,2表示女生,3表示潮童,4表示创意生活
* @return array 搜索到的数据
*/
public static function searchElasticByCondition($condition, $cache = false)
{
// 排序数据映射表
$orderMaps = array(
's_t_desc' => 'shelve_time:desc',
's_t_asc' => 'shelve_time:asc',
's_p_asc' => 'sales_price:asc',
's_p_desc' => 'sales_price:desc',
'p_d_desc' => 'discount:desc',
'p_d_asc' => 'discount:asc',
'skn_desc' => 'product_skn:desc',
'skn_asc' => 'product_skn:asc',
'activities_desc' => 'activities.order_by:desc',
'activities_asc' => 'activities.order_by:asc',
's_n_asc' => 'sales_num:asc',
's_n_desc' => 'sales_num:desc',
'activities_id_desc' => 'activities.activity_id:desc',
'activities_id_asc' => 'activities.activity_id:asc',
);
return 'http://101.200.31.165/yohosearch/search.json';
$param = array();
$param['status'] = 1; // 是否上架,1表示在架,2表示不在
$param['sales'] = 'Y'; // 只搜索销售的产品
$param['stocknumber'] = 1; // 过滤掉已售罄的商品
// $param['needFilter'] = 1; // 是否需要返回筛选条件
if (!isset($condition['order'])) {
$param['order'] = $orderMaps['s_t_desc'];
} else {
$param['order'] = $orderMaps[$condition['order']];
}
if (!isset($condition['page'])) {
$param['page'] = 1;
}
if(isset($condition['viewNum'])) {
$param['viewNum'] = $condition['viewNum'];
} else if (!isset($condition['limit'])) {
$param['viewNum'] = 60;
} else {
$param['viewNum'] = $condition['limit'];
unset($condition['limit']);
}
if (!empty($condition)) {
$param += $condition;
}
return Yohobuy::get(self::getUrl('search'), $param, $cache);
}
/**
* 根据分类列表获取商品信息
... ...
... ... @@ -4,6 +4,7 @@ namespace Plugin;
use Plugin\Paging;
use LibModels\Web\Product\BrandData;
use LibModels\Web\Product\SearchData;
use Api\Yohobuy;
use Api\Sign;
/**
... ... @@ -89,6 +90,10 @@ class HelperSearch
$result['shopEntry'] = isset($data['shop']) && !empty($data['shop']) ? self::shop($data['shop'], $data['sort']['sort']) : array();
//分页
$result['pager'] = self::pager($result['totalCount'],$options['viewNum']-1);
//浏览记录
if (isset($options['reviewNum']) && !empty($options['reviewNum'])) {
$result['latestWalk'] = $options['reviewNum'];
}
//选中条件
$result['filters']['checkedConditions'] = self::getSelected();
if (isset($options['controller']) && $options['controller'] == 'Search') {
... ... @@ -134,7 +139,7 @@ class HelperSearch
if (!empty($val['default_images'])) {
$val['default_images'] = Images::getImageUrl($val['default_images'],$imgSize[0],$imgSize[1]);
}
$goods[] = array(
$good = array(
'tags' => array(
'isNew' => $isNew,
'isLimit' => $isLimit
... ... @@ -143,12 +148,16 @@ class HelperSearch
'thumb' => $val['default_images'],
'name' => $val['product_name'],
'salePrice' => $val['sales_price'],
'marketPrice' => $val['market_price'],
'isFew' => $isFew,
'skn' => $val['product_skn'],
'showColBtn' => true,
'coled' => true
);
//市场价不等于售价时显示
if ($val['market_price'] != $val['sales_price']) {
$good['marketPrice'] = $val['market_price'];
}
$goods[] = $good;
}
return $goods;
}
... ... @@ -343,10 +352,6 @@ class HelperSearch
array(
'index' => 'all',
'name' => '全部'
),
array(
'index' => '0-9',
'name' => '0 ~ 9'
)
),
'brandsShow' => array()
... ... @@ -356,17 +361,29 @@ class HelperSearch
$brandIds = isset($params['brand']) && !empty($params['brand']) ? explode(',', $params['brand']) : array();
if (isset($filter['brand']) && !empty($filter['brand'])) {
$brand = $filter['brand'];
// print_r($filter); exit;
//已选中品牌数量
$existBrandNum = 0;
//已选中品牌标签名
$existName = '';
foreach ($brand as $key => $v) {
$selectBrandIds = $brandIds;
//品牌id在提交的参数中,构造url参数去除该品牌id
//品牌已被选中
if (in_array($v['id'], $brandIds)) {
$filterKey = array_search($v['id'], $selectBrandIds);
unset($selectBrandIds[$filterKey]);
$url = self::buildUrl(array_merge($params, array(
'brand' => implode(',', $selectBrandIds)
)));
if ($existBrandNum === 0) {
$existName .= $v['brand_name'].'、';
}
if ($existBrandNum === 1){
$existName .= substr($v['brand_name'], 0, 3).'...';
}
$existBrandNum++;
}
//该品牌url参数中添加该品牌的id
//该品牌未被选中
else {
$selectBrandIds[] = $v['id'];
$url = self::buildUrl(array_merge($params, array(
... ... @@ -396,25 +413,6 @@ class HelperSearch
}
//清空品牌参数
unset($params['brand']);
//设置已选中的品牌
$existBrandNum = 0;
$existName = '';
foreach ($brandIds as $key => $val) {
if (isset($brandAll[$val])) {
$brandParam = $brandIds;
unset($brandParam[$key]);
if ($existBrandNum === 0) {
$existName .= $brandAll[$val].'、';
}
if ($existBrandNum === 1){
$existName .= substr($brandAll[$val], 0, 3).'...';
}
$existBrandNum++;
}
if ($existBrandNum > 1) {
break;
}
}
//设置选中
if (isset(self::$params['brand']) && !empty(self::$params['brand'])) {
self::$selected['brand'] = array(
... ... @@ -448,6 +446,7 @@ class HelperSearch
if (count($result['brandsShow']) < 11) {
$result['hideMore'] = true;
}
// print_r($result); exit;
return $result;
}
/**
... ... @@ -459,14 +458,14 @@ class HelperSearch
{
$params = self::$params;
$paramsValue = array_filter($params);
if (!$isAjax && empty($paramsValue)) {
return array();
}
$sizeId = isset($params['size']) && !empty($params['size']) ? $params['size'] : '';
if (isset($params['size'])) {
unset($params['size']);
}
$result = array();
if (!$isAjax && empty($paramsValue)) {
return array();
}
if (isset($filter['size']) && !empty($filter['size'])) {
$size = $filter['size'];
foreach ($size as $k=> $v) {
... ... @@ -485,7 +484,7 @@ class HelperSearch
'checked' => isset(self::$params['size']) && self::$params['size'] == $v['size_id'] ? true : false
);
}
if (self::checkSearch('size')) {
if ( self::checkSearch('size')) {
return array();
}
}
... ... @@ -940,8 +939,8 @@ class HelperSearch
}
if ($data) {
$result['conditions'] = $data;
$result['clearUrl'] = self::current();
}
$result['clearUrl'] = self::current();
return $result;
}
... ... @@ -1200,7 +1199,7 @@ class HelperSearch
if (!empty($condition)) {
$param += $condition;
}
return Yohobuy::httpBuildQuery(self::getUrl(), $param);
return Yohobuy::httpBuildQuery(SearchData::getUrl(), $param);
}
/**
... ... @@ -1213,7 +1212,7 @@ class HelperSearch
$condition['sales'] = 'Y'; //在销售商品分类
$condition['status'] = 1; //上架商品分类
$condition['stocknumber'] = 1; //过滤掉已售罄
return Yohobuy::httpBuildQuery(self::getUrl('sort'), $condition);
return Yohobuy::httpBuildQuery(SearchData::getUrl('sort'), $condition);
}
/**
... ... @@ -1223,7 +1222,7 @@ class HelperSearch
public static function getDiscountUrl($param = array())
{
return Yohobuy::httpBuildQuery(self::getUrl('discount'), $param);
return Yohobuy::httpBuildQuery(SearchData::getUrl('discount'), $param);
}
/**
... ... @@ -1231,7 +1230,7 @@ class HelperSearch
*/
public static function getRecentShelveUrl($param = array())
{
return Yohobuy::httpBuildQuery(self::getUrl('recent'), $param);
return Yohobuy::httpBuildQuery(SearchData::getUrl('recent'), $param);
}
/**
... ... @@ -1262,15 +1261,6 @@ class HelperSearch
return Yohobuy::httpBuildQuery(Yohobuy::API_URL, $param);
}
/**
* 并行调接口url获取(获取用户浏览记录)
*/
// public static function getReviewUrl($param = array())
// {
// return Yohobuy::httpBuildQuery(self::getUrl('review'), $param);
// }
/**
... ... @@ -1280,58 +1270,7 @@ class HelperSearch
*/
public static function getShopUrl($param)
{
return Yohobuy::httpBuildQuery(self::getUrl('shop'), $param);
}
/**
* 获取搜索的服务地址
*
* 备注:此处是根据环境来确定使用阿里云内网还是外网的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';
}
elseif ($type == 'discount') {
return 'http://100.98.132.63/yohosearch/discount.json';
}
elseif ($type == 'recent') {
return 'http://100.98.132.63/yohosearch/recent.json';
}
// elseif ($type == 'review') {
//
// }
elseif ($type == 'shop') {
return 'http://100.98.132.63/yohosearch/shops.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';
}
elseif ($type == 'discount') {
return 'http://101.200.31.165/yohosearch/discount.json';
}
elseif ($type == 'recent') {
return 'http://101.200.31.165/yohosearch/recent.json';
}
// elseif ($type == 'review') {
//
// }
elseif ($type == 'shop') {
return 'http://101.200.31.165/yohosearch/shops.json';
}
// return 'http://101.200.31.165/yohosearch/search.json';
return 'http://192.168.10.64:8080/yohosearch/search-once.json';
}
return Yohobuy::httpBuildQuery(SearchData::getUrl('shop'), $param);
}
/**
... ...
No preview for this file type
This diff could not be displayed because it is too large.
No preview for this file type
No preview for this file type
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
... ... @@ -2,7 +2,7 @@
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
<svg xmlns="http://www.w3.org/2000/svg">
<metadata>
Created by FontForge 20120731 at Wed Jan 13 13:50:02 2016
Created by FontForge 20120731 at Wed Jan 20 14:25:44 2016
By Ads
</metadata>
<defs>
... ... @@ -19,7 +19,7 @@ Created by FontForge 20120731 at Wed Jan 13 13:50:02 2016
bbox="-0.75 -224 3943 896"
underline-thickness="50"
underline-position="-100"
unicode-range="U+0078-E644"
unicode-range="U+0078-E645"
/>
<missing-glyph horiz-adv-x="374"
d="M34 0v682h272v-682h-272zM68 34h204v614h-204v-614z" />
... ... @@ -278,5 +278,10 @@ q0 -14 -3.5 -27t-10 -23.5t-16 -20t-20.5 -15.5t-24 -10t-27 -4zM848 367q-42 0 -71.
d="M523 881q-101 0 -192.5 -39.5t-158 -105.5t-105.5 -158t-39 -193q0 -205 145 -350t350 -145q67 0 131.5 18t119 49.5t100 77.5t77.5 100.5t49.5 118.5t17.5 131q0 101 -39 193t-105.5 158t-158 105.5t-192.5 39.5zM739 224q8 -8 7 -19q0 -2 -0.5 -4.5t-1.5 -5t-2.5 -4.5
t-3.5 -3q-11 -10 -15 -14q-7 -7 -17 -7t-18 7l-34 34q-59 -42 -131 -42q-94 0 -160.5 66.5t-66.5 160.5q0 46 18 88t48.5 72.5t72.5 48.5t88 18t88 -18t72.5 -48.5t48.5 -72.5t18 -88q0 -75 -45 -135zM592 337q8 7 18 6.5t17 -7.5l27 -27q25 39 25 84q0 64 -45.5 109.5
t-110 45.5t-110 -45.5t-45.5 -109.5t45.5 -109.5t109.5 -45.5q44 0 80 21l-27 28q-8 7 -7.5 18t7.5 18z" />
<glyph glyph-name="uniE645" unicode="&#xe645;"
d="M512 798q-104 0 -198 -40.5t-162.5 -109t-109 -162.5t-40.5 -198t40.5 -198t109 -162.5t162.5 -109t198 -40.5t198 40.5t162.5 109t109 162.5t40.5 198t-40.5 198t-109 162.5t-162.5 109t-198 40.5zM512 -149q-89 0 -170 34.5t-139.5 93t-93 139.5t-34.5 170
q0 71 22 137.5t62.5 120.5t94.5 94.5t120.5 62.5t137.5 22t137.5 -22t120.5 -62.5t94.5 -94.5t62.5 -120.5t22 -137.5q0 -89 -34.5 -170t-93 -139.5t-139.5 -93t-170 -34.5zM659 288q15 0 25.5 10.5t10.5 25.5t-10.5 26t-25.5 11h-111v17l135 141q5 5 8 12t2.5 14t-3 13.5
t-8.5 11.5q-10 11 -25 10.5t-26 -11.5l-115 -121l-123 122q-11 11 -26 10.5t-25 -10.5q-7 -7 -10 -16.5t-0.5 -19t9.5 -16.5l135 -135v-22h-108q-8 0 -14.5 -3t-11.5 -8t-8 -11.5t-3 -14.5q0 -9 5 -17.5t13.5 -13.5t18.5 -5h108v-73h-108q-8 0 -14.5 -3t-11.5 -7.5t-8 -11.5
t-3 -14.5t3 -14t8 -11.5t11.5 -8t14.5 -3h108v-108q0 -15 10.5 -25.5t25.5 -10.5q10 0 18.5 4.5t13 13t4.5 18.5v108h111q10 0 18.5 5t13 13.5t4.5 18.5q0 7 -2.5 14t-7.5 11.5t-12 7.5t-14 3h-111v73h111z" />
</font>
</defs></svg>
... ...
No preview for this file type
... ... @@ -2,7 +2,7 @@
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
<svg xmlns="http://www.w3.org/2000/svg">
<metadata>
Created by FontForge 20120731 at Wed Jan 13 13:50:02 2016
Created by FontForge 20120731 at Wed Jan 20 14:25:44 2016
By Ads
</metadata>
<defs>
... ... @@ -19,7 +19,7 @@ Created by FontForge 20120731 at Wed Jan 13 13:50:02 2016
bbox="-0.75 -224 3943 896"
underline-thickness="50"
underline-position="-100"
unicode-range="U+0078-E644"
unicode-range="U+0078-E645"
/>
<missing-glyph horiz-adv-x="374"
d="M34 0v682h272v-682h-272zM68 34h204v614h-204v-614z" />
... ... @@ -278,5 +278,10 @@ q0 -14 -3.5 -27t-10 -23.5t-16 -20t-20.5 -15.5t-24 -10t-27 -4zM848 367q-42 0 -71.
d="M523 881q-101 0 -192.5 -39.5t-158 -105.5t-105.5 -158t-39 -193q0 -205 145 -350t350 -145q67 0 131.5 18t119 49.5t100 77.5t77.5 100.5t49.5 118.5t17.5 131q0 101 -39 193t-105.5 158t-158 105.5t-192.5 39.5zM739 224q8 -8 7 -19q0 -2 -0.5 -4.5t-1.5 -5t-2.5 -4.5
t-3.5 -3q-11 -10 -15 -14q-7 -7 -17 -7t-18 7l-34 34q-59 -42 -131 -42q-94 0 -160.5 66.5t-66.5 160.5q0 46 18 88t48.5 72.5t72.5 48.5t88 18t88 -18t72.5 -48.5t48.5 -72.5t18 -88q0 -75 -45 -135zM592 337q8 7 18 6.5t17 -7.5l27 -27q25 39 25 84q0 64 -45.5 109.5
t-110 45.5t-110 -45.5t-45.5 -109.5t45.5 -109.5t109.5 -45.5q44 0 80 21l-27 28q-8 7 -7.5 18t7.5 18z" />
<glyph glyph-name="uniE645" unicode="&#xe645;"
d="M512 798q-104 0 -198 -40.5t-162.5 -109t-109 -162.5t-40.5 -198t40.5 -198t109 -162.5t162.5 -109t198 -40.5t198 40.5t162.5 109t109 162.5t40.5 198t-40.5 198t-109 162.5t-162.5 109t-198 40.5zM512 -149q-89 0 -170 34.5t-139.5 93t-93 139.5t-34.5 170
q0 71 22 137.5t62.5 120.5t94.5 94.5t120.5 62.5t137.5 22t137.5 -22t120.5 -62.5t94.5 -94.5t62.5 -120.5t22 -137.5q0 -89 -34.5 -170t-93 -139.5t-139.5 -93t-170 -34.5zM659 288q15 0 25.5 10.5t10.5 25.5t-10.5 26t-25.5 11h-111v17l135 141q5 5 8 12t2.5 14t-3 13.5
t-8.5 11.5q-10 11 -25 10.5t-26 -11.5l-115 -121l-123 122q-11 11 -26 10.5t-25 -10.5q-7 -7 -10 -16.5t-0.5 -19t9.5 -16.5l135 -135v-22h-108q-8 0 -14.5 -3t-11.5 -8t-8 -11.5t-3 -14.5q0 -9 5 -17.5t13.5 -13.5t18.5 -5h108v-73h-108q-8 0 -14.5 -3t-11.5 -7.5t-8 -11.5
t-3 -14.5t3 -14t8 -11.5t11.5 -8t14.5 -3h108v-108q0 -15 10.5 -25.5t25.5 -10.5q10 0 18.5 4.5t13 13t4.5 18.5v108h111q10 0 18.5 5t13 13.5t4.5 18.5q0 7 -2.5 14t-7.5 11.5t-12 7.5t-14 3h-111v73h111z" />
</font>
</defs></svg>
... ...
No preview for this file type
No preview for this file type
var $ = require('jquery');
var $ = require('jquery'),
loading = require('../plugin/loading');
var page = 1;
loading.showLoadingMask();
function ajaxCurrencyDetail(page) {
$.ajax({
type: 'POST',
... ... @@ -29,3 +32,5 @@ $(window).scroll(function() {
});
ajaxCurrencyDetail(page);
$(document).ready(loading.hideLoadingMask);
... ...
... ... @@ -144,6 +144,7 @@
padding: 20rem / $pxConvertRem 0;
font-size: 24rem / $pxConvertRem;
border-top: 1px solid #e0e0e0;
border-bottom: 1px solid #e0e0e0;
margin-bottom: 30rem / $pxConvertRem;
> li {
... ... @@ -180,7 +181,7 @@
}
.count {
color: #f00;
color: #7b7b7b;
float: right;
}
... ...
... ... @@ -23,11 +23,11 @@
<div id="coupon-container" param="{{activityId}}" isLogged="{{isLogged}}">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/01.jpg">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/02.jpg">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/03.jpg">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/03-a.jpg">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/line-1.jpg">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/04.jpg">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/04-a.jpg">
<div class="img-box">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/05.jpg">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/05-a.jpg">
<a class="href href-right" href="{{url_yohope}}"></a>
</div>
<div class="img-box">
... ... @@ -98,11 +98,11 @@
</div>
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/24-3.jpg">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/line-2.jpg">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/25-1.jpg">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/25-2.jpg">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/25-3.jpg">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/26.jpg">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/27.jpg">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/25-1-a.jpg">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/25-2-a.jpg">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/25-3-a.jpg">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/26-a.jpg">
<img src="{{jsUrl}}/cuxiao/img/newuser/160107/27-a.jpg">
</div>
<script type="text/javascript" src="{{jsUrl}}/cuxiao/js/jquery.min.js"></script>
<script type="text/javascript" src="{{jsUrl}}/cuxiao/js/newuser/coupon2.js"></script>
... ...
... ... @@ -28,7 +28,7 @@
{{#if advanceBuy}}
<li class="advance-buy">
<a href="/cart/index/advanceBuy?cartType={{cartType}}">
<span class="iconfont">&#xe61b;</span>
<span class="iconfont">&#xe645;</span>
加价购
<span class="iconfont icon-right-arrow">&#xe614;</span>
<span class="count">{{advanceBuyCount}}</span>
... ...
... ... @@ -32,7 +32,7 @@
<div class="size-list block-list">
<span>尺码</span>
{{# sizes}}
<ul id="{{sizeName}}" data-index="{{@index}}" class="size-row clearfix {{#unless @first}}hide{{/if}}">
<ul class="size-row clearfix {{#unless @first}}hide{{/if}}">
{{# size}}
<li class="block {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}zero-stock{{/unless}}" data-num="{{sizeNum}}" data-id="{{id}}" data-skuid="{{skuId}}">
{{name}}
... ...
{{> layout/header}}
<div class="sale-list-page new-sale-page product-page yoho-page">
{{# saleList}}
{{> sale/sale-banner}}
<div class="center-content clearfix">
{{#saleTitle}}
<div class="sale-title">
<span class="title">{{title}}</span>
{{#if discount}}
<span class="discount">{{discount}}</span>
{{/if}}
{{#if up}}
{{/if}}
<div class="time pull-right">
<span class="iconfont">&#xe60d;</span>{{time}}
</div>
</div>
{{/saleTitle}}
<ul class="sort">
<li class="title">分类:</li>
{{#sort}}
<li class="{{#if active}}active{{/if}}"><a href="#">{{name}}{{#if number}}({{number}}){{/if}}</a></li>
{{/sort}}
</ul>
{{> product/standard-content}}
</div>
{{/ saleList}}
</div>
{{> layout/footer}}
... ...
{{> layout/header}}
<div class="new-sale-page product-page yoho-page">
{{# saleList}}
{{# saleBanner}}
<div class="sale-list-banner" style="height: {{bannerHeight}}px;">
<ul style="height: {{bannerHeight}}px;">
{{# list}}
<li class="banner-img" style="background:url({{img}}) no-repeat top center;"></li>
{{/ list}}
</ul>
</div>
{{/ saleBanner}}
{{> sale/sale-banner}}
<div class="center-content clearfix">
{{# saleTitle}}
<div class="header-title">
... ... @@ -31,4 +25,4 @@
</div>
{{/ saleList}}
</div>
{{> layout/footer}}
\ No newline at end of file
{{> layout/footer}}
... ...
... ... @@ -106,7 +106,7 @@
</div>
<div class="showdetail" data-code="{{content_code}}">
<a href="http://list.yohobuy.com/?gender=1,3&amp;msort=8">
<img src="http://img12.static.yhbimg.com/yhb-img01/2015/10/30/06/02af834d146e3f00b1f5fcc8388f641922.jpg?imageView/1/w/337/h/250" alt="" style=""></a>
<img src="data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" alt="" style=""></a>
<a class="title" href="http://list.yohobuy.com/?gender=1,3&amp;msort=8">热门小物优选</a>
</div>
</div>
... ... @@ -124,7 +124,7 @@
<div class="search float-left {{searchcate}}" >
<form action="http://search.yohobuy.com" method="get" id="searchForm">
<span class="searchspan">
<input class="searchinput" type="text" name="keyword" id="query_key" autocomplete="off" x-webkit-speech="" lang="zh-CN" x-webkit-grammar="builtin:translate" value="" onfocus="if(this.value==this.defaultValue){this.value='';this.style.color='#333'}" onblur="if(this.value==''){this.value=this.defaultValue;this.style.color='#999'}" maxlength="30"></span>
<input class="searchinput" type="text" name="query" id="query_key" autocomplete="off" x-webkit-speech="" lang="zh-CN" x-webkit-grammar="builtin:translate" value="" onfocus="if(this.value==this.defaultValue){this.value='';this.style.color='#333'}" onblur="if(this.value==''){this.value=this.defaultValue;this.style.color='#999'}" maxlength="30"></span>
<a class="icon-search" href="javascript:submitSearch();"></a>
<ul class="search-list"></ul>
</form>
... ...
... ... @@ -75,6 +75,38 @@
</script>
{{/if}}
{{!-- sale列表 --}}
{{#if saleListPage}}
<script>
seajs.use(['js/product/list', 'js/product/product', 'js/sale/banner'], function (list, product) {
product.init(4);
window.onresize = function () {
setTimeout(function () {
product.init(4);
}, 300);
};
});
</script>
{{/if}}
{{!-- sale 分类列表 --}}
{{#if saleCatPage}}
<script>
seajs.use(['js/product/list', 'js/product/product', 'js/sale/banner'], function (list, product) {
product.init(4);
window.onresize = function () {
setTimeout(function () {
product.init(4);
}, 300);
};
});
</script>
{{/if}}
{{!-- 登录注册找回密码--}}
{{#if loginPage}}
<script>
... ... @@ -139,20 +171,3 @@
seajs.use('js/order/save');
</script>
{{/if}}
{{!-- sale列表 --}}
{{#if saleListPage}}
<script>
seajs.use(['js/product/list', 'js/product/product', 'js/product/banner'], function (list, product) {
product.init(4);
window.onresize = function () {
setTimeout(function () {
product.init(4);
}, 300);
};
});
</script>
{{/if}}
... ...
... ... @@ -179,7 +179,7 @@
</div>
{{/if}}
<div class="size section hide">
<div class="size section {{#unless size}}hide{{/unless}}">
<span class="title">尺码:</span>
<div class="attr-content clearfix">
... ... @@ -196,38 +196,44 @@
<div class="attr-content">
<ul class="clearfix senior-attr-wrap">
{{#each seniorChose}}
<li class="attr">
{{name}}
<span class="iconfont">&#xe600;</span>
<li class="attr{{#unless sub}} no-sub{{/unless}}">
{{#if sub}}
{{name}}
<span class="iconfont">&#xe600;</span>
<div class="senior-up-icon"></div>
<div class="senior-up-icon"></div>
{{^}}
<a href="{{url}}">{{name}}</a>
{{/if}}
</li>
{{/each}}
</ul>
<div class="senior-sub-wrap">
{{#each seniorChose}}
<div class="senior-sub hide" data-attr="{{attr}}">
<div class="senior-content">
{{#if showMulti}}
<span class="multi-select">多选 +</span>
{{/if}}
<ul class="clearfix check-container">
{{#each sub}}
<li class="attr {{#if checked}}checked{{/if}}">
<a href="{{href}}">
<span class="iconfont checkbox" data-id="{{id}}">&#xe613;</span>
<span>{{name}}</span>
</a>
</li>
{{/each}}
</ul>
<div class="btns">
<button class="multi-select-ok dis">确定</button>
<button class="multi-select-cancel">取消</button>
{{#if sub}}
<div class="senior-sub hide" data-attr="{{attr}}">
<div class="senior-content">
{{#if showMulti}}
<span class="multi-select">多选 +</span>
{{/if}}
<ul class="clearfix check-container">
{{#each sub}}
<li class="attr {{#if checked}}checked{{/if}}">
<a href="{{href}}">
<span class="iconfont checkbox" data-id="{{id}}">&#xe613;</span>
<span>{{name}}</span>
</a>
</li>
{{/each}}
</ul>
<div class="btns">
<button class="multi-select-ok dis">确定</button>
<button class="multi-select-cancel">取消</button>
</div>
</div>
</div>
</div>
{{/if}}
{{/each}}
</div>
</div>
... ...
{{#if latestWalk}}
<input id="latest-walk-count" type="hidden" value="{{latestWalk}}">
<div class="latest-walk">
<h2>最近浏览的商品</h2>
<div class="goods clearfix">
{{# latestWalk}}
<div class="good">
<a href="{{href}}">
<img class="lazy" data-original="{{img}}">
</a>
<a class="name" href="{{href}}">{{name}}</a>
<p class="price">
{{#if salePrice}}
<span class="market-price">¥{{marketPrice}}</span>
{{/if}}
<span class="sale-price">¥{{salePrice}}</span>
</p>
</div>
{{/ latestWalk}}
</div>
<div id="latest-walk-goods" class="goods clearfix"></div>
</div>
<script id="latest-walk-tpl" type="text/html">
\{{# latestWalk}}
<div class="good">
<a href="\{{href}}">
<img class="lazy" data-original="\{{img}}">
</a>
<a class="name" href="\{{href}}">\{{name}}</a>
<p class="price">
<span class="market-price">\{{marketPrice}}</span>
<span class="sale-price">\{{salePrice}}</span>
</p>
</div>
\{{/ latestWalk}}
</script>
{{/if}}
\ No newline at end of file
... ...
{{# saleBanner}}
<div class="sale-list-banner" style="height: {{bannerHeight}}px;">
<ul style="height: {{bannerHeight}}px;">
{{# list}}
<li class="banner-img" style="background:url({{img}}) no-repeat top center;"></li>
{{/ list}}
</ul>
</div>
{{/ saleBanner}}
... ...
... ... @@ -159,8 +159,6 @@ var $ = require("jquery");
var $returnTop = $('.return-top');
var apiDomain;
/**
* 订阅
* @return {[type]} [description]
... ... @@ -170,41 +168,36 @@ function actionSubscription() {
$subscriberBtn = $('#subscriber-btn'),
emailReg = /^[.\-_a-zA-Z0-9]+@[\-_a-zA-Z0-9]+\.[a-zA-Z0-9]/;
var subscribeParam = {
method: 'open.subscriber.subscriber',
v: 1,
return_type: 'jsonp',
open_key: '12345'
};
var iconCode = {
mail: '&#xe61b;',
tick: '&#xe61a'
};
var email = $.trim($subscriberBox.val());
var params = {};
$subscriberBox.focus(function() {
$(this).val('').css('color', '');
$subscriberBtn.removeClass('done').html(iconCode.mail);
});
$subscriberBtn.click(function() {
var email = $.trim($subscriberBox.val());
if (email !== '' && emailReg.test(email)) {
$.extend(params, subscribeParam, {
email: email,
tmp: Math.random(),
uid: $.uid('_UID')
});
try {
$.getJSON('http://test.open.yohobuy.com' + '/?callback=?', params, function(data) {
if (data.data.result === 1) {
$subscriberBox.val('已订阅到:' + email);
$subscriberBtn.addClass('done').html(iconCode.tick);
} else {
$subscriberBox.css('color', 'red');
$.ajax({
url: 'http://www.yohobuy.com/common/emailsubscriber',
dataType: 'jsonp',
data: {
email: email,
tmp: Math.random(),
uid: window.getUid()
},
success: function(data) {
if (data.data.result === 1) {
$subscriberBox.val('已订阅到:' + email);
$subscriberBtn.addClass('done').html(iconCode.tick);
} else {
$subscriberBox.css('color', 'red');
}
}
});
} catch (e) {
... ... @@ -241,7 +234,6 @@ function actionhomeFootChange() {
var $this = $(this),
$li = $this.closest('li'),
index = $li.index(),
params = {},
_solution = [];
var _answer = $li.find('.feedback-answer').val(),
... ... @@ -252,28 +244,30 @@ function actionhomeFootChange() {
_solution.push($(this).val());
});
params = {
method: 'open.feedback.submit',
feedback: _feedback || 0,
question: _question || 0,
answer: _answer || '',
solution: _solution.join(',')
};
$.ajax({
url: 'http://www.yohobuy.com/common/suggestfeedback',
dataType: 'jsonp',
data: {
feedback_id: _feedback || 0,
question_id: _question || 0,
answer: _answer || '',
solution: _solution.join(',')
},
success: function(data) {
var next = index + 1;
if (~~data.data.result === 1) {
if (index === count - 1) {
alert('感谢您的参与!');
return;
}
$.getData(apiDomain, params, function(data) {
var next = index + 1;
$li.addClass('hide');
if (data.result === 1) {
if (index === count - 1) {
alert('感谢您的参与!');
return;
$vote.children(':eq(' + (index + 1) + ')').removeClass('hide');
$feedBackPage.children('.cur').removeClass('cur');
$feedBackPage.children(':eq(' + next + ')').addClass('cur');
}
$li.addClass('hide');
$vote.eq(index + 1).removeClass('hide');
$feedBackPage.children('.cur').removeClass('cur');
$feedBackPage.eq(next).addClass('cur');
}
});
});
... ... @@ -338,7 +332,7 @@ var handlebars = require("handlebars");
var json2 = require("index");
var vipInfoCombine = null; //用户信息编译模板
var loginInfoCombine = null; //登录信息编译模板
var apiDomain = 'http://api.open.yohobuy.com'; //获取数据的地址
var apiDomain = 'http://test.open.yohobuy.com/'; //获取数据的地址http://api.open.yohobuy.com
var cartTpl = ''; //购物车模板
/**
* 搜寻的时候过滤非法字符(+-/:等非法字符单独出现)
... ... @@ -405,7 +399,8 @@ function getSource(column, postition, event) {
} catch (e) {}
}
function submitSearch() {
window.submitSearch = function() {
var $keywordinput = $('#query_key').val();
var column = 'Search';
var postition = 'Head Search';
... ... @@ -427,6 +422,7 @@ function submitSearch() {
}
}
}
/**
* 定义购物车扩展
*/
... ... @@ -486,7 +482,7 @@ function actionGoodsCart() {
}, function() {
$(this).css('background-color', '#fff');
});
}, 'json');
}, 'jsonp');
}
function getText(obj) {
... ... @@ -515,7 +511,7 @@ function actionGoodsCart() {
listIndex = (listIndex + 1) % queryNum;
getText(this);
} else if (event.which === 13) {
submitSearch();
window.submitSearch();
} else {
getKeywords(this);
}
... ... @@ -535,13 +531,11 @@ function actionGoodsCart() {
var params = '';
if (typeof (domain) === undefined || domain === '') {
console.log('请设置请求的api地址');
return false;
}
params = $.extend(defaults, options);
params.page = params.page || 1;
if (params.method === '') {
console.log('请设置请求的URL');
return false;
}
try {
... ... @@ -1082,7 +1076,8 @@ function actionTipPic() {
function closeCover(){
function closeCover() {
var $cover = $('#cover');
$cover.remove();
... ... @@ -1093,58 +1088,97 @@ function closeCover(){
*/
function actionCover() {
var gender = cookieMap._Gender;
var newMask = '';
var windowheight = '';
var selfheight = '';
var containertop;
var length = '';
setCookie('_Channel','boys',{path : '/',domain : '.yohobuy.com',expires : 7});
if(typeof gender == 'undefined' || gender == '' || gender == null){
$.get('http://www.yohobuy.com/index/guide', function(data){
var newMask = document.createElement("div");
window.setCookie('_Channel', 'boys', {
path: '/',
domain: '.yohobuy.com',
expires: 7
});
if (typeof gender === 'undefined' || gender === '' || gender === null) {
$.get('http://www.yohobuy.com/index/guide', function(data) {
newMask = document.createElement('div');
newMask.id = 'cover';
newMask.innerHTML=data;
newMask.innerHTML = data;
document.body.appendChild(newMask);
var window_height = $(window).height();
var self_height = $('.guide-box').height();
var container_top = window_height / 2 - self_height / 2;
var length=$('.guide-box .clear').find("li").length;
windowheight = $(window).height();
selfheight = $('.guide-box').height();
containertop = windowheight / 2 - selfheight / 2;
length = $('.guide-box .clear').find('li').length;
$('.guide-box').css({
width: (200 * length) + 'px',
top: container_top + 'px'
top: containertop + 'px'
});
$('#cover').bind('click', function(event){
setCookie('_Gender','1,3',{path : '/',domain : '.yohobuy.com',expires : 90});
setCookie('_Channel','boys',{path : '/',domain : '.yohobuy.com',expires : 7});
closeCover();
$('#cover').bind('click', function(event) {
window.setCookie('_Gender', '1,3', {
path: '/',
domain: '.yohobuy.com',
expires: 90
});
window.setCookie('_Channel', 'boys', {
path: '/',
domain: '.yohobuy.com',
expires: 7
});
closeCover();
});
$('#cover .guide-box .close').bind('click', function(event){
getSource('弹窗','CLOSE','homepage_man');
setCookie('_Gender','1,3',{path : '/',domain : '.yohobuy.com',expires : 90});
setCookie('_Channel','boys',{path : '/',domain : '.yohobuy.com',expires : 7});
analy('guide_close');
closeCover();
$('#cover .guide-box .close').bind('click', function(event) {
getSource('弹窗', 'CLOSE', 'homepage_man');
window.setCookie('_Gender', '1,3', {
path: '/',
domain: '.yohobuy.com',
expires: 90
});
window.setCookie('_Channel', 'boys', {
path: '/',
domain: '.yohobuy.com',
expires: 7
});
closeCover();
});
$('.boys img , .boys .go').bind('click', function(event){
getSource('弹窗','BOYS','homepage_man');
setCookie('_Gender','1,3',{path : '/',domain : '.yohobuy.com',expires : 90});
setCookie('_Channel','boys',{path : '/',domain : '.yohobuy.com',expires : 7});
analy( 'guide_boys');
closeCover();
$('.boys img , .boys .go').bind('click', function(event) {
getSource('弹窗', 'BOYS', 'homepage_man');
window.setCookie('_Gender', '1,3', {
path: '/',
domain: '.yohobuy.com',
expires: 90
});
window.setCookie('_Channel', 'boys', {
path: '/',
domain: '.yohobuy.com',
expires: 7
});
closeCover();
});
$('.girls img, .girls .go').bind('click', function(event){
getSource('弹窗','GIRLS','homepage_woman');
setCookie('_Gender','2,3',{path : '/',domain : '.yohobuy.com',expires : 90});
setCookie('_Channel','girls',{path : '/',domain : '.yohobuy.com',expires : 7});
analy( 'guide_girls');
$('.girls img, .girls .go').bind('click', function(event) {
getSource('弹窗', 'GIRLS', 'homepage_woman');
window.setCookie('_Gender', '2,3', {
path: '/',
domain: '.yohobuy.com',
expires: 90
});
window.setCookie('_Channel', 'girls', {
path: '/',
domain: '.yohobuy.com',
expires: 7
});
});
$('.lifestyle img, .lifestyle .go').bind('click', function(event){
setCookie('_Channel','lifestyle',{path : '/',domain : '.yohobuy.com',expires : 7});
getSource('弹窗','LIEFSTYLE','homepage_lifestyle');
analy( 'guide_lifestyle');
$('.lifestyle img, .lifestyle .go').bind('click', function(event) {
window.setCookie('_Channel', 'lifestyle', {
path: '/',
domain: '.yohobuy.com',
expires: 7
});
getSource('弹窗', 'LIEFSTYLE', 'homepage_lifestyle');
});
//防止冒泡事件
$('#cover .guide-box').bind('click', function(event){
$('#cover .guide-box').bind('click', function(event) {
event.stopPropagation();
});
});
});
}
}
/**
... ... @@ -1774,8 +1808,7 @@ function init() {
actionCover(); //初次登录弹框
}
init();
init();
});
define("js/product/entry", ["jquery","handlebars","source-map","lazyload"], function(require, exports, module){
/**
... ... @@ -1799,358 +1832,367 @@ require("js/product/filter");
require("js/product/sort-pager");
require("js/product/latest-walk");
require("js/product/product");
});
define("js/product/filter", ["jquery","handlebars","source-map"], function(require, exports, module){
/**
* 商品筛选逻辑
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/12/4
*/
var $ = require("jquery"),
Handlebars = require("handlebars");
var checkUnicode = {
unchecked: '&#xe613;',
checked: '&#xe612;'
},
moreUnicode = {
up: '&#xe610;',
down: '&#xe600;'
};
//品牌相关变量
var $brandDefault = $('.brand .default'),
$brandPanel = $('.brand .brand-panel'),
$brandAttrs = $brandPanel.find('.attr'),
$brandMore = $('#brand-more'),
$brandMulti = $('#brand-multi');
var $brandMoreTxt, $brandMoreIcon;
//价格相关变量
var $udPrice = $('.ud-price-range'),
interReg = /^\d+$/,
$limit, $min, $max, $btn;
//分类相关变量
var $sortSub = $('.sort-sub-wrap');
//高级选项相关变量
var $seniorSubWrap = $('.senior-sub-wrap'),
$seniorAttrWrap = $('.senior-attr-wrap');
var seniorHoverTime, hoveredIndex;
// 尺寸 handlebars 模板
var sizeTmpl = '{{# size}}<a class="attr {{#if checked}}checked{{/if}}" href="{{href}}">{{name}}</a>{{/ size}}',
sizeCache = {}, // 缓存一下尺寸信息
$sizeWrap = $('.filter-box .size');
sizeTmpl = Handlebars.compile(sizeTmpl);
//清除checkbox选中状态
function clearChecked($checkbox) {
$checkbox.removeClass('checked').html(checkUnicode.unchecked);
}
//显示更多品牌面板
function brandShowMore() {
$brandDefault.addClass('hide');
$brandPanel.removeClass('hide');
}
//隐藏更多品牌面板
function brandHideMore() {
$brandPanel.addClass('hide');
$brandDefault.removeClass('hide');
}
//url构造&跳转
function uriLoc(attr, val) {
var href = decodeURIComponent(window.location.search),
query = attr + '=' + val,
newHref;
if (href === '') {
newHref = '?' + query;
} else {
newHref = href + '&' + query;
}
window.location.href = newHref;
}
//隐藏高级选项面板
function hideSeniorPanel(index) {
$seniorSubWrap.children('.senior-sub:eq(' + hoveredIndex + ')').addClass('hide');
$seniorAttrWrap.children('.attr:eq(' + hoveredIndex + ')').removeClass('hover');
hoveredIndex = -1;
}
//屏蔽筛选项双击文字选中
$('.filter-box').on('selectstart', '.attr, .brands-index span', function() {
return false;
});
//【分类】
$('.sort-pre').on('click', 'li', function() {
var $this = $(this),
index = $this.index(),
id = $this.data('id');
if ($this.hasClass('active')) {
// 选中时,再次点击取消选中
$this.removeClass('active');
$sortSub.children(':eq(' + index + ')').addClass('hide');
$sizeWrap.addClass('hide');
return;
}
$this.siblings('.active').removeClass('active');
$this.addClass('active');
$sortSub.children(':not(.hide)').addClass('hide');
$sortSub.children(':eq(' + index + ')').removeClass('hide');
if (sizeCache[id]) {
$sizeWrap.find('.attr-content').html(sizeCache[id]);
$sizeWrap.removeClass('hide');
} else {
$.ajax({
url: '/product/search/sortSize',
data: {
msort: id
}
}).then(function(res) {
if ($.type(res) === 'array' && res.length) {
sizeCache[id] = sizeTmpl({
size: res
});
$sizeWrap.find('.attr-content').html(sizeCache[id]);
$sizeWrap.removeClass('hide');
} else {
$sizeWrap.addClass('hide');
}
});
}
});
//【品牌】
if ($brandMore.length > 0) {
$brandMoreTxt = $brandMore.children('em');
$brandMoreIcon = $brandMore.children('.iconfont');
}
//【品牌】多选
$brandMulti.click(function() {
if ($brandPanel.css('display') === 'none') {
//显示品牌面板
$brandMore.trigger('click');
}
$brandPanel.addClass('multi'); //显示出checkbox
$(this).addClass('hide');
});
//【品牌】更多
$brandMore.click(function() {
var $this = $(this);
if ($this.hasClass('more')) {
brandHideMore();
$brandMoreTxt.text('更多');
$brandMoreIcon.html(moreUnicode.down);
} else {
brandShowMore();
$brandMoreTxt.text('收起');
$brandMoreIcon.html(moreUnicode.up);
}
$(this).toggleClass('more');
});
//【品牌】索引
$('.brands-index').on('mouseenter', 'span', function() {
var $this = $(this),
index = $this.data('index');
if ($this.hasClass('hover')) {
return;
}
$this.siblings('span.hover').removeClass('hover');
$this.addClass('hover');
if ($this.index() === 0) {
//全部
$brandAttrs.removeClass('hide');
} else {
$brandAttrs.addClass('hide').filter('[data-index=' + index + ']').removeClass('hide');
}
});
//【品牌】搜索
$('#brand-search-input').keyup(function() {
var val = $(this).val().toLowerCase();
if (val === '') {
$brandAttrs.removeClass('hide');
} else {
$brandAttrs.addClass('hide').filter('[data-key*="' + val + '"]').removeClass('hide');
}
});
//【品牌】多选确定
$('#brand-multi-ok').click(function() {
var val = '';
if ($(this).hasClass('dis')) {
return;
}
$brandPanel.find('.checked').each(function() {
var id = $(this).data('id');
val += (val === '') ? id : (',' + id);
});
uriLoc('brand', val);
});
//【品牌/高级选项】多选取消
$('.multi-select-cancel').click(function() {
var $panel = $(this).closest('.multi');
if ($panel.hasClass('brand-panel')) {
$brandMulti.removeClass('hide'); //显示多选按钮
$brandMore.trigger('click');
}
$panel.removeClass('multi');
clearChecked($panel.find('.checkbox.checked')); //清除选中状态
});
//【品牌/高级选项】checkbox
$('.check-container').on('click', '.attr', function() {
var $this = $(this),
$check = $this.find('.checkbox'),
$btnOk = $this.closest('.brand-panel, .senior-sub').find('.multi-select-ok');
$check.toggleClass('checked');
if ($check.hasClass('checked')) {
$check.html(checkUnicode.checked);
} else {
$check.html(checkUnicode.unchecked);
}
//更新按钮状态
if ($check.hasClass('checked') ||
$this.siblings('.attr').find('.checked').length > 0) {
$btnOk.removeClass('dis');
} else {
$btnOk.addClass('dis');
}
});
//【品牌/高级选项】当多选时阻止链接默认跳转
$('.brand, .senior').on('click', '.attr > a', function(e) {
if ($(this).closest('.multi').length > 0) {
e.preventDefault();
}
});
//【价格】用户定义价格处理
if ($udPrice.length > 0) {
$limit = $udPrice.find('.limit');
$min = $limit.filter('.min');
$max = $limit.filter('.max');
$btn = $udPrice.find('.price-sure');
//【价格】输入
$limit.keyup(function() {
var min = $.trim($min.val()),
max = $.trim($max.val()),
isMinInt = interReg.test(min),
isMaxInt = interReg.test(max);
if (isMaxInt && (min === '' || isMinInt) ||
isMinInt && (max === '' || isMaxInt)
) {
$btn.removeClass('hide');
} else {
$btn.addClass('hide');
}
});
//【价格】多项查询
$btn.click(function() {
var min = $.trim($min.val()),
max = $.trim($max.val()),
tmp;
//对于min大于max的情况,交换位置
if (min !== '' && max !== '' && +min > +max) {
tmp = max;
max = min;
min = tmp;
}
uriLoc('price', min + ',' + max);
});
}
//【高级选项】鼠标移入显示子项
$seniorAttrWrap.on('mouseenter', '.attr', function() {
var $this = $(this);
var index = $this.index();
$this.addClass('hover').siblings().removeClass('hover');
$seniorSubWrap.children('.senior-sub:eq(' + index + ')').removeClass('hide').siblings().addClass('hide');
}).on('mouseleave', '.attr', function() {
var $this = $(this),
index = $this.index();
hoveredIndex = index;
seniorHoverTime = setTimeout(function() {
hideSeniorPanel();
}, 100);
});
//【高级选项】多选
$('.senior-sub').on('click', '.multi-select', function() {
$(this).closest('.senior-sub').addClass('multi');
}).on('click', '.multi-select-ok', function() {
var $btn = $(this),
$sub = $btn.closest('.senior-sub'),
val = '';
if ($btn.hasClass('dis')) {
return;
}
$sub.find('.checked').each(function() {
var id = $(this).data('id');
val += (val === '') ? id : (',' + id);
});
uriLoc($sub.data('attr'), val);
}).on('mouseenter', function() {
clearTimeout(seniorHoverTime);
}).on('mouseleave', function() {
hideSeniorPanel();
});
/**
* 商品筛选逻辑
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/12/4
*/
var $ = require("jquery"),
Handlebars = require("handlebars");
var checkUnicode = {
unchecked: '&#xe613;',
checked: '&#xe612;'
},
moreUnicode = {
up: '&#xe610;',
down: '&#xe600;'
};
//品牌相关变量
var $brandDefault = $('.brand .default'),
$brandPanel = $('.brand .brand-panel'),
$brandAttrs = $brandPanel.find('.attr'),
$brandMore = $('#brand-more'),
$brandMulti = $('#brand-multi');
var $brandMoreTxt, $brandMoreIcon;
//价格相关变量
var $udPrice = $('.ud-price-range'),
interReg = /^\d+$/,
$limit, $min, $max, $btn;
//分类相关变量
var $sortSub = $('.sort-sub-wrap');
//高级选项相关变量
var $seniorSubWrap = $('.senior-sub-wrap'),
$seniorAttrWrap = $('.senior-attr-wrap');
var seniorHoverTime, hoveredIndex;
// 尺寸 handlebars 模板
var sizeTmpl = '{{# size}}<a class="attr {{#if checked}}checked{{/if}}" href="{{href}}">{{name}}</a>{{/ size}}',
sizeCache = {}, // 缓存一下尺寸信息
$sizeWrap = $('.filter-box .size');
sizeTmpl = Handlebars.compile(sizeTmpl);
//清除checkbox选中状态
function clearChecked($checkbox) {
$checkbox.removeClass('checked').html(checkUnicode.unchecked);
}
//显示更多品牌面板
function brandShowMore() {
$brandDefault.addClass('hide');
$brandPanel.removeClass('hide');
}
//隐藏更多品牌面板
function brandHideMore() {
$brandPanel.addClass('hide');
$brandDefault.removeClass('hide');
}
//url构造&跳转
function uriLoc(attr, val) {
var href = decodeURIComponent(window.location.search),
query = attr + '=' + val,
newHref;
if (href === '') {
newHref = '?' + query;
} else {
newHref = href + '&' + query;
}
window.location.href = newHref;
}
//隐藏高级选项面板
function hideSeniorPanel(index) {
$seniorSubWrap.children('.senior-sub:eq(' + hoveredIndex + ')').addClass('hide');
$seniorAttrWrap.children('.attr:eq(' + hoveredIndex + ')').removeClass('hover');
hoveredIndex = -1;
}
//屏蔽筛选项双击文字选中
$('.filter-box').on('selectstart', '.attr, .brands-index span', function() {
return false;
});
//【分类】
$('.sort-pre').on('click', 'li', function() {
var $this = $(this),
index = $this.index(),
id = $this.data('id');
if ($this.hasClass('active')) {
// 选中时,再次点击取消选中
$this.removeClass('active');
$sortSub.children(':eq(' + index + ')').addClass('hide');
$sizeWrap.addClass('hide');
return;
}
$this.siblings('.active').removeClass('active');
$this.addClass('active');
$sortSub.children(':not(.hide)').addClass('hide');
$sortSub.children(':eq(' + index + ')').removeClass('hide');
if (sizeCache[id]) {
$sizeWrap.find('.attr-content').html(sizeCache[id]);
$sizeWrap.removeClass('hide');
} else {
$.ajax({
url: '/product/search/sortSize',
data: {
msort: id
}
}).then(function(res) {
if ($.type(res) === 'array' && res.length) {
sizeCache[id] = sizeTmpl({
size: res
});
$sizeWrap.find('.attr-content').html(sizeCache[id]);
$sizeWrap.removeClass('hide');
} else {
$sizeWrap.addClass('hide');
}
});
}
});
//【品牌】
if ($brandMore.length > 0) {
$brandMoreTxt = $brandMore.children('em');
$brandMoreIcon = $brandMore.children('.iconfont');
}
//【品牌】多选
$brandMulti.click(function() {
if ($brandPanel.css('display') === 'none') {
//显示品牌面板
$brandMore.trigger('click');
}
$brandPanel.addClass('multi'); //显示出checkbox
$(this).addClass('hide');
});
//【品牌】更多
$brandMore.click(function() {
var $this = $(this);
if ($this.hasClass('more')) {
brandHideMore();
$brandMoreTxt.text('更多');
$brandMoreIcon.html(moreUnicode.down);
} else {
brandShowMore();
$brandMoreTxt.text('收起');
$brandMoreIcon.html(moreUnicode.up);
}
$(this).toggleClass('more');
});
//【品牌】索引
$('.brands-index').on('mouseenter', 'span', function() {
var $this = $(this),
index = $this.data('index');
if ($this.hasClass('hover')) {
return;
}
$this.siblings('span.hover').removeClass('hover');
$this.addClass('hover');
if ($this.index() === 0) {
//全部
$brandAttrs.removeClass('hide');
} else {
$brandAttrs.addClass('hide').filter('[data-index=' + index + ']').removeClass('hide');
}
});
//【品牌】搜索
$('#brand-search-input').keyup(function() {
var val = $(this).val().toLowerCase();
if (val === '') {
$brandAttrs.removeClass('hide');
} else {
$brandAttrs.addClass('hide').filter('[data-key*="' + val + '"]').removeClass('hide');
}
});
//【品牌】多选确定
$('#brand-multi-ok').click(function() {
var val = '';
if ($(this).hasClass('dis')) {
return;
}
$brandPanel.find('.checked').each(function() {
var id = $(this).data('id');
val += (val === '') ? id : (',' + id);
});
uriLoc('brand', val);
});
//【品牌/高级选项】多选取消
$('.multi-select-cancel').click(function() {
var $panel = $(this).closest('.multi');
if ($panel.hasClass('brand-panel')) {
$brandMulti.removeClass('hide'); //显示多选按钮
$brandMore.trigger('click');
}
$panel.removeClass('multi');
clearChecked($panel.find('.checkbox.checked')); //清除选中状态
});
//【品牌/高级选项】checkbox
$('.check-container').on('click', '.attr', function() {
var $this = $(this),
$check = $this.find('.checkbox'),
$btnOk = $this.closest('.brand-panel, .senior-sub').find('.multi-select-ok');
$check.toggleClass('checked');
if ($check.hasClass('checked')) {
$check.html(checkUnicode.checked);
} else {
$check.html(checkUnicode.unchecked);
}
//更新按钮状态
if ($check.hasClass('checked') ||
$this.siblings('.attr').find('.checked').length > 0) {
$btnOk.removeClass('dis');
} else {
$btnOk.addClass('dis');
}
});
//【品牌/高级选项】当多选时阻止链接默认跳转
$('.brand, .senior').on('click', '.attr > a', function(e) {
if ($(this).closest('.multi').length > 0) {
e.preventDefault();
}
});
//【价格】用户定义价格处理
if ($udPrice.length > 0) {
$limit = $udPrice.find('.limit');
$min = $limit.filter('.min');
$max = $limit.filter('.max');
$btn = $udPrice.find('.price-sure');
//【价格】输入
$limit.keyup(function() {
var min = $.trim($min.val()),
max = $.trim($max.val()),
isMinInt = interReg.test(min),
isMaxInt = interReg.test(max);
if (isMaxInt && (min === '' || isMinInt) ||
isMinInt && (max === '' || isMaxInt)
) {
$btn.removeClass('hide');
} else {
$btn.addClass('hide');
}
});
//【价格】多项查询
$btn.click(function() {
var min = $.trim($min.val()),
max = $.trim($max.val()),
tmp;
//对于min大于max的情况,交换位置
if (min !== '' && max !== '' && +min > +max) {
tmp = max;
max = min;
min = tmp;
}
uriLoc('price', min + ',' + max);
});
}
//【高级选项】鼠标移入显示子项
$seniorAttrWrap.on('mouseenter', '.attr', function() {
var $this = $(this);
var index = $this.index();
if ($this.hasClass('no-sub')) {
return;
}
$this.addClass('hover').siblings().removeClass('hover');
$seniorSubWrap.children('.senior-sub:eq(' + index + ')').removeClass('hide').siblings().addClass('hide');
}).on('mouseleave', '.attr', function() {
var $this = $(this),
index = $this.index();
if ($this.hasClass('no-sub')) {
return;
}
hoveredIndex = index;
seniorHoverTime = setTimeout(function() {
hideSeniorPanel();
}, 100);
});
//【高级选项】多选
$('.senior-sub').on('click', '.multi-select', function() {
$(this).closest('.senior-sub').addClass('multi');
}).on('click', '.multi-select-ok', function() {
var $btn = $(this),
$sub = $btn.closest('.senior-sub'),
val = '';
if ($btn.hasClass('dis')) {
return;
}
$sub.find('.checked').each(function() {
var id = $(this).data('id');
val += (val === '') ? id : (',' + id);
});
uriLoc($sub.data('attr'), val);
}).on('mouseenter', function() {
clearTimeout(seniorHoverTime);
}).on('mouseleave', function() {
hideSeniorPanel();
});
});
define("js/product/sort-pager", ["jquery"], function(require, exports, module){
... ... @@ -2183,6 +2225,65 @@ $countPerPage.click(function() {
}
});
});
define("js/product/latest-walk", ["jquery","handlebars","source-map","lazyload"], function(require, exports, module){
/**
* 最近浏览取接口渲染模板
* @author: xuqi<qi.xu@yoho.cn>
8 @date: 2016/1/20
*/
var $ = require("jquery");
var Handlebars = require("handlebars");
var lazyLoad = require("lazyload");
var $latestWalkCount = $('#latest-walk-count');
(function() {
var tpl;
if ($latestWalkCount.lenght < 0) {
return;
}
tpl = Handlebars.compile($('#latest-walk-tpl').html());
$.ajax({
url: 'http://itemapi.yohobuy.com/item/item/recentreview',
dataType: 'jsonp',
data: {
limit: $latestWalkCount.val()
},
success: function(data) {
var latestWalk = [],
res, i, cur;
if (data.code === 200) {
res = data.data;
for (i = 0; i < res.length; i++) {
cur = res[i];
latestWalk.push({
href: cur.url,
img: cur.pic_url,
name: cur.product_name,
salePrice: cur.price,
marketPrice: cur.market_price
});
}
if (latestWalk.length > 0) {
$('#latest-walk-goods').html(tpl({
latestWalk: latestWalk
}));
lazyLoad($('#latest-walk-goods .lazy'));
}
}
}
});
}());
});
define("js/product/product", ["jquery","lazyload"], function(require, exports, module){
/**
*Description: 商品列表页
... ... @@ -5744,11 +5845,10 @@ var $sc = $('#send-captcha'),
itime;
$sc.click(function() {
$.post('/passport/register/authcode', {
$.post('/passport/back/sendbackmobile', {
mobile: $('#mobile').val(),
area: $('#area').val(),
captcha: $('#captchaPic').val(),
project: 'repassword'
verifyCode: $('#captchaPic').val()
}, function(jsonData) {
if (jsonData.code === 200) {
$errTip.hide();
... ... @@ -5802,17 +5902,34 @@ itime = setInterval(function() {
$('#captcha').keyup(function() {
var v = $.trim($(this).val());
if (v !== '') {
var v = $.trim($(this).val()),
that = this;
//添加验证码正确验证
//$next.removeClass('disable').prop('disabled', false);
$next.removeClass('disable').removeAttr('disabled');
} else {
if (v.length === 4) {
$.ajax({
type: 'POST',
url: '/passport/back/backmobile',
dataType: 'json',
data: {
code: $('#captcha').val(),
verifyCode: $("#captchaPic").val(),
area: $('#area').val(),
mobile: $('#mobile').val()
},
success: function(res) {
if (res.code === 200) {
//$next.addClass('disable').prop('disabled', true);
$next.addClass('disable').attr('disabled', true);
//添加验证码正确验证
$next.removeClass('disable').removeAttr('disabled');
$errTip.addClass('hide');
$(that).removeClass('error');
} else {
$next.addClass('disable').attr('disabled', true);
$errTip.removeClass('hide').find('em').text('验证码输入错误');
$(that).addClass('error');
}
}
});
}
}).blur(function() {
var v = $.trim($(this).val());
... ... @@ -5821,10 +5938,7 @@ $('#captcha').keyup(function() {
//添加验证码正确验证
$(this).addClass('error');
$errTip.removeClass('hide');
} else {
$(this).removeClass('error');
$errTip.addClass('hide');
$errTip.removeClass('hide').text('请输入验证码');
}
}).focus(function() {
$(this).removeClass('error');
... ...
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
... ... @@ -8,7 +8,7 @@ var handlebars = require('yoho.handlebars');
var json2 = require('json2');
var vipInfoCombine = null; //用户信息编译模板
var loginInfoCombine = null; //登录信息编译模板
var apiDomain = 'http://api.open.yohobuy.com'; //获取数据的地址
var apiDomain = 'http://test.open.yohobuy.com/'; //获取数据的地址http://api.open.yohobuy.com
var cartTpl = ''; //购物车模板
/**
* 搜寻的时候过滤非法字符(+-/:等非法字符单独出现)
... ... @@ -75,7 +75,8 @@ function getSource(column, postition, event) {
} catch (e) {}
}
function submitSearch() {
window.submitSearch = function() {
var $keywordinput = $('#query_key').val();
var column = 'Search';
var postition = 'Head Search';
... ... @@ -97,6 +98,7 @@ function submitSearch() {
}
}
}
/**
* 定义购物车扩展
*/
... ... @@ -185,7 +187,7 @@ function actionGoodsCart() {
listIndex = (listIndex + 1) % queryNum;
getText(this);
} else if (event.which === 13) {
submitSearch();
window.submitSearch();
} else {
getKeywords(this);
}
... ...
... ... @@ -14,11 +14,10 @@ var $sc = $('#send-captcha'),
itime;
$sc.click(function() {
$.post('/passport/register/authcode', {
$.post('/passport/back/sendbackmobile', {
mobile: $('#mobile').val(),
area: $('#area').val(),
captcha: $('#captchaPic').val(),
project: 'repassword'
verifyCode: $('#captchaPic').val()
}, function(jsonData) {
if (jsonData.code === 200) {
$errTip.hide();
... ... @@ -72,17 +71,34 @@ itime = setInterval(function() {
$('#captcha').keyup(function() {
var v = $.trim($(this).val());
if (v !== '') {
//添加验证码正确验证
//$next.removeClass('disable').prop('disabled', false);
$next.removeClass('disable').removeAttr('disabled');
} else {
//$next.addClass('disable').prop('disabled', true);
$next.addClass('disable').attr('disabled', true);
var v = $.trim($(this).val()),
that = this;
if (v.length === 4) {
$.ajax({
type: 'POST',
url: '/passport/back/backmobile',
dataType: 'json',
data: {
code: $('#captcha').val(),
verifyCode: $("#captchaPic").val(),
area: $('#area').val(),
mobile: $('#mobile').val()
},
success: function(res) {
if (res.code === 200) {
//添加验证码正确验证
$next.removeClass('disable').removeAttr('disabled');
$errTip.addClass('hide');
$(that).removeClass('error');
} else {
$next.addClass('disable').attr('disabled', true);
$errTip.removeClass('hide').find('em').text('验证码输入错误');
$(that).addClass('error');
}
}
});
}
}).blur(function() {
var v = $.trim($(this).val());
... ... @@ -91,10 +107,7 @@ $('#captcha').keyup(function() {
//添加验证码正确验证
$(this).addClass('error');
$errTip.removeClass('hide');
} else {
$(this).removeClass('error');
$errTip.addClass('hide');
$errTip.removeClass('hide').text('请输入验证码');
}
}).focus(function() {
$(this).removeClass('error');
... ...
... ... @@ -309,6 +309,9 @@ $seniorAttrWrap.on('mouseenter', '.attr', function() {
var $this = $(this);
var index = $this.index();
if ($this.hasClass('no-sub')) {
return;
}
$this.addClass('hover').siblings().removeClass('hover');
$seniorSubWrap.children('.senior-sub:eq(' + index + ')').removeClass('hide').siblings().addClass('hide');
... ... @@ -316,6 +319,10 @@ $seniorAttrWrap.on('mouseenter', '.attr', function() {
var $this = $(this),
index = $this.index();
if ($this.hasClass('no-sub')) {
return;
}
hoveredIndex = index;
seniorHoverTime = setTimeout(function() {
... ...
/**
* 最近浏览取接口渲染模板
* @author: xuqi<qi.xu@yoho.cn>
8 @date: 2016/1/20
*/
var $ = require('yoho.jquery');
var Handlebars = require('yoho.handlebars');
var lazyLoad = require('yoho.lazyload');
var $latestWalkCount = $('#latest-walk-count');
(function() {
var tpl;
if ($latestWalkCount.lenght < 0) {
return;
}
tpl = Handlebars.compile($('#latest-walk-tpl').html());
$.ajax({
url: 'http://itemapi.yohobuy.com/item/item/recentreview',
dataType: 'jsonp',
data: {
limit: $latestWalkCount.val()
},
success: function(data) {
var latestWalk = [],
res, i, cur;
if (data.code === 200) {
res = data.data;
for (i = 0; i < res.length; i++) {
cur = res[i];
latestWalk.push({
href: cur.url,
img: cur.pic_url,
name: cur.product_name,
salePrice: cur.price,
marketPrice: cur.market_price
});
}
if (latestWalk.length > 0) {
$('#latest-walk-goods').html(tpl({
latestWalk: latestWalk
}));
lazyLoad($('#latest-walk-goods .lazy'));
}
}
}
});
}());
\ No newline at end of file
... ...
... ... @@ -8,4 +8,6 @@ require('./filter');
require('./sort-pager');
require('./latest-walk');
require('./product');
\ No newline at end of file
... ...
... ... @@ -386,6 +386,10 @@
}
}
.promise .left {
margin-right: 45px;
}
.subscribe {
width: 200px;
... ...
... ... @@ -161,187 +161,227 @@
background-color: #f5f5f5;
color: #6d6d6d;
margin-bottom: 10px;
}
.sale-nav li.active {
color: #fff;
background-repeat: no-repeat;
background-size: 100% 100%;
}
.sale-nav li.green.active {
color: #fff;
background-image: image-url('sale/navactive-green-middle.png');
background-repeat: no-repeat;
background-size: 100% 100%;
}
.sale-nav li.green.first.active {
background-image: image-url('sale/navactive-green-first.png');
}
.sale-nav li.green.last.active {
background-image: image-url('sale/navactive-green-last.png');
}
.sale-nav li.yellow.active {
color: #fff;
background-image: image-url('sale/navactive-yellow-middle.png');
background-repeat: no-repeat;
background-size: 100% 100%;
}
.sale-nav li.yellow.first.active {
background-image: image-url('sale/navactive-yellow-first.png');
}
.sale-nav li.yellow.last.active {
background-image: image-url('sale/navactive-yellow-last.png');
}
.sale-nav li.red.active {
color: #fff;
background-image: image-url('sale/navactive-red-middle.png');
background-repeat: no-repeat;
background-size: 100% 100%;
}
.sale-nav li.red.first.active {
background-image: image-url('sale/navactive-red-first.png');
}
.sale-nav li.red.last.active {
background-image: image-url('sale/navactive-red-last.png');
&.active {
color: #fff;
background-repeat: no-repeat;
background-size: 100% 100%;
}
&.green {
&.active {
color: #fff;
background-image: image-url("sale/navactive-green-middle.png");
background-repeat: no-repeat;
background-size: 100% 100%;
}
&.first.active {
background-image: image-url("sale/navactive-green-first.png");
}
&.last.active {
background-image: image-url("sale/navactive-green-last.png");
}
}
&.yellow {
&.active {
color: #fff;
background-image: image-url("sale/navactive-yellow-middle.png");
background-repeat: no-repeat;
background-size: 100% 100%;
}
&.first.active {
background-image: image-url("sale/navactive-yellow-first.png");
}
&.last.active {
background-image: image-url("sale/navactive-yellow-last.png");
}
}
&.red {
&.active {
color: #fff;
background-image: image-url("sale/navactive-red-middle.png");
background-repeat: no-repeat;
background-size: 100% 100%;
}
&.first.active {
background-image: image-url("sale/navactive-red-first.png");
}
&.last.active {
background-image: image-url("sale/navactive-red-last.png");
}
}
}
@media screen and (min-width: 1150px) {
.floor-header {
margin:80px 0 40px
}
.floor-header .header-navs li {
padding: 1px 15px
margin: 80px 0 40px;
.header-navs li {
padding: 1px 15px;
}
}
}
.commodity-list ul {
width: 1004px
width: 1004px;
}
.commodity-item {
float: left;
width: 241px;
margin: 0 10px 0 0
margin: 0 10px 0 0;
}
.commodity-img {
position: relative;
height: 323px;
text-align: center
}
.commodity-img img {
width: 100%;
height: 100%;
vertical-align: middle
}
.commodity-img .top-tag {
position: absolute;
width: 60px;
height: 60px;
top: 10px;
right: 10px;
line-height: 60px;
background: url('../assets/images/furniture/top-tag-bg.png?1450667948');
font-size: 20px;
color: #fff
}
.commodity-img .few-tag {
position: absolute;
bottom: 0;
width: 100%;
height: 20px;
background: #ffac5b;
color: #fff;
line-height: 20px;
text-align: center;
font-size: 12px
img {
width: 100%;
height: 100%;
vertical-align: middle;
}
.top-tag {
position: absolute;
width: 60px;
height: 60px;
top: 10px;
right: 10px;
line-height: 60px;
background: url('../assets/images/furniture/top-tag-bg.png?1450667948');
font-size: 20px;
color: #fff;
}
.few-tag {
position: absolute;
bottom: 0;
width: 100%;
height: 20px;
background: #ffac5b;
color: #fff;
line-height: 20px;
text-align: center;
font-size: 12px;
}
}
.commodity-content {
padding: 10px 0 0 0;
height: 69px;
overflow: hidden
overflow: hidden;
.commodity-name {
font-size: 12px;
color: #000;
line-height: 18px;
text-align: center;
}
.commodity-price {
position: relative;
margin: 3px 0 0 0;
text-align: center;
line-height: 20px;
color: #000;
span {
display: inline-block;
*display: inline;
*zoom: 1;
font-size: 12px;
padding: 0 15px;
&.origin {
text-decoration: line-through;
}
}
strong {
font-weight: normal;
color: #565656;
font-size: 13px;
}
span.vip-tag {
background-image: image-url("sale/vip.png");
background-repeat: no-repeat;
background-size: 100% 90%;
color: #fff;
font-style: italic;
margin-right: 5px;
}
.price-sale {
margin-left: 10px;
padding-left: 10px;
width: 36px;
height: 20px;
line-height: 20px;
background: url('../assets/images/furniture/sale-tag-bg.png?1450667948');
color: #fff;
}
}
}
.commodity-content .commodity-name {
font-size: 12px;
color: #000;
line-height: 18px;
text-align: center
@media screen and (min-width: 1150px) {
.commodity-list ul {
width: 1160px;
}
.commodity-item {
width: 280px;
}
.commodity-img {
height: 374px;
}
.commodity-content {
padding: 14px 0 0 0;
height: 77px;
}
}
.commodity-content .commodity-price {
position: relative;
margin: 3px 0 0 0;
text-align: center;
line-height: 20px;
color: #000
}
}
.commodity-content .commodity-price span {
display: inline-block;
*display: inline;
*zoom: 1;
font-size: 12px;
padding: 0 15px;
}
.sale-list-page {
.commodity-content .commodity-price span.origin {
text-decoration: line-through;
}
.sale-title {
margin: 30px 0;
font-size: 12px;
line-height: 26px;
.commodity-content .commodity-price strong {
font-weight: normal;
color: #565656;
font-size: 13px;
}
.title {
margin-right: 20px;
font-size: 16px;
}
.commodity-content .commodity-price span.vip-tag {
background-image: image-url('sale/vip.png');
background-repeat: no-repeat;
background-size: 100% 90%;
color: #fff;
font-style: italic;
margin-right: 5px;
}
.discount {
display: inline-block;
margin-right: 10px;
padding: 0 10px;
font-weight: lighter;
line-height: 16px;
vertical-align: text-bottom;
color: #fff;
background: #ff575c;
}
.commodity-content .commodity-price .price-sale {
margin-left: 10px;
padding-left: 10px;
width: 36px;
height: 20px;
line-height: 20px;
background: url('../assets/images/furniture/sale-tag-bg.png?1450667948');
color: #fff
.time {
.iconfont {
margin-right: 5px;
}
}
}
@media screen and (min-width: 1150px) {
.commodity-list ul {
width:1160px
}
.sort {
padding: 10px;
border: 1px solid #eaeceb;
.commodity-item {
width: 280px
}
li {
display: inline-block;
margin-right: 15px;
padding: 0 10px;
font-size: 12px;
line-height: 20px;
color: #444;
.commodity-img {
height: 374px
}
&.title {
margin-right: 0;
font-weight: bold;
}
.commodity-content {
padding: 14px 0 0 0;
height: 77px
&.active {
color: #666;
border: 1px solid #000;
}
}
}
}
... ...
<?php
namespace Hood;
use Yaf\Controller_Abstract;
use Hood\Helper\View as hoodView;
use Yaf;
use Hood\Validator as hoodValidator;
class Action extends Controller_Abstract
{
private $_viewLink = array();
private $_viewScript = array();
private $_headTitle;
private $_headmeta;
/**
* Meta
* @return \Hood\Helper\View\Meta
*/
public function _headMeta()
{
if (empty($this->_headmeta)) {
$this->_headmeta = new hoodView\Meta();
$this->getView()->assign("_headmeta", $this->_headmeta);
}
return $this->_headmeta;
}
/**
* Script
* @return \Hood\Helper\View\Script
*/
public function _viewScript($scriptName = '_headScript')
{
if (!isset($this->_viewScript[$scriptName])) {
$this->_viewScript[$scriptName] = new hoodView\Script();
$this->getView()->assign($scriptName, $this->_viewScript[$scriptName]);
}
return $this->_viewScript[$scriptName];
}
/**
*
* @return \Hood\Helper\View\Link
*/
public function _viewLink($linkName = '_headLink')
{
if (!isset($this->_viewLink[$linkName])) {
$this->_viewLink[$linkName] = new hoodView\Link();
$this->getView()->assign($linkName, $this->_viewLink[$linkName]);
}
return $this->_viewLink[$linkName];
}
/**
* Title
* @return \Hood\Helper\View\Title
*/
public function _headTitle($title)
{
if (empty($this->_headTitle)) {
$this->_headTitle = new hoodView\Title();
$this->getView()->assign("_headTitle", $this->_headTitle);
}
return $this->_headTitle->headTitle($title);
}
/**
* js 跳转 并 提示
*
* @param String $url
* @param String $expression
*/
protected function helpJsRedirect($message = '', $script = "history.back();")
{
$html = '';
if (!empty($message)) {
header("content-type: text/html; charset=utf-8");
$message = str_replace("\n", "\\n", $message);
$html .= "<script language=\"javascript\">";
$html .= "alert(\"{$message}\");";
$html .= "</script>";
}
$html .= "<script language=\"javascript\">";
$html .= $script;
$html .= "</script>";
die($html);
}
/**
* 跳转
* @param String $url
*/
protected function helpLocation($url)
{
header('Location: ' . $url);
}
/**
* refresh跳转
* @param $url
* @param string $message
*/
protected function helpRefresh($url, $message = '')
{
$html = '';
if (!empty($message)) {
header("content-type: text/html; charset=utf-8");
$message = str_replace("\n", "\\n", $message);
$html .= "<script language=\"javascript\">";
$html .= "alert(\"{$message}\");";
$html .= "</script>";
}
$html .= "<script language=\"javascript\">";
$html .= "window.location.href='{$url}';";
$html .= "</script>";
echo $html;
}
/**
* JSON输出
* @param $code
* @param null $message
* @param null $data
*/
protected function helpJsonResult($code, $message = null, $data = null)
{
header('Content-type: application/json');
echo json_encode(array('code' => $code, 'message' => $message, 'data' => $data));
exit();
}
/**
* JSON输出
* @param array $data
*/
protected function helpJson(array $data)
{
header('Content-type: application/json');
echo json_encode($data);
exit();
}
/**
* JSONP Callback输出,用于远程调用
* @param $callbackString
* @param $code
* @param null $message
* @param null $data
*/
protected function helpJsonCallbackResult($callbackString, $code, $message = null, $data = null)
{
header('Content-type: application/json');
echo $callbackString . "(";
echo json_encode(array('code' => $code, 'message' => $message, 'data' => $data));
echo ")";
exit();
}
/**
* @param string $namespace
* @return \Hood\Core\Session\SessionNamespace
*/
public function session($namespace = 'session_default', $sessionName = null)
{
return Session::start($namespace, $sessionName);
}
/**
* 数据校验
* @param array $data
* @param array $rules
* @param array $messagesAttribute
* @return Helper\Validation\Validator
*/
public function validator(array $data, array $rules, array $messagesAttribute = array())
{
return hoodValidator::make($data, $rules, $messagesAttribute);
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Zip
* Date: 14/12/9
* Time: 下午7:40
*/
namespace Hood;
use Hood\Cache\Memcached as Mcd;
use Hood\Cache\Memcache as Mc;
use Hood\Cache\CacheRedis;
use Hood\Cache\FileCache;
class Cache
{
/**
*
* @param null $node
* @return Mcd
*/
static public function Memcached($node = null, $childNode = 'hosts')
{
$mc = new Mcd();
$mc->setNode($node)->setChildNodes($childNode);
return $mc;
}
/**
* @param null $node
* @param string $childNode
* @return Mc
*/
static public function Memcache($node = null, $childNode = 'hosts')
{
$mc = new Mc();
$mc->setNode($node)->setChildNodes($childNode);
return $mc;
}
/**
* @return CacheRedis
*/
static public function Redis()
{
$servers = array();
$persistentID = '';
return new CacheRedis($servers, $persistentID);
}
/**
*
* @param null $childNode
* @param string $node
* @param null $cachePath
* @return FileCache
*/
static public function File($childNode = null, $node = 'cache', $cachePath = null)
{
return new FileCache($childNode, $node, $cachePath);
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Zip
* Date: 14/12/9
* Time: 下午10:35
*/
namespace Hood\Cache;
interface CacheInterface
{
/**
* @param $key
* @return mixed
*/
public function get($key);
/**
* @param $key
* @param $value
* @param $minutes
* @return mixed
*/
public function add($key, $value, $minutes);
/**
* @param $key
* @param $value
* @param $minutes
* @return mixed
*/
public function set($key, $value, $minutes);
/**
* @param $key
* @param int $value
* @return mixed
*/
public function increment($key, $value = 1);
/**
* @param $key
* @param int $value
* @return mixed
*/
public function decrement($key, $value = 1);
/**
* @param $key
* @return mixed
*/
public function delete($key);
/**
* @param $tagName
* @return $this
*/
public function tag($tagName);
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Zip
* Date: 14/11/23
* Time: 上午1:39
*/
namespace Hood\Cache;
use \Redis;
class CacheRedis
{
/**
*
* Enter description here ...
* @var Redis
*/
private $redis;
private $timeout = 2.5;
public function __construct(array $servers, $persistentID = '')
{
if (empty($servers)) {
throw new Q_Cache_Exception('redis server is null.');
}
$this->redis = new Redis();
$this->redis->connect($servers['host'], $servers['port'], $this->timeout);
}
/**
*
* 返回key所关联的字符串值,如果key不存在则返回特殊值nil。
* @param String $key
* @return Mixed or nil
*/
public function get($key)
{
assert(is_string($key));
return $this->redis->get($key);
}
/**
*
* 将字符串值value关联到key
* @param String $key
* @param Mixed $val
* @return bool
*/
public function set($key, $val)
{
assert(is_string($key));
return $this->redis->set($key, $val);
}
/**
*
* 同时设置一个或多个key-value对。
* @param array $keys
* @return bool
*/
public function mset(array $keys)
{
return $this->redis->mset($keys);
}
/**
*
* 返回所有(一个或多个)给定key的值.如果某个指定key不存在,那么返回特殊值nil。因此,该命令永不失败。
* @param array $keys
* @return Mixed
*/
public function mget(array $keys)
{
return $this->redis->mget($keys);
}
/**
*
* 返回key中字符串值的子字符串,字符串的截取范围由start和end两个偏移量决定(包括start和end在内)。
* 负数偏移量表示从字符串最后开始计数,-1表示最后一个字符,-2表示倒数第二个,以此类推
* @param String $key
* @param Integer $start
* @param Integer $end
* @return String
*/
public function getRange($key, $start, $end)
{
assert(is_string($key));
return $this->redis->getRange($key, $start, $end);
}
/**
*
* 删除数据 ( 返回删除个数 )
* @param String $key
* @return bool
*/
public function del($key)
{
assert(is_string($key));
return $this->redis->del($key);
}
/**
* 查找符合给定模式的key。
*
* 可以使用正则
* =========================================
* *命中数据库中所有key
* h?llo命中hello, hallo and hxllo等
* h*llo命中hllo和heeeeello等
* h[ae]llo命中hello和hallo,但不命中hillo
* =========================================
* KEYS的速度非常快,但在一个大的数据库中使用它仍然可能造成性能问题,如果你需要从一个数据集中查找特定的key,你最好还是用集合(set)结构。
* @param String $keys
* @return Mixed
*/
public function keys($keys)
{
return $this->redis->keys($keys);
}
/**
*
* 选择数据库
* @param String $db
* @return bool
*/
public function select($db = 9)
{
return $this->redis->select($db);
}
/**
*
* 获取 hash 集合中的键值
* @param String $hashName
* @param String $key
* @param Mixed $val
* @return Mixed
*/
public function hget($hashName, $key, $val)
{
assert(is_string($hashName)) && assert(is_string($key));
return $this->redis->hget($hashName, $key, $val);
}
/**
*
* 将哈希表key中的域field的值设为value。
* @param String $hashName
* @param String $key
* @param Mixed $val
* @return bool
*/
public function hset($hashName, $key, $val)
{
assert(is_string($hashName)) && assert(is_string($key));
return $this->redis->hset($hashName, $key, $val);
}
/**
*
* 排序
*
* @param String $key
* @param array $options
* 'by' => 'some_pattern_*',
* 'limit' => array(0, 1),
* 'get' => 'some_other_pattern_*' or an array of patterns,
* 'sort' => 'asc' or 'desc',
* 'alpha' => TRUE,
* 'store' => 'external-key'
* @return array
*/
public function sort($key, array $options = array())
{
assert(is_string($key));
return $this->redis->sort($key, $options);
}
/**
*
* 从当前数据库中随机返回(不删除)一个key。
* @return String or Mixed
*/
public function randomkey()
{
return $this->redis->randomKey();
}
/**
*
* 返回给定key的剩余生存时间(time to live)(以秒为单位)。
* @param String $key
* @return Integer
*/
public function ttl($key)
{
assert(is_string($key));
return $this->redis->ttl($key);
}
/**
*
* 检查给定key是否存在
* @param String $key
* @return bool
*/
public function exists($key)
{
assert(is_string($key));
return $this->redis->exists($key);
}
/**
*
* 移动key 到另外一个数据库
* @param String $key
* @param Integer $dbName
* @return bool
*/
public function move($key, $dbName)
{
assert(is_string($key));
return $this->redis->move($key, $dbName);
}
/**
*
* 将key改名为newkey
* @param String $key
* @param String $newKey
* @return bool
*/
public function rename($key, $newKey)
{
assert(is_string($key)) && assert(is_string($newKey));
return $this->redis->rename($key, $newKey);
}
/**
*
* 返回key所储存的值的类型
* @param String $key
* @return Mixed
* ================================
* none(key不存在) string(字符串) list(列表) set(集合) zset(有序集) hash(哈希表)
* ================================
*/
public function type($key)
{
return $this->redis->type($key);
}
/**
*
* 为给定key设置生存时间
* @param String $key
* @param Integer $expire
* @return bool
*/
public function setTimeout($key, $expire)
{
assert(is_string($key)) && assert(is_int($expire));
return $this->redis->setTimeout($key, $expire);
}
/**
*
* 不同在于EXPIREAT命令接受的时间参数是UNIX时间戳(unix timestamp)。
* @param String $key
* @param Integer $expire
* @return bool
*/
public function expireAt($key, $expire)
{
assert(is_string($key)) && assert(is_int($expire));
return $this->redis->expireAt($key, $expire);
}
/**
*
* 移除给定key的生存时间
* @param String $key
* @return bool
*/
public function persist($key)
{
assert(is_string($key));
return $this->redis->persist($key);
}
/**
*
* 将值value关联到key,并将key的生存时间设为seconds(以秒为单位)
* @param String $key
* @param Mixed $val
* @param Integer $expire
* @return bool
*/
public function setex($key, $val, $expire)
{
assert(is_string($key)) && assert(is_int($expire));
return $this->redis->setex($key, $expire, $val);
}
/**
*
* 如果key已经存在并且是一个字符串,APPEND命令将value追加到key原来的值之后
* @param String $key
* @param Mixed $val
* @return bool
*/
public function append($key, $val)
{
assert(is_string($key));
return $this->redis->append($key, $val);
}
/**
*
* 将给定key的值设为value,并返回key的旧值
* @param String $key
* @param Mixed $val
* @return Mixed
*/
public function getSet($key, $val)
{
assert(is_string($key));
return $this->redis->getSet($key, $val);
}
/**
*
* 返回key所储存的字符串值的长度
* @param String $key
* @return integer
*/
public function strlen($key)
{
return $this->redis->strlen($key);
}
/**
*
* 将key中储存的数字值减一
* @param String $key
* @return Integer
*/
public function decr($key)
{
assert(is_string($key));
return $this->redis->decr($key);
}
/**
*
* 将key所储存的值减去减量decrement。
* @param String $key
* @param Integer $value
* @return intger
*/
public function decrBy($key, $value = 1)
{
assert(is_string($key)) && assert(is_int($value));
return $this->redis->decrBy($key, $value);
}
/**
*
* 将key中储存的数字值增一
* @param String $key
* @param Integer $val
* @return Integer
*/
public function incrBy($key, $val = 1)
{
return $this->redis->incrBy($key, $val);
}
/**
*
* 同时将多个field - value(域-值)对设置到哈希表key中
* @param String $key
* @param array $vals
* @return bool
*/
public function hMset($hashKey, array $keys)
{
assert(is_string($hashKey));
return $this->redis->hMset($hashKey, $keys);
}
/**
*
* 返回哈希表key中,一个或多个给定域的值
* @param String $hashKey
* @param array $keys
* @return Mixed
*/
public function hmGet($hashKey, array $keys)
{
assert(is_string($hashKey));
return $this->redis->hmGet($hashKey, $keys);
}
/**
*
* 返回哈希表key中,所有的域和值
* @param String $hashKey
* @return Mixed
*/
public function hGetAll($hashKey)
{
assert(is_string($hashKey));
return $this->redis->hGetAll($hashKey);
}
/**
*
* 删除哈希表key中的一个或多个指定域
* @param String $hashKey
* @return bool
*/
public function hDel($hashKey, $hashKey2 = null, $hashKeyN = null)
{
$this->redis->hDel($hashKey, $hashKey2, $hashKeyN);
}
/**
*
* 返回哈希表key中域的数量
* @param String $hashKey
* @return Integer
*/
public function hLen($hashKey)
{
return $this->redis->hLen($hashKey);
}
/**
*
* 查看哈希表key中,给定域field是否存在
* @param String $hashKey
* @return bool
*/
public function hExists($key, $hashKey)
{
return $this->redis->hExists($key, $hashKey);
}
/**
*
* 为哈希表key中的域field的值加上增量increment。
* @param String $hashKey
* @param String $key
* @param Integer $member
* @return Integer
*/
public function hincrby($hashKey, $key, $member)
{
return $this->redis->hIncrBy($hashKey, $key, $member);
}
/**
*
* 返回哈希表key中的所有域
* @param String $hashKey
* @return array
*/
public function hKeys($hashKey)
{
return $this->redis->hKeys($hashKey);
}
/**
*
* 返回哈希表key中的所有值
* @param String $hashKey
* @return Array
*/
public function hVals($hashKey)
{
return $this->redis->hVals($hashKey);
}
###########################
# 表 List
###########################
/**
*
* 将值value插入到列表key的表头
* @param String $key
* @param Mixed $value
* @return bool
*/
public function lPush($key, $value)
{
assert(is_string($key));
return $this->redis->lPush($key, $value);
}
/**
*
* 将值value插入到列表key的表头,当且仅当key存在并且是一个列表
* @param String $key
* @param Mixed $value
* @return bool
*/
public function lPushx($key, $value)
{
assert(is_string($key));
return $this->redis->lPushx($key, $value);
}
/**
*
* 将值value插入到列表key的表尾
* @param String $key
* @param Mixed $value
* @return bool
*/
public function rPush($key, $value)
{
assert(is_string($key));
return $this->redis->rPush($key, $value);
}
/**
*
* 将值value插入到列表key的表尾,当且仅当key存在并且是一个列表
* @param String $key
* @param Mixed $value
* @return bool
*/
public function rPushx($key, $value)
{
assert(is_string($key));
return $this->redis->rPushx($key, $value);
}
/**
*
* 移除并返回列表key的头元素
* @param String $key
* @return bool or nil
*/
public function lPop($key)
{
return $this->redis->lPop($key);
}
/**
*
* 移除并返回列表key的尾元素
* @param String $key
* @return bool or nil
*/
public function rPop($key)
{
return $this->redis->rPop($key);
}
/**
*
* BLPOP是列表的阻塞式(blocking)弹出原语
* ===================================
* 类似 Gearman 等待移除
* ===================================
* @param array $keys
* @param Integer $timeout
* @return array
*/
public function blPop(array $keys, $timeout = 2)
{
return $this->redis->blPop($keys, (int)$timeout);
}
/**
*
* BRPOP是列表的阻塞式(blocking)弹出原语。
* ===================================
* 类似 Gearman 等待移除
* ===================================
* @param array $keys
* @param Integer $timeout
*
*/
public function brPop(array $keys, $timeout = 2)
{
return $this->redis->brPop($keys, (int)$timeout);
}
/**
* TODO
* 返回列表key的长度。
*/
public function llen()
{
}
/**
*
* 返回列表key中指定区间内的元素,区间以偏移量start和stop指定。
* @param String $key
* @param Integer $start
* @param Integer $end
* @return array
*/
public function lRange($key, $start = 0, $end = 0)
{
return $this->redis->lRange($key, (int)$start, (int)$end);
}
/**
*
* 根据参数count的值,移除列表中与参数value相等的元素
* ============================================
* count的值可以是以下几种:
* count > 0: 从表头开始向表尾搜索,移除与value相等的元素,数量为count
* count < 0: 从表尾开始向表头搜索,移除与value相等的元素,数量为count的绝对值
* count = 0: 移除表中所有与value相等的值
* ============================================
* @param String $key
* @param String $value
* @param Integer $count
* @return Integer
*/
public function lRem($key, $value, $count)
{
$this->redis->lRem((string)$key, (string)$value, (int)$count);
}
/**
*
* 将列表key下标为index的元素的值甚至为value
* (当index参数超出范围,或对一个空列表(key不存在)进行LSET时,返回一个错误)
* @param String $key
* @param Integer $index
* @param String $value
* @return bool
*/
public function lSet($key, $index, $value)
{
return $this->redis->lSet((string)$key, (int)$index, (string)$value);
}
/**
*
* 对一个列表进行修剪(trim),就是说,让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除
* @param String $key
* @param Integer $start
* @param Integer $stop
* @return bool
*/
public function lTrim($key, $start, $stop)
{
return $this->redis->lTrim((string)$key, (int)$start, (int)$stop);
}
/**
*
* 返回列表key中,下标为index的元素
* @param String $key
* @param Integer $index
* @return bool or nil
*/
public function lGet($key, $index)
{
return $this->redis->lGet((string)$key, (int)$index);
}
##################################################################
# SET
##################################################################
/**
*
* 将一个或多个member元素加入到集合key当中,已经存在于集合的member元素将被忽略
* @param String $key
* @param Mixed $value
* @return bool
*/
public function sAdd($skey, $value)
{
return $this->redis->sAdd($skey, $value);
}
/**
*
* ( 扩展 ) 将一个或多个member元素加入到集合key当中,已经存在于集合的member元素将被忽略
* @param String $key
* @param Mixed $value
* @param Integer $expiration
* @return bool
*/
public function sAdd2($skey, $value, $expiration = 0)
{
$result = $this->redis->sAdd($skey, $value);
$this->redis->setTimeout($skey, $expiration);
return $result;
}
/**
*
* 移除集合key中的一个或多个member元素,不存在的member元素会被忽略
* @param String $key
* @param String $member
* @return bool
*/
public function sRem($skey, $member)
{
return $this->redis->sRem((string)$skey, (string)$member);
}
/**
*
* 返回集合key中的所有成员
* @param String $key
* @return array
*/
public function sMembers($skey)
{
return $this->redis->sMembers((string)$skey);
}
/**
*
* 判断member元素是否是集合key的成员
* @param String $key
* @param String $value
*/
public function sIsMember($skey, $value)
{
return $this->redis->sIsMember((string)$skey, (string)$value);
}
/**
*
* 返回集合key的基数(集合中元素的数量)
* @param String $skey
* @return Integer
*/
public function sCard($skey)
{
return $this->redis->sCard((string)$skey);
}
/**
*
* 将member元素从source集合移动到destination集合
* @param String $srcKey
* @param String $dstKey
* @param String $member
* @return bool
*/
public function sMove($srcKey, $dstKey, $member)
{
return $this->redis->sMove((string)$srcKey, (string)$dstKey, (string)$member);
}
/**
*
* 移除并返回集合中的一个随机元素
* @param String $skey
* @return string or bool
*/
public function sPop($skey)
{
return $this->redis->sPop((string)$skey);
}
/**
*
* 返回集合中的一个随机元素。
* @param String $skey
* @return array or nil
*/
public function sRandMember($skey)
{
return $this->redis->sRandMember((string)$skey);
}
########################################################
# 有序集(Sorted Set)
########################################################
/**
*
* 将一个或多个member元素及其score值加入到有序集key当中
* @param String $zKey
* @param Integer $score
* @param String $value
* @return Integer
*/
public function zAdd($zKey, $score, $value)
{
assert(is_string($zKey)) && assert(is_int($score)) && assert(is_string($value));
return $this->redis->zAdd($zKey, $score, $value);
}
/**
*
* 移除有序集key中的一个或多个成员,不存在的成员将被忽略
* @param String $zKey
* @param String $member
* @return Integer
*/
public function zRem($zKey, $member)
{
return $this->redis->zRem((string)$zKey, (string)$member);
}
/**
*
* 返回有序集key的基数
* @param String $zKey
* @return Integer
*/
public function zSize($zKey)
{
return $this->redis->zSize((string)$zKey);
}
/**
*
* 返回有序集key中,score值在min和max之间(默认包括score值等于min或max)的成员
* @param String $zKey
* @param Integer $start
* @param Integer $end
* @return array
*/
public function zCount($zKey, $start, $end)
{
return $this->redis->zCount($zKey, $start, $end);
}
/**
*
* 返回有序集key中,成员member的score值
* @param String $zKey
* @param String $member
* @return String
*/
public function zScore($zKey, $member)
{
return $this->redis->zScore($zKey, $member);
}
/**
*
* 为有序集key的成员member的score值加上增量increment
* @param String $zKey
* @param Integer $value
* @param String $member
* @return Integer
*/
public function zIncrBy($zKey, $value, $member)
{
return $this->redis->zIncrBy($zKey, $value, $member);
}
/**
*
* 返回有序集key中,指定区间内的成员
* @param String $zKey
* @param Integer $start
* @param Integer $end
* @param bool $withscores
* @return bool ( 默认False无键值/True有键值 )
*/
public function zRange($zKey, $start, $end, $withscores = false)
{
return $this->redis->zRange($zKey, $start, $end, $withscores);
}
/**
*
* 返回有序集key中,指定区间内的成员
* 其中成员的位置按score值递减(从大到小)来排列
* @param String $zKey
* @param Integer $start
* @param Integer $end
* @param bool $withscores
* @return bool ( 默认False无键值/True有键值 )
*/
public function zRevRange($zKey, $start, $end, $withscores = false)
{
return $this->redis->zRevRange($zKey, $start, $end, $withscores);
}
/**
*
* 返回有序集key中,所有score值介于min和max之间(包括等于min或max)的成员。有序集成员按score值递增(从小到大 or 从大到小)次序排列
* @param String $zKey
* @param Integer $start
* @param Integer $end
* @param array $options
* @return array
* =========================================================
* $redis->zRangeByScore('key', 0, 3);
* array('val0', 'val2')
* $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE);
* array('val0' => 0, 'val2' => 2)
* $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));
* array('val2' => 2)
* $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));
* array('val2')
* $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE, 'limit' => array(1, 1));
* array('val2' => 2)
* =========================================================
*
*/
public function zRangeByScore($zKey, $start, $end, array $options)
{
return $this->redis->zRangeByScore($zKey, $start, $end, $options);
}
/**
*
* 返回有序集key中成员member的排名。其中有序集成员按score值递增(从小到大 or 从大到小)顺序排列
* @param String $zKey
* @param String $member
* @param String $order ( desc or asc )
* @return array
*/
public function zRank($zKey, $member, $order = 'desc')
{
return $order == 'desc' ? $this->redis->zRank($zKey, $member) : $this->redis->zRevRank($zKey, $member);
}
/**
* 移除有序集key中,指定排名(rank)区间内的所有成员
* 区间分别以下标参数start和stop指出,包含start和stop在内
* @param String $zKey
* @param Integer $start
* @param Integer $end
* @return Integer
*/
public function zRemRangeByRank($zKey, $start, $end)
{
return $this->redis->zRemRangeByRank($zKey, $start, $end);
}
public function tag($tagName)
{
}
/**
* 移除有序集key中,指定(socre)区间内的所有成员
* 区间分别以下标参数start和stop指出,包含start和stop在内
* @param String $zKey
* @param Integer $start
* @param Integer $end
* @return Integer
*/
public function zRemRangeByScore($zKey, $start, $end)
{
return $this->redis->zRemRangeByScore($zKey, $start, $end);
}
public function zRevRangeByScore($zkey, $start, $end, array $options)
{
return $this->redis->zRevRangeByScore($zkey, $start, $end, $options);
}
/**
* 发布消息
*
* @param String $channel
* @param String $message
* @return Integer
*/
public function publish($channel, $message)
{
return $this->redis->publish($channel, $message);
}
/**
* 订阅消息
* @param String $channel
* @return String
*/
public function subscribe(array $channel, $callback)
{
return $this->redis->subscribe($channel, $callback);
}
/**
* 退订
* @param String $channel
*/
public function unsubscribe($channel)
{
return $this->redis->unsubscribe($channel);
}
/**
* 按照模式匹配订阅多个频道
*
* @param String $pattern (如:news.* 可订阅news.开头的所有频道)
*/
public function psubscribe($pattern, $callback)
{
return $this->redis->psubscribe($pattern, $callback);
}
/**
* 退订给定模式的所有渠道
*
* @param String $pattern
*/
public function punsubscribe($pattern)
{
return $this->redis->punsubscribe($pattern);
}
public function pubsub($pattern)
{
return $this->redis->pubsub($pattern);
}
}
\ No newline at end of file
... ...
<?php
namespace Hood\Cache;
use Hood\Core\Root;
use Yaf\Exception;
/**
* Description of cache
*
* @author 13011908
*/
class FileCache extends Root implements CacheInterface
{
const DEFAULT_EXPIRE = 3600;
protected static $default = 'file';
protected static $instances = array();
protected $_cache_dir;
protected $_tag = null;
private $section = 'file';
private $node = 'cache';
public function __construct($childNode = null, $node = 'cache', $cachePath = null)
{
if ($cachePath == null) {
$server = $this->getServerHost('cache');
$this->node = ($node == null ? 'cache' : $node);
$_pathList = $cachePath = $server->getServerConfig($this->section, $this->node);
if ($childNode == null && is_array($cachePath)) {
$cachePath = (sys_get_temp_dir() . 'cached' . DIRECTORY_SEPARATOR);
} else {
$cachePath = $_pathList[$childNode];
}
}
$this->initFileInfo($cachePath);
}
private function initFileInfo($directory)
{
try {
$this->_cache_dir = new \SplFileInfo($directory);
} // PHP < 5.3 exception handle
catch (ErrorException $e) {
$this->_cache_dir = $this->_make_directory($directory, 0777, TRUE);
} // PHP >= 5.3 exception handle
catch (UnexpectedValueException $e) {
$this->_cache_dir = $this->_make_directory($directory, 0777, TRUE);
}
// If the defined directory is a file, get outta here
if ($this->_cache_dir->isFile()) {
throw new Exception('Unable to create cache directory as a file already exists : ' . $this->_cache_dir->getRealPath());
}
if (!$this->_cache_dir->isDir()) {
$this->_cache_dir = $this->_make_directory($directory, 0777, TRUE);
}
// Check the read status of the directory
if (!$this->_cache_dir->isReadable()) {
throw new Exception('Unable to read from the cache directory ' . $this->_cache_dir->getRealPath());
}
// Check the write status of the directory
if (!$this->_cache_dir->isWritable()) {
throw new Exception('Unable to write to the cache directory ' . $this->_cache_dir->getRealPath());
}
}
public function add($key, $value, $minutes)
{
}
public function increment($key, $value = 1)
{
$tag = $this->_tag;
if ($get = $this->get($key)) {
if (preg_match('/^\d+$/', $get)) {
$value = intval($get) + $value;
} else {
return false;
}
}
if ($tag) {
$this->tag($tag);
}
return $this->set($key, $value);
}
public function decrement($key, $value = 1)
{
$tag = $this->_tag;
if ($get = $this->get($key)) {
if (preg_match('/^\d+$/', $get)) {
$value = intval($get) - $value;
} else {
return false;
}
}
if ($tag) {
$this->tag($tag);
}
return $this->set($key, $value);
}
public function tag($tagName = null)
{
if ($tagName) {
$this->_tag = md5($tagName);
return $this;
} elseif (!empty($this->_tag)) {
$tag = $this->_tag;
unset($this->_tag);
return $tag . DIRECTORY_SEPARATOR;
} else {
return '';
}
}
public static function instance($group = NULL)
{
// If there is no group supplied
if ($group === NULL) {
// Use the default setting
$group = self::$default;
}
if (isset(self::$instances[$group])) {
// Return the current group if initiated already
return self::$instances[$group];
}
// Create a new cache type instance
self::$instances[$group] = new self();
// Return the instance
return self::$instances[$group];
}
/**
* Retrieve a cached value entry by id.
*
* // Retrieve cache entry from file group
* $data = self::instance('file')->get('foo');
*
* // Retrieve cache entry from file group and return 'bar' if miss
* $data = self::instance('file')->get('foo', 'bar');
*
* @param string id of cache to entry
* @param string default value to return if cache miss
* @return mixed
* @throws Cache_Exception
*/
public function get($id, $default = NULL)
{
$filename = self::filename($this->_sanitize_id($id));
$directory = $this->_resolve_directory($filename);
// Wrap operations in try/catch to handle notices
try {
// Open file
$file = new \SplFileInfo($directory . $filename);
// If file does not exist
if (!$file->isFile()) {
// Return default value
return $default;
} else {
// Open the file and parse data
$created = $file->getMTime();
$data = $file->openFile();
$lifetime = $data->fgets();
// If we're at the EOF at this point, corrupted!
if ($data->eof()) {
return false;
throw new Exception(__METHOD__ . ' corrupted cache file!');
}
$cache = '';
while ($data->eof() === FALSE) {
$cache .= $data->fgets();
}
// Test the expiry
if (($created + (int)$lifetime) < time()) {
// Delete the file
$this->_delete_file($file, NULL, TRUE);
return $default;
} else {
return unserialize($cache);
}
}
} catch (ErrorException $e) {
// Handle ErrorException caused by failed unserialization
if ($e->getCode() === E_NOTICE) {
throw new Exception(__METHOD__ . ' failed to unserialize cached object with message : ' . $e->getMessage());
}
// Otherwise throw the exception
throw $e;
}
}
/**
* Set a value to cache with id and lifetime
*
* $data = 'bar';
*
* // Set 'bar' to 'foo' in file group, using default expiry
* self::instance('file')->set('foo', $data);
*
* // Set 'bar' to 'foo' in file group for 30 seconds
* self::instance('file')->set('foo', $data, 30);
*
* @param string id of cache entry
* @param string data to set to cache
* @param integer lifetime in seconds
* @return boolean
*/
public function set($id, $data, $lifetime = NULL)
{
$filename = self::filename($this->_sanitize_id($id));
$directory = $this->_resolve_directory($filename);
// If lifetime is NULL
if ($lifetime === NULL) {
// Set to the default expiry
$lifetime = self::DEFAULT_EXPIRE;
}
// Open directory
$dir = new \SplFileInfo($directory);
// If the directory path is not a directory
if (!$dir->isDir()) {
// Create the directory
if (!mkdir($directory, 0777, TRUE)) {
throw new Exception(__METHOD__ . ' unable to create directory : ' . $directory);
}
// chmod to solve potential umask issues
chmod($directory, 0777);
}
// Open file to inspect
$resouce = new \SplFileInfo($directory . $filename);
$file = $resouce->openFile('w');
try {
$data = $lifetime . "\n" . serialize($data);
$file->fwrite($data, strlen($data));
return (bool)$file->fflush();
} catch (ErrorException $e) {
// If serialize through an error exception
if ($e->getCode() === E_NOTICE) {
// Throw a caching error
throw new Exception(__METHOD__ . ' failed to serialize data for caching with message : ' . $e->getMessage());
}
// Else rethrow the error exception
throw $e;
}
}
protected static function filename($string)
{
return sha1($string) . '.cache';
}
/**
* Delete a cache entry based on id
*
* // Delete 'foo' entry from the file group
* self::instance('file')->delete('foo');
*
* @param string id to remove from cache
* @return boolean
*/
public function delete($id)
{
$filename = self::filename($this->_sanitize_id($id));
$directory = $this->_resolve_directory($filename);
return $this->_delete_file(new \SplFileInfo($directory . $filename), NULL, TRUE);
}
/**
* Delete all cache entries.
*
* Beware of using this method when
* using shared memory cache systems, as it will wipe every
* entry within the system for all clients.
*
* // Delete all cache entries in the file group
* self::instance('file')->delete_all();
*
* @return boolean
*/
public function delete_all()
{
return $this->_delete_file($this->_cache_dir, TRUE);
}
protected function _delete_file(\SplFileInfo $file, $retain_parent_directory = FALSE, $ignore_errors = FALSE, $only_expired = FALSE)
{
// Allow graceful error handling
try {
// If is file
if ($file->isFile()) {
try {
if ($only_expired === FALSE) {
// We want to delete the file
$delete = TRUE;
} // Otherwise...
else {
// Assess the file expiry to flag it for deletion
$json = $file->openFile('r')->current();
$data = json_decode($json);
$delete = $data->expiry < time();
}
// If the delete flag is set delete file
if ($delete === TRUE)
return @unlink($file->getRealPath());
else
return FALSE;
} catch (ErrorException $e) {
// Catch any delete file warnings
if ($e->getCode() === E_WARNING) {
throw new Exception(__METHOD__ . ' failed to delete file : ' . $file->getRealPath());
}
}
} // Else, is directory
elseif ($file->isDir()) {
// Create new DirectoryIterator
$files = new DirectoryIterator($file->getPathname());
// Iterate over each entry
while ($files->valid()) {
// Extract the entry name
$name = $files->getFilename();
// If the name is not a dot
if ($name != '.' AND $name != '..') {
// Create new file resource
$fp = new \SplFileInfo($files->getRealPath());
// Delete the file
$this->_delete_file($fp);
}
// Move the file pointer on
$files->next();
}
// If set to retain parent directory, return now
if ($retain_parent_directory) {
return TRUE;
}
try {
// Remove the files iterator
// (fixes Windows PHP which has permission issues with open iterators)
unset($files);
// Try to remove the parent directory
return rmdir($file->getRealPath());
} catch (ErrorException $e) {
// Catch any delete directory warnings
if ($e->getCode() === E_WARNING) {
throw new Exception(__METHOD__ . ' failed to delete directory : ' . $file->getRealPath());
}
throw $e;
}
} else {
// We get here if a file has already been deleted
return FALSE;
}
} // Catch all exceptions
catch (Exception $e) {
// If ignore_errors is on
if ($ignore_errors === TRUE) {
// Return
return FALSE;
}
// Throw exception
throw $e;
}
}
protected function _resolve_directory($filename)
{
return $this->_cache_dir->getRealPath() . DIRECTORY_SEPARATOR . $this->tag() . $filename[0] . $filename[1] . DIRECTORY_SEPARATOR;
}
protected function _sanitize_id($id)
{
// Change slashes and spaces to underscores
return str_replace(array('/', '\\', ' '), '_', $id);
}
/**
* Makes the cache directory if it doesn't exist. Simply a wrapper for
* `mkdir` to ensure DRY principles
*
* @see http://php.net/manual/en/function.mkdir.php
* @param string directory
* @param string mode
* @param string recursive
* @param string context
* @return \SplFileInfo
* @throws Cache_Exception
*/
protected function _make_directory($directory, $mode = 0777, $recursive = FALSE, $context = NULL)
{
if (!mkdir($directory, $mode, $recursive)) {
throw new Exception('Failed to create the defined cache directory : ' . $directory);
}
chmod($directory, $mode);
return new \SplFileInfo($directory);;
}
/**
* Garbage collection method that cleans any expired
* cache entries from the cache.
*
* @return void
*/
public function garbage_collect()
{
$this->_delete_file($this->_cache_dir, TRUE, FALSE, TRUE);
return;
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Zip
* Date: 15/4/28
* Time: 下午3:16
*/
namespace Hood\Cache;
use Hood\Core\Root;
class Memcache extends Root implements CacheInterface
{
private $mcInstances = array();
private $persistentIDs = array();
private $section = 'memcached';
private $node = 'servers';
private $tagName = '';
private $prefix = '';
private $persistentID = 'hood.cache';
private $childNodes = 'hosts';
public function __construct($prefix = '', $persistentID = 'hood.cache')
{
parent::__construct();
$this->prefix = $prefix;
$this->persistentIDs[] = $this->persistentID = $persistentID;
}
public function init()
{
if (isset($this->mcInstances[$this->persistentID])) {
$mc = $this->mcInstances[$this->persistentID];
} else {
$instance = new \Memcache();
$server = $this->getServerHost('cache');
$_serverHosts = $server->getServerConfig($this->section, $this->node);
$mcServers = $this->_makeHosts($server->getServer($_serverHosts[$this->childNodes], 2));
foreach ($mcServers as $key => $val) {
$weight = 100;
if (count($val) == 3) {
list($host, $port, $weight) = $val;
} else {
list($host, $port) = $val;
}
$instance->addServer($host, $port, $this->persistentID, $weight);
}
$this->mcInstances[$this->persistentID] = $mc = $instance;
}
return $mc;
}
/**
* 组织host
* @param array $hosts
* @return array
*/
private function _makeHosts(array $hosts)
{
$_server = array();
foreach ($hosts as $key => $val) {
$_server[] = explode(':', $val);
}
return $_server;
}
/**
* 设置mc配置的块节点
* @param $node
* @return $this
*/
public function setNode($node = null)
{
if ($node != null) $this->node = $node;
return $this;
}
/**
* 设置子节点
* @param $childNode
* @return $this
*/
public function setChildNodes($childNode)
{
$this->childNodes = $childNode;
return $this;
}
/**
* 构建tag
* @param bool $mode
* @return string
*/
private function _makeTag($mode = false)
{
if (empty($this->tagName)) return '';
$_tagVal = $this->init()->get($this->tagName);
if (empty($_tagVal) && $mode == true) {
$_tagVal = md5(microtime() . mt_rand() . uniqid());
$this->init()->set($this->tagName, $_tagVal, 0);
}
unset($this->tagName);
return empty($_tagVal) ? '' : $_tagVal . '.';
}
/**
* 检索一个元素
* @param $key
* @param callable $flags
* @return mixed
*/
public function get($key, &$flags = \MEMCACHE_COMPRESSED)
{
return $this->init()->get($this->_makeTag() . $key, $flags);
}
/**
* 向一个新的key下面增加一个元素
* @param $key
* @param $value
* @param $expiration
* @return bool
*/
public function add($key, $value, $expiration = 0)
{
return $this->init()->add($this->_makeTag(true) . $key, $value, $expiration);
}
/**
* 减小数值元素的值
* @param $key
* @param int $offset
* @return int
*/
public function decrement($key, $offset = 1)
{
return $this->init()->decrement($this->_makeTag() . $key, $offset);
}
/**
* @param $key
* @param int $time
* @return bool
*/
public function delete($key, $time = 0)
{
return $this->init()->delete($this->_makeTag() . $key, $time);
}
/**
* 增加数值元素的值
* @param $key
* @param int $offset
* @param int $initialValue
* @param int $expiry
* @return int
*/
public function increment($key, $offset = 1, $initialValue = 0, $expiry = 0)
{
return $this->init()->increment($this->_makeTag() . $key, $offset, $initialValue, $expiry);
}
/**
* 设置
* @param $key
* @param $value
* @param int $expiration
* @return bool
*/
public function set($key, $var, $expire = 0, $flag = \MEMCACHE_COMPRESSED)
{
return $this->init()->set($this->_makeTag(true) . $key, $var, $flag, $expire);
}
/**
* 设置tag
* @param $tagName
* @return $this
*/
public function tag($tagName)
{
$this->tagName = $tagName;
return $this;
}
}
\ No newline at end of file
... ...