Authored by xuqi

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

... ... @@ -16,6 +16,7 @@ use Yaf\Dispatcher;
use WebPlugin\Cache;
use WebPlugin\Helpers;
use Hood\Session;
use WebPlugin\Mobile;
class WebAction extends Controller_Abstract
{
... ... @@ -48,6 +49,7 @@ class WebAction extends Controller_Abstract
*/
public function init()
{
Mobile::isGoMobile();
$this->_request = $this->getRequest();
// 设置环境变量
... ...
... ... @@ -78,6 +78,9 @@ class HelperSearch
self::$options = $options;
unset(self::$params['page']);
self::$filter = isset($data['product']['filter']) ? $data['product']['filter'] : array();
//当前页
$result['page'] = isset($data['product']['page']) ? $data['product']['page'] : '';
self::$page = $result['page'];
//产品列表
$result['goods'] = isset($data['product']['product_list']) ? self::getProductList($data['product']['product_list'], $options) : array();
//总页数
... ... @@ -88,8 +91,6 @@ class HelperSearch
if (isset($data['product']['total'])) {
self::$total = $data['product']['total'];
}
//当前页
self::$page = $result['page'] = isset($data['product']['page']) ? $data['product']['page'] : '';
//筛选条件
$result['filters'] = isset($data['product']['filter']) ? self::filter() : array();
//排序方式、显示数量等其他选项
... ... @@ -185,6 +186,10 @@ class HelperSearch
$isNew = false;
$isSale = false;
}
//SALE、NEW标签不共存
if ($isNew) {
$isSale = false;
}
$gender = 0;
if (isset(self::$options['gender'])) {
$genderArr = explode(',', self::$options['gender']);
... ... @@ -391,8 +396,10 @@ class HelperSearch
$sortList[$key]['active'] = isset(self::$params['msort']) && self::$params['msort'] == $val['sort_id'] ? true : false;
$sortList[$key]['childList'][] = array(
'name' => '全部'.$val['sort_name'],
'href' => self::buildUrl(array_merge($gender, array('msort'=>$val['sort_id'])))
'href' => self::buildUrl(array_merge($gender, array('msort'=>$val['sort_id']))),
'childActive' => isset(self::$params['msort']) && !isset(self::$params['misort']) && self::$params['msort'] == $val['sort_id'] ? true : false
);
if (isset($val['sub']) && !empty($val['sub'])) {
foreach ($val['sub'] as $k => $v) {
$sortList[$key]['childList'][$k+1]['name'] = $v['sort_name'];
... ... @@ -988,7 +995,7 @@ class HelperSearch
$url = self::buildUrl(array_merge($params, array(
'order' => 'p_d_desc'
)));
$desc = true;
$desc = false;
$active = true;
}
else {
... ... @@ -1138,6 +1145,19 @@ class HelperSearch
}
return $next;
}
/**
* 上一页
*/
public static function preUrl() {
$preUrl = '';
$param = self::$params;
$page = self::$page;
if ($page > 1) {
$param['page'] = $page - 1;
$preUrl = self::buildUrl($param);
}
return $preUrl;
}
/**
* 组织产品的图片
... ... @@ -1339,6 +1359,7 @@ class HelperSearch
$result['pageCounts'] = self::viewNum();
$result['curPage'] = self::$page;
$result['pageCount'] = self::$pageTotal;
$result['preHref'] = self::preUrl();
$result['nextHref'] = ($next = self::next(self::$pageTotal, self::$filter)) ? $next['href'] : '';
return $result;
}
... ... @@ -1362,23 +1383,23 @@ class HelperSearch
$type = isset(self::$params['msort']) && self::$params['msort'] ? self::$params['msort'] : '';
}
//新品到着
elseif ($controller == 'List' && $action == 'new') {
elseif ($controller == 'list' && $action == 'new') {
if (isset(self::$params['shelve_time'])) {
$date = explode(',', self::$params['shelve_time']);
$date = date('Y-m-d', $date[0]);
$type = $date;
}
$type = $date;
}
//list - sale
elseif ($controller == 'list' && $action == 'sale') {
$type = isset(self::$params['discount']) && self::$params['discount'] ? self::$params['discount'] : '0,0.9';
$type = isset(self::$params['p_d']) && self::$params['p_d'] ? self::$params['p_d'] : '0,0.9';
}
elseif ($controller == 'sale' && $action == 'index') {
$type = isset(self::$params['specialsale_id']) && self::$params['specialsale_id'] ? self::$params['specialsale_id'] : '';
}
// 品牌
elseif ($controller == 'list' && $action == 'sale') {
$type = isset(self::$params['brandId']) && self::$params['brandId'] ? self::$params['brandId'] : '';
elseif ($controller == 'index' && $action == 'brand') {
$type = isset(self::$options['brandId']) && self::$options['brandId'] ? self::$options['brandId'] : '';
}
// 搜索
elseif ($controller == 'search') {
... ...
<?php
/**
* Created by PhpStorm.
* User: haishengshen
* Date: 14-3-6
* Time: 下午1:15
*/
namespace WebPlugin;
class Mobile
{
/**
* 获取用户User-Agent
* @return bool
*/
public static function getUserAgent()
{
if (!isset($_SERVER['HTTP_USER_AGENT']) || empty($_SERVER['HTTP_USER_AGENT'])) {
return '';
}
return $_SERVER['HTTP_USER_AGENT'];
}
/**
* 获取当前地址
* @return array
*/
public static function getNowUrl()
{
return array('host'=>$_SERVER['HTTP_HOST'], 'uri'=> $_SERVER['REQUEST_URI']);
}
/**
* 获取手机版的对应地址
* @param $host
* @return mixed
*/
public static function newHost($host)
{
if ($host == 'www.yohobuy.com' || $host == 'new.yohobuy.com' || stristr($host, 'new.yohobuy.com')) {
return str_replace(array('www.yohobuy', 'new.yohobuy'), 'm.yohobuy', $host);
}
if ($host == 'huodong.yohobuy.com') {
return str_replace('huodong.yohobuy', 'm.yohobuy', $host);
}
return str_replace('yohobuy.com', 'm.yohobuy.com', $host);
}
public static function match($url, $host, $uri)
{
//guang.yohobuy.com
//guang.yohobuy.com/1.html
$list = array(
array(
'match' => '#^([guang\.]*)yohobuy\.com(\/*)$#',
),
array(
'match' => '#([guang\.]*)yohobuy.com/([0-9]+).html#',
'to' => 'guang.m.yohobuy.com/info/index?id='.substr($uri,1,(strpos($uri,'.')-1)) ,
),
);
foreach ($list as $value) {
if (preg_match($value['match'], $url) && !empty($value['to'])) {
return $value['to'];
} else if (preg_match($value['match'], $url)) {
$newHost = self::newHost($host);
return $newHost . $uri;
}
}
$continueList = array('www', 'list', 'search');
$hostSplit = explode('.', $host);
return 'm.yohobuy.com';
}
/**
* 获取新的URL
* @return string
*/
public static function getNewUrl()
{
$url = self::getNowUrl();
return self::match($url['host'].$url['uri'], $url['host'], $url['uri']);
}
/**
* 判断是否手机
* @return bool
*/
public static function isMobile()
{
$userAgent = self::getUserAgent();
$mobile_agents = Array("240x320","acer","acoon","acs-","abacho","ahong","airness","alcatel","amoi","android","anywhereyougo.com","applewebkit/525","applewebkit/532","asus","audio","au-mic","avantogo","becker","benq","bilbo","bird","blackberry","blazer","bleu","cdm-","compal","coolpad","danger","dbtel","dopod","elaine","eric","etouch","fly ","fly_","fly-","go.web","goodaccess","gradiente","grundig","haier","hedy","hitachi","htc","huawei","hutchison","inno","ipad","ipaq","ipod","jbrowser","kddi","kgt","kwc","lenovo","lg ","lg2","lg3","lg4","lg5","lg7","lg8","lg9","lg-","lge-","lge9","longcos","maemo","mercator","meridian","micromax","midp","mini","mitsu","mmm","mmp","mobi","mot-","moto","nec-","netfront","newgen","nexian","nf-browser","nintendo","nitro","nokia","nook","novarra","obigo","palm","panasonic","pantech","philips","phone","pg-","playstation","pocket","pt-","qc-","qtek","rover","sagem","sama","samu","sanyo","samsung","sch-","scooter","sec-","sendo","sgh-","sharp","siemens","sie-","softbank","sony","spice","sprint","spv","symbian","tablet","talkabout","tcl-","teleca","telit","tianyu","tim-","toshiba","tsm","up.browser","utec","utstar","verykool","virgin","vk-","voda","voxtel","vx","wap","wellco","wig browser","wii","windows ce","wireless","xda","xde","zte");
$is_mobile = false;
if (stristr($userAgent, 'ipad')) {
return $is_mobile;
}
foreach ($mobile_agents as $device) {
if (stristr($userAgent, $device)) {
$is_mobile = true;
break;
}
}
return $is_mobile;
}
/**
* 是否转到手机版
* @return bool
*/
public static function isGoMobile()
{
if (empty($_COOKIE['m2w']) && self::isMobile()) {
$newUrl = self::getNewUrl();
Header("HTTP/1.1 301 Moved Permanently");
header('Location:http://'.$newUrl);
exit;
}
return true;
}
}
\ No newline at end of file
... ...
... ... @@ -6,7 +6,7 @@
{{#if @last}}
<b>{{name}}</b>
{{else}}
{{name}}
<span title="{{name}}">{{name}}</span>
{{/if}}
{{#unless @last}}
... ... @@ -17,7 +17,7 @@
{{#if @last}}
<b>{{{name}}}</b>
{{else}}
{{name}}
<span title="{{name}}">{{name}}</span>
{{/if}}
{{#unless @last}}
... ...
... ... @@ -38,6 +38,11 @@
</div>
<div class="good-detail-text">
<a href="{{url}}" target="_blank">{{{name}}}</a>
{{#brand}}
<p class="brand">
<a href="{{url}}">{{name}}</a>
</p>
{{/brand}}
<p class="price">
{{# marketPrice}}
<span class="market-price">¥{{.}}</span>
... ... @@ -47,4 +52,4 @@
</span>
</p>
</div>
</div>
\ No newline at end of file
</div>
... ...
... ... @@ -12,8 +12,10 @@
</li>
{{#each list}}
<li {{#if active}}class="active"{{/if}}>
<a href="{{href}}">{{name}}</a>
<span>{{num}}</span>
<a href="{{href}}">
{{name}}
<span>{{num}}</span>
</a>
</li>
{{/each}}
</ul>
... ... @@ -30,8 +32,10 @@
<ul class="sort-child-list new-sale">
{{#each list}}
<li {{#if active}}active{{/if}}>
<a href="{{href}}">{{name}}</a>
<span>{{num}}</span>
<a href="{{href}}">
{{name}}
<span>{{num}}</span>
</a>
</li>
{{/each}}
</ul>
... ... @@ -56,8 +60,10 @@
<ul class="sort-child-list">
{{#each childList}}
<li class="{{#if childActive}}active{{/if}}">
<a href="{{href}}">{{name}}</a>
<span>{{num}}</span>
<a href="{{href}}">
{{name}}
<span>{{num}}</span>
</a>
</li>
{{/each}}
</ul>
... ...
... ... @@ -24,23 +24,11 @@ var $body = $('body');
require("js/footer");
function cookie(name) {
var cookies = document.cookie,
cookieVal,
offset;
if (document.cookie && document.cookie !== '') {
offset = cookies.indexOf(name + '=');
if (offset > -1) {
offset += name.length + 1;
cookieVal = decodeURIComponent($.trim(cookies.substring(offset, cookies.indexOf(';', offset))));
}
}
var re = new RegExp(name + '=([^;$]*)', 'i'),
matchPattern = '$1';
return cookieVal;
return re.test(decodeURIComponent(document.cookie)) ? RegExp[matchPattern] : '';
}
function setCookie(name, value, options) {
... ... @@ -492,7 +480,7 @@ function actionGoodsCart() {
}
}
if (cartInfo != null) {
if (cartInfo !== null && cartInfo !== '') {
totalNum = parseInt(cartInfo._nac) + parseInt(cartInfo._ac);
if (totalNum === 0) {
$('#icart-num').attr('class', 'icart-num icart-none');
... ... @@ -1159,7 +1147,7 @@ function actionTipPic() {
}
}
});
logolink = $('.first-nav-list .cur').find('a').attr('href');
logolink = $('.cure').find('.name-cn').find('a').attr('href');
$('.main-link').attr('href', logolink);
}
... ... @@ -1175,7 +1163,7 @@ function closeCover() {
* @return {[type]} [description]
*/
function actionCover() {
var gender = cookieMap._Gender;
var gender = window.cookie('_Gender');
var newMask = '';
var windowheight = '';
var selfheight = '';
... ... @@ -1812,6 +1800,7 @@ function init() {
actionNav(); //处理导航
actionTipPic(); //鼠标移入后查询
actionExeTemplate(); //处理模板
actionCover(); //初次登录弹框
actionInitCookie(); //初始化cookie
actionExeCookieMap(); //格式化cookie
actionGoodsCart(); //初始化购物车插件
... ... @@ -1829,7 +1818,6 @@ function init() {
actionListenDelCarGoods(); //监听购物车删除
actionListenCartMore(); //
actionLoginInfo(); //获取登录信息
actionCover(); //初次登录弹框
actionAddKeyWords(); //增加关键字
}
init();
... ...
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.
... ... @@ -30,7 +30,7 @@ slide = new Slide({
loop: false,
auto: false,
timeout: 2,
index: 1
index: 0
});
slide.on('change', function(data) {
... ...
... ... @@ -157,7 +157,7 @@ function actionGoodsCart() {
}
}
if (cartInfo != null) {
if (cartInfo !== null && cartInfo !== '') {
totalNum = parseInt(cartInfo._nac) + parseInt(cartInfo._ac);
if (totalNum === 0) {
$('#icart-num').attr('class', 'icart-num icart-none');
... ... @@ -840,7 +840,7 @@ function closeCover() {
* @return {[type]} [description]
*/
function actionCover() {
var gender = cookieMap._Gender;
var gender = window.cookie('_Gender');
var newMask = '';
var windowheight = '';
var selfheight = '';
... ... @@ -1477,6 +1477,7 @@ function init() {
actionNav(); //处理导航
actionTipPic(); //鼠标移入后查询
actionExeTemplate(); //处理模板
actionCover(); //初次登录弹框
actionInitCookie(); //初始化cookie
actionExeCookieMap(); //格式化cookie
actionGoodsCart(); //初始化购物车插件
... ... @@ -1494,7 +1495,6 @@ function init() {
actionListenDelCarGoods(); //监听购物车删除
actionListenCartMore(); //
actionLoginInfo(); //获取登录信息
actionCover(); //初次登录弹框
actionAddKeyWords(); //增加关键字
}
init();
... ...
... ... @@ -50,7 +50,14 @@
}
> .price {
margin-top: 10px;
margin-top: 5px;
}
.brand {
a {
color: #666;
line-height: 1.5;
}
}
.market-price {
... ...
... ... @@ -88,6 +88,7 @@
}
a {
display: block;
color: #666;
padding-left: 10px;
height: 22px;
... ...
... ... @@ -7,6 +7,7 @@ use LibModels\Web\Home\IndexData;
use LibModels\Web\Home\UserData;
use WebPlugin\Images;
use WebPlugin\Captcha;
use WebPlugin\Cache;
/**
* web登录注册等相关数据构建
... ... @@ -134,4 +135,22 @@ class PassportModel
return $ret;
}
/*
* 重写递增计数 cache方法
* $key cache-key
* $offset 递增偏移量
* $initValue 初始化值
* $expiry 缓存时间
*/
public static function increment($key, $offset = 1, $initValue = 0, $expire = 1800)
{
//初始化key
if (!Cache::get($key)) {
Cache::set($key, $initValue, $expire);
}
//增加偏移量
$cacheValue = intval(Cache::get($key))+$offset;
Cache::set($key, $cacheValue, $expire);
}
}
... ...
... ... @@ -135,12 +135,14 @@ class BrandsModel
//获取$condition和$option 筛选条件和排序条件
$searchCondition = SearchModel::searchCondition($customCondition, $customOptions);
// 组合搜索商品url
$urlList['product'] = SearchData::getProductUrl($searchCondition['condition']);
// 组合搜索分类url
$urlList['sort'] = SearchData::getClassesUrl($searchCondition['sortCondition']);
$brandSort = array(
'brand' => $searchCondition['sortCondition']['brand']
);
$urlList['sort'] = SearchData::getClassesUrl($brandSort);
//组合搜索品牌url
$urlList['brand'] = SearchData::getBrandUrl($customOptions);
... ...
... ... @@ -23,7 +23,7 @@ class IndexModel
$urlList['product'] = SearchData::getProductUrl($searchCondition['condition']);
// 组合搜索分类url
$urlList['sort'] = SearchData::getClassesUrl($searchCondition['sortCondition']);
$urlList['sort'] = SearchData::getClassesUrl();
//批量调接口获取数据
$result = Yohobuy::getMulti($urlList);
... ...
... ... @@ -57,6 +57,7 @@ class SearchModel
//关键字
if (isset($condition['query']) && !empty($condition['query'])) {
$condition['query'] = rawurldecode($condition['query']);
$condition['query'] = HelperSearch::stripTags($condition['query']);
}
//品牌
if (isset($condition['brand']) && !empty($condition['brand'])) {
... ... @@ -157,7 +158,6 @@ class SearchModel
// 组合搜索商品url
$urlList['product'] = SearchData::getProductUrl($searchCondition['condition']);
// 组合搜索分类url
//$urlList['sort'] = SearchData::getClassesUrl($searchCondition['sortCondition']);
$urlList['sort'] = SearchData::getClassesUrl();
// 组合搜索折扣区间url
$urlList['discount'] = SearchData::getDiscountUrl();
... ...
... ... @@ -109,27 +109,22 @@ class LoginController extends WebAction
$ip = Helpers::getClientIp();
$ipKey = md5('ip_signin_' . $ip);
$accountKey = md5('account_signin_' . $account);
if (!Cache::get($ipKey)) {
Cache::set($ipKey, 0);
}
if (!Cache::get($accountKey)) {
Cache::set($accountKey, 0);
}
Cache::increment($ipKey, 1, 0, 3600);
PassportModel::increment($ipKey, 1, 0, 3600);
$accountTimes = Cache::get($accountKey);
$ipTimes = Cache::get($ipKey);
if ($accountTimes > 10) {
$data = array('code' => 400, 'message' => '您的账号已被暂时锁定,请稍后再试', 'data' => '');
break;
}
$ipTimes = Cache::get($ipKey);
if ($ipTimes > 100) {
$data = array('code' => 400, 'message' => '您尝试的次数过多,账号已被暂时锁定,请稍后再试', 'data' => '');
break;
}
$data = LoginData::signin($area, $account, $password, $shoppingKey);
if (!isset($data['code']) || $data['code'] != 200 || !isset($data['data']['uid'])) {
Cache::increment($accountKey, 1, 0, 1800);
$data = array('code' => 400, 'message' => '您输入的密码及账户名不匹配,是否<a href="'.Helpers::url('/passport/back/index').'" target="_blank">忘记密码?</a>', 'data' => '');
PassportModel::increment($accountKey, 1, 0, 1800);
$data = array('code' => 400, 'message' => '您输入的密码及账户名不匹配,是否<a href="'.Helpers::url('/passport/back/index').'" target="_blank">忘记密码?</a>', 'data' => '');
break;
}
... ...
... ... @@ -48,10 +48,8 @@ class RegisterController extends WebAction
$ip = Helpers::getClientIp();
$data = array('code' => 400, 'message' => '', 'data' => '');
$ipKey = md5('ip_checkmobile_' . $ip);
if (!Cache::get($ipKey)) {
Cache::set($ipKey, 0);
}
$ipTimes = Cache::increment($ipKey, 1, 0, 3600);
PassportModel::increment($ipKey, 1, 0, 3600);
$ipTimes = Cache::get($ipKey);
do{
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
... ... @@ -132,10 +130,8 @@ class RegisterController extends WebAction
}
//发送代码
$sendCodeKey = md5('send_code_' . $area . '_' . $mobile);
if (!Cache::get($sendCodeKey)) {
Cache::set($sendCodeKey, 0);
}
$sendCodeTimes = Cache::increment($sendCodeKey, 1, 0, 3600);
PassportModel::increment($sendCodeKey, 1, 0, 3600);
$sendCodeTimes = Cache::get($sendCodeKey);
if ($sendCodeTimes > 50) {
$data['message'] = '发送验证码太多';
break;
... ...
... ... @@ -25,6 +25,7 @@ class ThirdloginController extends WebAction
'openId' => $openId,
'sourceType' => $sourceType,
'region' => RegData::getAreasData(),
'serviceUrl' => Helpers::url('/help', array('category_id' => 9))
);
$this->_view->display('index', $data);
... ... @@ -57,6 +58,7 @@ class ThirdloginController extends WebAction
* 绑定成功
*
*/
public function bindSuccessAction()
{
... ...
... ... @@ -70,4 +70,4 @@ class SearchController extends WebAction
$this->setWebNavHeader();
$this->_view->display('search', $data);
}
}
\ No newline at end of file
}
... ...